| 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..016e3bc51d15807d711fc900ae683829f66934a8 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,24 +31,34 @@ namespace data_reduction_proxy {
|
|
|
| namespace {
|
|
|
| +// Appends |suffix| to |kHistogramDataReductionProxyPrefix| and returns it as a
|
| +// string.
|
| +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)
|
|
|
| +// Records the kilobytes (i.e., bytes / 1024) to |histogram_name| in a histogram
|
| +// with 50 buckets capped at 500 MB.
|
| +#define RECORD_KILOBYTES_HISTOGRAM(histogram_name, bytes) \
|
| + UMA_HISTOGRAM_CUSTOM_COUNTS( \
|
| + histogram_name, static_cast<int>((bytes) / 1024), 1, 500 * 1024, 50)
|
| +
|
| } // namespace
|
|
|
| namespace internal {
|
| @@ -75,10 +87,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 +162,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 +175,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 +183,95 @@ 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)
|
| + 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_);
|
| +
|
| + // 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.
|
| + RECORD_KILOBYTES_HISTOGRAM(
|
| + GetConstHistogramWithSuffix(internal::kNetworkBytes), network_bytes_);
|
| +
|
| + // Record the total amount of bytes that went through the data reduction
|
| + // proxy.
|
| + RECORD_KILOBYTES_HISTOGRAM(
|
| + GetConstHistogramWithSuffix(internal::kBytesProxied),
|
| + network_bytes_proxied_);
|
| +
|
| + // Record the total amount of bytes that did not go through the data reduction
|
| + // proxy.
|
| + RECORD_KILOBYTES_HISTOGRAM(
|
| + GetConstHistogramWithSuffix(internal::kBytesNotProxied),
|
| + network_bytes_ - network_bytes_proxied_);
|
| +
|
| + // Record the total KB of network bytes that the user would have seen without
|
| + // using data reduction proxy.
|
| + RECORD_KILOBYTES_HISTOGRAM(
|
| + GetConstHistogramWithSuffix(internal::kBytesOriginal),
|
| + original_network_bytes_);
|
| +
|
| + // Record the savings the user saw by using data reduction proxy. If there was
|
| + // inflation instead, record that.
|
| + if (network_bytes_ <= original_network_bytes_) {
|
| + RECORD_KILOBYTES_HISTOGRAM(
|
| + GetConstHistogramWithSuffix(internal::kBytesSavings),
|
| + original_network_bytes_ - network_bytes_);
|
| + } else {
|
| + RECORD_KILOBYTES_HISTOGRAM(
|
| + GetConstHistogramWithSuffix(internal::kBytesInflation),
|
| + network_bytes_proxied_ - original_network_bytes_);
|
| + }
|
| +}
|
| +
|
| void DataReductionProxyMetricsObserver::SendPingback(
|
| const page_load_metrics::PageLoadTiming& timing,
|
| const page_load_metrics::PageLoadExtraInfo& info) {
|
| @@ -284,6 +406,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(
|
|
|