logd: annotate worst-UID pruned entries
- internal dropped entries are associated by prune by worst UID
and are applied by UID and by PID
- track dropped entries by rewriting them in place
- merge similar dropped entries together for same UID(implied),
PID and TID so that blame can more clearly be placed
- allow aging of dropped entries by the general backgound pruning
- report individual dropped entries formatted to reader
- add statistics to track dropped entries by UID, the combination
of statistics and dropped logging can track over-the-top Chattiest
clients.
Bug: 19608965
Change-Id: Ibc68480df0c69c55703270cd70c6b26aea165853
diff --git a/logd/LogStatistics.h b/logd/LogStatistics.h
index a65ffe0..f3110d7 100644
--- a/logd/LogStatistics.h
+++ b/logd/LogStatistics.h
@@ -78,13 +78,18 @@
struct UidEntry {
const uid_t uid;
size_t size;
+ size_t dropped;
- UidEntry(uid_t uid):uid(uid),size(0) { }
+ UidEntry(uid_t uid):uid(uid),size(0),dropped(0) { }
inline const uid_t&getKey() const { return uid; }
size_t getSizes() const { return size; }
+ size_t getDropped() const { return dropped; }
+
inline void add(size_t s) { size += s; }
- inline bool subtract(size_t s) { size -= s; return !size; }
+ inline void add_dropped(size_t d) { dropped += d; }
+ inline bool subtract(size_t s) { size -= s; return !dropped && !size; }
+ inline bool subtract_dropped(size_t d) { dropped -= d; return !dropped && !size; }
};
struct PidEntry {
@@ -92,13 +97,15 @@
uid_t uid;
char *name;
size_t size;
+ size_t dropped;
- PidEntry(pid_t p, uid_t u, char *n):pid(p),uid(u),name(n),size(0) { }
+ PidEntry(pid_t p, uid_t u, char *n):pid(p),uid(u),name(n),size(0),dropped(0) { }
PidEntry(const PidEntry &c):
pid(c.pid),
uid(c.uid),
name(c.name ? strdup(c.name) : NULL),
- size(c.size) { }
+ size(c.size),
+ dropped(c.dropped) { }
~PidEntry() { free(name); }
const pid_t&getKey() const { return pid; }
@@ -107,8 +114,11 @@
const char*getName() const { return name; }
char *setName(char *n) { free(name); return name = n; }
size_t getSizes() const { return size; }
+ size_t getDropped() const { return dropped; }
inline void add(size_t s) { size += s; }
- inline bool subtract(size_t s) { size -= s; return !size; }
+ inline void add_dropped(size_t d) { dropped += d; }
+ inline bool subtract(size_t s) { size -= s; return !dropped && !size; }
+ inline bool subtract_dropped(size_t d) { dropped -= d; return !dropped && !size; }
};
// Log Statistics
@@ -134,6 +144,10 @@
void add(LogBufferElement *entry);
void subtract(LogBufferElement *entry);
+ // entry->setDropped(1) must follow this call
+ void drop(LogBufferElement *entry);
+ // Correct for merging 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); }