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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | remoting/base/running_average.cc » ('j') | remoting/base/running_average.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/base/running_average.h
diff --git a/remoting/base/running_average.h b/remoting/base/running_average.h
new file mode 100644
index 0000000000000000000000000000000000000000..dd40e969422515e042dfc0c79504bdc9620936e5
--- /dev/null
+++ b/remoting/base/running_average.h
@@ -0,0 +1,90 @@
+// 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
+// these data come 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.
+
+// TimedRunningAverage keeps track of running average in a timed faction.
simonmorris 2011/03/25 09:24:59 "Fashion" instead of "faction"?
+// It essentially reports the rate of RunningAverage divided by the duration
+// of the window.
+
+// 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 most
simonmorris 2011/03/25 09:24:59 "|windows_size| most"
+ // |windows_size| 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.
+ int64 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);
+};
+
+class TimedRunningAverage {
+ public:
+ // Construct with a window size.
+ TimedRunningAverage(int window_size);
simonmorris 2011/03/25 09:24:59 Is it better for the window to be a length of time
+
+ virtual ~TimedRunningAverage();
+
+ // Record the value and the current time.
+ void Record(int64 value);
+
+ // Report the rate per second recorded.
+ double Rate();
+
+ private:
+ // Protects |time_|.
+ base::Lock lock_;
+
+ // Timestamps when Record() is called.
+ std::deque<base::Time> time_;
+
+ // Counter to measure the running average.
+ RunningAverage counter_;
+
+ // Window size for the rate.
+ size_t window_size_;
+
+ DISALLOW_COPY_AND_ASSIGN(TimedRunningAverage);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_BASE_RUNNING_AVERAGE_H_
« no previous file with comments | « no previous file | remoting/base/running_average.cc » ('j') | remoting/base/running_average.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698