Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f5fc5095 authored by Mark Salyzyn's avatar Mark Salyzyn
Browse files

logd: Add control statistics enable/disable.

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

Bug: 17526159
Bug: 17526187
Change-Id: I74796043ac34753c6dd10018719ebc0bcd94e00f
parent e72c6e43
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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); }
+24 −14
Original line number Diff line number Diff line
@@ -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,7 +552,9 @@ void LogStatistics::format(char **buf,

    spaces = 1;
    log_time t(CLOCK_MONOTONIC);
    unsigned long long d = t.nsec() - start.nsec();
    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);
@@ -562,8 +571,9 @@ void LogStatistics::format(char **buf,
                                sizesTotal(i), elementsTotal(i));
            spaces += spaces_total + oldLength - string.length();
        }

        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,
+2 −0
Original line number Diff line number Diff line
@@ -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);
+3 −0
Original line number Diff line number Diff line
@@ -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
+9 −0
Original line number Diff line number Diff line
@@ -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.