Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 63c15d50 authored by Mark Salyzyn's avatar Mark Salyzyn
Browse files

logd: prune more aggressively when over the top

Change-Id: I929dddc7da048c032fb791c7af23f215f8856bf3
parent 3e76e0a4
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -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);
    }
}