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

Commit 5e2addf2 authored by Christine Tsai's avatar Christine Tsai Committed by Android (Google) Code Review
Browse files

Merge "Slice by state in DurationMetricProducer"

parents 43b604f9 9ca6dc65
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -336,6 +336,7 @@ cc_test {
        "tests/external/StatsPullerManager_test.cpp",
        "tests/FieldValue_test.cpp",
        "tests/guardrail/StatsdStats_test.cpp",
        "tests/HashableDimensionKey_test.cpp",
        "tests/indexed_priority_queue_test.cpp",
        "tests/log_event/LogEventQueue_test.cpp",
        "tests/LogEntryMatcher_test.cpp",
+41 −0
Original line number Diff line number Diff line
@@ -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) {
    if (s1.size() != s2.size()) {
        return s1.size() < s2.size();
+30 −0
Original line number Diff line number Diff line
@@ -110,6 +110,10 @@ public:
        return mStateValuesKey;
    }

    inline HashableDimensionKey* getMutableStateValuesKey() {
        return &mStateValuesKey;
    }

    inline void setStateValuesKey(const HashableDimensionKey& key) {
        mStateValuesKey = key;
    }
@@ -169,6 +173,32 @@ void getDimensionForCondition(const std::vector<FieldValue>& eventValues,
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
+5 −0
Original line number Diff line number Diff line
@@ -301,6 +301,11 @@ private:
    FRIEND_TEST(DurationMetricE2eTest, TestWithCondition);
    FRIEND_TEST(DurationMetricE2eTest, TestWithSlicedCondition);
    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_WithDimensions);
+2 −1
Original line number Diff line number Diff line
@@ -123,7 +123,8 @@ message Atom {
        BatteryLevelChanged battery_level_changed =
                30 [(module) = "framework", (module) = "statsdtest"];
        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"];
        TouchEventReported touch_event_reported = 34;
        WakeupAlarmOccurred wakeup_alarm_occurred = 35 [(module) = "framework"];
Loading