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
This commit is contained in:
tsaichristine
2020-05-18 14:39:45 -07:00
parent ca83d45538
commit 6e2e92d968
27 changed files with 553 additions and 242 deletions

View File

@@ -37,7 +37,8 @@ CombinationConditionTracker::~CombinationConditionTracker() {
bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConfig,
const vector<sp<ConditionTracker>>& allConditionTrackers,
const unordered_map<int64_t, int>& conditionIdIndexMap,
vector<bool>& stack) {
vector<bool>& stack,
vector<ConditionState>& initialConditionCache) {
VLOG("Combination predicate init() %lld", (long long)mConditionId);
if (mInitialized) {
return true;
@@ -73,9 +74,9 @@ bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConf
return false;
}
bool initChildSucceeded = childTracker->init(allConditionConfig, allConditionTrackers,
conditionIdIndexMap, stack);
bool initChildSucceeded =
childTracker->init(allConditionConfig, allConditionTrackers, conditionIdIndexMap,
stack, initialConditionCache);
if (!initChildSucceeded) {
ALOGW("Child initialization failed %lld ", (long long)child);
@@ -95,6 +96,11 @@ bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConf
childTracker->getLogTrackerIndex().end());
}
mUnSlicedPartCondition = evaluateCombinationCondition(mUnSlicedChildren, mLogicalOperation,
initialConditionCache);
initialConditionCache[mIndex] =
evaluateCombinationCondition(mChildren, mLogicalOperation, initialConditionCache);
// unmark this node in the recursion stack.
stack[mIndex] = false;

View File

@@ -32,8 +32,8 @@ public:
bool init(const std::vector<Predicate>& allConditionConfig,
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
const std::unordered_map<int64_t, int>& conditionIdIndexMap,
std::vector<bool>& stack) override;
const std::unordered_map<int64_t, int>& conditionIdIndexMap, std::vector<bool>& stack,
std::vector<ConditionState>& initialConditionCache) override;
void evaluateCondition(const LogEvent& event,
const std::vector<MatchingState>& eventMatcherValues,

View File

@@ -51,10 +51,12 @@ public:
// need to call init() on children conditions)
// conditionIdIndexMap: the mapping from condition id to its index.
// stack: a bit map to keep track which nodes have been visited on the stack in the recursion.
// initialConditionCache: tracks initial conditions of all ConditionTrackers.
virtual bool init(const std::vector<Predicate>& allConditionConfig,
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
const std::unordered_map<int64_t, int>& conditionIdIndexMap,
std::vector<bool>& stack) = 0;
std::vector<bool>& stack,
std::vector<ConditionState>& initialConditionCache) = 0;
// evaluate current condition given the new event.
// event: the new log event

View File

