| Index: webrtc/base/rate_statistics.cc
|
| diff --git a/webrtc/base/rate_statistics.cc b/webrtc/base/rate_statistics.cc
|
| index 8db2851e682f3e152cced6a738eedb571d982c66..843eadbadacc22a9c131168b592b1cd2a86788f3 100644
|
| --- a/webrtc/base/rate_statistics.cc
|
| +++ b/webrtc/base/rate_statistics.cc
|
| @@ -10,7 +10,7 @@
|
|
|
| #include "webrtc/base/rate_statistics.h"
|
|
|
| -#include <assert.h>
|
| +#include <algorithm>
|
|
|
| namespace webrtc {
|
|
|
| @@ -20,7 +20,7 @@ RateStatistics::RateStatistics(uint32_t window_size_ms, float scale)
|
| accumulated_count_(0),
|
| oldest_time_(0),
|
| oldest_index_(0),
|
| - scale_(scale / (num_buckets_ - 1)) {}
|
| + scale_(scale) {}
|
|
|
| RateStatistics::~RateStatistics() {}
|
|
|
| @@ -53,15 +53,17 @@ void RateStatistics::Update(size_t count, int64_t now_ms) {
|
|
|
| uint32_t RateStatistics::Rate(int64_t now_ms) {
|
| EraseOld(now_ms);
|
| - return static_cast<uint32_t>(accumulated_count_ * scale_ + 0.5f);
|
| + float scale = scale_ / (now_ms - oldest_time_ + 1);
|
| + return static_cast<uint32_t>(accumulated_count_ * scale + 0.5f);
|
| }
|
|
|
| void RateStatistics::EraseOld(int64_t now_ms) {
|
| int64_t new_oldest_time = now_ms - num_buckets_ + 1;
|
| if (new_oldest_time <= oldest_time_) {
|
| + if (accumulated_count_ == 0)
|
| + oldest_time_ = now_ms;
|
| return;
|
| }
|
| -
|
| while (oldest_time_ < new_oldest_time) {
|
| size_t count_in_oldest_bucket = buckets_[oldest_index_];
|
| assert(accumulated_count_ >= count_in_oldest_bucket);
|
| @@ -74,6 +76,7 @@ void RateStatistics::EraseOld(int64_t now_ms) {
|
| if (accumulated_count_ == 0) {
|
| // This guarantees we go through all the buckets at most once, even if
|
| // |new_oldest_time| is far greater than |oldest_time_|.
|
| + new_oldest_time = now_ms;
|
| break;
|
| }
|
| }
|
|
|