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

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

Issue 2593243003: Add network quality change events to net log (Closed)
Patch Set: ryansturm comments 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)) {}
mmenke 2017/01/12 21:40:02 Seems like these should be top level events - i.e.
tbansal1 2017/01/12 23:12:31 My only concern with making this a top level event
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 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 return; 1560 return;
1545 } 1561 }
1546 ComputeEffectiveConnectionType(); 1562 ComputeEffectiveConnectionType();
1547 } 1563 }
1548 1564
1549 void NetworkQualityEstimator:: 1565 void NetworkQualityEstimator::
1550 NotifyObserversOfEffectiveConnectionTypeChanged() { 1566 NotifyObserversOfEffectiveConnectionTypeChanged() {
1551 DCHECK(thread_checker_.CalledOnValidThread()); 1567 DCHECK(thread_checker_.CalledOnValidThread());
1552 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_); 1568 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_);
1553 1569
1570 nqe::internal::AddEffectiveConnectionTypeChangedEventToNetLog(
1571 net_log_, network_quality_.http_rtt(), network_quality_.transport_rtt(),
1572 network_quality_.downstream_throughput_kbps(),
1573 effective_connection_type_);
1574
1554 // TODO(tbansal): Add hysteresis in the notification. 1575 // TODO(tbansal): Add hysteresis in the notification.
1555 for (auto& observer : effective_connection_type_observer_list_) 1576 for (auto& observer : effective_connection_type_observer_list_)
1556 observer.OnEffectiveConnectionTypeChanged(effective_connection_type_); 1577 observer.OnEffectiveConnectionTypeChanged(effective_connection_type_);
1557 1578
1558 // Add the estimates of the current network to the cache store. 1579 // Add the estimates of the current network to the cache store.
1559 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 1580 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
1560 network_quality_store_->Add(current_network_id_, 1581 network_quality_store_->Add(current_network_id_,
1561 nqe::internal::CachedNetworkQuality( 1582 nqe::internal::CachedNetworkQuality(
1562 tick_clock_->NowTicks(), network_quality_, 1583 tick_clock_->NowTicks(), network_quality_,
1563 effective_connection_type_)); 1584 effective_connection_type_));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); 1700 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE);
1680 downstream_throughput_kbps_observations_.AddObservation( 1701 downstream_throughput_kbps_observations_.AddObservation(
1681 throughput_observation); 1702 throughput_observation);
1682 NotifyObserversOfThroughput(throughput_observation); 1703 NotifyObserversOfThroughput(throughput_observation);
1683 } 1704 }
1684 1705
1685 ComputeEffectiveConnectionType(); 1706 ComputeEffectiveConnectionType();
1686 } 1707 }
1687 1708
1688 } // namespace net 1709 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698