Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ffa34f05 authored by Ruchir Rastogi's avatar Ruchir Rastogi
Browse files

Remove kAtomsWithUidField from atoms_info

Instead of using the map from atoms_info, we now receive uid information
in the form of StatsEvent annotations. The isUid annotation is exposed
from both LogEvent and FieldValue.

Test: bit statsd_test:*
Test: atest GtsStatsdHostTestCases
Bug: 150414601
Change-Id: Iebbe4ce5668de1ab91485daa1be9197cde6e8309
parent 288c434f
Loading
Loading
Loading
Loading
+5 −13
Original line number Diff line number Diff line
@@ -120,9 +120,9 @@ bool isAttributionUidField(const FieldValue& value) {
}

int32_t getUidIfExists(const FieldValue& value) {
    // the field is uid field if the field is the uid field in attribution node or marked as
    // is_uid in atoms.proto
    bool isUid = isAttributionUidField(value) || isUidField(value.mField, value.mValue);
    // the field is uid field if the field is the uid field in attribution node
    // or annotated as such in the atom
    bool isUid = isAttributionUidField(value) || isUidField(value);
    return isUid ? value.mValue.int_value : -1;
}

@@ -134,16 +134,8 @@ bool isAttributionUidField(const Field& field, const Value& value) {
    return false;
}

bool isUidField(const Field& field, const Value& value) {
    auto it = android::util::AtomsInfo::kAtomsWithUidField.find(field.getTag());

    if (it != android::util::AtomsInfo::kAtomsWithUidField.end()) {
        int uidField = it->second;  // uidField is the field number in proto
        return field.getDepth() == 0 && field.getPosAtDepth(0) == uidField &&
               value.getType() == INT;
    }

    return false;
bool isUidField(const FieldValue& fieldValue) {
    return fieldValue.mAnnotations.isUidField();
}

Value::Value(const Value& from) {
+9 −3
Original line number Diff line number Diff line
@@ -367,7 +367,8 @@ public:
    enum {
        NESTED_POS = 0x0,
        PRIMARY_POS = 0x1,
        EXCLUSIVE_POS = 0x2
        EXCLUSIVE_POS = 0x2,
        UID_POS = 0x3
    };

    inline void setNested(bool nested) { setBitmaskAtPos(NESTED_POS, nested); }
@@ -376,6 +377,8 @@ public:

    inline void setExclusiveState(bool exclusive) { setBitmaskAtPos(EXCLUSIVE_POS, exclusive); }

    inline void setUidField(bool isUid) { setBitmaskAtPos(UID_POS, isUid); }

    inline void setResetState(int resetState) { mResetState = resetState; }

    // Default value = false
@@ -387,6 +390,9 @@ public:
    // Default value = false
    inline bool isExclusiveState() const { return getValueFromBitmask(EXCLUSIVE_POS); }

    // Default value = false
    inline bool isUidField() const { return getValueFromBitmask(UID_POS); }

    // If a reset state is not sent in the StatsEvent, returns -1. Note that a
    // reset satate is only sent if and only if a reset should be triggered.
    inline int getResetState() const { return mResetState; }
@@ -402,7 +408,7 @@ private:
    }

    // This is a bitmask over all annotations stored in boolean form. Because
    // there are only 3 booleans, just one byte is required.
    // there are only 4 booleans, just one byte is required.
    uint8_t mBooleanBitmask = 0;

    int mResetState = -1;
@@ -449,7 +455,7 @@ int getUidIfExists(const FieldValue& value);
void translateFieldMatcher(const FieldMatcher& matcher, std::vector<Matcher>* output);

bool isAttributionUidField(const Field& field, const Value& value);
bool isUidField(const Field& field, const Value& value);
bool isUidField(const FieldValue& fieldValue);

bool equalDimensions(const std::vector<Matcher>& dimension_a,
                     const std::vector<Matcher>& dimension_b);
+6 −20
Original line number Diff line number Diff line
@@ -138,13 +138,6 @@ void StatsLogProcessor::onPeriodicAlarmFired(
    }
}

void updateUid(Value* value, int hostUid) {
    int uid = value->int_value;
    if (uid != hostUid) {
        value->setInt(hostUid);
    }
}

void StatsLogProcessor::mapIsolatedUidToHostUidIfNecessaryLocked(LogEvent* event) const {
    if (android::util::AtomsInfo::kAtomsWithAttributionChain.find(event->GetTagId()) !=
        android::util::AtomsInfo::kAtomsWithAttributionChain.end()) {
@@ -154,22 +147,15 @@ void StatsLogProcessor::mapIsolatedUidToHostUidIfNecessaryLocked(LogEvent* event
            }
            if (isAttributionUidField(value)) {
                const int hostUid = mUidMap->getHostUidOrSelf(value.mValue.int_value);
                updateUid(&value.mValue, hostUid);
                value.mValue.setInt(hostUid);
            }
        }
    } else {
        auto it = android::util::AtomsInfo::kAtomsWithUidField.find(event->GetTagId());
        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;
        int uidFieldIndex = event->getUidFieldIndex();
        if (uidFieldIndex != -1) {
           Value& value = (*event->getMutableValues())[uidFieldIndex].mValue;
           const int hostUid = mUidMap->getHostUidOrSelf(value.int_value);
                updateUid(&value, hostUid);
            } else {
                ALOGE("Malformed log, uid not found. %s", event->ToString().c_str());
            }
           value.setInt(hostUid);
        }
    }
}
+15 −17
Original line number Diff line number Diff line
@@ -49,10 +49,14 @@ using namespace std;
 */
void mapAndMergeIsolatedUidsToHostUid(vector<shared_ptr<LogEvent>>& data, const sp<UidMap>& uidMap,
                                      int tagId, const vector<int>& additiveFieldsVec) {
    if ((android::util::AtomsInfo::kAtomsWithAttributionChain.find(tagId) ==
         android::util::AtomsInfo::kAtomsWithAttributionChain.end()) &&
        (android::util::AtomsInfo::kAtomsWithUidField.find(tagId) ==
         android::util::AtomsInfo::kAtomsWithUidField.end())) {
    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.
    bool hasUidField = (data[0]->getUidFieldIndex() != -1);

    if (!hasAttributionChain && !hasUidField) {
        VLOG("No uid or attribution chain to merge, atom %d", tagId);
        return;
    }
@@ -75,19 +79,13 @@ void mapAndMergeIsolatedUidsToHostUid(vector<shared_ptr<LogEvent>>& data, const
                }
            }
        } 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;
            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());
                    return;
                }
            }
        }
    }
+7 −1
Original line number Diff line number Diff line
@@ -240,14 +240,20 @@ void LogEvent::parseAttributionChain(int32_t* pos, int32_t depth, bool* last,
    last[1] = last[2] = false;
}

// Assumes that mValues is not empty
bool LogEvent::checkPreviousValueType(Type expected) {
    return mValues[mValues.size() - 1].mValue.getType() == expected;
}

void LogEvent::parseIsUidAnnotation(uint8_t annotationType) {
    if (mValues.empty() || annotationType != BOOL_TYPE) {
    if (mValues.empty() || !checkPreviousValueType(INT) || annotationType != BOOL_TYPE) {
        mValid = false;
        return;
    }

    bool isUid = readNextValue<uint8_t>();
    if (isUid) mUidFieldIndex = mValues.size() - 1;
    mValues[mValues.size() - 1].mAnnotations.setUidField(isUid);
}

void LogEvent::parseTruncateTimestampAnnotation(uint8_t annotationType) {
Loading