diff options
Diffstat (limited to 'logd/LogBuffer.cpp')
-rw-r--r-- | logd/LogBuffer.cpp | 87 |
1 files changed, 34 insertions, 53 deletions
diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index 1c5cef0..38a237c 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -28,20 +28,16 @@ // Default #define LOG_BUFFER_SIZE (256 * 1024) // Tuned on a per-platform basis here? -#ifdef USERDEBUG_BUILD #define log_buffer_size(id) mMaxSize[id] -#else -#define log_buffer_size(id) LOG_BUFFER_SIZE -#endif LogBuffer::LogBuffer(LastLogTimes *times) : mTimes(*times) { pthread_mutex_init(&mLogElementsLock, NULL); -#ifdef USERDEBUG_BUILD + dgram_qlen_statistics = false; + log_id_for_each(i) { mMaxSize[i] = LOG_BUFFER_SIZE; } -#endif } void LogBuffer::log(log_id_t log_id, log_time realtime, @@ -61,6 +57,23 @@ void LogBuffer::log(log_id_t log_id, log_time realtime, LogBufferElementCollection::iterator last = it; while (--it != mLogElements.begin()) { if ((*it)->getRealTime() <= realtime) { + // halves the peak performance, use with caution + if (dgram_qlen_statistics) { + LogBufferElementCollection::iterator ib = it; + unsigned short buckets, num = 1; + for (unsigned short i = 0; (buckets = stats.dgram_qlen(i)); ++i) { + buckets -= num; + num += buckets; + while (buckets && (--ib != mLogElements.begin())) { + --buckets; + } + if (buckets) { + break; + } + stats.recordDiff( + elem->getRealTime() - (*ib)->getRealTime(), i); + } + } break; } last = it; @@ -152,22 +165,16 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows) { size_t worst_sizes = 0; size_t second_worst_sizes = 0; -#ifdef USERDEBUG_BUILD - if (mPrune.worstUidEnabled()) -#endif - { + if ((id != LOG_ID_CRASH) && mPrune.worstUidEnabled()) { LidStatistics &l = stats.id(id); - UidStatisticsCollection::iterator iu; - for (iu = l.begin(); iu != l.end(); ++iu) { - UidStatistics *u = (*iu); - size_t sizes = u->sizes(); - if (worst_sizes < sizes) { - second_worst_sizes = worst_sizes; - worst_sizes = sizes; - worst = u->getUid(); - } - if ((second_worst_sizes < sizes) && (sizes < worst_sizes)) { - second_worst_sizes = sizes; + l.sort(); + UidStatisticsCollection::iterator iu = l.begin(); + if (iu != l.end()) { + UidStatistics *u = *iu; + worst = u->getUid(); + worst_sizes = u->sizes(); + if (++iu != l.end()) { + second_worst_sizes = (*iu)->sizes(); } } } @@ -198,9 +205,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows) { break; } worst_sizes -= len; - } -#ifdef USERDEBUG_BUILD - else if (mPrune.naughty(e)) { // BlackListed + } else if (mPrune.naughty(e)) { // BlackListed it = mLogElements.erase(it); stats.subtract(e->getMsgLen(), id, uid, e->getPid()); delete e; @@ -208,34 +213,23 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows) { if (pruneRows == 0) { break; } - } -#endif - else { + } else { ++it; } } - if (!kick -#ifdef USERDEBUG_BUILD - || !mPrune.worstUidEnabled() -#endif - ) { + if (!kick || !mPrune.worstUidEnabled()) { break; // the following loop will ask bad clients to skip/drop } } -#ifdef USERDEBUG_BUILD bool whitelist = false; -#endif it = mLogElements.begin(); while((pruneRows > 0) && (it != mLogElements.end())) { LogBufferElement *e = *it; if (e->getLogId() == id) { if (oldest && (oldest->mStart <= e->getMonotonicTime())) { -#ifdef USERDEBUG_BUILD - if (!whitelist) -#endif - { + if (!whitelist) { if (stats.sizes(id) > (2 * log_buffer_size(id))) { // kick a misbehaving log reader client off the island oldest->release_Locked(); @@ -245,13 +239,13 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows) { } break; } -#ifdef USERDEBUG_BUILD + if (mPrune.nice(e)) { // WhiteListed whitelist = true; it++; continue; } -#endif + it = mLogElements.erase(it); stats.subtract(e->getMsgLen(), id, e->getUid(), e->getPid()); delete e; @@ -261,7 +255,6 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows) { } } -#ifdef USERDEBUG_BUILD if (whitelist && (pruneRows > 0)) { it = mLogElements.begin(); while((it != mLogElements.end()) && (pruneRows > 0)) { @@ -285,7 +278,6 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows) { } } } -#endif LogTimeEntry::unlock(); } @@ -305,8 +297,6 @@ unsigned long LogBuffer::getSizeUsed(log_id_t id) { return retval; } -#ifdef USERDEBUG_BUILD - // set the total space allocated to "id" int LogBuffer::setSize(log_id_t id, unsigned long size) { // Reasonable limits ... @@ -327,15 +317,6 @@ unsigned long LogBuffer::getSize(log_id_t id) { return retval; } -#else // ! USERDEBUG_BUILD - -// get the total space allocated to "id" -unsigned long LogBuffer::getSize(log_id_t /*id*/) { - return log_buffer_size(id); -} - -#endif - log_time LogBuffer::flushTo( SocketClient *reader, const log_time start, bool privileged, bool (*filter)(const LogBufferElement *element, void *arg), void *arg) { |