summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2017-04-17 14:46:12 -0500
committerMark Salyzyn2017-04-17 17:10:26 -0500
commit5836379b2114f47c53485b42ab157104c29b2c4e (patch)
tree7a1728529511862d750700e7cfdd1a16079f70e7 /logd/LogBuffer.cpp
parentffa38cfc1ea33de4ddddb291cc70cc507506b758 (diff)
downloadplatform-system-core-5836379b2114f47c53485b42ab157104c29b2c4e.tar.gz
platform-system-core-5836379b2114f47c53485b42ab157104c29b2c4e.tar.xz
platform-system-core-5836379b2114f47c53485b42ab157104c29b2c4e.zip
logd: regression in handling watermark boundary.
Deal with a regression introduced in commit 5a34d6ea43d28f3b5d27bf6dd5b9fa31ec033531 (logd: drop mSequence from LogBufferElement) where log_time was compared against nsec() time miscalculating the watermark boundary. When dealing with logcat -t/-T, or any tail reading, add a margin to prune to back off by a period of 3 seconds (pruneMargin). Test: gTest liblog-unit-tests logcat-unit-tests and logd-unit-tests Bug: 37378309 Change-Id: I72ea858e4e7b5fa91741ea84c40d2e7c3c4aa031
Diffstat (limited to 'logd/LogBuffer.cpp')
-rw-r--r--logd/LogBuffer.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp
index 0c7019ad8..4a790c9f5 100644
--- a/logd/LogBuffer.cpp
+++ b/logd/LogBuffer.cpp
@@ -43,6 +43,8 @@
43// Default 43// Default
44#define log_buffer_size(id) mMaxSize[id] 44#define log_buffer_size(id) mMaxSize[id]
45 45
46const log_time LogBuffer::pruneMargin(3, 0);
47
46void LogBuffer::init() { 48void LogBuffer::init() {
47 log_id_for_each(i) { 49 log_id_for_each(i) {
48 mLastSet[i] = false; 50 mLastSet[i] = false;
@@ -672,6 +674,8 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
672 } 674 }
673 times++; 675 times++;
674 } 676 }
677 log_time watermark(log_time::tv_sec_max, log_time::tv_nsec_max);
678 if (oldest) watermark = oldest->mStart - pruneMargin;
675 679
676 LogBufferElementCollection::iterator it; 680 LogBufferElementCollection::iterator it;
677 681
@@ -693,7 +697,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
693 mLastSet[id] = true; 697 mLastSet[id] = true;
694 } 698 }
695 699
696 if (oldest && (oldest->mStart <= element->getRealTime().nsec())) { 700 if (oldest && (watermark <= element->getRealTime())) {
697 busy = true; 701 busy = true;
698 if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) { 702 if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) {
699 oldest->triggerReader_Locked(); 703 oldest->triggerReader_Locked();
@@ -785,7 +789,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
785 while (it != mLogElements.end()) { 789 while (it != mLogElements.end()) {
786 LogBufferElement* element = *it; 790 LogBufferElement* element = *it;
787 791
788 if (oldest && (oldest->mStart <= element->getRealTime().nsec())) { 792 if (oldest && (watermark <= element->getRealTime())) {
789 busy = true; 793 busy = true;
790 if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) { 794 if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) {
791 oldest->triggerReader_Locked(); 795 oldest->triggerReader_Locked();
@@ -939,7 +943,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
939 mLastSet[id] = true; 943 mLastSet[id] = true;
940 } 944 }
941 945
942 if (oldest && (oldest->mStart <= element->getRealTime().nsec())) { 946 if (oldest && (watermark <= element->getRealTime())) {
943 busy = true; 947 busy = true;
944 if (whitelist) { 948 if (whitelist) {
945 break; 949 break;
@@ -983,7 +987,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
983 mLastSet[id] = true; 987 mLastSet[id] = true;
984 } 988 }
985 989
986 if (oldest && (oldest->mStart <= element->getRealTime().nsec())) { 990 if (oldest && (watermark <= element->getRealTime())) {
987 busy = true; 991 busy = true;
988 if (stats.sizes(id) > (2 * log_buffer_size(id))) { 992 if (stats.sizes(id) > (2 * log_buffer_size(id))) {
989 // kick a misbehaving log reader client off the island 993 // kick a misbehaving log reader client off the island
@@ -1090,13 +1094,15 @@ log_time LogBuffer::flushTo(SocketClient* reader, const log_time& start,
1090 // client wants to start from the beginning 1094 // client wants to start from the beginning
1091 it = mLogElements.begin(); 1095 it = mLogElements.begin();
1092 } else { 1096 } else {
1093 LogBufferElementCollection::iterator last;
1094 // 3 second limit to continue search for out-of-order entries. 1097 // 3 second limit to continue search for out-of-order entries.
1095 log_time min = start - log_time(3, 0); 1098 log_time min = start - pruneMargin;
1099
1096 // Cap to 300 iterations we look back for out-of-order entries. 1100 // Cap to 300 iterations we look back for out-of-order entries.
1097 size_t count = 300; 1101 size_t count = 300;
1102
1098 // Client wants to start from some specified time. Chances are 1103 // Client wants to start from some specified time. Chances are
1099 // we are better off starting from the end of the time sorted list. 1104 // we are better off starting from the end of the time sorted list.
1105 LogBufferElementCollection::iterator last;
1100 for (last = it = mLogElements.end(); it != mLogElements.begin(); 1106 for (last = it = mLogElements.end(); it != mLogElements.begin();
1101 /* do nothing */) { 1107 /* do nothing */) {
1102 --it; 1108 --it;