summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVova Sharaienko <sharaienko@google.com>2021-12-21 02:43:09 +0000
committerVova Sharaienko <sharaienko@google.com>2021-12-22 21:05:30 +0000
commit393c43256ec70cffe320d86fe9e3c21877feb8bc (patch)
treea9fb3d69890b073ef880372566aec4f9a05fbd88
parent1ce9989840f77e72d0dfc51b452556a6f6fc5905 (diff)
downloadplatform_testing-393c43256ec70cffe320d86fe9e3c21877feb8bc.tar.gz
Added Helper & Listener to collect StatsdStatsReport
This report represents statsd metadata - added pulled atoms stats Bug: 204890512 Test: atest CollectorsHelperTest:com.android.helpers.StatsdStatsHelperTest Change-Id: I32aa407de86a9eff9b19b95d4ee6b057559a015e
-rw-r--r--libraries/collectors-helper/statsd/src/com/android/helpers/StatsdStatsHelper.java65
-rw-r--r--libraries/collectors-helper/statsd/test/src/com/android/helpers/StatsdStatsHelperTest.java103
2 files changed, 168 insertions, 0 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 889bb07cc..6969694b4 100644
--- a/libraries/collectors-helper/statsd/src/com/android/helpers/StatsdStatsHelper.java
+++ b/libraries/collectors-helper/statsd/src/com/android/helpers/StatsdStatsHelper.java
@@ -37,6 +37,7 @@ public class StatsdStatsHelper implements ICollectorHelper<Long> {
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";
+ static final String PULLED_ATOM_STATS_PREFIX = "pulled_atom_stats";
interface IStatsdHelper {
StatsLog.StatsdStatsReport getStatsdStatsReport();
@@ -81,6 +82,7 @@ public class StatsdStatsHelper implements ICollectorHelper<Long> {
populateAtomStats(report.atomStats, resultMap);
populateConfigStats(report.configStats, resultMap);
populateAnomalyAlarmStats(report.anomalyAlarmStats, resultMap);
+ populatePulledAtomStats(report.pulledAtomStats, resultMap);
return resultMap;
}
@@ -203,6 +205,69 @@ public class StatsdStatsHelper implements ICollectorHelper<Long> {
resultMap.put(metricKey, Long.valueOf(anomalyAlarmStats.alarmsRegistered));
}
+ private static void populatePulledAtomStats(
+ StatsLog.StatsdStatsReport.PulledAtomStats[] pulledAtomStats,
+ Map<String, Long> resultMap) {
+ final String metricKeyPrefix =
+ MetricUtility.constructKey(STATSDSTATS_PREFIX, PULLED_ATOM_STATS_PREFIX);
+
+ for (final StatsLog.StatsdStatsReport.PulledAtomStats dataItem : pulledAtomStats) {
+ final String metricKeyWithTag =
+ MetricUtility.constructKey(metricKeyPrefix, String.valueOf(dataItem.atomId));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "total_pull"),
+ Long.valueOf(dataItem.totalPull));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "total_pull_from_cache"),
+ Long.valueOf(dataItem.totalPullFromCache));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "min_pull_interval_sec"),
+ Long.valueOf(dataItem.minPullIntervalSec));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "average_pull_time_nanos"),
+ Long.valueOf(dataItem.averagePullTimeNanos));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "max_pull_time_nanos"),
+ Long.valueOf(dataItem.maxPullTimeNanos));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "average_pull_delay_nanos"),
+ Long.valueOf(dataItem.averagePullDelayNanos));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "data_error"),
+ Long.valueOf(dataItem.dataError));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "pull_timeout"),
+ Long.valueOf(dataItem.pullTimeout));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "pull_exceed_max_delay"),
+ Long.valueOf(dataItem.pullExceedMaxDelay));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "pull_failed"),
+ Long.valueOf(dataItem.pullFailed));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "empty_data"),
+ Long.valueOf(dataItem.emptyData));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "pull_registered_count"),
+ Long.valueOf(dataItem.registeredCount));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "pull_unregistered_count"),
+ Long.valueOf(dataItem.unregisteredCount));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "atom_error_count"),
+ Long.valueOf(dataItem.atomErrorCount));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "binder_call_failed"),
+ Long.valueOf(dataItem.binderCallFailed));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "failed_uid_provider_not_found"),
+ Long.valueOf(dataItem.failedUidProviderNotFound));
+ resultMap.put(
+ MetricUtility.constructKey(metricKeyWithTag, "puller_not_found"),
+ Long.valueOf(dataItem.pullerNotFound));
+ }
+ }
+
/** 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 81dac6a8f..62876c9aa 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
@@ -47,11 +47,13 @@ public class StatsdStatsHelperTest {
static final int CONFIG_STATS_CONDITION_COUNT = 2;
static final int CONFIG_STATS_ALERT_COUNT = 2;
static final int CONFIG_STATS_MATCHER_COUNT = 2;
+ static final int PULLED_ATOM_STATS_COUNT = 2;
public TestNonEmptyStatsdHelper() {
populateAtomStatsTestData(testReport);
populateConfigStatsTestData(testReport);
populateAnomalyAlarmStatsTestData(testReport);
+ populatePulledAtomStatsTestData(testReport);
}
private static void populateAtomStatsTestData(StatsLog.StatsdStatsReport testReport) {
@@ -153,6 +155,34 @@ public class StatsdStatsHelperTest {
testReport.anomalyAlarmStats.alarmsRegistered = 1;
}
+ private void populatePulledAtomStatsTestData(StatsLog.StatsdStatsReport testReport) {
+ testReport.pulledAtomStats =
+ new StatsLog.StatsdStatsReport.PulledAtomStats[PULLED_ATOM_STATS_COUNT];
+
+ for (int i = 0; i < PULLED_ATOM_STATS_COUNT; i++) {
+ testReport.pulledAtomStats[i] = new StatsLog.StatsdStatsReport.PulledAtomStats();
+ int fieldValue = i + 1;
+ testReport.pulledAtomStats[i].atomId = fieldValue++;
+ testReport.pulledAtomStats[i].totalPull = fieldValue++;
+ testReport.pulledAtomStats[i].totalPullFromCache = fieldValue++;
+ testReport.pulledAtomStats[i].minPullIntervalSec = fieldValue++;
+ testReport.pulledAtomStats[i].averagePullTimeNanos = fieldValue++;
+ testReport.pulledAtomStats[i].maxPullTimeNanos = fieldValue++;
+ testReport.pulledAtomStats[i].averagePullDelayNanos = fieldValue++;
+ testReport.pulledAtomStats[i].dataError = fieldValue++;
+ testReport.pulledAtomStats[i].pullTimeout = fieldValue++;
+ testReport.pulledAtomStats[i].pullExceedMaxDelay = fieldValue++;
+ testReport.pulledAtomStats[i].pullFailed = fieldValue++;
+ testReport.pulledAtomStats[i].emptyData = fieldValue++;
+ testReport.pulledAtomStats[i].registeredCount = fieldValue++;
+ testReport.pulledAtomStats[i].unregisteredCount = fieldValue++;
+ testReport.pulledAtomStats[i].atomErrorCount = fieldValue++;
+ testReport.pulledAtomStats[i].binderCallFailed = fieldValue++;
+ testReport.pulledAtomStats[i].failedUidProviderNotFound = fieldValue++;
+ testReport.pulledAtomStats[i].pullerNotFound = fieldValue++;
+ }
+ }
+
@Override
public StatsLog.StatsdStatsReport getStatsdStatsReport() {
return testReport;
@@ -282,6 +312,78 @@ public class StatsdStatsHelperTest {
assertEquals(result.get(metricKey), Long.valueOf(1));
}
+ private static void verifyPulledAtomStats(Map<String, Long> result, int pulledAtomStatsCount) {
+ for (int i = 0; i < pulledAtomStatsCount; i++) {
+ int fieldValue = i + 1;
+ final String metricKeyPrefix =
+ MetricUtility.constructKey(
+ StatsdStatsHelper.STATSDSTATS_PREFIX,
+ StatsdStatsHelper.PULLED_ATOM_STATS_PREFIX,
+ String.valueOf(fieldValue++));
+ assertEquals(
+ result.get(MetricUtility.constructKey(metricKeyPrefix, "total_pull")),
+ Long.valueOf(fieldValue++));
+ assertEquals(
+ result.get(
+ MetricUtility.constructKey(metricKeyPrefix, "total_pull_from_cache")),
+ Long.valueOf(fieldValue++));
+ assertEquals(
+ result.get(
+ MetricUtility.constructKey(metricKeyPrefix, "min_pull_interval_sec")),
+ Long.valueOf(fieldValue++));
+ assertEquals(
+ result.get(
+ MetricUtility.constructKey(metricKeyPrefix, "average_pull_time_nanos")),
+ Long.valueOf(fieldValue++));
+ assertEquals(
+ result.get(MetricUtility.constructKey(metricKeyPrefix, "max_pull_time_nanos")),
+ Long.valueOf(fieldValue++));
+ assertEquals(
+ result.get(
+ MetricUtility.constructKey(
+ metricKeyPrefix, "average_pull_delay_nanos")),
+ Long.valueOf(fieldValue++));
+ assertEquals(
+ result.get(MetricUtility.constructKey(metricKeyPrefix, "data_error")),
+ Long.valueOf(fieldValue++));
+ assertEquals(
+ result.get(MetricUtility.constructKey(metricKeyPrefix, "pull_timeout")),
+ Long.valueOf(fieldValue++));
+ assertEquals(
+ result.get(
+ MetricUtility.constructKey(metricKeyPrefix, "pull_exceed_max_delay")),
+ Long.valueOf(fieldValue++));
+ assertEquals(
+ result.get(MetricUtility.constructKey(metricKeyPrefix, "pull_failed")),
+ Long.valueOf(fieldValue++));
+ assertEquals(
+ result.get(MetricUtility.constructKey(metricKeyPrefix, "empty_data")),
+ Long.valueOf(fieldValue++));
+ assertEquals(
+ result.get(
+ MetricUtility.constructKey(metricKeyPrefix, "pull_registered_count")),
+ Long.valueOf(fieldValue++));
+ assertEquals(
+ result.get(
+ MetricUtility.constructKey(metricKeyPrefix, "pull_unregistered_count")),
+ Long.valueOf(fieldValue++));
+ assertEquals(
+ result.get(MetricUtility.constructKey(metricKeyPrefix, "atom_error_count")),
+ Long.valueOf(fieldValue++));
+ assertEquals(
+ result.get(MetricUtility.constructKey(metricKeyPrefix, "binder_call_failed")),
+ Long.valueOf(fieldValue++));
+ assertEquals(
+ result.get(
+ MetricUtility.constructKey(
+ metricKeyPrefix, "failed_uid_provider_not_found")),
+ Long.valueOf(fieldValue++));
+ assertEquals(
+ result.get(MetricUtility.constructKey(metricKeyPrefix, "puller_not_found")),
+ Long.valueOf(fieldValue++));
+ }
+ }
+
@Test
public void testNonEmptyReport() throws Exception {
StatsdStatsHelper.IStatsdHelper statsdHelper = new TestNonEmptyStatsdHelper();
@@ -298,6 +400,7 @@ public class StatsdStatsHelperTest {
TestNonEmptyStatsdHelper.CONFIG_STATS_MATCHER_COUNT,
TestNonEmptyStatsdHelper.CONFIG_STATS_ALERT_COUNT);
verifyAnomalyAlarmStats(result);
+ verifyPulledAtomStats(result, TestNonEmptyStatsdHelper.PULLED_ATOM_STATS_COUNT);
assertTrue(statsdStatsHelper.stopCollecting());
}