summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVova Sharaienko <sharaienko@google.com>2021-12-23 20:23:03 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-12-23 20:23:03 +0000
commit45f79b32733e3f5d65fe3bda07c36bff07d37a82 (patch)
treeb6ef529b07bf00ee12fbdb3bbc21c0ad5f938791
parent1a6fd7525d32b3e69230fd9341adae3f1041e4d0 (diff)
parent1ce9989840f77e72d0dfc51b452556a6f6fc5905 (diff)
downloadplatform_testing-45f79b32733e3f5d65fe3bda07c36bff07d37a82.tar.gz
Added Helper & Listener to collect StatsdStatsReport am: 1ce9989840
Original change: https://googleplex-android-review.googlesource.com/c/platform/platform_testing/+/16511943 Change-Id: Iea0873cda5c54ff8e86bd0b542429ff8dbc583d1
-rw-r--r--libraries/collectors-helper/statsd/src/com/android/helpers/StatsdStatsHelper.java14
-rw-r--r--libraries/collectors-helper/statsd/test/src/com/android/helpers/StatsdStatsHelperTest.java33
2 files changed, 39 insertions, 8 deletions
diff --git a/libraries/collectors-helper/statsd/src/com/android/helpers/StatsdStatsHelper.java b/libraries/collectors-helper/statsd/src/com/android/helpers/StatsdStatsHelper.java
index b452f436f..889bb07cc 100644
--- a/libraries/collectors-helper/statsd/src/com/android/helpers/StatsdStatsHelper.java
+++ b/libraries/collectors-helper/statsd/src/com/android/helpers/StatsdStatsHelper.java
@@ -36,6 +36,7 @@ public class StatsdStatsHelper implements ICollectorHelper<Long> {
static final String METRIC_STATS_PREFIX = "metric_stats";
static final String ALERT_STATS_PREFIX = "alert_stats";
static final String CONFIG_STATS_PREFIX = "config_stats";
+ static final String ANOMALY_ALARM_STATS_PREFIX = "anomaly_alarm_stats";
interface IStatsdHelper {
StatsLog.StatsdStatsReport getStatsdStatsReport();
@@ -79,6 +80,7 @@ public class StatsdStatsHelper implements ICollectorHelper<Long> {
final StatsLog.StatsdStatsReport report = mStatsdHelper.getStatsdStatsReport();
populateAtomStats(report.atomStats, resultMap);
populateConfigStats(report.configStats, resultMap);
+ populateAnomalyAlarmStats(report.anomalyAlarmStats, resultMap);
return resultMap;
}
@@ -189,6 +191,18 @@ public class StatsdStatsHelper implements ICollectorHelper<Long> {
}
}
+ private static void populateAnomalyAlarmStats(
+ StatsLog.StatsdStatsReport.AnomalyAlarmStats anomalyAlarmStats,
+ Map<String, Long> resultMap) {
+ if (anomalyAlarmStats == null) {
+ return;
+ }
+ final String metricKey =
+ MetricUtility.constructKey(
+ STATSDSTATS_PREFIX, ANOMALY_ALARM_STATS_PREFIX, "alarms_registered");
+ resultMap.put(metricKey, Long.valueOf(anomalyAlarmStats.alarmsRegistered));
+ }
+
/** No op. */
@Override
public boolean stopCollecting() {
diff --git a/libraries/collectors-helper/statsd/test/src/com/android/helpers/StatsdStatsHelperTest.java b/libraries/collectors-helper/statsd/test/src/com/android/helpers/StatsdStatsHelperTest.java
index 9b8679293..81dac6a8f 100644
--- a/libraries/collectors-helper/statsd/test/src/com/android/helpers/StatsdStatsHelperTest.java
+++ b/libraries/collectors-helper/statsd/test/src/com/android/helpers/StatsdStatsHelperTest.java
@@ -51,9 +51,10 @@ public class StatsdStatsHelperTest {
public TestNonEmptyStatsdHelper() {
populateAtomStatsTestData(testReport);
populateConfigStatsTestData(testReport);
+ populateAnomalyAlarmStatsTestData(testReport);
}
- private void populateAtomStatsTestData(StatsLog.StatsdStatsReport testReport) {
+ private static void populateAtomStatsTestData(StatsLog.StatsdStatsReport testReport) {
testReport.atomStats = new StatsLog.StatsdStatsReport.AtomStats[ATOM_STATS_COUNT];
for (int i = 0; i < ATOM_STATS_COUNT; i++) {
@@ -65,7 +66,7 @@ public class StatsdStatsHelperTest {
}
}
- private void populateConfigStatsTestData(StatsLog.StatsdStatsReport testReport) {
+ private static void populateConfigStatsTestData(StatsLog.StatsdStatsReport testReport) {
testReport.configStats = new StatsLog.StatsdStatsReport.ConfigStats[CONFIG_STATS_COUNT];
for (int i = 0; i < CONFIG_STATS_COUNT; i++) {
testReport.configStats[i] = new StatsLog.StatsdStatsReport.ConfigStats();
@@ -86,7 +87,7 @@ public class StatsdStatsHelperTest {
}
}
- private StatsLog.StatsdStatsReport.AlertStats[] populateConfigStatsAlertTestData(
+ private static StatsLog.StatsdStatsReport.AlertStats[] populateConfigStatsAlertTestData(
int configStatsAlertCount) {
StatsLog.StatsdStatsReport.AlertStats[] alertStats =
new StatsLog.StatsdStatsReport.AlertStats[configStatsAlertCount];
@@ -101,7 +102,7 @@ public class StatsdStatsHelperTest {
return alertStats;
}
- private StatsLog.StatsdStatsReport.MetricStats[] populateConfigStatsMetricTestData(
+ private static StatsLog.StatsdStatsReport.MetricStats[] populateConfigStatsMetricTestData(
int configStatsMetricCount) {
StatsLog.StatsdStatsReport.MetricStats[] metricStats =
new StatsLog.StatsdStatsReport.MetricStats[configStatsMetricCount];
@@ -116,8 +117,8 @@ public class StatsdStatsHelperTest {
return metricStats;
}
- private StatsLog.StatsdStatsReport.ConditionStats[] populateConfigStatsConditionTestData(
- int configStatsConditionCount) {
+ private static StatsLog.StatsdStatsReport.ConditionStats[]
+ populateConfigStatsConditionTestData(int configStatsConditionCount) {
StatsLog.StatsdStatsReport.ConditionStats[] conditionStats =
new StatsLog.StatsdStatsReport.ConditionStats[configStatsConditionCount];
@@ -131,7 +132,7 @@ public class StatsdStatsHelperTest {
return conditionStats;
}
- private StatsLog.StatsdStatsReport.MatcherStats[] populateConfigStatsMatcherTestData(
+ private static StatsLog.StatsdStatsReport.MatcherStats[] populateConfigStatsMatcherTestData(
int configStatsMatcherCount) {
StatsLog.StatsdStatsReport.MatcherStats[] matcherStats =
new StatsLog.StatsdStatsReport.MatcherStats[configStatsMatcherCount];
@@ -146,6 +147,12 @@ public class StatsdStatsHelperTest {
return matcherStats;
}
+ private static void populateAnomalyAlarmStatsTestData(
+ StatsLog.StatsdStatsReport testReport) {
+ testReport.anomalyAlarmStats = new StatsLog.StatsdStatsReport.AnomalyAlarmStats();
+ testReport.anomalyAlarmStats.alarmsRegistered = 1;
+ }
+
@Override
public StatsLog.StatsdStatsReport getStatsdStatsReport() {
return testReport;
@@ -233,7 +240,7 @@ public class StatsdStatsHelperTest {
}
}
- private void verifyConfigStats(
+ private static void verifyConfigStats(
Map<String, Long> result,
int configStatsCount,
int configStatsMetricCount,
@@ -266,6 +273,15 @@ public class StatsdStatsHelperTest {
}
}
+ private static void verifyAnomalyAlarmStats(Map<String, Long> result) {
+ final String metricKeyPrefix =
+ MetricUtility.constructKey(
+ StatsdStatsHelper.STATSDSTATS_PREFIX,
+ StatsdStatsHelper.ANOMALY_ALARM_STATS_PREFIX);
+ final String metricKey = MetricUtility.constructKey(metricKeyPrefix, "alarms_registered");
+ assertEquals(result.get(metricKey), Long.valueOf(1));
+ }
+
@Test
public void testNonEmptyReport() throws Exception {
StatsdStatsHelper.IStatsdHelper statsdHelper = new TestNonEmptyStatsdHelper();
@@ -281,6 +297,7 @@ public class StatsdStatsHelperTest {
TestNonEmptyStatsdHelper.CONFIG_STATS_CONDITION_COUNT,
TestNonEmptyStatsdHelper.CONFIG_STATS_MATCHER_COUNT,
TestNonEmptyStatsdHelper.CONFIG_STATS_ALERT_COUNT);
+ verifyAnomalyAlarmStats(result);
assertTrue(statsdStatsHelper.stopCollecting());
}