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
This commit is contained in:
Mark Salyzyn 2015-08-19 17:06:11 -07:00
parent 2c1b8f9e20
commit c892ea3fa8
2 changed files with 23 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -40,6 +40,11 @@ class LogBuffer {
LogStatistics stats;
PruneList mPrune;
// watermark of any worst/chatty uid processing
typedef std::unordered_map<uid_t,
LogBufferElementCollection::iterator>
LogBufferIteratorMap;
LogBufferIteratorMap mLastWorstUid[LOG_ID_MAX];
unsigned long mMaxSize[LOG_ID_MAX];