diff options
author | hclam@google.com <hclam@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-05 18:03:31 +0000 |
---|---|---|
committer | hclam@google.com <hclam@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-05 18:03:31 +0000 |
commit | 778d599df45c985286cd70898187ecf7a6284eeb (patch) | |
tree | e4518f5d17d84f6613e0507c1dddc05ab1ddf23b /remoting/base/running_average.cc | |
parent | 6ca1745021ac1b7822eb23a58c3985b2a91b293d (diff) | |
download | chromium_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.cc')
-rw-r--r-- | remoting/base/running_average.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/remoting/base/running_average.cc b/remoting/base/running_average.cc new file mode 100644 index 0000000..4daa650 --- /dev/null +++ b/remoting/base/running_average.cc @@ -0,0 +1,39 @@ +// 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. + +#include "base/logging.h" +#include "remoting/base/running_average.h" + +namespace remoting { + +RunningAverage::RunningAverage(int window_size) + : window_size_(window_size), + sum_(0) { + CHECK(window_size_); +} + +RunningAverage::~RunningAverage() { +} + +void RunningAverage::Record(int64 value) { + base::AutoLock auto_lock(lock_); + + data_points_.push_back(value); + sum_ += value; + + if (data_points_.size() > window_size_) { + sum_ -= data_points_[0]; + data_points_.pop_front(); + } +} + +double RunningAverage::Average() { + base::AutoLock auto_lock(lock_); + + if (data_points_.empty()) + return 0; + return static_cast<double>(sum_) / data_points_.size(); +} + +} // namespace remoting |