[ Merge of http://go/wvgerrit/137810 ] Bug: 204946540 Test: Metric unit tests Change-Id: I78f839fafd27604a2bb78c04d587c40919c5372d
32 lines
944 B
C++
32 lines
944 B
C++
// Copyright 2017 Google LLC. All Rights Reserved. This file and proprietary
|
|
// source code may only be used and distributed under the Widevine License
|
|
// Agreement.
|
|
//
|
|
// This file contains implementations for the BaseEventMetric.
|
|
#include "event_metric.h"
|
|
|
|
namespace wvcdm {
|
|
namespace metrics {
|
|
BaseEventMetric::~BaseEventMetric() {
|
|
std::unique_lock<std::mutex> lock(internal_lock_);
|
|
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& key, double value) {
|
|
std::unique_lock<std::mutex> lock(internal_lock_);
|
|
Distribution* distribution;
|
|
if (value_map_.find(key) == value_map_.end()) {
|
|
distribution = new Distribution();
|
|
value_map_[key] = distribution;
|
|
} else {
|
|
distribution = value_map_[key];
|
|
}
|
|
|
|
distribution->Record(value);
|
|
}
|
|
} // namespace metrics
|
|
} // namespace wvcdm
|