diff options
Diffstat (limited to 'cmds/statsd/src/HashableDimensionKey.h')
-rw-r--r-- | cmds/statsd/src/HashableDimensionKey.h | 102 |
1 files changed, 84 insertions, 18 deletions
diff --git a/cmds/statsd/src/HashableDimensionKey.h b/cmds/statsd/src/HashableDimensionKey.h index 6f4941f717ee..bd011005a301 100644 --- a/cmds/statsd/src/HashableDimensionKey.h +++ b/cmds/statsd/src/HashableDimensionKey.h @@ -16,17 +16,18 @@ #pragma once +#include <aidl/android/os/StatsDimensionsValueParcel.h> #include <utils/JenkinsHash.h> #include <vector> -#include "FieldValue.h" #include "android-base/stringprintf.h" +#include "FieldValue.h" #include "logd/LogEvent.h" namespace android { namespace os { namespace statsd { -using android::base::StringPrintf; +using ::aidl::android::os::StatsDimensionsValueParcel; struct Metric2Condition { int64_t conditionId; @@ -34,6 +35,12 @@ struct Metric2Condition { std::vector<Matcher> conditionFields; }; +struct Metric2State { + int32_t stateAtomId; + std::vector<Matcher> metricFields; + std::vector<Matcher> stateFields; +}; + class HashableDimensionKey { public: explicit HashableDimensionKey(const std::vector<FieldValue>& values) { @@ -63,8 +70,12 @@ public: return nullptr; } + StatsDimensionsValueParcel toStatsDimensionsValueParcel() const; + std::string toString() const; + bool operator!=(const HashableDimensionKey& that) const; + bool operator==(const HashableDimensionKey& that) const; bool operator<(const HashableDimensionKey& that) const; @@ -76,17 +87,16 @@ private: }; class MetricDimensionKey { - public: +public: explicit MetricDimensionKey(const HashableDimensionKey& dimensionKeyInWhat, - const HashableDimensionKey& dimensionKeyInCondition) - : mDimensionKeyInWhat(dimensionKeyInWhat), - mDimensionKeyInCondition(dimensionKeyInCondition) {}; + const HashableDimensionKey& stateValuesKey) + : mDimensionKeyInWhat(dimensionKeyInWhat), mStateValuesKey(stateValuesKey){}; MetricDimensionKey(){}; MetricDimensionKey(const MetricDimensionKey& that) : mDimensionKeyInWhat(that.getDimensionKeyInWhat()), - mDimensionKeyInCondition(that.getDimensionKeyInCondition()) {}; + mStateValuesKey(that.getStateValuesKey()){}; MetricDimensionKey& operator=(const MetricDimensionKey& from) = default; @@ -96,30 +106,41 @@ class MetricDimensionKey { return mDimensionKeyInWhat; } - inline const HashableDimensionKey& getDimensionKeyInCondition() const { - return mDimensionKeyInCondition; + inline const HashableDimensionKey& getStateValuesKey() const { + return mStateValuesKey; } - inline void setDimensionKeyInCondition(const HashableDimensionKey& key) { - mDimensionKeyInCondition = key; + inline HashableDimensionKey* getMutableStateValuesKey() { + return &mStateValuesKey; } - bool hasDimensionKeyInCondition() const { - return mDimensionKeyInCondition.getValues().size() > 0; + inline void setStateValuesKey(const HashableDimensionKey& key) { + mStateValuesKey = key; + } + + bool hasStateValuesKey() const { + return mStateValuesKey.getValues().size() > 0; } bool operator==(const MetricDimensionKey& that) const; bool operator<(const MetricDimensionKey& that) const; - private: - HashableDimensionKey mDimensionKeyInWhat; - HashableDimensionKey mDimensionKeyInCondition; +private: + HashableDimensionKey mDimensionKeyInWhat; + HashableDimensionKey mStateValuesKey; }; android::hash_t hashDimension(const HashableDimensionKey& key); /** + * Returns true if a FieldValue field matches the matcher field. + * The value of the FieldValue is output. + */ +bool filterValues(const Matcher& matcherField, const std::vector<FieldValue>& values, + FieldValue* output); + +/** * Creating HashableDimensionKeys from FieldValues using matcher. * * This function may make modifications to the Field if the matcher has Position=FIRST,LAST or ALL @@ -133,6 +154,18 @@ bool filterValues(const std::vector<Matcher>& matcherFields, const std::vector<F 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. * * In contrast to the above function, this function will not do any modification to the original @@ -145,6 +178,39 @@ void getDimensionForCondition(const std::vector<FieldValue>& eventValues, const Metric2Condition& links, HashableDimensionKey* conditionDimension); +/** + * Get dimension values using metric's "what" fields and fill statePrimaryKey's + * mField information using "state" fields. + */ +void getDimensionForState(const std::vector<FieldValue>& eventValues, const Metric2State& link, + HashableDimensionKey* statePrimaryKey); + +/** + * Returns true if the primaryKey values are a subset of the whatKey values. + * The values from the primaryKey come from the state atom, so we need to + * check that a link exists between the state atom field and what atom field. + * + * Example: + * whatKey = [Atom: 10, {uid: 1005, wakelock_name: "compose"}] + * statePrimaryKey = [Atom: 27, {uid: 1005}] + * Returns true IF one of the Metric2State links Atom 10's uid to Atom 27's uid + * + * Example: + * whatKey = [Atom: 10, {uid: 1005, wakelock_name: "compose"}] + * statePrimaryKey = [Atom: 59, {uid: 1005, package_name: "system"}] + * Returns false + */ +bool containsLinkedStateValues(const HashableDimensionKey& whatKey, + const HashableDimensionKey& primaryKey, + const std::vector<Metric2State>& stateLinks, + const int32_t stateAtomId); + +/** + * Returns true if there is a Metric2State link that links the stateField and + * the metricField (they are equal fields from different atoms). + */ +bool linked(const std::vector<Metric2State>& stateLinks, const int32_t stateAtomId, + const Field& stateField, const Field& metricField); } // namespace statsd } // namespace os } // namespace android @@ -165,8 +231,8 @@ template <> struct hash<MetricDimensionKey> { std::size_t operator()(const MetricDimensionKey& key) const { android::hash_t hash = hashDimension(key.getDimensionKeyInWhat()); - hash = android::JenkinsHashMix(hash, hashDimension(key.getDimensionKeyInCondition())); + hash = android::JenkinsHashMix(hash, hashDimension(key.getStateValuesKey())); return android::JenkinsHashWhiten(hash); } }; -} // namespace std
\ No newline at end of file +} // namespace std |