logd: continue search out-of-order entries timestamp tail

Regression from commit 8e8e8db549

For liblogcat reader -t or -T <timestamp> tail requests, continue
search for pertinent out-of-order entries for an additional 30 seconds
back into logging history to find a more inclusive starting point.

For example, if you have an out of order landing like
[..., 3, 6, 1, 8, 2, 5] and ask for 3 you used to get only 5, and now
you get 3, 6, 8, 5 as 'expected'

Test: gTest liblog-unit-tests logd-unit-tests logcat-unit-tests
Bug: 35373582
Change-Id: I2a0732933fa371aed383d49c8d48d01f33db2a79
This commit is contained in:
Mark Salyzyn 2017-03-10 10:31:48 -08:00
parent 5a34d6ea43
commit 3b941d457b
1 changed files with 8 additions and 3 deletions

View File

@ -1078,7 +1078,6 @@ log_time LogBuffer::flushTo(
SocketClient* reader, const log_time& start, bool privileged, bool security,
int (*filter)(const LogBufferElement* element, void* arg), void* arg) {
LogBufferElementCollection::iterator it;
log_time max = start;
uid_t uid = reader->getUid();
pthread_mutex_lock(&mLogElementsLock);
@ -1087,19 +1086,25 @@ log_time LogBuffer::flushTo(
// client wants to start from the beginning
it = mLogElements.begin();
} else {
LogBufferElementCollection::iterator last = mLogElements.begin();
// 30 second limit to continue search for out-of-order entries.
log_time min = start - log_time(30, 0);
// Client wants to start from some specified time. Chances are
// we are better off starting from the end of the time sorted list.
for (it = mLogElements.end(); it != mLogElements.begin();
/* do nothing */) {
--it;
LogBufferElement* element = *it;
if (element->getRealTime() <= start) {
it++;
if (element->getRealTime() > start) {
last = it;
} else if (element->getRealTime() < min) {
break;
}
}
it = last;
}
log_time max = start;
// Help detect if the valid message before is from the same source so
// we can differentiate chatty filter types.
pid_t lastTid[LOG_ID_MAX] = { 0 };