blob: bbbf4b529be4cc4ba1a9ba0375c689face68e650 [file] [log] [blame]
Robert Shih93538812019-11-12 12:21:35 -08001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <binder/PersistableBundle.h>
18#include <mediadrm/IDrmMetricsConsumer.h>
19#include <utils/Errors.h>
20
21#ifndef ANDROID_METRICSCONSUMER_H_
22
23#define ANDROID_METRICSCONSUMER_H_
24
25namespace android {
26
27/**
28 * IDrmMetricsConsumer which saves IDrm/ICrypto metrics into a PersistableBundle.
29 *
30 * Example usage:
31 *
32 * PersistableBundle bundle;
33 * DrmMetricsConsumer consumer(&bundle);
34 * drm->exportMetrics(&consumer);
35 * crypto->exportMetrics(&consumer);
36 * // bundle now contains metrics from drm/crypto.
37 *
38 */
39struct DrmMetricsConsumer : public IDrmMetricsConsumer {
40 DrmMetricsConsumer(os::PersistableBundle *bundle) : mBundle(bundle) {}
41
42 status_t consumeFrameworkMetrics(const MediaDrmMetrics &) override;
43
44 status_t consumeHidlMetrics(
45 const String8 &/*vendor*/,
46 const hidl_vec<DrmMetricGroup> &/*pluginMetrics*/) override;
47
48 // Converts the DRM plugin metrics to a PersistableBundle. All of the metrics
49 // found in |pluginMetrics| are added to the |metricsBundle| parameter.
50 // |pluginBundle| is owned by the caller and must not be null.
51 //
52 // Each item in the pluginMetrics vector is added as a new PersistableBundle. E.g.
53 // DrmMetricGroup {
54 // metrics[0] {
55 // name: "buf_copy"
56 // attributes[0] {
57 // name: "size"
58 // type: INT64_TYPE
59 // int64Value: 1024
60 // }
61 // values[0] {
62 // componentName: "operation_count"
63 // type: INT64_TYPE
64 // int64Value: 75
65 // }
66 // values[1] {
67 // component_name: "average_time_seconds"
68 // type: DOUBLE_TYPE
69 // doubleValue: 0.00000042
70 // }
71 // }
72 // }
73 //
74 // becomes
75 //
76 // metricsBundle {
77 // "0": (PersistableBundle) {
78 // "attributes" : (PersistableBundle) {
79 // "size" : (int64) 1024
80 // }
81 // "operation_count" : (int64) 75
82 // "average_time_seconds" : (double) 0.00000042
83 // }
84 //
85 static status_t HidlMetricsToBundle(
86 const hardware::hidl_vec<hardware::drm::V1_1::DrmMetricGroup>& pluginMetrics,
87 os::PersistableBundle* metricsBundle);
88
89private:
90 os::PersistableBundle *mBundle;
91 DISALLOW_EVIL_CONSTRUCTORS(DrmMetricsConsumer);
92};
93
94} // namespace android
95
96#endif // ANDROID_METRICSCONSUMER_H_