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
inline bool shouldTruncateTimestamp() {
inline bool shouldTruncateTimestamp() const {
return mTruncateTimestamp;
}

View File

@@ -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);

View File

@@ -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.

View File

@@ -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 {

View File

@@ -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();
}
}

View File

@@ -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);

View File

@@ -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();