Merge "logd: report logging memory overhead"

am: d3754ff696

Change-Id: I3e0f11864dab17cc70f0e68a9b69adf8f1edb9d2
This commit is contained in:
Mark Salyzyn 2016-10-06 14:19:46 +00:00 committed by android-build-merger
commit 386630f4ce

View file

@ -21,6 +21,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <list>
#include <log/logger.h> #include <log/logger.h>
#include "LogStatistics.h" #include "LogStatistics.h"
@ -467,55 +469,86 @@ std::string LogStatistics::format(uid_t uid, pid_t pid,
short spaces = 1; short spaces = 1;
log_id_for_each(id) { log_id_for_each(id) {
if (!(logMask & (1 << id))) { if (!(logMask & (1 << id))) continue;
continue;
}
oldLength = output.length(); oldLength = output.length();
if (spaces < 0) { if (spaces < 0) spaces = 0;
spaces = 0;
}
output += android::base::StringPrintf("%*s%s", spaces, "", output += android::base::StringPrintf("%*s%s", spaces, "",
android_log_id_to_name(id)); android_log_id_to_name(id));
spaces += spaces_total + oldLength - output.length(); spaces += spaces_total + oldLength - output.length();
} }
if (spaces < 0) spaces = 0;
output += android::base::StringPrintf("%*sTotal", spaces, "");
spaces = 4; static const char TotalStr[] = "\nTotal";
output += "\nTotal"; spaces = 10 - strlen(TotalStr);
output += TotalStr;
size_t totalSize = 0;
size_t totalEls = 0;
log_id_for_each(id) { log_id_for_each(id) {
if (!(logMask & (1 << id))) { if (!(logMask & (1 << id))) continue;
continue;
}
oldLength = output.length(); oldLength = output.length();
if (spaces < 0) { if (spaces < 0) spaces = 0;
spaces = 0; size_t szs = sizesTotal(id);
} totalSize += szs;
output += android::base::StringPrintf("%*s%zu/%zu", spaces, "", size_t els = elementsTotal(id);
sizesTotal(id), totalEls += els;
elementsTotal(id)); output += android::base::StringPrintf("%*s%zu/%zu", spaces, "", szs, els);
spaces += spaces_total + oldLength - output.length(); spaces += spaces_total + oldLength - output.length();
} }
if (spaces < 0) spaces = 0;
output += android::base::StringPrintf("%*s%zu/%zu", spaces, "", totalSize, totalEls);
spaces = 6; static const char NowStr[] = "\nNow";
output += "\nNow"; spaces = 10 - strlen(NowStr);
output += NowStr;
totalSize = 0;
totalEls = 0;
log_id_for_each(id) { log_id_for_each(id) {
if (!(logMask & (1 << id))) { if (!(logMask & (1 << id))) continue;
continue;
}
size_t els = elements(id); size_t els = elements(id);
if (els) { if (els) {
oldLength = output.length(); oldLength = output.length();
if (spaces < 0) { if (spaces < 0) spaces = 0;
spaces = 0; size_t szs = sizes(id);
} totalSize += szs;
output += android::base::StringPrintf("%*s%zu/%zu", spaces, "", totalEls += els;
sizes(id), els); output += android::base::StringPrintf("%*s%zu/%zu", spaces, "", szs, els);
spaces -= output.length() - oldLength; spaces -= output.length() - oldLength;
} }
spaces += spaces_total; spaces += spaces_total;
} }
if (spaces < 0) spaces = 0;
output += android::base::StringPrintf("%*s%zu/%zu", spaces, "", totalSize, totalEls);
static const char OverheadStr[] = "\nOverhead";
spaces = 10 - strlen(OverheadStr);
output += OverheadStr;
totalSize = 0;
log_id_for_each(id) {
if (!(logMask & (1 << id))) continue;
size_t els = elements(id);
if (els) {
oldLength = output.length();
if (spaces < 0) spaces = 0;
// estimate the std::list overhead.
static const size_t overhead =
((sizeof(LogBufferElement) + sizeof(uint64_t) - 1) &
-sizeof(uint64_t)) +
sizeof(std::list<LogBufferElement*>);
size_t szs = sizes(id) + els * overhead;
totalSize += szs;
output += android::base::StringPrintf("%*s%zu", spaces, "", szs);
spaces -= output.length() - oldLength;
}
spaces += spaces_total;
}
if (spaces < 0) spaces = 0;
output += android::base::StringPrintf("%*s%zu", spaces, "", totalSize);
// Report on Chattiest // Report on Chattiest
@ -523,9 +556,7 @@ std::string LogStatistics::format(uid_t uid, pid_t pid,
// Chattiest by application (UID) // Chattiest by application (UID)
log_id_for_each(id) { log_id_for_each(id) {
if (!(logMask & (1 << id))) { if (!(logMask & (1 << id))) continue;
continue;
}
name = (uid == AID_ROOT) name = (uid == AID_ROOT)
? "Chattiest UIDs in %s log buffer:" ? "Chattiest UIDs in %s log buffer:"
@ -539,27 +570,21 @@ std::string LogStatistics::format(uid_t uid, pid_t pid,
: "Logging for this PID:"; : "Logging for this PID:";
output += pidTable.format(*this, uid, pid, name); output += pidTable.format(*this, uid, pid, name);
name = "Chattiest TIDs"; name = "Chattiest TIDs";
if (pid) { if (pid) name += android::base::StringPrintf(" for PID %d", pid);
name += android::base::StringPrintf(" for PID %d", pid);
}
name += ":"; name += ":";
output += tidTable.format(*this, uid, pid, name); output += tidTable.format(*this, uid, pid, name);
} }
if (enable && (logMask & (1 << LOG_ID_EVENTS))) { if (enable && (logMask & (1 << LOG_ID_EVENTS))) {
name = "Chattiest events log buffer TAGs"; name = "Chattiest events log buffer TAGs";
if (pid) { if (pid) name += android::base::StringPrintf(" for PID %d", pid);
name += android::base::StringPrintf(" for PID %d", pid);
}
name += ":"; name += ":";
output += tagTable.format(*this, uid, pid, name, LOG_ID_EVENTS); output += tagTable.format(*this, uid, pid, name, LOG_ID_EVENTS);
} }
if (enable && (logMask & (1 << LOG_ID_SECURITY))) { if (enable && (logMask & (1 << LOG_ID_SECURITY))) {
name = "Chattiest security log buffer TAGs"; name = "Chattiest security log buffer TAGs";
if (pid) { if (pid) name += android::base::StringPrintf(" for PID %d", pid);
name += android::base::StringPrintf(" for PID %d", pid);
}
name += ":"; name += ":";
output += securityTagTable.format(*this, uid, pid, name, LOG_ID_SECURITY); output += securityTagTable.format(*this, uid, pid, name, LOG_ID_SECURITY);
} }