From 0a368b2c391dd3ebaf6b8917c16c41b65c1d5ab7 Mon Sep 17 00:00:00 2001 From: David Chen Date: Wed, 6 Dec 2017 16:28:16 -0800 Subject: [PATCH] Adds API for apps to push events to statsd. This API allows app to construct custom metrics based on labels chosen by the app developers. Also added some buttons to manually test this functionality in the dogfood app. Test: Verified that Android can be built and tested with custom app. Bug: 69522276 Change-Id: Ifb7abea4c1d62fb435a9cb6f32df12bc2234d82f --- Android.bp | 2 +- api/current.txt | 6 ++ cmds/statsd/src/atoms.proto | 24 +++++++ .../dogfood/res/layout/activity_main.xml | 17 +++++ .../tools/dogfood/res/values/strings.xml | 3 + .../android/statsd/dogfood/MainActivity.java | 14 ++++ core/java/android/util/StatsLog.java | 70 +++++++++++++++++++ tools/stats_log_api_gen/main.cpp | 2 +- 8 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 core/java/android/util/StatsLog.java diff --git a/Android.bp b/Android.bp index 015e59fe9d08..773bf76da80d 100644 --- a/Android.bp +++ b/Android.bp @@ -624,7 +624,7 @@ genrule { name: "framework-statslog-gen", tools: ["stats-log-api-gen"], cmd: "$(location stats-log-api-gen) --java $(out)", - out: ["android/util/StatsLog.java"], + out: ["android/util/StatsLogInternal.java"], } gensrcs { diff --git a/api/current.txt b/api/current.txt index 66a577c17de5..455cb7db1264 100644 --- a/api/current.txt +++ b/api/current.txt @@ -44575,6 +44575,12 @@ package android.util { field public static final int[] WILD_CARD; } + public final class StatsLog { + method public static boolean logEvent(int); + method public static boolean logStart(int); + method public static boolean logStop(int); + } + public class StringBuilderPrinter implements android.util.Printer { ctor public StringBuilderPrinter(java.lang.StringBuilder); method public void println(java.lang.String); diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto index 716fee6bb1fb..3471737e7dd9 100644 --- a/cmds/statsd/src/atoms.proto +++ b/cmds/statsd/src/atoms.proto @@ -79,6 +79,7 @@ message Atom { IsolatedUidChanged isolated_uid_changed = 43; PacketWakeupOccurred packet_wakeup_occurred = 44; DropboxErrorChanged dropbox_error_changed = 45; + AppHook app_hook = 46; // TODO: Reorder the numbering so that the most frequent occur events occur in the first 15. } @@ -801,6 +802,29 @@ message DropboxErrorChanged { optional int32 is_foreground = 7; } +/* + * Allows other apps to push events into statsd. + * Logged from: + * frameworks/base/core/java/android/util/StatsLog.java + */ +message AppHook { + // The uid of the application that sent this custom atom. + optional int32 uid = 1; + + // An arbitrary label chosen by the developer. For Android P, the label should be in [0, 16). + optional int32 label = 2; + + // Allows applications to easily use a custom event as start/stop boundaries (ie, define custom + // predicates for the metrics). + enum State { + UNKNOWN = 0; + UNSPECIFIED = 1; // For events that are known to not represent START/STOP. + STOP = 2; + START = 3; + } + optional State state = 3; +} + /** * Pulls bytes transferred via wifi (Sum of foreground and background usage). * diff --git a/cmds/statsd/tools/dogfood/res/layout/activity_main.xml b/cmds/statsd/tools/dogfood/res/layout/activity_main.xml index 39978971d6b4..5d35c291f365 100644 --- a/cmds/statsd/tools/dogfood/res/layout/activity_main.xml +++ b/cmds/statsd/tools/dogfood/res/layout/activity_main.xml @@ -111,6 +111,23 @@ android:text="@string/screen_off"/> + + +