Files
android/libwvdrmengine/cdm/metrics/include/distribution.h
Alex Dale f5759c5149 Updated metric Distribution and Timer utils.
[ Merge of http://go/wvgerrit/137811 ]

Renamed TimerMetric to Timer.  Timer is used to generate durations
included in metrics, but is not a metric itself.  The method of
getting the current time did not require creating an instance of
std::steady_clock.

Updated Distribution and Timer to use default initializers instead of
constructor initialization list.

Bug: 204946540
Test: Metric unit tests
Change-Id: I7ed291b586347dd0b7ab305960883bec04637315
2021-11-05 15:12:09 -07:00

53 lines
1.7 KiB
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 the definition of a Distribution class which computes
// the distribution values of a series of samples.
#ifndef WVCDM_METRICS_DISTRIBUTION_H_
#define WVCDM_METRICS_DISTRIBUTION_H_
#include <stdint.h>
#include <limits>
namespace wvcdm {
namespace metrics {
// The Distribution class holds statistics about a series of values that the
// client provides via the Record method. A caller will call Record once for
// each of the values in a series. The Distribution instance will calculate the
// mean, count, min, max and variance of the distribution.
//
// Example usage:
// Distribution dist;
// dist.Record(1);
// dist.Record(2);
// dist.Mean(); // Returns 1.5.
// dist.Count(); // Returns 2.
class Distribution {
public:
Distribution() {}
// Uses the provided sample value to update the computed statistics.
void Record(float value);
// Return the value for each of the stats computed about the series of
// values (min, max, count, etc.).
float Min() const { return min_; }
float Max() const { return max_; }
float Mean() const { return mean_; }
uint64_t Count() const { return count_; }
double Variance() const {
return count_ == 0 ? 0.0 : sum_squared_deviation_ / count_;
}
private:
uint64_t count_ = 0;
float min_ = std::numeric_limits<float>::max();
float max_ = std::numeric_limits<float>::lowest();
float mean_ = 0.0f;
double sum_squared_deviation_ = 0.0;
};
} // namespace metrics
} // namespace wvcdm
#endif // WVCDM_METRICS_DISTRIBUTION_H_