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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: remoting/base/running_samples.cc
diff --git a/remoting/base/running_average.cc b/remoting/base/running_samples.cc
similarity index 60%
rename from remoting/base/running_average.cc
rename to remoting/base/running_samples.cc
index 5e24c0de3a95672c1e4f8d4c5b67cf5b11db81ba..8f6a0d1497042d652cbe3aa261ddfac67b0f1a44 100644
--- a/remoting/base/running_average.cc
+++ b/remoting/base/running_samples.cc
@@ -2,21 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "remoting/base/running_average.h"
+#include "remoting/base/running_samples.h"
+
+#include <algorithm>
#include "base/logging.h"
namespace remoting {
-RunningAverage::RunningAverage(int window_size)
+RunningSamples::RunningSamples(int window_size)
: window_size_(window_size),
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:)
DCHECK_GT(window_size, 0);
}
-RunningAverage::~RunningAverage() {}
+RunningSamples::~RunningSamples() {}
-void RunningAverage::Record(int64_t value) {
+void RunningSamples::Record(int64_t value) {
DCHECK(thread_checker_.CalledOnValidThread());
data_points_.push_back(value);
@@ -28,7 +30,7 @@ void RunningAverage::Record(int64_t value) {
}
}
-double RunningAverage::Average() {
+double RunningSamples::Average() {
DCHECK(thread_checker_.CalledOnValidThread());
if (data_points_.empty())
@@ -36,4 +38,14 @@ double RunningAverage::Average() {
return static_cast<double>(sum_) / data_points_.size();
}
+int64_t RunningSamples::Max() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ if (data_points_.empty())
+ return 0;
+
+ // O(n*w), may be improved.
+ return *std::max_element(data_points_.begin(), data_points_.end());
+}
+
} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698