metric activation on boot
Bug: 123038368
Test: unit test
Change-Id: Id374bdfd8d15264ada0e7bac0388080be308ac8f
diff --git a/cmds/statsd/src/metrics/MetricProducer.h b/cmds/statsd/src/metrics/MetricProducer.h
index ca37bbb..849cb76 100644
--- a/cmds/statsd/src/metrics/MetricProducer.h
+++ b/cmds/statsd/src/metrics/MetricProducer.h
@@ -37,12 +37,13 @@
// If the metric has no activation requirement, it will be active once the metric producer is
// created.
// If the metric needs to be activated by atoms, the metric producer will start
-// with kNotActive state, turn to kActive when the activation event arrives, become kNotActive
-// when it reaches the duration limit (timebomb). If the activation event arrives again before
-// or after it expires, the event producer will be re-activated and ttl will be reset.
+// with kNotActive state, turn to kActive or kActiveOnBoot when the activation event arrives, become
+// kNotActive when it reaches the duration limit (timebomb). If the activation event arrives again
+// before or after it expires, the event producer will be re-activated and ttl will be reset.
enum ActivationState {
kNotActive = 0,
kActive = 1,
+ kActiveOnBoot = 2,
};
// A MetricProducer is responsible for compute one single metrics, creating stats log report, and
@@ -218,8 +219,17 @@
return isActiveLocked();
}
+ void prepActiveForBootIfNecessary(int64_t currentTimeNs) {
+ std::lock_guard<std::mutex> lock(mMutex);
+ prepActiveForBootIfNecessaryLocked(currentTimeNs);
+ }
+
void addActivation(int activationTrackerIndex, int64_t ttl_seconds);
+ inline void setActivationType(const MetricActivation::ActivationType& activationType) {
+ mActivationType = activationType;
+ }
+
void flushIfExpire(int64_t elapsedTimestampNs);
protected:
@@ -243,6 +253,8 @@
return mIsActive;
}
+ void prepActiveForBootIfNecessaryLocked(int64_t currentTimeNs);
+
int64_t getRemainingTtlNsLocked(int64_t currentTimeNs) const;
void setActiveLocked(int64_t currentTimeNs, int64_t remainingTtlNs);
@@ -367,9 +379,12 @@
bool mIsActive;
+ MetricActivation::ActivationType mActivationType;
+
FRIEND_TEST(MetricActivationE2eTest, TestCountMetric);
FRIEND_TEST(StatsLogProcessorTest, TestActiveConfigMetricDiskWriteRead);
+ FRIEND_TEST(StatsLogProcessorTest, TestActivationOnBoot);
};
} // namespace statsd