| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/congestion_control/rtt_stats.h" | 5 #include "net/quic/congestion_control/rtt_stats.h" |
| 6 | 6 |
| 7 #include <cstdlib> // std::abs | 7 #include <cstdlib> // std::abs |
| 8 | 8 |
| 9 using std::max; | 9 using std::max; |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 RttStats::RttStats() | 26 RttStats::RttStats() |
| 27 : latest_rtt_(QuicTime::Delta::Zero()), | 27 : latest_rtt_(QuicTime::Delta::Zero()), |
| 28 min_rtt_(QuicTime::Delta::Zero()), | 28 min_rtt_(QuicTime::Delta::Zero()), |
| 29 smoothed_rtt_(QuicTime::Delta::Zero()), | 29 smoothed_rtt_(QuicTime::Delta::Zero()), |
| 30 mean_deviation_(QuicTime::Delta::Zero()), | 30 mean_deviation_(QuicTime::Delta::Zero()), |
| 31 initial_rtt_us_(kInitialRttMs * kNumMicrosPerMilli), | 31 initial_rtt_us_(kInitialRttMs * kNumMicrosPerMilli), |
| 32 num_min_rtt_samples_remaining_(0), | 32 num_min_rtt_samples_remaining_(0), |
| 33 recent_min_rtt_window_(QuicTime::Delta::Infinite()) {} | 33 recent_min_rtt_window_(QuicTime::Delta::Infinite()) {} |
| 34 | 34 |
| 35 void RttStats::SampleNewRecentMinRtt(uint32 num_samples) { | 35 void RttStats::SampleNewRecentMinRtt(uint32_t num_samples) { |
| 36 num_min_rtt_samples_remaining_ = num_samples; | 36 num_min_rtt_samples_remaining_ = num_samples; |
| 37 new_min_rtt_ = RttSample(); | 37 new_min_rtt_ = RttSample(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void RttStats::ExpireSmoothedMetrics() { | 40 void RttStats::ExpireSmoothedMetrics() { |
| 41 mean_deviation_ = | 41 mean_deviation_ = |
| 42 max(mean_deviation_, | 42 max(mean_deviation_, |
| 43 QuicTime::Delta::FromMicroseconds( | 43 QuicTime::Delta::FromMicroseconds( |
| 44 std::abs(smoothed_rtt_.Subtract(latest_rtt_).ToMicroseconds()))); | 44 std::abs(smoothed_rtt_.Subtract(latest_rtt_).ToMicroseconds()))); |
| 45 smoothed_rtt_ = max(smoothed_rtt_, latest_rtt_); | 45 smoothed_rtt_ = max(smoothed_rtt_, latest_rtt_); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 72 if (rtt_sample > ack_delay) { | 72 if (rtt_sample > ack_delay) { |
| 73 rtt_sample = rtt_sample.Subtract(ack_delay); | 73 rtt_sample = rtt_sample.Subtract(ack_delay); |
| 74 } | 74 } |
| 75 latest_rtt_ = rtt_sample; | 75 latest_rtt_ = rtt_sample; |
| 76 // First time call. | 76 // First time call. |
| 77 if (smoothed_rtt_.IsZero()) { | 77 if (smoothed_rtt_.IsZero()) { |
| 78 smoothed_rtt_ = rtt_sample; | 78 smoothed_rtt_ = rtt_sample; |
| 79 mean_deviation_ = | 79 mean_deviation_ = |
| 80 QuicTime::Delta::FromMicroseconds(rtt_sample.ToMicroseconds() / 2); | 80 QuicTime::Delta::FromMicroseconds(rtt_sample.ToMicroseconds() / 2); |
| 81 } else { | 81 } else { |
| 82 mean_deviation_ = QuicTime::Delta::FromMicroseconds(static_cast<int64>( | 82 mean_deviation_ = QuicTime::Delta::FromMicroseconds(static_cast<int64_t>( |
| 83 kOneMinusBeta * mean_deviation_.ToMicroseconds() + | 83 kOneMinusBeta * mean_deviation_.ToMicroseconds() + |
| 84 kBeta * std::abs(smoothed_rtt_.Subtract(rtt_sample).ToMicroseconds()))); | 84 kBeta * std::abs(smoothed_rtt_.Subtract(rtt_sample).ToMicroseconds()))); |
| 85 smoothed_rtt_ = | 85 smoothed_rtt_ = |
| 86 smoothed_rtt_.Multiply(kOneMinusAlpha).Add(rtt_sample.Multiply(kAlpha)); | 86 smoothed_rtt_.Multiply(kOneMinusAlpha).Add(rtt_sample.Multiply(kAlpha)); |
| 87 DVLOG(1) << " smoothed_rtt(us):" << smoothed_rtt_.ToMicroseconds() | 87 DVLOG(1) << " smoothed_rtt(us):" << smoothed_rtt_.ToMicroseconds() |
| 88 << " mean_deviation(us):" << mean_deviation_.ToMicroseconds(); | 88 << " mean_deviation(us):" << mean_deviation_.ToMicroseconds(); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 void RttStats::UpdateRecentMinRtt(QuicTime::Delta rtt_sample, QuicTime now) { | 92 void RttStats::UpdateRecentMinRtt(QuicTime::Delta rtt_sample, QuicTime now) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 min_rtt_ = QuicTime::Delta::Zero(); | 132 min_rtt_ = QuicTime::Delta::Zero(); |
| 133 smoothed_rtt_ = QuicTime::Delta::Zero(); | 133 smoothed_rtt_ = QuicTime::Delta::Zero(); |
| 134 mean_deviation_ = QuicTime::Delta::Zero(); | 134 mean_deviation_ = QuicTime::Delta::Zero(); |
| 135 initial_rtt_us_ = kInitialRttMs * kNumMicrosPerMilli; | 135 initial_rtt_us_ = kInitialRttMs * kNumMicrosPerMilli; |
| 136 num_min_rtt_samples_remaining_ = 0; | 136 num_min_rtt_samples_remaining_ = 0; |
| 137 recent_min_rtt_window_ = QuicTime::Delta::Infinite(); | 137 recent_min_rtt_window_ = QuicTime::Delta::Infinite(); |
| 138 recent_min_rtt_ = half_window_rtt_ = quarter_window_rtt_ = RttSample(); | 138 recent_min_rtt_ = half_window_rtt_ = quarter_window_rtt_ = RttSample(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 } // namespace net | 141 } // namespace net |
| OLD | NEW |