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

Commit bfc4bdb5 authored by Muhammad Qureshi's avatar Muhammad Qureshi
Browse files

Remove kStateAtomsInfo from atoms_info.

Use the annotation information in LogEvent/FieldValue instead.

- Initialize nested to true in FieldValue.mAnnotations

- Add filterPrimaryKey function to HashableDimensionKey for populating a
HashableDimensionKey with all FieldValues that have the primary key
annotation set.

- Create StateTrackers without checking if atom is a state atom. (We
  can't do this check anymore)

- Remove mAtomId, mStateField, mNested, mPrimaryFields, mDefaultState,
    mResetState members from StateTracker. Use the information passed in
    LogEvent in onLogEvent instead.

- Update tests to log annotations when logging events.

- Remote kStateAtomsFieldOptions from atoms_info.

- Make MetricProducer::mStateGroupMap const

- Rename handlePartialReset to clearStateForPrimaryKey

- Store "default" states in mStateMap. An entry in mStateMap means the
state is not kStateUnknown. Before, an entry in mStateMap meant the
state is not the "default" state.

- Consolidate all state change logic in updateStateForPrimaryKey()
    - remote StateTracker::updateState
    - handleReset and clearStateForPrimaryKey call
    updateStateForPrimaryKey for resetting and clearing of states
    respectively.

- Create a helper method for notifying StateTracker listeners

- Make StateManager::registerListener void

Bug: 151110842
Test: bit statsd_test:*
Change-Id: Ifb8371b213a178fcccaa484086fbdd283dbaec49
parent bba1891e
Loading
Loading
Loading
Loading
+11 −4
Original line number Original line Diff line number Diff line
@@ -181,6 +181,7 @@ public:


        return false;
        return false;
    }
    }

    bool matches(const Matcher& that) const;
    bool matches(const Matcher& that) const;
};
};


