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

Commit 49b65335 authored by John Bruce's avatar John Bruce Committed by Android (Google) Code Review
Browse files

Merge "Marshal Metrics"

parents 349978ee 33ecc4f6
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -13,16 +13,23 @@ cc_library_shared {
        "IDrm.cpp",
        "IDrm.cpp",
        "IDrmClient.cpp",
        "IDrmClient.cpp",
        "IMediaDrmService.cpp",
        "IMediaDrmService.cpp",
        "PluginMetricsReporting.cpp",
        "SharedLibrary.cpp",
        "SharedLibrary.cpp",
        "DrmHal.cpp",
        "DrmHal.cpp",
        "CryptoHal.cpp",
        "CryptoHal.cpp",
        "protos/plugin_metrics.proto",
    ],
    ],


    proto: {
        type: "lite",
    },

    shared_libs: [
    shared_libs: [
        "libbinder",
        "libbinder",
        "libcutils",
        "libcutils",
        "libdl",
        "libdl",
        "liblog",
        "liblog",
        "libmediametrics",
        "libmediautils",
        "libmediautils",
        "libstagefright_foundation",
        "libstagefright_foundation",
        "libutils",
        "libutils",
+31 −0
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@
#include <media/DrmHal.h>
#include <media/DrmHal.h>
#include <media/DrmSessionClientInterface.h>
#include <media/DrmSessionClientInterface.h>
#include <media/DrmSessionManager.h>
#include <media/DrmSessionManager.h>
#include <media/PluginMetricsReporting.h>
#include <media/drm/DrmAPI.h>
#include <media/drm/DrmAPI.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/AString.h>
#include <media/stagefright/foundation/AString.h>
@@ -421,6 +422,7 @@ status_t DrmHal::destroyPlugin() {
    }
    }


    closeOpenSessions();
    closeOpenSessions();
    reportMetrics();
    setListener(NULL);
    setListener(NULL);
    if (mPlugin != NULL) {
    if (mPlugin != NULL) {
        mPlugin->setListener(NULL);
        mPlugin->setListener(NULL);
@@ -494,6 +496,7 @@ status_t DrmHal::closeSession(Vector<uint8_t> const &sessionId) {
            }
            }
        }
        }
    }
    }
    reportMetrics();
    return toStatusT(status);
    return toStatusT(status);
}
}


