logd: Add control statistics enable/disable.

- ro.build.type=user turn off statistics
- ro.config.low_ram=true turn off statistics
- logd.statistics override

(cherry pick from commit f5fc509589)

Bug: 17526159
Bug: 17526187
Change-Id: I74796043ac34753c6dd10018719ebc0bcd94e00f
This commit is contained in:
Mark Salyzyn 2014-09-21 14:22:18 -07:00
parent 987f1e0de3
commit a0e53540da
5 changed files with 42 additions and 14 deletions

View file

@ -68,6 +68,10 @@ public:
dgramQlenStatistics = true;
}
void enableStatistics() {
stats.enableStatistics();
}
int initPrune(char *cp) { return mPrune.init(cp); }
// *strp uses malloc, use free to release.
void formatPrune(char **strp) { mPrune.format(strp); }

View file

@ -384,7 +384,8 @@ size_t LidStatistics::elementsTotal(uid_t uid, pid_t pid) {
}
LogStatistics::LogStatistics()
: dgramQlenStatistics(false)
: mStatistics(false)
, dgramQlenStatistics(false)
, start(CLOCK_MONOTONIC) {
log_id_for_each(i) {
mSizes[i] = 0;
@ -455,6 +456,9 @@ void LogStatistics::add(unsigned short size,
log_id_t log_id, uid_t uid, pid_t pid) {
mSizes[log_id] += size;
++mElements[log_id];
if (!mStatistics) {
return;
}
id(log_id).add(size, uid, pid);
}
@ -462,6 +466,9 @@ void LogStatistics::subtract(unsigned short size,
log_id_t log_id, uid_t uid, pid_t pid) {
mSizes[log_id] -= size;
--mElements[log_id];
if (!mStatistics) {
return;
}
id(log_id).subtract(size, uid, pid);
}
@ -545,25 +552,28 @@ void LogStatistics::format(char **buf,
spaces = 1;
log_time t(CLOCK_MONOTONIC);
unsigned long long d = t.nsec() - start.nsec();
string.appendFormat("\nTotal%4llu:%02llu:%02llu.%09llu",
unsigned long long d;
if (mStatistics) {
d = t.nsec() - start.nsec();
string.appendFormat("\nTotal%4llu:%02llu:%02llu.%09llu",
d / NS_PER_SEC / 60 / 60, (d / NS_PER_SEC / 60) % 60,
(d / NS_PER_SEC) % 60, d % NS_PER_SEC);
log_id_for_each(i) {
if (!(logMask & (1 << i))) {
continue;
log_id_for_each(i) {
if (!(logMask & (1 << i))) {
continue;
}
oldLength = string.length();
if (spaces < 0) {
spaces = 0;
}
string.appendFormat("%*s%zu/%zu", spaces, "",
sizesTotal(i), elementsTotal(i));
spaces += spaces_total + oldLength - string.length();
}
oldLength = string.length();
if (spaces < 0) {
spaces = 0;
}
string.appendFormat("%*s%zu/%zu", spaces, "",
sizesTotal(i), elementsTotal(i));
spaces += spaces_total + oldLength - string.length();
spaces = 1;
}
spaces = 1;
d = t.nsec() - oldest.nsec();
string.appendFormat("\nNow%6llu:%02llu:%02llu.%09llu",
d / NS_PER_SEC / 60 / 60, (d / NS_PER_SEC / 60) % 60,

View file

@ -144,6 +144,7 @@ class LogStatistics {
size_t mSizes[LOG_ID_MAX];
size_t mElements[LOG_ID_MAX];
bool mStatistics;
bool dgramQlenStatistics;
static const unsigned short mBuckets[14];
@ -157,6 +158,7 @@ public:
LidStatistics &id(log_id_t log_id) { return LogIds[log_id]; }
void enableDgramQlenStatistics() { dgramQlenStatistics = true; }
void enableStatistics() { mStatistics = true; }
static unsigned short dgramQlen(unsigned short bucket);
unsigned long long minimum(unsigned short bucket);
void recordDiff(log_time diff, unsigned short bucket);

View file

@ -4,6 +4,9 @@ name type default description
logd.auditd bool true Enable selinux audit daemon
logd.auditd.dmesg bool true selinux audit messages duplicated and
sent on to dmesg log
logd.statistics bool depends Enable logcat -S statistics.
ro.config.low_ram bool false if true, logd.statistics default false
ro.build.type string if user, logd.statistics default false
logd.statistics.dgram_qlen bool false Record dgram_qlen statistics. This
represents a performance impact and
is used to determine the platform's

View file

@ -152,6 +152,15 @@ int main() {
if (property_get_bool("logd.statistics.dgram_qlen", false)) {
logBuf->enableDgramQlenStatistics();
}
{
char property[PROPERTY_VALUE_MAX];
property_get("ro.build.type", property, "");
if (property_get_bool("logd.statistics",
!!strcmp(property, "user")
&& !property_get_bool("ro.config.low_ram", false))) {
logBuf->enableStatistics();
}
}
// LogReader listens on /dev/socket/logdr. When a client
// connects, log entries in the LogBuffer are written to the client.