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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: remoting/base/running_max.cc
diff --git a/remoting/base/running_average.cc b/remoting/base/running_max.cc
similarity index 57%
copy from remoting/base/running_average.cc
copy to remoting/base/running_max.cc
index 5e24c0de3a95672c1e4f8d4c5b67cf5b11db81ba..b882ce66cf6d0b6e950c2d5cffe928bd0f777123 100644
--- a/remoting/base/running_average.cc
+++ b/remoting/base/running_max.cc
@@ -2,38 +2,37 @@
// 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_max.h"
Yuwei 2016/03/17 18:50:21 running_max.h and running_max.cc are copied and mo
#include "base/logging.h"
namespace remoting {
-RunningAverage::RunningAverage(int window_size)
- : window_size_(window_size),
- sum_(0) {
+RunningMax::RunningMax(int window_size)
+ : window_size_(window_size) {
DCHECK_GT(window_size, 0);
}
-RunningAverage::~RunningAverage() {}
+RunningMax::~RunningMax() {}
-void RunningAverage::Record(int64_t value) {
+void RunningMax::Record(int64_t value) {
DCHECK(thread_checker_.CalledOnValidThread());
data_points_.push_back(value);
- sum_ += value;
if (data_points_.size() > window_size_) {
- sum_ -= data_points_[0];
data_points_.pop_front();
}
}
-double RunningAverage::Average() {
+int64_t RunningMax::Max() {
DCHECK(thread_checker_.CalledOnValidThread());
if (data_points_.empty())
return 0;
- return static_cast<double>(sum_) / data_points_.size();
+
+ // O(n*w), may be improved.
+ return *std::max_element(data_points_.begin(), data_points_.end());
}
-} // namespace remoting
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698