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

Side by Side Diff: remoting/base/running_average.h

Issue 12803008: Add unit tests for sub-components of CaptureScheduler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pick nits. Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « remoting/base/rate_counter_unittest.cc ('k') | remoting/base/running_average.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // RunningAverage defined in this file is used to generate statistics for
6 // bandwidth, latency and other performance metrics for remoting. Usually
7 // this data comes in as a stream and fluctuates a lot. They are processed by
8 // this class to generate a more stable value by taking average within a
9 // window of data points.
10
11 // All classes defined are thread-safe.
12
13 #ifndef REMOTING_BASE_RUNNING_AVERAGE_H_ 5 #ifndef REMOTING_BASE_RUNNING_AVERAGE_H_
14 #define REMOTING_BASE_RUNNING_AVERAGE_H_ 6 #define REMOTING_BASE_RUNNING_AVERAGE_H_
15 7
16 #include <deque> 8 #include <deque>
17 9
18 #include "base/basictypes.h" 10 #include "base/basictypes.h"
19 #include "base/synchronization/lock.h" 11 #include "base/threading/non_thread_safe.h"
20 12
21 namespace remoting { 13 namespace remoting {
22 14
23 class RunningAverage { 15 // Calculates the average of the most recent N recorded samples.
16 // This is typically used to smooth out random variation in point samples
17 // over bandwidth, frame rate, etc.
18 class RunningAverage : public base::NonThreadSafe {
24 public: 19 public:
25 // Construct a running average counter for a specific window size. The 20 // Constructs a helper to average over the |window_size| most recent samples.
26 // |windows_size| most recent values are kept and the average is reported.
27 explicit RunningAverage(int window_size); 21 explicit RunningAverage(int window_size);
28
29 virtual ~RunningAverage(); 22 virtual ~RunningAverage();
30 23
31 // Record the provided data point. 24 // Records a point sample.
32 void Record(int64 value); 25 void Record(int64 value);
33 26
34 // Return the average of data points in the last window. 27 // Returns the average over up to |window_size| of the most recent samples.
35 double Average(); 28 double Average() const;
36 29
37 private: 30 private:
38 // Size of the window. This is of type size_t to avoid casting when comparing 31 // Stores the desired window size, as size_t to avoid casting when comparing
39 // with the size of |data_points_|. 32 // with the size of |data_points_|.
40 size_t window_size_; 33 const size_t window_size_;
41 34
42 // Protects |data_points_| and |sum_|. 35 // Stores the |window_size| most recently recorded samples.
43 base::Lock lock_;
44
45 // Keep the values of all the data points.
46 std::deque<int64> data_points_; 36 std::deque<int64> data_points_;
47 37
48 // Sum of values in |data_points_|. 38 // Holds the sum of the samples in |data_points_|.
49 int64 sum_; 39 int64 sum_;
50 40
51 DISALLOW_COPY_AND_ASSIGN(RunningAverage); 41 DISALLOW_COPY_AND_ASSIGN(RunningAverage);
52 }; 42 };
53 43
54 } // namespace remoting 44 } // namespace remoting
55 45
56 #endif // REMOTING_BASE_RUNNING_AVERAGE_H_ 46 #endif // REMOTING_BASE_RUNNING_AVERAGE_H_
OLDNEW
« no previous file with comments | « remoting/base/rate_counter_unittest.cc ('k') | remoting/base/running_average.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698