summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2015-05-13 11:17:36 -0500
committerGerrit Code Review2015-05-13 11:17:37 -0500
commitd1371a8b8b55352e19332ba87f4b3ece6db58e1f (patch)
tree05117f65f88eb23b6390bc856b826a625d72125a /logd/LogStatistics.cpp
parent0c6c41502acdd73ddcefd2f52489d94e3ca70241 (diff)
parent17ed6797df722464eb5cc6dfc3e1e32aec284b70 (diff)
downloadplatform-system-core-d1371a8b8b55352e19332ba87f4b3ece6db58e1f.tar.gz
platform-system-core-d1371a8b8b55352e19332ba87f4b3ece6db58e1f.tar.xz
platform-system-core-d1371a8b8b55352e19332ba87f4b3ece6db58e1f.zip
Merge "logd: Add TID statistics"
Diffstat (limited to 'logd/LogStatistics.cpp')
-rw-r--r--logd/LogStatistics.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/logd/LogStatistics.cpp b/logd/LogStatistics.cpp
index 675b69274..90c49c0ee 100644
--- a/logd/LogStatistics.cpp
+++ b/logd/LogStatistics.cpp
@@ -83,6 +83,7 @@ void LogStatistics::add(LogBufferElement *e) {
83 } 83 }
84 84
85 pidTable.add(e->getPid(), e); 85 pidTable.add(e->getPid(), e);
86 tidTable.add(e->getTid(), e);
86 87
87 uint32_t tag = e->getTag(); 88 uint32_t tag = e->getTag();
88 if (tag) { 89 if (tag) {
@@ -107,6 +108,7 @@ void LogStatistics::subtract(LogBufferElement *e) {
107 } 108 }
108 109
109 pidTable.subtract(e->getPid(), e); 110 pidTable.subtract(e->getPid(), e);
111 tidTable.subtract(e->getTid(), e);
110 112
111 uint32_t tag = e->getTag(); 113 uint32_t tag = e->getTag();
112 if (tag) { 114 if (tag) {
@@ -128,6 +130,7 @@ void LogStatistics::drop(LogBufferElement *e) {
128 } 130 }
129 131
130 pidTable.drop(e->getPid(), e); 132 pidTable.drop(e->getPid(), e);
133 tidTable.drop(e->getTid(), e);
131} 134}
132 135
133// caller must own and free character string 136// caller must own and free character string
@@ -390,6 +393,63 @@ void LogStatistics::format(char **buf, uid_t uid, unsigned int logMask) {
390 } 393 }
391 } 394 }
392 395
396 if (enable) {
397 // Tid table
398 bool headerPrinted = false;
399 // sort() returns list of references, unique_ptr makes sure self-delete
400 std::unique_ptr<const TidEntry *[]> sorted = tidTable.sort(maximum_sorted_entries);
401 ssize_t index = -1;
402 while ((index = tidTable.next(index, sorted, maximum_sorted_entries)) >= 0) {
403 const TidEntry *entry = sorted[index];
404 uid_t u = entry->getUid();
405 if ((uid != AID_ROOT) && (u != uid)) {
406 continue;
407 }
408
409 if (!headerPrinted) { // Only print header if we have table to print
410 output.appendFormat("\n\n");
411 android::String8 name("Chattiest TIDs:");
412 android::String8 size("Size");
413 android::String8 pruned("Pruned");
414 format_line(output, name, size, pruned);
415
416 name.setTo(" TID/UID COMM");
417 size.setTo("BYTES");
418 pruned.setTo("LINES");
419 format_line(output, name, size, pruned);
420
421 headerPrinted = true;
422 }
423
424 android::String8 name("");
425 name.appendFormat("%5u/%u", entry->getKey(), u);
426 const char *n = entry->getName();
427 if (n) {
428 name.appendFormat("%*s%s", (int)std::max(12 - name.length(), (size_t)1), "", n);
429 } else {
430 // if we do not have a PID name, lets punt to try UID name?
431 char *un = uidToName(u);
432 if (un) {
433 name.appendFormat("%*s%s", (int)std::max(12 - name.length(), (size_t)1), "", un);
434 free(un);
435 }
436 // We tried, better to not have a name at all, we still
437 // have TID/UID by number to report in any case.
438 }
439
440 android::String8 size("");
441 size.appendFormat("%zu", entry->getSizes());
442
443 android::String8 pruned("");
444 size_t dropped = entry->getDropped();
445 if (dropped) {
446 pruned.appendFormat("%zu", dropped);
447 }
448
449 format_line(output, name, size, pruned);
450 }
451 }
452
393 if (enable && (logMask & (1 << LOG_ID_EVENTS))) { 453 if (enable && (logMask & (1 << LOG_ID_EVENTS))) {
394 // Tag table 454 // Tag table
395 bool headerPrinted = false; 455 bool headerPrinted = false;