diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index 8b273e27c..64d5cc228 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -99,12 +99,20 @@ void LogBuffer::log(log_id_t log_id, struct timespec realtime, } // If we're using more than 256K of memory for log entries, prune -// 10% of the log entries. +// at least 10% of the log entries. // // mLogElementsLock must be held when this function is called. void LogBuffer::maybePrune(log_id_t id) { - if (mSizes[id] > LOG_BUFFER_SIZE) { - prune(id, mElements[id] / 10); + unsigned long sizes = mSizes[id]; + if (sizes > LOG_BUFFER_SIZE) { + unsigned long sizeOver90Percent = sizes - ((LOG_BUFFER_SIZE * 9) / 10); + unsigned long elements = mElements[id]; + unsigned long pruneRows = elements * sizeOver90Percent / sizes; + elements /= 10; + if (pruneRows <= elements) { + pruneRows = elements; + } + prune(id, pruneRows); } }