diff options
author | Mark Salyzyn | 2017-03-16 12:19:47 -0500 |
---|---|---|
committer | android-build-merger | 2017-03-16 12:19:47 -0500 |
commit | f883804b562143a3b158d0a89a8de2234bf580b5 (patch) | |
tree | 1c9243cfe09d4189ab70a04147094b4c390f99f6 /logd/LogBuffer.cpp | |
parent | 6258cfee90ff442bf2774d8a5eea3fc00cdc638b (diff) | |
parent | 9f8a97ed0b8d05d1d333b8d80d1be37ea34a35d5 (diff) | |
download | platform-system-core-f883804b562143a3b158d0a89a8de2234bf580b5.tar.gz platform-system-core-f883804b562143a3b158d0a89a8de2234bf580b5.tar.xz platform-system-core-f883804b562143a3b158d0a89a8de2234bf580b5.zip |
Merge changes I2a073293,Ia55ef8b9,I79a385fc am: 82b5c619b8 am: 5a0afe7d27
am: 9f8a97ed0b
Change-Id: Iae26c69eb4ffdfdc3b20b1a841bfc67d768f33f1
Diffstat (limited to 'logd/LogBuffer.cpp')
-rw-r--r-- | logd/LogBuffer.cpp | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index 60d647d77..f67372a86 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp | |||
@@ -183,7 +183,7 @@ static enum match_type identical(LogBufferElement* elem, | |||
183 | lenr -= avcr - msgr; | 183 | lenr -= avcr - msgr; |
184 | if (lenl != lenr) return DIFFERENT; | 184 | if (lenl != lenr) return DIFFERENT; |
185 | // TODO: After b/35468874 is addressed, revisit "lenl > strlen(avc)" | 185 | // TODO: After b/35468874 is addressed, revisit "lenl > strlen(avc)" |
186 | // condition, it might become superflous. | 186 | // condition, it might become superfluous. |
187 | if (lenl > strlen(avc) && | 187 | if (lenl > strlen(avc) && |
188 | fastcmp<memcmp>(avcl + strlen(avc), avcr + strlen(avc), | 188 | fastcmp<memcmp>(avcl + strlen(avc), avcr + strlen(avc), |
189 | lenl - strlen(avc))) { | 189 | lenl - strlen(avc))) { |
@@ -376,18 +376,12 @@ void LogBuffer::log(LogBufferElement* elem) { | |||
376 | // NB: if end is region locked, place element at end of list | 376 | // NB: if end is region locked, place element at end of list |
377 | LogBufferElementCollection::iterator it = mLogElements.end(); | 377 | LogBufferElementCollection::iterator it = mLogElements.end(); |
378 | LogBufferElementCollection::iterator last = it; | 378 | LogBufferElementCollection::iterator last = it; |
379 | while (last != mLogElements.begin()) { | 379 | if (__predict_true(it != mLogElements.begin())) --it; |
380 | --it; | 380 | if (__predict_false(it == mLogElements.begin()) || |
381 | if ((*it)->getRealTime() <= elem->getRealTime()) { | 381 | __predict_true((*it)->getRealTime() <= elem->getRealTime())) { |
382 | break; | ||
383 | } | ||
384 | last = it; | ||
385 | } | ||
386 | |||
387 | if (last == mLogElements.end()) { | ||
388 | mLogElements.push_back(elem); | 382 | mLogElements.push_back(elem); |
389 | } else { | 383 | } else { |
390 | uint64_t end = 1; | 384 | log_time end = log_time::EPOCH; |
391 | bool end_set = false; | 385 | bool end_set = false; |
392 | bool end_always = false; | 386 | bool end_always = false; |
393 | 387 | ||
@@ -401,6 +395,7 @@ void LogBuffer::log(LogBufferElement* elem) { | |||
401 | end_always = true; | 395 | end_always = true; |
402 | break; | 396 | break; |
403 | } | 397 | } |
398 | // it passing mEnd is blocked by the following checks. | ||
404 | if (!end_set || (end <= entry->mEnd)) { | 399 | if (!end_set || (end <= entry->mEnd)) { |
405 | end = entry->mEnd; | 400 | end = entry->mEnd; |
406 | end_set = true; | 401 | end_set = true; |
@@ -409,12 +404,20 @@ void LogBuffer::log(LogBufferElement* elem) { | |||
409 | times++; | 404 | times++; |
410 | } | 405 | } |
411 | 406 | ||
412 | if (end_always || (end_set && (end >= (*last)->getSequence()))) { | 407 | if (end_always || (end_set && (end > (*it)->getRealTime()))) { |
413 | mLogElements.push_back(elem); | 408 | mLogElements.push_back(elem); |
414 | } else { | 409 | } else { |
410 | // should be short as timestamps are localized near end() | ||
411 | do { | ||
412 | last = it; | ||
413 | if (__predict_false(it == mLogElements.begin())) { | ||
414 | break; | ||
415 | } | ||
416 | --it; | ||
417 | } while (((*it)->getRealTime() > elem->getRealTime()) && | ||
418 | (!end_set || (end <= (*it)->getRealTime()))); | ||
415 | mLogElements.insert(last, elem); | 419 | mLogElements.insert(last, elem); |
416 | } | 420 | } |
417 | |||
418 | LogTimeEntry::unlock(); | 421 | LogTimeEntry::unlock(); |
419 | } | 422 | } |
420 | 423 | ||
@@ -589,12 +592,12 @@ class LogBufferElementLast { | |||
589 | } | 592 | } |
590 | 593 | ||
591 | void clear(LogBufferElement* element) { | 594 | void clear(LogBufferElement* element) { |
592 | uint64_t current = | 595 | log_time current = |
593 | element->getRealTime().nsec() - (EXPIRE_RATELIMIT * NS_PER_SEC); | 596 | element->getRealTime() - log_time(EXPIRE_RATELIMIT, 0); |
594 | for (LogBufferElementMap::iterator it = map.begin(); it != map.end();) { | 597 | for (LogBufferElementMap::iterator it = map.begin(); it != map.end();) { |
595 | LogBufferElement* mapElement = it->second; | 598 | LogBufferElement* mapElement = it->second; |
596 | if ((mapElement->getDropped() >= EXPIRE_THRESHOLD) && | 599 | if ((mapElement->getDropped() >= EXPIRE_THRESHOLD) && |
597 | (current > mapElement->getRealTime().nsec())) { | 600 | (current > mapElement->getRealTime())) { |
598 | it = map.erase(it); | 601 | it = map.erase(it); |
599 | } else { | 602 | } else { |
600 | ++it; | 603 | ++it; |
@@ -690,7 +693,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { | |||
690 | mLastSet[id] = true; | 693 | mLastSet[id] = true; |
691 | } | 694 | } |
692 | 695 | ||
693 | if (oldest && (oldest->mStart <= element->getSequence())) { | 696 | if (oldest && (oldest->mStart <= element->getRealTime().nsec())) { |
694 | busy = true; | 697 | busy = true; |
695 | if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) { | 698 | if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) { |
696 | oldest->triggerReader_Locked(); | 699 | oldest->triggerReader_Locked(); |
@@ -782,7 +785,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { | |||
782 | while (it != mLogElements.end()) { | 785 | while (it != mLogElements.end()) { |
783 | LogBufferElement* element = *it; | 786 | LogBufferElement* element = *it; |
784 | 787 | ||
785 | if (oldest && (oldest->mStart <= element->getSequence())) { | 788 | if (oldest && (oldest->mStart <= element->getRealTime().nsec())) { |
786 | busy = true; | 789 | busy = true; |
787 | if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) { | 790 | if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) { |
788 | oldest->triggerReader_Locked(); | 791 | oldest->triggerReader_Locked(); |
@@ -936,7 +939,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { | |||
936 | mLastSet[id] = true; | 939 | mLastSet[id] = true; |
937 | } | 940 | } |
938 | 941 | ||
939 | if (oldest && (oldest->mStart <= element->getSequence())) { | 942 | if (oldest && (oldest->mStart <= element->getRealTime().nsec())) { |
940 | busy = true; | 943 | busy = true; |
941 | if (whitelist) { | 944 | if (whitelist) { |
942 | break; | 945 | break; |
@@ -980,7 +983,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { | |||
980 | mLastSet[id] = true; | 983 | mLastSet[id] = true; |
981 | } | 984 | } |
982 | 985 | ||
983 | if (oldest && (oldest->mStart <= element->getSequence())) { | 986 | if (oldest && (oldest->mStart <= element->getRealTime().nsec())) { |
984 | busy = true; | 987 | busy = true; |
985 | if (stats.sizes(id) > (2 * log_buffer_size(id))) { | 988 | if (stats.sizes(id) > (2 * log_buffer_size(id))) { |
986 | // kick a misbehaving log reader client off the island | 989 | // kick a misbehaving log reader client off the island |
@@ -1073,32 +1076,37 @@ unsigned long LogBuffer::getSize(log_id_t id) { | |||
1073 | return retval; | 1076 | return retval; |
1074 | } | 1077 | } |
1075 | 1078 | ||
1076 | uint64_t LogBuffer::flushTo( | 1079 | log_time LogBuffer::flushTo( |
1077 | SocketClient* reader, const uint64_t start, bool privileged, bool security, | 1080 | SocketClient* reader, const log_time& start, bool privileged, bool security, |
1078 | int (*filter)(const LogBufferElement* element, void* arg), void* arg) { | 1081 | int (*filter)(const LogBufferElement* element, void* arg), void* arg) { |
1079 | LogBufferElementCollection::iterator it; | 1082 | LogBufferElementCollection::iterator it; |
1080 | uint64_t max = start; | ||
1081 | uid_t uid = reader->getUid(); | 1083 | uid_t uid = reader->getUid(); |
1082 | 1084 | ||
1083 | pthread_mutex_lock(&mLogElementsLock); | 1085 | pthread_mutex_lock(&mLogElementsLock); |
1084 | 1086 | ||
1085 | if (start <= 1) { | 1087 | if (start == log_time::EPOCH) { |
1086 | // client wants to start from the beginning | 1088 | // client wants to start from the beginning |
1087 | it = mLogElements.begin(); | 1089 | it = mLogElements.begin(); |
1088 | } else { | 1090 | } else { |
1091 | LogBufferElementCollection::iterator last = mLogElements.begin(); | ||
1092 | // 30 second limit to continue search for out-of-order entries. | ||
1093 | log_time min = start - log_time(30, 0); | ||
1089 | // Client wants to start from some specified time. Chances are | 1094 | // Client wants to start from some specified time. Chances are |
1090 | // we are better off starting from the end of the time sorted list. | 1095 | // we are better off starting from the end of the time sorted list. |
1091 | for (it = mLogElements.end(); it != mLogElements.begin(); | 1096 | for (it = mLogElements.end(); it != mLogElements.begin(); |
1092 | /* do nothing */) { | 1097 | /* do nothing */) { |
1093 | --it; | 1098 | --it; |
1094 | LogBufferElement* element = *it; | 1099 | LogBufferElement* element = *it; |
1095 | if (element->getSequence() <= start) { | 1100 | if (element->getRealTime() > start) { |
1096 | it++; | 1101 | last = it; |
1102 | } else if (element->getRealTime() < min) { | ||
1097 | break; | 1103 | break; |
1098 | } | 1104 | } |
1099 | } | 1105 | } |
1106 | it = last; | ||
1100 | } | 1107 | } |
1101 | 1108 | ||
1109 | log_time max = start; | ||
1102 | // Help detect if the valid message before is from the same source so | 1110 | // Help detect if the valid message before is from the same source so |
1103 | // we can differentiate chatty filter types. | 1111 | // we can differentiate chatty filter types. |
1104 | pid_t lastTid[LOG_ID_MAX] = { 0 }; | 1112 | pid_t lastTid[LOG_ID_MAX] = { 0 }; |
@@ -1114,7 +1122,7 @@ uint64_t LogBuffer::flushTo( | |||
1114 | continue; | 1122 | continue; |
1115 | } | 1123 | } |
1116 | 1124 | ||
1117 | if (element->getSequence() <= start) { | 1125 | if (element->getRealTime() <= start) { |
1118 | continue; | 1126 | continue; |
1119 | } | 1127 | } |
1120 | 1128 | ||