Merge "Timestamp Truncating whitelist."

This commit is contained in:
TreeHugger Robot
2018-02-20 20:41:29 +00:00
committed by Android (Google) Code Review
5 changed files with 40 additions and 6 deletions

View File

@@ -129,12 +129,23 @@ void EventMetricProducer::onMatchedLogEventInternalLocked(
long long wrapperToken =
mProto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_DATA);
mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS,
(long long)event.GetElapsedTimestampNs());
long long eventToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_ID_ATOMS);
const bool truncateTimestamp =
android::util::kNotTruncatingTimestampAtomWhiteList.find(event.GetTagId()) ==
android::util::kNotTruncatingTimestampAtomWhiteList.end();
if (truncateTimestamp) {
mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS,
(long long)truncateTimestampNsToFiveMinutes(event.GetElapsedTimestampNs()));
mProto->write(FIELD_TYPE_INT64 | FIELD_ID_WALL_CLOCK_TIMESTAMP_NANOS,
(long long)truncateTimestampNsToFiveMinutes(getWallClockNs()));
} else {
mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS,
(long long)event.GetElapsedTimestampNs());
mProto->write(FIELD_TYPE_INT64 | FIELD_ID_WALL_CLOCK_TIMESTAMP_NANOS,
(long long)getWallClockNs());
}
event.ToProto(*mProto);
mProto->write(FIELD_TYPE_INT64 | FIELD_ID_WALL_CLOCK_TIMESTAMP_NANOS,
(long long)getWallClockNs());
mProto->end(eventToken);
mProto->end(wrapperToken);
}

View File

@@ -173,11 +173,15 @@ void GaugeMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs,
writeFieldValueTreeToStream(mTagId, *(atom.mFields), protoOutput);
}
protoOutput->end(atomsToken);
for (const auto& atom : bucket.mGaugeAtoms) {
const bool truncateTimestamp =
android::util::kNotTruncatingTimestampAtomWhiteList.find(mTagId) ==
android::util::kNotTruncatingTimestampAtomWhiteList.end();
int64_t timestampNs = truncateTimestamp ?
truncateTimestampNsToFiveMinutes(atom.mTimestamps) : atom.mTimestamps;
protoOutput->write(
FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED | FIELD_ID_ELAPSED_ATOM_TIMESTAMP,
(long long)atom.mTimestamps);
(long long)timestampNs);
}
}
protoOutput->end(bucketInfoToken);

View File

@@ -290,6 +290,10 @@ int64_t getWallClockMillis() {
return time(nullptr) * MS_PER_SEC;
}
int64_t truncateTimestampNsToFiveMinutes(int64_t timestampNs) {
return timestampNs / NS_PER_SEC / (5 * 60) * NS_PER_SEC * (5 * 60);
}
} // namespace statsd
} // namespace os
} // namespace android

View File

@@ -73,6 +73,9 @@ bool parseProtoOutputStream(util::ProtoOutputStream& protoOutput, T* message) {
return message->ParseFromArray(pbBytes.c_str(), pbBytes.size());
}
// Returns the truncated timestamp.
int64_t truncateTimestampNsToFiveMinutes(int64_t timestampNs);
} // namespace statsd
} // namespace os
} // namespace android

View File

@@ -365,6 +365,18 @@ write_stats_log_header(FILE* out, const Atoms& atoms, const AtomDecl &attributio
fprintf(out, "};\n");
fprintf(out, "\n");
std::set<string> kFuzzingAtomNames = { "mobile_radio_power_state_changed" };
fprintf(out, "const static std::set<int> kNotTruncatingTimestampAtomWhiteList = {\n");
for (set<AtomDecl>::const_iterator atom = atoms.decls.begin();
atom != atoms.decls.end(); atom++) {
if (kFuzzingAtomNames.find(atom->name) == kFuzzingAtomNames.end()) {
string constant = make_constant_name(atom->name);
fprintf(out, " %s,\n", constant.c_str());
}
}
fprintf(out, "};\n");
fprintf(out, "\n");
fprintf(out, "const static std::set<int> kAtomsWithUidField = {\n");
for (set<AtomDecl>::const_iterator atom = atoms.decls.begin();
atom != atoms.decls.end(); atom++) {