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

Side by Side Diff: webrtc/base/ratetracker.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, 3 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
« no previous file with comments | « no previous file | webrtc/base/ratetracker.cc » ('j') | webrtc/base/ratetracker.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_BASE_RATETRACKER_H_ 11 #ifndef WEBRTC_BASE_RATETRACKER_H_
12 #define WEBRTC_BASE_RATETRACKER_H_ 12 #define WEBRTC_BASE_RATETRACKER_H_
13 13
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #include "webrtc/base/basictypes.h" 15 #include "webrtc/base/basictypes.h"
16 16
17 namespace rtc { 17 namespace rtc {
18 18
19 // Computes instantaneous units per second. 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.
20 class RateTracker { 22 class RateTracker {
21 public: 23 public:
22 RateTracker(); 24 RateTracker(uint32 bucket_milliseconds, size_t bucket_count);
23 virtual ~RateTracker() {} 25 virtual ~RateTracker();
24 26
25 size_t total_units() const; 27 double ComputeCurrentRate(uint32 interval_milliseconds) const;
26 size_t units_second(); 28 double ComputeCurrentRate() const {
noahric 2015/09/03 21:42:24 Use a different name for these; C++ style guide fr
tpsiaki 2015/09/03 23:28:59 Done.
27 void Update(size_t units); 29 return ComputeCurrentRate(
30 bucket_milliseconds_ * static_cast<uint32>(bucket_count_));
31 }
32
33 // Computes the average rate over the lifetime of the rate tracker.
noahric 2015/09/03 21:42:24 I'd replace "lifetime" with "since the first sampl
tpsiaki 2015/09/03 23:28:59 Done.
34 double ComputeTotalRate() const;
35
36 // The total number of samples added.
37 size_t TotalSampleCount() const;
38
39 // Reads the current time in order to determine the appropriate bucket for
40 // these samples, and increments the count for that bucket by sample_count.
41 void AddSamples(size_t sample_count);
28 42
29 protected: 43 protected:
30 // overrideable for tests 44 // overrideable for tests
31 virtual uint32 Time() const; 45 virtual uint32 Time() const;
32 46
33 private: 47 private:
34 size_t total_units_; 48 void EnsureInitialized();
35 size_t units_second_; 49 size_t NextBucketIndex(size_t bucket_index) const;
36 uint32 last_units_second_time_; 50
37 size_t last_units_second_calc_; 51 const uint32 bucket_milliseconds_;
52 const size_t bucket_count_;
53 size_t* sample_buckets_;
54 size_t total_sample_count_;
55 size_t current_bucket_;
56 uint32 bucket_start_time_;
noahric 2015/09/03 21:42:24 Prefer these have units as well (millis, ms, or mi
tpsiaki 2015/09/03 23:28:59 Done.
57 uint32 initialization_time_;
38 }; 58 };
39 59
40 } // namespace rtc 60 } // namespace rtc
41 61
42 #endif // WEBRTC_BASE_RATETRACKER_H_ 62 #endif // WEBRTC_BASE_RATETRACKER_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/ratetracker.cc » ('j') | webrtc/base/ratetracker.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698