summaryrefslogtreecommitdiff
path: root/cmds/statsd/src/external/puller_util.cpp
diff options
context:
space:
mode:
authorXin Li <delphij@google.com>2020-09-10 17:22:01 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2020-09-10 17:22:01 +0000
commit8ac6741e47c76bde065f868ea64d2f04541487b9 (patch)
tree1a679458fdbd8d370692d56791e2bf83acee35b5 /cmds/statsd/src/external/puller_util.cpp
parent3de940cc40b1e3fdf8224e18a8308a16768cbfa8 (diff)
parentc64112eb974e9aa7638aead998f07a868acfb5a7 (diff)
Merge "Merge Android R"
Diffstat (limited to 'cmds/statsd/src/external/puller_util.cpp')
-rw-r--r--cmds/statsd/src/external/puller_util.cpp65
1 files changed, 23 insertions, 42 deletions
diff --git a/cmds/statsd/src/external/puller_util.cpp b/cmds/statsd/src/external/puller_util.cpp
index ccfd666573c4..aa99d0082bdd 100644
--- a/cmds/statsd/src/external/puller_util.cpp
+++ b/cmds/statsd/src/external/puller_util.cpp
@@ -17,20 +17,13 @@
#define DEBUG false // STOPSHIP if true
#include "Log.h"
-#include "StatsPullerManager.h"
-#include "atoms_info.h"
#include "puller_util.h"
namespace android {
namespace os {
namespace statsd {
-using std::list;
-using std::map;
-using std::set;
-using std::shared_ptr;
-using std::sort;
-using std::vector;
+using namespace std;
/**
* Process all data and merge isolated with host if necessary.
@@ -54,16 +47,14 @@ using std::vector;
* All atoms should be of the same tagId. All fields should be present.
*/
void mapAndMergeIsolatedUidsToHostUid(vector<shared_ptr<LogEvent>>& data, const sp<UidMap>& uidMap,
- int tagId) {
- if (StatsPullerManager::kAllPullAtomInfo.find(tagId) ==
- StatsPullerManager::kAllPullAtomInfo.end()) {
- VLOG("Unknown pull atom id %d", tagId);
- return;
- }
- if ((android::util::AtomsInfo::kAtomsWithAttributionChain.find(tagId) ==
- android::util::AtomsInfo::kAtomsWithAttributionChain.end()) &&
- (android::util::AtomsInfo::kAtomsWithUidField.find(tagId) ==
- android::util::AtomsInfo::kAtomsWithUidField.end())) {
+ int tagId, const vector<int>& additiveFieldsVec) {
+ // 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.
+ std::pair<int, int> attrIndexRange;
+ const bool hasAttributionChain = data[0]->hasAttributionChain(&attrIndexRange);
+ bool hasUidField = (data[0]->getUidFieldIndex() != -1);
+
+ if (!hasAttributionChain && !hasUidField) {
VLOG("No uid or attribution chain to merge, atom %d", tagId);
return;
}
@@ -74,31 +65,23 @@ void mapAndMergeIsolatedUidsToHostUid(vector<shared_ptr<LogEvent>>& 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()) {
- for (auto& value : *(event->getMutableValues())) {
- if (value.mField.getPosAtDepth(0) > kAttributionField) {
- break;
- }
- if (isAttributionUidField(value)) {
- const int hostUid = uidMap->getHostUidOrSelf(value.mValue.int_value);
- value.mValue.setInt(hostUid);
+ if (hasAttributionChain) {
+ vector<FieldValue>* const fieldValues = event->getMutableValues();
+ for (int i = attrIndexRange.first; i <= attrIndexRange.second; i++) {
+ FieldValue& fieldValue = fieldValues->at(i);
+ if (isAttributionUidField(fieldValue)) {
+ const int hostUid = uidMap->getHostUidOrSelf(fieldValue.mValue.int_value);
+ fieldValue.mValue.setInt(hostUid);
}
}
} else {
- auto it = android::util::AtomsInfo::kAtomsWithUidField.find(tagId);
- if (it != android::util::AtomsInfo::kAtomsWithUidField.end()) {
- int uidField = it->second; // uidField is the field number in proto,
- // starting from 1
- if (uidField > 0 && (int)event->getValues().size() >= uidField &&
- (event->getValues())[uidField - 1].mValue.getType() == INT) {
- Value& value = (*event->getMutableValues())[uidField - 1].mValue;
- const int hostUid = uidMap->getHostUidOrSelf(value.int_value);
- value.setInt(hostUid);
- } else {
- ALOGE("Malformed log, uid not found. %s", event->ToString().c_str());
- return;
- }
+ int uidFieldIndex = event->getUidFieldIndex();
+ if (uidFieldIndex != -1) {
+ Value& value = (*event->getMutableValues())[uidFieldIndex].mValue;
+ const int hostUid = uidMap->getHostUidOrSelf(value.int_value);
+ value.setInt(hostUid);
+ } else {
+ ALOGE("Malformed log, uid not found. %s", event->ToString().c_str());
}
}
}
@@ -120,8 +103,6 @@ void mapAndMergeIsolatedUidsToHostUid(vector<shared_ptr<LogEvent>>& data, const
});
vector<shared_ptr<LogEvent>> mergedData;
- const vector<int>& additiveFieldsVec =
- StatsPullerManager::kAllPullAtomInfo.find(tagId)->second.additiveFields;
const set<int> additiveFields(additiveFieldsVec.begin(), additiveFieldsVec.end());
bool needMerge = true;