summaryrefslogtreecommitdiffstats
path: root/logd/LogStatistics.cpp
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2015-03-16 12:04:09 -0700
committerMark Salyzyn <salyzyn@google.com>2015-04-10 15:45:08 -0700
commitab0dcf682867bd7e1fdebfd8d8f9fafaccfad7f6 (patch)
tree7270dcf317cb23df7f8386afc6031053dd53b920 /logd/LogStatistics.cpp
parent65937e9bac665e216268d7341094afcaa52ef8c1 (diff)
downloadsystem_core-ab0dcf682867bd7e1fdebfd8d8f9fafaccfad7f6.tar.gz
system_core-ab0dcf682867bd7e1fdebfd8d8f9fafaccfad7f6.tar.bz2
system_core-ab0dcf682867bd7e1fdebfd8d8f9fafaccfad7f6.zip
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
Diffstat (limited to 'logd/LogStatistics.cpp')
-rw-r--r--logd/LogStatistics.cpp92
1 files changed, 78 insertions, 14 deletions
diff --git a/logd/LogStatistics.cpp b/logd/LogStatistics.cpp
index 3fbcfd6c3..e0b8fd882 100644
--- a/logd/LogStatistics.cpp
+++ b/logd/LogStatistics.cpp
@@ -71,16 +71,19 @@ void LogStatistics::add(LogBufferElement *e) {
++mElements[log_id];
uid_t uid = e->getUid();
+ unsigned short dropped = e->getDropped();
android::hash_t hash = android::hash_type(uid);
uidTable_t &table = uidTable[log_id];
ssize_t index = table.find(-1, hash, uid);
if (index == -1) {
UidEntry initEntry(uid);
initEntry.add(size);
+ initEntry.add_dropped(dropped);
table.add(hash, initEntry);
} else {
UidEntry &entry = table.editEntryAt(index);
entry.add(size);
+ entry.add_dropped(dropped);
}
mSizesTotal[log_id] += size;
@@ -96,6 +99,7 @@ void LogStatistics::add(LogBufferElement *e) {
if (index == -1) {
PidEntry initEntry(pid, uid, android::pidToName(pid));
initEntry.add(size);
+ initEntry.add_dropped(dropped);
pidTable.add(hash, initEntry);
} else {
PidEntry &entry = pidTable.editEntryAt(index);
@@ -109,6 +113,7 @@ void LogStatistics::add(LogBufferElement *e) {
}
}
entry.add(size);
+ entry.add_dropped(dropped);
}
}
@@ -119,12 +124,13 @@ void LogStatistics::subtract(LogBufferElement *e) {
--mElements[log_id];
uid_t uid = e->getUid();
+ unsigned short dropped = e->getDropped();
android::hash_t hash = android::hash_type(uid);
uidTable_t &table = uidTable[log_id];
ssize_t index = table.find(-1, hash, uid);
if (index != -1) {
UidEntry &entry = table.editEntryAt(index);
- if (entry.subtract(size)) {
+ if (entry.subtract(size) || entry.subtract_dropped(dropped)) {
table.removeAt(index);
}
}
@@ -138,12 +144,43 @@ void LogStatistics::subtract(LogBufferElement *e) {
index = pidTable.find(-1, hash, pid);
if (index != -1) {
PidEntry &entry = pidTable.editEntryAt(index);
- if (entry.subtract(size)) {
+ if (entry.subtract(size) || entry.subtract_dropped(dropped)) {
pidTable.removeAt(index);
}
}
}
+// Atomically set an entry to drop
+// entry->setDropped(1) must follow this call, caller should do this explicitly.
+void LogStatistics::drop(LogBufferElement *e) {
+ log_id_t log_id = e->getLogId();
+ unsigned short size = e->getMsgLen();
+ mSizes[log_id] -= size;
+
+ uid_t uid = e->getUid();
+ android::hash_t hash = android::hash_type(uid);
+ typeof uidTable[0] &table = uidTable[log_id];
+ ssize_t index = table.find(-1, hash, uid);
+ if (index != -1) {
+ UidEntry &entry = table.editEntryAt(index);
+ entry.subtract(size);
+ entry.add_dropped(1);
+ }
+
+ if (!enable) {
+ return;
+ }
+
+ pid_t pid = e->getPid();
+ hash = android::hash_type(pid);
+ index = pidTable.find(-1, hash, pid);
+ if (index != -1) {
+ PidEntry &entry = pidTable.editEntryAt(index);
+ entry.subtract(size);
+ entry.add_dropped(1);
+ }
+}
+
// caller must own and free character string
char *LogStatistics::uidToName(uid_t uid) {
// Local hard coded favourites
@@ -191,12 +228,22 @@ char *LogStatistics::uidToName(uid_t uid) {
}
static void format_line(android::String8 &output,
- android::String8 &name, android::String8 &size) {
- static const size_t total_len = 70;
-
- output.appendFormat("%s%*s\n", name.string(),
- (int)std::max(total_len - name.length() - 1, size.length() + 1),
- size.string());
+ android::String8 &name, android::String8 &size, android::String8 &pruned) {
+ static const size_t pruned_len = 6;
+ static const size_t total_len = 70 + pruned_len;
+
+ ssize_t drop_len = std::max(pruned.length() + 1, pruned_len);
+ ssize_t size_len = std::max(size.length() + 1,
+ total_len - name.length() - drop_len - 1);
+
+ if (pruned.length()) {
+ output.appendFormat("%s%*s%*s\n", name.string(),
+ (int)size_len, size.string(),
+ (int)drop_len, pruned.string());
+ } else {
+ output.appendFormat("%s%*s\n", name.string(),
+ (int)size_len, size.string());
+ }
}
void LogStatistics::format(char **buf, uid_t uid, unsigned int logMask) {
@@ -285,14 +332,18 @@ void LogStatistics::format(char **buf, uid_t uid, unsigned int logMask) {
output.appendFormat(
"\n\nChattiest UIDs in %s:\n",
android_log_id_to_name(id));
- android::String8 name("UID");
- android::String8 size("Size");
- format_line(output, name, size);
} else {
output.appendFormat(
"\n\nLogging for your UID in %s:\n",
android_log_id_to_name(id));
}
+ android::String8 name("UID");
+ android::String8 size("Size");
+ android::String8 pruned("Pruned");
+ if (id == LOG_ID_CRASH) {
+ pruned.setTo("");
+ }
+ format_line(output, name, size, pruned);
headerPrinted = true;
}
@@ -307,7 +358,13 @@ void LogStatistics::format(char **buf, uid_t uid, unsigned int logMask) {
android::String8 size("");
size.appendFormat("%zu", entry->getSizes());
- format_line(output, name, size);
+ android::String8 pruned("");
+ size_t dropped = entry->getDropped();
+ if (dropped) {
+ pruned.appendFormat("%zu", dropped);
+ }
+
+ format_line(output, name, size, pruned);
}
}
@@ -330,7 +387,8 @@ void LogStatistics::format(char **buf, uid_t uid, unsigned int logMask) {
}
android::String8 name(" PID/UID");
android::String8 size("Size");
- format_line(output, name, size);
+ android::String8 pruned("Pruned");
+ format_line(output, name, size, pruned);
headerPrinted = true;
}
@@ -350,7 +408,13 @@ void LogStatistics::format(char **buf, uid_t uid, unsigned int logMask) {
android::String8 size("");
size.appendFormat("%zu", entry->getSizes());
- format_line(output, name, size);
+ android::String8 pruned("");
+ size_t dropped = entry->getDropped();
+ if (dropped) {
+ pruned.appendFormat("%zu", dropped);
+ }
+
+ format_line(output, name, size, pruned);
}
}