Loading cmds/statsd/Android.bp +3 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,8 @@ cc_defaults { "src/shell/shell_config.proto", "src/shell/ShellSubscriber.cpp", "src/socket/StatsSocketListener.cpp", "src/state/StateManager.cpp", "src/state/StateTracker.cpp", "src/stats_log_util.cpp", "src/statscompanion_util.cpp", "src/statsd_config.proto", Loading Loading @@ -253,6 +255,7 @@ cc_test { "tests/metrics/ValueMetricProducer_test.cpp", "tests/MetricsManager_test.cpp", "tests/shell/ShellSubscriber_test.cpp", "tests/state/StateTracker_test.cpp", "tests/statsd_test_util.cpp", "tests/StatsLogProcessor_test.cpp", "tests/StatsService_test.cpp", Loading cmds/statsd/src/HashableDimensionKey.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,16 @@ android::hash_t hashDimension(const HashableDimensionKey& value) { return JenkinsHashWhiten(hash); } bool filterValues(const Matcher& matcherField, const vector<FieldValue>& values, Value* output) { for (const auto& value : values) { if (value.mField.matches(matcherField)) { (*output) = value.mValue; return true; } } return false; } bool filterValues(const vector<Matcher>& matcherFields, const vector<FieldValue>& values, HashableDimensionKey* output) { size_t num_matches = 0; Loading cmds/statsd/src/HashableDimensionKey.h +8 −1 Original line number Diff line number Diff line Loading @@ -119,6 +119,13 @@ class MetricDimensionKey { 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, Value* output); /** * Creating HashableDimensionKeys from FieldValues using matcher. * Loading cmds/statsd/src/atoms.proto +3 −3 Original line number Diff line number Diff line Loading @@ -3069,9 +3069,9 @@ message PictureInPictureStateChanged { * services/core/java/com/android/server/wm/Session.java */ message OverlayStateChanged { optional int32 uid = 1 [(is_uid) = true]; optional int32 uid = 1 [(state_field_option).option = PRIMARY, (is_uid) = true]; optional string package_name = 2; optional string package_name = 2 [(state_field_option).option = PRIMARY]; optional bool using_alert_window = 3; Loading @@ -3079,7 +3079,7 @@ message OverlayStateChanged { ENTERED = 1; EXITED = 2; } optional State state = 4; optional State state = 4 [(state_field_option).option = EXCLUSIVE]; } /* Loading cmds/statsd/src/state/StateListener.h 0 → 100644 +52 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <utils/RefBase.h> #include "HashableDimensionKey.h" namespace android { namespace os { namespace statsd { class StateListener : public virtual RefBase { public: StateListener(){}; virtual ~StateListener(){}; /** * Interface for handling a state change. * * The old and new state values map to the original state values. * StateTrackers only track the original state values and are unaware * of higher-level state groups. MetricProducers hold information on * state groups and are responsible for mapping original state values to * the correct state group. * * [atomId]: The id of the state atom * [primaryKey]: The primary field values of the state atom * [oldState]: Previous state value before state change * [newState]: Current state value after state change */ virtual void onStateChanged(int atomId, const HashableDimensionKey& primaryKey, int oldState, int newState) = 0; }; } // namespace statsd } // namespace os } // namespace android Loading
cmds/statsd/Android.bp +3 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,8 @@ cc_defaults { "src/shell/shell_config.proto", "src/shell/ShellSubscriber.cpp", "src/socket/StatsSocketListener.cpp", "src/state/StateManager.cpp", "src/state/StateTracker.cpp", "src/stats_log_util.cpp", "src/statscompanion_util.cpp", "src/statsd_config.proto", Loading Loading @@ -253,6 +255,7 @@ cc_test { "tests/metrics/ValueMetricProducer_test.cpp", "tests/MetricsManager_test.cpp", "tests/shell/ShellSubscriber_test.cpp", "tests/state/StateTracker_test.cpp", "tests/statsd_test_util.cpp", "tests/StatsLogProcessor_test.cpp", "tests/StatsService_test.cpp", Loading
cmds/statsd/src/HashableDimensionKey.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,16 @@ android::hash_t hashDimension(const HashableDimensionKey& value) { return JenkinsHashWhiten(hash); } bool filterValues(const Matcher& matcherField, const vector<FieldValue>& values, Value* output) { for (const auto& value : values) { if (value.mField.matches(matcherField)) { (*output) = value.mValue; return true; } } return false; } bool filterValues(const vector<Matcher>& matcherFields, const vector<FieldValue>& values, HashableDimensionKey* output) { size_t num_matches = 0; Loading
cmds/statsd/src/HashableDimensionKey.h +8 −1 Original line number Diff line number Diff line Loading @@ -119,6 +119,13 @@ class MetricDimensionKey { 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, Value* output); /** * Creating HashableDimensionKeys from FieldValues using matcher. * Loading
cmds/statsd/src/atoms.proto +3 −3 Original line number Diff line number Diff line Loading @@ -3069,9 +3069,9 @@ message PictureInPictureStateChanged { * services/core/java/com/android/server/wm/Session.java */ message OverlayStateChanged { optional int32 uid = 1 [(is_uid) = true]; optional int32 uid = 1 [(state_field_option).option = PRIMARY, (is_uid) = true]; optional string package_name = 2; optional string package_name = 2 [(state_field_option).option = PRIMARY]; optional bool using_alert_window = 3; Loading @@ -3079,7 +3079,7 @@ message OverlayStateChanged { ENTERED = 1; EXITED = 2; } optional State state = 4; optional State state = 4 [(state_field_option).option = EXCLUSIVE]; } /* Loading
cmds/statsd/src/state/StateListener.h 0 → 100644 +52 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <utils/RefBase.h> #include "HashableDimensionKey.h" namespace android { namespace os { namespace statsd { class StateListener : public virtual RefBase { public: StateListener(){}; virtual ~StateListener(){}; /** * Interface for handling a state change. * * The old and new state values map to the original state values. * StateTrackers only track the original state values and are unaware * of higher-level state groups. MetricProducers hold information on * state groups and are responsible for mapping original state values to * the correct state group. * * [atomId]: The id of the state atom * [primaryKey]: The primary field values of the state atom * [oldState]: Previous state value before state change * [newState]: Current state value after state change */ virtual void onStateChanged(int atomId, const HashableDimensionKey& primaryKey, int oldState, int newState) = 0; }; } // namespace statsd } // namespace os } // namespace android