Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 97247eac authored by jiabin's avatar jiabin
Browse files

Log metrics for aaudio stream.

Add log for total transferred frame, actual performance type, format
requested by apps.
Collect the missing information when sending the data to statsd.

Bug: 171345744
Test: dumpsys media.metrics
Change-Id: Ifd2c7db848aedd01c9d57ea2ecab85cd1abdc784
parent a4bfdc34
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <algorithm>
#include <audio_utils/primitives.h>
#include <aaudio/AAudio.h>
#include <media/MediaMetricsItem.h>

#include "client/AudioStreamInternalCapture.h"
#include "utility/AudioClock.h"
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

#define ATRACE_TAG ATRACE_TAG_AUDIO

#include <media/MediaMetricsItem.h>
#include <utils/Trace.h>

#include "client/AudioStreamInternalPlay.h"
+26 −1
Original line number Diff line number Diff line
@@ -59,6 +59,10 @@ AudioStream::~AudioStream() {
    if (!mMetricsId.empty()) {
        android::mediametrics::LogItem(mMetricsId)
                .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_ENDAAUDIOSTREAM)
                .set(AMEDIAMETRICS_PROP_ENCODINGREQUESTED,
                     android::toString(mDeviceFormat).c_str())
                .set(AMEDIAMETRICS_PROP_PERFORMANCEMODEACTUAL,
                     AudioGlobal_convertPerformanceModeToText(getPerformanceMode()))
                .record();
    }

@@ -124,7 +128,12 @@ void AudioStream::logOpen() {
            .set(AMEDIAMETRICS_PROP_PERFORMANCEMODE,
                AudioGlobal_convertPerformanceModeToText(getPerformanceMode()))
            .set(AMEDIAMETRICS_PROP_SHARINGMODE,
                AudioGlobal_convertSharingModeToText(getSharingMode()));
                AudioGlobal_convertSharingModeToText(getSharingMode()))
            .set(AMEDIAMETRICS_PROP_BUFFERCAPACITYFRAMES, getBufferCapacity())
            .set(AMEDIAMETRICS_PROP_BURSTFRAMES, getFramesPerBurst())
            .set(AMEDIAMETRICS_PROP_DIRECTION,
                AudioGlobal_convertDirectionToText(getDirection()));

        if (getDirection() == AAUDIO_DIRECTION_OUTPUT) {
            item.set(AMEDIAMETRICS_PROP_PLAYERIID, mPlayerBase->getPlayerIId());
        }
@@ -338,6 +347,22 @@ aaudio_result_t AudioStream::safeReleaseCloseInternal() {
    return AAUDIO_OK;
}

void AudioStream::close_l() {
    // Releasing the stream will set the state to CLOSING.
    assert(getState() == AAUDIO_STREAM_STATE_CLOSING);
    // setState() prevents a transition from CLOSING to any state other than CLOSED.
    // State is checked by destructor.
    setState(AAUDIO_STREAM_STATE_CLOSED);

    if (!mMetricsId.empty()) {
        android::mediametrics::LogItem(mMetricsId)
                .set(AMEDIAMETRICS_PROP_FRAMESTRANSFERRED,
                        getDirection() == AAUDIO_DIRECTION_INPUT ? getFramesWritten()
                                                                 : getFramesRead())
                .record();
    }
}

void AudioStream::setState(aaudio_stream_state_t state) {
    ALOGD("%s(s#%d) from %d to %d", __func__, getId(), mState, state);
    if (state == mState) {
+1 −7
Original line number Diff line number Diff line
@@ -146,13 +146,7 @@ protected:
     * Free any resources not already freed by release_l().
     * Assume release_l() already called.
     */
    virtual void close_l() REQUIRES(mStreamLock) {
        // Releasing the stream will set the state to CLOSING.
        assert(getState() == AAUDIO_STREAM_STATE_CLOSING);
        // setState() prevents a transition from CLOSING to any state other than CLOSED.
        // State is checked by destructor.
        setState(AAUDIO_STREAM_STATE_CLOSED);
    }
    virtual void close_l() REQUIRES(mStreamLock);

public:
    // This is only used to identify a stream in the logs without
+6 −0
Original line number Diff line number Diff line
@@ -160,6 +160,12 @@
#define AMEDIAMETRICS_PROP_VOLUME_LEFT    "volume.left"    // double (AudioTrack)
#define AMEDIAMETRICS_PROP_VOLUME_RIGHT   "volume.right"   // double (AudioTrack)
#define AMEDIAMETRICS_PROP_WHERE          "where"          // string value
// EncodingRequested is the encoding format requested by the app
#define AMEDIAMETRICS_PROP_ENCODINGREQUESTED "encodingRequested" // string
// PerformanceModeActual is the actual selected performance mode, could be "none', "loeLatency" or
// "powerSaving"
#define AMEDIAMETRICS_PROP_PERFORMANCEMODEACTUAL "performanceModeActual" // string
#define AMEDIAMETRICS_PROP_FRAMESTRANSFERRED "framesTransferred" // int64_t, transferred frames

// Timing values: millisecond values are suffixed with MS and the type is double
// nanosecond values are suffixed with NS and the type is int64.
Loading