summaryrefslogtreecommitdiffstats
path: root/remoting/base/running_average.h
diff options
context:
space:
mode:
authorhclam@google.com <hclam@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-05 18:03:31 +0000
committerhclam@google.com <hclam@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-05 18:03:31 +0000
commit778d599df45c985286cd70898187ecf7a6284eeb (patch)
treee4518f5d17d84f6613e0507c1dddc05ab1ddf23b /remoting/base/running_average.h
parent6ca1745021ac1b7822eb23a58c3985b2a91b293d (diff)
downloadchromium_src-778d599df45c985286cd70898187ecf7a6284eeb.zip
chromium_src-778d599df45c985286cd70898187ecf7a6284eeb.tar.gz
chromium_src-778d599df45c985286cd70898187ecf7a6284eeb.tar.bz2
Measure bandwidth for chromoting video channel
Define RunningAverage, TimedRunningAverage and use that to record video bandwidth. This doesn't account for overhead of protobuf envelop. However the number should be small that can be ignored. BUG=None TEST=None Review URL: http://codereview.chromium.org/6736009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80486 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/base/running_average.h')
-rw-r--r--remoting/base/running_average.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/remoting/base/running_average.h b/remoting/base/running_average.h
new file mode 100644
index 0000000..fadea1f
--- /dev/null
+++ b/remoting/base/running_average.h
@@ -0,0 +1,57 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// RunningAverage defined in this file is used to generate statistics for
+// bandwidth, latency and other performance metrics for remoting. Usually
+// this data comes in as a stream and fluctuates a lot. They are processed by
+// this class to generate a more stable value by taking average within a
+// window of data points.
+
+// All classes defined are thread-safe.
+
+#ifndef REMOTING_BASE_RUNNING_AVERAGE_H_
+#define REMOTING_BASE_RUNNING_AVERAGE_H_
+
+#include <deque>
+
+#include "base/basictypes.h"
+#include "base/synchronization/lock.h"
+#include "base/time.h"
+
+namespace remoting {
+
+class RunningAverage {
+ public:
+ // Construct a running average counter for a specific window size. The
+ // |windows_size| most recent values are kept and the average is reported.
+ RunningAverage(int window_size);
+
+ virtual ~RunningAverage();
+
+ // Record the provided data point.
+ void Record(int64 value);
+
+ // Return the average of data points in the last window.
+ double Average();
+
+ private:
+ // Size of the window. This is of type size_t to avoid casting when comparing
+ // with the size of |data_points_|.
+ size_t window_size_;
+
+ // Protects |data_points_| and |sum_|.
+ base::Lock lock_;
+
+ // Keep the values of all the data points.
+ std::deque<int64> data_points_;
+
+ // Sum of values in |data_points_|.
+ int64 sum_;
+
+ DISALLOW_COPY_AND_ASSIGN(RunningAverage);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_BASE_RUNNING_AVERAGE_H_