| Index: webrtc/base/bucketratetracker.h
|
| diff --git a/webrtc/base/bucketratetracker.h b/webrtc/base/bucketratetracker.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f91596fd9f488af6108e95e4748449111428c975
|
| --- /dev/null
|
| +++ b/webrtc/base/bucketratetracker.h
|
| @@ -0,0 +1,60 @@
|
| +/*
|
| + * 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, size_t bucket_count);
|
| + virtual ~BucketRateTracker();
|
| +
|
| + double ComputeCurrentRate(uint32 interval_milliseconds) const;
|
| +
|
| + // Reads the current time in order to determine the appropriate bucket for
|
| + // these samples, and increments the count for that bucket by sample_count.
|
| + void AddSamples(size_t sample_count);
|
| +
|
| + protected:
|
| + // overrideable for tests
|
| + virtual uint32 Time() const;
|
| +
|
| + private:
|
| + void EnsureInitialized();
|
| + size_t NextBucketIndex(size_t bucket_index) const;
|
| +
|
| + const uint32 bucket_milliseconds_;
|
| + const size_t bucket_count_;
|
| + size_t* sample_buckets_;
|
| + size_t current_bucket_;
|
| + uint32 bucket_start_time_;
|
| + uint32 initialization_time_;
|
| +};
|
| +
|
| +// Computes samples 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_
|
|
|