Loading cmds/statsd/src/FieldValue.h +11 −4 Original line number Original line Diff line number Diff line Loading @@ -181,6 +181,7 @@ public: return false; return false; } } bool matches(const Matcher& that) const; bool matches(const Matcher& that) const; }; }; Loading Loading @@ -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. Loading @@ -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); } Loading @@ -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) { Loading @@ -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; }; }; /** /** Loading cmds/statsd/src/HashableDimensionKey.cpp +17 −0 Original line number Original line Diff line number Diff line Loading @@ -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) { Loading cmds/statsd/src/HashableDimensionKey.h +12 −0 Original line number Original line Diff line number Diff line Loading @@ -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. * * Loading cmds/statsd/src/logd/LogEvent.cpp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -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) { Loading cmds/statsd/src/logd/LogEvent.h +15 −0 Original line number Original line Diff line number Diff line Loading @@ -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); } } Loading Loading @@ -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 Loading
cmds/statsd/src/FieldValue.h +11 −4 Original line number Original line Diff line number Diff line Loading @@ -181,6 +181,7 @@ public: return false; return false; } } bool matches(const Matcher& that) const; bool matches(const Matcher& that) const; }; }; Loading Loading @@ -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. Loading @@ -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); } Loading @@ -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) { Loading @@ -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; }; }; /** /** Loading
cmds/statsd/src/HashableDimensionKey.cpp +17 −0 Original line number Original line Diff line number Diff line Loading @@ -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) { Loading
cmds/statsd/src/HashableDimensionKey.h +12 −0 Original line number Original line Diff line number Diff line Loading @@ -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. * * Loading
cmds/statsd/src/logd/LogEvent.cpp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -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) { Loading
cmds/statsd/src/logd/LogEvent.h +15 −0 Original line number Original line Diff line number Diff line Loading @@ -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); } } Loading Loading @@ -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