Loading cmds/statsd/src/metrics/EventMetricProducer.cpp +15 −4 Original line number Diff line number Diff line Loading @@ -129,12 +129,23 @@ void EventMetricProducer::onMatchedLogEventInternalLocked( long long wrapperToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_DATA); 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()); long long eventToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_ID_ATOMS); event.ToProto(*mProto); mProto->write(FIELD_TYPE_INT64 | FIELD_ID_WALL_CLOCK_TIMESTAMP_NANOS, (long long)getWallClockNs()); } event.ToProto(*mProto); mProto->end(eventToken); mProto->end(wrapperToken); } Loading cmds/statsd/src/metrics/GaugeMetricProducer.cpp +6 −2 Original line number Diff line number Diff line Loading @@ -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); Loading cmds/statsd/src/stats_log_util.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -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 cmds/statsd/src/stats_log_util.h +3 −0 Original line number Diff line number Diff line Loading @@ -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 tools/stats_log_api_gen/main.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -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++) { Loading Loading
cmds/statsd/src/metrics/EventMetricProducer.cpp +15 −4 Original line number Diff line number Diff line Loading @@ -129,12 +129,23 @@ void EventMetricProducer::onMatchedLogEventInternalLocked( long long wrapperToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_DATA); 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()); long long eventToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_ID_ATOMS); event.ToProto(*mProto); mProto->write(FIELD_TYPE_INT64 | FIELD_ID_WALL_CLOCK_TIMESTAMP_NANOS, (long long)getWallClockNs()); } event.ToProto(*mProto); mProto->end(eventToken); mProto->end(wrapperToken); } Loading
cmds/statsd/src/metrics/GaugeMetricProducer.cpp +6 −2 Original line number Diff line number Diff line Loading @@ -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); Loading
cmds/statsd/src/stats_log_util.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -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
cmds/statsd/src/stats_log_util.h +3 −0 Original line number Diff line number Diff line Loading @@ -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
tools/stats_log_api_gen/main.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -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++) { Loading