From e06a6e0f26f51a8f1aab84076d5241ae820069b7 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Mon, 20 Apr 2015 14:08:56 -0700 Subject: logd: ratelimit drop messages to 1/sec Bug: 20334069 Bug: 20370119 Change-Id: I6f850aec46c4df1c99a5b1f28db75d071e134ad5 --- logd/LogBuffer.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index 1859461..83a6b1d 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -247,7 +247,7 @@ public: uint64_t getKey() { return value; } }; -struct LogBufferElementEntry { +class LogBufferElementEntry { const uint64_t key; LogBufferElement *last; @@ -259,8 +259,9 @@ public: LogBufferElement *getLast() { return last; } }; -struct LogBufferElementLast : public android::BasicHashtable { +class LogBufferElementLast : public android::BasicHashtable { +public: bool merge(LogBufferElement *e, unsigned short dropped) { LogBufferElementKey key(e->getUid(), e->getPid(), e->getTid()); android::hash_t hash = android::hash_type(key.getKey()); @@ -286,6 +287,21 @@ struct LogBufferElementLast : public android::BasicHashtable::clear(); + } + + void clear(LogBufferElement *e) { + uint64_t current = e->getRealTime().nsec() - NS_PER_SEC; + ssize_t index = -1; + while((index = next(index)) >= 0) { + if (current > editEntryAt(index).getLast()->getRealTime().nsec()) { + removeAt(index); + index = -1; + } + } + } + }; // prune "pruneRows" of type "id" from the buffer. @@ -395,7 +411,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { leading = false; if (hasBlacklist && mPrune.naughty(e)) { - last.clear(); + last.clear(e); it = erase(it); if (dropped) { continue; @@ -423,7 +439,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { } if (e->getUid() != worst) { - last.clear(); + last.clear(e); ++it; continue; } -- cgit v1.1