Log broadcast dispatch latency during BOOT_COMPLETED

From device boot until BOOT_COMPLETED, log the dispatch latency of a
broadcast, which is the duration between it being enqueued and it being
dispatched, to get an idea of how long the queue is blocked for.

Each time a broadcast is dispatched, we check mLogLatencyMetrics, which
defaults to true when the queue is initialized, and log to statsd.

When the queue is empty, we check if BOOT_COMPLETED is done. If it is,
we stop logging by setting mLogLatencyMetrics to false, since it means
that we have finished all broadcasts that
would have been blocked by BOOT_COMPLETED.

Bug: 120794810
Test: flash, reboot, use stasd_testdrive to verify logging
Change-Id: I40c14744e5247412c0a03032fd5621706758a324
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index 79ef2ca..73ebdc3 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -202,6 +202,7 @@
         NfcHceTransactionOccurred nfc_hce_transaction_occurred = 139;
         SeStateChanged se_state_changed = 140;
         SeOmapiReported se_omapi_reported = 141;
+        BroadcastDispatchLatencyReported broadcast_dispatch_latency_reported = 142;
     }
 
     // Pulled events will start at field 10000.
@@ -4452,3 +4453,13 @@
 
   optional string packageName = 3;
 }
+
+/**
+  * Logs the dispatch latencey of a broadcast during processing of BOOT_COMPLETED.
+  * The dispatch latencey is the dispatchClockTime - enqueueClockTime.
+  * Logged from:
+  *   frameworks/base/services/core/java/com/android/server/am/BroadcastQueue.java
+  */
+message BroadcastDispatchLatencyReported {
+  optional int64 dispatch_latency_millis = 1;
+}