From 9bc35ef4c975891e2fb77745c877ce8847727b73 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 16 Sep 2015 15:34:00 -0700 Subject: [PATCH] logd: clearAll by UID speedup (cherry pick from commit 2b25c66070f73413013caa48e1c171cb895869b5) - If doing a clear, skip accounting - Ensure for busy checking, behind a region lock for instance, only break out if there was something to do. Basically move the filter actions first, and defer checking the region lock to the ends of the loops. Bug: 23711431 Change-Id: Icc984f406880633516fb17dda84188a30d092e01 --- logd/LogBuffer.cpp | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index 0dcc1c3c3..6c24b5206 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -377,6 +377,7 @@ public: bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { LogTimeEntry *oldest = NULL; bool busy = false; + bool clearAll = pruneRows == ULONG_MAX; LogTimeEntry::lock(); @@ -394,29 +395,23 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { LogBufferElementCollection::iterator it; if (caller_uid != AID_ROOT) { + // Only here if clearAll condition (pruneRows == ULONG_MAX) for(it = mLogElements.begin(); it != mLogElements.end();) { LogBufferElement *e = *it; + if ((e->getLogId() != id) || (e->getUid() != caller_uid)) { + ++it; + continue; + } + if (oldest && (oldest->mStart <= e->getSequence())) { oldest->triggerSkip_Locked(id, pruneRows); busy = true; break; } - if (e->getLogId() != id) { - ++it; - continue; - } - - if (e->getUid() == caller_uid) { - it = erase(it); - pruneRows--; - if (pruneRows == 0) { - break; - } - } else { - ++it; - } + it = erase(it); + pruneRows--; } LogTimeEntry::unlock(); return busy; @@ -424,7 +419,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { // prune by worst offender by uid bool hasBlacklist = mPrune.naughty(); - while (pruneRows > 0) { + while (!clearAll && (pruneRows > 0)) { // recalculate the worst offender on every batched pass uid_t worst = (uid_t) -1; size_t worst_sizes = 0; @@ -592,7 +587,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { } bool whitelist = false; - bool hasWhitelist = mPrune.nice(); + bool hasWhitelist = mPrune.nice() && !clearAll; it = mLogElements.begin(); while((pruneRows > 0) && (it != mLogElements.end())) { LogBufferElement *e = *it;