Fixes widevine metrics proto serialization

Changes to a much more efficient and more reusable protobuf format for
metrics.

Test: Widevine tests, Google Play and MediaDrm CTS test.
Bug: 73724218

Change-Id: I3299051d7a16bcd7758c8f272415ca40e10c1313
This commit is contained in:
Adam Stone
2018-02-20 19:12:02 -08:00
parent efc008c5a1
commit b19f0d106f
25 changed files with 1587 additions and 1867 deletions

View File

@@ -4,60 +4,34 @@
#include "event_metric.h"
using ::google::protobuf::RepeatedPtrField;
namespace wvcdm {
namespace metrics {
BaseEventMetric::~BaseEventMetric() {
AutoLock lock(internal_lock_);
for (std::map<std::string, Distribution*>::iterator it
= value_map_.begin(); it != value_map_.end(); it++) {
for (std::map<std::string, Distribution *>::iterator it = value_map_.begin();
it != value_map_.end(); it++) {
delete it->second;
}
}
void BaseEventMetric::Record(const std::string& field_names_values,
double value) {
void BaseEventMetric::Record(const std::string &key, double value) {
AutoLock lock(internal_lock_);
Distribution* distribution;
Distribution *distribution;
if (value_map_.find(field_names_values) == value_map_.end()) {
if (value_map_.find(key) == value_map_.end()) {
distribution = new Distribution();
value_map_[field_names_values] = distribution;
value_map_[key] = distribution;
} else {
distribution = value_map_[field_names_values];
distribution = value_map_[key];
}
distribution->Record(value);
}
void BaseEventMetric::Serialize(MetricSerializer* serializer) {
AutoLock lock(internal_lock_);
for (std::map<std::string, Distribution*>::iterator it
= value_map_.begin(); it != value_map_.end(); it++) {
serializer->SetInt64(
metric_name_ + "/count" + it->first,
it->second->Count());
serializer->SetDouble(
metric_name_ + "/mean" + it->first,
it->second->Mean());
// Only publish additional information if there was more than one sample.
if (it->second->Count() > 1) {
serializer->SetDouble(
metric_name_ + "/variance" + it->first,
it->second->Variance());
serializer->SetDouble(
metric_name_ + "/min" + it->first,
it->second->Min());
serializer->SetDouble(
metric_name_ + "/max" + it->first,
it->second->Max());
}
}
}
} // namespace metrics
} // namespace wvcdm