From e72c6e43668c8c6e1af77e2e5038557581cbf148 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Sun, 21 Sep 2014 14:22:18 -0700 Subject: [PATCH 1/2] logd: cleanup - simplify access and control exposure to class list - indent - compile warning - Follow standard naming convention for variables and methods - merge common fragments - Side Effects: none Change-Id: I74796043ac34753c6dd10018719ebc0bcd94e010 --- logd/LogBuffer.cpp | 33 ++++++++++------------ logd/LogBuffer.h | 5 ++-- logd/LogStatistics.cpp | 62 +++++++++++++++++++++--------------------- logd/LogStatistics.h | 12 ++++++-- 4 files changed, 56 insertions(+), 56 deletions(-) diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index cd9ea2097..8c1c3447a 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -93,9 +93,9 @@ static unsigned long property_get_size(const char *key) { } LogBuffer::LogBuffer(LastLogTimes *times) - : mTimes(*times) { + : dgramQlenStatistics(false) + , mTimes(*times) { pthread_mutex_init(&mLogElementsLock, NULL); - dgram_qlen_statistics = false; static const char global_tuneable[] = "persist.logd.size"; // Settings App static const char global_default[] = "ro.logd.size"; // BoardConfig.mk @@ -150,10 +150,10 @@ void LogBuffer::log(log_id_t log_id, log_time realtime, while (--it != mLogElements.begin()) { if ((*it)->getRealTime() <= realtime) { // halves the peak performance, use with caution - if (dgram_qlen_statistics) { + if (dgramQlenStatistics) { LogBufferElementCollection::iterator ib = it; unsigned short buckets, num = 1; - for (unsigned short i = 0; (buckets = stats.dgram_qlen(i)); ++i) { + for (unsigned short i = 0; (buckets = stats.dgramQlen(i)); ++i) { buckets -= num; num += buckets; while (buckets && (--ib != mLogElements.begin())) { @@ -267,8 +267,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { if (uid == caller_uid) { it = mLogElements.erase(it); - unsigned short len = e->getMsgLen(); - stats.subtract(len, id, uid, e->getPid()); + stats.subtract(e->getMsgLen(), id, uid, e->getPid()); delete e; pruneRows--; if (pruneRows == 0) { @@ -318,23 +317,19 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { uid_t uid = e->getUid(); - if (uid == worst) { + if ((uid == worst) || mPrune.naughty(e)) { // Worst or BlackListed it = mLogElements.erase(it); unsigned short len = e->getMsgLen(); - stats.subtract(len, id, worst, e->getPid()); - delete e; - kick = true; - pruneRows--; - if ((pruneRows == 0) || (worst_sizes < second_worst_sizes)) { - break; - } - worst_sizes -= len; - } else if (mPrune.naughty(e)) { // BlackListed - it = mLogElements.erase(it); - stats.subtract(e->getMsgLen(), id, uid, e->getPid()); + stats.subtract(len, id, uid, e->getPid()); delete e; pruneRows--; - if (pruneRows == 0) { + if (uid == worst) { + kick = true; + if ((pruneRows == 0) || (worst_sizes < second_worst_sizes)) { + break; + } + worst_sizes -= len; + } else if (pruneRows == 0) { break; } } else { diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h index 4b982a878..91175e0c0 100644 --- a/logd/LogBuffer.h +++ b/logd/LogBuffer.h @@ -37,8 +37,7 @@ class LogBuffer { pthread_mutex_t mLogElementsLock; LogStatistics stats; - - bool dgram_qlen_statistics; + bool dgramQlenStatistics; PruneList mPrune; @@ -66,7 +65,7 @@ public: void enableDgramQlenStatistics() { stats.enableDgramQlenStatistics(); - dgram_qlen_statistics = true; + dgramQlenStatistics = true; } int initPrune(char *cp) { return mPrune.init(cp); } diff --git a/logd/LogStatistics.cpp b/logd/LogStatistics.cpp index 82f91655b..b887ce9d5 100644 --- a/logd/LogStatistics.cpp +++ b/logd/LogStatistics.cpp @@ -51,10 +51,7 @@ PidStatistics::~PidStatistics() { } bool PidStatistics::pidGone() { - if (mGone) { - return true; - } - if (pid == gone) { + if (mGone || (pid == gone)) { return true; } if (kill(pid, 0) && (errno != EPERM)) { @@ -90,6 +87,9 @@ void PidStatistics::addTotal(size_t size, size_t element) { } // must call free to release return value +// If only we could sniff our own logs for: +//