Merge "Pass initial conditions to combination conditions and metrics" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c5111c995b
@@ -37,7 +37,8 @@ CombinationConditionTracker::~CombinationConditionTracker() {
|
|||||||
bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConfig,
|
bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConfig,
|
||||||
const vector<sp<ConditionTracker>>& allConditionTrackers,
|
const vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||||
const unordered_map<int64_t, int>& conditionIdIndexMap,
|
const unordered_map<int64_t, int>& conditionIdIndexMap,
|
||||||
vector<bool>& stack) {
|
vector<bool>& stack,
|
||||||
|
vector<ConditionState>& initialConditionCache) {
|
||||||
VLOG("Combination predicate init() %lld", (long long)mConditionId);
|
VLOG("Combination predicate init() %lld", (long long)mConditionId);
|
||||||
if (mInitialized) {
|
if (mInitialized) {
|
||||||
return true;
|
return true;
|
||||||
@@ -73,9 +74,9 @@ bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConf
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool initChildSucceeded =
|
||||||
bool initChildSucceeded = childTracker->init(allConditionConfig, allConditionTrackers,
|
childTracker->init(allConditionConfig, allConditionTrackers, conditionIdIndexMap,
|
||||||
conditionIdIndexMap, stack);
|
stack, initialConditionCache);
|
||||||
|
|
||||||
if (!initChildSucceeded) {
|
if (!initChildSucceeded) {
|
||||||
ALOGW("Child initialization failed %lld ", (long long)child);
|
ALOGW("Child initialization failed %lld ", (long long)child);
|
||||||
@@ -95,6 +96,11 @@ bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConf
|
|||||||
childTracker->getLogTrackerIndex().end());
|
childTracker->getLogTrackerIndex().end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mUnSlicedPartCondition = evaluateCombinationCondition(mUnSlicedChildren, mLogicalOperation,
|
||||||
|
initialConditionCache);
|
||||||
|
initialConditionCache[mIndex] =
|
||||||
|
evaluateCombinationCondition(mChildren, mLogicalOperation, initialConditionCache);
|
||||||
|
|
||||||
// unmark this node in the recursion stack.
|
// unmark this node in the recursion stack.
|
||||||
stack[mIndex] = false;
|
stack[mIndex] = false;
|
||||||
|
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ public:
|
|||||||
|
|
||||||
bool init(const std::vector<Predicate>& allConditionConfig,
|
bool init(const std::vector<Predicate>& allConditionConfig,
|
||||||
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
|
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||||
const std::unordered_map<int64_t, int>& conditionIdIndexMap,
|
const std::unordered_map<int64_t, int>& conditionIdIndexMap, std::vector<bool>& stack,
|
||||||
std::vector<bool>& stack) override;
|
std::vector<ConditionState>& initialConditionCache) override;
|
||||||
|
|
||||||
void evaluateCondition(const LogEvent& event,
|
void evaluateCondition(const LogEvent& event,
|
||||||
const std::vector<MatchingState>& eventMatcherValues,
|
const std::vector<MatchingState>& eventMatcherValues,
|
||||||
|
|||||||
@@ -51,10 +51,12 @@ public:
|
|||||||
// need to call init() on children conditions)
|
// need to call init() on children conditions)
|
||||||
// conditionIdIndexMap: the mapping from condition id to its index.
|
// 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.
|
// 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,
|
virtual bool init(const std::vector<Predicate>& allConditionConfig,
|
||||||
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
|
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||||
const std::unordered_map<int64_t, int>& conditionIdIndexMap,
|
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.
|
// evaluate current condition given the new event.
|
||||||
// event: the new log event
|
// event: the new log event
|
||||||
|
|||||||
@@ -95,9 +95,11 @@ SimpleConditionTracker::~SimpleConditionTracker() {
|
|||||||
bool SimpleConditionTracker::init(const vector<Predicate>& allConditionConfig,
|
bool SimpleConditionTracker::init(const vector<Predicate>& allConditionConfig,
|
||||||
const vector<sp<ConditionTracker>>& allConditionTrackers,
|
const vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||||
const unordered_map<int64_t, int>& conditionIdIndexMap,
|
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
|
// SimpleConditionTracker does not have dependency on other conditions, thus we just return
|
||||||
// if the initialization was successful.
|
// if the initialization was successful.
|
||||||
|
initialConditionCache[mIndex] = mInitialValue;
|
||||||
return mInitialized;
|
return mInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ public:
|
|||||||
|
|
||||||
bool init(const std::vector<Predicate>& allConditionConfig,
|
bool init(const std::vector<Predicate>& allConditionConfig,
|
||||||
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
|
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||||
const std::unordered_map<int64_t, int>& conditionIdIndexMap,
|
const std::unordered_map<int64_t, int>& conditionIdIndexMap, std::vector<bool>& stack,
|
||||||
std::vector<bool>& stack) override;
|
std::vector<ConditionState>& initialConditionCache) override;
|
||||||
|
|
||||||
void evaluateCondition(const LogEvent& event,
|
void evaluateCondition(const LogEvent& event,
|
||||||
const std::vector<MatchingState>& eventMatcherValues,
|
const std::vector<MatchingState>& eventMatcherValues,
|
||||||
|
|||||||
@@ -68,14 +68,14 @@ const int FIELD_ID_END_BUCKET_ELAPSED_MILLIS = 6;
|
|||||||
|
|
||||||
CountMetricProducer::CountMetricProducer(
|
CountMetricProducer::CountMetricProducer(
|
||||||
const ConfigKey& key, const CountMetric& metric, const int conditionIndex,
|
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, shared_ptr<Activation>>& eventActivationMap,
|
||||||
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap,
|
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap,
|
||||||
const vector<int>& slicedStateAtoms,
|
const vector<int>& slicedStateAtoms,
|
||||||
const unordered_map<int, unordered_map<int, int64_t>>& stateGroupMap)
|
const unordered_map<int, unordered_map<int, int64_t>>& stateGroupMap)
|
||||||
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, wizard, eventActivationMap,
|
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, initialConditionCache, wizard,
|
||||||
eventDeactivationMap, slicedStateAtoms, stateGroupMap) {
|
eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap) {
|
||||||
if (metric.has_bucket()) {
|
if (metric.has_bucket()) {
|
||||||
mBucketSizeNs =
|
mBucketSizeNs =
|
||||||
TimeUnitToBucketSizeInMillisGuardrailed(key.GetUid(), metric.bucket()) * 1000000;
|
TimeUnitToBucketSizeInMillisGuardrailed(key.GetUid(), metric.bucket()) * 1000000;
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ class CountMetricProducer : public MetricProducer {
|
|||||||
public:
|
public:
|
||||||
CountMetricProducer(
|
CountMetricProducer(
|
||||||
const ConfigKey& key, const CountMetric& countMetric, const int conditionIndex,
|
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::shared_ptr<Activation>>& eventActivationMap = {},
|
||||||
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
|
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
|
||||||
eventDeactivationMap = {},
|
eventDeactivationMap = {},
|
||||||
|
|||||||
@@ -64,15 +64,16 @@ const int FIELD_ID_END_BUCKET_ELAPSED_MILLIS = 6;
|
|||||||
|
|
||||||
DurationMetricProducer::DurationMetricProducer(
|
DurationMetricProducer::DurationMetricProducer(
|
||||||
const ConfigKey& key, const DurationMetric& metric, const int conditionIndex,
|
const ConfigKey& key, const DurationMetric& metric, const int conditionIndex,
|
||||||
const size_t startIndex, const size_t stopIndex, const size_t stopAllIndex,
|
const vector<ConditionState>& initialConditionCache, const size_t startIndex,
|
||||||
const bool nesting, const sp<ConditionWizard>& wizard,
|
const size_t stopIndex, const size_t stopAllIndex, const bool nesting,
|
||||||
const FieldMatcher& internalDimensions, const int64_t timeBaseNs, const int64_t startTimeNs,
|
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, shared_ptr<Activation>>& eventActivationMap,
|
||||||
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap,
|
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap,
|
||||||
const vector<int>& slicedStateAtoms,
|
const vector<int>& slicedStateAtoms,
|
||||||
const unordered_map<int, unordered_map<int, int64_t>>& stateGroupMap)
|
const unordered_map<int, unordered_map<int, int64_t>>& stateGroupMap)
|
||||||
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, wizard, eventActivationMap,
|
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, initialConditionCache, wizard,
|
||||||
eventDeactivationMap, slicedStateAtoms, stateGroupMap),
|
eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap),
|
||||||
mAggregationType(metric.aggregation_type()),
|
mAggregationType(metric.aggregation_type()),
|
||||||
mStartIndex(startIndex),
|
mStartIndex(startIndex),
|
||||||
mStopIndex(stopIndex),
|
mStopIndex(stopIndex),
|
||||||
|
|||||||
@@ -40,10 +40,10 @@ class DurationMetricProducer : public MetricProducer {
|
|||||||
public:
|
public:
|
||||||
DurationMetricProducer(
|
DurationMetricProducer(
|
||||||
const ConfigKey& key, const DurationMetric& durationMetric, const int conditionIndex,
|
const ConfigKey& key, const DurationMetric& durationMetric, const int conditionIndex,
|
||||||
const size_t startIndex, const size_t stopIndex, const size_t stopAllIndex,
|
const vector<ConditionState>& initialConditionCache, const size_t startIndex,
|
||||||
const bool nesting, const sp<ConditionWizard>& wizard,
|
const size_t stopIndex, const size_t stopAllIndex, const bool nesting,
|
||||||
const FieldMatcher& internalDimensions, const int64_t timeBaseNs,
|
const sp<ConditionWizard>& wizard, const FieldMatcher& internalDimensions,
|
||||||
const int64_t startTimeNs,
|
const int64_t timeBaseNs, const int64_t startTimeNs,
|
||||||
const unordered_map<int, shared_ptr<Activation>>& eventActivationMap = {},
|
const unordered_map<int, shared_ptr<Activation>>& eventActivationMap = {},
|
||||||
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap = {},
|
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap = {},
|
||||||
const vector<int>& slicedStateAtoms = {},
|
const vector<int>& slicedStateAtoms = {},
|
||||||
|
|||||||
@@ -54,13 +54,14 @@ const int FIELD_ID_ATOMS = 2;
|
|||||||
|
|
||||||
EventMetricProducer::EventMetricProducer(
|
EventMetricProducer::EventMetricProducer(
|
||||||
const ConfigKey& key, const EventMetric& metric, const int conditionIndex,
|
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, shared_ptr<Activation>>& eventActivationMap,
|
||||||
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap,
|
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap,
|
||||||
const vector<int>& slicedStateAtoms,
|
const vector<int>& slicedStateAtoms,
|
||||||
const unordered_map<int, unordered_map<int, int64_t>>& stateGroupMap)
|
const unordered_map<int, unordered_map<int, int64_t>>& stateGroupMap)
|
||||||
: MetricProducer(metric.id(), key, startTimeNs, conditionIndex, wizard, eventActivationMap,
|
: MetricProducer(metric.id(), key, startTimeNs, conditionIndex, initialConditionCache, wizard,
|
||||||
eventDeactivationMap, slicedStateAtoms, stateGroupMap) {
|
eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap) {
|
||||||
if (metric.links().size() > 0) {
|
if (metric.links().size() > 0) {
|
||||||
for (const auto& link : metric.links()) {
|
for (const auto& link : metric.links()) {
|
||||||
Metric2Condition mc;
|
Metric2Condition mc;
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ class EventMetricProducer : public MetricProducer {
|
|||||||
public:
|
public:
|
||||||
EventMetricProducer(
|
EventMetricProducer(
|
||||||
const ConfigKey& key, const EventMetric& eventMetric, const int conditionIndex,
|
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::shared_ptr<Activation>>& eventActivationMap = {},
|
||||||
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
|
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
|
||||||
eventDeactivationMap = {},
|
eventDeactivationMap = {},
|
||||||
|
|||||||
@@ -70,14 +70,15 @@ const int FIELD_ID_END_BUCKET_ELAPSED_MILLIS = 8;
|
|||||||
|
|
||||||
GaugeMetricProducer::GaugeMetricProducer(
|
GaugeMetricProducer::GaugeMetricProducer(
|
||||||
const ConfigKey& key, const GaugeMetric& metric, const int conditionIndex,
|
const ConfigKey& key, const GaugeMetric& metric, const int conditionIndex,
|
||||||
const sp<ConditionWizard>& wizard, const int whatMatcherIndex,
|
const vector<ConditionState>& initialConditionCache, const sp<ConditionWizard>& wizard,
|
||||||
const sp<EventMatcherWizard>& matcherWizard, const int pullTagId, const int triggerAtomId,
|
const int whatMatcherIndex, const sp<EventMatcherWizard>& matcherWizard,
|
||||||
const int atomId, const int64_t timeBaseNs, const int64_t startTimeNs,
|
const int pullTagId, const int triggerAtomId, const int atomId, const int64_t timeBaseNs,
|
||||||
const sp<StatsPullerManager>& pullerManager,
|
const int64_t startTimeNs, const sp<StatsPullerManager>& pullerManager,
|
||||||
const unordered_map<int, shared_ptr<Activation>>& eventActivationMap,
|
const unordered_map<int, shared_ptr<Activation>>& eventActivationMap,
|
||||||
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap)
|
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap)
|
||||||
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, wizard, eventActivationMap,
|
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, initialConditionCache, wizard,
|
||||||
eventDeactivationMap, /*slicedStateAtoms=*/{}, /*stateGroupMap=*/{}),
|
eventActivationMap, eventDeactivationMap, /*slicedStateAtoms=*/{},
|
||||||
|
/*stateGroupMap=*/{}),
|
||||||
mWhatMatcherIndex(whatMatcherIndex),
|
mWhatMatcherIndex(whatMatcherIndex),
|
||||||
mEventMatcherWizard(matcherWizard),
|
mEventMatcherWizard(matcherWizard),
|
||||||
mPullerManager(pullerManager),
|
mPullerManager(pullerManager),
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ class GaugeMetricProducer : public virtual MetricProducer, public virtual PullDa
|
|||||||
public:
|
public:
|
||||||
GaugeMetricProducer(
|
GaugeMetricProducer(
|
||||||
const ConfigKey& key, const GaugeMetric& gaugeMetric, const int conditionIndex,
|
const ConfigKey& key, const GaugeMetric& gaugeMetric, const int conditionIndex,
|
||||||
|
const vector<ConditionState>& initialConditionCache,
|
||||||
const sp<ConditionWizard>& conditionWizard, const int whatMatcherIndex,
|
const sp<ConditionWizard>& conditionWizard, const int whatMatcherIndex,
|
||||||
const sp<EventMatcherWizard>& matcherWizard, const int pullTagId,
|
const sp<EventMatcherWizard>& matcherWizard, const int pullTagId,
|
||||||
const int triggerAtomId, const int atomId, const int64_t timeBaseNs,
|
const int triggerAtomId, const int atomId, const int64_t timeBaseNs,
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ const int FIELD_ID_ACTIVE_EVENT_ACTIVATION_STATE = 3;
|
|||||||
|
|
||||||
MetricProducer::MetricProducer(
|
MetricProducer::MetricProducer(
|
||||||
const int64_t& metricId, const ConfigKey& key, const int64_t timeBaseNs,
|
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::shared_ptr<Activation>>& eventActivationMap,
|
||||||
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
|
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
|
||||||
eventDeactivationMap,
|
eventDeactivationMap,
|
||||||
@@ -56,7 +57,7 @@ MetricProducer::MetricProducer(
|
|||||||
mTimeBaseNs(timeBaseNs),
|
mTimeBaseNs(timeBaseNs),
|
||||||
mCurrentBucketStartTimeNs(timeBaseNs),
|
mCurrentBucketStartTimeNs(timeBaseNs),
|
||||||
mCurrentBucketNum(0),
|
mCurrentBucketNum(0),
|
||||||
mCondition(initialCondition(conditionIndex)),
|
mCondition(initialCondition(conditionIndex, initialConditionCache)),
|
||||||
mConditionTrackerIndex(conditionIndex),
|
mConditionTrackerIndex(conditionIndex),
|
||||||
mConditionSliced(false),
|
mConditionSliced(false),
|
||||||
mWizard(wizard),
|
mWizard(wizard),
|
||||||
|
|||||||
@@ -129,7 +129,8 @@ struct SkippedBucket {
|
|||||||
class MetricProducer : public virtual android::RefBase, public virtual StateListener {
|
class MetricProducer : public virtual android::RefBase, public virtual StateListener {
|
||||||
public:
|
public:
|
||||||
MetricProducer(const int64_t& metricId, const ConfigKey& key, const int64_t timeBaseNs,
|
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::shared_ptr<Activation>>& eventActivationMap,
|
||||||
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
|
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
|
||||||
eventDeactivationMap,
|
eventDeactivationMap,
|
||||||
@@ -138,8 +139,9 @@ public:
|
|||||||
|
|
||||||
virtual ~MetricProducer(){};
|
virtual ~MetricProducer(){};
|
||||||
|
|
||||||
ConditionState initialCondition(const int conditionIndex) const {
|
ConditionState initialCondition(const int conditionIndex,
|
||||||
return conditionIndex >= 0 ? ConditionState::kUnknown : ConditionState::kTrue;
|
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_WithDimensions);
|
||||||
FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState_WithIncorrectDimensions);
|
FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState_WithIncorrectDimensions);
|
||||||
FRIEND_TEST(ValueMetricE2eTest, TestInitialConditionChanges);
|
FRIEND_TEST(ValueMetricE2eTest, TestInitialConditionChanges);
|
||||||
|
|
||||||
|
FRIEND_TEST(MetricsManagerTest, TestInitialConditions);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace statsd
|
} // namespace statsd
|
||||||
|
|||||||
@@ -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
|
// ValueMetric has a minimum bucket size of 10min so that we don't pull too frequently
|
||||||
ValueMetricProducer::ValueMetricProducer(
|
ValueMetricProducer::ValueMetricProducer(
|
||||||
const ConfigKey& key, const ValueMetric& metric, const int conditionIndex,
|
const ConfigKey& key, const ValueMetric& metric, const int conditionIndex,
|
||||||
|
const vector<ConditionState>& initialConditionCache,
|
||||||
const sp<ConditionWizard>& conditionWizard, const int whatMatcherIndex,
|
const sp<ConditionWizard>& conditionWizard, const int whatMatcherIndex,
|
||||||
const sp<EventMatcherWizard>& matcherWizard, const int pullTagId, const int64_t timeBaseNs,
|
const sp<EventMatcherWizard>& matcherWizard, const int pullTagId, const int64_t timeBaseNs,
|
||||||
const int64_t startTimeNs, const sp<StatsPullerManager>& pullerManager,
|
const int64_t startTimeNs, const sp<StatsPullerManager>& pullerManager,
|
||||||
@@ -85,8 +86,9 @@ ValueMetricProducer::ValueMetricProducer(
|
|||||||
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap,
|
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap,
|
||||||
const vector<int>& slicedStateAtoms,
|
const vector<int>& slicedStateAtoms,
|
||||||
const unordered_map<int, unordered_map<int, int64_t>>& stateGroupMap)
|
const unordered_map<int, unordered_map<int, int64_t>>& stateGroupMap)
|
||||||
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, conditionWizard,
|
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, initialConditionCache,
|
||||||
eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap),
|
conditionWizard, eventActivationMap, eventDeactivationMap, slicedStateAtoms,
|
||||||
|
stateGroupMap),
|
||||||
mWhatMatcherIndex(whatMatcherIndex),
|
mWhatMatcherIndex(whatMatcherIndex),
|
||||||
mEventMatcherWizard(matcherWizard),
|
mEventMatcherWizard(matcherWizard),
|
||||||
mPullerManager(pullerManager),
|
mPullerManager(pullerManager),
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ class ValueMetricProducer : public virtual MetricProducer, public virtual PullDa
|
|||||||
public:
|
public:
|
||||||
ValueMetricProducer(
|
ValueMetricProducer(
|
||||||
const ConfigKey& key, const ValueMetric& valueMetric, const int conditionIndex,
|
const ConfigKey& key, const ValueMetric& valueMetric, const int conditionIndex,
|
||||||
|
const vector<ConditionState>& initialConditionCache,
|
||||||
const sp<ConditionWizard>& conditionWizard, const int whatMatcherIndex,
|
const sp<ConditionWizard>& conditionWizard, const int whatMatcherIndex,
|
||||||
const sp<EventMatcherWizard>& matcherWizard, const int pullTagId,
|
const sp<EventMatcherWizard>& matcherWizard, const int pullTagId,
|
||||||
const int64_t timeBaseNs, const int64_t startTimeNs,
|
const int64_t timeBaseNs, const int64_t startTimeNs,
|
||||||
|
|||||||
@@ -285,11 +285,14 @@ bool initConditions(const ConfigKey& key, const StatsdConfig& config,
|
|||||||
const unordered_map<int64_t, int>& logTrackerMap,
|
const unordered_map<int64_t, int>& logTrackerMap,
|
||||||
unordered_map<int64_t, int>& conditionTrackerMap,
|
unordered_map<int64_t, int>& conditionTrackerMap,
|
||||||
vector<sp<ConditionTracker>>& allConditionTrackers,
|
vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||||
unordered_map<int, std::vector<int>>& trackerToConditionMap) {
|
unordered_map<int, std::vector<int>>& trackerToConditionMap,
|
||||||
|
vector<ConditionState>& initialConditionCache) {
|
||||||
vector<Predicate> conditionConfigs;
|
vector<Predicate> conditionConfigs;
|
||||||
const int conditionTrackerCount = config.predicate_size();
|
const int conditionTrackerCount = config.predicate_size();
|
||||||
conditionConfigs.reserve(conditionTrackerCount);
|
conditionConfigs.reserve(conditionTrackerCount);
|
||||||
allConditionTrackers.reserve(conditionTrackerCount);
|
allConditionTrackers.reserve(conditionTrackerCount);
|
||||||
|
initialConditionCache.reserve(conditionTrackerCount);
|
||||||
|
std::fill(initialConditionCache.begin(), initialConditionCache.end(), ConditionState::kUnknown);
|
||||||
|
|
||||||
for (int i = 0; i < conditionTrackerCount; i++) {
|
for (int i = 0; i < conditionTrackerCount; i++) {
|
||||||
const Predicate& condition = config.predicate(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++) {
|
for (size_t i = 0; i < allConditionTrackers.size(); i++) {
|
||||||
auto& conditionTracker = allConditionTrackers[i];
|
auto& conditionTracker = allConditionTrackers[i];
|
||||||
if (!conditionTracker->init(conditionConfigs, allConditionTrackers, conditionTrackerMap,
|
if (!conditionTracker->init(conditionConfigs, allConditionTrackers, conditionTrackerMap,
|
||||||
stackTracker)) {
|
stackTracker, initialConditionCache)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (const int trackerIndex : conditionTracker->getLogTrackerIndex()) {
|
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,
|
bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t timeBaseTimeNs,
|
||||||
const int64_t currentTimeNs,
|
const int64_t currentTimeNs, const sp<StatsPullerManager>& pullerManager,
|
||||||
const sp<StatsPullerManager>& pullerManager,
|
|
||||||
const unordered_map<int64_t, int>& logTrackerMap,
|
const unordered_map<int64_t, int>& logTrackerMap,
|
||||||
const unordered_map<int64_t, int>& conditionTrackerMap,
|
const unordered_map<int64_t, int>& conditionTrackerMap,
|
||||||
const vector<sp<LogMatchingTracker>>& allAtomMatchers,
|
const vector<sp<LogMatchingTracker>>& allAtomMatchers,
|
||||||
const unordered_map<int64_t, int>& stateAtomIdMap,
|
const unordered_map<int64_t, int>& stateAtomIdMap,
|
||||||
const unordered_map<int64_t, unordered_map<int, int64_t>>& allStateGroupMaps,
|
const unordered_map<int64_t, unordered_map<int, int64_t>>& allStateGroupMaps,
|
||||||
vector<sp<ConditionTracker>>& allConditionTrackers,
|
vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||||
|
const vector<ConditionState>& initialConditionCache,
|
||||||
vector<sp<MetricProducer>>& allMetricProducers,
|
vector<sp<MetricProducer>>& allMetricProducers,
|
||||||
unordered_map<int, vector<int>>& conditionToMetricMap,
|
unordered_map<int, vector<int>>& conditionToMetricMap,
|
||||||
unordered_map<int, vector<int>>& trackerToMetricMap,
|
unordered_map<int, vector<int>>& trackerToMetricMap,
|
||||||
@@ -441,9 +444,10 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t
|
|||||||
eventDeactivationMap);
|
eventDeactivationMap);
|
||||||
if (!success) return false;
|
if (!success) return false;
|
||||||
|
|
||||||
sp<MetricProducer> countProducer = new CountMetricProducer(
|
sp<MetricProducer> countProducer =
|
||||||
key, metric, conditionIndex, wizard, timeBaseTimeNs, currentTimeNs,
|
new CountMetricProducer(key, metric, conditionIndex, initialConditionCache, wizard,
|
||||||
eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap);
|
timeBaseTimeNs, currentTimeNs, eventActivationMap,
|
||||||
|
eventDeactivationMap, slicedStateAtoms, stateGroupMap);
|
||||||
allMetricProducers.push_back(countProducer);
|
allMetricProducers.push_back(countProducer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,10 +551,10 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t
|
|||||||
if (!success) return false;
|
if (!success) return false;
|
||||||
|
|
||||||
sp<MetricProducer> durationMetric = new DurationMetricProducer(
|
sp<MetricProducer> durationMetric = new DurationMetricProducer(
|
||||||
key, metric, conditionIndex, trackerIndices[0], trackerIndices[1],
|
key, metric, conditionIndex, initialConditionCache, trackerIndices[0],
|
||||||
trackerIndices[2], nesting, wizard, internalDimensions, timeBaseTimeNs,
|
trackerIndices[1], trackerIndices[2], nesting, wizard, internalDimensions,
|
||||||
currentTimeNs, eventActivationMap, eventDeactivationMap, slicedStateAtoms,
|
timeBaseTimeNs, currentTimeNs, eventActivationMap, eventDeactivationMap,
|
||||||
stateGroupMap);
|
slicedStateAtoms, stateGroupMap);
|
||||||
|
|
||||||
allMetricProducers.push_back(durationMetric);
|
allMetricProducers.push_back(durationMetric);
|
||||||
}
|
}
|
||||||
@@ -593,9 +597,9 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t
|
|||||||
eventDeactivationMap);
|
eventDeactivationMap);
|
||||||
if (!success) return false;
|
if (!success) return false;
|
||||||
|
|
||||||
sp<MetricProducer> eventMetric = new EventMetricProducer(
|
sp<MetricProducer> eventMetric =
|
||||||
key, metric, conditionIndex, wizard, timeBaseTimeNs, eventActivationMap,
|
new EventMetricProducer(key, metric, conditionIndex, initialConditionCache, wizard,
|
||||||
eventDeactivationMap);
|
timeBaseTimeNs, eventActivationMap, eventDeactivationMap);
|
||||||
|
|
||||||
allMetricProducers.push_back(eventMetric);
|
allMetricProducers.push_back(eventMetric);
|
||||||
}
|
}
|
||||||
@@ -683,9 +687,9 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t
|
|||||||
if (!success) return false;
|
if (!success) return false;
|
||||||
|
|
||||||
sp<MetricProducer> valueProducer = new ValueMetricProducer(
|
sp<MetricProducer> valueProducer = new ValueMetricProducer(
|
||||||
key, metric, conditionIndex, wizard, trackerIndex, matcherWizard, pullTagId,
|
key, metric, conditionIndex, initialConditionCache, wizard, trackerIndex,
|
||||||
timeBaseTimeNs, currentTimeNs, pullerManager, eventActivationMap,
|
matcherWizard, pullTagId, timeBaseTimeNs, currentTimeNs, pullerManager,
|
||||||
eventDeactivationMap, slicedStateAtoms, stateGroupMap);
|
eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap);
|
||||||
allMetricProducers.push_back(valueProducer);
|
allMetricProducers.push_back(valueProducer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -778,9 +782,9 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t
|
|||||||
if (!success) return false;
|
if (!success) return false;
|
||||||
|
|
||||||
sp<MetricProducer> gaugeProducer = new GaugeMetricProducer(
|
sp<MetricProducer> gaugeProducer = new GaugeMetricProducer(
|
||||||
key, metric, conditionIndex, wizard, trackerIndex, matcherWizard, pullTagId,
|
key, metric, conditionIndex, initialConditionCache, wizard, trackerIndex,
|
||||||
triggerAtomId, atomTagId, timeBaseTimeNs, currentTimeNs, pullerManager,
|
matcherWizard, pullTagId, triggerAtomId, atomTagId, timeBaseTimeNs, currentTimeNs,
|
||||||
eventActivationMap, eventDeactivationMap);
|
pullerManager, eventActivationMap, eventDeactivationMap);
|
||||||
allMetricProducers.push_back(gaugeProducer);
|
allMetricProducers.push_back(gaugeProducer);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < config.no_report_metric_size(); ++i) {
|
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) {
|
std::set<int64_t>& noReportMetricIds) {
|
||||||
unordered_map<int64_t, int> logTrackerMap;
|
unordered_map<int64_t, int> logTrackerMap;
|
||||||
unordered_map<int64_t, int> conditionTrackerMap;
|
unordered_map<int64_t, int> conditionTrackerMap;
|
||||||
|
vector<ConditionState> initialConditionCache;
|
||||||
unordered_map<int64_t, int> metricProducerMap;
|
unordered_map<int64_t, int> metricProducerMap;
|
||||||
unordered_map<int64_t, int> stateAtomIdMap;
|
unordered_map<int64_t, int> stateAtomIdMap;
|
||||||
unordered_map<int64_t, unordered_map<int, int64_t>> allStateGroupMaps;
|
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...");
|
VLOG("initLogMatchingTrackers succeed...");
|
||||||
|
|
||||||
if (!initConditions(key, config, logTrackerMap, conditionTrackerMap, allConditionTrackers,
|
if (!initConditions(key, config, logTrackerMap, conditionTrackerMap, allConditionTrackers,
|
||||||
trackerToConditionMap)) {
|
trackerToConditionMap, initialConditionCache)) {
|
||||||
ALOGE("initConditionTrackers failed");
|
ALOGE("initConditionTrackers failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -952,10 +957,10 @@ bool initStatsdConfig(const ConfigKey& key, const StatsdConfig& config, UidMap&
|
|||||||
}
|
}
|
||||||
if (!initMetrics(key, config, timeBaseNs, currentTimeNs, pullerManager, logTrackerMap,
|
if (!initMetrics(key, config, timeBaseNs, currentTimeNs, pullerManager, logTrackerMap,
|
||||||
conditionTrackerMap, allAtomMatchers, stateAtomIdMap, allStateGroupMaps,
|
conditionTrackerMap, allAtomMatchers, stateAtomIdMap, allStateGroupMaps,
|
||||||
allConditionTrackers, allMetricProducers,
|
allConditionTrackers, initialConditionCache, allMetricProducers,
|
||||||
conditionToMetricMap, trackerToMetricMap, metricProducerMap,
|
conditionToMetricMap, trackerToMetricMap, metricProducerMap, noReportMetricIds,
|
||||||
noReportMetricIds, activationAtomTrackerToMetricMap,
|
activationAtomTrackerToMetricMap, deactivationAtomTrackerToMetricMap,
|
||||||
deactivationAtomTrackerToMetricMap, metricsWithActivation)) {
|
metricsWithActivation)) {
|
||||||
ALOGE("initMetricProducers failed");
|
ALOGE("initMetricProducers failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,12 +60,14 @@ bool initLogTrackers(const StatsdConfig& config,
|
|||||||
// [allConditionTrackers]: stores the sp to all the ConditionTrackers
|
// [allConditionTrackers]: stores the sp to all the ConditionTrackers
|
||||||
// [trackerToConditionMap]: contain the mapping from index of
|
// [trackerToConditionMap]: contain the mapping from index of
|
||||||
// log tracker to condition trackers that use the log tracker
|
// 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,
|
bool initConditions(const ConfigKey& key, const StatsdConfig& config,
|
||||||
const std::unordered_map<int64_t, int>& logTrackerMap,
|
const std::unordered_map<int64_t, int>& logTrackerMap,
|
||||||
std::unordered_map<int64_t, int>& conditionTrackerMap,
|
std::unordered_map<int64_t, int>& conditionTrackerMap,
|
||||||
std::vector<sp<ConditionTracker>>& allConditionTrackers,
|
std::vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||||
std::unordered_map<int, std::vector<int>>& trackerToConditionMap,
|
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
|
// Initialize State maps using State protos in the config. These maps will
|
||||||
// eventually be passed to MetricProducers to initialize their state info.
|
// 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, int>& stateAtomIdMap,
|
||||||
const unordered_map<int64_t, unordered_map<int, int64_t>>& allStateGroupMaps,
|
const unordered_map<int64_t, unordered_map<int, int64_t>>& allStateGroupMaps,
|
||||||
vector<sp<ConditionTracker>>& allConditionTrackers,
|
vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||||
|
const std::vector<ConditionState>& initialConditionCache,
|
||||||
std::vector<sp<MetricProducer>>& allMetricProducers,
|
std::vector<sp<MetricProducer>>& allMetricProducers,
|
||||||
std::unordered_map<int, std::vector<int>>& conditionToMetricMap,
|
std::unordered_map<int, std::vector<int>>& conditionToMetricMap,
|
||||||
std::unordered_map<int, std::vector<int>>& trackerToMetricMap,
|
std::unordered_map<int, std::vector<int>>& trackerToMetricMap,
|
||||||
|
|||||||
@@ -276,11 +276,157 @@ StatsdConfig buildCirclePredicates() {
|
|||||||
return config;
|
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) {
|
bool isSubset(const set<int32_t>& set1, const set<int32_t>& set2) {
|
||||||
return std::includes(set2.begin(), set2.end(), set1.begin(), set1.end());
|
return std::includes(set2.begin(), set2.end(), set1.begin(), set1.end());
|
||||||
}
|
}
|
||||||
} // anonymous namespace
|
} // 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) {
|
TEST(MetricsManagerTest, TestGoodConfig) {
|
||||||
UidMap uidMap;
|
UidMap uidMap;
|
||||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ using namespace android::os::statsd;
|
|||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
|
|
||||||
TEST(ConditionTrackerTest, TestUnknownCondition) {
|
TEST(ConditionTrackerTest, TestUnknownCondition) {
|
||||||
LogicalOperation operation = LogicalOperation::AND;
|
LogicalOperation operation = LogicalOperation::AND;
|
||||||
|
|
||||||
|
|||||||
@@ -112,6 +112,114 @@ std::map<int64_t, HashableDimensionKey> getWakeLockQueryKey(
|
|||||||
return outputKeyMap;
|
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) {
|
TEST(SimpleConditionTrackerTest, TestNonSlicedCondition) {
|
||||||
SimplePredicate simplePredicate;
|
SimplePredicate simplePredicate;
|
||||||
simplePredicate.set_start(StringToId("SCREEN_TURNED_ON"));
|
simplePredicate.set_start(StringToId("SCREEN_TURNED_ON"));
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ TEST(CountMetricProducerTest, TestFirstBucket) {
|
|||||||
metric.set_bucket(ONE_MINUTE);
|
metric.set_bucket(ONE_MINUTE);
|
||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
|
|
||||||
CountMetricProducer countProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, 5,
|
CountMetricProducer countProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
|
||||||
600 * NS_PER_SEC + NS_PER_SEC / 2);
|
wizard, 5, 600 * NS_PER_SEC + NS_PER_SEC / 2);
|
||||||
EXPECT_EQ(600500000000, countProducer.mCurrentBucketStartTimeNs);
|
EXPECT_EQ(600500000000, countProducer.mCurrentBucketStartTimeNs);
|
||||||
EXPECT_EQ(10, countProducer.mCurrentBucketNum);
|
EXPECT_EQ(10, countProducer.mCurrentBucketNum);
|
||||||
EXPECT_EQ(660000000005, countProducer.getCurrentBucketEndTimeNs());
|
EXPECT_EQ(660000000005, countProducer.getCurrentBucketEndTimeNs());
|
||||||
@@ -94,8 +94,8 @@ TEST(CountMetricProducerTest, TestNonDimensionalEvents) {
|
|||||||
|
|
||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
|
|
||||||
CountMetricProducer countProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
|
CountMetricProducer countProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
|
||||||
bucketStartTimeNs, bucketStartTimeNs);
|
wizard, bucketStartTimeNs, bucketStartTimeNs);
|
||||||
|
|
||||||
// 2 events in bucket 1.
|
// 2 events in bucket 1.
|
||||||
LogEvent event1(/*uid=*/0, /*pid=*/0);
|
LogEvent event1(/*uid=*/0, /*pid=*/0);
|
||||||
@@ -157,8 +157,8 @@ TEST(CountMetricProducerTest, TestEventsWithNonSlicedCondition) {
|
|||||||
|
|
||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
|
|
||||||
CountMetricProducer countProducer(kConfigKey, metric, 1, wizard, bucketStartTimeNs,
|
CountMetricProducer countProducer(kConfigKey, metric, 0, {ConditionState::kUnknown}, wizard,
|
||||||
bucketStartTimeNs);
|
bucketStartTimeNs, bucketStartTimeNs);
|
||||||
|
|
||||||
countProducer.onConditionChanged(true, bucketStartTimeNs);
|
countProducer.onConditionChanged(true, bucketStartTimeNs);
|
||||||
|
|
||||||
@@ -220,12 +220,14 @@ TEST(CountMetricProducerTest, TestEventsWithSlicedCondition) {
|
|||||||
getMockedDimensionKey(conditionTagId, 2, "222")};
|
getMockedDimensionKey(conditionTagId, 2, "222")};
|
||||||
|
|
||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
|
|
||||||
EXPECT_CALL(*wizard, query(_, key1, _)).WillOnce(Return(ConditionState::kFalse));
|
EXPECT_CALL(*wizard, query(_, key1, _)).WillOnce(Return(ConditionState::kFalse));
|
||||||
|
|
||||||
EXPECT_CALL(*wizard, query(_, key2, _)).WillOnce(Return(ConditionState::kTrue));
|
EXPECT_CALL(*wizard, query(_, key2, _)).WillOnce(Return(ConditionState::kTrue));
|
||||||
|
|
||||||
CountMetricProducer countProducer(kConfigKey, metric, 1 /*condition tracker index*/, wizard,
|
CountMetricProducer countProducer(kConfigKey, metric, 0 /*condition tracker index*/,
|
||||||
bucketStartTimeNs, bucketStartTimeNs);
|
{ConditionState::kUnknown}, wizard, bucketStartTimeNs,
|
||||||
|
bucketStartTimeNs);
|
||||||
|
|
||||||
countProducer.onMatchedLogEvent(1 /*log matcher index*/, event1);
|
countProducer.onMatchedLogEvent(1 /*log matcher index*/, event1);
|
||||||
countProducer.flushIfNeededLocked(bucketStartTimeNs + 1);
|
countProducer.flushIfNeededLocked(bucketStartTimeNs + 1);
|
||||||
@@ -261,7 +263,8 @@ TEST_P(CountMetricProducerTest_PartialBucket, TestSplitInCurrentBucket) {
|
|||||||
alert.set_trigger_if_sum_gt(2);
|
alert.set_trigger_if_sum_gt(2);
|
||||||
|
|
||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
CountMetricProducer countProducer(kConfigKey, metric, -1 /* no condition */, wizard,
|
|
||||||
|
CountMetricProducer countProducer(kConfigKey, metric, -1 /* no condition */, {}, wizard,
|
||||||
bucketStartTimeNs, bucketStartTimeNs);
|
bucketStartTimeNs, bucketStartTimeNs);
|
||||||
|
|
||||||
sp<AnomalyTracker> anomalyTracker = countProducer.addAnomalyTracker(alert, alarmMonitor);
|
sp<AnomalyTracker> anomalyTracker = countProducer.addAnomalyTracker(alert, alarmMonitor);
|
||||||
@@ -327,7 +330,8 @@ TEST_P(CountMetricProducerTest_PartialBucket, TestSplitInNextBucket) {
|
|||||||
metric.set_bucket(ONE_MINUTE);
|
metric.set_bucket(ONE_MINUTE);
|
||||||
|
|
||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
CountMetricProducer countProducer(kConfigKey, metric, -1 /* no condition */, wizard,
|
|
||||||
|
CountMetricProducer countProducer(kConfigKey, metric, -1 /* no condition */, {}, wizard,
|
||||||
bucketStartTimeNs, bucketStartTimeNs);
|
bucketStartTimeNs, bucketStartTimeNs);
|
||||||
|
|
||||||
// Bucket is flushed yet.
|
// Bucket is flushed yet.
|
||||||
@@ -391,8 +395,9 @@ TEST(CountMetricProducerTest, TestAnomalyDetectionUnSliced) {
|
|||||||
metric.set_bucket(ONE_MINUTE);
|
metric.set_bucket(ONE_MINUTE);
|
||||||
|
|
||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
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);
|
sp<AnomalyTracker> anomalyTracker = countProducer.addAnomalyTracker(alert, alarmMonitor);
|
||||||
|
|
||||||
@@ -453,8 +458,8 @@ TEST(CountMetricProducerTest, TestOneWeekTimeUnit) {
|
|||||||
int64_t oneDayNs = 24 * 60 * 60 * 1e9;
|
int64_t oneDayNs = 24 * 60 * 60 * 1e9;
|
||||||
int64_t fiveWeeksNs = 5 * 7 * oneDayNs;
|
int64_t fiveWeeksNs = 5 * 7 * oneDayNs;
|
||||||
|
|
||||||
CountMetricProducer countProducer(
|
CountMetricProducer countProducer(kConfigKey, metric, -1 /* meaning no condition */, {}, wizard,
|
||||||
kConfigKey, metric, -1 /* meaning no condition */, wizard, oneDayNs, fiveWeeksNs);
|
oneDayNs, fiveWeeksNs);
|
||||||
|
|
||||||
int64_t fiveWeeksOneDayNs = fiveWeeksNs + oneDayNs;
|
int64_t fiveWeeksOneDayNs = fiveWeeksNs + oneDayNs;
|
||||||
|
|
||||||
|
|||||||
@@ -70,9 +70,11 @@ TEST(DurationMetricTrackerTest, TestFirstBucket) {
|
|||||||
metric.set_aggregation_type(DurationMetric_AggregationType_SUM);
|
metric.set_aggregation_type(DurationMetric_AggregationType_SUM);
|
||||||
|
|
||||||
FieldMatcher dimensions;
|
FieldMatcher dimensions;
|
||||||
DurationMetricProducer durationProducer(
|
|
||||||
kConfigKey, metric, -1 /*no condition*/, 1 /* start index */, 2 /* stop index */,
|
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /*no condition*/, {},
|
||||||
3 /* stop_all index */, false /*nesting*/, wizard, dimensions, 5, 600 * NS_PER_SEC + NS_PER_SEC/2);
|
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(600500000000, durationProducer.mCurrentBucketStartTimeNs);
|
||||||
EXPECT_EQ(10, durationProducer.mCurrentBucketNum);
|
EXPECT_EQ(10, durationProducer.mCurrentBucketNum);
|
||||||
@@ -96,7 +98,8 @@ TEST(DurationMetricTrackerTest, TestNoCondition) {
|
|||||||
makeLogEvent(&event2, bucketStartTimeNs + bucketSizeNs + 2, tagId);
|
makeLogEvent(&event2, bucketStartTimeNs + bucketSizeNs + 2, tagId);
|
||||||
|
|
||||||
FieldMatcher dimensions;
|
FieldMatcher dimensions;
|
||||||
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /*no condition*/,
|
|
||||||
|
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /*no condition*/, {},
|
||||||
1 /* start index */, 2 /* stop index */,
|
1 /* start index */, 2 /* stop index */,
|
||||||
3 /* stop_all index */, false /*nesting*/, wizard,
|
3 /* stop_all index */, false /*nesting*/, wizard,
|
||||||
dimensions, bucketStartTimeNs, bucketStartTimeNs);
|
dimensions, bucketStartTimeNs, bucketStartTimeNs);
|
||||||
@@ -138,10 +141,11 @@ TEST(DurationMetricTrackerTest, TestNonSlicedCondition) {
|
|||||||
makeLogEvent(&event4, bucketStartTimeNs + bucketSizeNs + 3, tagId);
|
makeLogEvent(&event4, bucketStartTimeNs + bucketSizeNs + 3, tagId);
|
||||||
|
|
||||||
FieldMatcher dimensions;
|
FieldMatcher dimensions;
|
||||||
DurationMetricProducer durationProducer(kConfigKey, metric, 0 /* condition index */,
|
|
||||||
1 /* start index */, 2 /* stop index */,
|
DurationMetricProducer durationProducer(
|
||||||
3 /* stop_all index */, false /*nesting*/, wizard,
|
kConfigKey, metric, 0 /* condition index */, {ConditionState::kUnknown},
|
||||||
dimensions, bucketStartTimeNs, bucketStartTimeNs);
|
1 /* start index */, 2 /* stop index */, 3 /* stop_all index */, false /*nesting*/,
|
||||||
|
wizard, dimensions, bucketStartTimeNs, bucketStartTimeNs);
|
||||||
durationProducer.mCondition = ConditionState::kFalse;
|
durationProducer.mCondition = ConditionState::kFalse;
|
||||||
|
|
||||||
EXPECT_FALSE(durationProducer.mCondition);
|
EXPECT_FALSE(durationProducer.mCondition);
|
||||||
@@ -187,10 +191,11 @@ TEST(DurationMetricTrackerTest, TestNonSlicedConditionUnknownState) {
|
|||||||
makeLogEvent(&event4, bucketStartTimeNs + bucketSizeNs + 3, tagId);
|
makeLogEvent(&event4, bucketStartTimeNs + bucketSizeNs + 3, tagId);
|
||||||
|
|
||||||
FieldMatcher dimensions;
|
FieldMatcher dimensions;
|
||||||
DurationMetricProducer durationProducer(kConfigKey, metric, 0 /* condition index */,
|
|
||||||
1 /* start index */, 2 /* stop index */,
|
DurationMetricProducer durationProducer(
|
||||||
3 /* stop_all index */, false /*nesting*/, wizard,
|
kConfigKey, metric, 0 /* condition index */, {ConditionState::kUnknown},
|
||||||
dimensions, bucketStartTimeNs, bucketStartTimeNs);
|
1 /* start index */, 2 /* stop index */, 3 /* stop_all index */, false /*nesting*/,
|
||||||
|
wizard, dimensions, bucketStartTimeNs, bucketStartTimeNs);
|
||||||
|
|
||||||
EXPECT_EQ(ConditionState::kUnknown, durationProducer.mCondition);
|
EXPECT_EQ(ConditionState::kUnknown, durationProducer.mCondition);
|
||||||
EXPECT_FALSE(durationProducer.isConditionSliced());
|
EXPECT_FALSE(durationProducer.isConditionSliced());
|
||||||
@@ -232,7 +237,8 @@ TEST_P(DurationMetricProducerTest_PartialBucket, TestSumDuration) {
|
|||||||
metric.set_aggregation_type(DurationMetric_AggregationType_SUM);
|
metric.set_aggregation_type(DurationMetric_AggregationType_SUM);
|
||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
FieldMatcher dimensions;
|
FieldMatcher dimensions;
|
||||||
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */,
|
|
||||||
|
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, {},
|
||||||
1 /* start index */, 2 /* stop index */,
|
1 /* start index */, 2 /* stop index */,
|
||||||
3 /* stop_all index */, false /*nesting*/, wizard,
|
3 /* stop_all index */, false /*nesting*/, wizard,
|
||||||
dimensions, bucketStartTimeNs, bucketStartTimeNs);
|
dimensions, bucketStartTimeNs, bucketStartTimeNs);
|
||||||
@@ -294,7 +300,8 @@ TEST_P(DurationMetricProducerTest_PartialBucket, TestSumDurationWithSplitInFollo
|
|||||||
metric.set_aggregation_type(DurationMetric_AggregationType_SUM);
|
metric.set_aggregation_type(DurationMetric_AggregationType_SUM);
|
||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
FieldMatcher dimensions;
|
FieldMatcher dimensions;
|
||||||
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */,
|
|
||||||
|
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, {},
|
||||||
1 /* start index */, 2 /* stop index */,
|
1 /* start index */, 2 /* stop index */,
|
||||||
3 /* stop_all index */, false /*nesting*/, wizard,
|
3 /* stop_all index */, false /*nesting*/, wizard,
|
||||||
dimensions, bucketStartTimeNs, bucketStartTimeNs);
|
dimensions, bucketStartTimeNs, bucketStartTimeNs);
|
||||||
@@ -357,7 +364,8 @@ TEST_P(DurationMetricProducerTest_PartialBucket, TestSumDurationAnomaly) {
|
|||||||
|
|
||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
FieldMatcher dimensions;
|
FieldMatcher dimensions;
|
||||||
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */,
|
|
||||||
|
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, {},
|
||||||
1 /* start index */, 2 /* stop index */,
|
1 /* start index */, 2 /* stop index */,
|
||||||
3 /* stop_all index */, false /*nesting*/, wizard,
|
3 /* stop_all index */, false /*nesting*/, wizard,
|
||||||
dimensions, bucketStartTimeNs, bucketStartTimeNs);
|
dimensions, bucketStartTimeNs, bucketStartTimeNs);
|
||||||
@@ -402,7 +410,8 @@ TEST_P(DurationMetricProducerTest_PartialBucket, TestMaxDuration) {
|
|||||||
|
|
||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
FieldMatcher dimensions;
|
FieldMatcher dimensions;
|
||||||
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */,
|
|
||||||
|
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, {},
|
||||||
1 /* start index */, 2 /* stop index */,
|
1 /* start index */, 2 /* stop index */,
|
||||||
3 /* stop_all index */, false /*nesting*/, wizard,
|
3 /* stop_all index */, false /*nesting*/, wizard,
|
||||||
dimensions, bucketStartTimeNs, bucketStartTimeNs);
|
dimensions, bucketStartTimeNs, bucketStartTimeNs);
|
||||||
@@ -455,7 +464,8 @@ TEST_P(DurationMetricProducerTest_PartialBucket, TestMaxDurationWithSplitInNextB
|
|||||||
|
|
||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
FieldMatcher dimensions;
|
FieldMatcher dimensions;
|
||||||
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */,
|
|
||||||
|
DurationMetricProducer durationProducer(kConfigKey, metric, -1 /* no condition */, {},
|
||||||
1 /* start index */, 2 /* stop index */,
|
1 /* start index */, 2 /* stop index */,
|
||||||
3 /* stop_all index */, false /*nesting*/, wizard,
|
3 /* stop_all index */, false /*nesting*/, wizard,
|
||||||
dimensions, bucketStartTimeNs, bucketStartTimeNs);
|
dimensions, bucketStartTimeNs, bucketStartTimeNs);
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ TEST(EventMetricProducerTest, TestNoCondition) {
|
|||||||
|
|
||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
|
|
||||||
EventMetricProducer eventProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
|
EventMetricProducer eventProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
|
||||||
bucketStartTimeNs);
|
wizard, bucketStartTimeNs);
|
||||||
|
|
||||||
eventProducer.onMatchedLogEvent(1 /*matcher index*/, event1);
|
eventProducer.onMatchedLogEvent(1 /*matcher index*/, event1);
|
||||||
eventProducer.onMatchedLogEvent(1 /*matcher index*/, event2);
|
eventProducer.onMatchedLogEvent(1 /*matcher index*/, event2);
|
||||||
@@ -101,7 +101,8 @@ TEST(EventMetricProducerTest, TestEventsWithNonSlicedCondition) {
|
|||||||
|
|
||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
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.onConditionChanged(true /*condition*/, bucketStartTimeNs);
|
||||||
eventProducer.onMatchedLogEvent(1 /*matcher index*/, event1);
|
eventProducer.onMatchedLogEvent(1 /*matcher index*/, event1);
|
||||||
@@ -155,7 +156,8 @@ TEST(EventMetricProducerTest, TestEventsWithSlicedCondition) {
|
|||||||
// Condition is true for second event.
|
// Condition is true for second event.
|
||||||
EXPECT_CALL(*wizard, query(_, key2, _)).WillOnce(Return(ConditionState::kTrue));
|
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*/, event1);
|
||||||
eventProducer.onMatchedLogEvent(1 /*matcher index*/, event2);
|
eventProducer.onMatchedLogEvent(1 /*matcher index*/, event2);
|
||||||
|
|||||||
@@ -104,10 +104,9 @@ TEST(GaugeMetricProducerTest, TestFirstBucket) {
|
|||||||
|
|
||||||
// statsd started long ago.
|
// statsd started long ago.
|
||||||
// The metric starts in the middle of the bucket
|
// The metric starts in the middle of the bucket
|
||||||
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
|
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
|
||||||
logEventMatcherIndex, eventMatcherWizard,
|
wizard, logEventMatcherIndex, eventMatcherWizard, -1, -1,
|
||||||
-1, -1, tagId, 5, 600 * NS_PER_SEC + NS_PER_SEC / 2,
|
tagId, 5, 600 * NS_PER_SEC + NS_PER_SEC / 2, pullerManager);
|
||||||
pullerManager);
|
|
||||||
gaugeProducer.prepareFirstBucket();
|
gaugeProducer.prepareFirstBucket();
|
||||||
|
|
||||||
EXPECT_EQ(600500000000, gaugeProducer.mCurrentBucketStartTimeNs);
|
EXPECT_EQ(600500000000, gaugeProducer.mCurrentBucketStartTimeNs);
|
||||||
@@ -147,9 +146,9 @@ TEST(GaugeMetricProducerTest, TestPulledEventsNoCondition) {
|
|||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
|
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
|
||||||
logEventMatcherIndex, eventMatcherWizard, tagId, -1, tagId,
|
wizard, logEventMatcherIndex, eventMatcherWizard, tagId, -1,
|
||||||
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
||||||
gaugeProducer.prepareFirstBucket();
|
gaugeProducer.prepareFirstBucket();
|
||||||
|
|
||||||
vector<shared_ptr<LogEvent>> allData;
|
vector<shared_ptr<LogEvent>> allData;
|
||||||
@@ -225,8 +224,8 @@ TEST_P(GaugeMetricProducerTest_PartialBucket, TestPushedEvents) {
|
|||||||
new EventMatcherWizard({new SimpleLogMatchingTracker(
|
new EventMatcherWizard({new SimpleLogMatchingTracker(
|
||||||
atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)});
|
atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)});
|
||||||
|
|
||||||
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
|
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
|
||||||
logEventMatcherIndex, eventMatcherWizard,
|
wizard, logEventMatcherIndex, eventMatcherWizard,
|
||||||
-1 /* -1 means no pulling */, -1, tagId, bucketStartTimeNs,
|
-1 /* -1 means no pulling */, -1, tagId, bucketStartTimeNs,
|
||||||
bucketStartTimeNs, pullerManager);
|
bucketStartTimeNs, pullerManager);
|
||||||
gaugeProducer.prepareFirstBucket();
|
gaugeProducer.prepareFirstBucket();
|
||||||
@@ -308,7 +307,6 @@ TEST_P(GaugeMetricProducerTest_PartialBucket, TestPulled) {
|
|||||||
sp<EventMatcherWizard> eventMatcherWizard =
|
sp<EventMatcherWizard> eventMatcherWizard =
|
||||||
new EventMatcherWizard({new SimpleLogMatchingTracker(
|
new EventMatcherWizard({new SimpleLogMatchingTracker(
|
||||||
atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)});
|
atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)});
|
||||||
|
|
||||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return());
|
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return());
|
||||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return());
|
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return());
|
||||||
@@ -322,9 +320,9 @@ TEST_P(GaugeMetricProducerTest_PartialBucket, TestPulled) {
|
|||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
|
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
|
||||||
logEventMatcherIndex, eventMatcherWizard, tagId, -1, tagId,
|
wizard, logEventMatcherIndex, eventMatcherWizard, tagId, -1,
|
||||||
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
||||||
gaugeProducer.prepareFirstBucket();
|
gaugeProducer.prepareFirstBucket();
|
||||||
|
|
||||||
vector<shared_ptr<LogEvent>> allData;
|
vector<shared_ptr<LogEvent>> allData;
|
||||||
@@ -393,9 +391,9 @@ TEST(GaugeMetricProducerTest, TestPulledWithAppUpgradeDisabled) {
|
|||||||
EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _))
|
EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _))
|
||||||
.WillOnce(Return(false));
|
.WillOnce(Return(false));
|
||||||
|
|
||||||
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
|
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
|
||||||
logEventMatcherIndex, eventMatcherWizard, tagId, -1, tagId,
|
wizard, logEventMatcherIndex, eventMatcherWizard, tagId, -1,
|
||||||
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
||||||
gaugeProducer.prepareFirstBucket();
|
gaugeProducer.prepareFirstBucket();
|
||||||
|
|
||||||
vector<shared_ptr<LogEvent>> allData;
|
vector<shared_ptr<LogEvent>> allData;
|
||||||
@@ -450,7 +448,8 @@ TEST(GaugeMetricProducerTest, TestPulledEventsWithCondition) {
|
|||||||
return true;
|
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,
|
eventMatcherWizard, tagId, -1, tagId, bucketStartTimeNs,
|
||||||
bucketStartTimeNs, pullerManager);
|
bucketStartTimeNs, pullerManager);
|
||||||
gaugeProducer.prepareFirstBucket();
|
gaugeProducer.prepareFirstBucket();
|
||||||
@@ -536,7 +535,8 @@ TEST(GaugeMetricProducerTest, TestPulledEventsWithSlicedCondition) {
|
|||||||
return true;
|
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,
|
eventMatcherWizard, tagId, -1, tagId, bucketStartTimeNs,
|
||||||
bucketStartTimeNs, pullerManager);
|
bucketStartTimeNs, pullerManager);
|
||||||
gaugeProducer.prepareFirstBucket();
|
gaugeProducer.prepareFirstBucket();
|
||||||
@@ -584,9 +584,9 @@ TEST(GaugeMetricProducerTest, TestPulledEventsAnomalyDetection) {
|
|||||||
new EventMatcherWizard({new SimpleLogMatchingTracker(
|
new EventMatcherWizard({new SimpleLogMatchingTracker(
|
||||||
atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)});
|
atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)});
|
||||||
|
|
||||||
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
|
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
|
||||||
logEventMatcherIndex, eventMatcherWizard, tagId, -1, tagId,
|
wizard, logEventMatcherIndex, eventMatcherWizard, tagId, -1,
|
||||||
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
||||||
gaugeProducer.prepareFirstBucket();
|
gaugeProducer.prepareFirstBucket();
|
||||||
|
|
||||||
Alert alert;
|
Alert alert;
|
||||||
@@ -683,9 +683,10 @@ TEST(GaugeMetricProducerTest, TestPullOnTrigger) {
|
|||||||
.WillOnce(Return(true));
|
.WillOnce(Return(true));
|
||||||
|
|
||||||
int triggerId = 5;
|
int triggerId = 5;
|
||||||
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
|
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
|
||||||
logEventMatcherIndex, eventMatcherWizard, tagId, triggerId,
|
wizard, logEventMatcherIndex, eventMatcherWizard, tagId,
|
||||||
tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
triggerId, tagId, bucketStartTimeNs, bucketStartTimeNs,
|
||||||
|
pullerManager);
|
||||||
gaugeProducer.prepareFirstBucket();
|
gaugeProducer.prepareFirstBucket();
|
||||||
|
|
||||||
ASSERT_EQ(0UL, gaugeProducer.mCurrentSlicedBucket->size());
|
ASSERT_EQ(0UL, gaugeProducer.mCurrentSlicedBucket->size());
|
||||||
@@ -761,9 +762,10 @@ TEST(GaugeMetricProducerTest, TestRemoveDimensionInOutput) {
|
|||||||
.WillOnce(Return(true));
|
.WillOnce(Return(true));
|
||||||
|
|
||||||
int triggerId = 5;
|
int triggerId = 5;
|
||||||
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
|
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
|
||||||
logEventMatcherIndex, eventMatcherWizard, tagId, triggerId,
|
wizard, logEventMatcherIndex, eventMatcherWizard, tagId,
|
||||||
tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
triggerId, tagId, bucketStartTimeNs, bucketStartTimeNs,
|
||||||
|
pullerManager);
|
||||||
gaugeProducer.prepareFirstBucket();
|
gaugeProducer.prepareFirstBucket();
|
||||||
|
|
||||||
LogEvent triggerEvent(/*uid=*/0, /*pid=*/0);
|
LogEvent triggerEvent(/*uid=*/0, /*pid=*/0);
|
||||||
@@ -823,9 +825,10 @@ TEST(GaugeMetricProducerTest_BucketDrop, TestBucketDropWhenBucketTooSmall) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
int triggerId = 5;
|
int triggerId = 5;
|
||||||
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
|
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
|
||||||
logEventMatcherIndex, eventMatcherWizard, tagId, triggerId,
|
wizard, logEventMatcherIndex, eventMatcherWizard, tagId,
|
||||||
tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
triggerId, tagId, bucketStartTimeNs, bucketStartTimeNs,
|
||||||
|
pullerManager);
|
||||||
gaugeProducer.prepareFirstBucket();
|
gaugeProducer.prepareFirstBucket();
|
||||||
|
|
||||||
LogEvent triggerEvent(/*uid=*/0, /*pid=*/0);
|
LogEvent triggerEvent(/*uid=*/0, /*pid=*/0);
|
||||||
|
|||||||
@@ -111,15 +111,17 @@ public:
|
|||||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _))
|
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _))
|
||||||
.WillRepeatedly(Return());
|
.WillRepeatedly(Return());
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer = new ValueMetricProducer(
|
sp<ValueMetricProducer> valueProducer =
|
||||||
kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard, logEventMatcherIndex,
|
new ValueMetricProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
|
||||||
eventMatcherWizard, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
wizard, logEventMatcherIndex, eventMatcherWizard, tagId,
|
||||||
|
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
||||||
valueProducer->prepareFirstBucket();
|
valueProducer->prepareFirstBucket();
|
||||||
return valueProducer;
|
return valueProducer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static sp<ValueMetricProducer> createValueProducerWithCondition(
|
static sp<ValueMetricProducer> createValueProducerWithCondition(
|
||||||
sp<MockStatsPullerManager>& pullerManager, ValueMetric& metric) {
|
sp<MockStatsPullerManager>& pullerManager, ValueMetric& metric,
|
||||||
|
ConditionState conditionAfterFirstBucketPrepared) {
|
||||||
UidMap uidMap;
|
UidMap uidMap;
|
||||||
SimpleAtomMatcher atomMatcher;
|
SimpleAtomMatcher atomMatcher;
|
||||||
atomMatcher.set_atom_id(tagId);
|
atomMatcher.set_atom_id(tagId);
|
||||||
@@ -133,31 +135,11 @@ public:
|
|||||||
.WillRepeatedly(Return());
|
.WillRepeatedly(Return());
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer = new ValueMetricProducer(
|
sp<ValueMetricProducer> valueProducer = new ValueMetricProducer(
|
||||||
kConfigKey, metric, 1, wizard, logEventMatcherIndex, eventMatcherWizard, tagId,
|
kConfigKey, metric, 0 /*condition index*/, {ConditionState::kUnknown}, wizard,
|
||||||
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
logEventMatcherIndex, eventMatcherWizard, tagId, bucketStartTimeNs,
|
||||||
valueProducer->prepareFirstBucket();
|
bucketStartTimeNs, pullerManager);
|
||||||
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);
|
|
||||||
valueProducer->prepareFirstBucket();
|
valueProducer->prepareFirstBucket();
|
||||||
|
valueProducer->mCondition = conditionAfterFirstBucketPrepared;
|
||||||
return valueProducer;
|
return valueProducer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,8 +158,9 @@ public:
|
|||||||
.WillOnce(Return());
|
.WillOnce(Return());
|
||||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _))
|
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _))
|
||||||
.WillRepeatedly(Return());
|
.WillRepeatedly(Return());
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer = new ValueMetricProducer(
|
sp<ValueMetricProducer> valueProducer = new ValueMetricProducer(
|
||||||
kConfigKey, metric, -1 /* no condition */, wizard, logEventMatcherIndex,
|
kConfigKey, metric, -1 /* no condition */, {}, wizard, logEventMatcherIndex,
|
||||||
eventMatcherWizard, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager, {},
|
eventMatcherWizard, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager, {},
|
||||||
{}, slicedStateAtoms, stateGroupMap);
|
{}, slicedStateAtoms, stateGroupMap);
|
||||||
valueProducer->prepareFirstBucket();
|
valueProducer->prepareFirstBucket();
|
||||||
@@ -232,9 +215,9 @@ TEST(ValueMetricProducerTest, TestCalcPreviousBucketEndTime) {
|
|||||||
|
|
||||||
// statsd started long ago.
|
// statsd started long ago.
|
||||||
// The metric starts in the middle of the bucket
|
// The metric starts in the middle of the bucket
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
|
ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
|
||||||
logEventMatcherIndex, eventMatcherWizard, -1, startTimeBase,
|
wizard, logEventMatcherIndex, eventMatcherWizard, -1,
|
||||||
22, pullerManager);
|
startTimeBase, 22, pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
|
|
||||||
EXPECT_EQ(startTimeBase, valueProducer.calcPreviousBucketEndTime(60 * NS_PER_SEC + 10));
|
EXPECT_EQ(startTimeBase, valueProducer.calcPreviousBucketEndTime(60 * NS_PER_SEC + 10));
|
||||||
@@ -262,8 +245,8 @@ TEST(ValueMetricProducerTest, TestFirstBucket) {
|
|||||||
|
|
||||||
// statsd started long ago.
|
// statsd started long ago.
|
||||||
// The metric starts in the middle of the bucket
|
// The metric starts in the middle of the bucket
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
|
ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
|
||||||
logEventMatcherIndex, eventMatcherWizard, -1, 5,
|
wizard, logEventMatcherIndex, eventMatcherWizard, -1, 5,
|
||||||
600 * NS_PER_SEC + NS_PER_SEC / 2, pullerManager);
|
600 * NS_PER_SEC + NS_PER_SEC / 2, pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
|
|
||||||
@@ -427,7 +410,7 @@ TEST(ValueMetricProducerTest, TestPulledEventsWithFiltering) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer = new ValueMetricProducer(
|
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);
|
eventMatcherWizard, tagId, bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
||||||
valueProducer->prepareFirstBucket();
|
valueProducer->prepareFirstBucket();
|
||||||
|
|
||||||
@@ -629,7 +612,8 @@ TEST(ValueMetricProducerTest, TestEventsWithNonSlicedCondition) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
||||||
|
|
||||||
@@ -689,7 +673,8 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestPushedEvents) {
|
|||||||
atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)});
|
atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)});
|
||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
|
|
||||||
|
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
|
||||||
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
||||||
pullerManager);
|
pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
@@ -762,7 +747,8 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestPulledValue) {
|
|||||||
data->push_back(CreateRepeatedValueLogEvent(tagId, partialBucketSplitTimeNs, 120));
|
data->push_back(CreateRepeatedValueLogEvent(tagId, partialBucketSplitTimeNs, 120));
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
|
|
||||||
|
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
|
||||||
eventMatcherWizard, tagId, bucketStartTimeNs,
|
eventMatcherWizard, tagId, bucketStartTimeNs,
|
||||||
bucketStartTimeNs, pullerManager);
|
bucketStartTimeNs, pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
@@ -813,7 +799,8 @@ TEST(ValueMetricProducerTest, TestPulledWithAppUpgradeDisabled) {
|
|||||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return());
|
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillOnce(Return());
|
||||||
EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _))
|
EXPECT_CALL(*pullerManager, Pull(tagId, kConfigKey, bucketStartTimeNs, _, _))
|
||||||
.WillOnce(Return(true));
|
.WillOnce(Return(true));
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
|
|
||||||
|
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
|
||||||
eventMatcherWizard, tagId, bucketStartTimeNs,
|
eventMatcherWizard, tagId, bucketStartTimeNs,
|
||||||
bucketStartTimeNs, pullerManager);
|
bucketStartTimeNs, pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
@@ -851,7 +838,8 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestPulledValueWhileConditionFalse
|
|||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 1);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 1);
|
||||||
|
|
||||||
@@ -875,6 +863,7 @@ TEST_P(ValueMetricProducerTest_PartialBucket, TestPulledValueWhileConditionFalse
|
|||||||
{bucketStartTimeNs}, {partialBucketSplitTimeNs});
|
{bucketStartTimeNs}, {partialBucketSplitTimeNs});
|
||||||
EXPECT_FALSE(valueProducer->mCondition);
|
EXPECT_FALSE(valueProducer->mCondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ValueMetricProducerTest, TestPushedEventsWithoutCondition) {
|
TEST(ValueMetricProducerTest, TestPushedEventsWithoutCondition) {
|
||||||
ValueMetric metric = ValueMetricProducerTestHelper::createMetric();
|
ValueMetric metric = ValueMetricProducerTestHelper::createMetric();
|
||||||
|
|
||||||
@@ -887,7 +876,7 @@ TEST(ValueMetricProducerTest, TestPushedEventsWithoutCondition) {
|
|||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||||
|
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
|
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
|
||||||
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
||||||
pullerManager);
|
pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
@@ -931,9 +920,9 @@ TEST(ValueMetricProducerTest, TestPushedEventsWithCondition) {
|
|||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||||
|
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, 1, wizard, logEventMatcherIndex,
|
ValueMetricProducer valueProducer(kConfigKey, metric, 0, {ConditionState::kUnknown}, wizard,
|
||||||
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
logEventMatcherIndex, eventMatcherWizard, -1,
|
||||||
pullerManager);
|
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
valueProducer.mCondition = ConditionState::kFalse;
|
valueProducer.mCondition = ConditionState::kFalse;
|
||||||
|
|
||||||
@@ -1001,9 +990,11 @@ TEST(ValueMetricProducerTest, TestAnomalyDetection) {
|
|||||||
atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)});
|
atomMatcherId, logEventMatcherIndex, atomMatcher, uidMap)});
|
||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
|
|
||||||
logEventMatcherIndex, eventMatcherWizard, -1 /*not pulled*/,
|
ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, {},
|
||||||
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
wizard, logEventMatcherIndex, eventMatcherWizard,
|
||||||
|
-1 /*not pulled*/, bucketStartTimeNs, bucketStartTimeNs,
|
||||||
|
pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
|
|
||||||
sp<AnomalyTracker> anomalyTracker = valueProducer.addAnomalyTracker(alert, alarmMonitor);
|
sp<AnomalyTracker> anomalyTracker = valueProducer.addAnomalyTracker(alert, alarmMonitor);
|
||||||
@@ -1158,7 +1149,8 @@ TEST(ValueMetricProducerTest, TestBucketBoundaryWithCondition) {
|
|||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
||||||
|
|
||||||
@@ -1229,7 +1221,8 @@ TEST(ValueMetricProducerTest, TestBucketBoundaryWithCondition2) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
||||||
|
|
||||||
@@ -1300,7 +1293,7 @@ TEST(ValueMetricProducerTest, TestPushedAggregateMin) {
|
|||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||||
|
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
|
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
|
||||||
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
||||||
pullerManager);
|
pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
@@ -1344,7 +1337,7 @@ TEST(ValueMetricProducerTest, TestPushedAggregateMax) {
|
|||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||||
|
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
|
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
|
||||||
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
||||||
pullerManager);
|
pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
@@ -1387,7 +1380,7 @@ TEST(ValueMetricProducerTest, TestPushedAggregateAvg) {
|
|||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||||
|
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
|
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
|
||||||
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
||||||
pullerManager);
|
pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
@@ -1435,7 +1428,7 @@ TEST(ValueMetricProducerTest, TestPushedAggregateSum) {
|
|||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||||
|
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
|
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
|
||||||
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
||||||
pullerManager);
|
pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
@@ -1479,7 +1472,7 @@ TEST(ValueMetricProducerTest, TestSkipZeroDiffOutput) {
|
|||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||||
|
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
|
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
|
||||||
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
||||||
pullerManager);
|
pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
@@ -1551,7 +1544,7 @@ TEST(ValueMetricProducerTest, TestSkipZeroDiffOutputMultiValue) {
|
|||||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||||
|
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
|
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
|
||||||
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
eventMatcherWizard, -1, bucketStartTimeNs, bucketStartTimeNs,
|
||||||
pullerManager);
|
pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
@@ -1944,7 +1937,8 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullFailAfterConditionChange_EndOfB
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
||||||
// has one slice
|
// has one slice
|
||||||
@@ -1979,7 +1973,8 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullFailAfterConditionChange) {
|
|||||||
.WillOnce(Return(false));
|
.WillOnce(Return(false));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
||||||
|
|
||||||
@@ -2023,7 +2018,8 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullFailBeforeConditionChange) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
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
|
// Don't directly set mCondition; the real code never does that. Go through regular code path
|
||||||
// to avoid unexpected behaviors.
|
// to avoid unexpected behaviors.
|
||||||
@@ -2057,9 +2053,8 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullDelayExceeded) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
valueProducer->mCondition = ConditionState::kFalse;
|
|
||||||
|
|
||||||
// Max delay is set to 0 so pull will exceed max delay.
|
// Max delay is set to 0 so pull will exceed max delay.
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 1);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 1);
|
||||||
@@ -2080,9 +2075,9 @@ TEST(ValueMetricProducerTest, TestResetBaseOnPullTooLate) {
|
|||||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return());
|
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, kConfigKey, _, _, _)).WillOnce(Return());
|
||||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillRepeatedly(Return());
|
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, kConfigKey, _)).WillRepeatedly(Return());
|
||||||
|
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, 1, wizard, logEventMatcherIndex,
|
ValueMetricProducer valueProducer(kConfigKey, metric, 0, {ConditionState::kUnknown}, wizard,
|
||||||
eventMatcherWizard, tagId, bucket2StartTimeNs,
|
logEventMatcherIndex, eventMatcherWizard, tagId,
|
||||||
bucket2StartTimeNs, pullerManager);
|
bucket2StartTimeNs, bucket2StartTimeNs, pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
valueProducer.mCondition = ConditionState::kFalse;
|
valueProducer.mCondition = ConditionState::kFalse;
|
||||||
|
|
||||||
@@ -2105,9 +2100,8 @@ TEST(ValueMetricProducerTest, TestBaseSetOnConditionChange) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
valueProducer->mCondition = ConditionState::kFalse;
|
|
||||||
valueProducer->mHasGlobalBase = false;
|
valueProducer->mHasGlobalBase = false;
|
||||||
|
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 1);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 1);
|
||||||
@@ -2142,9 +2136,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenOneConditionFailed
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kTrue);
|
||||||
valueProducer->mCondition = ConditionState::kTrue;
|
|
||||||
|
|
||||||
// Bucket start.
|
// Bucket start.
|
||||||
vector<shared_ptr<LogEvent>> allData;
|
vector<shared_ptr<LogEvent>> allData;
|
||||||
@@ -2218,8 +2211,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenGuardRailHit) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
valueProducer->mCondition = ConditionState::kFalse;
|
ConditionState::kFalse);
|
||||||
|
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 2);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 2);
|
||||||
EXPECT_EQ(true, valueProducer->mCurrentBucketIsSkipped);
|
EXPECT_EQ(true, valueProducer->mCurrentBucketIsSkipped);
|
||||||
@@ -2283,9 +2276,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenInitialPullFailed)
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kTrue);
|
||||||
valueProducer->mCondition = ConditionState::kTrue;
|
|
||||||
|
|
||||||
// Bucket start.
|
// Bucket start.
|
||||||
vector<shared_ptr<LogEvent>> allData;
|
vector<shared_ptr<LogEvent>> allData;
|
||||||
@@ -2363,9 +2355,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenLastPullFailed) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kTrue);
|
||||||
valueProducer->mCondition = ConditionState::kTrue;
|
|
||||||
|
|
||||||
// Bucket start.
|
// Bucket start.
|
||||||
vector<shared_ptr<LogEvent>> allData;
|
vector<shared_ptr<LogEvent>> allData;
|
||||||
@@ -2468,7 +2459,8 @@ TEST(ValueMetricProducerTest, TestEmptyDataResetsBase_onConditionChanged) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
|
||||||
ASSERT_EQ(1UL, valueProducer->mCurrentSlicedBucket.size());
|
ASSERT_EQ(1UL, valueProducer->mCurrentSlicedBucket.size());
|
||||||
@@ -2518,7 +2510,8 @@ TEST(ValueMetricProducerTest, TestEmptyDataResetsBase_onBucketBoundary) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
|
||||||
valueProducer->onConditionChanged(false, bucketStartTimeNs + 11);
|
valueProducer->onConditionChanged(false, bucketStartTimeNs + 11);
|
||||||
@@ -2566,7 +2559,8 @@ TEST(ValueMetricProducerTest, TestPartialResetOnBucketBoundaries) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
|
||||||
ASSERT_EQ(1UL, valueProducer->mCurrentSlicedBucket.size());
|
ASSERT_EQ(1UL, valueProducer->mCurrentSlicedBucket.size());
|
||||||
@@ -2673,8 +2667,8 @@ TEST(ValueMetricProducerTest, TestBucketBoundariesOnConditionChange) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(
|
||||||
valueProducer->mCondition = ConditionState::kUnknown;
|
pullerManager, metric, ConditionState::kUnknown);
|
||||||
|
|
||||||
valueProducer->onConditionChanged(false, bucketStartTimeNs);
|
valueProducer->onConditionChanged(false, bucketStartTimeNs);
|
||||||
ASSERT_EQ(0UL, valueProducer->mCurrentSlicedBucket.size());
|
ASSERT_EQ(0UL, valueProducer->mCurrentSlicedBucket.size());
|
||||||
@@ -2814,7 +2808,8 @@ TEST(ValueMetricProducerTest, TestDataIsNotUpdatedWhenNoConditionChanged) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
||||||
valueProducer->onConditionChanged(false, bucketStartTimeNs + 10);
|
valueProducer->onConditionChanged(false, bucketStartTimeNs + 10);
|
||||||
@@ -2866,7 +2861,8 @@ TEST(ValueMetricProducerTest, TestBucketInvalidIfGlobalBaseIsNotSet) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
valueProducer->onConditionChanged(true, bucket2StartTimeNs + 10);
|
valueProducer->onConditionChanged(true, bucket2StartTimeNs + 10);
|
||||||
|
|
||||||
vector<shared_ptr<LogEvent>> allData;
|
vector<shared_ptr<LogEvent>> allData;
|
||||||
@@ -2911,7 +2907,7 @@ TEST(ValueMetricProducerTest, TestPullNeededFastDump) {
|
|||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
|
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
|
||||||
eventMatcherWizard, tagId, bucketStartTimeNs,
|
eventMatcherWizard, tagId, bucketStartTimeNs,
|
||||||
bucketStartTimeNs, pullerManager);
|
bucketStartTimeNs, pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
@@ -2949,7 +2945,7 @@ TEST(ValueMetricProducerTest, TestFastDumpWithoutCurrentBucket) {
|
|||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
|
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
|
||||||
eventMatcherWizard, tagId, bucketStartTimeNs,
|
eventMatcherWizard, tagId, bucketStartTimeNs,
|
||||||
bucketStartTimeNs, pullerManager);
|
bucketStartTimeNs, pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
@@ -3002,7 +2998,7 @@ TEST(ValueMetricProducerTest, TestPullNeededNoTimeConstraints) {
|
|||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, logEventMatcherIndex,
|
ValueMetricProducer valueProducer(kConfigKey, metric, -1, {}, wizard, logEventMatcherIndex,
|
||||||
eventMatcherWizard, tagId, bucketStartTimeNs,
|
eventMatcherWizard, tagId, bucketStartTimeNs,
|
||||||
bucketStartTimeNs, pullerManager);
|
bucketStartTimeNs, pullerManager);
|
||||||
valueProducer.prepareFirstBucket();
|
valueProducer.prepareFirstBucket();
|
||||||
@@ -3058,8 +3054,8 @@ TEST(ValueMetricProducerTest, TestPulledData_noDiff_withMultipleConditionChanges
|
|||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
valueProducer->mCondition = ConditionState::kFalse;
|
ConditionState::kFalse);
|
||||||
|
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
||||||
valueProducer->onConditionChanged(false, bucketStartTimeNs + 50);
|
valueProducer->onConditionChanged(false, bucketStartTimeNs + 50);
|
||||||
@@ -3099,8 +3095,8 @@ TEST(ValueMetricProducerTest, TestPulledData_noDiff_bucketBoundaryTrue) {
|
|||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
valueProducer->mCondition = ConditionState::kFalse;
|
ConditionState::kFalse);
|
||||||
|
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
||||||
|
|
||||||
@@ -3124,8 +3120,8 @@ TEST(ValueMetricProducerTest, TestPulledData_noDiff_bucketBoundaryFalse) {
|
|||||||
|
|
||||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
valueProducer->mCondition = ConditionState::kFalse;
|
ConditionState::kFalse);
|
||||||
|
|
||||||
// Now the alarm is delivered. Condition is off though.
|
// Now the alarm is delivered. Condition is off though.
|
||||||
vector<shared_ptr<LogEvent>> allData;
|
vector<shared_ptr<LogEvent>> allData;
|
||||||
@@ -3152,8 +3148,8 @@ TEST(ValueMetricProducerTest, TestPulledData_noDiff_withFailure) {
|
|||||||
}))
|
}))
|
||||||
.WillOnce(Return(false));
|
.WillOnce(Return(false));
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
valueProducer->mCondition = ConditionState::kFalse;
|
ConditionState::kFalse);
|
||||||
|
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 8);
|
||||||
valueProducer->onConditionChanged(false, bucketStartTimeNs + 50);
|
valueProducer->onConditionChanged(false, bucketStartTimeNs + 50);
|
||||||
@@ -3191,7 +3187,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenDumpReportRequeste
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
// Condition change event.
|
// Condition change event.
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 20);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 20);
|
||||||
@@ -3236,7 +3233,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenConditionEventWron
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
// Condition change event.
|
// Condition change event.
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 50);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 50);
|
||||||
@@ -3298,7 +3296,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenAccumulateEventWro
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
// Condition change event.
|
// Condition change event.
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 50);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 50);
|
||||||
@@ -3363,8 +3362,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenConditionUnknown)
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithNoInitialCondition(pullerManager,
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(
|
||||||
metric);
|
pullerManager, metric, ConditionState::kUnknown);
|
||||||
|
|
||||||
// Condition change event.
|
// Condition change event.
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 50);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 50);
|
||||||
@@ -3413,7 +3412,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenPullFailed) {
|
|||||||
.WillOnce(Return(false));
|
.WillOnce(Return(false));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
// Condition change event.
|
// Condition change event.
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 50);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 50);
|
||||||
@@ -3468,7 +3468,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestInvalidBucketWhenMultipleBucketsSki
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
// Condition change event.
|
// Condition change event.
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
|
||||||
@@ -3542,7 +3543,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestBucketDropWhenBucketTooSmall) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
// Condition change event.
|
// Condition change event.
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
|
||||||
@@ -3579,7 +3581,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestBucketDropWhenDataUnavailable) {
|
|||||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(
|
||||||
|
pullerManager, metric, ConditionState::kUnknown);
|
||||||
|
|
||||||
// Check dump report.
|
// Check dump report.
|
||||||
ProtoOutputStream output;
|
ProtoOutputStream output;
|
||||||
@@ -3632,7 +3635,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestBucketDropWhenForceBucketSplitBefor
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric);
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(pullerManager, metric,
|
||||||
|
ConditionState::kFalse);
|
||||||
|
|
||||||
// Condition changed event
|
// Condition changed event
|
||||||
int64_t conditionChangeTimeNs = bucketStartTimeNs + 10;
|
int64_t conditionChangeTimeNs = bucketStartTimeNs + 10;
|
||||||
@@ -3687,8 +3691,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestMultipleBucketDropEvents) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithNoInitialCondition(pullerManager,
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(
|
||||||
metric);
|
pullerManager, metric, ConditionState::kUnknown);
|
||||||
|
|
||||||
// Condition change event.
|
// Condition change event.
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
|
||||||
@@ -3756,8 +3760,8 @@ TEST(ValueMetricProducerTest_BucketDrop, TestMaxBucketDropEvents) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
sp<ValueMetricProducer> valueProducer =
|
sp<ValueMetricProducer> valueProducer =
|
||||||
ValueMetricProducerTestHelper::createValueProducerWithNoInitialCondition(pullerManager,
|
ValueMetricProducerTestHelper::createValueProducerWithCondition(
|
||||||
metric);
|
pullerManager, metric, ConditionState::kUnknown);
|
||||||
|
|
||||||
// First condition change event causes guardrail to be reached.
|
// First condition change event causes guardrail to be reached.
|
||||||
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
|
valueProducer->onConditionChanged(true, bucketStartTimeNs + 10);
|
||||||
|
|||||||
Reference in New Issue
Block a user