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

Commit c4c331c9 authored by jiabin's avatar jiabin
Browse files

Update aaudio metrics.

1) Remove caller name as it is not required.
2) Use 0 as the first value for unknown value, which is the default
   value.
3) Add content type and sample rate.

Bug: 183154959
Test: adb shell dumpsys media.metrics
Change-Id: I710101ed0b68fc8f635346e6b480a4d72d83be55
parent ac77b699
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -140,7 +140,6 @@ static constexpr const char * const AudioDeviceConnectionFields[] = {

static constexpr const char * const AAudioStreamFields[] {
    "mediametrics_aaudiostream_reported",
    "caller_name",
    "path",
    "direction",
    "frames_per_burst",
@@ -156,6 +155,8 @@ static constexpr const char * const AAudioStreamFields[] {
    "format_app",
    "format_device",
    "log_session_id",
    "sample_rate",
    "content_type",
};

/**
@@ -932,12 +933,6 @@ void AudioAnalytics::AAudioStreamInfo::endAAudioStream(
        const std::shared_ptr<const android::mediametrics::Item> &item, CallerPath path) const {
    const std::string& key = item->getKey();

    std::string callerNameStr;
    mAudioAnalytics.mAnalyticsState->timeMachine().get(
            key, AMEDIAMETRICS_PROP_CALLERNAME, &callerNameStr);

    const auto callerName = types::lookup<types::CALLER_NAME, int32_t>(callerNameStr);

    std::string directionStr;
    mAudioAnalytics.mAnalyticsState->timeMachine().get(
            key, AMEDIAMETRICS_PROP_DIRECTION, &directionStr);
@@ -994,8 +989,16 @@ void AudioAnalytics::AAudioStreamInfo::endAAudioStream(
    std::string logSessionId;
    // TODO: log logSessionId

    int32_t sampleRate = 0;
    mAudioAnalytics.mAnalyticsState->timeMachine().get(
            key, AMEDIAMETRICS_PROP_SAMPLERATE, &sampleRate);

    std::string contentTypeStr;
    mAudioAnalytics.mAnalyticsState->timeMachine().get(
            key, AMEDIAMETRICS_PROP_CONTENTTYPE, &contentTypeStr);
    const auto contentType = types::lookup<types::CONTENT_TYPE, int32_t>(contentTypeStr);

    LOG(LOG_LEVEL) << "key:" << key
            << " caller_name:" << callerName << "(" << callerNameStr << ")"
            << " path:" << path
            << " direction:" << direction << "(" << directionStr << ")"
            << " frames_per_burst:" << framesPerBurst
@@ -1010,14 +1013,15 @@ void AudioAnalytics::AAudioStreamInfo::endAAudioStream(
            << " device_type:" << serializedDeviceTypes
            << " format_app:" << formatApp
            << " format_device: " << formatDevice << "(" << formatDeviceStr << ")"
            << " log_session_id: " << logSessionId;
            << " log_session_id: " << logSessionId
            << " sample_rate: " << sampleRate
            << " content_type: " << contentType << "(" << contentTypeStr << ")";

    if (mAudioAnalytics.mDeliverStatistics) {
        android::util::BytesField bf_serialized(
            serializedDeviceTypes.c_str(), serializedDeviceTypes.size());
        const auto result = sendToStatsd(
                CONDITION(android::util::MEDIAMETRICS_AAUDIOSTREAM_REPORTED)
                , callerName
                , path
                , direction
                , framesPerBurst
@@ -1033,12 +1037,13 @@ void AudioAnalytics::AAudioStreamInfo::endAAudioStream(
                , formatApp
                , formatDevice
                , logSessionId.c_str()
                , sampleRate
                , contentType
                );
        std::stringstream ss;
        ss << "result:" << result;
        const auto fieldsStr = printFields(AAudioStreamFields,
                CONDITION(android::util::MEDIAMETRICS_AAUDIOSTREAM_REPORTED)
                , callerName
                , path
                , direction
                , framesPerBurst
@@ -1054,6 +1059,8 @@ void AudioAnalytics::AAudioStreamInfo::endAAudioStream(
                , formatApp
                , formatDevice
                , logSessionId.c_str()
                , sampleRate
                , contentType
                );
        ss << " " << fieldsStr;
        std::string str = ss.str();
+10 −10
Original line number Diff line number Diff line
@@ -158,9 +158,9 @@ const std::unordered_map<std::string, int32_t>& getAAudioDirection() {
    // DO NOT MODIFY VALUES(OK to add new ones).
    // This may be found in frameworks/av/media/libaaudio/include/aaudio/AAudio.h
    static std::unordered_map<std::string, int32_t> map {
        // UNKNOWN is -1
        {"AAUDIO_DIRECTION_OUTPUT",    0},
        {"AAUDIO_DIRECTION_INPUT",     1},
        // UNKNOWN is 0
        {"AAUDIO_DIRECTION_OUTPUT",    1 /* AAUDIO_DIRECTION_OUTPUT + 1 */},
        {"AAUDIO_DIRECTION_INPUT",     2 /* AAUDIO_DIRECTION_INPUT + 1*/},
    };
    return map;
}
@@ -169,7 +169,7 @@ const std::unordered_map<std::string, int32_t>& getAAudioPerformanceMode() {
    // DO NOT MODIFY VALUES(OK to add new ones).
    // This may be found in frameworks/av/media/libaaudio/include/aaudio/AAudio.h
    static std::unordered_map<std::string, int32_t> map {
        // UNKNOWN is -1
        // UNKNOWN is 0
        {"AAUDIO_PERFORMANCE_MODE_NONE",            10},
        {"AAUDIO_PERFORMANCE_MODE_POWER_SAVING",    11},
        {"AAUDIO_PERFORMANCE_MODE_LOW_LATENCY",     12},
@@ -181,9 +181,9 @@ const std::unordered_map<std::string, int32_t>& getAAudioSharingMode() {
    // DO NOT MODIFY VALUES(OK to add new ones).
    // This may be found in frameworks/av/media/libaaudio/include/aaudio/AAudio.h
    static std::unordered_map<std::string, int32_t> map {
        // UNKNOWN is -1
        {"AAUDIO_SHARING_MODE_EXCLUSIVE",    0},
        {"AAUDIO_SHARING_MODE_SHARED",       1},
        // UNKNOWN is 0
        {"AAUDIO_SHARING_MODE_EXCLUSIVE",    1 /* AAUDIO_SHARING_MODE_EXCLUSIVE + 1 */},
        {"AAUDIO_SHARING_MODE_SHARED",       2 /* AAUDIO_SHARING_MODE_SHARED + 1 */},
    };
    return map;
}
@@ -484,7 +484,7 @@ int32_t lookup<AAUDIO_DIRECTION>(const std::string &direction)
    auto& map = getAAudioDirection();
    auto it = map.find(direction);
    if (it == map.end()) {
        return -1; // return unknown
        return 0; // return unknown
    }
    return it->second;
}
@@ -506,7 +506,7 @@ int32_t lookup<AAUDIO_PERFORMANCE_MODE>(const std::string &performanceMode)
    auto& map = getAAudioPerformanceMode();
    auto it = map.find(performanceMode);
    if (it == map.end()) {
        return -1; // return unknown
        return 0; // return unknown
    }
    return it->second;
}
@@ -528,7 +528,7 @@ int32_t lookup<AAUDIO_SHARING_MODE>(const std::string &sharingMode)
    auto& map = getAAudioSharingMode();
    auto it = map.find(sharingMode);
    if (it == map.end()) {
        return -1; // return unknown
        return 0; // return unknown
    }
    return it->second;
}