From c892ea3fa80dfd3d35c5a3b8bfdc73e7b85eaede Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 19 Aug 2015 17:06:11 -0700 Subject: [PATCH] logd: worst uid record watermark Hold on to last worst uid watermark and bypass a spike to O(n*n*x) (n=samples, x=number of spammers) wrt chatty trimming. Bug: 23327476 Change-Id: I9f21ce95e969b67e576417a760f75c4d86acf364 --- logd/LogBuffer.cpp | 19 ++++++++++++++++++- logd/LogBuffer.h | 5 +++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index 85f770a95..db3f26c72 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -240,7 +240,12 @@ void LogBuffer::maybePrune(log_id_t id) { LogBufferElementCollection::iterator LogBuffer::erase(LogBufferElementCollection::iterator it) { LogBufferElement *e = *it; + log_id_t id = e->getLogId(); + LogBufferIteratorMap::iterator f = mLastWorstUid[id].find(e->getUid()); + if ((f != mLastWorstUid[id].end()) && (it == f->second)) { + mLastWorstUid[id].erase(f); + } it = mLogElements.erase(it); stats.subtract(e); delete e; @@ -399,8 +404,17 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { bool kick = false; bool leading = true; + it = mLogElements.begin(); + if (worst != (uid_t) -1) { + LogBufferIteratorMap::iterator f = mLastWorstUid[id].find(worst); + if ((f != mLastWorstUid[id].end()) + && (f->second != mLogElements.end())) { + leading = false; + it = f->second; + } + } LogBufferElementLast last; - for(it = mLogElements.begin(); it != mLogElements.end();) { + while (it != mLogElements.end()) { LogBufferElement *e = *it; if (oldest && (oldest->mStart <= e->getSequence())) { @@ -450,8 +464,10 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { continue; } + // unmerged drop message if (dropped) { last.add(e); + mLastWorstUid[id][e->getUid()] = it; ++it; continue; } @@ -496,6 +512,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { delete e; } else { last.add(e); + mLastWorstUid[id][e->getUid()] = it; ++it; } } diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h index 76571c67d..e94598c82 100644 --- a/logd/LogBuffer.h +++ b/logd/LogBuffer.h @@ -40,6 +40,11 @@ class LogBuffer { LogStatistics stats; PruneList mPrune; + // watermark of any worst/chatty uid processing + typedef std::unordered_map + LogBufferIteratorMap; + LogBufferIteratorMap mLastWorstUid[LOG_ID_MAX]; unsigned long mMaxSize[LOG_ID_MAX];