OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // RateCounter is defined to measure average rate over a given time window. | 5 // RateCounter is defined to measure average rate over a given time window. |
6 // Rate is reported as the sum of values recorded divided by the time window. | 6 // Rate is reported as the sum of values recorded divided by the time window. |
7 // This can be used for measuring bandwidth, bitrate, etc. | 7 // This can be used for measuring bandwidth, bitrate, etc. |
8 | 8 |
9 // This class is thread-safe. | 9 // This class is thread-safe. |
10 | 10 |
11 #ifndef REMOTING_BASE_RATE_COUNTER_H_ | 11 #ifndef REMOTING_BASE_RATE_COUNTER_H_ |
12 #define REMOTING_BASE_RATE_COUNTER_H_ | 12 #define REMOTING_BASE_RATE_COUNTER_H_ |
13 | 13 |
14 #include <queue> | 14 #include <queue> |
15 #include <utility> | 15 #include <utility> |
16 | 16 |
17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 #include "base/time.h" | 19 #include "base/time.h" |
20 | 20 |
21 namespace remoting { | 21 namespace remoting { |
22 | 22 |
23 class RateCounter { | 23 class RateCounter { |
24 public: | 24 public: |
25 // Construct a counter for a specific time window. | 25 // Construct a counter for a specific time window. |
26 RateCounter(base::TimeDelta time_window); | 26 explicit RateCounter(base::TimeDelta time_window); |
27 | 27 |
28 virtual ~RateCounter(); | 28 virtual ~RateCounter(); |
29 | 29 |
30 // Record the data point. | 30 // Record the data point. |
31 void Record(int64 value); | 31 void Record(int64 value); |
32 | 32 |
33 // Report the rate recorded. At the beginning of recording the numbers before | 33 // Report the rate recorded. At the beginning of recording the numbers before |
34 // |time_window| is reached the reported rate will not be accurate. | 34 // |time_window| is reached the reported rate will not be accurate. |
35 double Rate(); | 35 double Rate(); |
36 | 36 |
(...skipping 15 matching lines...) Expand all Loading... |
52 | 52 |
53 // Sum of values in |data_points_|. | 53 // Sum of values in |data_points_|. |
54 int64 sum_; | 54 int64 sum_; |
55 | 55 |
56 DISALLOW_COPY_AND_ASSIGN(RateCounter); | 56 DISALLOW_COPY_AND_ASSIGN(RateCounter); |
57 }; | 57 }; |
58 | 58 |
59 } // namespace remoting | 59 } // namespace remoting |
60 | 60 |
61 #endif // REMOTING_BASE_RATE_COUNTER_H_ | 61 #endif // REMOTING_BASE_RATE_COUNTER_H_ |
OLD | NEW |