Loading cmds/statsd/src/StatsService.cpp +9 −2 Original line number Diff line number Diff line Loading @@ -669,11 +669,18 @@ Status StatsService::informAnomalyAlarmFired() { "Only system uid can call informAnomalyAlarmFired"); } VLOG("StatsService::informAnomalyAlarmFired succeeded"); // TODO: This may be a bug. time(nullptr) can be off (wrt AlarmManager's time) and cause us to // miss the alarm! Eventually we will switch to using elapsedRealTime everywhere, // which may hopefully fix the problem, so we'll leave this alone for now. uint64_t currentTimeSec = time(nullptr); std::unordered_set<sp<const AnomalyAlarm>, SpHash<AnomalyAlarm>> anomalySet = mAnomalyMonitor->popSoonerThan(static_cast<uint32_t>(currentTimeSec)); if (anomalySet.size() > 0) { VLOG("Found an anomaly alarm that fired."); mProcessor->onAnomalyAlarmFired(currentTimeSec * NS_PER_SEC, anomalySet); } else { VLOG("Cannot find an anomaly alarm that fired. Perhaps it was recently cancelled."); } return Status::ok(); } Loading cmds/statsd/src/anomaly/DurationAnomalyTracker.cpp +4 −3 Original line number Diff line number Diff line Loading @@ -53,10 +53,11 @@ void DurationAnomalyTracker::declareAnomalyIfAlarmExpired(const MetricDimensionK void DurationAnomalyTracker::startAlarm(const MetricDimensionKey& dimensionKey, const uint64_t& timestampNs) { uint32_t timestampSec = static_cast<uint32_t>(timestampNs / NS_PER_SEC); // Alarms are stored in secs. Must round up, since if it fires early, it is ignored completely. uint32_t timestampSec = static_cast<uint32_t>((timestampNs -1)/ NS_PER_SEC) + 1; // round up if (isInRefractoryPeriod(timestampNs, dimensionKey)) { VLOG("Skipping setting anomaly alarm since it'd fall in the refractory period"); return; VLOG("Setting a delayed anomaly alarm lest it fall in the refractory period"); timestampSec = getRefractoryPeriodEndsSec(dimensionKey) + 1; } sp<const AnomalyAlarm> alarm = new AnomalyAlarm{timestampSec}; mAlarms.insert({dimensionKey, alarm}); Loading services/core/java/com/android/server/stats/StatsCompanionService.java +3 −3 Original line number Diff line number Diff line Loading @@ -290,7 +290,8 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { public final static class AnomalyAlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Slog.i(TAG, "StatsCompanionService believes an anomaly has occurred."); Slog.i(TAG, "StatsCompanionService believes an anomaly has occurred at time " + System.currentTimeMillis() + "ms."); synchronized (sStatsdLock) { if (sStatsd == null) { Slog.w(TAG, "Could not access statsd to inform it of anomaly alarm firing"); Loading Loading @@ -361,9 +362,8 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { final long callingToken = Binder.clearCallingIdentity(); try { // using RTC, not RTC_WAKEUP, so if device is asleep, will only fire when it awakens. // This alarm is inexact, leaving its exactness completely up to the OS optimizations. // AlarmManager will automatically cancel any previous mAnomalyAlarmIntent alarm. mAlarmManager.set(AlarmManager.RTC, timestampMs, mAnomalyAlarmIntent); mAlarmManager.setExact(AlarmManager.RTC, timestampMs, mAnomalyAlarmIntent); } finally { Binder.restoreCallingIdentity(callingToken); } Loading cmds/statsd/src/anomaly/AnomalyMonitor.cpp +1 −1 File changed.Contains only whitespace changes. Show changes Loading
cmds/statsd/src/StatsService.cpp +9 −2 Original line number Diff line number Diff line Loading @@ -669,11 +669,18 @@ Status StatsService::informAnomalyAlarmFired() { "Only system uid can call informAnomalyAlarmFired"); } VLOG("StatsService::informAnomalyAlarmFired succeeded"); // TODO: This may be a bug. time(nullptr) can be off (wrt AlarmManager's time) and cause us to // miss the alarm! Eventually we will switch to using elapsedRealTime everywhere, // which may hopefully fix the problem, so we'll leave this alone for now. uint64_t currentTimeSec = time(nullptr); std::unordered_set<sp<const AnomalyAlarm>, SpHash<AnomalyAlarm>> anomalySet = mAnomalyMonitor->popSoonerThan(static_cast<uint32_t>(currentTimeSec)); if (anomalySet.size() > 0) { VLOG("Found an anomaly alarm that fired."); mProcessor->onAnomalyAlarmFired(currentTimeSec * NS_PER_SEC, anomalySet); } else { VLOG("Cannot find an anomaly alarm that fired. Perhaps it was recently cancelled."); } return Status::ok(); } Loading
cmds/statsd/src/anomaly/DurationAnomalyTracker.cpp +4 −3 Original line number Diff line number Diff line Loading @@ -53,10 +53,11 @@ void DurationAnomalyTracker::declareAnomalyIfAlarmExpired(const MetricDimensionK void DurationAnomalyTracker::startAlarm(const MetricDimensionKey& dimensionKey, const uint64_t& timestampNs) { uint32_t timestampSec = static_cast<uint32_t>(timestampNs / NS_PER_SEC); // Alarms are stored in secs. Must round up, since if it fires early, it is ignored completely. uint32_t timestampSec = static_cast<uint32_t>((timestampNs -1)/ NS_PER_SEC) + 1; // round up if (isInRefractoryPeriod(timestampNs, dimensionKey)) { VLOG("Skipping setting anomaly alarm since it'd fall in the refractory period"); return; VLOG("Setting a delayed anomaly alarm lest it fall in the refractory period"); timestampSec = getRefractoryPeriodEndsSec(dimensionKey) + 1; } sp<const AnomalyAlarm> alarm = new AnomalyAlarm{timestampSec}; mAlarms.insert({dimensionKey, alarm}); Loading
services/core/java/com/android/server/stats/StatsCompanionService.java +3 −3 Original line number Diff line number Diff line Loading @@ -290,7 +290,8 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { public final static class AnomalyAlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Slog.i(TAG, "StatsCompanionService believes an anomaly has occurred."); Slog.i(TAG, "StatsCompanionService believes an anomaly has occurred at time " + System.currentTimeMillis() + "ms."); synchronized (sStatsdLock) { if (sStatsd == null) { Slog.w(TAG, "Could not access statsd to inform it of anomaly alarm firing"); Loading Loading @@ -361,9 +362,8 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { final long callingToken = Binder.clearCallingIdentity(); try { // using RTC, not RTC_WAKEUP, so if device is asleep, will only fire when it awakens. // This alarm is inexact, leaving its exactness completely up to the OS optimizations. // AlarmManager will automatically cancel any previous mAnomalyAlarmIntent alarm. mAlarmManager.set(AlarmManager.RTC, timestampMs, mAnomalyAlarmIntent); mAlarmManager.setExact(AlarmManager.RTC, timestampMs, mAnomalyAlarmIntent); } finally { Binder.restoreCallingIdentity(callingToken); } Loading
cmds/statsd/src/anomaly/AnomalyMonitor.cpp +1 −1 File changed.Contains only whitespace changes. Show changes