Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | #ifndef DRM_METRICS_H_ |
| 18 | #define DRM_METRICS_H_ |
| 19 | |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 20 | #include <map> |
| 21 | |
| 22 | #include <android/hardware/drm/1.0/types.h> |
Adam Stone | 28f27c3 | 2018-02-05 15:07:48 -0800 | [diff] [blame] | 23 | #include <android/hardware/drm/1.1/types.h> |
Robert Shih | a503326 | 2019-05-06 14:15:12 -0700 | [diff] [blame] | 24 | #include <android/hardware/drm/1.2/types.h> |
Adam Stone | 637b785 | 2018-01-30 12:09:36 -0800 | [diff] [blame] | 25 | #include <binder/PersistableBundle.h> |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 26 | #include <media/CounterMetric.h> |
| 27 | #include <media/EventMetric.h> |
| 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | /** |
| 32 | * This class contains the definition of metrics captured within MediaDrm. |
| 33 | * It also contains a method for exporting all of the metrics to a |
Adam Stone | 568b3c4 | 2018-01-31 12:57:16 -0800 | [diff] [blame] | 34 | * PersistableBundle. |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 35 | */ |
| 36 | class MediaDrmMetrics { |
| 37 | public: |
| 38 | explicit MediaDrmMetrics(); |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 39 | virtual ~MediaDrmMetrics() {}; |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 40 | // Count of openSession calls. |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 41 | CounterMetric<status_t> mOpenSessionCounter; |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 42 | // Count of closeSession calls. |
| 43 | CounterMetric<status_t> mCloseSessionCounter; |
| 44 | // Count and timing of getKeyRequest calls. |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 45 | EventMetric<status_t> mGetKeyRequestTimeUs; |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 46 | // Count and timing of provideKeyResponse calls. |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 47 | EventMetric<status_t> mProvideKeyResponseTimeUs; |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 48 | // Count of getProvisionRequest calls. |
| 49 | CounterMetric<status_t> mGetProvisionRequestCounter; |
| 50 | // Count of provideProvisionResponse calls. |
| 51 | CounterMetric<status_t> mProvideProvisionResponseCounter; |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 52 | |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 53 | // Count of key status events broken out by status type. |
Robert Shih | a503326 | 2019-05-06 14:15:12 -0700 | [diff] [blame] | 54 | CounterMetric<::android::hardware::drm::V1_2::KeyStatusType> |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 55 | mKeyStatusChangeCounter; |
| 56 | // Count of events broken out by event type |
| 57 | CounterMetric<::android::hardware::drm::V1_0::EventType> mEventCounter; |
| 58 | |
| 59 | // Count getPropertyByteArray calls to retrieve the device unique id. |
| 60 | CounterMetric<status_t> mGetDeviceUniqueIdCounter; |
| 61 | |
Adam Stone | 568b3c4 | 2018-01-31 12:57:16 -0800 | [diff] [blame] | 62 | // Adds a session start time record. |
| 63 | void SetSessionStart(const Vector<uint8_t>& sessionId); |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 64 | |
Adam Stone | 568b3c4 | 2018-01-31 12:57:16 -0800 | [diff] [blame] | 65 | // Adds a session end time record. |
| 66 | void SetSessionEnd(const Vector<uint8_t>& sessionId); |
| 67 | |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 68 | // The app package name is the application package name that is using the |
| 69 | // instance. The app package name is held here for convenience. It is not |
| 70 | // serialized or exported with the metrics. |
| 71 | void SetAppPackageName(const String8& appPackageName) { mAppPackageName = appPackageName; } |
| 72 | const String8& GetAppPackageName() { return mAppPackageName; } |
| 73 | |
Adam Stone | 568b3c4 | 2018-01-31 12:57:16 -0800 | [diff] [blame] | 74 | // Export the metrics to a PersistableBundle. |
Adam Stone | 637b785 | 2018-01-30 12:09:36 -0800 | [diff] [blame] | 75 | void Export(os::PersistableBundle* metricsBundle); |
Adam Stone | 568b3c4 | 2018-01-31 12:57:16 -0800 | [diff] [blame] | 76 | |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 77 | // Get the serialized metrics. Metrics are formatted as a serialized |
| 78 | // DrmFrameworkMetrics proto. If there is a failure serializing the metrics, |
| 79 | // this returns an error. The parameter |serlializedMetrics| is owned by the |
| 80 | // caller and must not be null. |
| 81 | status_t GetSerializedMetrics(std::string* serializedMetrics); |
| 82 | |
Adam Stone | 28f27c3 | 2018-02-05 15:07:48 -0800 | [diff] [blame] | 83 | // Converts the DRM plugin metrics to a PersistableBundle. All of the metrics |
| 84 | // found in |pluginMetrics| are added to the |metricsBundle| parameter. |
| 85 | // |pluginBundle| is owned by the caller and must not be null. |
| 86 | // |
| 87 | // Each item in the pluginMetrics vector is added as a new PersistableBundle. E.g. |
| 88 | // DrmMetricGroup { |
| 89 | // metrics[0] { |
| 90 | // name: "buf_copy" |
| 91 | // attributes[0] { |
| 92 | // name: "size" |
| 93 | // type: INT64_TYPE |
| 94 | // int64Value: 1024 |
| 95 | // } |
| 96 | // values[0] { |
| 97 | // componentName: "operation_count" |
| 98 | // type: INT64_TYPE |
| 99 | // int64Value: 75 |
| 100 | // } |
| 101 | // values[1] { |
| 102 | // component_name: "average_time_seconds" |
| 103 | // type: DOUBLE_TYPE |
| 104 | // doubleValue: 0.00000042 |
| 105 | // } |
| 106 | // } |
| 107 | // } |
| 108 | // |
| 109 | // becomes |
| 110 | // |
| 111 | // metricsBundle { |
| 112 | // "0": (PersistableBundle) { |
| 113 | // "attributes" : (PersistableBundle) { |
| 114 | // "size" : (int64) 1024 |
| 115 | // } |
| 116 | // "operation_count" : (int64) 75 |
| 117 | // "average_time_seconds" : (double) 0.00000042 |
| 118 | // } |
| 119 | // |
| 120 | static status_t HidlMetricsToBundle( |
| 121 | const hardware::hidl_vec<hardware::drm::V1_1::DrmMetricGroup>& pluginMetrics, |
| 122 | os::PersistableBundle* metricsBundle); |
| 123 | |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 124 | protected: |
| 125 | // This is visible for testing only. |
| 126 | virtual int64_t GetCurrentTimeMs(); |
| 127 | |
Adam Stone | 568b3c4 | 2018-01-31 12:57:16 -0800 | [diff] [blame] | 128 | private: |
| 129 | // Session lifetimes. A pair of values representing the milliseconds since |
| 130 | // epoch, UTC. The first value is the start time, the second is the end time. |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 131 | std::map<std::string, std::pair<int64_t, int64_t>> mSessionLifespans; |
| 132 | |
| 133 | String8 mAppPackageName; |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | } // namespace android |
| 137 | |
| 138 | #endif // DRM_METRICS_H_ |