Pass initial conditions to combination conditions and metrics
SimplePredicates have a configurable initial value that can be set to
unknown or false. Previously, CombinationPredicates and MetricProducers
were automatically initialized with an unknown condition value instead
of being synced with the conditions of the SimplePredicates that they
rely on.
An initial condition cache is used to store initial conditions of
ConditionTrackers after they are initialized.
CombinationConditionTrackers evaluate their initial condition based on
the initial conditions of their child SimpleConditionTrackers.
MetricProducers also use the initial condition cache to set its
condition during initialization.
Added unit tests in SimpleConditionTracker_test to check that
SimpleConditionTrackers have the correct initial conditions based on
what the InitialValue is set to and the condition is updated properly
after the first few condition change events.
Added unit test in MetricsManager_test to check that all
ConditionTrackers and MetricProducers have the correct initial
conditions.
Test: m statsd_test && adb sync data && adb shell
data/nativetest64/statsd_test/statsd_test64
Bug: b/156762672
Change-Id: I9f6088f8c92fb18eb2ca8632aaa338fb0ed8e679
diff --git a/cmds/statsd/src/metrics/ValueMetricProducer.cpp b/cmds/statsd/src/metrics/ValueMetricProducer.cpp
index 71df710..c0d1174 100644
--- a/cmds/statsd/src/metrics/ValueMetricProducer.cpp
+++ b/cmds/statsd/src/metrics/ValueMetricProducer.cpp
@@ -78,6 +78,7 @@
// ValueMetric has a minimum bucket size of 10min so that we don't pull too frequently
ValueMetricProducer::ValueMetricProducer(
const ConfigKey& key, const ValueMetric& metric, const int conditionIndex,
+ const vector<ConditionState>& initialConditionCache,
const sp<ConditionWizard>& conditionWizard, const int whatMatcherIndex,
const sp<EventMatcherWizard>& matcherWizard, const int pullTagId, const int64_t timeBaseNs,
const int64_t startTimeNs, const sp<StatsPullerManager>& pullerManager,
@@ -85,8 +86,9 @@
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap,
const vector<int>& slicedStateAtoms,
const unordered_map<int, unordered_map<int, int64_t>>& stateGroupMap)
- : MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, conditionWizard,
- eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap),
+ : MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, initialConditionCache,
+ conditionWizard, eventActivationMap, eventDeactivationMap, slicedStateAtoms,
+ stateGroupMap),
mWhatMatcherIndex(whatMatcherIndex),
mEventMatcherWizard(matcherWizard),
mPullerManager(pullerManager),