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

Commit 41b3f9a8 authored by Tej Singh's avatar Tej Singh
Browse files

Add proto output of statsd stats in adb

Test: statsd unit tests
Test: visually verified output of adb shell cmd stats print-stats was
sane
Test: making a CTS test that uses proto output
Bug: b/77548658

Change-Id: Ie60d66b9883f109446745dfcef97b7fb6194a1ac
parent 5260eea5
Loading
Loading
Loading
Loading
+38 −11
Original line number Diff line number Diff line
@@ -178,24 +178,35 @@ status_t StatsService::dump(int fd, const Vector<String16>& args) {
    }

    bool verbose = false;
    bool proto = false;
    if (args.size() > 0 && !args[0].compare(String16("-v"))) {
        verbose = true;
    }
    if (args.size() > 0 && !args[args.size()-1].compare(String16("--proto"))) {
        proto = true;
    }

    // TODO: Proto format for incident reports
    dump_impl(out, verbose);
    dump_impl(out, verbose, proto);

    fclose(out);
    return NO_ERROR;
}

/**
 * Write debugging data about statsd in text format.
 * Write debugging data about statsd in text or proto format.
 */
void StatsService::dump_impl(FILE* out, bool verbose) {
void StatsService::dump_impl(FILE* out, bool verbose, bool proto) {
    if (proto) {
        vector<uint8_t> data;
        StatsdStats::getInstance().dumpStats(&data, false); // does not reset statsdStats.
        for (size_t i = 0; i < data.size(); i ++) {
            fprintf(out, "%c", data[i]);
        }
    } else {
        StatsdStats::getInstance().dumpStats(out);
        mProcessor->dumpStates(out, verbose);
    }
}

/**
 * Implementation of the adb shell cmd stats command.
@@ -325,6 +336,7 @@ void StatsService::print_cmd_help(FILE* out) {
    fprintf(out, "\n");
    fprintf(out, "usage: adb shell cmd stats print-stats\n");
    fprintf(out, "  Prints some basic stats.\n");
    fprintf(out, "  --proto       Print proto binary instead of string format.\n");
    fprintf(out, "\n");
    fprintf(out, "\n");
    fprintf(out, "usage: adb shell cmd stats clear-puller-cache\n");
@@ -524,13 +536,28 @@ status_t StatsService::cmd_dump_report(FILE* out, FILE* err, const Vector<String
}

status_t StatsService::cmd_print_stats(FILE* out, const Vector<String8>& args) {
    int argCount = args.size();
    bool proto = false;
    if (!std::strcmp("--proto", args[argCount-1].c_str())) {
        proto = true;
        argCount -= 1;
    }
    StatsdStats& statsdStats = StatsdStats::getInstance();
    if (proto) {
        vector<uint8_t> data;
        statsdStats.dumpStats(&data, false); // does not reset statsdStats.
        for (size_t i = 0; i < data.size(); i ++) {
            fprintf(out, "%c", data[i]);
        }

    } else {
        vector<ConfigKey> configs = mConfigManager->GetAllConfigKeys();
        for (const ConfigKey& key : configs) {
            fprintf(out, "Config %s uses %zu bytes\n", key.ToString().c_str(),
                    mProcessor->GetMetricsSize(key));
        }
    StatsdStats& statsdStats = StatsdStats::getInstance();
        statsdStats.dumpStats(out);
    }
    return NO_ERROR;
}

+2 −2
Original line number Diff line number Diff line
@@ -149,9 +149,9 @@ private:
                                         uint32_t serial);

    /**
     * Text output of dumpsys.
     * Text or proto output of dumpsys.
     */
    void dump_impl(FILE* out, bool verbose);
    void dump_impl(FILE* out, bool verbose, bool proto);

    /**
     * Print usage information for the commands