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

Unified Diff: net/nqe/network_quality_estimator.cc

Issue 2421063002: NQE: Separate out params to a different file (Closed)
Patch Set: Addressed bengr comments Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_params.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/nqe/network_quality_estimator.cc
diff --git a/net/nqe/network_quality_estimator.cc b/net/nqe/network_quality_estimator.cc
index fc6ed937aeb11eee266a16b302954de116f77aea..6fcc6ee171a5a6ee3846f4c287ecc56b4867d2e9 100644
--- a/net/nqe/network_quality_estimator.cc
+++ b/net/nqe/network_quality_estimator.cc
@@ -30,6 +30,7 @@
#include "net/base/network_interfaces.h"
#include "net/base/url_util.h"
#include "net/http/http_status_code.h"
+#include "net/nqe/network_quality_estimator_params.h"
#include "net/nqe/socket_watcher_factory.h"
#include "net/nqe/throughput_analyzer.h"
#include "net/url_request/url_request.h"
@@ -43,92 +44,6 @@
namespace {
-// Default value of the half life (in seconds) for computing time weighted
-// percentiles. Every half life, the weight of all observations reduces by
-// half. Lowering the half life would reduce the weight of older values faster.
-const int kDefaultHalfLifeSeconds = 60;
-
-// Name of the variation parameter that holds the value of the half life (in
-// seconds) of the observations.
-const char kHalfLifeSecondsParamName[] = "HalfLifeSeconds";
-
-// Returns a descriptive name corresponding to |connection_type|.
-const char* GetNameForConnectionType(
- net::NetworkChangeNotifier::ConnectionType connection_type) {
- switch (connection_type) {
- case net::NetworkChangeNotifier::CONNECTION_UNKNOWN:
- return "Unknown";
- case net::NetworkChangeNotifier::CONNECTION_ETHERNET:
- return "Ethernet";
- case net::NetworkChangeNotifier::CONNECTION_WIFI:
- return "WiFi";
- case net::NetworkChangeNotifier::CONNECTION_2G:
- return "2G";
- case net::NetworkChangeNotifier::CONNECTION_3G:
- return "3G";
- case net::NetworkChangeNotifier::CONNECTION_4G:
- return "4G";
- case net::NetworkChangeNotifier::CONNECTION_NONE:
- return "None";
- case net::NetworkChangeNotifier::CONNECTION_BLUETOOTH:
- return "Bluetooth";
- default:
- NOTREACHED();
- break;
- }
- return "";
-}
-
-// Suffix of the name of the variation parameter that contains the default RTT
-// observation (in milliseconds). Complete name of the variation parameter
-// would be |ConnectionType|.|kDefaultRTTMsecObservationSuffix| where
-// |ConnectionType| is from |kConnectionTypeNames|. For example, variation
-// parameter for Wi-Fi would be "WiFi.DefaultMedianRTTMsec".
-const char kDefaultRTTMsecObservationSuffix[] = ".DefaultMedianRTTMsec";
-
-// Suffix of the name of the variation parameter that contains the default
-// downstream throughput observation (in Kbps). Complete name of the variation
-// parameter would be |ConnectionType|.|kDefaultKbpsObservationSuffix| where
-// |ConnectionType| is from |kConnectionTypeNames|. For example, variation
-// parameter for Wi-Fi would be "WiFi.DefaultMedianKbps".
-const char kDefaultKbpsObservationSuffix[] = ".DefaultMedianKbps";
-
-// Suffix of the name of the variation parameter that contains the threshold
-// HTTP RTTs (in milliseconds) for different effective connection types.
-// Complete name of the variation parameter would be
-// |EffectiveConnectionType|.|kThresholdURLRTTMsecSuffix|.
-const char kThresholdURLRTTMsecSuffix[] = ".ThresholdMedianHttpRTTMsec";
-
-// Suffix of the name of the variation parameter that contains the threshold
-// transport RTTs (in milliseconds) for different effective connection types.
-// Complete name of the variation parameter would be
-// |EffectiveConnectionType|.|kThresholdTransportRTTMsecSuffix|.
-const char kThresholdTransportRTTMsecSuffix[] =
- ".ThresholdMedianTransportRTTMsec";
-
-// Suffix of the name of the variation parameter that contains the threshold
-// downlink throughput (in kbps) for different effective connection types.
-// Complete name of the variation parameter would be
-// |EffectiveConnectionType|.|kThresholdKbpsSuffix|.
-const char kThresholdKbpsSuffix[] = ".ThresholdMedianKbps";
-
-// Computes and returns the weight multiplier per second.
-// |variation_params| is the map containing all field trial parameters
-// related to NetworkQualityEstimator field trial.
-double GetWeightMultiplierPerSecond(
- const std::map<std::string, std::string>& variation_params) {
- int half_life_seconds = kDefaultHalfLifeSeconds;
- int32_t variations_value = 0;
- auto it = variation_params.find(kHalfLifeSecondsParamName);
- if (it != variation_params.end() &&
- base::StringToInt(it->second, &variations_value) &&
- variations_value >= 1) {
- half_life_seconds = variations_value;
- }
- DCHECK_GT(half_life_seconds, 0);
- return exp(log(0.5) / half_life_seconds);
-}
-
// Returns the histogram that should be used to record the given statistic.
// |max_limit| is the maximum value that can be stored in the histogram.
base::HistogramBase* GetHistogram(
@@ -139,66 +54,11 @@ base::HistogramBase* GetHistogram(
DCHECK_GT(max_limit, kLowerLimit);
const size_t kBucketCount = 50;
- // Prefix of network quality estimator histograms.
- const char prefix[] = "NQE.";
return base::Histogram::FactoryGet(
- prefix + statistic_name + GetNameForConnectionType(type), kLowerLimit,
- max_limit, kBucketCount, base::HistogramBase::kUmaTargetedHistogramFlag);
-}
-
-// Sets |variations_value| to the value of |parameter_name| read from
-// |variation_params|. If the value is unavailable from |variation_params|, then
-// |variations_value| is set to |default_value|.
-void GetValueForVariationParam(
- const std::map<std::string, std::string>& variation_params,
- const std::string& parameter_name,
- int64_t default_value,
- int64_t* variations_value) {
- const auto it = variation_params.find(parameter_name);
- if (it != variation_params.end() &&
- base::StringToInt64(it->second, variations_value)) {
- return;
- }
- *variations_value = default_value;
-}
-
-// Returns the variation value for |parameter_name|. If the value is
-// unavailable, |default_value| is returned.
-double GetDoubleValueForVariationParamWithDefaultValue(
- const std::map<std::string, std::string>& variation_params,
- const std::string& parameter_name,
- double default_value) {
- const auto it = variation_params.find(parameter_name);
- if (it == variation_params.end())
- return default_value;
-
- double variations_value = default_value;
- if (!base::StringToDouble(it->second, &variations_value))
- return default_value;
- return variations_value;
-}
-
-// Returns the variation value for |parameter_name|. If the value is
-// unavailable, |default_value| is returned.
-std::string GetStringValueForVariationParamWithDefaultValue(
- const std::map<std::string, std::string>& variation_params,
- const std::string& parameter_name,
- const std::string& default_value) {
- const auto it = variation_params.find(parameter_name);
- if (it == variation_params.end())
- return default_value;
- return it->second;
-}
-
-// Returns the algorithm that should be used for computing effective connection
-// type based on field trial params. Returns an empty string if a valid
-// algorithm paramter is not present in the field trial params.
-std::string GetEffectiveConnectionTypeAlgorithm(
- const std::map<std::string, std::string>& variation_params) {
- const auto it = variation_params.find("effective_connection_type_algorithm");
- if (it == variation_params.end())
- return std::string();
- return it->second;
+ "NQE." + statistic_name +
+ net::nqe::internal::GetNameForConnectionType(type),
+ kLowerLimit, max_limit, kBucketCount,
+ base::HistogramBase::kUmaTargetedHistogramFlag);
}
net::NetworkQualityObservationSource ProtocolSourceToObservationSource(
@@ -367,13 +227,16 @@ NetworkQualityEstimator::NetworkQualityEstimator(
use_localhost_requests_(use_local_host_requests_for_tests),
use_small_responses_(use_smaller_responses_for_tests),
weight_multiplier_per_second_(
- GetWeightMultiplierPerSecond(variation_params)),
+ nqe::internal::GetWeightMultiplierPerSecond(variation_params)),
effective_connection_type_algorithm_(
- algorithm_name_to_enum_.find(GetEffectiveConnectionTypeAlgorithm(
- variation_params)) == algorithm_name_to_enum_.end()
+ algorithm_name_to_enum_.find(
+ net::nqe::internal::GetEffectiveConnectionTypeAlgorithm(
+ variation_params)) == algorithm_name_to_enum_.end()
? kDefaultEffectiveConnectionTypeAlgorithm
: algorithm_name_to_enum_
- .find(GetEffectiveConnectionTypeAlgorithm(variation_params))
+ .find(
+ net::nqe::internal::GetEffectiveConnectionTypeAlgorithm(
+ variation_params))
->second),
tick_clock_(new base::DefaultTickClock()),
last_connection_change_(tick_clock_->NowTicks()),
@@ -396,27 +259,13 @@ NetworkQualityEstimator::NetworkQualityEstimator(
min_signal_strength_since_connection_change_(INT32_MAX),
max_signal_strength_since_connection_change_(INT32_MIN),
correlation_uma_logging_probability_(
- GetDoubleValueForVariationParamWithDefaultValue(
- variation_params,
- "correlation_logging_probability",
- 0.0)),
+ nqe::internal::correlation_uma_logging_probability(variation_params)),
forced_effective_connection_type_set_(
- !GetStringValueForVariationParamWithDefaultValue(
- variation_params,
- "force_effective_connection_type",
- "")
- .empty()),
+ nqe::internal::forced_effective_connection_type_set(
+ variation_params)),
+ forced_effective_connection_type_(
+ nqe::internal::forced_effective_connection_type(variation_params)),
weak_ptr_factory_(this) {
- static_assert(kDefaultHalfLifeSeconds > 0,
- "Default half life duration must be > 0");
- static_assert(kMinimumRTTVariationParameterMsec > 0 &&
- kMinimumRTTVariationParameterMsec >
- nqe::internal::INVALID_RTT_THROUGHPUT,
- "kMinimumRTTVariationParameterMsec is set incorrectly");
- static_assert(kMinimumThroughputVariationParameterKbps > 0 &&
- kMinimumThroughputVariationParameterKbps >
- nqe::internal::kInvalidThroughput,
- "kMinimumThroughputVariationParameterKbps is set incorrectly");
// None of the algorithms can have an empty name.
DCHECK(algorithm_name_to_enum_.end() ==
algorithm_name_to_enum_.find(std::string()));
@@ -427,12 +276,9 @@ NetworkQualityEstimator::NetworkQualityEstimator(
DCHECK_NE(EffectiveConnectionTypeAlgorithm::
EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST,
effective_connection_type_algorithm_);
- DCHECK_LE(0.0, correlation_uma_logging_probability_);
- DCHECK_GE(1.0, correlation_uma_logging_probability_);
network_quality_store_.reset(new nqe::internal::NetworkQualityStore());
ObtainOperatingParams(variation_params);
- ObtainEffectiveConnectionTypeModelParams(variation_params);
NetworkChangeNotifier::AddConnectionTypeObserver(this);
if (external_estimate_provider_) {
RecordExternalEstimateProviderMetrics(
@@ -462,146 +308,15 @@ NetworkQualityEstimator::NetworkQualityEstimator(
accuracy_recording_intervals_.push_back(base::TimeDelta::FromSeconds(15));
accuracy_recording_intervals_.push_back(base::TimeDelta::FromSeconds(30));
accuracy_recording_intervals_.push_back(base::TimeDelta::FromSeconds(60));
-
- if (forced_effective_connection_type_set_) {
- std::string forced_value = GetStringValueForVariationParamWithDefaultValue(
- variation_params, "force_effective_connection_type",
- GetNameForEffectiveConnectionType(EFFECTIVE_CONNECTION_TYPE_UNKNOWN));
- DCHECK(!forced_value.empty());
- bool effective_connection_type_available =
- GetEffectiveConnectionTypeForName(forced_value,
- &forced_effective_connection_type_);
- DCHECK(effective_connection_type_available);
-
- // Silence unused variable warning in release builds.
- (void)effective_connection_type_available;
- }
}
void NetworkQualityEstimator::ObtainOperatingParams(
const std::map<std::string, std::string>& variation_params) {
DCHECK(thread_checker_.CalledOnValidThread());
-
- for (size_t i = 0; i <= NetworkChangeNotifier::CONNECTION_LAST; ++i) {
- NetworkChangeNotifier::ConnectionType type =
- static_cast<NetworkChangeNotifier::ConnectionType>(i);
- DCHECK_EQ(nqe::internal::InvalidRTT(), default_observations_[i].http_rtt());
- DCHECK_EQ(nqe::internal::InvalidRTT(),
- default_observations_[i].transport_rtt());
- DCHECK_EQ(nqe::internal::kInvalidThroughput,
- default_observations_[i].downstream_throughput_kbps());
- int32_t variations_value = kMinimumRTTVariationParameterMsec - 1;
- // Name of the parameter that holds the RTT value for this connection type.
- std::string rtt_parameter_name =
- std::string(GetNameForConnectionType(type))
- .append(kDefaultRTTMsecObservationSuffix);
- auto it = variation_params.find(rtt_parameter_name);
- if (it != variation_params.end() &&
- base::StringToInt(it->second, &variations_value) &&
- variations_value >= kMinimumRTTVariationParameterMsec) {
- default_observations_[i] = nqe::internal::NetworkQuality(
- base::TimeDelta::FromMilliseconds(variations_value),
- default_observations_[i].transport_rtt(),
- default_observations_[i].downstream_throughput_kbps());
- }
-
- variations_value = kMinimumThroughputVariationParameterKbps - 1;
- // Name of the parameter that holds the Kbps value for this connection
- // type.
- std::string kbps_parameter_name =
- std::string(GetNameForConnectionType(type))
- .append(kDefaultKbpsObservationSuffix);
- it = variation_params.find(kbps_parameter_name);
- if (it != variation_params.end() &&
- base::StringToInt(it->second, &variations_value) &&
- variations_value >= kMinimumThroughputVariationParameterKbps) {
- default_observations_[i] = nqe::internal::NetworkQuality(
- default_observations_[i].http_rtt(),
- default_observations_[i].transport_rtt(), variations_value);
- }
- }
-}
-
-void NetworkQualityEstimator::ObtainEffectiveConnectionTypeModelParams(
- const std::map<std::string, std::string>& variation_params) {
- DCHECK(thread_checker_.CalledOnValidThread());
-
- default_effective_connection_type_thresholds_
- [EFFECTIVE_CONNECTION_TYPE_SLOW_2G] = nqe::internal::NetworkQuality(
- // Set to 2010 milliseconds, which corresponds to the 33rd percentile
- // of 2G HTTP RTT observations on Android.
- base::TimeDelta::FromMilliseconds(2010),
- // Set to 1870 milliseconds, which corresponds to the 33rd percentile
- // of 2G transport RTT observations on Android.
- base::TimeDelta::FromMilliseconds(1870),
- nqe::internal::kInvalidThroughput);
-
- default_effective_connection_type_thresholds_[EFFECTIVE_CONNECTION_TYPE_2G] =
- nqe::internal::NetworkQuality(
- // Set to 1420 milliseconds, which corresponds to 50th percentile of
- // 2G
- // HTTP RTT observations on Android.
- base::TimeDelta::FromMilliseconds(1420),
- // Set to 1280 milliseconds, which corresponds to 50th percentile of
- // 2G
- // transport RTT observations on Android.
- base::TimeDelta::FromMilliseconds(1280),
- nqe::internal::kInvalidThroughput);
-
- default_effective_connection_type_thresholds_[EFFECTIVE_CONNECTION_TYPE_3G] =
- nqe::internal::NetworkQuality(
- // Set to 273 milliseconds, which corresponds to 50th percentile of
- // 3G HTTP RTT observations on Android.
- base::TimeDelta::FromMilliseconds(273),
- // Set to 204 milliseconds, which corresponds to 50th percentile of
- // 3G transport RTT observations on Android.
- base::TimeDelta::FromMilliseconds(204),
- nqe::internal::kInvalidThroughput);
-
- for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) {
- EffectiveConnectionType effective_connection_type =
- static_cast<EffectiveConnectionType>(i);
- DCHECK_EQ(nqe::internal::InvalidRTT(),
- connection_thresholds_[i].http_rtt());
- DCHECK_EQ(nqe::internal::InvalidRTT(),
- connection_thresholds_[i].transport_rtt());
- DCHECK_EQ(nqe::internal::kInvalidThroughput,
- connection_thresholds_[i].downstream_throughput_kbps());
- if (effective_connection_type == EFFECTIVE_CONNECTION_TYPE_UNKNOWN)
- continue;
-
- std::string connection_type_name = std::string(
- GetNameForEffectiveConnectionType(effective_connection_type));
-
- int64_t variations_value;
- GetValueForVariationParam(variation_params,
- connection_type_name + kThresholdURLRTTMsecSuffix,
- default_effective_connection_type_thresholds_[i]
- .http_rtt()
- .InMilliseconds(),
- &variations_value);
- connection_thresholds_[i].set_http_rtt(
- base::TimeDelta::FromMilliseconds(variations_value));
-
- GetValueForVariationParam(
- variation_params,
- connection_type_name + kThresholdTransportRTTMsecSuffix,
- default_effective_connection_type_thresholds_[i]
- .transport_rtt()
- .InMilliseconds(),
- &variations_value);
- connection_thresholds_[i].set_transport_rtt(
- base::TimeDelta::FromMilliseconds(variations_value));
-
- GetValueForVariationParam(variation_params,
- connection_type_name + kThresholdKbpsSuffix,
- default_effective_connection_type_thresholds_[i]
- .downstream_throughput_kbps(),
- &variations_value);
- connection_thresholds_[i].set_downstream_throughput_kbps(variations_value);
- DCHECK(i == 0 ||
- connection_thresholds_[i].IsFaster(connection_thresholds_[i - 1]));
- }
+ nqe::internal::ObtainDefaultObservations(variation_params,
+ default_observations_);
+ nqe::internal::ObtainEffectiveConnectionTypeModelParams(
+ variation_params, connection_thresholds_);
}
void NetworkQualityEstimator::AddDefaultEstimates() {
@@ -1222,7 +937,7 @@ void NetworkQualityEstimator::RecordMetricsOnMainFrameRequest() const {
base::HistogramBase* effective_connection_type_histogram =
base::Histogram::FactoryGet(
std::string("NQE.MainFrame.EffectiveConnectionType.") +
- GetNameForConnectionType(current_network_id_.type),
+ nqe::internal::GetNameForConnectionType(current_network_id_.type),
0, EFFECTIVE_CONNECTION_TYPE_LAST,
EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */,
base::HistogramBase::kUmaTargetedHistogramFlag);
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_params.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698