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(); }