logd: use coalesce instead of merge (cleanup)
- switch to coalesce instead of merge in naming of functions and variables. Confusing since we also to merge-sorts and other activities in the logger. - define maxPrune rather than using a number in the code path. Bug: 24511000
This commit is contained in:
parent
55793400f2
commit
aaad42f47c
|
@ -217,7 +217,7 @@ int LogBuffer::log(log_id_t log_id, log_time realtime,
|
|||
return len;
|
||||
}
|
||||
|
||||
// Prune at most 10% of the log entries or 256, whichever is less.
|
||||
// Prune at most 10% of the log entries or maxPrune, whichever is less.
|
||||
//
|
||||
// mLogElementsLock must be held when this function is called.
|
||||
void LogBuffer::maybePrune(log_id_t id) {
|
||||
|
@ -228,18 +228,18 @@ void LogBuffer::maybePrune(log_id_t id) {
|
|||
size_t elements = stats.elements(id);
|
||||
size_t minElements = elements / 10;
|
||||
unsigned long pruneRows = elements * sizeOver / sizes;
|
||||
if (pruneRows <= minElements) {
|
||||
if (pruneRows < minElements) {
|
||||
pruneRows = minElements;
|
||||
}
|
||||
if (pruneRows > 256) {
|
||||
pruneRows = 256;
|
||||
if (pruneRows > maxPrune) {
|
||||
pruneRows = maxPrune;
|
||||
}
|
||||
prune(id, pruneRows);
|
||||
}
|
||||
}
|
||||
|
||||
LogBufferElementCollection::iterator LogBuffer::erase(
|
||||
LogBufferElementCollection::iterator it, bool engageStats) {
|
||||
LogBufferElementCollection::iterator it, bool coalesce) {
|
||||
LogBufferElement *e = *it;
|
||||
log_id_t id = e->getLogId();
|
||||
|
||||
|
@ -248,10 +248,10 @@ LogBufferElementCollection::iterator LogBuffer::erase(
|
|||
mLastWorstUid[id].erase(f);
|
||||
}
|
||||
it = mLogElements.erase(it);
|
||||
if (engageStats) {
|
||||
stats.subtract(e);
|
||||
} else {
|
||||
if (coalesce) {
|
||||
stats.erase(e);
|
||||
} else {
|
||||
stats.subtract(e);
|
||||
}
|
||||
delete e;
|
||||
|
||||
|
@ -286,7 +286,7 @@ class LogBufferElementLast {
|
|||
|
||||
public:
|
||||
|
||||
bool merge(LogBufferElement *e, unsigned short dropped) {
|
||||
bool coalesce(LogBufferElement *e, unsigned short dropped) {
|
||||
LogBufferElementKey key(e->getUid(), e->getPid(), e->getTid());
|
||||
LogBufferElementMap::iterator it = map.find(key.getKey());
|
||||
if (it != map.end()) {
|
||||
|
@ -454,7 +454,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
|
|||
it = mLogElements.begin();
|
||||
// Perform at least one mandatory garbage collection cycle in following
|
||||
// - clear leading chatty tags
|
||||
// - merge chatty tags
|
||||
// - coalesce chatty tags
|
||||
// - check age-out of preserved logs
|
||||
bool gc = pruneRows <= 1;
|
||||
if (!gc && (worst != (uid_t) -1)) {
|
||||
|
@ -493,9 +493,8 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
|
|||
continue;
|
||||
}
|
||||
|
||||
// merge any drops
|
||||
if (dropped && last.merge(e, dropped)) {
|
||||
it = erase(it, false);
|
||||
if (dropped && last.coalesce(e, dropped)) {
|
||||
it = erase(it, true);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -526,7 +525,6 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
|
|||
break;
|
||||
}
|
||||
|
||||
// unmerged drop message
|
||||
if (dropped) {
|
||||
last.add(e);
|
||||
if ((!gc && (e->getUid() == worst))
|
||||
|
@ -560,8 +558,8 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
|
|||
} else {
|
||||
stats.drop(e);
|
||||
e->setDropped(1);
|
||||
if (last.merge(e, 1)) {
|
||||
it = erase(it, false);
|
||||
if (last.coalesce(e, 1)) {
|
||||
it = erase(it, true);
|
||||
} else {
|
||||
last.add(e);
|
||||
if (!gc || (mLastWorstUid[id].find(worst)
|
||||
|
|
|
@ -85,10 +85,13 @@ public:
|
|||
void unlock() { pthread_mutex_unlock(&mLogElementsLock); }
|
||||
|
||||
private:
|
||||
|
||||
static constexpr size_t maxPrune = 256;
|
||||
|
||||
void maybePrune(log_id_t id);
|
||||
bool prune(log_id_t id, unsigned long pruneRows, uid_t uid = AID_ROOT);
|
||||
LogBufferElementCollection::iterator erase(
|
||||
LogBufferElementCollection::iterator it, bool engageStats = true);
|
||||
LogBufferElementCollection::iterator it, bool coalesce = false);
|
||||
};
|
||||
|
||||
#endif // _LOGD_LOG_BUFFER_H__
|
||||
|
|
|
@ -321,7 +321,7 @@ public:
|
|||
void subtract(LogBufferElement *entry);
|
||||
// entry->setDropped(1) must follow this call
|
||||
void drop(LogBufferElement *entry);
|
||||
// Correct for merging two entries referencing dropped content
|
||||
// Correct for coalescing two entries referencing dropped content
|
||||
void erase(LogBufferElement *e) { --mElements[e->getLogId()]; }
|
||||
|
||||
std::unique_ptr<const UidEntry *[]> sort(size_t n, log_id i) { return uidTable[i].sort(n); }
|
||||
|
|
Loading…
Reference in New Issue