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.
5 #include "net/quic/quic_sustained_bandwidth_recorder.h"
7 #include "base/logging.h"
8 #include "net/quic/quic_bandwidth.h"
9 #include "net/quic/quic_time.h"
13 QuicSustainedBandwidthRecorder::QuicSustainedBandwidthRecorder()
14 : has_estimate_(false),
16 bandwidth_estimate_recorded_during_slow_start_(false),
17 bandwidth_estimate_(QuicBandwidth::Zero()),
18 max_bandwidth_estimate_(QuicBandwidth::Zero()),
19 max_bandwidth_timestamp_(0),
20 start_time_(QuicTime::Zero()) {}
22 void QuicSustainedBandwidthRecorder::RecordEstimate(bool in_recovery
,
24 QuicBandwidth bandwidth
,
25 QuicTime estimate_time
,
26 QuicWallTime wall_time
,
27 QuicTime::Delta srtt
) {
29 is_recording_
= false;
30 DVLOG(1) << "Stopped recording at: " << estimate_time
.ToDebuggingValue();
35 // This is the first estimate of a new recording period.
36 start_time_
= estimate_time
;
38 DVLOG(1) << "Started recording at: " << start_time_
.ToDebuggingValue();
42 // If we have been recording for at least 3 * srtt, then record the latest
43 // bandwidth estimate as a valid sustained bandwidth estimate.
44 if (estimate_time
.Subtract(start_time_
) >= srtt
.Multiply(3)) {
46 bandwidth_estimate_recorded_during_slow_start_
= in_slow_start
;
47 bandwidth_estimate_
= bandwidth
;
48 DVLOG(1) << "New sustained bandwidth estimate (KBytes/s): "
49 << bandwidth_estimate_
.ToKBytesPerSecond();
52 // Check for an increase in max bandwidth.
53 if (bandwidth
> max_bandwidth_estimate_
) {
54 max_bandwidth_estimate_
= bandwidth
;
55 max_bandwidth_timestamp_
= wall_time
.ToUNIXSeconds();
56 DVLOG(1) << "New max bandwidth estimate (KBytes/s): "
57 << max_bandwidth_estimate_
.ToKBytesPerSecond();