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

Commit 9af33ee7 authored by Mark Salyzyn's avatar Mark Salyzyn
Browse files

logd: report logging memory overhead

On 64 bit system, calculates to roughly 80 bytes of metadata and
list overhead for each entry.

In unit test example, we report 3388987 bytes of logging data and
overhead total, showmap reports 4652K of dirty data. We still want
to account for the remainder (fragmentation, other sources of
internal allocations etc).

Test: see values and check math
Bug: 31942525
Change-Id: I75f3162ce691faf1ae5a5dec18939fea535ede7e
parent 0d762648
Loading
Loading
Loading
Loading
+63 −38
Original line number Original line Diff line number Diff line
@@ -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;
            totalEls += els;
            output += android::base::StringPrintf("%*s%zu/%zu", spaces, "", szs, els);
            spaces -= output.length() - oldLength;
        }
        }
            output += android::base::StringPrintf("%*s%zu/%zu", spaces, "",
        spaces += spaces_total;
                                                  sizes(id), els);
    }
    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 -= output.length() - oldLength;
        }
        }
        spaces += spaces_total;
        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);
    }
    }