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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/test/leaky_bucket.h ('k') | remoting/test/protocol_perftest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/test/leaky_bucket.h"
6
7 #include "base/logging.h"
8
9 namespace remoting {
10
11 LeakyBucket::LeakyBucket(double depth, double rate)
12 : depth_(depth),
13 rate_(rate),
14 level_(0.0),
15 last_update_(base::TimeTicks::Now()) {
16 }
17
18 LeakyBucket::~LeakyBucket() {
19 }
20
21 base::TimeDelta LeakyBucket::AddPacket(int size) {
22 UpdateLevel();
23
24 double new_level = level_ + size;
25 if (new_level > depth_)
26 return base::TimeDelta::Max();
27
28 base::TimeDelta result = base::TimeDelta::FromSecondsD(level_ / rate_);
29 level_ = new_level;
30 return result;
31 }
32
33 void LeakyBucket::UpdateLevel() {
34 base::TimeTicks now = base::TimeTicks::Now();
35 level_ -= rate_ * (now - last_update_).InSecondsF();
36 if (level_ < 0.0)
37 level_ = 0.0;
38 last_update_ = now;
39 }
40
41 } // namespace remoting
OLDNEW
« 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