Merge "Remove kTruncatingTimestampAtomBlackList" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-04-16 13:07:00 +00:00
committed by Android (Google) Code Review
7 changed files with 20 additions and 43 deletions

View File

@@ -145,7 +145,7 @@ public:
} }
// Default value = false // Default value = false
inline bool shouldTruncateTimestamp() { inline bool shouldTruncateTimestamp() const {
return mTruncateTimestamp; return mTruncateTimestamp;
} }

View File

@@ -151,8 +151,7 @@ void EventMetricProducer::onMatchedLogEventInternalLocked(
uint64_t wrapperToken = uint64_t wrapperToken =
mProto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_DATA); mProto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_DATA);
const int64_t elapsedTimeNs = truncateTimestampIfNecessary( const int64_t elapsedTimeNs = truncateTimestampIfNecessary(event);
event.GetTagId(), event.GetElapsedTimestampNs());
mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS, (long long) elapsedTimeNs); mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS, (long long) elapsedTimeNs);
uint64_t eventToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_ID_ATOMS); uint64_t eventToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_ID_ATOMS);

View File

@@ -270,11 +270,9 @@ void GaugeMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs,
protoOutput->end(atomsToken); protoOutput->end(atomsToken);
} }
for (const auto& atom : bucket.mGaugeAtoms) { for (const auto& atom : bucket.mGaugeAtoms) {
const int64_t elapsedTimestampNs = protoOutput->write(FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED |
truncateTimestampIfNecessary(mAtomId, atom.mElapsedTimestamps); FIELD_ID_ELAPSED_ATOM_TIMESTAMP,
protoOutput->write( (long long)atom.mElapsedTimestampNs);
FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED | FIELD_ID_ELAPSED_ATOM_TIMESTAMP,
(long long)elapsedTimestampNs);
} }
} }
protoOutput->end(bucketInfoToken); protoOutput->end(bucketInfoToken);
@@ -477,7 +475,9 @@ void GaugeMetricProducer::onMatchedLogEventInternalLocked(
if ((*mCurrentSlicedBucket)[eventKey].size() >= mGaugeAtomsPerDimensionLimit) { if ((*mCurrentSlicedBucket)[eventKey].size() >= mGaugeAtomsPerDimensionLimit) {
return; return;
} }
GaugeAtom gaugeAtom(getGaugeFields(event), eventTimeNs);
const int64_t truncatedElapsedTimestampNs = truncateTimestampIfNecessary(event);
GaugeAtom gaugeAtom(getGaugeFields(event), truncatedElapsedTimestampNs);
(*mCurrentSlicedBucket)[eventKey].push_back(gaugeAtom); (*mCurrentSlicedBucket)[eventKey].push_back(gaugeAtom);
// Anomaly detection on gauge metric only works when there is one numeric // Anomaly detection on gauge metric only works when there is one numeric
// field specified. // field specified.

View File

@@ -35,10 +35,10 @@ namespace statsd {
struct GaugeAtom { struct GaugeAtom {
GaugeAtom(std::shared_ptr<vector<FieldValue>> fields, int64_t elapsedTimeNs) GaugeAtom(std::shared_ptr<vector<FieldValue>> fields, int64_t elapsedTimeNs)
: mFields(fields), mElapsedTimestamps(elapsedTimeNs) { : mFields(fields), mElapsedTimestampNs(elapsedTimeNs) {
} }
std::shared_ptr<vector<FieldValue>> mFields; std::shared_ptr<vector<FieldValue>> mFields;
int64_t mElapsedTimestamps; int64_t mElapsedTimestampNs;
}; };
struct GaugeBucket { struct GaugeBucket {

View File

@@ -549,14 +549,13 @@ int64_t getWallClockMillis() {
return time(nullptr) * MS_PER_SEC; return time(nullptr) * MS_PER_SEC;
} }
int64_t truncateTimestampIfNecessary(int atomId, int64_t timestampNs) { int64_t truncateTimestampIfNecessary(const LogEvent& event) {
if (AtomsInfo::kTruncatingTimestampAtomBlackList.find(atomId) != if (event.shouldTruncateTimestamp() ||
AtomsInfo::kTruncatingTimestampAtomBlackList.end() || (event.GetTagId() >= StatsdStats::kTimestampTruncationStartTag &&
(atomId >= StatsdStats::kTimestampTruncationStartTag && event.GetTagId() <= StatsdStats::kTimestampTruncationEndTag)) {
atomId <= StatsdStats::kTimestampTruncationEndTag)) { return event.GetElapsedTimestampNs() / NS_PER_SEC / (5 * 60) * NS_PER_SEC * (5 * 60);
return timestampNs / NS_PER_SEC / (5 * 60) * NS_PER_SEC * (5 * 60);
} else { } else {
return timestampNs; return event.GetElapsedTimestampNs();
} }
} }

View File

@@ -17,11 +17,12 @@
#pragma once #pragma once
#include <android/util/ProtoOutputStream.h> #include <android/util/ProtoOutputStream.h>
#include "FieldValue.h" #include "FieldValue.h"
#include "HashableDimensionKey.h" #include "HashableDimensionKey.h"
#include "atoms_info.h"
#include "frameworks/base/cmds/statsd/src/statsd_config.pb.h" #include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
#include "guardrail/StatsdStats.h" #include "guardrail/StatsdStats.h"
#include "logd/LogEvent.h"
using android::util::ProtoOutputStream; using android::util::ProtoOutputStream;
@@ -93,9 +94,9 @@ bool parseProtoOutputStream(ProtoOutputStream& protoOutput, T* message) {
return message->ParseFromArray(pbBytes.c_str(), pbBytes.size()); 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. // 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. // Checks permission for given pid and uid.
bool checkPermissionForIds(const char* permission, pid_t pid, uid_t uid); bool checkPermissionForIds(const char* permission, pid_t pid, uid_t uid);

View File

@@ -27,9 +27,6 @@ namespace stats_log_api_gen {
static void write_atoms_info_header_body(FILE* out, const Atoms& atoms) { static void write_atoms_info_header_body(FILE* out, const Atoms& atoms) {
fprintf(out, "struct AtomsInfo {\n"); 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> kAtomsWithAttributionChain;\n");
fprintf(out, " const static std::set<int> kWhitelistedAtoms;\n"); fprintf(out, " const static std::set<int> kWhitelistedAtoms;\n");
fprintf(out, "};\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) { 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"); fprintf(out, "const std::set<int> AtomsInfo::kAtomsWithAttributionChain = {\n");
for (AtomDeclSet::const_iterator atomIt = atoms.decls.begin(); atomIt != atoms.decls.end(); for (AtomDeclSet::const_iterator atomIt = atoms.decls.begin(); atomIt != atoms.decls.end();