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

Commit 44f8814b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Remove kAtomsWithUidField from atoms_info" into rvc-dev am: 04d2f143...

Merge "Remove kAtomsWithUidField from atoms_info" into rvc-dev am: 04d2f143 am: 52131232 am: 81ce5f29

Change-Id: I7c80322437a94690af636bfb471f4ca2a7f2fa86
parents 3fb9fb0e 81ce5f29
Loading
Loading
Loading
Loading
+5 −13
Original line number Original line Diff line number Diff line
@@ -120,9 +120,9 @@ bool isAttributionUidField(const FieldValue& value) {
}
}


int32_t getUidIfExists(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
    // the field is uid field if the field is the uid field in attribution node
    // is_uid in atoms.proto
    // or annotated as such in the atom
    bool isUid = isAttributionUidField(value) || isUidField(value.mField, value.mValue);
    bool isUid = isAttributionUidField(value) || isUidField(value);
    return isUid ? value.mValue.int_value : -1;
    return isUid ? value.mValue.int_value : -1;
}
}


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


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

    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;
}
}


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


    inline void setNested(bool nested) { setBitmaskAtPos(NESTED_POS, nested); }
    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 setExclusiveState(bool exclusive) { setBitmaskAtPos(EXCLUSIVE_POS, exclusive); }


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

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


    // Default value = false
    // Default value = false
@@ -387,6 +390,9 @@ public:
    // Default value = false
    // Default value = false
    inline bool isExclusiveState() const { return getValueFromBitmask(EXCLUSIVE_POS); }
    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
    // 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.
    // reset satate is only sent if and only if a reset should be triggered.
    inline int getResetState() const { return mResetState; }
    inline int getResetState() const { return mResetState; }
@@ -402,7 +408,7 @@ private:
    }
    }


    // This is a bitmask over all annotations stored in boolean form. Because
    // 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;
    uint8_t mBooleanBitmask = 0;


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


bool isAttributionUidField(const Field& field, const Value& value);
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,
bool equalDimensions(const std::vector<Matcher>& dimension_a,
                     const std::vector<Matcher>& dimension_b);
                     const std::vector<Matcher>& dimension_b);
+6 −20
Original line number Original line 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 {
void StatsLogProcessor::mapIsolatedUidToHostUidIfNecessaryLocked(LogEvent* event) const {
    if (android::util::AtomsInfo::kAtomsWithAttributionChain.find(event->GetTagId()) !=
    if (android::util::AtomsInfo::kAtomsWithAttributionChain.find(event->GetTagId()) !=
        android::util::AtomsInfo::kAtomsWithAttributionChain.end()) {
        android::util::AtomsInfo::kAtomsWithAttributionChain.end()) {
@@ -154,22 +147,15 @@ void StatsLogProcessor::mapIsolatedUidToHostUidIfNecessaryLocked(LogEvent* event
            }
            }
            if (isAttributionUidField(value)) {
            if (isAttributionUidField(value)) {
                const int hostUid = mUidMap->getHostUidOrSelf(value.mValue.int_value);
                const int hostUid = mUidMap->getHostUidOrSelf(value.mValue.int_value);
                updateUid(&value.mValue, hostUid);
                value.mValue.setInt(hostUid);
            }
            }
        }
        }
    } else {
    } else {
        auto it = android::util::AtomsInfo::kAtomsWithUidField.find(event->GetTagId());
        int uidFieldIndex = event->getUidFieldIndex();
        if (it != android::util::AtomsInfo::kAtomsWithUidField.end()) {
        if (uidFieldIndex != -1) {
            int uidField = it->second;  // uidField is the field number in proto,
           Value& value = (*event->getMutableValues())[uidFieldIndex].mValue;
                                        // 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 = mUidMap->getHostUidOrSelf(value.int_value);
           const int hostUid = mUidMap->getHostUidOrSelf(value.int_value);
                updateUid(&value, hostUid);
           value.setInt(hostUid);
            } else {
                ALOGE("Malformed log, uid not found. %s", event->ToString().c_str());
            }
        }
        }
    }
    }
}
}
+15 −17
Original line number Original line Diff line number Diff line
@@ -49,10 +49,14 @@ using namespace std;
 */
 */
void mapAndMergeIsolatedUidsToHostUid(vector<shared_ptr<LogEvent>>& data, const sp<UidMap>& uidMap,
void mapAndMergeIsolatedUidsToHostUid(vector<shared_ptr<LogEvent>>& data, const sp<UidMap>& uidMap,
                                      int tagId, const vector<int>& additiveFieldsVec) {
                                      int tagId, const vector<int>& additiveFieldsVec) {
    if ((android::util::AtomsInfo::kAtomsWithAttributionChain.find(tagId) ==
    bool hasAttributionChain = (android::util::AtomsInfo::kAtomsWithAttributionChain.find(tagId) !=
         android::util::AtomsInfo::kAtomsWithAttributionChain.end()) &&
                                android::util::AtomsInfo::kAtomsWithAttributionChain.end());
        (android::util::AtomsInfo::kAtomsWithUidField.find(tagId) ==
    // To check if any LogEvent has a uid field, we can just check the first
         android::util::AtomsInfo::kAtomsWithUidField.end())) {
    // 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);
        VLOG("No uid or attribution chain to merge, atom %d", tagId);
        return;
        return;
    }
    }
@@ -75,19 +79,13 @@ void mapAndMergeIsolatedUidsToHostUid(vector<shared_ptr<LogEvent>>& data, const
                }
                }
            }
            }
        } else {
        } else {
            auto it = android::util::AtomsInfo::kAtomsWithUidField.find(tagId);
            int uidFieldIndex = event->getUidFieldIndex();
            if (it != android::util::AtomsInfo::kAtomsWithUidField.end()) {
            if (uidFieldIndex != -1) {
                int uidField = it->second;  // uidField is the field number in proto,
                Value& value = (*event->getMutableValues())[uidFieldIndex].mValue;
                // 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);
                const int hostUid = uidMap->getHostUidOrSelf(value.int_value);
                value.setInt(hostUid);
                value.setInt(hostUid);
            } else {
            } else {
                ALOGE("Malformed log, uid not found. %s", event->ToString().c_str());
                ALOGE("Malformed log, uid not found. %s", event->ToString().c_str());
                    return;
                }
            }
            }
        }
        }
    }
    }
+7 −1
Original line number Original line 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;
    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) {
void LogEvent::parseIsUidAnnotation(uint8_t annotationType) {
    if (mValues.empty() || annotationType != BOOL_TYPE) {
    if (mValues.empty() || !checkPreviousValueType(INT) || annotationType != BOOL_TYPE) {
        mValid = false;
        mValid = false;
        return;
        return;
    }
    }


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


void LogEvent::parseTruncateTimestampAnnotation(uint8_t annotationType) {
void LogEvent::parseTruncateTimestampAnnotation(uint8_t annotationType) {
Loading