summaryrefslogtreecommitdiff
path: root/cmds/statsd/src/StatsService.cpp
diff options
context:
space:
mode:
authorTej Singh <singhtejinder@google.com>2020-07-14 23:16:24 -0700
committerJeffrey Huang <jeffreyhuang@google.com>2020-10-09 16:05:57 -0700
commit8b914c0f00144aa5785e7fc51dd112ffa9ef4832 (patch)
treec24449c0434c3e608b850d5adeb3713f62ba93a1 /cmds/statsd/src/StatsService.cpp
parent85e07ab8bb30fa7aeda8c7e87cef52879c55ab77 (diff)
Remove alarm manager dependency from anomalyalarms
Anomaly alarms, which are used for prediction-base duration metric anomaly detection, currently use alarm manager for setting alarms. This can result in excessive binder calls to SCS to set/cancel the alarms if the duration metric that the alarm is based on gets stopped/started in quick succession. To resolve this without losing precision, we can instead rely on the flow of events into the statsd socket for this prediction. The socket receives events very frequently, so there should be minimal (if any) loss of precision, and we can remove the binder call entirely. One concern is that we used to hold a wakelock when the alarm fired (since alarm manager would hold a wakelock), and we now lose this ability. Test: atest statsd_test Test: atest AnomalyDetectionTests Bug: 161326200 Bug: 152642091 Change-Id: If37e5c6ccd8efa4e822c70a0444fa6b5a31bebca Merged-In: If37e5c6ccd8efa4e822c70a0444fa6b5a31bebca
Diffstat (limited to 'cmds/statsd/src/StatsService.cpp')
-rw-r--r--cmds/statsd/src/StatsService.cpp28
1 files changed, 7 insertions, 21 deletions
diff --git a/cmds/statsd/src/StatsService.cpp b/cmds/statsd/src/StatsService.cpp
index 322648229d0e..73d16cdf608a 100644
--- a/cmds/statsd/src/StatsService.cpp
+++ b/cmds/statsd/src/StatsService.cpp
@@ -91,17 +91,13 @@ Status checkUid(uid_t expectedUid) {
StatsService::StatsService(const sp<Looper>& handlerLooper, shared_ptr<LogEventQueue> queue)
: mAnomalyAlarmMonitor(new AlarmMonitor(
MIN_DIFF_TO_UPDATE_REGISTERED_ALARM_SECS,
- [](const shared_ptr<IStatsCompanionService>& sc, int64_t timeMillis) {
- if (sc != nullptr) {
- sc->setAnomalyAlarm(timeMillis);
- StatsdStats::getInstance().noteRegisteredAnomalyAlarmChanged();
- }
+ [this](const shared_ptr<IStatsCompanionService>& /*sc*/, int64_t timeMillis) {
+ mProcessor->setAnomalyAlarm(timeMillis);
+ StatsdStats::getInstance().noteRegisteredAnomalyAlarmChanged();
},
- [](const shared_ptr<IStatsCompanionService>& sc) {
- if (sc != nullptr) {
- sc->cancelAnomalyAlarm();
- StatsdStats::getInstance().noteRegisteredAnomalyAlarmChanged();
- }
+ [this](const shared_ptr<IStatsCompanionService>& /*sc*/) {
+ mProcessor->cancelAnomalyAlarm();
+ StatsdStats::getInstance().noteRegisteredAnomalyAlarmChanged();
})),
mPeriodicAlarmMonitor(new AlarmMonitor(
MIN_DIFF_TO_UPDATE_REGISTERED_ALARM_SECS,
@@ -977,17 +973,7 @@ Status StatsService::informOnePackageRemoved(const string& app, int32_t uid) {
Status StatsService::informAnomalyAlarmFired() {
ENFORCE_UID(AID_SYSTEM);
-
- VLOG("StatsService::informAnomalyAlarmFired was called");
- int64_t currentTimeSec = getElapsedRealtimeSec();
- std::unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>> alarmSet =
- mAnomalyAlarmMonitor->popSoonerThan(static_cast<uint32_t>(currentTimeSec));
- if (alarmSet.size() > 0) {
- VLOG("Found an anomaly alarm that fired.");
- mProcessor->onAnomalyAlarmFired(currentTimeSec * NS_PER_SEC, alarmSet);
- } else {
- VLOG("Cannot find an anomaly alarm that fired. Perhaps it was recently cancelled.");
- }
+ // Anomaly alarms are handled internally now. This code should be fully deleted.
return Status::ok();
}