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

Commit 1f560f85 authored by Andy Hung's avatar Andy Hung
Browse files

MediaMetrics: Report last statsd atoms pulled

Report last pulled statsd atoms.

Test: adb shell dumpsys media.metrics
Bug: 184263266
Change-Id: I82ac5d3852296632af5b096f7ea41c54bc42e4fb
parent dbacbadf
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -547,7 +547,7 @@ AStatsManager_PullAtomCallbackReturn MediaMetricsService::pullItems(
    std::lock_guard _l(mLock);
    for (auto &item : mPullableItems[key]) {
        if (const auto sitem = item.lock()) {
            dump2Statsd(sitem, data);
            dump2Statsd(sitem, data, mStatsdLog);
        }
    }
    mPullableItems[key].clear();
+21 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

#pragma once

#include <iomanip>
#include <sstream>
#include <string>
#include <vector>

@@ -146,4 +148,23 @@ inline std::string sanitizeLogSessionId(const std::string& string) {
    return {}; // if not a logSessionId, return an empty string.
}

inline std::string bytesToString(const std::vector<uint8_t>& bytes, size_t maxSize = SIZE_MAX) {
    if (bytes.size() == 0) {
        return "{}";
    }
    std::stringstream ss;
    ss << "{";
    ss << std::hex << std::setfill('0');
    maxSize = std::min(maxSize, bytes.size());
    for (size_t i = 0; i < maxSize; ++i) {
        ss << " " << std::setw(2) << (int)bytes[i];
    }
    if (maxSize != bytes.size()) {
        ss << " ... }";
    } else {
        ss << " }";
    }
    return ss.str();
}

} // namespace android::mediametrics::stringutils
+3 −2
Original line number Diff line number Diff line
@@ -93,12 +93,13 @@ bool dump2Statsd(
    return dump2StatsdInternal(statsd_pushers, item, statsdLog);
}

bool dump2Statsd(const std::shared_ptr<const mediametrics::Item>& item, AStatsEventList* out) {
bool dump2Statsd(const std::shared_ptr<const mediametrics::Item>& item, AStatsEventList* out,
        const std::shared_ptr<mediametrics::StatsdLog>& statsdLog) {
    static const std::map<std::string, statsd_puller*> statsd_pullers =
    {
        { "mediadrm", statsd_mediadrm_puller },
    };
    return dump2StatsdInternal(statsd_pullers, item, out);
    return dump2StatsdInternal(statsd_pullers, item, out, statsdLog);
}

} // namespace android
+3 −3
Original line number Diff line number Diff line
@@ -39,12 +39,12 @@ extern statsd_pusher statsd_mediadrm;
extern statsd_pusher statsd_drmmanager;

using statsd_puller = bool (const std::shared_ptr<const mediametrics::Item>& item,
        AStatsEventList *);
        AStatsEventList *, const std::shared_ptr<mediametrics::StatsdLog>& statsdLog);
// component specific pullers
extern statsd_puller statsd_mediadrm_puller;

bool dump2Statsd(const std::shared_ptr<const mediametrics::Item>& item,
        const std::shared_ptr<mediametrics::StatsdLog>& statsdLog);
bool dump2Statsd(const std::shared_ptr<const mediametrics::Item>& item, AStatsEventList* out);

bool dump2Statsd(const std::shared_ptr<const mediametrics::Item>& item, AStatsEventList* out,
        const std::shared_ptr<mediametrics::StatsdLog>& statsdLog);
} // namespace android
+16 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include <pwd.h>

#include "MediaMetricsService.h"
#include "StringUtils.h"
#include "iface_statsd.h"

#include <statslog.h>
@@ -172,7 +173,8 @@ std::vector<uint8_t> base64DecodeNoPad(std::string& str) {

// |out| and its contents are memory-managed by statsd.
bool statsd_mediadrm_puller(
        const std::shared_ptr<const mediametrics::Item>& item, AStatsEventList* out)
        const std::shared_ptr<const mediametrics::Item>& item, AStatsEventList* out,
        const std::shared_ptr<mediametrics::StatsdLog>& statsdLog)
{
    if (item == nullptr) {
        return false;
@@ -201,6 +203,19 @@ bool statsd_mediadrm_puller(
    AStatsEvent_writeByteArray(event, framework_raw.data(), framework_raw.size());
    AStatsEvent_writeByteArray(event, plugin_raw.data(), plugin_raw.size());
    AStatsEvent_build(event);

    std::stringstream log;
    log << "pulled:" << " {"
            << " media_drm_activity_info:"
            << android::util::MEDIA_DRM_ACTIVITY_INFO
            << " package_name:" << item->getPkgName()
            << " package_version_code:" << item->getPkgVersionCode()
            << " vendor:" << vendor
            << " description:" << description
            << " framework_metrics:" << mediametrics::stringutils::bytesToString(framework_raw, 8)
            << " vendor_metrics:" <<  mediametrics::stringutils::bytesToString(plugin_raw, 8)
            << " }";
    statsdLog->log(android::util::MEDIA_DRM_ACTIVITY_INFO, log.str());
    return true;
}