Loading cmds/statsd/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -337,6 +337,7 @@ cc_test { "tests/external/StatsPullerManager_test.cpp", "tests/external/StatsPullerManager_test.cpp", "tests/FieldValue_test.cpp", "tests/FieldValue_test.cpp", "tests/guardrail/StatsdStats_test.cpp", "tests/guardrail/StatsdStats_test.cpp", "tests/HashableDimensionKey_test.cpp", "tests/indexed_priority_queue_test.cpp", "tests/indexed_priority_queue_test.cpp", "tests/log_event/LogEventQueue_test.cpp", "tests/log_event/LogEventQueue_test.cpp", "tests/LogEntryMatcher_test.cpp", "tests/LogEntryMatcher_test.cpp", Loading cmds/statsd/src/HashableDimensionKey.cpp +41 −0 Original line number Original line Diff line number Diff line Loading @@ -230,6 +230,47 @@ void getDimensionForState(const std::vector<FieldValue>& eventValues, const Metr } } } } bool containsLinkedStateValues(const HashableDimensionKey& whatKey, const HashableDimensionKey& primaryKey, const vector<Metric2State>& stateLinks, const int32_t stateAtomId) { if (whatKey.getValues().size() < primaryKey.getValues().size()) { ALOGE("Contains linked values false: whatKey is too small"); return false; } for (const auto& primaryValue : primaryKey.getValues()) { bool found = false; for (const auto& whatValue : whatKey.getValues()) { if (linked(stateLinks, stateAtomId, primaryValue.mField, whatValue.mField) && primaryValue.mValue == whatValue.mValue) { found = true; break; } } if (!found) { return false; } } return true; } bool linked(const vector<Metric2State>& stateLinks, const int32_t stateAtomId, const Field& stateField, const Field& metricField) { for (auto stateLink : stateLinks) { if (stateLink.stateAtomId != stateAtomId) { continue; } for (size_t i = 0; i < stateLink.stateFields.size(); i++) { if (stateLink.stateFields[i].mMatcher == stateField && stateLink.metricFields[i].mMatcher == metricField) { return true; } } } return false; } bool LessThan(const vector<FieldValue>& s1, const vector<FieldValue>& s2) { bool LessThan(const vector<FieldValue>& s1, const vector<FieldValue>& s2) { if (s1.size() != s2.size()) { if (s1.size() != s2.size()) { return s1.size() < s2.size(); return s1.size() < s2.size(); Loading cmds/statsd/src/HashableDimensionKey.h +30 −0 Original line number Original line Diff line number Diff line Loading @@ -110,6 +110,10 @@ public: return mStateValuesKey; return mStateValuesKey; } } inline HashableDimensionKey* getMutableStateValuesKey() { return &mStateValuesKey; } inline void setStateValuesKey(const HashableDimensionKey& key) { inline void setStateValuesKey(const HashableDimensionKey& key) { mStateValuesKey = key; mStateValuesKey = key; } } Loading Loading @@ -169,6 +173,32 @@ void getDimensionForCondition(const std::vector<FieldValue>& eventValues, void getDimensionForState(const std::vector<FieldValue>& eventValues, const Metric2State& link, void getDimensionForState(const std::vector<FieldValue>& eventValues, const Metric2State& link, HashableDimensionKey* statePrimaryKey); 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 statsd } // namespace os } // namespace os } // namespace android } // namespace android Loading cmds/statsd/src/StatsLogProcessor.h +5 −0 Original line number Original line Diff line number Diff line Loading @@ -334,6 +334,11 @@ private: FRIEND_TEST(DurationMetricE2eTest, TestWithCondition); FRIEND_TEST(DurationMetricE2eTest, TestWithCondition); FRIEND_TEST(DurationMetricE2eTest, TestWithSlicedCondition); FRIEND_TEST(DurationMetricE2eTest, TestWithSlicedCondition); FRIEND_TEST(DurationMetricE2eTest, TestWithActivationAndSlicedCondition); FRIEND_TEST(DurationMetricE2eTest, TestWithActivationAndSlicedCondition); FRIEND_TEST(DurationMetricE2eTest, TestWithSlicedState); FRIEND_TEST(DurationMetricE2eTest, TestWithConditionAndSlicedState); FRIEND_TEST(DurationMetricE2eTest, TestWithSlicedStateMapped); FRIEND_TEST(DurationMetricE2eTest, TestSlicedStatePrimaryFieldsNotSubsetDimInWhat); FRIEND_TEST(DurationMetricE2eTest, TestWithSlicedStatePrimaryFieldsSubset); FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState); FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState); FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState_WithDimensions); FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState_WithDimensions); Loading cmds/statsd/src/atoms.proto +2 −1 Original line number Original line Diff line number Diff line Loading @@ -123,7 +123,8 @@ message Atom { BatteryLevelChanged battery_level_changed = BatteryLevelChanged battery_level_changed = 30 [(module) = "framework", (module) = "statsdtest"]; 30 [(module) = "framework", (module) = "statsdtest"]; ChargingStateChanged charging_state_changed = 31 [(module) = "framework"]; ChargingStateChanged charging_state_changed = 31 [(module) = "framework"]; PluggedStateChanged plugged_state_changed = 32 [(module) = "framework"]; PluggedStateChanged plugged_state_changed = 32 [(module) = "framework", (module) = "statsdtest"]; InteractiveStateChanged interactive_state_changed = 33 [(module) = "framework"]; InteractiveStateChanged interactive_state_changed = 33 [(module) = "framework"]; TouchEventReported touch_event_reported = 34; TouchEventReported touch_event_reported = 34; WakeupAlarmOccurred wakeup_alarm_occurred = 35 [(module) = "framework"]; WakeupAlarmOccurred wakeup_alarm_occurred = 35 [(module) = "framework"]; Loading Loading
cmds/statsd/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -337,6 +337,7 @@ cc_test { "tests/external/StatsPullerManager_test.cpp", "tests/external/StatsPullerManager_test.cpp", "tests/FieldValue_test.cpp", "tests/FieldValue_test.cpp", "tests/guardrail/StatsdStats_test.cpp", "tests/guardrail/StatsdStats_test.cpp", "tests/HashableDimensionKey_test.cpp", "tests/indexed_priority_queue_test.cpp", "tests/indexed_priority_queue_test.cpp", "tests/log_event/LogEventQueue_test.cpp", "tests/log_event/LogEventQueue_test.cpp", "tests/LogEntryMatcher_test.cpp", "tests/LogEntryMatcher_test.cpp", Loading
cmds/statsd/src/HashableDimensionKey.cpp +41 −0 Original line number Original line Diff line number Diff line Loading @@ -230,6 +230,47 @@ void getDimensionForState(const std::vector<FieldValue>& eventValues, const Metr } } } } bool containsLinkedStateValues(const HashableDimensionKey& whatKey, const HashableDimensionKey& primaryKey, const vector<Metric2State>& stateLinks, const int32_t stateAtomId) { if (whatKey.getValues().size() < primaryKey.getValues().size()) { ALOGE("Contains linked values false: whatKey is too small"); return false; } for (const auto& primaryValue : primaryKey.getValues()) { bool found = false; for (const auto& whatValue : whatKey.getValues()) { if (linked(stateLinks, stateAtomId, primaryValue.mField, whatValue.mField) && primaryValue.mValue == whatValue.mValue) { found = true; break; } } if (!found) { return false; } } return true; } bool linked(const vector<Metric2State>& stateLinks, const int32_t stateAtomId, const Field& stateField, const Field& metricField) { for (auto stateLink : stateLinks) { if (stateLink.stateAtomId != stateAtomId) { continue; } for (size_t i = 0; i < stateLink.stateFields.size(); i++) { if (stateLink.stateFields[i].mMatcher == stateField && stateLink.metricFields[i].mMatcher == metricField) { return true; } } } return false; } bool LessThan(const vector<FieldValue>& s1, const vector<FieldValue>& s2) { bool LessThan(const vector<FieldValue>& s1, const vector<FieldValue>& s2) { if (s1.size() != s2.size()) { if (s1.size() != s2.size()) { return s1.size() < s2.size(); return s1.size() < s2.size(); Loading
cmds/statsd/src/HashableDimensionKey.h +30 −0 Original line number Original line Diff line number Diff line Loading @@ -110,6 +110,10 @@ public: return mStateValuesKey; return mStateValuesKey; } } inline HashableDimensionKey* getMutableStateValuesKey() { return &mStateValuesKey; } inline void setStateValuesKey(const HashableDimensionKey& key) { inline void setStateValuesKey(const HashableDimensionKey& key) { mStateValuesKey = key; mStateValuesKey = key; } } Loading Loading @@ -169,6 +173,32 @@ void getDimensionForCondition(const std::vector<FieldValue>& eventValues, void getDimensionForState(const std::vector<FieldValue>& eventValues, const Metric2State& link, void getDimensionForState(const std::vector<FieldValue>& eventValues, const Metric2State& link, HashableDimensionKey* statePrimaryKey); 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 statsd } // namespace os } // namespace os } // namespace android } // namespace android Loading
cmds/statsd/src/StatsLogProcessor.h +5 −0 Original line number Original line Diff line number Diff line Loading @@ -334,6 +334,11 @@ private: FRIEND_TEST(DurationMetricE2eTest, TestWithCondition); FRIEND_TEST(DurationMetricE2eTest, TestWithCondition); FRIEND_TEST(DurationMetricE2eTest, TestWithSlicedCondition); FRIEND_TEST(DurationMetricE2eTest, TestWithSlicedCondition); FRIEND_TEST(DurationMetricE2eTest, TestWithActivationAndSlicedCondition); FRIEND_TEST(DurationMetricE2eTest, TestWithActivationAndSlicedCondition); FRIEND_TEST(DurationMetricE2eTest, TestWithSlicedState); FRIEND_TEST(DurationMetricE2eTest, TestWithConditionAndSlicedState); FRIEND_TEST(DurationMetricE2eTest, TestWithSlicedStateMapped); FRIEND_TEST(DurationMetricE2eTest, TestSlicedStatePrimaryFieldsNotSubsetDimInWhat); FRIEND_TEST(DurationMetricE2eTest, TestWithSlicedStatePrimaryFieldsSubset); FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState); FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState); FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState_WithDimensions); FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState_WithDimensions); Loading
cmds/statsd/src/atoms.proto +2 −1 Original line number Original line Diff line number Diff line Loading @@ -123,7 +123,8 @@ message Atom { BatteryLevelChanged battery_level_changed = BatteryLevelChanged battery_level_changed = 30 [(module) = "framework", (module) = "statsdtest"]; 30 [(module) = "framework", (module) = "statsdtest"]; ChargingStateChanged charging_state_changed = 31 [(module) = "framework"]; ChargingStateChanged charging_state_changed = 31 [(module) = "framework"]; PluggedStateChanged plugged_state_changed = 32 [(module) = "framework"]; PluggedStateChanged plugged_state_changed = 32 [(module) = "framework", (module) = "statsdtest"]; InteractiveStateChanged interactive_state_changed = 33 [(module) = "framework"]; InteractiveStateChanged interactive_state_changed = 33 [(module) = "framework"]; TouchEventReported touch_event_reported = 34; TouchEventReported touch_event_reported = 34; WakeupAlarmOccurred wakeup_alarm_occurred = 35 [(module) = "framework"]; WakeupAlarmOccurred wakeup_alarm_occurred = 35 [(module) = "framework"]; Loading