@@ -360,7 +361,9 @@ struct Value {


class Annotations {
class Annotations {
public:
public:
    Annotations() {}
    Annotations() {
        setNested(true);  // Nested = true by default
    }


    // This enum stores where particular annotations can be found in the
    // This enum stores where particular annotations can be found in the
    // bitmask. Note that these pos do not correspond to annotation ids.
    // bitmask. Note that these pos do not correspond to annotation ids.
@@ -379,7 +382,9 @@ public:


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


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


    // Default value = false
    // Default value = false
    inline bool isNested() const { return getValueFromBitmask(NESTED_POS); }
    inline bool isNested() const { return getValueFromBitmask(NESTED_POS); }
@@ -395,7 +400,9 @@ public:


    // 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 int32_t getResetState() const {
        return mResetState;
    }


private:
private:
    inline void setBitmaskAtPos(int pos, bool value) {
    inline void setBitmaskAtPos(int pos, bool value) {
@@ -411,7 +418,7 @@ private:
    // there are only 4 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;
    int32_t mResetState = -1;
};
};


/**
/**
+17 −0
Original line number Original line Diff line number Diff line
@@ -180,6 +180,23 @@ bool filterValues(const vector<Matcher>& matcherFields, const vector<FieldValue>
    return num_matches > 0;
    return num_matches > 0;
}
}


bool filterPrimaryKey(const std::vector<FieldValue>& values, HashableDimensionKey* output) {
    size_t num_matches = 0;
    const int32_t simpleFieldMask = 0xff7f0000;
    const int32_t attributionUidFieldMask = 0xff7f7f7f;
    for (const auto& value : values) {
        if (value.mAnnotations.isPrimaryField()) {
            output->addValue(value);
            output->mutableValue(num_matches)->mField.setTag(value.mField.getTag());
            const int32_t mask =
                    isAttributionUidField(value) ? attributionUidFieldMask : simpleFieldMask;
            output->mutableValue(num_matches)->mField.setField(value.mField.getField() & mask);
            num_matches++;
        }
    }
    return num_matches > 0;
}

void filterGaugeValues(const std::vector<Matcher>& matcherFields,
void filterGaugeValues(const std::vector<Matcher>& matcherFields,
                       const std::vector<FieldValue>& values, std::vector<FieldValue>* output) {
                       const std::vector<FieldValue>& values, std::vector<FieldValue>* output) {
    for (const auto& field : matcherFields) {
    for (const auto& field : matcherFields) {
+12 −0
Original line number Original line Diff line number Diff line
@@ -153,6 +153,18 @@ bool filterValues(const Matcher& matcherField, const std::vector<FieldValue>& va
bool filterValues(const std::vector<Matcher>& matcherFields, const std::vector<FieldValue>& values,
bool filterValues(const std::vector<Matcher>& matcherFields, const std::vector<FieldValue>& values,
                  HashableDimensionKey* output);
                  HashableDimensionKey* output);


/**
 * Creating HashableDimensionKeys from State Primary Keys in FieldValues.
 *
 * This function may make modifications to the Field if the matcher has Position=FIRST,LAST or ALL
 * in it. This is because: for example, when we create dimension from last uid in attribution chain,
 * In one event, uid 1000 is at position 5 and it's the last
 * In another event, uid 1000 is at position 6, and it's the last
 * these 2 events should be mapped to the same dimension.  So we will remove the original position
 * from the dimension key for the uid field (by applying 0x80 bit mask).
 */
bool filterPrimaryKey(const std::vector<FieldValue>& values, HashableDimensionKey* output);

/**
/**
 * Filter the values from FieldValues using the matchers.
 * Filter the values from FieldValues using the matchers.
 *
 *
+2 −1
Original line number Original line Diff line number Diff line
@@ -293,7 +293,8 @@ void LogEvent::parseExclusiveStateAnnotation(uint8_t annotationType) {
    }
    }


    const bool exclusiveState = readNextValue<uint8_t>();
    const bool exclusiveState = readNextValue<uint8_t>();
    mValues[mValues.size() - 1].mAnnotations.setExclusiveState(exclusiveState);
    mExclusiveStateFieldIndex = mValues.size() - 1;
    mValues[getExclusiveStateFieldIndex()].mAnnotations.setExclusiveState(exclusiveState);
}
}


void LogEvent::parseTriggerStateResetAnnotation(uint8_t annotationType) {
void LogEvent::parseTriggerStateResetAnnotation(uint8_t annotationType) {
+15 −0
Original line number Original line Diff line number Diff line
@@ -170,6 +170,20 @@ public:
        return mAttributionChainIndex;
        return mAttributionChainIndex;
    }
    }


    // Returns the index of the exclusive state field within the FieldValues vector if
    // an exclusive state exists. If there is no exclusive state field, returns -1.
    //
    // If the index within the atom definition is desired, do the following:
    //    int vectorIndex = LogEvent.getExclusiveStateFieldIndex();
    //    if (vectorIndex != -1) {
    //        FieldValue& v = LogEvent.getValues()[vectorIndex];
    //        int atomIndex = v.mField.getPosAtDepth(0);
    //    }
    // Note that atomIndex is 1-indexed.
    inline int getExclusiveStateFieldIndex() const {
        return mExclusiveStateFieldIndex;
    }

    inline LogEvent makeCopy() {
    inline LogEvent makeCopy() {
        return LogEvent(*this);
        return LogEvent(*this);
    }
    }
@@ -297,6 +311,7 @@ private:
    bool mTruncateTimestamp = false;
    bool mTruncateTimestamp = false;
    int mUidFieldIndex = -1;
    int mUidFieldIndex = -1;
    int mAttributionChainIndex = -1;
    int mAttributionChainIndex = -1;
    int mExclusiveStateFieldIndex = -1;
};
};


void writeExperimentIdsToProto(const std::vector<int64_t>& experimentIds, std::vector<uint8_t>* protoOut);
void writeExperimentIdsToProto(const std::vector<int64_t>& experimentIds, std::vector<uint8_t>* protoOut);
Loading