diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index 5cfc02f32..1b6838656 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -217,7 +217,7 @@ int LogBuffer::log(log_id_t log_id, log_time realtime, return len; } -// Prune at most 10% of the log entries or 256, whichever is less. +// Prune at most 10% of the log entries or maxPrune, whichever is less. // // mLogElementsLock must be held when this function is called. void LogBuffer::maybePrune(log_id_t id) { @@ -228,18 +228,18 @@ void LogBuffer::maybePrune(log_id_t id) { size_t elements = stats.elements(id); size_t minElements = elements / 10; unsigned long pruneRows = elements * sizeOver / sizes; - if (pruneRows <= minElements) { + if (pruneRows < minElements) { pruneRows = minElements; } - if (pruneRows > 256) { - pruneRows = 256; + if (pruneRows > maxPrune) { + pruneRows = maxPrune; } prune(id, pruneRows); } } LogBufferElementCollection::iterator LogBuffer::erase( - LogBufferElementCollection::iterator it, bool engageStats) { + LogBufferElementCollection::iterator it, bool coalesce) { LogBufferElement *e = *it; log_id_t id = e->getLogId(); @@ -248,10 +248,10 @@ LogBufferElementCollection::iterator LogBuffer::erase( mLastWorstUid[id].erase(f); } it = mLogElements.erase(it); - if (engageStats) { - stats.subtract(e); - } else { + if (coalesce) { stats.erase(e); + } else { + stats.subtract(e); } delete e; @@ -286,7 +286,7 @@ class LogBufferElementLast { public: - bool merge(LogBufferElement *e, unsigned short dropped) { + bool coalesce(LogBufferElement *e, unsigned short dropped) { LogBufferElementKey key(e->getUid(), e->getPid(), e->getTid()); LogBufferElementMap::iterator it = map.find(key.getKey()); if (it != map.end()) { @@ -454,7 +454,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { it = mLogElements.begin(); // Perform at least one mandatory garbage collection cycle in following // - clear leading chatty tags - // - merge chatty tags + // - coalesce chatty tags // - check age-out of preserved logs bool gc = pruneRows <= 1; if (!gc && (worst != (uid_t) -1)) { @@ -493,9 +493,8 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { continue; } - // merge any drops - if (dropped && last.merge(e, dropped)) { - it = erase(it, false); + if (dropped && last.coalesce(e, dropped)) { + it = erase(it, true); continue; } @@ -526,7 +525,6 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { break; } - // unmerged drop message if (dropped) { last.add(e); if ((!gc && (e->getUid() == worst)) @@ -560,8 +558,8 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { } else { stats.drop(e); e->setDropped(1); - if (last.merge(e, 1)) { - it = erase(it, false); + if (last.coalesce(e, 1)) { + it = erase(it, true); } else { last.add(e); if (!gc || (mLastWorstUid[id].find(worst) diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h index d8e0b90f2..28f452685 100644 --- a/logd/LogBuffer.h +++ b/logd/LogBuffer.h @@ -85,10 +85,13 @@ public: void unlock() { pthread_mutex_unlock(&mLogElementsLock); } private: + + static constexpr size_t maxPrune = 256; + void maybePrune(log_id_t id); bool prune(log_id_t id, unsigned long pruneRows, uid_t uid = AID_ROOT); LogBufferElementCollection::iterator erase( - LogBufferElementCollection::iterator it, bool engageStats = true); + LogBufferElementCollection::iterator it, bool coalesce = false); }; #endif // _LOGD_LOG_BUFFER_H__ diff --git a/logd/LogStatistics.h b/logd/LogStatistics.h index 5a44d59ab..6041ae670 100644 --- a/logd/LogStatistics.h +++ b/logd/LogStatistics.h @@ -321,7 +321,7 @@ public: void subtract(LogBufferElement *entry); // entry->setDropped(1) must follow this call void drop(LogBufferElement *entry); - // Correct for merging two entries referencing dropped content + // Correct for coalescing two entries referencing dropped content void erase(LogBufferElement *e) { --mElements[e->getLogId()]; } std::unique_ptr sort(size_t n, log_id i) { return uidTable[i].sort(n); }