Loading cmds/statsd/src/anomaly/AnomalyTracker.cpp +27 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,9 @@ #include "AnomalyTracker.h" #include <android/os/IIncidentManager.h> #include <android/os/IncidentReportArgs.h> #include <binder/IServiceManager.h> #include <time.h> namespace android { Loading Loading @@ -213,7 +216,7 @@ void AnomalyTracker::declareAnomaly(const uint64_t& timestampNs) { // TODO: Can construct a name based on the criteria (and/or relay the criteria). ALOGW("An anomaly (nameless) has occurred! Informing incidentd."); } // TODO: informIncidentd(); informIncidentd(); } else { ALOGW("An anomaly has occurred! (But informing incidentd not requested.)"); } Loading Loading @@ -314,6 +317,29 @@ void AnomalyTracker::informAlarmsFired(const uint64_t& timestampNs, } } void AnomalyTracker::informIncidentd() { VLOG("informIncidentd called."); if (!mAlert.has_incidentd_details()) { ALOGE("Attempted to call incidentd without any incidentd_details."); return; } sp<IIncidentManager> service = interface_cast<IIncidentManager>( defaultServiceManager()->getService(android::String16("incident"))); if (service == NULL) { ALOGW("Couldn't get the incident service."); return; } IncidentReportArgs incidentReport; const Alert::IncidentdDetails& details = mAlert.incidentd_details(); for (int i = 0; i < details.section_size(); i++) { incidentReport.addSection(details.section(i)); } // TODO: Pass in mAlert.name() into the addHeader? service->reportIncident(incidentReport); } } // namespace statsd } // namespace os } // namespace android cmds/statsd/src/anomaly/AnomalyTracker.h +3 −0 Original line number Diff line number Diff line Loading @@ -148,6 +148,9 @@ protected: // Resets all bucket data. For use when all the data gets stale. void resetStorage(); // Informs the incident service that an anomaly has occurred. void informIncidentd(); FRIEND_TEST(AnomalyTrackerTest, TestConsecutiveBuckets); FRIEND_TEST(AnomalyTrackerTest, TestSparseBuckets); FRIEND_TEST(GaugeMetricProducerTest, TestAnomalyDetection); Loading cmds/statsd/src/config/ConfigManager.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -210,6 +210,9 @@ StatsdConfig build_fake_config() { alert->set_number_of_buckets(6); alert->set_trigger_if_sum_gt(10); alert->set_refractory_period_secs(30); Alert::IncidentdDetails* details = alert->mutable_incidentd_details(); details->add_section(12); details->add_section(13); // Count process state changes, slice by uid. metric = config.add_count_metric(); Loading @@ -226,6 +229,9 @@ StatsdConfig build_fake_config() { alert->set_number_of_buckets(4); alert->set_trigger_if_sum_gt(30); alert->set_refractory_period_secs(20); details = alert->mutable_incidentd_details(); details->add_section(14); details->add_section(15); // Count process state changes, slice by uid, while SCREEN_IS_OFF metric = config.add_count_metric(); Loading Loading
cmds/statsd/src/anomaly/AnomalyTracker.cpp +27 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,9 @@ #include "AnomalyTracker.h" #include <android/os/IIncidentManager.h> #include <android/os/IncidentReportArgs.h> #include <binder/IServiceManager.h> #include <time.h> namespace android { Loading Loading @@ -213,7 +216,7 @@ void AnomalyTracker::declareAnomaly(const uint64_t& timestampNs) { // TODO: Can construct a name based on the criteria (and/or relay the criteria). ALOGW("An anomaly (nameless) has occurred! Informing incidentd."); } // TODO: informIncidentd(); informIncidentd(); } else { ALOGW("An anomaly has occurred! (But informing incidentd not requested.)"); } Loading Loading @@ -314,6 +317,29 @@ void AnomalyTracker::informAlarmsFired(const uint64_t& timestampNs, } } void AnomalyTracker::informIncidentd() { VLOG("informIncidentd called."); if (!mAlert.has_incidentd_details()) { ALOGE("Attempted to call incidentd without any incidentd_details."); return; } sp<IIncidentManager> service = interface_cast<IIncidentManager>( defaultServiceManager()->getService(android::String16("incident"))); if (service == NULL) { ALOGW("Couldn't get the incident service."); return; } IncidentReportArgs incidentReport; const Alert::IncidentdDetails& details = mAlert.incidentd_details(); for (int i = 0; i < details.section_size(); i++) { incidentReport.addSection(details.section(i)); } // TODO: Pass in mAlert.name() into the addHeader? service->reportIncident(incidentReport); } } // namespace statsd } // namespace os } // namespace android
cmds/statsd/src/anomaly/AnomalyTracker.h +3 −0 Original line number Diff line number Diff line Loading @@ -148,6 +148,9 @@ protected: // Resets all bucket data. For use when all the data gets stale. void resetStorage(); // Informs the incident service that an anomaly has occurred. void informIncidentd(); FRIEND_TEST(AnomalyTrackerTest, TestConsecutiveBuckets); FRIEND_TEST(AnomalyTrackerTest, TestSparseBuckets); FRIEND_TEST(GaugeMetricProducerTest, TestAnomalyDetection); Loading
cmds/statsd/src/config/ConfigManager.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -210,6 +210,9 @@ StatsdConfig build_fake_config() { alert->set_number_of_buckets(6); alert->set_trigger_if_sum_gt(10); alert->set_refractory_period_secs(30); Alert::IncidentdDetails* details = alert->mutable_incidentd_details(); details->add_section(12); details->add_section(13); // Count process state changes, slice by uid. metric = config.add_count_metric(); Loading @@ -226,6 +229,9 @@ StatsdConfig build_fake_config() { alert->set_number_of_buckets(4); alert->set_trigger_if_sum_gt(30); alert->set_refractory_period_secs(20); details = alert->mutable_incidentd_details(); details->add_section(14); details->add_section(15); // Count process state changes, slice by uid, while SCREEN_IS_OFF metric = config.add_count_metric(); Loading