Chromium Code Reviews| Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_experiments_stats.h |
| diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_experiments_stats.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_experiments_stats.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5aeb3e960d26f0ac2a5976beac0f6cb6f09ecd24 |
| --- /dev/null |
| +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_experiments_stats.h |
| @@ -0,0 +1,194 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_EXPERIMENTS_STATS_H_ |
| +#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_EXPERIMENTS_STATS_H_ |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "base/time/time.h" |
| +#include "base/timer/timer.h" |
| +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics.h" |
| + |
| +class PrefService; |
| + |
| +namespace base { |
| +class HistogramBase; |
| +class Value; |
| +} |
| + |
| +namespace net { |
| +class URLRequest; |
| +} |
| + |
| +namespace data_reduction_proxy { |
| + |
| +namespace experiments { |
| + |
| +// The name of the trial group for measuring lost bytes during fetching the |
| +// configuration. |
| +extern const char kConfigFetchTrialGroup[]; |
| + |
| +// The config retrieval round trip time is calculated as: |
| +// (previous base) * (multiplier) + increment. |
| +// Multipler is >= 1. Increment is >= 0. |
| +// The name of the param prefix for determining the base round trip time in |
| +// milliseconds for simulating a configuration fetch. |
| +extern const char kConfigRoundtripMillisecondsBaseParam[]; |
| + |
| +// The name of the param prefix for determining the base round trip time in |
| +// milliseconds for simulating a configuration fetch. |
| +extern const char kConfigRoundtripMultiplierParam[]; |
| + |
| +// The name of the param prefix for determining the base round trip time in |
| +// milliseconds for simulating a configuration fetch. |
| +extern const char kConfigRoundtripMillisecondsIncrementParam[]; |
| + |
| +// The name of the param for determining the expiration interval of the |
| +// configuration in seconds. |
| +extern const char kConfigExpirationSecondsParam[]; |
| + |
| +// The name of the param for determining if the config should be |
| +// considered |
|
sclittle
2015/05/12 19:32:25
nit: line wrapping
jeremyim
2015/05/12 20:38:29
Done.
|
| +// stale on startup (regardless of whether it is stale or not). |
| +extern const char kConfigAlwaysStaleParam[]; |
| + |
| +// The number of seconds by which the expiration interval exceeds the refresh |
| +// interval so that we maintain a valid configuration. |
| +extern const int kConfigFetchBufferSeconds; |
| + |
| +} // namespace experiments |
| + |
| +typedef base::Callback<void(const std::string&, int64)> Int64ValueSetter; |
| + |
| +// Collects statistics specific to experiments of which a client may be part. |
| +// Any calls into this class should be as lightweight as possible such that if |
| +// no experiments are being performed, there should be minimal code being |
| +// executed. |
| +// Currently supported experiments are: |
| +// - Measuring potentially uncompressed bytes during simulated config retrieval. |
| +class DataReductionProxyExperimentsStats { |
| + public: |
| + enum ConfigState { |
| + VALID = 0, |
| + RETRIEVING = 1, |
| + EXPIRED = 2, |
| + }; |
| + |
| + // Parameters for setting up an experiment to measure potentially uncompressed |
| + // bytes during the retrieval of the Data Reduction Proxy configuration. |
| + class ConfigRetrievalParams { |
| + public: |
| + class Variation { |
|
sclittle
2015/05/12 19:32:25
Could you add a comment describing what this class
jeremyim
2015/05/12 20:38:29
Done.
|
| + public: |
| + Variation(int index, const base::Time& simulated_config_retrieved); |
|
sclittle
2015/05/12 19:32:25
optional nit: This is three levels deep of classes
jeremyim
2015/05/12 20:38:29
Done.
|
| + |
| + // Returns the current state of the Data Reduction Proxy configuration. |
| + // Virtual for testing. |
| + virtual ConfigState GetState(const base::Time& request_time, |
| + const base::Time& config_expiration) const; |
| + |
| + void RecordStats(int64 received_content_length, |
| + int64 original_content_length) const; |
| + |
| + private: |
| + // The time at which the simulated Data Reduction Proxy configuration is |
| + // considered to have been received. |
| + base::Time simulated_config_retrieved_; |
| + |
| + // Histograms for recording stats. |
| + base::HistogramBase* lost_bytes_ocl_; |
| + base::HistogramBase* lost_bytes_rcl_; |
| + base::HistogramBase* lost_bytes_diff_; |
| + }; |
| + |
| + static scoped_ptr<ConfigRetrievalParams> Create(PrefService* pref_service); |
| + |
| + virtual ~ConfigRetrievalParams(); |
| + |
| + void RecordStats(const base::Time& request_time, |
| + int64 received_content_length, |
| + int64 original_content_length) const; |
| + |
| + // Simulates retrieving a new configuration. |
| + void RefreshConfig(); |
| + |
| + // Returns the expiration time of the current configuration. |
| + const base::Time& config_expiration() const { return config_expiration_; } |
| + |
| + // Returns how often the configuration should be retrieved. |
| + const base::TimeDelta& refresh_interval() const { |
| + return config_refresh_interval_; |
| + } |
| + |
| + private: |
| + friend class DataReductionProxyExperimentsStatsTest; |
| + |
| + ConfigRetrievalParams(const std::vector<Variation>& variations, |
| + const base::Time& config_expiration, |
| + const base::TimeDelta& config_refresh_interval); |
| + |
| + // The time at which the simulated Data Reduction Proxy configuration |
| + // expires. |
| + base::Time config_expiration_; |
| + |
| + // The duration for which a Data Reduction Proxy configuration is considered |
| + // valid. |
| + base::TimeDelta config_expiration_interval_; |
| + |
| + // The duration after which a simulated retrieval of a new Data Reduction |
| + // Proxy configuration should be performed. |
| + base::TimeDelta config_refresh_interval_; |
| + |
| + // The different variations on roundtrip time that can take place. |
| + std::vector<Variation> variations_; |
| + }; |
| + |
| + DataReductionProxyExperimentsStats(Int64ValueSetter value_setter); |
|
sclittle
2015/05/12 19:32:25
nit: const Int64ValueSetter&
jeremyim
2015/05/12 20:38:29
Done.
|
| + virtual ~DataReductionProxyExperimentsStats(); |
| + |
| + // Initializes |this| on the UI thread. |
| + void InitializeOnUIThread( |
| + scoped_ptr<ConfigRetrievalParams> config_retrieval_params); |
| + |
| + // Initializes |this| on the IO thread. |
| + void InitializeOnIOThread(); |
| + |
| + // Collect received bytes for the experiment. |
| + void RecordBytes(const base::Time& request_time, |
| + DataReductionProxyRequestType request_type, |
| + int64 received_content_length, |
| + int64 original_content_length); |
| + |
| + private: |
| + // Updates the simulated expiration of the Data Reduction Proxy configuration |
| + // if |config_retrieval_| is set. |
| + void UpdateSimulatedConfig(); |
| + |
| + // Allows an experiment to persist data to preferences. |
| + Int64ValueSetter value_setter_; |
| + |
| + // Enables measuring of potentially uncompressed bytes during a simulated Data |
| + // Reduction Proxy configuration retrieval. |
| + scoped_ptr<ConfigRetrievalParams> config_retrieval_params_; |
| + |
| + // If set, periodically updates the simulated expiration of the Data Reduction |
| + // Proxy configuration. |
| + base::RepeatingTimer<DataReductionProxyExperimentsStats> config_refresh_time_; |
| + |
| + // Enforce usage on the IO thread. |
| + base::ThreadChecker thread_checker_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DataReductionProxyExperimentsStats); |
| +}; |
| + |
| +} // namespace data_reduction_proxy |
| + |
| +#endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_EXPERIMENTS_STATS_H_ |