Chromium Code Reviews| Index: chrome/browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer.cc |
| diff --git a/chrome/browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer.cc b/chrome/browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer.cc |
| index 50e1cdbaa1ab92012a541d2ad8bb643fb5b59d33..b75546fc6f4ff114370b4b22287e8edd88517a05 100644 |
| --- a/chrome/browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer.cc |
| +++ b/chrome/browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer.cc |
| @@ -6,7 +6,9 @@ |
| #include <string> |
| +#include "base/metrics/histogram_macros.h" |
| #include "base/optional.h" |
| +#include "base/strings/string_piece.h" |
| #include "base/time/time.h" |
| #include "chrome/browser/loader/chrome_navigation_data.h" |
| #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
| @@ -29,22 +31,24 @@ namespace data_reduction_proxy { |
| namespace { |
| +std::string GetConstHistogramWithSuffix(const char* suffix) { |
| + return std::string(internal::kHistogramDataReductionProxyPrefix) |
| + .append(suffix); |
| +} |
| + |
| // A macro is needed because PAGE_LOAD_HISTOGRAM creates a static instance of |
| // the histogram. A distinct histogram is needed for each place that calls |
| // RECORD_HISTOGRAMS_FOR_SUFFIX. |event| is the timing event representing when |
| // |value| became available. |
| -#define RECORD_HISTOGRAMS_FOR_SUFFIX(data, value, histogram_suffix) \ |
| - do { \ |
| - PAGE_LOAD_HISTOGRAM( \ |
| - std::string(internal::kHistogramDataReductionProxyPrefix) \ |
| - .append(histogram_suffix), \ |
| - value); \ |
| - if (data->lofi_requested()) { \ |
| - PAGE_LOAD_HISTOGRAM( \ |
| - std::string(internal::kHistogramDataReductionProxyLoFiOnPrefix) \ |
| - .append(histogram_suffix), \ |
| - value); \ |
| - } \ |
| +#define RECORD_HISTOGRAMS_FOR_SUFFIX(data, value, histogram_suffix) \ |
| + do { \ |
| + PAGE_LOAD_HISTOGRAM(GetConstHistogramWithSuffix(histogram_suffix), value); \ |
| + if (data->lofi_requested()) { \ |
| + PAGE_LOAD_HISTOGRAM( \ |
| + std::string(internal::kHistogramDataReductionProxyLoFiOnPrefix) \ |
| + .append(histogram_suffix), \ |
| + value); \ |
| + } \ |
| } while (false) |
| } // namespace |
| @@ -75,10 +79,32 @@ const char kHistogramParseBlockedOnScriptLoadSuffix[] = |
| "ParseTiming.ParseBlockedOnScriptLoad"; |
| const char kHistogramParseDurationSuffix[] = "ParseTiming.ParseDuration"; |
| +const char kRequestsPercentProxied[] = |
| + "Experimental.Requests.Network.PercentProxied"; |
| +const char kBytesPercentProxied[] = "Experimental.Bytes.Network.PercentProxied"; |
| +const char kBytesCompressionRatio[] = |
| + "Experimental.Bytes.Network.CompressionRatio"; |
| +const char kBytesInflationPercent[] = |
| + "Experimental.Bytes.Network.InflationPercent"; |
| +const char kNetworkRequests[] = "Experimental.Requests.Network"; |
| +const char kRequestsProxied[] = "Experimental.Requests.Network.Proxied"; |
| +const char kRequestsNotProxied[] = "Experimental.Requests.Network.NonProxied"; |
| +const char kNetworkBytes[] = "Experimental.Bytes.Network"; |
| +const char kBytesProxied[] = "Experimental.Bytes.Network.Proxied"; |
| +const char kBytesNotProxied[] = "Experimental.Bytes.Network.NonProxied"; |
| +const char kBytesOriginal[] = "Experimental.Bytes.Network.Original"; |
| +const char kBytesSavings[] = "Experimental.Bytes.Network.Savings"; |
| +const char kBytesInflation[] = "Experimental.Bytes.Network.Inflation"; |
| + |
| } // namespace internal |
| DataReductionProxyMetricsObserver::DataReductionProxyMetricsObserver() |
| - : browser_context_(nullptr) {} |
| + : browser_context_(nullptr), |
| + num_data_reduction_proxy_requests_(0), |
| + num_network_requests_(0), |
| + original_network_bytes_(0), |
| + network_bytes_proxied_(0), |
| + network_bytes_(0) {} |
| DataReductionProxyMetricsObserver::~DataReductionProxyMetricsObserver() {} |
| @@ -128,6 +154,7 @@ page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
| DataReductionProxyMetricsObserver::OnHidden( |
| const page_load_metrics::PageLoadTiming& timing, |
| const page_load_metrics::PageLoadExtraInfo& info) { |
| + RecordPageSizeUMA(); |
| SendPingback(timing, info); |
| return STOP_OBSERVING; |
| } |
| @@ -140,6 +167,7 @@ DataReductionProxyMetricsObserver::FlushMetricsOnAppEnterBackground( |
| // app is about to be backgrounded, as part of the Activity.onPause() |
| // flow. After this method is invoked, Chrome may be killed without further |
| // notification, so we send a pingback with data collected up to this point. |
| + RecordPageSizeUMA(); |
| SendPingback(timing, info); |
| return STOP_OBSERVING; |
| } |
| @@ -147,9 +175,101 @@ DataReductionProxyMetricsObserver::FlushMetricsOnAppEnterBackground( |
| void DataReductionProxyMetricsObserver::OnComplete( |
| const page_load_metrics::PageLoadTiming& timing, |
| const page_load_metrics::PageLoadExtraInfo& info) { |
| + RecordPageSizeUMA(); |
| SendPingback(timing, info); |
| } |
| +void DataReductionProxyMetricsObserver::RecordPageSizeUMA() const { |
| + // If the first request didn't complete, don't record UMA. |
| + if (num_network_requests_ == 0) { |
|
Alexei Svitkine (slow)
2017/01/19 20:12:46
Nit: No {}'s
RyanSturm
2017/01/19 20:43:04
Done.
|
| + return; |
| + } |
| + |
| + // TODO(ryansturm): Evaluate if any of the below histograms are unncessary |
| + // once data is available. crbug.com/682782 |
| + |
| + // The percent of requests that went through the data reduction proxy. |
| + UMA_HISTOGRAM_PERCENTAGE( |
| + GetConstHistogramWithSuffix(internal::kRequestsPercentProxied), |
| + (100 * num_data_reduction_proxy_requests_) / num_network_requests_); |
|
Alexei Svitkine (slow)
2017/01/19 20:12:46
Nit: Add the static_cast<int>() cast here if you'r
RyanSturm
2017/01/19 20:43:04
I only want to cast int64_t->int, and this (and ot
|
| + |
| + // The percent of bytes that went through the data reduction proxy. |
| + if (network_bytes_ > 0) { |
| + UMA_HISTOGRAM_PERCENTAGE( |
| + GetConstHistogramWithSuffix(internal::kBytesPercentProxied), |
| + static_cast<int>((100 * network_bytes_proxied_) / network_bytes_)); |
| + } |
| + |
| + // If the data reduction proxy caused savings, record the compression ratio; |
| + // otherwise, record the inflation ratio. |
| + if (original_network_bytes_ > 0 && |
| + original_network_bytes_ >= network_bytes_) { |
| + UMA_HISTOGRAM_PERCENTAGE( |
| + GetConstHistogramWithSuffix(internal::kBytesCompressionRatio), |
| + static_cast<int>((100 * network_bytes_) / original_network_bytes_)); |
| + } else if (original_network_bytes_ > 0) { |
| + // Inflation should never be above one hundred percent. |
| + UMA_HISTOGRAM_PERCENTAGE( |
| + GetConstHistogramWithSuffix(internal::kBytesInflationPercent), |
| + static_cast<int>((100 * network_bytes_) / original_network_bytes_ - |
| + 100)); |
| + } |
| + |
| + // Record the number of network requests seen. |
| + UMA_HISTOGRAM_COUNTS_10000( |
| + GetConstHistogramWithSuffix(internal::kNetworkRequests), |
| + num_network_requests_); |
| + |
| + // Record the number of requests that used data reduction proxy. |
| + UMA_HISTOGRAM_COUNTS_10000( |
| + GetConstHistogramWithSuffix(internal::kRequestsProxied), |
| + num_data_reduction_proxy_requests_); |
| + |
| + // Record the number of requests that did not use data reduction proxy. |
| + UMA_HISTOGRAM_COUNTS_10000( |
| + GetConstHistogramWithSuffix(internal::kRequestsNotProxied), |
| + num_network_requests_ - num_data_reduction_proxy_requests_); |
| + |
| + // Record the total KB of network bytes. Capped at 500 MB. |
| + UMA_HISTOGRAM_CUSTOM_COUNTS( |
| + GetConstHistogramWithSuffix(internal::kNetworkBytes), |
| + static_cast<int>(network_bytes_ / 1024), 1, 500 * 1024, 50); |
|
Alexei Svitkine (slow)
2017/01/19 20:12:46
Since you're re-using these macro params for all o
RyanSturm
2017/01/19 20:43:04
Done.
|
| + |
| + // Record the total amount of bytes that went through the data reduction |
| + // proxy. Capped at 500 MB. |
| + UMA_HISTOGRAM_CUSTOM_COUNTS( |
| + GetConstHistogramWithSuffix(internal::kBytesProxied), |
| + static_cast<int>(network_bytes_proxied_ / 1024), 1, 500 * 1024, 50); |
| + |
| + // Record the total amount of bytes that did not go through the data reduction |
| + // proxy. Capped at 500 MB. |
| + UMA_HISTOGRAM_CUSTOM_COUNTS( |
| + GetConstHistogramWithSuffix(internal::kBytesNotProxied), |
| + static_cast<int>((network_bytes_ - network_bytes_proxied_) / 1024), 1, |
| + 500 * 1024, 50); |
| + |
| + // Record the total KB of network bytes that the user would have seen without |
| + // using data reduction proxy. Capped at 500 MB. |
| + UMA_HISTOGRAM_CUSTOM_COUNTS( |
| + GetConstHistogramWithSuffix(internal::kBytesOriginal), |
| + static_cast<int>(original_network_bytes_ / 1024), 1, 500 * 1024, 50); |
| + |
| + // Record the savings the user saw by using data reduction proxy. If there was |
| + // inflation instead, record that. Capped at 500 MB. |
| + if (network_bytes_ <= original_network_bytes_) { |
| + UMA_HISTOGRAM_CUSTOM_COUNTS( |
| + GetConstHistogramWithSuffix(internal::kBytesSavings), |
| + static_cast<int>((original_network_bytes_ - network_bytes_) / 1024), 1, |
| + 500 * 1024, 50); |
| + } else { |
| + UMA_HISTOGRAM_CUSTOM_COUNTS( |
| + GetConstHistogramWithSuffix(internal::kBytesInflation), |
| + static_cast<int>((network_bytes_proxied_ - original_network_bytes_) / |
| + 1024), |
| + 1, 500 * 1024, 50); |
| + } |
| +} |
| + |
| void DataReductionProxyMetricsObserver::SendPingback( |
| const page_load_metrics::PageLoadTiming& timing, |
| const page_load_metrics::PageLoadExtraInfo& info) { |
| @@ -284,6 +404,19 @@ void DataReductionProxyMetricsObserver::OnParseStop( |
| internal::kHistogramParseBlockedOnScriptLoadSuffix); |
| } |
| +void DataReductionProxyMetricsObserver::OnLoadedResource( |
| + const page_load_metrics::ExtraRequestInfo& extra_request_info) { |
| + if (extra_request_info.was_cached) |
| + return; |
| + original_network_bytes_ += extra_request_info.original_network_content_length; |
| + network_bytes_ += extra_request_info.raw_body_bytes; |
| + num_network_requests_++; |
| + if (!extra_request_info.data_reduction_proxy_used) |
| + return; |
| + num_data_reduction_proxy_requests_++; |
| + network_bytes_proxied_ += extra_request_info.raw_body_bytes; |
| +} |
| + |
| DataReductionProxyPingbackClient* |
| DataReductionProxyMetricsObserver::GetPingbackClient() const { |
| return DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |