From d93a00408699b996bb4d3db22ad731bb14e42387 Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Tue, 9 Apr 2019 15:38:07 +0200 Subject: [PATCH] Adds AddSamples function to SamplesStatsCounter. this allows merging two stats counter objects, will be used in a future CL to merge statistics for multiple video layers. Bug: webrtc:10365 Change-Id: Iee9c48b68dfd7ba29537c14fc5f4a7c1c333d145 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131942 Reviewed-by: Karl Wiberg Reviewed-by: Yves Gerey Commit-Queue: Sebastian Jansson Cr-Commit-Position: refs/heads/master@{#27534} --- rtc_base/numerics/samples_stats_counter.cc | 10 ++++++++++ rtc_base/numerics/samples_stats_counter.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/rtc_base/numerics/samples_stats_counter.cc b/rtc_base/numerics/samples_stats_counter.cc index 4f6c6857bd..134a65db1c 100644 --- a/rtc_base/numerics/samples_stats_counter.cc +++ b/rtc_base/numerics/samples_stats_counter.cc @@ -38,6 +38,16 @@ void SamplesStatsCounter::AddSample(double value) { sum_squared_ += value * value; } +void SamplesStatsCounter::AddSamples(const SamplesStatsCounter& other) { + for (double sample : other.samples_) + samples_.push_back(sample); + sorted_ = false; + max_ = std::max(max_, other.max_); + min_ = std::min(min_, other.min_); + sum_ += other.sum_; + sum_squared_ += other.sum_squared_; +} + double SamplesStatsCounter::GetPercentile(double percentile) { RTC_DCHECK(!IsEmpty()); RTC_CHECK_GE(percentile, 0); diff --git a/rtc_base/numerics/samples_stats_counter.h b/rtc_base/numerics/samples_stats_counter.h index a982b2ebf3..05a8c145f5 100644 --- a/rtc_base/numerics/samples_stats_counter.h +++ b/rtc_base/numerics/samples_stats_counter.h @@ -31,6 +31,9 @@ class SamplesStatsCounter { // Adds sample to the stats in amortized O(1) time. void AddSample(double value); + // Adds samples from another counter. + void AddSamples(const SamplesStatsCounter& other); + // Returns if there are any values in O(1) time. bool IsEmpty() const { return samples_.empty(); }