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

Unified Diff: remoting/test/leaky_bucket.cc

Issue 427613005: Implement network performance simulation for remoting perf tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
« no previous file with comments | « remoting/test/leaky_bucket.h ('k') | remoting/test/protocol_perftest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/test/leaky_bucket.cc
diff --git a/remoting/test/leaky_bucket.cc b/remoting/test/leaky_bucket.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ee8a62b06de136d82c2a040c5abb5706f2d9f06e
--- /dev/null
+++ b/remoting/test/leaky_bucket.cc
@@ -0,0 +1,41 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/test/leaky_bucket.h"
+
+#include "base/logging.h"
+
+namespace remoting {
+
+LeakyBucket::LeakyBucket(double depth, double rate)
+ : depth_(depth),
+ rate_(rate),
+ level_(0.0),
+ last_update_(base::TimeTicks::Now()) {
+}
+
+LeakyBucket::~LeakyBucket() {
+}
+
+base::TimeDelta LeakyBucket::AddPacket(int size) {
+ UpdateLevel();
+
+ double new_level = level_ + size;
+ if (new_level > depth_)
+ return base::TimeDelta::Max();
+
+ base::TimeDelta result = base::TimeDelta::FromSecondsD(level_ / rate_);
+ level_ = new_level;
+ return result;
+}
+
+void LeakyBucket::UpdateLevel() {
+ base::TimeTicks now = base::TimeTicks::Now();
+ level_ -= rate_ * (now - last_update_).InSecondsF();
+ if (level_ < 0.0)
+ level_ = 0.0;
+ last_update_ = now;
+}
+
+} // namespace remoting
« no previous file with comments | « remoting/test/leaky_bucket.h ('k') | remoting/test/protocol_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698