MediaMetrics: Prepare statistics for protos
1) Add AudioRecord to Analytics trigger.
2) Log RecordThread statistics.
3) Rename DURATIONNS to EXECUTETIMENS to avoid confusion.
4) Use streamType from server not client.
5) Split MMAP types to MMAP_PLAYBACK and MMAP_CAPTURE.
6) Use string flags for AudioTrack and AudioRecord.
7) Compute underrun frames for MixerThread.
8) Log BT connection state.
Test: adb shell dumpsys media.metrics
Test: atest mediametrics_tests
Test: adb shell dumpsys stats --metadata
Bug: 149850236
Change-Id: Iacf3f117c00ec9f377e62862080252aef9dc084f
diff --git a/services/mediametrics/AudioAnalytics.h b/services/mediametrics/AudioAnalytics.h
index f9c776d..9089d6f 100644
--- a/services/mediametrics/AudioAnalytics.h
+++ b/services/mediametrics/AudioAnalytics.h
@@ -83,6 +83,17 @@
private:
+ /*
+ * AudioAnalytics class does not contain a monitor mutex.
+ * Instead, all of its variables are individually locked for access.
+ * Since data and items are generally added only (gc removes it), this is a reasonable
+ * compromise for availability/concurrency versus consistency.
+ *
+ * It is possible for concurrent threads to be reading and writing inside of AudioAnalytics.
+ * Reads based on a prior time (e.g. one second) in the past from the TimeMachine can be
+ * used to achieve better consistency if needed.
+ */
+
/**
* Checks for any pending actions for a particular item.
*
@@ -117,12 +128,19 @@
// TODO: Consider statistics aggregation.
class DeviceUse {
public:
+ enum ItemType {
+ RECORD = 0,
+ THREAD = 1,
+ TRACK = 2,
+ };
+
explicit DeviceUse(AudioAnalytics &audioAnalytics) : mAudioAnalytics{audioAnalytics} {}
// Called every time an endAudioIntervalGroup message is received.
void endAudioIntervalGroup(
const std::shared_ptr<const android::mediametrics::Item> &item,
- bool isTrack) const;
+ ItemType itemType) const;
+
private:
AudioAnalytics &mAudioAnalytics;
} mDeviceUse{*this};
@@ -144,6 +162,10 @@
void createPatch(
const std::shared_ptr<const android::mediametrics::Item> &item);
+ // Called through AudioManager when the BT service wants to notify connection
+ void postBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(
+ const std::shared_ptr<const android::mediametrics::Item> &item);
+
// When the timer expires.
void expire();
@@ -151,10 +173,16 @@
AudioAnalytics &mAudioAnalytics;
mutable std::mutex mLock;
- int64_t mA2dpTimeConnectedNs GUARDED_BY(mLock) = 0;
- int32_t mA2dpConnectedAttempts GUARDED_BY(mLock) = 0;
- int32_t mA2dpConnectedSuccesses GUARDED_BY(mLock) = 0;
- int32_t mA2dpConnectedFailures GUARDED_BY(mLock) = 0;
+ int64_t mA2dpConnectionRequestNs GUARDED_BY(mLock) = 0; // Time for BT service request.
+ int64_t mA2dpConnectionServiceNs GUARDED_BY(mLock) = 0; // Time audio service agrees.
+
+ int32_t mA2dpConnectionRequests GUARDED_BY(mLock) = 0;
+ int32_t mA2dpConnectionServices GUARDED_BY(mLock) = 0;
+
+ // See the statsd atoms.proto
+ int32_t mA2dpConnectionSuccesses GUARDED_BY(mLock) = 0;
+ int32_t mA2dpConnectionJavaServiceCancels GUARDED_BY(mLock) = 0;
+ int32_t mA2dpConnectionUnknowns GUARDED_BY(mLock) = 0;
} mDeviceConnection{*this};
AudioPowerUsage mAudioPowerUsage{this};