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

Side by Side Diff: remoting/base/running_max.cc

Issue 1811833002: Show max latency on client's status bar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/base/running_average.h" 5 #include "remoting/base/running_max.h"
Yuwei 2016/03/17 18:50:21 running_max.h and running_max.cc are copied and mo
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace remoting { 9 namespace remoting {
10 10
11 RunningAverage::RunningAverage(int window_size) 11 RunningMax::RunningMax(int window_size)
12 : window_size_(window_size), 12 : window_size_(window_size) {
13 sum_(0) {
14 DCHECK_GT(window_size, 0); 13 DCHECK_GT(window_size, 0);
15 } 14 }
16 15
17 RunningAverage::~RunningAverage() {} 16 RunningMax::~RunningMax() {}
18 17
19 void RunningAverage::Record(int64_t value) { 18 void RunningMax::Record(int64_t value) {
20 DCHECK(thread_checker_.CalledOnValidThread()); 19 DCHECK(thread_checker_.CalledOnValidThread());
21 20
22 data_points_.push_back(value); 21 data_points_.push_back(value);
23 sum_ += value;
24 22
25 if (data_points_.size() > window_size_) { 23 if (data_points_.size() > window_size_) {
26 sum_ -= data_points_[0];
27 data_points_.pop_front(); 24 data_points_.pop_front();
28 } 25 }
29 } 26 }
30 27
31 double RunningAverage::Average() { 28 int64_t RunningMax::Max() {
32 DCHECK(thread_checker_.CalledOnValidThread()); 29 DCHECK(thread_checker_.CalledOnValidThread());
33 30
34 if (data_points_.empty()) 31 if (data_points_.empty())
35 return 0; 32 return 0;
36 return static_cast<double>(sum_) / data_points_.size(); 33
34 // O(n*w), may be improved.
35 return *std::max_element(data_points_.begin(), data_points_.end());
37 } 36 }
38 37
39 } // namespace remoting 38 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698