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

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: added rate counter Created 9 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
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 // these data come in as a stream and fluctuates a lot. They are processed by
simonmorris 2011/04/04 10:27:34 "this...comes...fluctuates" or "these...come...flu
Alpha Left Google 2011/04/05 00:16:06 Done.
Alpha Left Google 2011/04/05 00:16:06 Done.
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 most
27 // |windows_size| recent values are kept and the average is reported.
simonmorris 2011/04/04 10:27:34 "|windows_size| most recent", not "most |windows_s
Alpha Left Google 2011/04/05 00:16:06 Done.
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 int64 Average();
simonmorris 2011/04/04 10:27:34 Is int64 better than the expected double?
Alpha Left Google 2011/04/05 00:16:06 In a later patch this is changed to double.
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

Powered by Google App Engine
This is Rietveld 408576698