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

Side by Side Diff: net/nqe/network_quality_estimator.cc

Issue 2593243003: Add network quality change events to net log (Closed)
Patch Set: ps Created 3 years, 11 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
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 15 matching lines...) Expand all
26 #include "base/trace_event/trace_event.h" 26 #include "base/trace_event/trace_event.h"
27 #include "build/build_config.h" 27 #include "build/build_config.h"
28 #include "net/base/load_flags.h" 28 #include "net/base/load_flags.h"
29 #include "net/base/load_timing_info.h" 29 #include "net/base/load_timing_info.h"
30 #include "net/base/network_interfaces.h" 30 #include "net/base/network_interfaces.h"
31 #include "net/base/trace_constants.h" 31 #include "net/base/trace_constants.h"
32 #include "net/base/url_util.h" 32 #include "net/base/url_util.h"
33 #include "net/http/http_response_headers.h" 33 #include "net/http/http_response_headers.h"
34 #include "net/http/http_response_info.h" 34 #include "net/http/http_response_info.h"
35 #include "net/http/http_status_code.h" 35 #include "net/http/http_status_code.h"
36 #include "net/nqe/event_creator.h"
36 #include "net/nqe/network_quality_estimator_params.h" 37 #include "net/nqe/network_quality_estimator_params.h"
37 #include "net/nqe/socket_watcher_factory.h" 38 #include "net/nqe/socket_watcher_factory.h"
38 #include "net/nqe/throughput_analyzer.h" 39 #include "net/nqe/throughput_analyzer.h"
39 #include "net/url_request/url_request.h" 40 #include "net/url_request/url_request.h"
40 #include "net/url_request/url_request_status.h" 41 #include "net/url_request/url_request_status.h"
41 #include "url/gurl.h" 42 #include "url/gurl.h"
42 43
43 #if defined(OS_ANDROID) 44 #if defined(OS_ANDROID)
44 #include "net/android/cellular_signal_strength.h" 45 #include "net/android/cellular_signal_strength.h"
45 #include "net/android/network_library.h" 46 #include "net/android/network_library.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 histogram_name, 0, EFFECTIVE_CONNECTION_TYPE_LAST, 201 histogram_name, 0, EFFECTIVE_CONNECTION_TYPE_LAST,
201 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, 202 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */,
202 base::HistogramBase::kUmaTargetedHistogramFlag); 203 base::HistogramBase::kUmaTargetedHistogramFlag);
203 histogram->Add(std::abs(metric)); 204 histogram->Add(std::abs(metric));
204 } 205 }
205 206
206 } // namespace 207 } // namespace
207 208
208 NetworkQualityEstimator::NetworkQualityEstimator( 209 NetworkQualityEstimator::NetworkQualityEstimator(
209 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, 210 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
210 const std::map<std::string, std::string>& variation_params)
211 : NetworkQualityEstimator(std::move(external_estimates_provider),
212 variation_params,
213 false,
214 false) {}
215
216 NetworkQualityEstimator::NetworkQualityEstimator(
217 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
218 const std::map<std::string, std::string>& variation_params, 211 const std::map<std::string, std::string>& variation_params,
219 bool use_local_host_requests_for_tests, 212 NetLog* net_log)
220 bool use_smaller_responses_for_tests)
221 : NetworkQualityEstimator(std::move(external_estimates_provider), 213 : NetworkQualityEstimator(std::move(external_estimates_provider),
222 variation_params, 214 variation_params,
223 use_local_host_requests_for_tests, 215 false,
224 use_smaller_responses_for_tests, 216 false,
225 true) {} 217 net_log) {}
226 218
227 NetworkQualityEstimator::NetworkQualityEstimator( 219 NetworkQualityEstimator::NetworkQualityEstimator(
228 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, 220 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
229 const std::map<std::string, std::string>& variation_params, 221 const std::map<std::string, std::string>& variation_params,
230 bool use_local_host_requests_for_tests, 222 bool use_local_host_requests_for_tests,
231 bool use_smaller_responses_for_tests, 223 bool use_smaller_responses_for_tests,
232 bool add_default_platform_observations) 224 NetLog* net_log)
225 : NetworkQualityEstimator(
226 std::move(external_estimates_provider),
227 variation_params,
228 use_local_host_requests_for_tests,
229 use_smaller_responses_for_tests,
230 true,
231 NetLogWithSource::Make(net_log, net::NetLogSourceType::NONE)) {}
232
233 NetworkQualityEstimator::NetworkQualityEstimator(
234 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
235 const std::map<std::string, std::string>& variation_params,
236 bool use_local_host_requests_for_tests,
237 bool use_smaller_responses_for_tests,
238 bool add_default_platform_observations,
239 const NetLogWithSource& net_log)
233 : algorithm_name_to_enum_({{"HttpRTTAndDownstreamThroughput", 240 : algorithm_name_to_enum_({{"HttpRTTAndDownstreamThroughput",
234 EffectiveConnectionTypeAlgorithm:: 241 EffectiveConnectionTypeAlgorithm::
235 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, 242 HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT},
236 {"TransportRTTOrDownstreamThroughput", 243 {"TransportRTTOrDownstreamThroughput",
237 EffectiveConnectionTypeAlgorithm:: 244 EffectiveConnectionTypeAlgorithm::
238 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}), 245 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}),
239 use_localhost_requests_(use_local_host_requests_for_tests), 246 use_localhost_requests_(use_local_host_requests_for_tests),
240 use_small_responses_(use_smaller_responses_for_tests), 247 use_small_responses_(use_smaller_responses_for_tests),
241 add_default_platform_observations_(add_default_platform_observations), 248 add_default_platform_observations_(add_default_platform_observations),
242 weight_multiplier_per_second_( 249 weight_multiplier_per_second_(
(...skipping 25 matching lines...) Expand all
268 signal_strength_dbm_(INT32_MIN), 275 signal_strength_dbm_(INT32_MIN),
269 min_signal_strength_since_connection_change_(INT32_MAX), 276 min_signal_strength_since_connection_change_(INT32_MAX),
270 max_signal_strength_since_connection_change_(INT32_MIN), 277 max_signal_strength_since_connection_change_(INT32_MIN),
271 correlation_uma_logging_probability_( 278 correlation_uma_logging_probability_(
272 nqe::internal::correlation_uma_logging_probability(variation_params)), 279 nqe::internal::correlation_uma_logging_probability(variation_params)),
273 forced_effective_connection_type_set_( 280 forced_effective_connection_type_set_(
274 nqe::internal::forced_effective_connection_type_set( 281 nqe::internal::forced_effective_connection_type_set(
275 variation_params)), 282 variation_params)),
276 forced_effective_connection_type_( 283 forced_effective_connection_type_(
277 nqe::internal::forced_effective_connection_type(variation_params)), 284 nqe::internal::forced_effective_connection_type(variation_params)),
285 net_log_(net_log),
278 weak_ptr_factory_(this) { 286 weak_ptr_factory_(this) {
279 // None of the algorithms can have an empty name. 287 // None of the algorithms can have an empty name.
280 DCHECK(algorithm_name_to_enum_.end() == 288 DCHECK(algorithm_name_to_enum_.end() ==
281 algorithm_name_to_enum_.find(std::string())); 289 algorithm_name_to_enum_.find(std::string()));
282 290
283 DCHECK_EQ(algorithm_name_to_enum_.size(), 291 DCHECK_EQ(algorithm_name_to_enum_.size(),
284 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: 292 static_cast<size_t>(EffectiveConnectionTypeAlgorithm::
285 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); 293 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST));
286 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: 294 DCHECK_NE(EffectiveConnectionTypeAlgorithm::
287 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, 295 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST,
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 void NetworkQualityEstimator::SetUseSmallResponsesForTesting( 723 void NetworkQualityEstimator::SetUseSmallResponsesForTesting(
716 bool use_small_responses) { 724 bool use_small_responses) {
717 DCHECK(thread_checker_.CalledOnValidThread()); 725 DCHECK(thread_checker_.CalledOnValidThread());
718 use_small_responses_ = use_small_responses; 726 use_small_responses_ = use_small_responses;
719 throughput_analyzer_->SetUseSmallResponsesForTesting(use_small_responses_); 727 throughput_analyzer_->SetUseSmallResponsesForTesting(use_small_responses_);
720 } 728 }
721 729
722 void NetworkQualityEstimator::ReportEffectiveConnectionTypeForTesting( 730 void NetworkQualityEstimator::ReportEffectiveConnectionTypeForTesting(
723 EffectiveConnectionType effective_connection_type) { 731 EffectiveConnectionType effective_connection_type) {
724 DCHECK(thread_checker_.CalledOnValidThread()); 732 DCHECK(thread_checker_.CalledOnValidThread());
733
734 nqe::internal::AddEffectiveConnectionTypeChangedEventToNetLog(
735 net_log_, typical_network_quality_[effective_connection_type].http_rtt(),
736 typical_network_quality_[effective_connection_type].transport_rtt(),
737 typical_network_quality_[effective_connection_type]
738 .downstream_throughput_kbps(),
739 effective_connection_type);
740
725 for (auto& observer : effective_connection_type_observer_list_) 741 for (auto& observer : effective_connection_type_observer_list_)
726 observer.OnEffectiveConnectionTypeChanged(effective_connection_type); 742 observer.OnEffectiveConnectionTypeChanged(effective_connection_type);
727 743
728 network_quality_store_->Add(current_network_id_, 744 network_quality_store_->Add(current_network_id_,
729 nqe::internal::CachedNetworkQuality( 745 nqe::internal::CachedNetworkQuality(
730 tick_clock_->NowTicks(), network_quality_, 746 tick_clock_->NowTicks(), network_quality_,
731 effective_connection_type)); 747 effective_connection_type));
732 } 748 }
733 749
734 bool NetworkQualityEstimator::RequestProvidesRTTObservation( 750 bool NetworkQualityEstimator::RequestProvidesRTTObservation(
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 GetRecentEffectiveConnectionTypeAndNetworkQuality( 1017 GetRecentEffectiveConnectionTypeAndNetworkQuality(
1002 base::TimeTicks(), &http_rtt, &transport_rtt, 1018 base::TimeTicks(), &http_rtt, &transport_rtt,
1003 &downstream_throughput_kbps); 1019 &downstream_throughput_kbps);
1004 1020
1005 network_quality_ = nqe::internal::NetworkQuality(http_rtt, transport_rtt, 1021 network_quality_ = nqe::internal::NetworkQuality(http_rtt, transport_rtt,
1006 downstream_throughput_kbps); 1022 downstream_throughput_kbps);
1007 1023
1008 NotifyObserversOfRTTOrThroughputComputed(); 1024 NotifyObserversOfRTTOrThroughputComputed();
1009 1025
1010 if (past_type != effective_connection_type_) 1026 if (past_type != effective_connection_type_)
1011 NotifyObserversOfEffectiveConnectionTypeChanged(); 1027 NotifyObserversOfEffectiveConnectionTypeChanged(http_rtt, transport_rtt,
1028 downstream_throughput_kbps);
1012 1029
1013 rtt_observations_size_at_last_ect_computation_ = rtt_observations_.Size(); 1030 rtt_observations_size_at_last_ect_computation_ = rtt_observations_.Size();
1014 throughput_observations_size_at_last_ect_computation_ = 1031 throughput_observations_size_at_last_ect_computation_ =
1015 downstream_throughput_kbps_observations_.Size(); 1032 downstream_throughput_kbps_observations_.Size();
1016 } 1033 }
1017 1034
1018 EffectiveConnectionType NetworkQualityEstimator::GetEffectiveConnectionType() 1035 EffectiveConnectionType NetworkQualityEstimator::GetEffectiveConnectionType()
1019 const { 1036 const {
1020 DCHECK(thread_checker_.CalledOnValidThread()); 1037 DCHECK(thread_checker_.CalledOnValidThread());
1021 return effective_connection_type_; 1038 return effective_connection_type_;
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 1381
1365 const base::TimeTicks now = tick_clock_->NowTicks(); 1382 const base::TimeTicks now = tick_clock_->NowTicks();
1366 1383
1367 if (effective_connection_type_ == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 1384 if (effective_connection_type_ == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
1368 // Read the effective connection type from the cached estimate. 1385 // Read the effective connection type from the cached estimate.
1369 last_effective_connection_type_computation_ = now; 1386 last_effective_connection_type_computation_ = now;
1370 network_quality_ = cached_network_quality.network_quality(); 1387 network_quality_ = cached_network_quality.network_quality();
1371 effective_connection_type_ = 1388 effective_connection_type_ =
1372 cached_network_quality.effective_connection_type(); 1389 cached_network_quality.effective_connection_type();
1373 1390
1374 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) 1391 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
1375 NotifyObserversOfEffectiveConnectionTypeChanged(); 1392 NotifyObserversOfEffectiveConnectionTypeChanged(
1393 network_quality_.http_rtt(), network_quality_.transport_rtt(),
1394 network_quality_.downstream_throughput_kbps());
1395 }
1376 } 1396 }
1377 1397
1378 if (cached_network_quality.network_quality().downstream_throughput_kbps() != 1398 if (cached_network_quality.network_quality().downstream_throughput_kbps() !=
1379 nqe::internal::kInvalidThroughput) { 1399 nqe::internal::kInvalidThroughput) {
1380 ThroughputObservation througphput_observation( 1400 ThroughputObservation througphput_observation(
1381 cached_network_quality.network_quality().downstream_throughput_kbps(), 1401 cached_network_quality.network_quality().downstream_throughput_kbps(),
1382 now, INT32_MIN, 1402 now, INT32_MIN,
1383 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); 1403 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE);
1384 downstream_throughput_kbps_observations_.AddObservation( 1404 downstream_throughput_kbps_observations_.AddObservation(
1385 througphput_observation); 1405 througphput_observation);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 // available when the effective connection type was last computed. 1559 // available when the effective connection type was last computed.
1540 rtt_observations_size_at_last_ect_computation_ * 1.5 >= 1560 rtt_observations_size_at_last_ect_computation_ * 1.5 >=
1541 rtt_observations_.Size() && 1561 rtt_observations_.Size() &&
1542 throughput_observations_size_at_last_ect_computation_ * 1.5 >= 1562 throughput_observations_size_at_last_ect_computation_ * 1.5 >=
1543 downstream_throughput_kbps_observations_.Size()) { 1563 downstream_throughput_kbps_observations_.Size()) {
1544 return; 1564 return;
1545 } 1565 }
1546 ComputeEffectiveConnectionType(); 1566 ComputeEffectiveConnectionType();
1547 } 1567 }
1548 1568
1549 void NetworkQualityEstimator:: 1569 void NetworkQualityEstimator::NotifyObserversOfEffectiveConnectionTypeChanged(
1550 NotifyObserversOfEffectiveConnectionTypeChanged() { 1570 base::TimeDelta http_rtt,
RyanSturm 2017/01/10 16:22:37 Why are you passing these values in? Can't you acc
tbansal1 2017/01/10 18:27:53 Good catch. Done.
1571 base::TimeDelta transport_rtt,
1572 int32_t downstream_throughput_kbps) {
1551 DCHECK(thread_checker_.CalledOnValidThread()); 1573 DCHECK(thread_checker_.CalledOnValidThread());
1552 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_); 1574 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_);
1553 1575
1576 nqe::internal::AddEffectiveConnectionTypeChangedEventToNetLog(
1577 net_log_, http_rtt, transport_rtt, downstream_throughput_kbps,
1578 effective_connection_type_);
1579
1554 // TODO(tbansal): Add hysteresis in the notification. 1580 // TODO(tbansal): Add hysteresis in the notification.
1555 for (auto& observer : effective_connection_type_observer_list_) 1581 for (auto& observer : effective_connection_type_observer_list_)
1556 observer.OnEffectiveConnectionTypeChanged(effective_connection_type_); 1582 observer.OnEffectiveConnectionTypeChanged(effective_connection_type_);
1557 1583
1558 // Add the estimates of the current network to the cache store. 1584 // Add the estimates of the current network to the cache store.
1559 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 1585 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
1560 network_quality_store_->Add(current_network_id_, 1586 network_quality_store_->Add(current_network_id_,
1561 nqe::internal::CachedNetworkQuality( 1587 nqe::internal::CachedNetworkQuality(
1562 tick_clock_->NowTicks(), network_quality_, 1588 tick_clock_->NowTicks(), network_quality_,
1563 effective_connection_type_)); 1589 effective_connection_type_));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); 1705 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE);
1680 downstream_throughput_kbps_observations_.AddObservation( 1706 downstream_throughput_kbps_observations_.AddObservation(
1681 throughput_observation); 1707 throughput_observation);
1682 NotifyObserversOfThroughput(throughput_observation); 1708 NotifyObserversOfThroughput(throughput_observation);
1683 } 1709 }
1684 1710
1685 ComputeEffectiveConnectionType(); 1711 ComputeEffectiveConnectionType();
1686 } 1712 }
1687 1713
1688 } // namespace net 1714 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698