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

Side by Side Diff: remoting/base/running_samples.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_samples.h"
6
7 #include <algorithm>
6 8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 10
9 namespace remoting { 11 namespace remoting {
10 12
11 RunningAverage::RunningAverage(int window_size) 13 RunningSamples::RunningSamples(int window_size)
12 : window_size_(window_size), 14 : window_size_(window_size),
13 sum_(0) { 15 sum_(0) {
Sergey Ulanov 2016/03/18 19:42:06 while you are here please remove this initializer
Yuwei 2016/03/18 20:05:59 Then how can we construct RunningSamples...?
Sergey Ulanov 2016/03/18 20:17:08 Sorry for not being clear. My comment was only abo
Yuwei 2016/03/18 20:46:47 Got it:)
14 DCHECK_GT(window_size, 0); 16 DCHECK_GT(window_size, 0);
15 } 17 }
16 18
17 RunningAverage::~RunningAverage() {} 19 RunningSamples::~RunningSamples() {}
18 20
19 void RunningAverage::Record(int64_t value) { 21 void RunningSamples::Record(int64_t value) {
20 DCHECK(thread_checker_.CalledOnValidThread()); 22 DCHECK(thread_checker_.CalledOnValidThread());
21 23
22 data_points_.push_back(value); 24 data_points_.push_back(value);
23 sum_ += value; 25 sum_ += value;
24 26
25 if (data_points_.size() > window_size_) { 27 if (data_points_.size() > window_size_) {
26 sum_ -= data_points_[0]; 28 sum_ -= data_points_[0];
27 data_points_.pop_front(); 29 data_points_.pop_front();
28 } 30 }
29 } 31 }
30 32
31 double RunningAverage::Average() { 33 double RunningSamples::Average() {
32 DCHECK(thread_checker_.CalledOnValidThread()); 34 DCHECK(thread_checker_.CalledOnValidThread());
33 35
34 if (data_points_.empty()) 36 if (data_points_.empty())
35 return 0; 37 return 0;
36 return static_cast<double>(sum_) / data_points_.size(); 38 return static_cast<double>(sum_) / data_points_.size();
37 } 39 }
38 40
41 int64_t RunningSamples::Max() {
42 DCHECK(thread_checker_.CalledOnValidThread());
43
44 if (data_points_.empty())
45 return 0;
46
47 // O(n*w), may be improved.
48 return *std::max_element(data_points_.begin(), data_points_.end());
49 }
50
39 } // namespace remoting 51 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698