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

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

Issue 2572483003: Record difference between the maximum and minimum wireless signal strength (Closed)
Patch Set: ryansturm comments Created 4 years 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 27 matching lines...) Expand all
38 #include "net/nqe/throughput_analyzer.h" 38 #include "net/nqe/throughput_analyzer.h"
39 #include "net/url_request/url_request.h" 39 #include "net/url_request/url_request.h"
40 #include "net/url_request/url_request_status.h" 40 #include "net/url_request/url_request_status.h"
41 #include "url/gurl.h" 41 #include "url/gurl.h"
42 42
43 #if defined(OS_ANDROID) 43 #if defined(OS_ANDROID)
44 #include "net/android/cellular_signal_strength.h" 44 #include "net/android/cellular_signal_strength.h"
45 #include "net/android/network_library.h" 45 #include "net/android/network_library.h"
46 #endif // OS_ANDROID 46 #endif // OS_ANDROID
47 47
48 namespace net {
49
48 namespace { 50 namespace {
49 51
50 // Returns the histogram that should be used to record the given statistic. 52 // Returns the histogram that should be used to record the given statistic.
51 // |max_limit| is the maximum value that can be stored in the histogram. 53 // |max_limit| is the maximum value that can be stored in the histogram.
52 base::HistogramBase* GetHistogram( 54 base::HistogramBase* GetHistogram(const std::string& statistic_name,
53 const std::string& statistic_name, 55 NetworkChangeNotifier::ConnectionType type,
54 net::NetworkChangeNotifier::ConnectionType type, 56 int32_t max_limit) {
55 int32_t max_limit) {
56 const base::LinearHistogram::Sample kLowerLimit = 1; 57 const base::LinearHistogram::Sample kLowerLimit = 1;
57 DCHECK_GT(max_limit, kLowerLimit); 58 DCHECK_GT(max_limit, kLowerLimit);
58 const size_t kBucketCount = 50; 59 const size_t kBucketCount = 50;
59 60
60 return base::Histogram::FactoryGet( 61 return base::Histogram::FactoryGet(
61 "NQE." + statistic_name + 62 "NQE." + statistic_name + nqe::internal::GetNameForConnectionType(type),
62 net::nqe::internal::GetNameForConnectionType(type),
63 kLowerLimit, max_limit, kBucketCount, 63 kLowerLimit, max_limit, kBucketCount,
64 base::HistogramBase::kUmaTargetedHistogramFlag); 64 base::HistogramBase::kUmaTargetedHistogramFlag);
65 } 65 }
66 66
67 net::NetworkQualityObservationSource ProtocolSourceToObservationSource( 67 NetworkQualityObservationSource ProtocolSourceToObservationSource(
68 net::SocketPerformanceWatcherFactory::Protocol protocol) { 68 SocketPerformanceWatcherFactory::Protocol protocol) {
69 switch (protocol) { 69 switch (protocol) {
70 case net::SocketPerformanceWatcherFactory::PROTOCOL_TCP: 70 case SocketPerformanceWatcherFactory::PROTOCOL_TCP:
71 return net::NETWORK_QUALITY_OBSERVATION_SOURCE_TCP; 71 return NETWORK_QUALITY_OBSERVATION_SOURCE_TCP;
72 case net::SocketPerformanceWatcherFactory::PROTOCOL_QUIC: 72 case SocketPerformanceWatcherFactory::PROTOCOL_QUIC:
73 return net::NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC; 73 return NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC;
74 } 74 }
75 NOTREACHED(); 75 NOTREACHED();
76 return net::NETWORK_QUALITY_OBSERVATION_SOURCE_TCP; 76 return NETWORK_QUALITY_OBSERVATION_SOURCE_TCP;
77 } 77 }
78 78
79 // Returns true if the scheme of the |request| is either HTTP or HTTPS. 79 // Returns true if the scheme of the |request| is either HTTP or HTTPS.
80 bool RequestSchemeIsHTTPOrHTTPS(const net::URLRequest& request) { 80 bool RequestSchemeIsHTTPOrHTTPS(const URLRequest& request) {
81 return request.url().is_valid() && request.url().SchemeIsHTTPOrHTTPS(); 81 return request.url().is_valid() && request.url().SchemeIsHTTPOrHTTPS();
82 } 82 }
83 83
84 // Returns the suffix of the histogram that should be used for recording the 84 // Returns the suffix of the histogram that should be used for recording the
85 // accuracy when the observed RTT is |observed_rtt|. The width of the intervals 85 // accuracy when the observed RTT is |observed_rtt|. The width of the intervals
86 // are in exponentially increasing order. 86 // are in exponentially increasing order.
87 const char* GetHistogramSuffixObservedRTT(const base::TimeDelta& observed_rtt) { 87 const char* GetHistogramSuffixObservedRTT(const base::TimeDelta& observed_rtt) {
88 const float rtt_milliseconds = observed_rtt.InMillisecondsF(); 88 const float rtt_milliseconds = observed_rtt.InMillisecondsF();
89 DCHECK_GE(rtt_milliseconds, 0); 89 DCHECK_GE(rtt_milliseconds, 0);
90 90
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 base::HistogramBase* histogram = base::Histogram::FactoryGet( 182 base::HistogramBase* histogram = base::Histogram::FactoryGet(
183 histogram_name, 1, 1000 * 1000 /* 1 Gbps */, 50 /* Number of buckets */, 183 histogram_name, 1, 1000 * 1000 /* 1 Gbps */, 50 /* Number of buckets */,
184 base::HistogramBase::kUmaTargetedHistogramFlag); 184 base::HistogramBase::kUmaTargetedHistogramFlag);
185 histogram->Add(std::abs(metric)); 185 histogram->Add(std::abs(metric));
186 } 186 }
187 187
188 void RecordEffectiveConnectionTypeAccuracy( 188 void RecordEffectiveConnectionTypeAccuracy(
189 const char* prefix, 189 const char* prefix,
190 int32_t metric, 190 int32_t metric,
191 base::TimeDelta measuring_duration, 191 base::TimeDelta measuring_duration,
192 net::EffectiveConnectionType observed_effective_connection_type) { 192 EffectiveConnectionType observed_effective_connection_type) {
193 const std::string histogram_name = 193 const std::string histogram_name = base::StringPrintf(
194 base::StringPrintf("%s.EstimatedObservedDiff.%s.%d.%s", prefix, 194 "%s.EstimatedObservedDiff.%s.%d.%s", prefix,
195 metric >= 0 ? "Positive" : "Negative", 195 metric >= 0 ? "Positive" : "Negative",
196 static_cast<int32_t>(measuring_duration.InSeconds()), 196 static_cast<int32_t>(measuring_duration.InSeconds()),
197 net::GetNameForEffectiveConnectionType( 197 GetNameForEffectiveConnectionType(observed_effective_connection_type));
198 observed_effective_connection_type));
199 198
200 base::HistogramBase* histogram = base::Histogram::FactoryGet( 199 base::HistogramBase* histogram = base::Histogram::FactoryGet(
201 histogram_name, 0, net::EFFECTIVE_CONNECTION_TYPE_LAST, 200 histogram_name, 0, EFFECTIVE_CONNECTION_TYPE_LAST,
202 net::EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, 201 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */,
203 base::HistogramBase::kUmaTargetedHistogramFlag); 202 base::HistogramBase::kUmaTargetedHistogramFlag);
204 histogram->Add(std::abs(metric)); 203 histogram->Add(std::abs(metric));
205 } 204 }
206 205
207 } // namespace 206 } // namespace
208 207
209 namespace net {
210
211 NetworkQualityEstimator::NetworkQualityEstimator( 208 NetworkQualityEstimator::NetworkQualityEstimator(
212 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, 209 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
213 const std::map<std::string, std::string>& variation_params) 210 const std::map<std::string, std::string>& variation_params)
214 : NetworkQualityEstimator(std::move(external_estimates_provider), 211 : NetworkQualityEstimator(std::move(external_estimates_provider),
215 variation_params, 212 variation_params,
216 false, 213 false,
217 false) {} 214 false) {}
218 215
219 NetworkQualityEstimator::NetworkQualityEstimator( 216 NetworkQualityEstimator::NetworkQualityEstimator(
220 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, 217 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
(...skipping 18 matching lines...) Expand all
239 {"TransportRTTOrDownstreamThroughput", 236 {"TransportRTTOrDownstreamThroughput",
240 EffectiveConnectionTypeAlgorithm:: 237 EffectiveConnectionTypeAlgorithm::
241 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}), 238 TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}),
242 use_localhost_requests_(use_local_host_requests_for_tests), 239 use_localhost_requests_(use_local_host_requests_for_tests),
243 use_small_responses_(use_smaller_responses_for_tests), 240 use_small_responses_(use_smaller_responses_for_tests),
244 add_default_platform_observations_(add_default_platform_observations), 241 add_default_platform_observations_(add_default_platform_observations),
245 weight_multiplier_per_second_( 242 weight_multiplier_per_second_(
246 nqe::internal::GetWeightMultiplierPerSecond(variation_params)), 243 nqe::internal::GetWeightMultiplierPerSecond(variation_params)),
247 effective_connection_type_algorithm_( 244 effective_connection_type_algorithm_(
248 algorithm_name_to_enum_.find( 245 algorithm_name_to_enum_.find(
249 net::nqe::internal::GetEffectiveConnectionTypeAlgorithm( 246 nqe::internal::GetEffectiveConnectionTypeAlgorithm(
250 variation_params)) == algorithm_name_to_enum_.end() 247 variation_params)) == algorithm_name_to_enum_.end()
251 ? kDefaultEffectiveConnectionTypeAlgorithm 248 ? kDefaultEffectiveConnectionTypeAlgorithm
252 : algorithm_name_to_enum_ 249 : algorithm_name_to_enum_
253 .find( 250 .find(nqe::internal::GetEffectiveConnectionTypeAlgorithm(
254 net::nqe::internal::GetEffectiveConnectionTypeAlgorithm( 251 variation_params))
255 variation_params))
256 ->second), 252 ->second),
257 tick_clock_(new base::DefaultTickClock()), 253 tick_clock_(new base::DefaultTickClock()),
258 last_connection_change_(tick_clock_->NowTicks()), 254 last_connection_change_(tick_clock_->NowTicks()),
259 current_network_id_(nqe::internal::NetworkID( 255 current_network_id_(nqe::internal::NetworkID(
260 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, 256 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN,
261 std::string())), 257 std::string())),
262 downstream_throughput_kbps_observations_(weight_multiplier_per_second_), 258 downstream_throughput_kbps_observations_(weight_multiplier_per_second_),
263 rtt_observations_(weight_multiplier_per_second_), 259 rtt_observations_(weight_multiplier_per_second_),
264 effective_connection_type_at_last_main_frame_( 260 effective_connection_type_at_last_main_frame_(
265 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), 261 EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 396
401 if (!RequestSchemeIsHTTPOrHTTPS(request) || 397 if (!RequestSchemeIsHTTPOrHTTPS(request) ||
402 !RequestProvidesRTTObservation(request)) { 398 !RequestProvidesRTTObservation(request)) {
403 return; 399 return;
404 } 400 }
405 401
406 const base::TimeTicks now = tick_clock_->NowTicks(); 402 const base::TimeTicks now = tick_clock_->NowTicks();
407 403
408 // Update |estimated_quality_at_last_main_frame_| if this is a main frame 404 // Update |estimated_quality_at_last_main_frame_| if this is a main frame
409 // request. 405 // request.
406 // TODO(tbansal): Refactor this to a separate method.
410 if (request.load_flags() & LOAD_MAIN_FRAME_DEPRECATED) { 407 if (request.load_flags() & LOAD_MAIN_FRAME_DEPRECATED) {
411 last_main_frame_request_ = now; 408 last_main_frame_request_ = now;
412 409
413 ComputeEffectiveConnectionType(); 410 ComputeEffectiveConnectionType();
414 effective_connection_type_at_last_main_frame_ = effective_connection_type_; 411 effective_connection_type_at_last_main_frame_ = effective_connection_type_;
415 estimated_quality_at_last_main_frame_ = network_quality_; 412 estimated_quality_at_last_main_frame_ = network_quality_;
416 413
417 RecordMetricsOnMainFrameRequest(); 414 RecordMetricsOnMainFrameRequest();
418 MaybeQueryExternalEstimateProvider(); 415 MaybeQueryExternalEstimateProvider();
419 416
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 peak_network_quality_ = nqe::internal::NetworkQuality(); 764 peak_network_quality_ = nqe::internal::NetworkQuality();
768 downstream_throughput_kbps_observations_.Clear(); 765 downstream_throughput_kbps_observations_.Clear();
769 rtt_observations_.Clear(); 766 rtt_observations_.Clear();
770 767
771 #if defined(OS_ANDROID) 768 #if defined(OS_ANDROID)
772 if (NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) { 769 if (NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) {
773 UMA_HISTOGRAM_BOOLEAN( 770 UMA_HISTOGRAM_BOOLEAN(
774 "NQE.CellularSignalStrengthAvailable", 771 "NQE.CellularSignalStrengthAvailable",
775 min_signal_strength_since_connection_change_ != INT32_MAX && 772 min_signal_strength_since_connection_change_ != INT32_MAX &&
776 max_signal_strength_since_connection_change_ != INT32_MIN); 773 max_signal_strength_since_connection_change_ != INT32_MIN);
774
775 if (min_signal_strength_since_connection_change_ != INT32_MAX &&
776 max_signal_strength_since_connection_change_ != INT32_MIN) {
777 UMA_HISTOGRAM_COUNTS_100(
rkaplow 2016/12/16 18:34:24 double checking 100 is a good max
tbansal1 2016/12/16 19:14:10 Yes, I think it is.
778 "NQE.CellularSignalStrengthDifference",
779 max_signal_strength_since_connection_change_ -
780 min_signal_strength_since_connection_change_);
781 }
777 } 782 }
778 #endif // OS_ANDROID 783 #endif // OS_ANDROID
784
779 min_signal_strength_since_connection_change_ = INT32_MAX; 785 min_signal_strength_since_connection_change_ = INT32_MAX;
780 max_signal_strength_since_connection_change_ = INT32_MIN; 786 max_signal_strength_since_connection_change_ = INT32_MIN;
781 network_quality_ = nqe::internal::NetworkQuality(); 787 network_quality_ = nqe::internal::NetworkQuality();
782 effective_connection_type_ = EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 788 effective_connection_type_ = EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
783 effective_connection_type_at_last_main_frame_ = 789 effective_connection_type_at_last_main_frame_ =
784 EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 790 EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
785 791
786 // Update the local state as part of preparation for the new connection. 792 // Update the local state as part of preparation for the new connection.
787 current_network_id_ = GetCurrentNetworkID(); 793 current_network_id_ = GetCurrentNetworkID();
788 RecordNetworkIDAvailability(); 794 RecordNetworkIDAvailability();
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 void NetworkQualityEstimator::OnPrefsRead( 1599 void NetworkQualityEstimator::OnPrefsRead(
1594 const std::map<nqe::internal::NetworkID, 1600 const std::map<nqe::internal::NetworkID,
1595 nqe::internal::CachedNetworkQuality> read_prefs) { 1601 nqe::internal::CachedNetworkQuality> read_prefs) {
1596 DCHECK(thread_checker_.CalledOnValidThread()); 1602 DCHECK(thread_checker_.CalledOnValidThread());
1597 UMA_HISTOGRAM_COUNTS("NQE.Prefs.ReadSize", read_prefs.size()); 1603 UMA_HISTOGRAM_COUNTS("NQE.Prefs.ReadSize", read_prefs.size());
1598 // TODO(tbansal): crbug.com/490870. Incorporate the network quality into the 1604 // TODO(tbansal): crbug.com/490870. Incorporate the network quality into the
1599 // current estimates. 1605 // current estimates.
1600 } 1606 }
1601 1607
1602 } // namespace net 1608 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | tools/metrics/histograms/histograms.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698