@@ -745,6 +748,12 @@ status_t DrmHal::releaseAllSecureStops() {


status_t DrmHal::getPropertyString(String8 const &name, String8 &value ) const {
status_t DrmHal::getPropertyString(String8 const &name, String8 &value ) const {
    Mutex::Autolock autoLock(mLock);
    Mutex::Autolock autoLock(mLock);
    return getPropertyStringInternal(name, value);
}

status_t DrmHal::getPropertyStringInternal(String8 const &name, String8 &value) const {
    // This function is internal to the class and should only be called while
    // mLock is already held.


    if (mInitCheck != OK) {
    if (mInitCheck != OK) {
        return mInitCheck;
        return mInitCheck;
@@ -766,6 +775,12 @@ status_t DrmHal::getPropertyString(String8 const &name, String8 &value ) const {


status_t DrmHal::getPropertyByteArray(String8 const &name, Vector<uint8_t> &value ) const {
status_t DrmHal::getPropertyByteArray(String8 const &name, Vector<uint8_t> &value ) const {
    Mutex::Autolock autoLock(mLock);
    Mutex::Autolock autoLock(mLock);
    return getPropertyByteArrayInternal(name, value);
}

status_t DrmHal::getPropertyByteArrayInternal(String8 const &name, Vector<uint8_t> &value ) const {
    // This function is internal to the class and should only be called while
    // mLock is already held.


    if (mInitCheck != OK) {
    if (mInitCheck != OK) {
        return mInitCheck;
        return mInitCheck;
@@ -999,4 +1014,20 @@ void DrmHal::writeByteArray(Parcel &obj, hidl_vec<uint8_t> const &vec)
    }
    }
}
}


void DrmHal::reportMetrics() const
{
    Vector<uint8_t> metrics;
    String8 vendor;
    String8 description;
    if (getPropertyStringInternal(String8("vendor"), vendor) == OK &&
            getPropertyStringInternal(String8("description"), description) == OK &&
            getPropertyByteArrayInternal(String8("metrics"), metrics) == OK) {
        status_t res = android::reportDrmPluginMetrics(
                metrics, vendor, description);
        if (res != OK) {
            ALOGE("Metrics were retrieved but could not be reported: %i", res);
        }
    }
}

}  // namespace android
}  // namespace android
+122 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

//#define LOG_NDEBUG 0
#define LOG_TAG "PluginMetricsReporting"
#include <utils/Log.h>

#include <media/PluginMetricsReporting.h>

#include <media/MediaAnalyticsItem.h>

#include "protos/plugin_metrics.pb.h"

namespace android {

namespace {

using android::drm_metrics::MetricsGroup;
using android::drm_metrics::MetricsGroup_Metric;
using android::drm_metrics::MetricsGroup_Metric_MetricValue;

const char* const kParentAttribute = "/parent/external";

status_t reportMetricsGroup(const MetricsGroup& metricsGroup,
                            const String8& batchName,
                            const int64_t* parentId) {
    MediaAnalyticsItem analyticsItem(batchName.c_str());
    analyticsItem.generateSessionID();
    int64_t sessionId = analyticsItem.getSessionID();
    if (parentId != NULL) {
        analyticsItem.setInt64(kParentAttribute, *parentId);
    }

    for (int i = 0; i < metricsGroup.metric_size(); ++i) {
        const MetricsGroup_Metric& metric = metricsGroup.metric(i);
        if (!metric.has_name()) {
            ALOGE("Metric with no name.");
            return BAD_VALUE;
        }

        if (!metric.has_value()) {
            ALOGE("Metric with no value.");
            return BAD_VALUE;
        }

        const MetricsGroup_Metric_MetricValue& value = metric.value();
        if (value.has_int_value()) {
            analyticsItem.setInt64(metric.name().c_str(),
                                   value.int_value());
        } else if (value.has_double_value()) {
            analyticsItem.setDouble(metric.name().c_str(),
                                    value.double_value());
        } else if (value.has_string_value()) {
            analyticsItem.setCString(metric.name().c_str(),
                                     value.string_value().c_str());
        } else {
            ALOGE("Metric Value with no actual value.");
            return BAD_VALUE;
        }
    }

    analyticsItem.setFinalized(true);
    analyticsItem.selfrecord();

    for (int i = 0; i < metricsGroup.metric_sub_group_size(); ++i) {
        const MetricsGroup& subGroup = metricsGroup.metric_sub_group(i);
        status_t res = reportMetricsGroup(subGroup, batchName, &sessionId);
        if (res != OK) {
            return res;
        }
    }

    return OK;
}

String8 sanitize(const String8& input) {
    // Filters the input string down to just alphanumeric characters.
    String8 output;
    for (size_t i = 0; i < input.size(); ++i) {
        char candidate = input[i];
        if ((candidate >= 'a' && candidate <= 'z') ||
                (candidate >= 'A' && candidate <= 'Z') ||
                (candidate >= '0' && candidate <= '9')) {
            output.append(&candidate, 1);
        }
    }
    return output;
}

}  // namespace

status_t reportDrmPluginMetrics(const Vector<uint8_t>& serializedMetrics,
                                const String8& vendor,
                                const String8& description) {
    MetricsGroup root_metrics_group;
    if (!root_metrics_group.ParseFromArray(serializedMetrics.array(),
                                           serializedMetrics.size())) {
        ALOGE("Failure to parse.");
        return BAD_VALUE;
    }

    String8 name = String8::format("drm.vendor.%s.%s",
                                   sanitize(vendor).c_str(),
                                   sanitize(description).c_str());

    return reportMetricsGroup(root_metrics_group, name, NULL);
}

}  // namespace android
+47 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

syntax = "proto2";

package android.drm_metrics;

// need this if we are using libprotobuf-cpp-2.3.0-lite
option optimize_for = LITE_RUNTIME;

// The MetricsGroup is a collection of metric name/value pair instances
// that can be serialized and provided to a caller.
message MetricsGroup {
  message Metric {
    message MetricValue {
      // Exactly one of the following values must be set.
      optional int64 int_value = 1;
      optional double double_value = 2;
      optional string string_value = 3;
    }

    // The name of the metric. Must be valid UTF-8. Required.
    optional string name = 1;

    // The value of the metric. Required.
    optional MetricValue value = 2;
  }

  // The list of name/value pairs of metrics.
  repeated Metric metric = 1;

  // Allow multiple sub groups of metrics.
  repeated MetricsGroup metric_sub_group = 2;
}
+1 −0
Original line number Original line Diff line number Diff line
../../media/libmedia/include/media/PluginMetricsReporting.h
 No newline at end of file
Loading