diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2020-04-16 13:07:00 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-04-16 13:07:00 +0000 |
commit | cbd9f03e82221f96c362717669cfee49093e386c (patch) | |
tree | fcd4c0dc0f843669b70de611221a89a9f4058a9b | |
parent | 1f976bf63402d1ad221e28bc28556142ebeaf3f6 (diff) | |
parent | a7de00022bce6a641fd3753d0549dfc3a5146620 (diff) |
Merge "Remove kTruncatingTimestampAtomBlackList" into rvc-dev
-rw-r--r-- | cmds/statsd/src/logd/LogEvent.h | 2 | ||||
-rw-r--r-- | cmds/statsd/src/metrics/EventMetricProducer.cpp | 3 | ||||
-rw-r--r-- | cmds/statsd/src/metrics/GaugeMetricProducer.cpp | 12 | ||||
-rw-r--r-- | cmds/statsd/src/metrics/GaugeMetricProducer.h | 4 | ||||
-rw-r--r-- | cmds/statsd/src/stats_log_util.cpp | 13 | ||||
-rw-r--r-- | cmds/statsd/src/stats_log_util.h | 7 | ||||
-rw-r--r-- | tools/stats_log_api_gen/atoms_info_writer.cpp | 22 |
7 files changed, 20 insertions, 43 deletions
diff --git a/cmds/statsd/src/logd/LogEvent.h b/cmds/statsd/src/logd/LogEvent.h index c9c0305dea4d..41fdcc2cbe7a 100644 --- a/cmds/statsd/src/logd/LogEvent.h +++ b/cmds/statsd/src/logd/LogEvent.h @@ -145,7 +145,7 @@ public: } // Default value = false - inline bool shouldTruncateTimestamp() { + inline bool shouldTruncateTimestamp() const { return mTruncateTimestamp; } diff --git a/cmds/statsd/src/metrics/EventMetricProducer.cpp b/cmds/statsd/src/metrics/EventMetricProducer.cpp index 6833f8dd0114..d68f64ae40b0 100644 --- a/cmds/statsd/src/metrics/EventMetricProducer.cpp +++ b/cmds/statsd/src/metrics/EventMetricProducer.cpp @@ -151,8 +151,7 @@ void EventMetricProducer::onMatchedLogEventInternalLocked( uint64_t wrapperToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_DATA); - const int64_t elapsedTimeNs = truncateTimestampIfNecessary( - event.GetTagId(), event.GetElapsedTimestampNs()); + const int64_t elapsedTimeNs = truncateTimestampIfNecessary(event); mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS, (long long) elapsedTimeNs); uint64_t eventToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_ID_ATOMS); diff --git a/cmds/statsd/src/metrics/GaugeMetricProducer.cpp b/cmds/statsd/src/metrics/GaugeMetricProducer.cpp index 42bbd8eb4d35..c4bd0549465a 100644 --- a/cmds/statsd/src/metrics/GaugeMetricProducer.cpp +++ b/cmds/statsd/src/metrics/GaugeMetricProducer.cpp @@ -270,11 +270,9 @@ void GaugeMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs, protoOutput->end(atomsToken); } for (const auto& atom : bucket.mGaugeAtoms) { - const int64_t elapsedTimestampNs = - truncateTimestampIfNecessary(mAtomId, atom.mElapsedTimestamps); - protoOutput->write( - FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED | FIELD_ID_ELAPSED_ATOM_TIMESTAMP, - (long long)elapsedTimestampNs); + protoOutput->write(FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED | + FIELD_ID_ELAPSED_ATOM_TIMESTAMP, + (long long)atom.mElapsedTimestampNs); } } protoOutput->end(bucketInfoToken); @@ -477,7 +475,9 @@ void GaugeMetricProducer::onMatchedLogEventInternalLocked( if ((*mCurrentSlicedBucket)[eventKey].size() >= mGaugeAtomsPerDimensionLimit) { return; } - GaugeAtom gaugeAtom(getGaugeFields(event), eventTimeNs); + + const int64_t truncatedElapsedTimestampNs = truncateTimestampIfNecessary(event); + GaugeAtom gaugeAtom(getGaugeFields(event), truncatedElapsedTimestampNs); (*mCurrentSlicedBucket)[eventKey].push_back(gaugeAtom); // Anomaly detection on gauge metric only works when there is one numeric // field specified. diff --git a/cmds/statsd/src/metrics/GaugeMetricProducer.h b/cmds/statsd/src/metrics/GaugeMetricProducer.h index 79ec71120f18..aa0cae26080d 100644 --- a/cmds/statsd/src/metrics/GaugeMetricProducer.h +++ b/cmds/statsd/src/metrics/GaugeMetricProducer.h @@ -35,10 +35,10 @@ namespace statsd { struct GaugeAtom { GaugeAtom(std::shared_ptr<vector<FieldValue>> fields, int64_t elapsedTimeNs) - : mFields(fields), mElapsedTimestamps(elapsedTimeNs) { + : mFields(fields), mElapsedTimestampNs(elapsedTimeNs) { } std::shared_ptr<vector<FieldValue>> mFields; - int64_t mElapsedTimestamps; + int64_t mElapsedTimestampNs; }; struct GaugeBucket { diff --git a/cmds/statsd/src/stats_log_util.cpp b/cmds/statsd/src/stats_log_util.cpp index 77a3eb31fdd4..563531351fe0 100644 --- a/cmds/statsd/src/stats_log_util.cpp +++ b/cmds/statsd/src/stats_log_util.cpp @@ -549,14 +549,13 @@ int64_t getWallClockMillis() { return time(nullptr) * MS_PER_SEC; } -int64_t truncateTimestampIfNecessary(int atomId, int64_t timestampNs) { - if (AtomsInfo::kTruncatingTimestampAtomBlackList.find(atomId) != - AtomsInfo::kTruncatingTimestampAtomBlackList.end() || - (atomId >= StatsdStats::kTimestampTruncationStartTag && - atomId <= StatsdStats::kTimestampTruncationEndTag)) { - return timestampNs / NS_PER_SEC / (5 * 60) * NS_PER_SEC * (5 * 60); +int64_t truncateTimestampIfNecessary(const LogEvent& event) { + if (event.shouldTruncateTimestamp() || + (event.GetTagId() >= StatsdStats::kTimestampTruncationStartTag && + event.GetTagId() <= StatsdStats::kTimestampTruncationEndTag)) { + return event.GetElapsedTimestampNs() / NS_PER_SEC / (5 * 60) * NS_PER_SEC * (5 * 60); } else { - return timestampNs; + return event.GetElapsedTimestampNs(); } } diff --git a/cmds/statsd/src/stats_log_util.h b/cmds/statsd/src/stats_log_util.h index ade25d69a3a4..20d93b5a5365 100644 --- a/cmds/statsd/src/stats_log_util.h +++ b/cmds/statsd/src/stats_log_util.h @@ -17,11 +17,12 @@ #pragma once #include <android/util/ProtoOutputStream.h> + #include "FieldValue.h" #include "HashableDimensionKey.h" -#include "atoms_info.h" #include "frameworks/base/cmds/statsd/src/statsd_config.pb.h" #include "guardrail/StatsdStats.h" +#include "logd/LogEvent.h" using android::util::ProtoOutputStream; @@ -93,9 +94,9 @@ bool parseProtoOutputStream(ProtoOutputStream& protoOutput, T* message) { return message->ParseFromArray(pbBytes.c_str(), pbBytes.size()); } -// Checks the blacklist of atoms as well as the blacklisted range of 300,000 - 304,999. +// Checks the truncate timestamp annotation as well as the blacklisted range of 300,000 - 304,999. // Returns the truncated timestamp to the nearest 5 minutes if needed. -int64_t truncateTimestampIfNecessary(int atomId, int64_t timestampNs); +int64_t truncateTimestampIfNecessary(const LogEvent& event); // Checks permission for given pid and uid. bool checkPermissionForIds(const char* permission, pid_t pid, uid_t uid); diff --git a/tools/stats_log_api_gen/atoms_info_writer.cpp b/tools/stats_log_api_gen/atoms_info_writer.cpp index 9261da64f2d5..b33995017bae 100644 --- a/tools/stats_log_api_gen/atoms_info_writer.cpp +++ b/tools/stats_log_api_gen/atoms_info_writer.cpp @@ -27,9 +27,6 @@ namespace stats_log_api_gen { static void write_atoms_info_header_body(FILE* out, const Atoms& atoms) { fprintf(out, "struct AtomsInfo {\n"); - fprintf(out, - " const static std::set<int> " - "kTruncatingTimestampAtomBlackList;\n"); fprintf(out, " const static std::set<int> kAtomsWithAttributionChain;\n"); fprintf(out, " const static std::set<int> kWhitelistedAtoms;\n"); fprintf(out, "};\n"); @@ -37,25 +34,6 @@ static void write_atoms_info_header_body(FILE* out, const Atoms& atoms) { } static void write_atoms_info_cpp_body(FILE* out, const Atoms& atoms) { - std::set<string> kTruncatingAtomNames = {"mobile_radio_power_state_changed", - "audio_state_changed", - "call_state_changed", - "phone_signal_strength_changed", - "mobile_bytes_transfer_by_fg_bg", - "mobile_bytes_transfer"}; - fprintf(out, - "const std::set<int> " - "AtomsInfo::kTruncatingTimestampAtomBlackList = {\n"); - for (AtomDeclSet::const_iterator atomIt = atoms.decls.begin(); atomIt != atoms.decls.end(); - atomIt++) { - if (kTruncatingAtomNames.find((*atomIt)->name) != kTruncatingAtomNames.end()) { - const string constant = make_constant_name((*atomIt)->name); - fprintf(out, " %d, // %s\n", (*atomIt)->code, constant.c_str()); - } - } - - fprintf(out, "};\n"); - fprintf(out, "\n"); fprintf(out, "const std::set<int> AtomsInfo::kAtomsWithAttributionChain = {\n"); for (AtomDeclSet::const_iterator atomIt = atoms.decls.begin(); atomIt != atoms.decls.end(); |