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

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

Issue 6736009: Measure bandwidth for chromoting video channel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: done Created 9 years, 8 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.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
(Empty)
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.
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_
14 #define REMOTING_BASE_RUNNING_AVERAGE_H_
15
16 #include <deque>
17
18 #include "base/basictypes.h"
19 #include "base/synchronization/lock.h"
20 #include "base/time.h"
21
22 namespace remoting {
23
24 class RunningAverage {
25 public:
26 // Construct a running average counter for a specific window size. The
27 // |windows_size| most recent values are kept and the average is reported.
28 RunningAverage(int window_size);
29
30 virtual ~RunningAverage();
31
32 // Record the provided data point.
33 void Record(int64 value);
34
35 // Return the average of data points in the last window.
36 double Average();
37
38 private:
39 // Size of the window. This is of type size_t to avoid casting when comparing
40 // with the size of |data_points_|.
41 size_t window_size_;
42
43 // Protects |data_points_| and |sum_|.
44 base::Lock lock_;
45
46 // Keep the values of all the data points.
47 std::deque<int64> data_points_;
48
49 // Sum of values in |data_points_|.
50 int64 sum_;
51
52 DISALLOW_COPY_AND_ASSIGN(RunningAverage);
53 };
54
55 } // namespace remoting
56
57 #endif // REMOTING_BASE_RUNNING_AVERAGE_H_
OLDNEW
« no previous file with comments | « remoting/base/rate_counter.cc ('k') | remoting/base/running_average.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698