// Copyright 2017 Google Inc. All Rights Reserved. // // This file contains implementations for the BaseEventMetric. #include "event_metric.h" namespace wvcdm { namespace metrics { BaseEventMetric::~BaseEventMetric() { AutoLock lock(internal_lock_); for (std::map::iterator it = value_map_.begin(); it != value_map_.end(); it++) { delete it->second; } } void BaseEventMetric::Record(const std::string& field_names_values, double value) { AutoLock lock(internal_lock_); Distribution* distribution; if (value_map_.find(field_names_values) == value_map_.end()) { distribution = new Distribution(); value_map_[field_names_values] = distribution; } else { distribution = value_map_[field_names_values]; } distribution->Record(value); } void BaseEventMetric::Serialize(MetricSerializer* serializer) { AutoLock lock(internal_lock_); for (std::map::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