Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/page_load_metrics/observers/data_reduction_proxy_metric s_observer.h" | 5 #include "chrome/browser/page_load_metrics/observers/data_reduction_proxy_metric s_observer.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/metrics/histogram_macros.h" | |
| 9 #include "base/optional.h" | 10 #include "base/optional.h" |
| 11 #include "base/strings/string_piece.h" | |
| 10 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 11 #include "chrome/browser/loader/chrome_navigation_data.h" | 13 #include "chrome/browser/loader/chrome_navigation_data.h" |
| 12 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 14 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
| 13 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" | 15 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" |
| 14 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" | 16 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" |
| 15 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 17 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
| 16 #include "chrome/common/page_load_metrics/page_load_timing.h" | 18 #include "chrome/common/page_load_metrics/page_load_timing.h" |
| 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" | 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" |
| 18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping back_client.h" | 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping back_client.h" |
| 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" | 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" |
| 20 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_page_ load_timing.h" | 22 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_page_ load_timing.h" |
| 21 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | 23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" |
| 22 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/browser/navigation_data.h" | 25 #include "content/public/browser/navigation_data.h" |
| 24 #include "content/public/browser/navigation_handle.h" | 26 #include "content/public/browser/navigation_handle.h" |
| 25 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 26 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 27 | 29 |
| 28 namespace data_reduction_proxy { | 30 namespace data_reduction_proxy { |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 34 std::string GetConstHistogramWithSuffix(const char* suffix) { | |
| 35 return std::string(internal::kHistogramDataReductionProxyPrefix) | |
| 36 .append(suffix); | |
| 37 } | |
| 38 | |
| 32 // A macro is needed because PAGE_LOAD_HISTOGRAM creates a static instance of | 39 // A macro is needed because PAGE_LOAD_HISTOGRAM creates a static instance of |
| 33 // the histogram. A distinct histogram is needed for each place that calls | 40 // the histogram. A distinct histogram is needed for each place that calls |
| 34 // RECORD_HISTOGRAMS_FOR_SUFFIX. |event| is the timing event representing when | 41 // RECORD_HISTOGRAMS_FOR_SUFFIX. |event| is the timing event representing when |
| 35 // |value| became available. | 42 // |value| became available. |
| 36 #define RECORD_HISTOGRAMS_FOR_SUFFIX(data, value, histogram_suffix) \ | 43 #define RECORD_HISTOGRAMS_FOR_SUFFIX(data, value, histogram_suffix) \ |
| 37 do { \ | 44 do { \ |
| 38 PAGE_LOAD_HISTOGRAM( \ | 45 PAGE_LOAD_HISTOGRAM(GetConstHistogramWithSuffix(histogram_suffix), value); \ |
| 39 std::string(internal::kHistogramDataReductionProxyPrefix) \ | 46 if (data->lofi_requested()) { \ |
| 40 .append(histogram_suffix), \ | 47 PAGE_LOAD_HISTOGRAM( \ |
| 41 value); \ | 48 std::string(internal::kHistogramDataReductionProxyLoFiOnPrefix) \ |
| 42 if (data->lofi_requested()) { \ | 49 .append(histogram_suffix), \ |
| 43 PAGE_LOAD_HISTOGRAM( \ | 50 value); \ |
| 44 std::string(internal::kHistogramDataReductionProxyLoFiOnPrefix) \ | 51 } \ |
| 45 .append(histogram_suffix), \ | |
| 46 value); \ | |
| 47 } \ | |
| 48 } while (false) | 52 } while (false) |
| 49 | 53 |
| 50 } // namespace | 54 } // namespace |
| 51 | 55 |
| 52 namespace internal { | 56 namespace internal { |
| 53 | 57 |
| 54 const char kHistogramDataReductionProxyPrefix[] = | 58 const char kHistogramDataReductionProxyPrefix[] = |
| 55 "PageLoad.Clients.DataReductionProxy."; | 59 "PageLoad.Clients.DataReductionProxy."; |
| 56 const char kHistogramDataReductionProxyLoFiOnPrefix[] = | 60 const char kHistogramDataReductionProxyLoFiOnPrefix[] = |
| 57 "PageLoad.Clients.DataReductionProxy.LoFiOn."; | 61 "PageLoad.Clients.DataReductionProxy.LoFiOn."; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 68 const char kHistogramFirstImagePaintSuffix[] = | 72 const char kHistogramFirstImagePaintSuffix[] = |
| 69 "PaintTiming.NavigationToFirstImagePaint"; | 73 "PaintTiming.NavigationToFirstImagePaint"; |
| 70 const char kHistogramFirstPaintSuffix[] = "PaintTiming.NavigationToFirstPaint"; | 74 const char kHistogramFirstPaintSuffix[] = "PaintTiming.NavigationToFirstPaint"; |
| 71 const char kHistogramFirstTextPaintSuffix[] = | 75 const char kHistogramFirstTextPaintSuffix[] = |
| 72 "PaintTiming.NavigationToFirstTextPaint"; | 76 "PaintTiming.NavigationToFirstTextPaint"; |
| 73 const char kHistogramParseStartSuffix[] = "ParseTiming.NavigationToParseStart"; | 77 const char kHistogramParseStartSuffix[] = "ParseTiming.NavigationToParseStart"; |
| 74 const char kHistogramParseBlockedOnScriptLoadSuffix[] = | 78 const char kHistogramParseBlockedOnScriptLoadSuffix[] = |
| 75 "ParseTiming.ParseBlockedOnScriptLoad"; | 79 "ParseTiming.ParseBlockedOnScriptLoad"; |
| 76 const char kHistogramParseDurationSuffix[] = "ParseTiming.ParseDuration"; | 80 const char kHistogramParseDurationSuffix[] = "ParseTiming.ParseDuration"; |
| 77 | 81 |
| 82 const char kRequestsPercentProxied[] = | |
| 83 "Experimental.Requests.Network.PercentProxied"; | |
| 84 const char kBytesPercentProxied[] = "Experimental.Bytes.Network.PercentProxied"; | |
| 85 const char kBytesCompressionRatio[] = | |
| 86 "Experimental.Bytes.Network.CompressionRatio"; | |
| 87 const char kBytesInflationPercent[] = | |
| 88 "Experimental.Bytes.Network.InflationPercent"; | |
| 89 const char kNetworkRequests[] = "Experimental.Requests.Network"; | |
| 90 const char kRequestsProxied[] = "Experimental.Requests.Network.Proxied"; | |
| 91 const char kRequestsNotProxied[] = "Experimental.Requests.Network.NonProxied"; | |
| 92 const char kNetworkBytes[] = "Experimental.Bytes.Network"; | |
| 93 const char kBytesProxied[] = "Experimental.Bytes.Network.Proxied"; | |
| 94 const char kBytesNotProxied[] = "Experimental.Bytes.Network.NonProxied"; | |
| 95 const char kBytesOriginal[] = "Experimental.Bytes.Network.Original"; | |
| 96 const char kBytesSavings[] = "Experimental.Bytes.Network.Savings"; | |
| 97 const char kBytesInflation[] = "Experimental.Bytes.Network.Inflation"; | |
| 98 | |
| 78 } // namespace internal | 99 } // namespace internal |
| 79 | 100 |
| 80 DataReductionProxyMetricsObserver::DataReductionProxyMetricsObserver() | 101 DataReductionProxyMetricsObserver::DataReductionProxyMetricsObserver() |
| 81 : browser_context_(nullptr) {} | 102 : browser_context_(nullptr), |
| 103 num_data_reduction_proxy_requests_(0), | |
| 104 num_network_requests_(0), | |
| 105 original_network_bytes_(0), | |
| 106 network_bytes_proxied_(0), | |
| 107 network_bytes_(0) {} | |
| 82 | 108 |
| 83 DataReductionProxyMetricsObserver::~DataReductionProxyMetricsObserver() {} | 109 DataReductionProxyMetricsObserver::~DataReductionProxyMetricsObserver() {} |
| 84 | 110 |
| 85 // Check if the NavigationData indicates anything about the DataReductionProxy. | 111 // Check if the NavigationData indicates anything about the DataReductionProxy. |
| 86 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 112 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
| 87 DataReductionProxyMetricsObserver::OnCommit( | 113 DataReductionProxyMetricsObserver::OnCommit( |
| 88 content::NavigationHandle* navigation_handle) { | 114 content::NavigationHandle* navigation_handle) { |
| 89 // This BrowserContext is valid for the lifetime of | 115 // This BrowserContext is valid for the lifetime of |
| 90 // DataReductionProxyMetricsObserver. BrowserContext is always valid and | 116 // DataReductionProxyMetricsObserver. BrowserContext is always valid and |
| 91 // non-nullptr in NavigationControllerImpl, which is a member of WebContents. | 117 // non-nullptr in NavigationControllerImpl, which is a member of WebContents. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 121 bool started_in_foreground) { | 147 bool started_in_foreground) { |
| 122 if (!started_in_foreground) | 148 if (!started_in_foreground) |
| 123 return STOP_OBSERVING; | 149 return STOP_OBSERVING; |
| 124 return CONTINUE_OBSERVING; | 150 return CONTINUE_OBSERVING; |
| 125 } | 151 } |
| 126 | 152 |
| 127 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 153 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
| 128 DataReductionProxyMetricsObserver::OnHidden( | 154 DataReductionProxyMetricsObserver::OnHidden( |
| 129 const page_load_metrics::PageLoadTiming& timing, | 155 const page_load_metrics::PageLoadTiming& timing, |
| 130 const page_load_metrics::PageLoadExtraInfo& info) { | 156 const page_load_metrics::PageLoadExtraInfo& info) { |
| 157 RecordPageSizeUMA(); | |
| 131 SendPingback(timing, info); | 158 SendPingback(timing, info); |
| 132 return STOP_OBSERVING; | 159 return STOP_OBSERVING; |
| 133 } | 160 } |
| 134 | 161 |
| 135 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 162 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
| 136 DataReductionProxyMetricsObserver::FlushMetricsOnAppEnterBackground( | 163 DataReductionProxyMetricsObserver::FlushMetricsOnAppEnterBackground( |
| 137 const page_load_metrics::PageLoadTiming& timing, | 164 const page_load_metrics::PageLoadTiming& timing, |
| 138 const page_load_metrics::PageLoadExtraInfo& info) { | 165 const page_load_metrics::PageLoadExtraInfo& info) { |
| 139 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the | 166 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the |
| 140 // app is about to be backgrounded, as part of the Activity.onPause() | 167 // app is about to be backgrounded, as part of the Activity.onPause() |
| 141 // flow. After this method is invoked, Chrome may be killed without further | 168 // flow. After this method is invoked, Chrome may be killed without further |
| 142 // notification, so we send a pingback with data collected up to this point. | 169 // notification, so we send a pingback with data collected up to this point. |
| 170 RecordPageSizeUMA(); | |
| 143 SendPingback(timing, info); | 171 SendPingback(timing, info); |
| 144 return STOP_OBSERVING; | 172 return STOP_OBSERVING; |
| 145 } | 173 } |
| 146 | 174 |
| 147 void DataReductionProxyMetricsObserver::OnComplete( | 175 void DataReductionProxyMetricsObserver::OnComplete( |
| 148 const page_load_metrics::PageLoadTiming& timing, | 176 const page_load_metrics::PageLoadTiming& timing, |
| 149 const page_load_metrics::PageLoadExtraInfo& info) { | 177 const page_load_metrics::PageLoadExtraInfo& info) { |
| 178 RecordPageSizeUMA(); | |
| 150 SendPingback(timing, info); | 179 SendPingback(timing, info); |
| 151 } | 180 } |
| 152 | 181 |
| 182 void DataReductionProxyMetricsObserver::RecordPageSizeUMA() const { | |
| 183 // If the first request didn't complete, don't record UMA. | |
| 184 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.
| |
| 185 return; | |
| 186 } | |
| 187 | |
| 188 // TODO(ryansturm): Evaluate if any of the below histograms are unncessary | |
| 189 // once data is available. crbug.com/682782 | |
| 190 | |
| 191 // The percent of requests that went through the data reduction proxy. | |
| 192 UMA_HISTOGRAM_PERCENTAGE( | |
| 193 GetConstHistogramWithSuffix(internal::kRequestsPercentProxied), | |
| 194 (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
| |
| 195 | |
| 196 // The percent of bytes that went through the data reduction proxy. | |
| 197 if (network_bytes_ > 0) { | |
| 198 UMA_HISTOGRAM_PERCENTAGE( | |
| 199 GetConstHistogramWithSuffix(internal::kBytesPercentProxied), | |
| 200 static_cast<int>((100 * network_bytes_proxied_) / network_bytes_)); | |
| 201 } | |
| 202 | |
| 203 // If the data reduction proxy caused savings, record the compression ratio; | |
| 204 // otherwise, record the inflation ratio. | |
| 205 if (original_network_bytes_ > 0 && | |
| 206 original_network_bytes_ >= network_bytes_) { | |
| 207 UMA_HISTOGRAM_PERCENTAGE( | |
| 208 GetConstHistogramWithSuffix(internal::kBytesCompressionRatio), | |
| 209 static_cast<int>((100 * network_bytes_) / original_network_bytes_)); | |
| 210 } else if (original_network_bytes_ > 0) { | |
| 211 // Inflation should never be above one hundred percent. | |
| 212 UMA_HISTOGRAM_PERCENTAGE( | |
| 213 GetConstHistogramWithSuffix(internal::kBytesInflationPercent), | |
| 214 static_cast<int>((100 * network_bytes_) / original_network_bytes_ - | |
| 215 100)); | |
| 216 } | |
| 217 | |
| 218 // Record the number of network requests seen. | |
| 219 UMA_HISTOGRAM_COUNTS_10000( | |
| 220 GetConstHistogramWithSuffix(internal::kNetworkRequests), | |
| 221 num_network_requests_); | |
| 222 | |
| 223 // Record the number of requests that used data reduction proxy. | |
| 224 UMA_HISTOGRAM_COUNTS_10000( | |
| 225 GetConstHistogramWithSuffix(internal::kRequestsProxied), | |
| 226 num_data_reduction_proxy_requests_); | |
| 227 | |
| 228 // Record the number of requests that did not use data reduction proxy. | |
| 229 UMA_HISTOGRAM_COUNTS_10000( | |
| 230 GetConstHistogramWithSuffix(internal::kRequestsNotProxied), | |
| 231 num_network_requests_ - num_data_reduction_proxy_requests_); | |
| 232 | |
| 233 // Record the total KB of network bytes. Capped at 500 MB. | |
| 234 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
| 235 GetConstHistogramWithSuffix(internal::kNetworkBytes), | |
| 236 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.
| |
| 237 | |
| 238 // Record the total amount of bytes that went through the data reduction | |
| 239 // proxy. Capped at 500 MB. | |
| 240 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
| 241 GetConstHistogramWithSuffix(internal::kBytesProxied), | |
| 242 static_cast<int>(network_bytes_proxied_ / 1024), 1, 500 * 1024, 50); | |
| 243 | |
| 244 // Record the total amount of bytes that did not go through the data reduction | |
| 245 // proxy. Capped at 500 MB. | |
| 246 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
| 247 GetConstHistogramWithSuffix(internal::kBytesNotProxied), | |
| 248 static_cast<int>((network_bytes_ - network_bytes_proxied_) / 1024), 1, | |
| 249 500 * 1024, 50); | |
| 250 | |
| 251 // Record the total KB of network bytes that the user would have seen without | |
| 252 // using data reduction proxy. Capped at 500 MB. | |
| 253 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
| 254 GetConstHistogramWithSuffix(internal::kBytesOriginal), | |
| 255 static_cast<int>(original_network_bytes_ / 1024), 1, 500 * 1024, 50); | |
| 256 | |
| 257 // Record the savings the user saw by using data reduction proxy. If there was | |
| 258 // inflation instead, record that. Capped at 500 MB. | |
| 259 if (network_bytes_ <= original_network_bytes_) { | |
| 260 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
| 261 GetConstHistogramWithSuffix(internal::kBytesSavings), | |
| 262 static_cast<int>((original_network_bytes_ - network_bytes_) / 1024), 1, | |
| 263 500 * 1024, 50); | |
| 264 } else { | |
| 265 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
| 266 GetConstHistogramWithSuffix(internal::kBytesInflation), | |
| 267 static_cast<int>((network_bytes_proxied_ - original_network_bytes_) / | |
| 268 1024), | |
| 269 1, 500 * 1024, 50); | |
| 270 } | |
| 271 } | |
| 272 | |
| 153 void DataReductionProxyMetricsObserver::SendPingback( | 273 void DataReductionProxyMetricsObserver::SendPingback( |
| 154 const page_load_metrics::PageLoadTiming& timing, | 274 const page_load_metrics::PageLoadTiming& timing, |
| 155 const page_load_metrics::PageLoadExtraInfo& info) { | 275 const page_load_metrics::PageLoadExtraInfo& info) { |
| 156 // TODO(ryansturm): Move to OnFirstBackgroundEvent to handle some fast | 276 // TODO(ryansturm): Move to OnFirstBackgroundEvent to handle some fast |
| 157 // shutdown cases. crbug.com/618072 | 277 // shutdown cases. crbug.com/618072 |
| 158 if (!browser_context_) | 278 if (!browser_context_) |
| 159 return; | 279 return; |
| 160 if (data_reduction_proxy::params::IsIncludedInHoldbackFieldTrial() || | 280 if (data_reduction_proxy::params::IsIncludedInHoldbackFieldTrial() || |
| 161 data_reduction_proxy::params::IsIncludedInTamperDetectionExperiment()) { | 281 data_reduction_proxy::params::IsIncludedInTamperDetectionExperiment()) { |
| 162 return; | 282 return; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 const page_load_metrics::PageLoadExtraInfo& info) { | 397 const page_load_metrics::PageLoadExtraInfo& info) { |
| 278 base::TimeDelta parse_duration = | 398 base::TimeDelta parse_duration = |
| 279 timing.parse_stop.value() - timing.parse_start.value(); | 399 timing.parse_stop.value() - timing.parse_start.value(); |
| 280 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, parse_duration, | 400 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, parse_duration, |
| 281 internal::kHistogramParseDurationSuffix); | 401 internal::kHistogramParseDurationSuffix); |
| 282 RECORD_HISTOGRAMS_FOR_SUFFIX( | 402 RECORD_HISTOGRAMS_FOR_SUFFIX( |
| 283 data_, timing.parse_blocked_on_script_load_duration.value(), | 403 data_, timing.parse_blocked_on_script_load_duration.value(), |
| 284 internal::kHistogramParseBlockedOnScriptLoadSuffix); | 404 internal::kHistogramParseBlockedOnScriptLoadSuffix); |
| 285 } | 405 } |
| 286 | 406 |
| 407 void DataReductionProxyMetricsObserver::OnLoadedResource( | |
| 408 const page_load_metrics::ExtraRequestInfo& extra_request_info) { | |
| 409 if (extra_request_info.was_cached) | |
| 410 return; | |
| 411 original_network_bytes_ += extra_request_info.original_network_content_length; | |
| 412 network_bytes_ += extra_request_info.raw_body_bytes; | |
| 413 num_network_requests_++; | |
| 414 if (!extra_request_info.data_reduction_proxy_used) | |
| 415 return; | |
| 416 num_data_reduction_proxy_requests_++; | |
| 417 network_bytes_proxied_ += extra_request_info.raw_body_bytes; | |
| 418 } | |
| 419 | |
| 287 DataReductionProxyPingbackClient* | 420 DataReductionProxyPingbackClient* |
| 288 DataReductionProxyMetricsObserver::GetPingbackClient() const { | 421 DataReductionProxyMetricsObserver::GetPingbackClient() const { |
| 289 return DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 422 return DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 290 browser_context_) | 423 browser_context_) |
| 291 ->data_reduction_proxy_service() | 424 ->data_reduction_proxy_service() |
| 292 ->pingback_client(); | 425 ->pingback_client(); |
| 293 } | 426 } |
| 294 | 427 |
| 295 } // namespace data_reduction_proxy | 428 } // namespace data_reduction_proxy |
| OLD | NEW |