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() {}
19 void RunningAverage::Record(int64_t value
) {
20 DCHECK(thread_checker_
.CalledOnValidThread());
22 data_points_
.push_back(value
);
25 if (data_points_
.size() > window_size_
) {
26 sum_
-= data_points_
[0];
27 data_points_
.pop_front();
31 double RunningAverage::Average() {
32 DCHECK(thread_checker_
.CalledOnValidThread());
34 if (data_points_
.empty())
36 return static_cast<double>(sum_
) / data_points_
.size();
39 } // namespace remoting