blob: f5365455943314489eff295d6a0e60d67e80a27a [file] [log] [blame]
Adam Stonef0e618d2018-01-17 19:20:41 -08001/*
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#include <media/DrmMetrics.h>
18
19namespace {
20
21template<typename T>
22void ExportCounterMetric(const android::CounterMetric<T>& counter,
23 android::MediaAnalyticsItem* item) {
24 std::string success_count_name = counter.metric_name() + "/ok/count";
25 std::string error_count_name = counter.metric_name() + "/error/count";
26 counter.ExportValues(
27 [&] (const android::status_t status, const int64_t value) {
28 if (status == android::OK) {
29 item->setInt64(success_count_name.c_str(), value);
30 } else {
31 int64_t total_errors(0);
32 item->getInt64(error_count_name.c_str(), &total_errors);
33 item->setInt64(error_count_name.c_str(), total_errors + value);
34 // TODO: Add support for exporting the list of error values.
35 // This probably needs to be added to MediaAnalyticsItem.
36 }
37 });
38}
39
40template<typename T>
41void ExportEventMetric(const android::EventMetric<T>& event,
42 android::MediaAnalyticsItem* item) {
43 std::string success_count_name = event.metric_name() + "/ok/count";
44 std::string error_count_name = event.metric_name() + "/error/count";
45 std::string timing_name = event.metric_name() + "/average_time_micros";
46 event.ExportValues(
47 [&] (const android::status_t& status,
48 const android::EventStatistics& value) {
49 if (status == android::OK) {
50 item->setInt64(success_count_name.c_str(), value.count);
51 item->setInt64(timing_name.c_str(), value.mean);
52 } else {
53 int64_t total_errors(0);
54 item->getInt64(error_count_name.c_str(), &total_errors);
55 item->setInt64(error_count_name.c_str(),
56 total_errors + value.count);
57 // TODO: Add support for exporting the list of error values.
58 // This probably needs to be added to MediaAnalyticsItem.
59 }
60 });
61}
62
63} // namespace anonymous
64
65namespace android {
66
67MediaDrmMetrics::MediaDrmMetrics()
68 : mOpenSessionCounter("/drm/mediadrm/open_session", "status"),
69 mGetKeyRequestTiming("/drm/mediadrm/get_key_request", "status") {
70}
71
72void MediaDrmMetrics::Export(MediaAnalyticsItem* item) {
73 ExportCounterMetric(mOpenSessionCounter, item);
74 ExportEventMetric(mGetKeyRequestTiming, item);
75}
76
77} // namespace android