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

Side by Side Diff: chrome/browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer.cc

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

Powered by Google App Engine
This is Rietveld 408576698