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

Commit d36934d8 authored by Jeffrey Huang's avatar Jeffrey Huang Committed by Automerger Merge Worker
Browse files

Merge "Avoid timestamp update when data is kept on dump" into rvc-dev am:...

Merge "Avoid timestamp update when data is kept on dump" into rvc-dev am: 0017b441 am: 3046d458 am: 3c1f62cc am: 9eb9d90c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11829658

Change-Id: Ibb08eebbfa0eeb3f09fa838407c0886f59ff473d
parents 012a81b0 9eb9d90c
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -361,8 +361,12 @@ void MetricsManager::onDumpReport(const int64_t dumpTimeStampNs,
        protoOutput->end(token);
    }

    // Do not update the timestamps when data is not cleared to avoid timestamps from being
    // misaligned.
    if (erase_data) {
        mLastReportTimeNs = dumpTimeStampNs;
        mLastReportWallClockNs = getWallClockNs();
    }
    VLOG("=========================Metric Reports End==========================");
}

+42 −0
Original line number Diff line number Diff line
@@ -1831,6 +1831,48 @@ TEST(StatsLogProcessorTest_mapIsolatedUidToHostUid, LogIsolatedUidAttributionCha
    EXPECT_EQ(field2, actualFieldValues->at(5).mValue.int_value);
}

TEST(StatsLogProcessorTest, TestDumpReportWithoutErasingDataDoesNotUpdateTimestamp) {
    int hostUid = 20;
    int isolatedUid = 30;
    sp<MockUidMap> mockUidMap = makeMockUidMapForOneHost(hostUid, {isolatedUid});
    ConfigKey key(3, 4);
    StatsdConfig config = MakeConfig(false);
    sp<StatsLogProcessor> processor =
            CreateStatsLogProcessor(1, 1, config, key, nullptr, 0, mockUidMap);
    vector<uint8_t> bytes;

    int64_t dumpTime1Ns = 1 * NS_PER_SEC;
    processor->onDumpReport(key, dumpTime1Ns, false /* include_current_bucket */,
            true /* erase_data */, ADB_DUMP, FAST, &bytes);

    ConfigMetricsReportList output;
    output.ParseFromArray(bytes.data(), bytes.size());
    EXPECT_EQ(output.reports_size(), 1);
    EXPECT_EQ(output.reports(0).current_report_elapsed_nanos(), dumpTime1Ns);

    int64_t dumpTime2Ns = 5 * NS_PER_SEC;
    processor->onDumpReport(key, dumpTime2Ns, false /* include_current_bucket */,
            false /* erase_data */, ADB_DUMP, FAST, &bytes);

    // Check that the dump report without clearing data is successful.
    output.ParseFromArray(bytes.data(), bytes.size());
    EXPECT_EQ(output.reports_size(), 1);
    EXPECT_EQ(output.reports(0).current_report_elapsed_nanos(), dumpTime2Ns);
    EXPECT_EQ(output.reports(0).last_report_elapsed_nanos(), dumpTime1Ns);

    int64_t dumpTime3Ns = 10 * NS_PER_SEC;
    processor->onDumpReport(key, dumpTime3Ns, false /* include_current_bucket */,
            true /* erase_data */, ADB_DUMP, FAST, &bytes);

    // Check that the previous dump report that didn't clear data did not overwrite the first dump's
    // timestamps.
    output.ParseFromArray(bytes.data(), bytes.size());
    EXPECT_EQ(output.reports_size(), 1);
    EXPECT_EQ(output.reports(0).current_report_elapsed_nanos(), dumpTime3Ns);
    EXPECT_EQ(output.reports(0).last_report_elapsed_nanos(), dumpTime1Ns);

}

#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif