Add CounterMetric and a single use case.
This adds a new class CounterMetric which is used to hold metric
information. It also adds a single use case for recording and
reporting a counter metric.
BUG: 64001676
Test: Added and ran a new test for the specific CounterMetric use case.
Change-Id: I39cab8328f135e579f80b6c2fab721da5f569795
diff --git a/drm/libmediadrm/DrmHal.cpp b/drm/libmediadrm/DrmHal.cpp
index c4b197c..9fc7d04 100644
--- a/drm/libmediadrm/DrmHal.cpp
+++ b/drm/libmediadrm/DrmHal.cpp
@@ -228,6 +228,7 @@
DrmHal::DrmHal()
: mDrmSessionClient(new DrmSessionClient(this)),
mFactories(makeDrmFactories()),
+ mOpenSessionCounter("/drm/mediadrm/open_session", "status"),
mInitCheck((mFactories.size() == 0) ? ERROR_UNSUPPORTED : NO_INIT) {
}
@@ -518,6 +519,8 @@
mDrmSessionClient, sessionId);
mOpenSessions.push(sessionId);
}
+
+ mOpenSessionCounter.Increment(err);
return err;
}
@@ -946,8 +949,25 @@
}
status_t DrmHal::getMetrics(MediaAnalyticsItem* metrics) {
- // TODO: Replace this with real metrics.
- metrics->setCString("/drm/mediadrm/dummymetric", "dummy");
+ // TODO: Move mOpenSessionCounter and suffixes to a separate class
+ // that manages the collection of metrics and exporting them.
+ std::string success_count_name =
+ mOpenSessionCounter.metric_name() + "/ok/count";
+ std::string error_count_name =
+ mOpenSessionCounter.metric_name() + "/error/count";
+ mOpenSessionCounter.ExportValues(
+ [&] (status_t status, int64_t value) {
+ if (status == OK) {
+ metrics->setInt64(success_count_name.c_str(), value);
+ } else {
+ int64_t total_errors(0);
+ metrics->getInt64(error_count_name.c_str(), &total_errors);
+ metrics->setInt64(error_count_name.c_str(),
+ total_errors + value);
+ // TODO: Add support for exporting the list of error values.
+ // This probably needs to be added to MediaAnalyticsItem.
+ }
+ });
return OK;
}