OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/nqe/network_quality_estimator.h" | 5 #include "net/nqe/network_quality_estimator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <utility> | 10 #include <utility> |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 const int32_t kBitsPerMetric = 7; | 133 const int32_t kBitsPerMetric = 7; |
134 | 134 |
135 static_assert(32 >= kBitsPerMetric * 4, | 135 static_assert(32 >= kBitsPerMetric * 4, |
136 "Four metrics would not fit in a 32-bit int"); | 136 "Four metrics would not fit in a 32-bit int"); |
137 | 137 |
138 // Trims the |metric| by removing the last kTrimBits, and then rounding down | 138 // Trims the |metric| by removing the last kTrimBits, and then rounding down |
139 // the |metric| such that the |metric| fits in kBitsPerMetric. | 139 // the |metric| such that the |metric| fits in kBitsPerMetric. |
140 int32_t FitInKBitsPerMetricBits(int32_t metric) { | 140 int32_t FitInKBitsPerMetricBits(int32_t metric) { |
141 // Remove the last kTrimBits. This will allow the metric to fit within | 141 // Remove the last kTrimBits. This will allow the metric to fit within |
142 // kBitsPerMetric while losing only the least significant bits. | 142 // kBitsPerMetric while losing only the least significant bits. |
| 143 DCHECK_LE(0, metric); |
143 metric = metric >> kTrimBits; | 144 metric = metric >> kTrimBits; |
144 | 145 |
145 // kLargestValuePossible is the largest value that can be recorded using | 146 // kLargestValuePossible is the largest value that can be recorded using |
146 // kBitsPerMetric. | 147 // kBitsPerMetric. |
147 static const int32_t kLargestValuePossible = (1 << kBitsPerMetric) - 1; | 148 static const int32_t kLargestValuePossible = (1 << kBitsPerMetric) - 1; |
148 if (metric > kLargestValuePossible) { | 149 if (metric > kLargestValuePossible) { |
149 // Fit |metric| in kBitsPerMetric by clamping it down. | 150 // Fit |metric| in kBitsPerMetric by clamping it down. |
150 metric = kLargestValuePossible; | 151 metric = kLargestValuePossible; |
151 } | 152 } |
152 DCHECK_EQ(0, metric >> kBitsPerMetric); | 153 DCHECK_EQ(0, metric >> kBitsPerMetric) << metric; |
153 return metric; | 154 return metric; |
154 } | 155 } |
155 | 156 |
156 void RecordRTTAccuracy(const char* prefix, | 157 void RecordRTTAccuracy(const char* prefix, |
157 int32_t metric, | 158 int32_t metric, |
158 base::TimeDelta measuring_duration, | 159 base::TimeDelta measuring_duration, |
159 base::TimeDelta observed_rtt) { | 160 base::TimeDelta observed_rtt) { |
160 const std::string histogram_name = | 161 const std::string histogram_name = |
161 base::StringPrintf("%s.EstimatedObservedDiff.%s.%d.%s", prefix, | 162 base::StringPrintf("%s.EstimatedObservedDiff.%s.%d.%s", prefix, |
162 metric >= 0 ? "Positive" : "Negative", | 163 metric >= 0 ? "Positive" : "Negative", |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 // Record UMA only for successful requests that have completed. | 600 // Record UMA only for successful requests that have completed. |
600 if (net_error != OK) | 601 if (net_error != OK) |
601 return; | 602 return; |
602 if (!request.response_info().headers.get() || | 603 if (!request.response_info().headers.get() || |
603 request.response_info().headers->response_code() != HTTP_OK) { | 604 request.response_info().headers->response_code() != HTTP_OK) { |
604 return; | 605 return; |
605 } | 606 } |
606 if (load_timing_info.receive_headers_end < last_main_frame_request_) | 607 if (load_timing_info.receive_headers_end < last_main_frame_request_) |
607 return; | 608 return; |
608 | 609 |
609 const base::TimeTicks now = tick_clock_->NowTicks(); | 610 // Use the system clock instead of |tick_clock_| to compare the current |
| 611 // timestamp with the |load_timing_info| timestamp since the latter is set by |
| 612 // the system clock, and may be different from |tick_clock_| in tests. |
| 613 const base::TimeTicks now = base::TimeTicks::Now(); |
610 // Record UMA only for requests that started recently. | 614 // Record UMA only for requests that started recently. |
611 if (now - last_main_frame_request_ > base::TimeDelta::FromSeconds(15)) | 615 if (now - last_main_frame_request_ > base::TimeDelta::FromSeconds(15)) |
612 return; | 616 return; |
613 | 617 |
614 DCHECK_GE(now, load_timing_info.send_start); | 618 DCHECK_GE(now, load_timing_info.send_start); |
615 | 619 |
616 int32_t rtt = 0; | 620 int32_t rtt = 0; |
617 | 621 |
618 if (UseTransportRTT()) { | 622 if (UseTransportRTT()) { |
619 rtt = estimated_quality_at_last_main_frame_.transport_rtt() != | 623 rtt = estimated_quality_at_last_main_frame_.transport_rtt() != |
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1679 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); | 1683 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); |
1680 downstream_throughput_kbps_observations_.AddObservation( | 1684 downstream_throughput_kbps_observations_.AddObservation( |
1681 throughput_observation); | 1685 throughput_observation); |
1682 NotifyObserversOfThroughput(throughput_observation); | 1686 NotifyObserversOfThroughput(throughput_observation); |
1683 } | 1687 } |
1684 | 1688 |
1685 ComputeEffectiveConnectionType(); | 1689 ComputeEffectiveConnectionType(); |
1686 } | 1690 } |
1687 | 1691 |
1688 } // namespace net | 1692 } // namespace net |
OLD | NEW |