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

Commit 926fc757 authored by David Chen's avatar David Chen
Browse files

Fixes timebase used when dumping reports.

We should be using elapsed realtime for most timestamps in statsd
so that the times can only increase monotonically.

Test: Test that statsd builds and unit-tests passes.
Change-Id: I0bb23e89aa9a6dbf6d56a0c23eec77bdd053f29b
parent 08ddee73
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -316,7 +316,7 @@ void StatsLogProcessor::flushIfNecessaryLocked(
        StatsdStats::kMaxMetricsBytesPerConfig) {  // Too late. We need to start clearing data.
        // TODO(b/70571383): By 12/15/2017 add API to drop data directly
        ProtoOutputStream proto;
        metricsManager.onDumpReport(time(nullptr) * NS_PER_SEC, &proto);
        metricsManager.onDumpReport(timestampNs, &proto);
        StatsdStats::getInstance().noteDataDropped(key);
        VLOG("StatsD had to toss out metrics for %s", key.ToString().c_str());
    } else if (totalBytes > .9 * StatsdStats::kMaxMetricsBytesPerConfig) {
@@ -340,7 +340,7 @@ void StatsLogProcessor::WriteDataToDisk() {
    for (auto& pair : mMetricsManagers) {
        const ConfigKey& key = pair.first;
        vector<uint8_t> data;
        onDumpReportLocked(key, time(nullptr) * NS_PER_SEC, &data);
        onDumpReportLocked(key, getElapsedRealtimeNs(), &data);
        // TODO: Add a guardrail to prevent accumulation of file on disk.
        string file_name = StringPrintf("%s/%ld_%d_%lld", STATS_DATA_DIR,
             (long)getWallClockSec(), key.GetUid(), (long long)key.GetId());
+2 −2
Original line number Diff line number Diff line
@@ -493,7 +493,7 @@ status_t StatsService::cmd_dump_report(FILE* out, FILE* err, const Vector<String
        }
        if (good) {
            vector<uint8_t> data;
            mProcessor->onDumpReport(ConfigKey(uid, StrToInt64(name)), time(nullptr) * NS_PER_SEC,
            mProcessor->onDumpReport(ConfigKey(uid, StrToInt64(name)), getElapsedRealtimeNs(),
                                     &data);
            // TODO: print the returned StatsLogReport to file instead of printing to logcat.
            if (proto) {
@@ -786,7 +786,7 @@ Status StatsService::getData(int64_t key, vector<uint8_t>* output) {
    VLOG("StatsService::getData with Pid %i, Uid %i", ipc->getCallingPid(), ipc->getCallingUid());
    if (checkCallingPermission(String16(kPermissionDump))) {
        ConfigKey configKey(ipc->getCallingUid(), key);
        mProcessor->onDumpReport(configKey, time(nullptr) * NS_PER_SEC, output);
        mProcessor->onDumpReport(configKey, getElapsedRealtimeNs(), output);
        return Status::ok();
    } else {
        return Status::fromExceptionCode(binder::Status::EX_SECURITY);