Chromium Code Reviews| 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 EffectiveConnectionTypeAlgorithm:: | 246 EffectiveConnectionTypeAlgorithm:: |
| 247 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, | 247 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, |
| 248 {"TransportRTTOrDownstreamThroughput", | 248 {"TransportRTTOrDownstreamThroughput", |
| 249 EffectiveConnectionTypeAlgorithm:: | 249 EffectiveConnectionTypeAlgorithm:: |
| 250 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}), | 250 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}), |
| 251 params_(variation_params), | 251 params_(variation_params), |
| 252 use_localhost_requests_(use_local_host_requests_for_tests), | 252 use_localhost_requests_(use_local_host_requests_for_tests), |
| 253 use_small_responses_(use_smaller_responses_for_tests), | 253 use_small_responses_(use_smaller_responses_for_tests), |
| 254 disable_offline_check_(false), | 254 disable_offline_check_(false), |
| 255 add_default_platform_observations_(add_default_platform_observations), | 255 add_default_platform_observations_(add_default_platform_observations), |
| 256 weight_multiplier_per_second_(params_.GetWeightMultiplierPerSecond()), | |
| 257 weight_multiplier_per_dbm_(params_.GetWeightMultiplierPerDbm()), | |
| 258 effective_connection_type_algorithm_( | 256 effective_connection_type_algorithm_( |
| 259 algorithm_name_to_enum_.find( | 257 algorithm_name_to_enum_.find( |
| 260 params_.GetEffectiveConnectionTypeAlgorithm()) == | 258 params_.GetEffectiveConnectionTypeAlgorithm()) == |
| 261 algorithm_name_to_enum_.end() | 259 algorithm_name_to_enum_.end() |
| 262 ? kDefaultEffectiveConnectionTypeAlgorithm | 260 ? kDefaultEffectiveConnectionTypeAlgorithm |
| 263 : algorithm_name_to_enum_ | 261 : algorithm_name_to_enum_ |
| 264 .find(params_.GetEffectiveConnectionTypeAlgorithm()) | 262 .find(params_.GetEffectiveConnectionTypeAlgorithm()) |
| 265 ->second), | 263 ->second), |
| 266 tick_clock_(new base::DefaultTickClock()), | 264 tick_clock_(new base::DefaultTickClock()), |
| 267 last_connection_change_(tick_clock_->NowTicks()), | 265 last_connection_change_(tick_clock_->NowTicks()), |
| 268 current_network_id_(nqe::internal::NetworkID( | 266 current_network_id_(nqe::internal::NetworkID( |
| 269 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, | 267 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, |
| 270 std::string())), | 268 std::string())), |
| 271 downstream_throughput_kbps_observations_(weight_multiplier_per_second_, | 269 downstream_throughput_kbps_observations_( |
| 272 weight_multiplier_per_dbm_), | 270 params_.weight_multiplier_per_second(), |
| 273 rtt_observations_(weight_multiplier_per_second_, | 271 params_.weight_multiplier_per_dbm()), |
| 274 weight_multiplier_per_dbm_), | 272 rtt_observations_(params_.weight_multiplier_per_second(), |
| 273 params_.weight_multiplier_per_dbm()), | |
| 275 effective_connection_type_at_last_main_frame_( | 274 effective_connection_type_at_last_main_frame_( |
| 276 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), | 275 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), |
| 277 external_estimate_provider_(std::move(external_estimates_provider)), | 276 external_estimate_provider_(std::move(external_estimates_provider)), |
| 278 effective_connection_type_recomputation_interval_( | 277 effective_connection_type_recomputation_interval_( |
| 279 base::TimeDelta::FromSeconds(10)), | 278 base::TimeDelta::FromSeconds(10)), |
| 280 rtt_observations_size_at_last_ect_computation_(0), | 279 rtt_observations_size_at_last_ect_computation_(0), |
| 281 throughput_observations_size_at_last_ect_computation_(0), | 280 throughput_observations_size_at_last_ect_computation_(0), |
| 282 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), | 281 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), |
| 283 signal_strength_dbm_(INT32_MIN), | 282 signal_strength_dbm_(INT32_MIN), |
| 284 min_signal_strength_since_connection_change_(INT32_MAX), | 283 min_signal_strength_since_connection_change_(INT32_MAX), |
| 285 max_signal_strength_since_connection_change_(INT32_MIN), | 284 max_signal_strength_since_connection_change_(INT32_MIN), |
| 286 correlation_uma_logging_probability_( | |
| 287 params_.correlation_uma_logging_probability()), | |
| 288 forced_effective_connection_type_set_( | |
| 289 params_.forced_effective_connection_type_set()), | |
| 290 forced_effective_connection_type_( | |
| 291 params_.forced_effective_connection_type()), | |
| 292 persistent_cache_reading_enabled_( | 285 persistent_cache_reading_enabled_( |
| 293 params_.persistent_cache_reading_enabled()), | 286 params_.persistent_cache_reading_enabled()), |
| 294 event_creator_(net_log), | 287 event_creator_(net_log), |
| 295 disallowed_observation_sources_for_http_( | 288 disallowed_observation_sources_for_http_( |
| 296 {NETWORK_QUALITY_OBSERVATION_SOURCE_TCP, | 289 {NETWORK_QUALITY_OBSERVATION_SOURCE_TCP, |
| 297 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC, | 290 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC, |
| 298 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE, | 291 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE, |
| 299 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM}), | 292 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM}), |
| 300 disallowed_observation_sources_for_transport_( | 293 disallowed_observation_sources_for_transport_( |
| 301 {NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP, | 294 {NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 329 AddDefaultEstimates(); | 322 AddDefaultEstimates(); |
| 330 | 323 |
| 331 throughput_analyzer_.reset(new nqe::internal::ThroughputAnalyzer( | 324 throughput_analyzer_.reset(new nqe::internal::ThroughputAnalyzer( |
| 332 base::ThreadTaskRunnerHandle::Get(), | 325 base::ThreadTaskRunnerHandle::Get(), |
| 333 base::Bind(&NetworkQualityEstimator::OnNewThroughputObservationAvailable, | 326 base::Bind(&NetworkQualityEstimator::OnNewThroughputObservationAvailable, |
| 334 base::Unretained(this)), | 327 base::Unretained(this)), |
| 335 use_localhost_requests_, use_smaller_responses_for_tests)); | 328 use_localhost_requests_, use_smaller_responses_for_tests)); |
| 336 | 329 |
| 337 watcher_factory_.reset(new nqe::internal::SocketWatcherFactory( | 330 watcher_factory_.reset(new nqe::internal::SocketWatcherFactory( |
| 338 base::ThreadTaskRunnerHandle::Get(), | 331 base::ThreadTaskRunnerHandle::Get(), |
| 339 params_.GetMinSocketWatcherNotificationInterval(), | 332 params_.min_socket_watcher_notification_interval(), |
| 340 base::Bind(&NetworkQualityEstimator::OnUpdatedRTTAvailable, | 333 base::Bind(&NetworkQualityEstimator::OnUpdatedRTTAvailable, |
| 341 base::Unretained(this)), | 334 base::Unretained(this)), |
| 342 tick_clock_.get())); | 335 tick_clock_.get())); |
| 343 | 336 |
| 344 // Record accuracy after a 15 second interval. The values used here must | 337 // Record accuracy after a 15 second interval. The values used here must |
| 345 // remain in sync with the suffixes specified in | 338 // remain in sync with the suffixes specified in |
| 346 // tools/metrics/histograms/histograms.xml. | 339 // tools/metrics/histograms/histograms.xml. |
| 347 accuracy_recording_intervals_.push_back(base::TimeDelta::FromSeconds(15)); | 340 accuracy_recording_intervals_.push_back(base::TimeDelta::FromSeconds(15)); |
| 348 | 341 |
| 349 for (int i = 0; i < STATISTIC_LAST; ++i) | 342 for (int i = 0; i < STATISTIC_LAST; ++i) |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 | 615 |
| 623 throughput_analyzer_->NotifyRequestCompleted(request); | 616 throughput_analyzer_->NotifyRequestCompleted(request); |
| 624 RecordCorrelationMetric(request, net_error); | 617 RecordCorrelationMetric(request, net_error); |
| 625 } | 618 } |
| 626 | 619 |
| 627 void NetworkQualityEstimator::RecordCorrelationMetric(const URLRequest& request, | 620 void NetworkQualityEstimator::RecordCorrelationMetric(const URLRequest& request, |
| 628 int net_error) const { | 621 int net_error) const { |
| 629 DCHECK(thread_checker_.CalledOnValidThread()); | 622 DCHECK(thread_checker_.CalledOnValidThread()); |
| 630 | 623 |
| 631 // The histogram is recorded with probability | 624 // The histogram is recorded with probability |
| 632 // |correlation_uma_logging_probability_| to reduce overhead involved with | 625 // |params_.correlation_uma_logging_probability()| to reduce overhead involved |
|
RyanSturm
2017/05/03 17:41:02
Just remove this reference to the logging probabil
tbansal1
2017/05/03 23:17:25
Done.
| |
| 633 // sparse histograms. Also, recording the correlation on each request is | 626 // with sparse histograms. Also, recording the correlation on each request is |
| 634 // unnecessary. | 627 // unnecessary. |
| 635 if (RandDouble() >= correlation_uma_logging_probability_) | 628 if (RandDouble() >= params_.correlation_uma_logging_probability()) |
| 636 return; | 629 return; |
| 637 | 630 |
| 638 if (request.response_info().was_cached || | 631 if (request.response_info().was_cached || |
| 639 !request.response_info().network_accessed) { | 632 !request.response_info().network_accessed) { |
| 640 return; | 633 return; |
| 641 } | 634 } |
| 642 | 635 |
| 643 LoadTimingInfo load_timing_info; | 636 LoadTimingInfo load_timing_info; |
| 644 request.GetLoadTimingInfo(&load_timing_info); | 637 request.GetLoadTimingInfo(&load_timing_info); |
| 645 // If the load timing info is unavailable, it probably means that the request | 638 // If the load timing info is unavailable, it probably means that the request |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 844 last_effective_connection_type_computation_, | 837 last_effective_connection_type_computation_, |
| 845 network_quality_, effective_connection_type_)); | 838 network_quality_, effective_connection_type_)); |
| 846 | 839 |
| 847 // Clear the local state. | 840 // Clear the local state. |
| 848 last_connection_change_ = tick_clock_->NowTicks(); | 841 last_connection_change_ = tick_clock_->NowTicks(); |
| 849 peak_network_quality_ = nqe::internal::NetworkQuality(); | 842 peak_network_quality_ = nqe::internal::NetworkQuality(); |
| 850 downstream_throughput_kbps_observations_.Clear(); | 843 downstream_throughput_kbps_observations_.Clear(); |
| 851 rtt_observations_.Clear(); | 844 rtt_observations_.Clear(); |
| 852 | 845 |
| 853 #if defined(OS_ANDROID) | 846 #if defined(OS_ANDROID) |
| 854 if (weight_multiplier_per_dbm_ < 1.0 && | 847 if (params_.weight_multiplier_per_dbm() < 1.0 && |
| 855 NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) { | 848 NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) { |
| 856 UMA_HISTOGRAM_BOOLEAN( | 849 UMA_HISTOGRAM_BOOLEAN( |
| 857 "NQE.CellularSignalStrengthAvailable", | 850 "NQE.CellularSignalStrengthAvailable", |
| 858 min_signal_strength_since_connection_change_ != INT32_MAX && | 851 min_signal_strength_since_connection_change_ != INT32_MAX && |
| 859 max_signal_strength_since_connection_change_ != INT32_MIN); | 852 max_signal_strength_since_connection_change_ != INT32_MIN); |
| 860 | 853 |
| 861 if (min_signal_strength_since_connection_change_ != INT32_MAX && | 854 if (min_signal_strength_since_connection_change_ != INT32_MAX && |
| 862 max_signal_strength_since_connection_change_ != INT32_MIN) { | 855 max_signal_strength_since_connection_change_ != INT32_MIN) { |
| 863 UMA_HISTOGRAM_COUNTS_100( | 856 UMA_HISTOGRAM_COUNTS_100( |
| 864 "NQE.CellularSignalStrengthDifference", | 857 "NQE.CellularSignalStrengthDifference", |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET && | 899 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET && |
| 907 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) { | 900 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) { |
| 908 RecordExternalEstimateProviderMetrics( | 901 RecordExternalEstimateProviderMetrics( |
| 909 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED); | 902 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED); |
| 910 external_estimate_provider_->Update(); | 903 external_estimate_provider_->Update(); |
| 911 } | 904 } |
| 912 } | 905 } |
| 913 | 906 |
| 914 void NetworkQualityEstimator::UpdateSignalStrength() { | 907 void NetworkQualityEstimator::UpdateSignalStrength() { |
| 915 #if defined(OS_ANDROID) | 908 #if defined(OS_ANDROID) |
| 916 if (weight_multiplier_per_dbm_ >= 1.0 || | 909 if (params_.weight_multiplier_per_dbm() >= 1.0 || |
| 917 !NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type) || | 910 !NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type) || |
| 918 !android::cellular_signal_strength::GetSignalStrengthDbm( | 911 !android::cellular_signal_strength::GetSignalStrengthDbm( |
| 919 &signal_strength_dbm_)) { | 912 &signal_strength_dbm_)) { |
| 920 signal_strength_dbm_ = INT32_MIN; | 913 signal_strength_dbm_ = INT32_MIN; |
| 921 } | 914 } |
| 922 min_signal_strength_since_connection_change_ = std::min( | 915 min_signal_strength_since_connection_change_ = std::min( |
| 923 min_signal_strength_since_connection_change_, signal_strength_dbm_); | 916 min_signal_strength_since_connection_change_, signal_strength_dbm_); |
| 924 max_signal_strength_since_connection_change_ = std::max( | 917 max_signal_strength_since_connection_change_ = std::max( |
| 925 max_signal_strength_since_connection_change_, signal_strength_dbm_); | 918 max_signal_strength_since_connection_change_, signal_strength_dbm_); |
| 926 #endif // OS_ANDROID | 919 #endif // OS_ANDROID |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1202 NetworkQualityEstimator::MetricUsage downstream_throughput_kbps_metric, | 1195 NetworkQualityEstimator::MetricUsage downstream_throughput_kbps_metric, |
| 1203 base::TimeDelta* http_rtt, | 1196 base::TimeDelta* http_rtt, |
| 1204 base::TimeDelta* transport_rtt, | 1197 base::TimeDelta* transport_rtt, |
| 1205 int32_t* downstream_throughput_kbps) const { | 1198 int32_t* downstream_throughput_kbps) const { |
| 1206 DCHECK(thread_checker_.CalledOnValidThread()); | 1199 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1207 | 1200 |
| 1208 *http_rtt = nqe::internal::InvalidRTT(); | 1201 *http_rtt = nqe::internal::InvalidRTT(); |
| 1209 *transport_rtt = nqe::internal::InvalidRTT(); | 1202 *transport_rtt = nqe::internal::InvalidRTT(); |
| 1210 *downstream_throughput_kbps = nqe::internal::kInvalidThroughput; | 1203 *downstream_throughput_kbps = nqe::internal::kInvalidThroughput; |
| 1211 | 1204 |
| 1212 if (forced_effective_connection_type_set_) | 1205 if (params_.forced_effective_connection_type()) |
| 1213 return forced_effective_connection_type_; | 1206 return params_.forced_effective_connection_type().value(); |
| 1214 | 1207 |
| 1215 // If the device is currently offline, then return | 1208 // If the device is currently offline, then return |
| 1216 // EFFECTIVE_CONNECTION_TYPE_OFFLINE. | 1209 // EFFECTIVE_CONNECTION_TYPE_OFFLINE. |
| 1217 | 1210 |
| 1218 if (current_network_id_.type == NetworkChangeNotifier::CONNECTION_NONE && | 1211 if (current_network_id_.type == NetworkChangeNotifier::CONNECTION_NONE && |
| 1219 !disable_offline_check_) { | 1212 !disable_offline_check_) { |
| 1220 return EFFECTIVE_CONNECTION_TYPE_OFFLINE; | 1213 return EFFECTIVE_CONNECTION_TYPE_OFFLINE; |
| 1221 } | 1214 } |
| 1222 | 1215 |
| 1223 if (!GetRecentHttpRTT(start_time, http_rtt)) | 1216 if (!GetRecentHttpRTT(start_time, http_rtt)) |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1840 return base::Optional<base::TimeDelta>(); | 1833 return base::Optional<base::TimeDelta>(); |
| 1841 } | 1834 } |
| 1842 | 1835 |
| 1843 base::Optional<int32_t> | 1836 base::Optional<int32_t> |
| 1844 NetworkQualityEstimator::NetworkQualityProvider::GetDownstreamThroughputKbps() | 1837 NetworkQualityEstimator::NetworkQualityProvider::GetDownstreamThroughputKbps() |
| 1845 const { | 1838 const { |
| 1846 return base::Optional<int32_t>(); | 1839 return base::Optional<int32_t>(); |
| 1847 } | 1840 } |
| 1848 | 1841 |
| 1849 } // namespace net | 1842 } // namespace net |
| OLD | NEW |