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.
5 #include "remoting/base/running_average.h"
7 #include "base/logging.h"
11 RunningAverage::RunningAverage(int window_size
)
12 : window_size_(window_size
),
14 DCHECK_GT(window_size
, 0);
17 RunningAverage::~RunningAverage() {
20 void RunningAverage::Record(int64 value
) {
21 base::AutoLock
auto_lock(lock_
);
23 data_points_
.push_back(value
);
26 if (data_points_
.size() > window_size_
) {
27 sum_
-= data_points_
[0];
28 data_points_
.pop_front();
32 double RunningAverage::Average() {
33 base::AutoLock
auto_lock(lock_
);
35 if (data_points_
.empty())
37 return static_cast<double>(sum_
) / data_points_
.size();
40 } // namespace remoting