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
3 // found in the LICENSE file.
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.
11 // All classes defined are thread-safe.
13 #ifndef REMOTING_BASE_RUNNING_AVERAGE_H_
14 #define REMOTING_BASE_RUNNING_AVERAGE_H_
18 #include "base/basictypes.h"
19 #include "base/synchronization/lock.h"
23 class RunningAverage
{
25 // Construct a running average counter for a specific window size. The
26 // |windows_size| most recent values are kept and the average is reported.
27 explicit RunningAverage(int window_size
);
29 virtual ~RunningAverage();
31 // Record the provided data point.
32 void Record(int64 value
);
34 // Return the average of data points in the last window.
38 // Size of the window. This is of type size_t to avoid casting when comparing
39 // with the size of |data_points_|.
42 // Protects |data_points_| and |sum_|.
45 // Keep the values of all the data points.
46 std::deque
<int64
> data_points_
;
48 // Sum of values in |data_points_|.
51 DISALLOW_COPY_AND_ASSIGN(RunningAverage
);
54 } // namespace remoting
56 #endif // REMOTING_BASE_RUNNING_AVERAGE_H_