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

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

Change-Id: Ic6533b4be2a0249f49b00fe1a254009cfa690dbd
This commit is contained in:
Jeffrey Huang
2020-06-11 18:42:19 +00:00
committed by Automerger Merge Worker
2 changed files with 48 additions and 2 deletions

View File

@@ -361,8 +361,12 @@ void MetricsManager::onDumpReport(const int64_t dumpTimeStampNs,
protoOutput->end(token);
}
mLastReportTimeNs = dumpTimeStampNs;
mLastReportWallClockNs = getWallClockNs();
// 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==========================");
}

View File

@@ -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