summaryrefslogtreecommitdiffstats
path: root/logd/LogBuffer.cpp
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2017-03-14 13:11:12 -0700
committerMark Salyzyn <salyzyn@google.com>2017-03-17 14:17:38 +0000
commit09d663229fe253ec91b341c9f15ed7f2d22f931a (patch)
treefe3aa1e3dcb390fe0f9ef945e533dde0947961dc /logd/LogBuffer.cpp
parentb280bb210b1cbc5a3cc0ab4ba1610a1d31409215 (diff)
downloadsystem_core-09d663229fe253ec91b341c9f15ed7f2d22f931a.tar.gz
system_core-09d663229fe253ec91b341c9f15ed7f2d22f931a.tar.bz2
system_core-09d663229fe253ec91b341c9f15ed7f2d22f931a.zip
logd: cap how far back in-place sort will go to 5 seconds
Add some deterministic behavior should the user change the hour backwards when altering the device time, prevent sort-in-place and cause the logger to land the new entries at the end. Do not limit how far kernel logs can be sorted. Test: gTest liblog-unit-tests logd-unit-tests logcat-unit-tests Bug: 35373582 Change-Id: Ie897c40b97adf1e3996687a0e28c1199c41e0d0c
Diffstat (limited to 'logd/LogBuffer.cpp')
-rw-r--r--logd/LogBuffer.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp
index 1b79e89b9..352fc187f 100644
--- a/logd/LogBuffer.cpp
+++ b/logd/LogBuffer.cpp
@@ -370,13 +370,19 @@ int LogBuffer::log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid,
// assumes mLogElementsLock held, owns elem, will look after garbage collection
void LogBuffer::log(LogBufferElement* elem) {
+ // cap on how far back we will sort in-place, otherwise append
+ static uint32_t too_far_back = 5; // five seconds
// Insert elements in time sorted order if possible
// NB: if end is region locked, place element at end of list
LogBufferElementCollection::iterator it = mLogElements.end();
LogBufferElementCollection::iterator last = it;
if (__predict_true(it != mLogElements.begin())) --it;
if (__predict_false(it == mLogElements.begin()) ||
- __predict_true((*it)->getRealTime() <= elem->getRealTime())) {
+ __predict_true((*it)->getRealTime() <= elem->getRealTime()) ||
+ __predict_false((((*it)->getRealTime().tv_sec - too_far_back) >
+ elem->getRealTime().tv_sec) &&
+ (elem->getLogId() != LOG_ID_KERNEL) &&
+ ((*it)->getLogId() != LOG_ID_KERNEL))) {
mLogElements.push_back(elem);
} else {
log_time end = log_time::EPOCH;