logd: prune more aggressively when over the top

(cherry picked from commit 63c15d5061)

Change-Id: I929dddc7da048c032fb791c7af23f215f8856bf3
This commit is contained in:
Mark Salyzyn 2014-01-13 16:37:51 -08:00
parent 0175b0747a
commit 740f9b4f97

View file

@ -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);
}
}