From 2e8f3807379f5d5d151ad2cb434d8a7aca910238 Mon Sep 17 00:00:00 2001 From: David Chen Date: Wed, 22 Nov 2017 10:56:48 -0800 Subject: Adds new API to retrieve statsd metadata. This API can be used by clients to gather stats about statsd, eg. memory usage, number of metrics/matchers, etc. This data can be used to debug if devices are not providing expected metrics. The metadata will be for all configurations, but will not contain the actual collected metrics since those might have privacy implications. Test: Tests that statsd and Android still build. Bug: 69522276 Change-Id: I8e0fedc142f5deed7be6e6309f9444e67d8369ce --- core/java/android/util/StatsManager.java | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'core/java/android/util/StatsManager.java') diff --git a/core/java/android/util/StatsManager.java b/core/java/android/util/StatsManager.java index 2bcd863cd409..26a3c361e8c1 100644 --- a/core/java/android/util/StatsManager.java +++ b/core/java/android/util/StatsManager.java @@ -93,10 +93,11 @@ public final class StatsManager { } /** - * Clients can request data with a binder call. + * Clients can request data with a binder call. This getter is destructive and also clears + * the retrieved metrics from statsd memory. * * @param configKey Configuration key to retrieve data from. - * @return Serialized ConfigMetricsReport proto. Returns null on failure. + * @return Serialized ConfigMetricsReportList proto. Returns null on failure. */ @RequiresPermission(Manifest.permission.DUMP) public byte[] getData(String configKey) { @@ -115,6 +116,30 @@ public final class StatsManager { } } + /** + * Clients can request metadata for statsd. Will contain stats across all configurations but not + * the actual metrics themselves (metrics must be collected via {@link #getData(String)}. + * This getter is not destructive and will not reset any metrics/counters. + * + * @return Serialized StatsdStatsReport proto. Returns null on failure. + */ + @RequiresPermission(Manifest.permission.DUMP) + public byte[] getMetadata() { + synchronized (this) { + try { + IStatsManager service = getIStatsManagerLocked(); + if (service == null) { + Slog.d(TAG, "Failed to find statsd when getting metadata"); + return null; + } + return service.getMetadata(); + } catch (RemoteException e) { + Slog.d(TAG, "Failed to connecto statsd when getting metadata"); + return null; + } + } + } + private class StatsdDeathRecipient implements IBinder.DeathRecipient { @Override public void binderDied() { -- cgit v1.2.3