@@ -95,9 +95,11 @@ SimpleConditionTracker::~SimpleConditionTracker() {
bool SimpleConditionTracker::init(const vector<Predicate>& allConditionConfig,
const vector<sp<ConditionTracker>>& allConditionTrackers,
const unordered_map<int64_t, int>& conditionIdIndexMap,
vector<bool>& stack) {
vector<bool>& stack,
vector<ConditionState>& initialConditionCache) {
// SimpleConditionTracker does not have dependency on other conditions, thus we just return
// if the initialization was successful.
initialConditionCache[mIndex] = mInitialValue;
return mInitialized;
}

View File

@@ -37,8 +37,8 @@ public:
bool init(const std::vector<Predicate>& allConditionConfig,
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
const std::unordered_map<int64_t, int>& conditionIdIndexMap,
std::vector<bool>& stack) override;
const std::unordered_map<int64_t, int>& conditionIdIndexMap, std::vector<bool>& stack,
std::vector<ConditionState>& initialConditionCache) override;
void evaluateCondition(const LogEvent& event,
const std::vector<MatchingState>& eventMatcherValues,

View File

@@ -68,14 +68,14 @@ const int FIELD_ID_END_BUCKET_ELAPSED_MILLIS = 6;
CountMetricProducer::CountMetricProducer(
const ConfigKey& key, const CountMetric& metric, const int conditionIndex,
const sp<ConditionWizard>& wizard, const int64_t timeBaseNs, const int64_t startTimeNs,
const vector<ConditionState>& initialConditionCache, const sp<ConditionWizard>& wizard,
const int64_t timeBaseNs, const int64_t startTimeNs,
const unordered_map<int, shared_ptr<Activation>>& eventActivationMap,
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, wizard, eventActivationMap,
eventDeactivationMap, slicedStateAtoms, stateGroupMap) {
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, initialConditionCache, wizard,
eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap) {
if (metric.has_bucket()) {
mBucketSizeNs =
TimeUnitToBucketSizeInMillisGuardrailed(key.GetUid(), metric.bucket()) * 1000000;

View File

@@ -43,7 +43,8 @@ class CountMetricProducer : public MetricProducer {
public:
CountMetricProducer(
const ConfigKey& key, const CountMetric& countMetric, const int conditionIndex,
const sp<ConditionWizard>& wizard, const int64_t timeBaseNs, const int64_t startTimeNs,
const vector<ConditionState>& initialConditionCache, const sp<ConditionWizard>& wizard,
const int64_t timeBaseNs, const int64_t startTimeNs,
const std::unordered_map<int, std::shared_ptr<Activation>>& eventActivationMap = {},
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
eventDeactivationMap = {},

View File

@@ -64,15 +64,16 @@ const int FIELD_ID_END_BUCKET_ELAPSED_MILLIS = 6;
DurationMetricProducer::DurationMetricProducer(
const ConfigKey& key, const DurationMetric& metric, const int conditionIndex,
const size_t startIndex, const size_t stopIndex, const size_t stopAllIndex,
const bool nesting, const sp<ConditionWizard>& wizard,
const FieldMatcher& internalDimensions, const int64_t timeBaseNs, const int64_t startTimeNs,
const vector<ConditionState>& initialConditionCache, const size_t startIndex,
const size_t stopIndex, const size_t stopAllIndex, const bool nesting,
const sp<ConditionWizard>& wizard, const FieldMatcher& internalDimensions,
const int64_t timeBaseNs, const int64_t startTimeNs,
const unordered_map<int, shared_ptr<Activation>>& eventActivationMap,
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, wizard, eventActivationMap,
eventDeactivationMap, slicedStateAtoms, stateGroupMap),
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, initialConditionCache, wizard,
eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap),
mAggregationType(metric.aggregation_type()),
mStartIndex(startIndex),
mStopIndex(stopIndex),

View File

@@ -40,10 +40,10 @@ class DurationMetricProducer : public MetricProducer {
public:
DurationMetricProducer(
const ConfigKey& key, const DurationMetric& durationMetric, const int conditionIndex,
const size_t startIndex, const size_t stopIndex, const size_t stopAllIndex,
const bool nesting, const sp<ConditionWizard>& wizard,
const FieldMatcher& internalDimensions, const int64_t timeBaseNs,
const int64_t startTimeNs,
const vector<ConditionState>& initialConditionCache, const size_t startIndex,
const size_t stopIndex, const size_t stopAllIndex, const bool nesting,
const sp<ConditionWizard>& wizard, const FieldMatcher& internalDimensions,
const int64_t timeBaseNs, const int64_t startTimeNs,
const unordered_map<int, shared_ptr<Activation>>& eventActivationMap = {},
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap = {},
const vector<int>& slicedStateAtoms = {},

View File

@@ -54,13 +54,14 @@ const int FIELD_ID_ATOMS = 2;
EventMetricProducer::EventMetricProducer(
const ConfigKey& key, const EventMetric& metric, const int conditionIndex,
const sp<ConditionWizard>& wizard, const int64_t startTimeNs,
const vector<ConditionState>& initialConditionCache, const sp<ConditionWizard>& wizard,
const int64_t startTimeNs,
const unordered_map<int, shared_ptr<Activation>>& eventActivationMap,
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, startTimeNs, conditionIndex, wizard, eventActivationMap,
eventDeactivationMap, slicedStateAtoms, stateGroupMap) {
: MetricProducer(metric.id(), key, startTimeNs, conditionIndex, initialConditionCache, wizard,
eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap) {
if (metric.links().size() > 0) {
for (const auto& link : metric.links()) {
Metric2Condition mc;

View File

@@ -35,7 +35,8 @@ class EventMetricProducer : public MetricProducer {
public:
EventMetricProducer(
const ConfigKey& key, const EventMetric& eventMetric, const int conditionIndex,
const sp<ConditionWizard>& wizard, const int64_t startTimeNs,
const vector<ConditionState>& initialConditionCache, const sp<ConditionWizard>& wizard,
const int64_t startTimeNs,
const std::unordered_map<int, std::shared_ptr<Activation>>& eventActivationMap = {},
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
eventDeactivationMap = {},

View File

@@ -70,14 +70,15 @@ const int FIELD_ID_END_BUCKET_ELAPSED_MILLIS = 8;
GaugeMetricProducer::GaugeMetricProducer(
const ConfigKey& key, const GaugeMetric& metric, const int conditionIndex,
const sp<ConditionWizard>& wizard, const int whatMatcherIndex,
const sp<EventMatcherWizard>& matcherWizard, const int pullTagId, const int triggerAtomId,
const int atomId, const int64_t timeBaseNs, const int64_t startTimeNs,
const sp<StatsPullerManager>& pullerManager,
const vector<ConditionState>& initialConditionCache, const sp<ConditionWizard>& wizard,
const int whatMatcherIndex, const sp<EventMatcherWizard>& matcherWizard,
const int pullTagId, const int triggerAtomId, const int atomId, const int64_t timeBaseNs,
const int64_t startTimeNs, const sp<StatsPullerManager>& pullerManager,
const unordered_map<int, shared_ptr<Activation>>& eventActivationMap,
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap)
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, wizard, eventActivationMap,
eventDeactivationMap, /*slicedStateAtoms=*/{}, /*stateGroupMap=*/{}),
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, initialConditionCache, wizard,
eventActivationMap, eventDeactivationMap, /*slicedStateAtoms=*/{},
/*stateGroupMap=*/{}),
mWhatMatcherIndex(whatMatcherIndex),
mEventMatcherWizard(matcherWizard),
mPullerManager(pullerManager),

View File

@@ -58,6 +58,7 @@ class GaugeMetricProducer : public virtual MetricProducer, public virtual PullDa
public:
GaugeMetricProducer(
const ConfigKey& key, const GaugeMetric& gaugeMetric, const int conditionIndex,
const vector<ConditionState>& initialConditionCache,
const sp<ConditionWizard>& conditionWizard, const int whatMatcherIndex,
const sp<EventMatcherWizard>& matcherWizard, const int pullTagId,
const int triggerAtomId, const int atomId, const int64_t timeBaseNs,

View File

@@ -45,7 +45,8 @@ const int FIELD_ID_ACTIVE_EVENT_ACTIVATION_STATE = 3;
MetricProducer::MetricProducer(
const int64_t& metricId, const ConfigKey& key, const int64_t timeBaseNs,
const int conditionIndex, const sp<ConditionWizard>& wizard,
const int conditionIndex, const vector<ConditionState>& initialConditionCache,
const sp<ConditionWizard>& wizard,
const std::unordered_map<int, std::shared_ptr<Activation>>& eventActivationMap,
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
eventDeactivationMap,
@@ -56,7 +57,7 @@ MetricProducer::MetricProducer(
mTimeBaseNs(timeBaseNs),
mCurrentBucketStartTimeNs(timeBaseNs),
mCurrentBucketNum(0),
mCondition(initialCondition(conditionIndex)),
mCondition(initialCondition(conditionIndex, initialConditionCache)),
mConditionTrackerIndex(conditionIndex),
mConditionSliced(false),
mWizard(wizard),

View File

@@ -129,7 +129,8 @@ struct SkippedBucket {
class MetricProducer : public virtual android::RefBase, public virtual StateListener {
public:
MetricProducer(const int64_t& metricId, const ConfigKey& key, const int64_t timeBaseNs,
const int conditionIndex, const sp<ConditionWizard>& wizard,
const int conditionIndex, const vector<ConditionState>& initialConditionCache,
const sp<ConditionWizard>& wizard,
const std::unordered_map<int, std::shared_ptr<Activation>>& eventActivationMap,
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
eventDeactivationMap,
@@ -138,8 +139,9 @@ public:
virtual ~MetricProducer(){};
ConditionState initialCondition(const int conditionIndex) const {
return conditionIndex >= 0 ? ConditionState::kUnknown : ConditionState::kTrue;
ConditionState initialCondition(const int conditionIndex,
const vector<ConditionState>& initialConditionCache) const {
return conditionIndex >= 0 ? initialConditionCache[conditionIndex] : ConditionState::kTrue;
}
/**
@@ -496,6 +498,8 @@ protected:
FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState_WithDimensions);
FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState_WithIncorrectDimensions);
FRIEND_TEST(ValueMetricE2eTest, TestInitialConditionChanges);
FRIEND_TEST(MetricsManagerTest, TestInitialConditions);
};
} // namespace statsd

View File

@@ -78,6 +78,7 @@ const Value ZERO_DOUBLE((int64_t)0);
// 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 @@ ValueMetricProducer::ValueMetricProducer(
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),

View File

@@ -52,6 +52,7 @@ class ValueMetricProducer : public virtual MetricProducer, public virtual PullDa
public:
ValueMetricProducer(
const ConfigKey& key, const ValueMetric& valueMetric, 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,

View File

@@ -285,11 +285,14 @@ bool initConditions(const ConfigKey& key, const StatsdConfig& config,
const unordered_map<int64_t, int>& logTrackerMap,
unordered_map<int64_t, int>& conditionTrackerMap,
vector<sp<ConditionTracker>>& allConditionTrackers,
unordered_map<int, std::vector<int>>& trackerToConditionMap) {
unordered_map<int, std::vector<int>>& trackerToConditionMap,
vector<ConditionState>& initialConditionCache) {
vector<Predicate> conditionConfigs;
const int conditionTrackerCount = config.predicate_size();
conditionConfigs.reserve(conditionTrackerCount);
allConditionTrackers.reserve(conditionTrackerCount);
initialConditionCache.reserve(conditionTrackerCount);
std::fill(initialConditionCache.begin(), initialConditionCache.end(), ConditionState::kUnknown);
for (int i = 0; i < conditionTrackerCount; i++) {
const Predicate& condition = config.predicate(i);
@@ -321,7 +324,7 @@ bool initConditions(const ConfigKey& key, const StatsdConfig& config,
for (size_t i = 0; i < allConditionTrackers.size(); i++) {
auto& conditionTracker = allConditionTrackers[i];
if (!conditionTracker->init(conditionConfigs, allConditionTrackers, conditionTrackerMap,
stackTracker)) {
stackTracker, initialConditionCache)) {
return false;
}
for (const int trackerIndex : conditionTracker->getLogTrackerIndex()) {
@@ -351,14 +354,14 @@ bool initStates(const StatsdConfig& config, unordered_map<int64_t, int>& stateAt
}
bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t timeBaseTimeNs,
const int64_t currentTimeNs,
const sp<StatsPullerManager>& pullerManager,
const int64_t currentTimeNs, const sp<StatsPullerManager>& pullerManager,
const unordered_map<int64_t, int>& logTrackerMap,
const unordered_map<int64_t, int>& conditionTrackerMap,
const vector<sp<LogMatchingTracker>>& allAtomMatchers,
const unordered_map<int64_t, int>& stateAtomIdMap,
const unordered_map<int64_t, unordered_map<int, int64_t>>& allStateGroupMaps,
vector<sp<ConditionTracker>>& allConditionTrackers,
const vector<ConditionState>& initialConditionCache,
vector<sp<MetricProducer>>& allMetricProducers,
unordered_map<int, vector<int>>& conditionToMetricMap,
unordered_map<int, vector<int>>& trackerToMetricMap,
@@ -441,9 +444,10 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t
eventDeactivationMap);
if (!success) return false;
sp<MetricProducer> countProducer = new CountMetricProducer(
key, metric, conditionIndex, wizard, timeBaseTimeNs, currentTimeNs,
eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap);
sp<MetricProducer> countProducer =
new CountMetricProducer(key, metric, conditionIndex, initialConditionCache, wizard,
timeBaseTimeNs, currentTimeNs, eventActivationMap,
eventDeactivationMap, slicedStateAtoms, stateGroupMap);
allMetricProducers.push_back(countProducer);
}
@@ -547,10 +551,10 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t
if (!success) return false;
sp<MetricProducer> durationMetric = new DurationMetricProducer(
key, metric, conditionIndex, trackerIndices[0], trackerIndices[1],
trackerIndices[2], nesting, wizard, internalDimensions, timeBaseTimeNs,
currentTimeNs, eventActivationMap, eventDeactivationMap, slicedStateAtoms,
stateGroupMap);
key, metric, conditionIndex, initialConditionCache, trackerIndices[0],
trackerIndices[1], trackerIndices[2], nesting, wizard, internalDimensions,
timeBaseTimeNs, currentTimeNs, eventActivationMap, eventDeactivationMap,
slicedStateAtoms, stateGroupMap);
allMetricProducers.push_back(durationMetric);
}
@@ -593,9 +597,9 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t
eventDeactivationMap);
if (!success) return false;
sp<MetricProducer> eventMetric = new EventMetricProducer(
key, metric, conditionIndex, wizard, timeBaseTimeNs, eventActivationMap,
eventDeactivationMap);
sp<MetricProducer> eventMetric =
new EventMetricProducer(key, metric, conditionIndex, initialConditionCache, wizard,
timeBaseTimeNs, eventActivationMap, eventDeactivationMap);
allMetricProducers.push_back(eventMetric);
}
@@ -683,9 +687,9 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t
if (!success) return false;
sp<MetricProducer> valueProducer = new ValueMetricProducer(
key, metric, conditionIndex, wizard, trackerIndex, matcherWizard, pullTagId,
timeBaseTimeNs, currentTimeNs, pullerManager, eventActivationMap,
eventDeactivationMap, slicedStateAtoms, stateGroupMap);
key, metric, conditionIndex, initialConditionCache, wizard, trackerIndex,
matcherWizard, pullTagId, timeBaseTimeNs, currentTimeNs, pullerManager,
eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap);
allMetricProducers.push_back(valueProducer);
}
@@ -778,9 +782,9 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t
if (!success) return false;
sp<MetricProducer> gaugeProducer = new GaugeMetricProducer(
key, metric, conditionIndex, wizard, trackerIndex, matcherWizard, pullTagId,
triggerAtomId, atomTagId, timeBaseTimeNs, currentTimeNs, pullerManager,
eventActivationMap, eventDeactivationMap);
key, metric, conditionIndex, initialConditionCache, wizard, trackerIndex,
matcherWizard, pullTagId, triggerAtomId, atomTagId, timeBaseTimeNs, currentTimeNs,
pullerManager, eventActivationMap, eventDeactivationMap);
allMetricProducers.push_back(gaugeProducer);
}
for (int i = 0; i < config.no_report_metric_size(); ++i) {
@@ -930,6 +934,7 @@ bool initStatsdConfig(const ConfigKey& key, const StatsdConfig& config, UidMap&
std::set<int64_t>& noReportMetricIds) {
unordered_map<int64_t, int> logTrackerMap;
unordered_map<int64_t, int> conditionTrackerMap;
vector<ConditionState> initialConditionCache;
unordered_map<int64_t, int> metricProducerMap;
unordered_map<int64_t, int> stateAtomIdMap;
unordered_map<int64_t, unordered_map<int, int64_t>> allStateGroupMaps;
@@ -941,7 +946,7 @@ bool initStatsdConfig(const ConfigKey& key, const StatsdConfig& config, UidMap&
VLOG("initLogMatchingTrackers succeed...");
if (!initConditions(key, config, logTrackerMap, conditionTrackerMap, allConditionTrackers,
trackerToConditionMap)) {
trackerToConditionMap, initialConditionCache)) {
ALOGE("initConditionTrackers failed");
return false;
}
@@ -952,10 +957,10 @@ bool initStatsdConfig(const ConfigKey& key, const StatsdConfig& config, UidMap&
}
if (!initMetrics(key, config, timeBaseNs, currentTimeNs, pullerManager, logTrackerMap,
conditionTrackerMap, allAtomMatchers, stateAtomIdMap, allStateGroupMaps,
allConditionTrackers, allMetricProducers,
conditionToMetricMap, trackerToMetricMap, metricProducerMap,
noReportMetricIds, activationAtomTrackerToMetricMap,
deactivationAtomTrackerToMetricMap, metricsWithActivation)) {
allConditionTrackers, initialConditionCache, allMetricProducers,
conditionToMetricMap, trackerToMetricMap, metricProducerMap, noReportMetricIds,
activationAtomTrackerToMetricMap, deactivationAtomTrackerToMetricMap,
metricsWithActivation)) {
ALOGE("initMetricProducers failed");
return false;
}

View File

@@ -60,12 +60,14 @@ bool initLogTrackers(const StatsdConfig& config,
// [allConditionTrackers]: stores the sp to all the ConditionTrackers
// [trackerToConditionMap]: contain the mapping from index of
// log tracker to condition trackers that use the log tracker
// [initialConditionCache]: stores the initial conditions for each ConditionTracker
bool initConditions(const ConfigKey& key, const StatsdConfig& config,
const std::unordered_map<int64_t, int>& logTrackerMap,
std::unordered_map<int64_t, int>& conditionTrackerMap,
std::vector<sp<ConditionTracker>>& allConditionTrackers,
std::unordered_map<int, std::vector<int>>& trackerToConditionMap,
std::unordered_map<int, std::vector<MetricConditionLink>>& eventConditionLinks);
std::unordered_map<int, std::vector<MetricConditionLink>>& eventConditionLinks,
std::vector<ConditionState>& initialConditionCache);
// Initialize State maps using State protos in the config. These maps will
// eventually be passed to MetricProducers to initialize their state info.
@@ -103,6 +105,7 @@ bool initMetrics(
const unordered_map<int64_t, int>& stateAtomIdMap,
const unordered_map<int64_t, unordered_map<int, int64_t>>& allStateGroupMaps,
vector<sp<ConditionTracker>>& allConditionTrackers,
const std::vector<ConditionState>& initialConditionCache,
std::vector<sp<MetricProducer>>& allMetricProducers,
std::unordered_map<int, std::vector<int>>& conditionToMetricMap,
std::unordered_map<int, std::vector<int>>& trackerToMetricMap,

View File

@@ -276,11 +276,157 @@ StatsdConfig buildCirclePredicates() {
return config;
}
StatsdConfig buildConfigWithDifferentPredicates() {
StatsdConfig config;
config.set_id(12345);
auto pulledAtomMatcher =
CreateSimpleAtomMatcher("SUBSYSTEM_SLEEP", util::SUBSYSTEM_SLEEP_STATE);
*config.add_atom_matcher() = pulledAtomMatcher;
auto screenOnAtomMatcher = CreateScreenTurnedOnAtomMatcher();
*config.add_atom_matcher() = screenOnAtomMatcher;
auto screenOffAtomMatcher = CreateScreenTurnedOffAtomMatcher();
*config.add_atom_matcher() = screenOffAtomMatcher;
auto batteryNoneAtomMatcher = CreateBatteryStateNoneMatcher();
*config.add_atom_matcher() = batteryNoneAtomMatcher;
auto batteryUsbAtomMatcher = CreateBatteryStateUsbMatcher();
*config.add_atom_matcher() = batteryUsbAtomMatcher;
// Simple condition with InitialValue set to default (unknown).
auto screenOnUnknownPredicate = CreateScreenIsOnPredicate();
*config.add_predicate() = screenOnUnknownPredicate;
// Simple condition with InitialValue set to false.
auto screenOnFalsePredicate = config.add_predicate();
screenOnFalsePredicate->set_id(StringToId("ScreenIsOnInitialFalse"));
SimplePredicate* simpleScreenOnFalsePredicate =
screenOnFalsePredicate->mutable_simple_predicate();
simpleScreenOnFalsePredicate->set_start(screenOnAtomMatcher.id());
simpleScreenOnFalsePredicate->set_stop(screenOffAtomMatcher.id());
simpleScreenOnFalsePredicate->set_initial_value(SimplePredicate_InitialValue_FALSE);
// Simple condition with InitialValue set to false.
auto onBatteryFalsePredicate = config.add_predicate();
onBatteryFalsePredicate->set_id(StringToId("OnBatteryInitialFalse"));
SimplePredicate* simpleOnBatteryFalsePredicate =
onBatteryFalsePredicate->mutable_simple_predicate();
simpleOnBatteryFalsePredicate->set_start(batteryNoneAtomMatcher.id());
simpleOnBatteryFalsePredicate->set_stop(batteryUsbAtomMatcher.id());
simpleOnBatteryFalsePredicate->set_initial_value(SimplePredicate_InitialValue_FALSE);
// Combination condition with both simple condition InitialValues set to false.
auto screenOnFalseOnBatteryFalsePredicate = config.add_predicate();
screenOnFalseOnBatteryFalsePredicate->set_id(StringToId("ScreenOnFalseOnBatteryFalse"));
screenOnFalseOnBatteryFalsePredicate->mutable_combination()->set_operation(
LogicalOperation::AND);
addPredicateToPredicateCombination(*screenOnFalsePredicate,
screenOnFalseOnBatteryFalsePredicate);
addPredicateToPredicateCombination(*onBatteryFalsePredicate,
screenOnFalseOnBatteryFalsePredicate);
// Combination condition with one simple condition InitialValue set to unknown and one set to
// false.
auto screenOnUnknownOnBatteryFalsePredicate = config.add_predicate();
screenOnUnknownOnBatteryFalsePredicate->set_id(StringToId("ScreenOnUnknowneOnBatteryFalse"));
screenOnUnknownOnBatteryFalsePredicate->mutable_combination()->set_operation(
LogicalOperation::AND);
addPredicateToPredicateCombination(screenOnUnknownPredicate,
screenOnUnknownOnBatteryFalsePredicate);
addPredicateToPredicateCombination(*onBatteryFalsePredicate,
screenOnUnknownOnBatteryFalsePredicate);
// Simple condition metric with initial value false.
ValueMetric* metric1 = config.add_value_metric();
metric1->set_id(StringToId("ValueSubsystemSleepWhileScreenOnInitialFalse"));
metric1->set_what(pulledAtomMatcher.id());
*metric1->mutable_value_field() =
CreateDimensions(util::SUBSYSTEM_SLEEP_STATE, {4 /* time sleeping field */});
metric1->set_bucket(FIVE_MINUTES);
metric1->set_condition(screenOnFalsePredicate->id());
// Simple condition metric with initial value unknown.
ValueMetric* metric2 = config.add_value_metric();
metric2->set_id(StringToId("ValueSubsystemSleepWhileScreenOnInitialUnknown"));
metric2->set_what(pulledAtomMatcher.id());
*metric2->mutable_value_field() =
CreateDimensions(util::SUBSYSTEM_SLEEP_STATE, {4 /* time sleeping field */});
metric2->set_bucket(FIVE_MINUTES);
metric2->set_condition(screenOnUnknownPredicate.id());
// Combination condition metric with initial values false and false.
ValueMetric* metric3 = config.add_value_metric();
metric3->set_id(StringToId("ValueSubsystemSleepWhileScreenOnFalseDeviceUnpluggedFalse"));
metric3->set_what(pulledAtomMatcher.id());
*metric3->mutable_value_field() =
CreateDimensions(util::SUBSYSTEM_SLEEP_STATE, {4 /* time sleeping field */});
metric3->set_bucket(FIVE_MINUTES);
metric3->set_condition(screenOnFalseOnBatteryFalsePredicate->id());
// Combination condition metric with initial values unknown and false.
ValueMetric* metric4 = config.add_value_metric();
metric4->set_id(StringToId("ValueSubsystemSleepWhileScreenOnUnknownDeviceUnpluggedFalse"));
metric4->set_what(pulledAtomMatcher.id());
*metric4->mutable_value_field() =
CreateDimensions(util::SUBSYSTEM_SLEEP_STATE, {4 /* time sleeping field */});
metric4->set_bucket(FIVE_MINUTES);
metric4->set_condition(screenOnUnknownOnBatteryFalsePredicate->id());
return config;
}
bool isSubset(const set<int32_t>& set1, const set<int32_t>& set2) {
return std::includes(set2.begin(), set2.end(), set1.begin(), set1.end());
}
} // anonymous namespace
TEST(MetricsManagerTest, TestInitialConditions) {
UidMap uidMap;
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
sp<AlarmMonitor> anomalyAlarmMonitor;
sp<AlarmMonitor> periodicAlarmMonitor;
StatsdConfig config = buildConfigWithDifferentPredicates();
set<int> allTagIds;
vector<sp<LogMatchingTracker>> allAtomMatchers;
vector<sp<ConditionTracker>> allConditionTrackers;
vector<sp<MetricProducer>> allMetricProducers;
std::vector<sp<AnomalyTracker>> allAnomalyTrackers;
std::vector<sp<AlarmTracker>> allAlarmTrackers;
unordered_map<int, std::vector<int>> conditionToMetricMap;
unordered_map<int, std::vector<int>> trackerToMetricMap;
unordered_map<int, std::vector<int>> trackerToConditionMap;
unordered_map<int, std::vector<int>> activationAtomTrackerToMetricMap;
unordered_map<int, std::vector<int>> deactivationAtomTrackerToMetricMap;
unordered_map<int64_t, int> alertTrackerMap;
vector<int> metricsWithActivation;
std::set<int64_t> noReportMetricIds;
EXPECT_TRUE(initStatsdConfig(
kConfigKey, config, uidMap, pullerManager, anomalyAlarmMonitor, periodicAlarmMonitor,
timeBaseSec, timeBaseSec, allTagIds, allAtomMatchers, allConditionTrackers,
allMetricProducers, allAnomalyTrackers, allAlarmTrackers, conditionToMetricMap,
trackerToMetricMap, trackerToConditionMap, activationAtomTrackerToMetricMap,
deactivationAtomTrackerToMetricMap, alertTrackerMap, metricsWithActivation,
noReportMetricIds));
ASSERT_EQ(4u, allMetricProducers.size());
ASSERT_EQ(5u, allConditionTrackers.size());
ConditionKey queryKey;
vector<ConditionState> conditionCache(5, ConditionState::kNotEvaluated);
allConditionTrackers[3]->isConditionMet(queryKey, allConditionTrackers, false, conditionCache);
allConditionTrackers[4]->isConditionMet(queryKey, allConditionTrackers, false, conditionCache);
EXPECT_EQ(ConditionState::kUnknown, conditionCache[0]);
EXPECT_EQ(ConditionState::kFalse, conditionCache[1]);
EXPECT_EQ(ConditionState::kFalse, conditionCache[2]);
EXPECT_EQ(ConditionState::kFalse, conditionCache[3]);
EXPECT_EQ(ConditionState::kUnknown, conditionCache[4]);
EXPECT_EQ(ConditionState::kFalse, allMetricProducers[0]->mCondition);
EXPECT_EQ(ConditionState::kUnknown, allMetricProducers[1]->mCondition);
EXPECT_EQ(ConditionState::kFalse, allMetricProducers[2]->mCondition);
EXPECT_EQ(ConditionState::kUnknown, allMetricProducers[3]->mCondition);
}
TEST(MetricsManagerTest, TestGoodConfig) {
UidMap uidMap;
sp<StatsPullerManager> pullerManager = new StatsPullerManager();

View File

@@ -24,6 +24,7 @@ using namespace android::os::statsd;
using std::vector;
#ifdef __ANDROID__
TEST(ConditionTrackerTest, TestUnknownCondition) {
LogicalOperation operation = LogicalOperation::AND;

View File

@@ -112,6 +112,114 @@ std::map<int64_t, HashableDimensionKey> getWakeLockQueryKey(
return outputKeyMap;
}
TEST(SimpleConditionTrackerTest, TestNonSlicedInitialValueFalse) {
SimplePredicate simplePredicate;
simplePredicate.set_start(StringToId("SCREEN_TURNED_ON"));
simplePredicate.set_stop(StringToId("SCREEN_TURNED_OFF"));
simplePredicate.set_count_nesting(false);
simplePredicate.set_initial_value(SimplePredicate_InitialValue_FALSE);
unordered_map<int64_t, int> trackerNameIndexMap;
trackerNameIndexMap[StringToId("SCREEN_TURNED_ON")] = 0;
trackerNameIndexMap[StringToId("SCREEN_TURNED_OFF")] = 1;
SimpleConditionTracker conditionTracker(kConfigKey, StringToId("SCREEN_IS_ON"),
0 /*tracker index*/, simplePredicate,
trackerNameIndexMap);
ConditionKey queryKey;
vector<sp<ConditionTracker>> allPredicates;
vector<ConditionState> conditionCache(1, ConditionState::kNotEvaluated);
// Check that initial condition is false.
conditionTracker.isConditionMet(queryKey, allPredicates, false, conditionCache);
EXPECT_EQ(ConditionState::kFalse, conditionCache[0]);
vector<MatchingState> matcherState;
vector<bool> changedCache(1, false);
// Matched stop event.
// Check that condition is still false.
unique_ptr<LogEvent> screenOffEvent =
CreateScreenStateChangedEvent(/*timestamp=*/50, android::view::DISPLAY_STATE_OFF);
matcherState.clear();
matcherState.push_back(MatchingState::kNotMatched); // On matcher not matched
matcherState.push_back(MatchingState::kMatched); // Off matcher matched
conditionCache[0] = ConditionState::kNotEvaluated;
conditionTracker.evaluateCondition(*screenOffEvent, matcherState, allPredicates, conditionCache,
changedCache);
EXPECT_EQ(ConditionState::kFalse, conditionCache[0]);
EXPECT_FALSE(changedCache[0]);
// Matched start event.
// Check that condition has changed to true.
unique_ptr<LogEvent> screenOnEvent =
CreateScreenStateChangedEvent(/*timestamp=*/100, android::view::DISPLAY_STATE_ON);
matcherState.clear();
matcherState.push_back(MatchingState::kMatched); // On matcher matched
matcherState.push_back(MatchingState::kNotMatched); // Off matcher not matched
conditionCache[0] = ConditionState::kNotEvaluated;
changedCache[0] = false;
conditionTracker.evaluateCondition(*screenOnEvent, matcherState, allPredicates, conditionCache,
changedCache);
EXPECT_EQ(ConditionState::kTrue, conditionCache[0]);
EXPECT_TRUE(changedCache[0]);
}
TEST(SimpleConditionTrackerTest, TestNonSlicedInitialValueUnknown) {
SimplePredicate simplePredicate;
simplePredicate.set_start(StringToId("SCREEN_TURNED_ON"));
simplePredicate.set_stop(StringToId("SCREEN_TURNED_OFF"));
simplePredicate.set_count_nesting(false);
simplePredicate.set_initial_value(SimplePredicate_InitialValue_UNKNOWN);
unordered_map<int64_t, int> trackerNameIndexMap;
trackerNameIndexMap[StringToId("SCREEN_TURNED_ON")] = 0;
trackerNameIndexMap[StringToId("SCREEN_TURNED_OFF")] = 1;
SimpleConditionTracker conditionTracker(kConfigKey, StringToId("SCREEN_IS_ON"),
0 /*tracker index*/, simplePredicate,
trackerNameIndexMap);
ConditionKey queryKey;
vector<sp<ConditionTracker>> allPredicates;
vector<ConditionState> conditionCache(1, ConditionState::kNotEvaluated);
// Check that initial condition is unknown.
conditionTracker.isConditionMet(queryKey, allPredicates, false, conditionCache);
EXPECT_EQ(ConditionState::kUnknown, conditionCache[0]);
vector<MatchingState> matcherState;
vector<bool> changedCache(1, false);
// Matched stop event.
// Check that condition is changed to false.
unique_ptr<LogEvent> screenOffEvent =
CreateScreenStateChangedEvent(/*timestamp=*/50, android::view::DISPLAY_STATE_OFF);
matcherState.clear();
matcherState.push_back(MatchingState::kNotMatched); // On matcher not matched
matcherState.push_back(MatchingState::kMatched); // Off matcher matched
conditionCache[0] = ConditionState::kNotEvaluated;
conditionTracker.evaluateCondition(*screenOffEvent, matcherState, allPredicates, conditionCache,
changedCache);
EXPECT_EQ(ConditionState::kFalse, conditionCache[0]);
EXPECT_TRUE(changedCache[0]);
// Matched start event.
// Check that condition has changed to true.
unique_ptr<LogEvent> screenOnEvent =
CreateScreenStateChangedEvent(/*timestamp=*/100, android::view::DISPLAY_STATE_ON);
matcherState.clear();
matcherState.push_back(MatchingState::kMatched); // On matcher matched
matcherState.push_back(MatchingState::kNotMatched); // Off matcher not matched
conditionCache[0] = ConditionState::kNotEvaluated;
changedCache[0] = false;
conditionTracker.evaluateCondition(*screenOnEvent, matcherState, allPredicates, conditionCache,
changedCache);
EXPECT_EQ(ConditionState::kTrue, conditionCache[0]);
EXPECT_TRUE(changedCache[0]);
}
TEST(SimpleConditionTrackerTest, TestNonSlicedCondition) {
SimplePredicate simplePredicate;
simplePredicate.set_start(StringToId("SCREEN_TURNED_ON"));

View File

@@ -74,8 +74,8 @@ TEST(CountMetricProducerTest, TestFirstBucket) {
metric.set_bucket(ONE_MINUTE);
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
CountMetricProducer countProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, 5,
600 * NS_PER_SEC + NS_PER_SEC / 2);
CountMetricProducer countProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, 5, 600 * NS_PER_SEC + NS_PER_SEC / 2);
EXPECT_EQ(600500000000, countProducer.mCurrentBucketStartTimeNs);
EXPECT_EQ(10, countProducer.mCurrentBucketNum);
EXPECT_EQ(660000000005, countProducer.getCurrentBucketEndTimeNs());
@@ -94,8 +94,8 @@ TEST(CountMetricProducerTest, TestNonDimensionalEvents) {
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
CountMetricProducer countProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
bucketStartTimeNs, bucketStartTimeNs);
CountMetricProducer countProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, bucketStartTimeNs, bucketStartTimeNs);
// 2 events in bucket 1.
LogEvent event1(/*uid=*/0, /*pid=*/0);
@@ -157,8 +157,8 @@ TEST(CountMetricProducerTest, TestEventsWithNonSlicedCondition) {
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
CountMetricProducer countProducer(kConfigKey, metric, 1, wizard, bucketStartTimeNs,
bucketStartTimeNs);
CountMetricProducer countProducer(kConfigKey, metric, 0, {ConditionState::kUnknown}, wizard,
bucketStartTimeNs, bucketStartTimeNs);
countProducer.onConditionChanged(true, bucketStartTimeNs);
@@ -220,12 +220,14 @@ TEST(CountMetricProducerTest, TestEventsWithSlicedCondition) {
getMockedDimensionKey(conditionTagId, 2, "222")};
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
EXPECT_CALL(*wizard, query(_, key1, _)).WillOnce(Return(ConditionState::kFalse));
EXPECT_CALL(*wizard, query(_, key2, _)).WillOnce(Return(ConditionState::kTrue));
CountMetricProducer countProducer(kConfigKey, metric, 1 /*condition tracker index*/, wizard,
bucketStartTimeNs, bucketStartTimeNs);
CountMetricProducer countProducer(kConfigKey, metric, 0 /*condition tracker index*/,
{ConditionState::kUnknown}, wizard, bucketStartTimeNs,
bucketStartTimeNs);
countProducer.onMatchedLogEvent(1 /*log matcher index*/, event1);
countProducer.flushIfNeededLocked(bucketStartTimeNs + 1);
@@ -261,7 +263,8 @@ TEST_P(CountMetricProducerTest_PartialBucket, TestSplitInCurrentBucket) {
alert.set_trigger_if_sum_gt(2);
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
CountMetricProducer countProducer(kConfigKey, metric, -1 /* no condition */, wizard,
CountMetricProducer countProducer(kConfigKey, metric, -1 /* no condition */, {}, wizard,
bucketStartTimeNs, bucketStartTimeNs);
sp<AnomalyTracker> anomalyTracker = countProducer.addAnomalyTracker(alert, alarmMonitor);
@@ -327,7 +330,8 @@ TEST_P(CountMetricProducerTest_PartialBucket, TestSplitInNextBucket) {
metric.set_bucket(ONE_MINUTE);
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
CountMetricProducer countProducer(kConfigKey, metric, -1 /* no condition */, wizard,
CountMetricProducer countProducer(kConfigKey, metric, -1 /* no condition */, {}, wizard,
bucketStartTimeNs, bucketStartTimeNs);
// Bucket is flushed yet.
@@ -391,8 +395,9 @@ TEST(CountMetricProducerTest, TestAnomalyDetectionUnSliced) {
metric.set_bucket(ONE_MINUTE);
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
CountMetricProducer countProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
bucketStartTimeNs, bucketStartTimeNs);
CountMetricProducer countProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, bucketStartTimeNs, bucketStartTimeNs);
sp<AnomalyTracker> anomalyTracker = countProducer.addAnomalyTracker(alert, alarmMonitor);
@@ -453,8 +458,8 @@ TEST(CountMetricProducerTest, TestOneWeekTimeUnit) {
int64_t oneDayNs = 24 * 60 * 60 * 1e9;
int64_t fiveWeeksNs = 5 * 7 * oneDayNs;
CountMetricProducer countProducer(
kConfigKey, metric, -1 /* meaning no condition */, wizard, oneDayNs, fiveWeeksNs);
CountMetricProducer countProducer(kConfigKey, metric, -1 /* meaning no condition */, {}, wizard,
oneDayNs, fiveWeeksNs);
int64_t fiveWeeksOneDayNs = fiveWeeksNs + oneDayNs;

View File

@@ -70,9 +70,11 @@ TEST(DurationMetricTrackerTest, TestFirstBucket) {
metric.set_aggregation_type(DurationMetric_AggregationType_SUM);
FieldMatcher dimensions;
DurationMetricProducer durationProducer(
kConfigKey, metric, -1 /*no condition*/, 1 /* start index */, 2 /* stop index */,
3 /* stop_all index */, false /*nesting*/, wizard, dimensions, 5, 600 * NS_PER_SEC + NS_PER_SEC/2);
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /*no condition*/, {},
1 /* start index */, 2 /* stop index */,
3 /* stop_all index */, false /*nesting*/, wizard,
dimensions, 5, 600 * NS_PER_SEC + NS_PER_SEC / 2);
EXPECT_EQ(600500000000, durationProducer.mCurrentBucketStartTimeNs);
EXPECT_EQ(10, durationProducer.mCurrentBucketNum);
@@ -96,7 +98,8 @@ TEST(DurationMetricTrackerTest, TestNoCondition) {
makeLogEvent(&event2, bucketStartTimeNs + bucketSizeNs + 2, tagId);
FieldMatcher dimensions;
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /*no condition*/,
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /*no condition*/, {},
1 /* start index */, 2 /* stop index */,
3 /* stop_all index */, false /*nesting*/, wizard,
dimensions, bucketStartTimeNs, bucketStartTimeNs);
@@ -138,10 +141,11 @@ TEST(DurationMetricTrackerTest, TestNonSlicedCondition) {
makeLogEvent(&event4, bucketStartTimeNs + bucketSizeNs + 3, tagId);
FieldMatcher dimensions;
DurationMetricProducer durationProducer(kConfigKey, metric, 0 /* condition index */,
1 /* start index */, 2 /* stop index */,
3 /* stop_all index */, false /*nesting*/, wizard,
dimensions, bucketStartTimeNs, bucketStartTimeNs);
DurationMetricProducer durationProducer(
kConfigKey, metric, 0 /* condition index */, {ConditionState::kUnknown},
1 /* start index */, 2 /* stop index */, 3 /* stop_all index */, false /*nesting*/,
wizard, dimensions, bucketStartTimeNs, bucketStartTimeNs);
durationProducer.mCondition = ConditionState::kFalse;
EXPECT_FALSE(durationProducer.mCondition);
@@ -187,10 +191,11 @@ TEST(DurationMetricTrackerTest, TestNonSlicedConditionUnknownState) {
makeLogEvent(&event4, bucketStartTimeNs + bucketSizeNs + 3, tagId);
FieldMatcher dimensions;
DurationMetricProducer durationProducer(kConfigKey, metric, 0 /* condition index */,
1 /* start index */, 2 /* stop index */,
3 /* stop_all index */, false /*nesting*/, wizard,
dimensions, bucketStartTimeNs, bucketStartTimeNs);
DurationMetricProducer durationProducer(
kConfigKey, metric, 0 /* condition index */, {ConditionState::kUnknown},
1 /* start index */, 2 /* stop index */, 3 /* stop_all index */, false /*nesting*/,
wizard, dimensions, bucketStartTimeNs, bucketStartTimeNs);
EXPECT_EQ(ConditionState::kUnknown, durationProducer.mCondition);
EXPECT_FALSE(durationProducer.isConditionSliced());
@@ -232,7 +237,8 @@ TEST_P(DurationMetricProducerTest_PartialBucket, TestSumDuration) {
metric.set_aggregation_type(DurationMetric_AggregationType_SUM);
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
FieldMatcher dimensions;
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */,
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, {},
1 /* start index */, 2 /* stop index */,
3 /* stop_all index */, false /*nesting*/, wizard,
dimensions, bucketStartTimeNs, bucketStartTimeNs);
@@ -294,7 +300,8 @@ TEST_P(DurationMetricProducerTest_PartialBucket, TestSumDurationWithSplitInFollo
metric.set_aggregation_type(DurationMetric_AggregationType_SUM);
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
FieldMatcher dimensions;
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */,
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, {},
1 /* start index */, 2 /* stop index */,
3 /* stop_all index */, false /*nesting*/, wizard,
dimensions, bucketStartTimeNs, bucketStartTimeNs);
@@ -357,7 +364,8 @@ TEST_P(DurationMetricProducerTest_PartialBucket, TestSumDurationAnomaly) {
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
FieldMatcher dimensions;
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */,
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, {},
1 /* start index */, 2 /* stop index */,
3 /* stop_all index */, false /*nesting*/, wizard,
dimensions, bucketStartTimeNs, bucketStartTimeNs);
@@ -402,7 +410,8 @@ TEST_P(DurationMetricProducerTest_PartialBucket, TestMaxDuration) {
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
FieldMatcher dimensions;
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */,
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, {},
1 /* start index */, 2 /* stop index */,
3 /* stop_all index */, false /*nesting*/, wizard,
dimensions, bucketStartTimeNs, bucketStartTimeNs);
@@ -455,7 +464,8 @@ TEST_P(DurationMetricProducerTest_PartialBucket, TestMaxDurationWithSplitInNextB
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
FieldMatcher dimensions;
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */,
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, {},
1 /* start index */, 2 /* stop index */,
3 /* stop_all index */, false /*nesting*/, wizard,
dimensions, bucketStartTimeNs, bucketStartTimeNs);

View File

@@ -65,8 +65,8 @@ TEST(EventMetricProducerTest, TestNoCondition) {
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
EventMetricProducer eventProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
bucketStartTimeNs);
EventMetricProducer eventProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, bucketStartTimeNs);
eventProducer.onMatchedLogEvent(1 /*matcher index*/, event1);
eventProducer.onMatchedLogEvent(1 /*matcher index*/, event2);
@@ -101,7 +101,8 @@ TEST(EventMetricProducerTest, TestEventsWithNonSlicedCondition) {
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
EventMetricProducer eventProducer(kConfigKey, metric, 1, wizard, bucketStartTimeNs);
EventMetricProducer eventProducer(kConfigKey, metric, 0 /*condition index*/,
{ConditionState::kUnknown}, wizard, bucketStartTimeNs);
eventProducer.onConditionChanged(true /*condition*/, bucketStartTimeNs);
eventProducer.onMatchedLogEvent(1 /*matcher index*/, event1);
@@ -155,7 +156,8 @@ TEST(EventMetricProducerTest, TestEventsWithSlicedCondition) {
// Condition is true for second event.
EXPECT_CALL(*wizard, query(_, key2, _)).WillOnce(Return(ConditionState::kTrue));
EventMetricProducer eventProducer(kConfigKey, metric, 1, wizard, bucketStartTimeNs);
EventMetricProducer eventProducer(kConfigKey, metric, 0 /*condition index*/,
{ConditionState::kUnknown}, wizard, bucketStartTimeNs);
eventProducer.onMatchedLogEvent(1 /*matcher index*/, event1);
eventProducer.onMatchedLogEvent(1 /*matcher index*/, event2);

View File

@@ -104,10 +104,9 @@ TEST(GaugeMetricProducerTest, TestFirstBucket) {
// statsd started long ago.
// The metric starts in the middle of the bucket
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
logEventMatcherIndex, eventMatcherWizard,
-1, -1, tagId, 5, 600 * NS_PER_SEC + NS_PER_SEC / 2,
pullerManager);
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, logEventMatcherIndex, eventMatcherWizard, -1, -1,
tagId, 5, 600 * NS_PER_SEC + NS_PER_SEC / 2, pullerManager);
gaugeProducer.prepareFirstBucket();
EXPECT_EQ(600500000000, gaugeProducer.mCurrentBucketStartTimeNs);
@@ -147,9 +146,9 @@ TEST(GaugeMetricProducerTest, TestPulledEventsNoCondition) {
return true;
}));
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
logEventMatcherIndex, eventMatcherWizard, tagId, -1, tagId,
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, logEventMatcherIndex, eventMatcherWizard, tagId, -1,
tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
gaugeProducer.prepareFirstBucket();
vector<shared_ptr<LogEvent>> allData;
@@ -225,8 +224,8 @@ TEST_P(GaugeMetricProducerTest_PartialBucket, TestPushedEvents) {
new EventMatcherWizard({new SimpleLogMatchingTracker(
atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)});
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
logEventMatcherIndex, eventMatcherWizard,
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, logEventMatcherIndex, eventMatcherWizard,
-1 /* -1 means no pulling */, -1, tagId, bucketStartTimeNs,
bucketStartTimeNs, pullerManager);
gaugeProducer.prepareFirstBucket();
@@ -308,7 +307,6 @@ TEST_P(GaugeMetricProducerTest_PartialBucket, TestPulled) {
sp<EventMatcherWizard> eventMatcherWizard =
new EventMatcherWizard({new SimpleLogMatchingTracker(
atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)});
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return());
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return());
@@ -322,9 +320,9 @@ TEST_P(GaugeMetricProducerTest_PartialBucket, TestPulled) {
return true;
}));
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
logEventMatcherIndex, eventMatcherWizard, tagId, -1, tagId,
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, logEventMatcherIndex, eventMatcherWizard, tagId, -1,
tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
gaugeProducer.prepareFirstBucket();
vector<shared_ptr<LogEvent>> allData;
@@ -393,9 +391,9 @@ TEST(GaugeMetricProducerTest, TestPulledWithAppUpgradeDisabled) {
EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _))
.WillOnce(Return(false));
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
logEventMatcherIndex, eventMatcherWizard, tagId, -1, tagId,
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, logEventMatcherIndex, eventMatcherWizard, tagId, -1,
tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
gaugeProducer.prepareFirstBucket();
vector<shared_ptr<LogEvent>> allData;
@@ -450,7 +448,8 @@ TEST(GaugeMetricProducerTest, TestPulledEventsWithCondition) {
return true;
}));
GaugeMetricProducer gaugeProducer(kConfigKey, metric, 1, wizard, logEventMatcherIndex,
GaugeMetricProducer gaugeProducer(kConfigKey, metric, 0 /*condition index*/,
{ConditionState::kUnknown}, wizard, logEventMatcherIndex,
eventMatcherWizard, tagId, -1, tagId, bucketStartTimeNs,
bucketStartTimeNs, pullerManager);
gaugeProducer.prepareFirstBucket();
@@ -536,7 +535,8 @@ TEST(GaugeMetricProducerTest, TestPulledEventsWithSlicedCondition) {
return true;
}));
GaugeMetricProducer gaugeProducer(kConfigKey, metric, 1, wizard, logEventMatcherIndex,
GaugeMetricProducer gaugeProducer(kConfigKey, metric, 0 /*condition index*/,
{ConditionState::kUnknown}, wizard, logEventMatcherIndex,
eventMatcherWizard, tagId, -1, tagId, bucketStartTimeNs,
bucketStartTimeNs, pullerManager);
gaugeProducer.prepareFirstBucket();
@@ -584,9 +584,9 @@ TEST(GaugeMetricProducerTest, TestPulledEventsAnomalyDetection) {
new EventMatcherWizard({new SimpleLogMatchingTracker(
atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)});
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
logEventMatcherIndex, eventMatcherWizard, tagId, -1, tagId,
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, logEventMatcherIndex, eventMatcherWizard, tagId, -1,
tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
gaugeProducer.prepareFirstBucket();
Alert alert;
@@ -683,9 +683,10 @@ TEST(GaugeMetricProducerTest, TestPullOnTrigger) {
.WillOnce(Return(true));
int triggerId = 5;
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
logEventMatcherIndex, eventMatcherWizard, tagId, triggerId,
tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, logEventMatcherIndex, eventMatcherWizard, tagId,
triggerId, tagId, bucketStartTimeNs, bucketStartTimeNs,
pullerManager);
gaugeProducer.prepareFirstBucket();
ASSERT_EQ(0UL, gaugeProducer.mCurrentSlicedBucket->size());
@@ -761,9 +762,10 @@ TEST(GaugeMetricProducerTest, TestRemoveDimensionInOutput) {
.WillOnce(Return(true));
int triggerId = 5;
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
logEventMatcherIndex, eventMatcherWizard, tagId, triggerId,
tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, logEventMatcherIndex, eventMatcherWizard, tagId,
triggerId, tagId, bucketStartTimeNs, bucketStartTimeNs,
pullerManager);
gaugeProducer.prepareFirstBucket();
LogEvent triggerEvent(/*uid=*/0, /*pid=*/0);
@@ -823,9 +825,10 @@ TEST(GaugeMetricProducerTest_BucketDrop, TestBucketDropWhenBucketTooSmall) {
}));
int triggerId = 5;
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
logEventMatcherIndex, eventMatcherWizard, tagId, triggerId,
tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, logEventMatcherIndex, eventMatcherWizard, tagId,
triggerId, tagId, bucketStartTimeNs, bucketStartTimeNs,
pullerManager);
gaugeProducer.prepareFirstBucket();
LogEvent triggerEvent(/*uid=*/0, /*pid=*/0);

View File

@@ -111,15 +111,17 @@ public:
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _))
.WillRepeatedly(Return());
sp<ValueMetricProducer> valueProducer = new ValueMetricProducer(
kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, logEventMatcherIndex,
eventMatcherWizard, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
sp<ValueMetricProducer> valueProducer =
new ValueMetricProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, logEventMatcherIndex, eventMatcherWizard, tagId,
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
valueProducer->prepareFirstBucket();
return valueProducer;
}
static sp<ValueMetricProducer> createValueProducerWithCondition(
sp<MockStatsPullerManager>& pullerManager, ValueMetric& metric) {
sp<MockStatsPullerManager>& pullerManager, ValueMetric& metric,
ConditionState conditionAfterFirstBucketPrepared) {
UidMap uidMap;
SimpleAtomMatcher atomMatcher;
atomMatcher.set_atom_id(tagId);
@@ -133,31 +135,11 @@ public:
.WillRepeatedly(Return());
sp<ValueMetricProducer> valueProducer = new ValueMetricProducer(
kConfigKey, metric, 1, wizard, logEventMatcherIndex, eventMatcherWizard, tagId,
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
valueProducer->prepareFirstBucket();
valueProducer->mCondition = ConditionState::kFalse;
return valueProducer;
}
static sp<ValueMetricProducer> createValueProducerWithNoInitialCondition(
sp<MockStatsPullerManager>& pullerManager, ValueMetric& metric) {
UidMap uidMap;
SimpleAtomMatcher atomMatcher;
atomMatcher.set_atom_id(tagId);
sp<EventMatcherWizard> eventMatcherWizard =
new EventMatcherWizard({new SimpleLogMatchingTracker(
atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)});
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _))
.WillOnce(Return());
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _))
.WillRepeatedly(Return());
sp<ValueMetricProducer> valueProducer = new ValueMetricProducer(
kConfigKey, metric, 1, wizard, logEventMatcherIndex, eventMatcherWizard, tagId,
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
kConfigKey, metric, 0 /*condition index*/, {ConditionState::kUnknown}, wizard,
logEventMatcherIndex, eventMatcherWizard, tagId, bucketStartTimeNs,
bucketStartTimeNs, pullerManager);
valueProducer->prepareFirstBucket();
valueProducer->mCondition = conditionAfterFirstBucketPrepared;
return valueProducer;
}
@@ -176,8 +158,9 @@ public:
.WillOnce(Return());
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _))
.WillRepeatedly(Return());
sp<ValueMetricProducer> valueProducer = new ValueMetricProducer(
kConfigKey, metric, -1 /* no condition */, wizard, logEventMatcherIndex,
kConfigKey, metric, -1 /* no condition */, {}, wizard, logEventMatcherIndex,
eventMatcherWizard, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager, {},
{}, slicedStateAtoms, stateGroupMap);
valueProducer->prepareFirstBucket();
@@ -232,9 +215,9 @@ TEST(ValueMetricProducerTest, TestCalcPreviousBucketEndTime) {
// statsd started long ago.
// The metric starts in the middle of the bucket
ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
logEventMatcherIndex, eventMatcherWizard, -1, startTimeBase,
22, pullerManager);
ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, logEventMatcherIndex, eventMatcherWizard, -1,
startTimeBase, 22, pullerManager);
valueProducer.prepareFirstBucket();
EXPECT_EQ(startTimeBase, valueProducer.calcPreviousBucketEndTime(60 * NS_PER_SEC + 10));
@@ -262,8 +245,8 @@ TEST(ValueMetricProducerTest, TestFirstBucket) {
// statsd started long ago.
// The metric starts in the middle of the bucket
ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
logEventMatcherIndex, eventMatcherWizard, -1, 5,
ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, logEventMatcherIndex, eventMatcherWizard, -1, 5,
600 * NS_PER_SEC + NS_PER_SEC / 2, pullerManager);
valueProducer.prepareFirstBucket();
@@ -427,7 +410,7 @@ TEST(ValueMetricProducerTest, TestPulledEventsWithFiltering) {
}));
sp<ValueMetricProducer> valueProducer = new ValueMetricProducer(
kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, logEventMatcherIndex,
kConfigKey, metric, -1 /*-1 meaning no condition*/, {}, wizard, logEventMatcherIndex,
eventMatcherWizard, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
valueProducer->prepareFirstBucket();
@@ -629,7 +612,8 @@ TEST(ValueMetricProducerTest, TestEventsWithNonSlicedCondition) {
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
@@ -689,7 +673,8 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestPushedEvents) {
atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)});
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
pullerManager);
valueProducer.prepareFirstBucket();
@@ -762,7 +747,8 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestPulledValue) {
data->push_back(CreateRepeatedValueLogEvent(tagId, partialBucketSplitTimeNs, 120));
return true;
}));
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
eventMatcherWizard, tagId, bucketStartTimeNs,
bucketStartTimeNs, pullerManager);
valueProducer.prepareFirstBucket();
@@ -813,7 +799,8 @@ TEST(ValueMetricProducerTest, TestPulledWithAppUpgradeDisabled) {
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return());
EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _))
.WillOnce(Return(true));
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
eventMatcherWizard, tagId, bucketStartTimeNs,
bucketStartTimeNs, pullerManager);
valueProducer.prepareFirstBucket();
@@ -851,7 +838,8 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestPulledValueWhileConditionFalse
return true;
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
valueProducer->onConditionChanged(true, bucketStartTimeNs + 1);
@@ -875,6 +863,7 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestPulledValueWhileConditionFalse
{bucketStartTimeNs}, {partialBucketSplitTimeNs});
EXPECT_FALSE(valueProducer->mCondition);
}
TEST(ValueMetricProducerTest, TestPushedEventsWithoutCondition) {
ValueMetric metric = ValueMetricProducerTestHelper::createMetric();
@@ -887,7 +876,7 @@ TEST(ValueMetricProducerTest, TestPushedEventsWithoutCondition) {
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
pullerManager);
valueProducer.prepareFirstBucket();
@@ -931,9 +920,9 @@ TEST(ValueMetricProducerTest, TestPushedEventsWithCondition) {
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
ValueMetricProducer valueProducer(kConfigKey, metric, 1, wizard, logEventMatcherIndex,
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
pullerManager);
ValueMetricProducer valueProducer(kConfigKey, metric, 0, {ConditionState::kUnknown}, wizard,
logEventMatcherIndex, eventMatcherWizard, -1,
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
valueProducer.prepareFirstBucket();
valueProducer.mCondition = ConditionState::kFalse;
@@ -1001,9 +990,11 @@ TEST(ValueMetricProducerTest, TestAnomalyDetection) {
atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)});
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
logEventMatcherIndex, eventMatcherWizard, -1 /*not pulled*/,
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
wizard, logEventMatcherIndex, eventMatcherWizard,
-1 /*not pulled*/, bucketStartTimeNs, bucketStartTimeNs,
pullerManager);
valueProducer.prepareFirstBucket();
sp<AnomalyTracker> anomalyTracker = valueProducer.addAnomalyTracker(alert, alarmMonitor);
@@ -1158,7 +1149,8 @@ TEST(ValueMetricProducerTest, TestBucketBoundaryWithCondition) {
return true;
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
@@ -1229,7 +1221,8 @@ TEST(ValueMetricProducerTest, TestBucketBoundaryWithCondition2) {
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
@@ -1300,7 +1293,7 @@ TEST(ValueMetricProducerTest, TestPushedAggregateMin) {
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
pullerManager);
valueProducer.prepareFirstBucket();
@@ -1344,7 +1337,7 @@ TEST(ValueMetricProducerTest, TestPushedAggregateMax) {
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
pullerManager);
valueProducer.prepareFirstBucket();
@@ -1387,7 +1380,7 @@ TEST(ValueMetricProducerTest, TestPushedAggregateAvg) {
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
pullerManager);
valueProducer.prepareFirstBucket();
@@ -1435,7 +1428,7 @@ TEST(ValueMetricProducerTest, TestPushedAggregateSum) {
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
pullerManager);
valueProducer.prepareFirstBucket();
@@ -1479,7 +1472,7 @@ TEST(ValueMetricProducerTest, TestSkipZeroDiffOutput) {
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
pullerManager);
valueProducer.prepareFirstBucket();
@@ -1551,7 +1544,7 @@ TEST(ValueMetricProducerTest, TestSkipZeroDiffOutputMultiValue) {
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
pullerManager);
valueProducer.prepareFirstBucket();
@@ -1944,7 +1937,8 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullFailAfterConditionChange_EndOfB
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
// has one slice
@@ -1979,7 +1973,8 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullFailAfterConditionChange) {
.WillOnce(Return(false));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
@@ -2023,7 +2018,8 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullFailBeforeConditionChange) {
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
// Don't directly set mCondition; the real code never does that. Go through regular code path
// to avoid unexpected behaviors.
@@ -2057,9 +2053,8 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullDelayExceeded) {
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
valueProducer->mCondition = ConditionState::kFalse;
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
// Max delay is set to 0 so pull will exceed max delay.
valueProducer->onConditionChanged(true, bucketStartTimeNs + 1);
@@ -2080,9 +2075,9 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullTooLate) {
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return());
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillRepeatedly(Return());
ValueMetricProducer valueProducer(kConfigKey, metric, 1, wizard, logEventMatcherIndex,
eventMatcherWizard, tagId, bucket2StartTimeNs,
bucket2StartTimeNs, pullerManager);
ValueMetricProducer valueProducer(kConfigKey, metric, 0, {ConditionState::kUnknown}, wizard,
logEventMatcherIndex, eventMatcherWizard, tagId,
bucket2StartTimeNs, bucket2StartTimeNs, pullerManager);
valueProducer.prepareFirstBucket();
valueProducer.mCondition = ConditionState::kFalse;
@@ -2105,9 +2100,8 @@ TEST(ValueMetricProducerTest, TestBaseSetOnConditionChange) {
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
valueProducer->mCondition = ConditionState::kFalse;
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
valueProducer->mHasGlobalBase = false;
valueProducer->onConditionChanged(true, bucketStartTimeNs + 1);
@@ -2142,9 +2136,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenOneConditionFailed
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
valueProducer->mCondition = ConditionState::kTrue;
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kTrue);
// Bucket start.
vector<shared_ptr<LogEvent>> allData;
@@ -2218,8 +2211,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenGuardRailHit) {
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
valueProducer->mCondition = ConditionState::kFalse;
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
valueProducer->onConditionChanged(true, bucketStartTimeNs + 2);
EXPECT_EQ(true, valueProducer->mCurrentBucketIsSkipped);
@@ -2283,9 +2276,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenInitialPullFailed)
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
valueProducer->mCondition = ConditionState::kTrue;
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kTrue);
// Bucket start.
vector<shared_ptr<LogEvent>> allData;
@@ -2363,9 +2355,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenLastPullFailed) {
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
valueProducer->mCondition = ConditionState::kTrue;
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kTrue);
// Bucket start.
vector<shared_ptr<LogEvent>> allData;
@@ -2468,7 +2459,8 @@ TEST(ValueMetricProducerTest, TestEmptyDataResetsBase_onConditionChanged) {
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
ASSERT_EQ(1UL, valueProducer->mCurrentSlicedBucket.size());
@@ -2518,7 +2510,8 @@ TEST(ValueMetricProducerTest, TestEmptyDataResetsBase_onBucketBoundary) {
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
valueProducer->onConditionChanged(false, bucketStartTimeNs + 11);
@@ -2566,7 +2559,8 @@ TEST(ValueMetricProducerTest, TestPartialResetOnBucketBoundaries) {
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
ASSERT_EQ(1UL, valueProducer->mCurrentSlicedBucket.size());
@@ -2673,8 +2667,8 @@ TEST(ValueMetricProducerTest, TestBucketBoundariesOnConditionChange) {
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
valueProducer->mCondition = ConditionState::kUnknown;
ValueMetricProducerTestHelper::createValueProducerWithCondition(
pullerManager, metric, ConditionState::kUnknown);
valueProducer->onConditionChanged(false, bucketStartTimeNs);
ASSERT_EQ(0UL, valueProducer->mCurrentSlicedBucket.size());
@@ -2814,7 +2808,8 @@ TEST(ValueMetricProducerTest, TestDataIsNotUpdatedWhenNoConditionChanged) {
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
valueProducer->onConditionChanged(false, bucketStartTimeNs + 10);
@@ -2866,7 +2861,8 @@ TEST(ValueMetricProducerTest, TestBucketInvalidIfGlobalBaseIsNotSet) {
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
valueProducer->onConditionChanged(true, bucket2StartTimeNs + 10);
vector<shared_ptr<LogEvent>> allData;
@@ -2911,7 +2907,7 @@ TEST(ValueMetricProducerTest, TestPullNeededFastDump) {
return true;
}));
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
eventMatcherWizard, tagId, bucketStartTimeNs,
bucketStartTimeNs, pullerManager);
valueProducer.prepareFirstBucket();
@@ -2949,7 +2945,7 @@ TEST(ValueMetricProducerTest, TestFastDumpWithoutCurrentBucket) {
return true;
}));
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
eventMatcherWizard, tagId, bucketStartTimeNs,
bucketStartTimeNs, pullerManager);
valueProducer.prepareFirstBucket();
@@ -3002,7 +2998,7 @@ TEST(ValueMetricProducerTest, TestPullNeededNoTimeConstraints) {
return true;
}));
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
eventMatcherWizard, tagId, bucketStartTimeNs,
bucketStartTimeNs, pullerManager);
valueProducer.prepareFirstBucket();
@@ -3058,8 +3054,8 @@ TEST(ValueMetricProducerTest, TestPulledData_noDiff_withMultipleConditionChanges
return true;
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
valueProducer->mCondition = ConditionState::kFalse;
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
valueProducer->onConditionChanged(false, bucketStartTimeNs + 50);
@@ -3099,8 +3095,8 @@ TEST(ValueMetricProducerTest, TestPulledData_noDiff_bucketBoundaryTrue) {
return true;
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
valueProducer->mCondition = ConditionState::kFalse;
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
@@ -3124,8 +3120,8 @@ TEST(ValueMetricProducerTest, TestPulledData_noDiff_bucketBoundaryFalse) {
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
valueProducer->mCondition = ConditionState::kFalse;
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
// Now the alarm is delivered. Condition is off though.
vector<shared_ptr<LogEvent>> allData;
@@ -3152,8 +3148,8 @@ TEST(ValueMetricProducerTest, TestPulledData_noDiff_withFailure) {
}))
.WillOnce(Return(false));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
valueProducer->mCondition = ConditionState::kFalse;
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
valueProducer->onConditionChanged(false, bucketStartTimeNs + 50);
@@ -3191,7 +3187,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenDumpReportRequeste
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
// Condition change event.
valueProducer->onConditionChanged(true, bucketStartTimeNs + 20);
@@ -3236,7 +3233,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenConditionEventWron
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
// Condition change event.
valueProducer->onConditionChanged(true, bucketStartTimeNs + 50);
@@ -3298,7 +3296,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenAccumulateEventWro
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
// Condition change event.
valueProducer->onConditionChanged(true, bucketStartTimeNs + 50);
@@ -3363,8 +3362,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenConditionUnknown)
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithNoInitialCondition(pullerManager,
metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(
pullerManager, metric, ConditionState::kUnknown);
// Condition change event.
valueProducer->onConditionChanged(true, bucketStartTimeNs + 50);
@@ -3413,7 +3412,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenPullFailed) {
.WillOnce(Return(false));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
// Condition change event.
valueProducer->onConditionChanged(true, bucketStartTimeNs + 50);
@@ -3468,7 +3468,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenMultipleBucketsSki
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
// Condition change event.
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
@@ -3542,7 +3543,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestBucketDropWhenBucketTooSmall) {
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
// Condition change event.
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
@@ -3579,7 +3581,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestBucketDropWhenDataUnavailable) {
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(
pullerManager, metric, ConditionState::kUnknown);
// Check dump report.
ProtoOutputStream output;
@@ -3632,7 +3635,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestBucketDropWhenForceBucketSplitBefor
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
ConditionState::kFalse);
// Condition changed event
int64_t conditionChangeTimeNs = bucketStartTimeNs + 10;
@@ -3687,8 +3691,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestMultipleBucketDropEvents) {
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithNoInitialCondition(pullerManager,
metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(
pullerManager, metric, ConditionState::kUnknown);
// Condition change event.
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
@@ -3756,8 +3760,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestMaxBucketDropEvents) {
}));
sp<ValueMetricProducer> valueProducer =
ValueMetricProducerTestHelper::createValueProducerWithNoInitialCondition(pullerManager,
metric);
ValueMetricProducerTestHelper::createValueProducerWithCondition(
pullerManager, metric, ConditionState::kUnknown);
// First condition change event causes guardrail to be reached.
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);