Collects binder call stats data through WestWorld.

We require binder calls detailed tracking to be enabled to collect the
stats (in addition to enabling it in WestWorld).

Test: unit test + manual

adb shell cmd stats pull-source 10022
Pull from 10022: { 1531240941000000000 25807560798 (10022)0x10000->0[I]
0x20000->com.android.server.StorageManagerService$3[S]
0x30000->onVolumePathChanged[S] 0x40000->1[L] 0x50000->0[L]
0x60000->18490[L] 0x70000->18490[L] 0x80000->2611[L] 0x90000->2611[L]
0xa0000->0[L]  } ...

Change-Id: I07cad5d8678426cdac45872cda028ea7a85d7d81
diff --git a/stats/atoms.proto b/stats/atoms.proto
index cdb72ab..e23676f 100644
--- a/stats/atoms.proto
+++ b/stats/atoms.proto
@@ -126,7 +126,7 @@
     }
 
     // Pulled events will start at field 10000.
-    // Next: 10022
+    // Next: 10023
     oneof pulled {
         WifiBytesTransfer wifi_bytes_transfer = 10000;
         WifiBytesTransferByFgBg wifi_bytes_transfer_by_fg_bg = 10001;
@@ -150,6 +150,7 @@
         RemainingBatteryCapacity remaining_battery_capacity = 10019;
         FullBatteryCapacity full_battery_capacity = 10020;
         Temperature temperature = 10021;
+        BinderCalls binder_calls = 10022;
     }
 
     // DO NOT USE field numbers above 100,000 in AOSP. Field numbers above
@@ -1975,3 +1976,39 @@
     // Temperature in tenths of a degree C.
     optional int32 temperature_dC = 3;
 }
+
+/**
+ * Pulls the statistics of calls to Binder.
+ *
+ * Binder stats are cumulative from boot unless somebody reset the data using
+ * > adb shell dumpsys binder_calls_stats --reset
+ */
+message BinderCalls {
+   // TODO(gaillard): figure out if binder call stats includes data from isolated uids, if a uid
+   // gets recycled and we have isolated uids, we might attribute the data incorrectly.
+   // TODO(gaillard): there is a high dimensions cardinality, figure out if we should drop the less
+   // commonly used APIs.
+   optional int32 uid = 1 [(is_uid) = true];
+   // Fully qualified class name of the API call.
+   optional string service_class_name = 2;
+   // Method name of the API call. It can also be a transaction code if we cannot resolve it to a
+   // name. See Binder#getTransactionName.
+   optional string service_method_name = 3;
+   // Total number of API calls.
+   optional int64 call_count = 4;
+   // Number of exceptions thrown by the API.
+   optional int64 exception_count = 5;
+   // Total latency of all API calls.
+   // Average can be computed using total_latency_micros / call_count.
+   optional int64 total_latency_micros = 6;
+   // Maximum latency of one API call.
+   optional int64 max_latency_micros = 7;
+   // Total CPU usage of all API calls.
+   optional int64 total_cpu_micros = 8;
+   // Maximum CPU usage of one API call.
+   optional int64 max_cpu_micros = 9;
+   // Maximum parcel reply size of one API call.
+   optional int64 max_reply_size_bytes = 10;
+   // Maximum parcel request size of one API call.
+   optional int64 max_request_size_bytes = 11;
+}