Chromium Code Reviews| Index: webrtc/base/bucketratetracker.h |
| diff --git a/webrtc/base/bucketratetracker.h b/webrtc/base/bucketratetracker.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5aaa2d751fee75562c956bb3304feb2a7ce57944 |
| --- /dev/null |
| +++ b/webrtc/base/bucketratetracker.h |
| @@ -0,0 +1,56 @@ |
| +/* |
| + * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#ifndef WEBRTC_BASE_BUCKETRATETRACKER_H_ |
| +#define WEBRTC_BASE_BUCKETRATETRACKER_H_ |
| + |
| +#include <stdlib.h> |
| +#include "webrtc/base/basictypes.h" |
| + |
| +namespace rtc { |
| + |
| +// Computes units per second over a given interval by tracking the units over |
| +// each bucket of a given size and calculating the instantaneous rate assuming |
| +// that over each bucket the rate was constant. |
| +class BucketRateTracker { |
| + public: |
| + BucketRateTracker(uint32 bucket_milliseconds, uint32 interval_buckets); |
|
noahric
2015/08/07 23:56:38
maybe size_t bucket_count? (and bucket_count_)
tpsiaki
2015/08/11 18:33:27
Done.
|
| + virtual ~BucketRateTracker(); |
| + |
| + size_t units_second() const; |
|
noahric
2015/08/07 23:56:38
double? Also since this is simply returning a fiel
tpsiaki
2015/08/11 18:33:27
Done.
|
| + void Update(size_t units); |
|
noahric
2015/08/07 23:56:38
I know this matches RateTracker, but I feel like A
tpsiaki
2015/08/11 18:33:27
Done.
|
| + |
| + protected: |
| + // overrideable for tests |
| + virtual uint32 Time() const; |
| + |
| + private: |
| + void EnsureInitialized(); |
| + |
| + const uint32 bucket_milliseconds_; |
| + const uint32 interval_buckets_; |
| + size_t* unit_buckets_; |
| + uint32 current_bucket_; |
| + uint32 bucket_start_time_; |
| + uint32 initialization_time_; |
| +}; |
| + |
| +// Computes units per second over a given interval by dividing it into buckets |
| +// of one second each and calculating the rate over the appropriate number of |
| +// buckets. |
| +class IntervalRateTracker : public BucketRateTracker { |
| + public: |
| + explicit IntervalRateTracker(uint32 interval_seconds) |
| + : BucketRateTracker(1000u, interval_seconds) {} |
| +}; |
| + |
| +} // namespace rtc |
| + |
| +#endif // WEBRTC_BASE_BUCKETRATETRACKER_H_ |