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
This commit is contained in:
@@ -3,27 +3,15 @@
|
||||
// Agreement.
|
||||
//
|
||||
// This file contains the definitions for the Distribution class members.
|
||||
|
||||
#include "distribution.h"
|
||||
|
||||
#include <float.h>
|
||||
|
||||
namespace wvcdm {
|
||||
namespace metrics {
|
||||
Distribution::Distribution()
|
||||
: count_(0ULL),
|
||||
min_(FLT_MAX),
|
||||
max_(-FLT_MAX),
|
||||
mean_(0.0),
|
||||
sum_squared_deviation_(0.0) {}
|
||||
|
||||
void Distribution::Record(float value) {
|
||||
// Using method of provisional means.
|
||||
float deviation = value - mean_;
|
||||
mean_ = mean_ + (deviation / ++count_);
|
||||
sum_squared_deviation_ =
|
||||
sum_squared_deviation_ + (deviation * (value - mean_));
|
||||
|
||||
const float deviation = value - mean_;
|
||||
mean_ += (deviation / ++count_);
|
||||
sum_squared_deviation_ += (deviation * (value - mean_));
|
||||
min_ = min_ < value ? min_ : value;
|
||||
max_ = max_ > value ? max_ : value;
|
||||
}
|
||||
|
||||
@@ -5,19 +5,26 @@
|
||||
|
||||
namespace wvcdm {
|
||||
namespace metrics {
|
||||
void TimerMetric::Start() {
|
||||
start_ = clock_.now();
|
||||
using ClockType = std::chrono::steady_clock;
|
||||
using TimePoint = std::chrono::time_point<ClockType>;
|
||||
|
||||
void Timer::Start() {
|
||||
start_ = ClockType::now();
|
||||
is_started_ = true;
|
||||
}
|
||||
|
||||
void TimerMetric::Clear() { is_started_ = false; }
|
||||
void Timer::Clear() { is_started_ = false; }
|
||||
|
||||
double TimerMetric::AsMs() const {
|
||||
return (clock_.now() - start_) / std::chrono::milliseconds(1);
|
||||
double Timer::AsMs() const {
|
||||
if (!is_started_) return 0.0;
|
||||
const TimePoint end = ClockType::now();
|
||||
return (end - start_) / std::chrono::milliseconds(1);
|
||||
}
|
||||
|
||||
double TimerMetric::AsUs() const {
|
||||
return (clock_.now() - start_) / std::chrono::microseconds(1);
|
||||
double Timer::AsUs() const {
|
||||
if (!is_started_) return 0.0;
|
||||
const TimePoint end = ClockType::now();
|
||||
return (end - start_) / std::chrono::microseconds(1);
|
||||
}
|
||||
} // namespace metrics
|
||||
} // namespace wvcdm
|
||||
|
||||
Reference in New Issue
Block a user