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

Side by Side Diff: net/quic/quic_sustained_bandwidth_recorder.cc

Issue 477053002: Add a QuicSustainedBandwidthEstimator class. Not yet used. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@re-add_DCHECK_to_ensure_packets_73128051
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
OLDNEW
(Empty)
1 // Copyright (c) 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 "net/quic/quic_sustained_bandwidth_recorder.h"
6
7 #include "base/logging.h"
8 #include "net/quic/quic_bandwidth.h"
9 #include "net/quic/quic_time.h"
10
11 namespace net {
12
13 QuicSustainedBandwidthRecorder::QuicSustainedBandwidthRecorder()
14 : has_estimate_(false),
15 is_recording_(false),
16 bandwidth_estimate_(QuicBandwidth::Zero()),
17 max_bandwidth_estimate_(QuicBandwidth::Zero()),
18 max_bandwidth_timestamp_(0),
19 start_time_(QuicTime::Zero()) {}
20
21 void QuicSustainedBandwidthRecorder::RecordEstimate(bool is_reliable_estimate,
22 QuicBandwidth bandwidth,
23 QuicTime estimate_time,
24 QuicWallTime wall_time,
25 QuicTime::Delta srtt) {
26 if (!is_reliable_estimate) {
27 is_recording_ = false;
28 DVLOG(1) << "Stopped recording due to unreliable estimate at: "
29 << estimate_time.ToDebuggingValue();
30 return;
31 }
32
33 if (!is_recording_) {
34 // This is the first estimate of a new recording period.
35 start_time_ = estimate_time;
36 is_recording_ = true;
37 DVLOG(1) << "Started recording at: " << start_time_.ToDebuggingValue();
38 return;
39 }
40
41 // If we have been recording for at least 3 * srtt, then record the latest
42 // bandwidth estimate as a valid sustained bandwidth estimate.
43 if (estimate_time.Subtract(start_time_) >= srtt.Multiply(3)) {
44 has_estimate_ = true;
45 bandwidth_estimate_ = bandwidth;
46 DVLOG(1) << "New sustained bandwidth estimate (KBytes/s): "
47 << bandwidth_estimate_.ToKBytesPerSecond();
48 }
49
50 // Check for an increase in max bandwidth.
51 if (bandwidth > max_bandwidth_estimate_) {
52 max_bandwidth_estimate_ = bandwidth;
53 max_bandwidth_timestamp_ = wall_time.ToUNIXSeconds();
54 DVLOG(1) << "New max bandwidth estimate (KBytes/s): "
55 << max_bandwidth_estimate_.ToKBytesPerSecond();
56 }
57 }
58
59 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698