Blacklist truncated atoms instead of whitelistnig
We used a whitelist to determine which atoms should have their
timestamps truncated to the nearest 5 minutes. This changes the logic
to a blacklist so that we can get fine grained timestamps from vendor and
mainline atoms. Also reserves a range for atoms that need to be
truncated in the future.
Bug: 134574701
Test: inspected generated statslog.cpp file to make sure it had the
correct blacklist
Test: testdrive on ScreenStateChanged to ensure timestamps are preserved
when they should be
Test: testdrive on CallStateChanged to ensure timestamps are truncated
when they should be.
Change-Id: Id3468542c830cdf41395a94c77f7df0b46cd11b7
diff --git a/cmds/statsd/src/metrics/EventMetricProducer.cpp b/cmds/statsd/src/metrics/EventMetricProducer.cpp
index 69816cb..96133bd 100644
--- a/cmds/statsd/src/metrics/EventMetricProducer.cpp
+++ b/cmds/statsd/src/metrics/EventMetricProducer.cpp
@@ -146,16 +146,9 @@
uint64_t wrapperToken =
mProto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_DATA);
- const bool truncateTimestamp =
- android::util::AtomsInfo::kNotTruncatingTimestampAtomWhiteList.find(event.GetTagId()) ==
- android::util::AtomsInfo::kNotTruncatingTimestampAtomWhiteList.end();
- if (truncateTimestamp) {
- mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS,
- (long long)truncateTimestampNsToFiveMinutes(event.GetElapsedTimestampNs()));
- } else {
- mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS,
- (long long)event.GetElapsedTimestampNs());
- }
+ const int64_t elapsedTimeNs = truncateTimestampIfNecessary(
+ event.GetTagId(), event.GetElapsedTimestampNs());
+ mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS, (long long) elapsedTimeNs);
uint64_t eventToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_ID_ATOMS);
event.ToProto(*mProto);
diff --git a/cmds/statsd/src/metrics/GaugeMetricProducer.cpp b/cmds/statsd/src/metrics/GaugeMetricProducer.cpp
index 7a87f03..a64bbc1 100644
--- a/cmds/statsd/src/metrics/GaugeMetricProducer.cpp
+++ b/cmds/statsd/src/metrics/GaugeMetricProducer.cpp
@@ -283,14 +283,9 @@
writeFieldValueTreeToStream(mAtomId, *(atom.mFields), protoOutput);
protoOutput->end(atomsToken);
}
- const bool truncateTimestamp =
- android::util::AtomsInfo::kNotTruncatingTimestampAtomWhiteList.find(
- mAtomId) ==
- android::util::AtomsInfo::kNotTruncatingTimestampAtomWhiteList.end();
for (const auto& atom : bucket.mGaugeAtoms) {
- const int64_t elapsedTimestampNs = truncateTimestamp ?
- truncateTimestampNsToFiveMinutes(atom.mElapsedTimestamps) :
- atom.mElapsedTimestamps;
+ const int64_t elapsedTimestampNs =
+ truncateTimestampIfNecessary(mAtomId, atom.mElapsedTimestamps);
protoOutput->write(
FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED | FIELD_ID_ELAPSED_ATOM_TIMESTAMP,
(long long)elapsedTimestampNs);