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 2145613003: NQE: Add accuracy histogram for external estimate provider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: patch Created 4 years, 5 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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 if (!GetDownlinkThroughputKbpsEstimate(&downstream_throughput_kbps)) 510 if (!GetDownlinkThroughputKbpsEstimate(&downstream_throughput_kbps))
511 downstream_throughput_kbps = nqe::internal::kInvalidThroughput; 511 downstream_throughput_kbps = nqe::internal::kInvalidThroughput;
512 512
513 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality( 513 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality(
514 estimated_http_rtt, estimated_transport_rtt, 514 estimated_http_rtt, estimated_transport_rtt,
515 downstream_throughput_kbps); 515 downstream_throughput_kbps);
516 effective_connection_type_at_last_main_frame_ = 516 effective_connection_type_at_last_main_frame_ =
517 GetEffectiveConnectionType(); 517 GetEffectiveConnectionType();
518 518
519 RecordMetricsOnMainFrameRequest(); 519 RecordMetricsOnMainFrameRequest();
520 MaybeQueryExternalEstimateProvider();
520 521
521 // Post the tasks which will run in the future and record the estimation 522 // Post the tasks which will run in the future and record the estimation
522 // accuracy based on the observations received between now and the time of 523 // accuracy based on the observations received between now and the time of
523 // task execution. Posting the task at different intervals makes it 524 // task execution. Posting the task at different intervals makes it
524 // possible to measure the accuracy by comparing the estimate with the 525 // possible to measure the accuracy by comparing the estimate with the
525 // observations received over intervals of varying durations. 526 // observations received over intervals of varying durations.
526 for (const base::TimeDelta& measuring_delay : 527 for (const base::TimeDelta& measuring_delay :
527 GetAccuracyRecordingIntervals()) { 528 GetAccuracyRecordingIntervals()) {
528 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 529 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
529 FROM_HERE, 530 FROM_HERE,
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 if (effective_connection_type_at_last_main_frame_ != 656 if (effective_connection_type_at_last_main_frame_ !=
656 EFFECTIVE_CONNECTION_TYPE_UNKNOWN && 657 EFFECTIVE_CONNECTION_TYPE_UNKNOWN &&
657 recent_effective_connection_type != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 658 recent_effective_connection_type != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
658 const int estimated_observed_diff = 659 const int estimated_observed_diff =
659 static_cast<int>(effective_connection_type_at_last_main_frame_) - 660 static_cast<int>(effective_connection_type_at_last_main_frame_) -
660 static_cast<int>(recent_effective_connection_type); 661 static_cast<int>(recent_effective_connection_type);
661 662
662 const std::string sign_suffix = 663 const std::string sign_suffix =
663 estimated_observed_diff >= 0 ? "Positive." : "Negative."; 664 estimated_observed_diff >= 0 ? "Positive." : "Negative.";
664 665
665 base::HistogramBase* histogram = base::Histogram::FactoryGet( 666 base::HistogramBase* histogram = base::Histogram::FactoryGet(
bengr 2016/07/20 23:51:28 You should have tests for histograms.
tbansal1 2016/07/21 22:00:50 Done. I completely forgot that I already have harn
666 "NQE.Accuracy.EffectiveConnectionType.EstimatedObservedDiff." + 667 "NQE.Accuracy.EffectiveConnectionType.EstimatedObservedDiff." +
667 sign_suffix + base::IntToString(measuring_duration.InSeconds()) + 668 sign_suffix + base::IntToString(measuring_duration.InSeconds()) +
668 "." + 669 "." +
669 GetNameForEffectiveConnectionType(recent_effective_connection_type), 670 GetNameForEffectiveConnectionType(recent_effective_connection_type),
670 0, EFFECTIVE_CONNECTION_TYPE_LAST, 671 0, EFFECTIVE_CONNECTION_TYPE_LAST,
671 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, 672 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */,
672 base::HistogramBase::kUmaTargetedHistogramFlag); 673 base::HistogramBase::kUmaTargetedHistogramFlag);
673 histogram->Add(std::abs(estimated_observed_diff)); 674 histogram->Add(std::abs(estimated_observed_diff));
674 } 675 }
676
677 // Add histogram for accuracy of external estimate provider.
bengr 2016/07/20 23:51:28 for -> to evaluate the of -> of the
tbansal1 2016/07/21 22:00:50 Done.
678 if (external_estimate_provider_quality_.http_rtt() !=
679 nqe::internal::InvalidRTT() &&
680 recent_http_rtt != nqe::internal::InvalidRTT()) {
681 const int estimated_observed_diff_milliseconds =
682 external_estimate_provider_quality_.http_rtt().InMilliseconds() -
683 recent_http_rtt.InMilliseconds();
684
685 const std::string sign_suffix =
686 estimated_observed_diff_milliseconds >= 0 ? "Positive." : "Negative.";
bengr 2016/07/20 23:51:28 You should probably create a helper called GetSign
tbansal1 2016/07/21 22:00:50 Done.
687
688 base::HistogramBase* histogram = base::Histogram::FactoryGet(
bengr 2016/07/20 23:51:28 You get similar histograms all over this method. C
tbansal1 2016/07/21 22:00:50 Done.
689 "NQE.ExternalEstimateProvider.RTT.Accuracy."
bengr 2016/07/20 23:51:28 Here and everywhere in this method, consider using
tbansal1 2016/07/21 22:00:50 Done.
690 "EstimatedObservedDiff." +
691 sign_suffix + base::IntToString(measuring_duration.InSeconds()) +
692 "." + GetHistogramSuffixObservedRTT(recent_http_rtt),
693 1, 10 * 1000 /* 10 seconds */, 50 /* Number of buckets */,
694 base::HistogramBase::kUmaTargetedHistogramFlag);
695 histogram->Add(std::abs(estimated_observed_diff_milliseconds));
696 }
675 } 697 }
676 698
677 void NetworkQualityEstimator::NotifyRequestCompleted( 699 void NetworkQualityEstimator::NotifyRequestCompleted(
678 const URLRequest& request) { 700 const URLRequest& request) {
679 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), 701 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"),
680 "NetworkQualityEstimator::NotifyRequestCompleted"); 702 "NetworkQualityEstimator::NotifyRequestCompleted");
681 DCHECK(thread_checker_.CalledOnValidThread()); 703 DCHECK(thread_checker_.CalledOnValidThread());
682 704
683 if (!RequestSchemeIsHTTPOrHTTPS(request)) 705 if (!RequestSchemeIsHTTPOrHTTPS(request))
684 return; 706 return;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 "NQE.CellularSignalStrengthAvailable", 798 "NQE.CellularSignalStrengthAvailable",
777 min_signal_strength_since_connection_change_ != INT32_MAX && 799 min_signal_strength_since_connection_change_ != INT32_MAX &&
778 max_signal_strength_since_connection_change_ != INT32_MIN); 800 max_signal_strength_since_connection_change_ != INT32_MIN);
779 } 801 }
780 #endif // OS_ANDROID 802 #endif // OS_ANDROID
781 min_signal_strength_since_connection_change_ = INT32_MAX; 803 min_signal_strength_since_connection_change_ = INT32_MAX;
782 max_signal_strength_since_connection_change_ = INT32_MIN; 804 max_signal_strength_since_connection_change_ = INT32_MIN;
783 805
784 current_network_id_ = GetCurrentNetworkID(); 806 current_network_id_ = GetCurrentNetworkID();
785 807
808 MaybeQueryExternalEstimateProvider();
809
810 // Read any cached estimates for the new network. If cached estimates are
811 // unavailable, add the default estimates.
812 if (!ReadCachedNetworkQualityEstimate())
813 AddDefaultEstimates();
814 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality();
815 throughput_analyzer_->OnConnectionTypeChanged();
816 MaybeRecomputeEffectiveConnectionType();
817 UpdateSignalStrength();
818 }
819
820 void NetworkQualityEstimator::MaybeQueryExternalEstimateProvider() const {
786 // Query the external estimate provider on certain connection types. Once the 821 // Query the external estimate provider on certain connection types. Once the
787 // updated estimates are available, OnUpdatedEstimateAvailable will be called 822 // updated estimates are available, OnUpdatedEstimateAvailable will be called
788 // by |external_estimate_provider_| with updated estimates. 823 // by |external_estimate_provider_| with updated estimates.
789 if (external_estimate_provider_ && 824 if (external_estimate_provider_ &&
790 current_network_id_.type != NetworkChangeNotifier::CONNECTION_NONE && 825 current_network_id_.type != NetworkChangeNotifier::CONNECTION_NONE &&
791 current_network_id_.type != NetworkChangeNotifier::CONNECTION_UNKNOWN && 826 current_network_id_.type != NetworkChangeNotifier::CONNECTION_UNKNOWN &&
792 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET && 827 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET &&
793 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) { 828 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) {
794 RecordExternalEstimateProviderMetrics( 829 RecordExternalEstimateProviderMetrics(
795 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED); 830 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED);
796 external_estimate_provider_->Update(); 831 external_estimate_provider_->Update();
797 } 832 }
798
799 // Read any cached estimates for the new network. If cached estimates are
800 // unavailable, add the default estimates.
801 if (!ReadCachedNetworkQualityEstimate())
802 AddDefaultEstimates();
803 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality();
804 throughput_analyzer_->OnConnectionTypeChanged();
805 MaybeRecomputeEffectiveConnectionType();
806 UpdateSignalStrength();
807 } 833 }
808 834
809 void NetworkQualityEstimator::UpdateSignalStrength() { 835 void NetworkQualityEstimator::UpdateSignalStrength() {
810 #if defined(OS_ANDROID) 836 #if defined(OS_ANDROID)
811 int32_t signal_strength_dbm; 837 int32_t signal_strength_dbm;
812 if (!android::cellular_signal_strength::GetSignalStrengthDbm( 838 if (!android::cellular_signal_strength::GetSignalStrengthDbm(
813 &signal_strength_dbm)) { 839 &signal_strength_dbm)) {
814 return; 840 return;
815 } 841 }
816 min_signal_strength_since_connection_change_ = std::min( 842 min_signal_strength_since_connection_change_ = std::min(
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 void NetworkQualityEstimator::OnUpdatedEstimateAvailable( 1282 void NetworkQualityEstimator::OnUpdatedEstimateAvailable(
1257 const base::TimeDelta& rtt, 1283 const base::TimeDelta& rtt,
1258 int32_t downstream_throughput_kbps, 1284 int32_t downstream_throughput_kbps,
1259 int32_t upstream_throughput_kbps) { 1285 int32_t upstream_throughput_kbps) {
1260 DCHECK(thread_checker_.CalledOnValidThread()); 1286 DCHECK(thread_checker_.CalledOnValidThread());
1261 DCHECK(external_estimate_provider_); 1287 DCHECK(external_estimate_provider_);
1262 1288
1263 RecordExternalEstimateProviderMetrics( 1289 RecordExternalEstimateProviderMetrics(
1264 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK); 1290 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK);
1265 1291
1292 external_estimate_provider_quality_ = nqe::internal::NetworkQuality();
1293
1266 if (rtt > base::TimeDelta()) { 1294 if (rtt > base::TimeDelta()) {
1267 RecordExternalEstimateProviderMetrics( 1295 RecordExternalEstimateProviderMetrics(
1268 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE); 1296 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE);
1269 UMA_HISTOGRAM_TIMES("NQE.ExternalEstimateProvider.RTT", rtt); 1297 UMA_HISTOGRAM_TIMES("NQE.ExternalEstimateProvider.RTT", rtt);
1270 rtt_observations_.AddObservation( 1298 rtt_observations_.AddObservation(
1271 RttObservation(rtt, tick_clock_->NowTicks(), 1299 RttObservation(rtt, tick_clock_->NowTicks(),
1272 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE)); 1300 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE));
1301 external_estimate_provider_quality_.set_http_rtt(rtt);
1273 } 1302 }
1274 1303
1275 if (downstream_throughput_kbps > 0) { 1304 if (downstream_throughput_kbps > 0) {
1276 RecordExternalEstimateProviderMetrics( 1305 RecordExternalEstimateProviderMetrics(
1277 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE); 1306 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE);
1278 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth", 1307 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth",
1279 downstream_throughput_kbps); 1308 downstream_throughput_kbps);
1280 downstream_throughput_kbps_observations_.AddObservation( 1309 downstream_throughput_kbps_observations_.AddObservation(
1281 ThroughputObservation( 1310 ThroughputObservation(
1282 downstream_throughput_kbps, tick_clock_->NowTicks(), 1311 downstream_throughput_kbps, tick_clock_->NowTicks(),
1283 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE)); 1312 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE));
1313 external_estimate_provider_quality_.set_downstream_throughput_kbps(
1314 downstream_throughput_kbps);
1284 } 1315 }
1285 } 1316 }
1286 1317
1287 // static 1318 // static
1288 const char* NetworkQualityEstimator::GetNameForEffectiveConnectionType( 1319 const char* NetworkQualityEstimator::GetNameForEffectiveConnectionType(
1289 EffectiveConnectionType type) { 1320 EffectiveConnectionType type) {
1290 switch (type) { 1321 switch (type) {
1291 case EFFECTIVE_CONNECTION_TYPE_UNKNOWN: 1322 case EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
1292 return "Unknown"; 1323 return "Unknown";
1293 case EFFECTIVE_CONNECTION_TYPE_OFFLINE: 1324 case EFFECTIVE_CONNECTION_TYPE_OFFLINE:
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 NotifyObserversOfEffectiveConnectionTypeChanged() { 1503 NotifyObserversOfEffectiveConnectionTypeChanged() {
1473 DCHECK(thread_checker_.CalledOnValidThread()); 1504 DCHECK(thread_checker_.CalledOnValidThread());
1474 1505
1475 // TODO(tbansal): Add hysteresis in the notification. 1506 // TODO(tbansal): Add hysteresis in the notification.
1476 FOR_EACH_OBSERVER( 1507 FOR_EACH_OBSERVER(
1477 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, 1508 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_,
1478 OnEffectiveConnectionTypeChanged(effective_connection_type_)); 1509 OnEffectiveConnectionTypeChanged(effective_connection_type_));
1479 } 1510 }
1480 1511
1481 } // namespace net 1512 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698