Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: webrtc/base/bucketratetracker.h

Issue 1279433006: Add a rate tracker that tracks rate over a given interval split up into buckets that accumulate uni… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: win64 fix Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifndef WEBRTC_BASE_BUCKETRATETRACKER_H_
12 #define WEBRTC_BASE_BUCKETRATETRACKER_H_
13
14 #include <stdlib.h>
15 #include "webrtc/base/basictypes.h"
16
17 namespace rtc {
18
19 // Computes units per second over a given interval by tracking the units over
20 // each bucket of a given size and calculating the instantaneous rate assuming
21 // that over each bucket the rate was constant.
22 class BucketRateTracker {
23 public:
24 BucketRateTracker(uint32 bucket_milliseconds, size_t bucket_count);
25 virtual ~BucketRateTracker();
26
27 double ComputeCurrentRate(uint32 interval_milliseconds) const;
28
29 // Reads the current time in order to determine the appropriate bucket for
30 // these samples, and increments the count for that bucket by sample_count.
31 void AddSamples(size_t sample_count);
32
33 protected:
34 // overrideable for tests
35 virtual uint32 Time() const;
36
37 private:
38 void EnsureInitialized();
39 size_t NextBucketIndex(size_t bucket_index) const;
40
41 const uint32 bucket_milliseconds_;
42 const size_t bucket_count_;
43 size_t* sample_buckets_;
44 size_t current_bucket_;
45 uint32 bucket_start_time_;
46 uint32 initialization_time_;
47 };
48
49 // Computes samples per second over a given interval by dividing it into buckets
50 // of one second each and calculating the rate over the appropriate number of
51 // buckets.
52 class IntervalRateTracker : public BucketRateTracker {
53 public:
54 explicit IntervalRateTracker(uint32 interval_seconds)
55 : BucketRateTracker(1000u, interval_seconds) {}
56 };
57
58 } // namespace rtc
59
60 #endif // WEBRTC_BASE_BUCKETRATETRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698