From 7fee54bb27e127a3afddfb3a3e81ab415c63bee5 Mon Sep 17 00:00:00 2001 From: Muhammad Qureshi Date: Tue, 14 Apr 2020 22:38:37 -0700 Subject: [PATCH] Remove kAtomsWithAttributionChain from atoms_info Use LogEvent::getAttributionChainIndex() to check presence of attribution chains Bug: 150414252 Test: bit statsd_test:* Change-Id: Ic798d3b182c2b5aaf73444f2796d539cd3f7bf40 --- cmds/statsd/src/StatsLogProcessor.cpp | 3 +-- cmds/statsd/src/external/puller_util.cpp | 11 ++++------- tools/stats_log_api_gen/atoms_info_writer.cpp | 17 ----------------- 3 files changed, 5 insertions(+), 26 deletions(-) diff --git a/cmds/statsd/src/StatsLogProcessor.cpp b/cmds/statsd/src/StatsLogProcessor.cpp index 325cbc7e80e59..d914ab2436c7c 100644 --- a/cmds/statsd/src/StatsLogProcessor.cpp +++ b/cmds/statsd/src/StatsLogProcessor.cpp @@ -139,8 +139,7 @@ void StatsLogProcessor::onPeriodicAlarmFired( } void StatsLogProcessor::mapIsolatedUidToHostUidIfNecessaryLocked(LogEvent* event) const { - if (android::util::AtomsInfo::kAtomsWithAttributionChain.find(event->GetTagId()) != - android::util::AtomsInfo::kAtomsWithAttributionChain.end()) { + if (event->getAttributionChainIndex() != -1) { for (auto& value : *(event->getMutableValues())) { if (value.mField.getPosAtDepth(0) > kAttributionField) { break; diff --git a/cmds/statsd/src/external/puller_util.cpp b/cmds/statsd/src/external/puller_util.cpp index 90247cf9d68ca..9e72a23d27f43 100644 --- a/cmds/statsd/src/external/puller_util.cpp +++ b/cmds/statsd/src/external/puller_util.cpp @@ -49,11 +49,9 @@ using namespace std; */ void mapAndMergeIsolatedUidsToHostUid(vector>& data, const sp& uidMap, int tagId, const vector& additiveFieldsVec) { - bool hasAttributionChain = (android::util::AtomsInfo::kAtomsWithAttributionChain.find(tagId) != - android::util::AtomsInfo::kAtomsWithAttributionChain.end()); - // To check if any LogEvent has a uid field, we can just check the first - // LogEvent because all atoms with this tagId should have the uid - // annotation. + // Check the first LogEvent for attribution chain or a uid field as either all atoms with this + // tagId have them or none of them do. + const bool hasAttributionChain = data[0]->getAttributionChainIndex() != -1; bool hasUidField = (data[0]->getUidFieldIndex() != -1); if (!hasAttributionChain && !hasUidField) { @@ -67,8 +65,7 @@ void mapAndMergeIsolatedUidsToHostUid(vector>& data, const ALOGE("Wrong atom. Expecting %d, got %d", tagId, event->GetTagId()); return; } - if (android::util::AtomsInfo::kAtomsWithAttributionChain.find(tagId) != - android::util::AtomsInfo::kAtomsWithAttributionChain.end()) { + if (event->getAttributionChainIndex() != -1) { for (auto& value : *(event->getMutableValues())) { if (value.mField.getPosAtDepth(0) > kAttributionField) { break; diff --git a/tools/stats_log_api_gen/atoms_info_writer.cpp b/tools/stats_log_api_gen/atoms_info_writer.cpp index b33995017bae5..2b2cf677922b0 100644 --- a/tools/stats_log_api_gen/atoms_info_writer.cpp +++ b/tools/stats_log_api_gen/atoms_info_writer.cpp @@ -27,7 +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 kAtomsWithAttributionChain;\n"); fprintf(out, " const static std::set kWhitelistedAtoms;\n"); fprintf(out, "};\n"); fprintf(out, "const static int kMaxPushedAtomId = %d;\n\n", atoms.maxPushedAtomId); @@ -35,22 +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) { - fprintf(out, "const std::set AtomsInfo::kAtomsWithAttributionChain = {\n"); - for (AtomDeclSet::const_iterator atomIt = atoms.decls.begin(); atomIt != atoms.decls.end(); - atomIt++) { - for (vector::const_iterator field = (*atomIt)->fields.begin(); - field != (*atomIt)->fields.end(); field++) { - if (field->javaType == JAVA_TYPE_ATTRIBUTION_CHAIN) { - const string constant = make_constant_name((*atomIt)->name); - fprintf(out, " %d, // %s\n", (*atomIt)->code, constant.c_str()); - break; - } - } - } - - fprintf(out, "};\n"); - fprintf(out, "\n"); - fprintf(out, "const std::set AtomsInfo::kWhitelistedAtoms = {\n"); for (AtomDeclSet::const_iterator atomIt = atoms.decls.begin(); atomIt != atoms.decls.end(); atomIt++) {