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

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: 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"
10 #include "base/time/time.h" 11 #include "base/time/time.h"
11 #include "chrome/browser/loader/chrome_navigation_data.h" 12 #include "chrome/browser/loader/chrome_navigation_data.h"
12 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" 13 #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" 14 #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" 15 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h"
15 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" 16 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h"
16 #include "chrome/common/page_load_metrics/page_load_timing.h" 17 #include "chrome/common/page_load_metrics/page_load_timing.h"
17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" 18 #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" 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping back_client.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 const char kHistogramFirstTextPaintSuffix[] = 72 const char kHistogramFirstTextPaintSuffix[] =
72 "PaintTiming.NavigationToFirstTextPaint"; 73 "PaintTiming.NavigationToFirstTextPaint";
73 const char kHistogramParseStartSuffix[] = "ParseTiming.NavigationToParseStart"; 74 const char kHistogramParseStartSuffix[] = "ParseTiming.NavigationToParseStart";
74 const char kHistogramParseBlockedOnScriptLoadSuffix[] = 75 const char kHistogramParseBlockedOnScriptLoadSuffix[] =
75 "ParseTiming.ParseBlockedOnScriptLoad"; 76 "ParseTiming.ParseBlockedOnScriptLoad";
76 const char kHistogramParseDurationSuffix[] = "ParseTiming.ParseDuration"; 77 const char kHistogramParseDurationSuffix[] = "ParseTiming.ParseDuration";
77 78
78 } // namespace internal 79 } // namespace internal
79 80
80 DataReductionProxyMetricsObserver::DataReductionProxyMetricsObserver() 81 DataReductionProxyMetricsObserver::DataReductionProxyMetricsObserver()
81 : browser_context_(nullptr) {} 82 : browser_context_(nullptr),
83 num_data_reduction_proxy_requests_(0),
84 num_network_requests_(0),
85 original_network_bytes_(0),
86 network_bytes_proxied_(0),
87 network_bytes_(0) {}
82 88
83 DataReductionProxyMetricsObserver::~DataReductionProxyMetricsObserver() {} 89 DataReductionProxyMetricsObserver::~DataReductionProxyMetricsObserver() {}
84 90
85 // Check if the NavigationData indicates anything about the DataReductionProxy. 91 // Check if the NavigationData indicates anything about the DataReductionProxy.
86 page_load_metrics::PageLoadMetricsObserver::ObservePolicy 92 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
87 DataReductionProxyMetricsObserver::OnCommit( 93 DataReductionProxyMetricsObserver::OnCommit(
88 content::NavigationHandle* navigation_handle) { 94 content::NavigationHandle* navigation_handle) {
89 // This BrowserContext is valid for the lifetime of 95 // This BrowserContext is valid for the lifetime of
90 // DataReductionProxyMetricsObserver. BrowserContext is always valid and 96 // DataReductionProxyMetricsObserver. BrowserContext is always valid and
91 // non-nullptr in NavigationControllerImpl, which is a member of WebContents. 97 // non-nullptr in NavigationControllerImpl, which is a member of WebContents.
(...skipping 29 matching lines...) Expand all
121 bool started_in_foreground) { 127 bool started_in_foreground) {
122 if (!started_in_foreground) 128 if (!started_in_foreground)
123 return STOP_OBSERVING; 129 return STOP_OBSERVING;
124 return CONTINUE_OBSERVING; 130 return CONTINUE_OBSERVING;
125 } 131 }
126 132
127 page_load_metrics::PageLoadMetricsObserver::ObservePolicy 133 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
128 DataReductionProxyMetricsObserver::OnHidden( 134 DataReductionProxyMetricsObserver::OnHidden(
129 const page_load_metrics::PageLoadTiming& timing, 135 const page_load_metrics::PageLoadTiming& timing,
130 const page_load_metrics::PageLoadExtraInfo& info) { 136 const page_load_metrics::PageLoadExtraInfo& info) {
137 RecordPageSizeUMA();
131 SendPingback(timing, info); 138 SendPingback(timing, info);
132 return STOP_OBSERVING; 139 return STOP_OBSERVING;
133 } 140 }
134 141
135 page_load_metrics::PageLoadMetricsObserver::ObservePolicy 142 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
136 DataReductionProxyMetricsObserver::FlushMetricsOnAppEnterBackground( 143 DataReductionProxyMetricsObserver::FlushMetricsOnAppEnterBackground(
137 const page_load_metrics::PageLoadTiming& timing, 144 const page_load_metrics::PageLoadTiming& timing,
138 const page_load_metrics::PageLoadExtraInfo& info) { 145 const page_load_metrics::PageLoadExtraInfo& info) {
139 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the 146 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the
140 // app is about to be backgrounded, as part of the Activity.onPause() 147 // 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 148 // 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. 149 // notification, so we send a pingback with data collected up to this point.
150 RecordPageSizeUMA();
143 SendPingback(timing, info); 151 SendPingback(timing, info);
144 return STOP_OBSERVING; 152 return STOP_OBSERVING;
145 } 153 }
146 154
147 void DataReductionProxyMetricsObserver::OnComplete( 155 void DataReductionProxyMetricsObserver::OnComplete(
148 const page_load_metrics::PageLoadTiming& timing, 156 const page_load_metrics::PageLoadTiming& timing,
149 const page_load_metrics::PageLoadExtraInfo& info) { 157 const page_load_metrics::PageLoadExtraInfo& info) {
158 RecordPageSizeUMA();
150 SendPingback(timing, info); 159 SendPingback(timing, info);
151 } 160 }
152 161
162 void DataReductionProxyMetricsObserver::RecordPageSizeUMA() {
tbansal1 2017/01/18 22:35:19 const method?
RyanSturm 2017/01/18 22:57:49 Done.
163 if (num_network_requests_ == 0) {
164 return;
tbansal1 2017/01/18 22:35:19 Why return? It might be useful to know if there ar
RyanSturm 2017/01/18 22:57:49 This is happens when the main page request uses DR
165 }
166
167 // The percent of requests that went through the data reduction proxy.
168 int percent_proxied_requests =
169 100 * num_data_reduction_proxy_requests_ / num_network_requests_;
tbansal1 2017/01/18 22:35:19 do we need parenthesis here? to get around the amb
RyanSturm 2017/01/18 22:57:49 No, but I'll add it for you.
170 UMA_HISTOGRAM_PERCENTAGE(
171 std::string(internal::kHistogramDataReductionProxyPrefix)
172 .append("Experimental.Requests.Network.PercentProxied"),
173 percent_proxied_requests);
174
175 // The percent of bytes that went through the data reduction proxy.
176 if (network_bytes_ > 0) {
177 int percent_network_bytes_proxied =
178 100 * network_bytes_proxied_ / network_bytes_;
179 UMA_HISTOGRAM_PERCENTAGE(
180 std::string(internal::kHistogramDataReductionProxyPrefix)
181 .append("Experimental.Bytes.Network.PercentProxied"),
182 percent_network_bytes_proxied);
183 }
184
185 // If the data reduction proxy caused savings, record the compression ratio;
186 // otherwise, record the inflation ratio.
187 if (original_network_bytes_ > 0 && original_network_bytes_ > network_bytes_) {
tbansal1 2017/01/18 22:35:19 s/>/>=/ for the second condition? If the two are e
RyanSturm 2017/01/18 22:57:49 Done.
188 int compression_ratio = 100 * network_bytes_ / original_network_bytes_;
189 UMA_HISTOGRAM_PERCENTAGE(
190 std::string(internal::kHistogramDataReductionProxyPrefix)
191 .append("Experimental.Bytes.Network.CompressionRatio"),
tbansal1 2017/01/18 22:35:19 Should we record savings percent because that's wh
RyanSturm 2017/01/18 22:57:49 I'd prefer compression ratio because it shows when
192 compression_ratio);
193 } else if (network_bytes_ > 0) {
tbansal1 2017/01/18 22:35:19 Can network_bytes_ be 0 when num_network_requests_
RyanSturm 2017/01/18 22:57:49 I assume so. This is body bytes, and I believe bod
194 int inflation_ratio = 100 * original_network_bytes_ / network_bytes_;
tbansal1 2017/01/18 22:35:19 This histogram is difficult to parse. eg., if orig
RyanSturm 2017/01/18 22:57:49 Done.
195 UMA_HISTOGRAM_PERCENTAGE(
196 std::string(internal::kHistogramDataReductionProxyPrefix)
197 .append("Experimental.Bytes.Network.InflationRatio"),
198 inflation_ratio);
199 }
200
201 // Record the number of network requests seen.
202 UMA_HISTOGRAM_COUNTS_10000(
203 std::string(internal::kHistogramDataReductionProxyPrefix)
204 .append("Experimental.Requests.Network"),
205 num_network_requests_);
206
207 // Record the number of requests that used data reduction proxy.
208 UMA_HISTOGRAM_COUNTS_10000(
209 std::string(internal::kHistogramDataReductionProxyPrefix)
210 .append("Experimental.Requests.Network.Proxied"),
211 num_data_reduction_proxy_requests_);
212
213 // Record the number of requests that did not use data reduction proxy.
214 UMA_HISTOGRAM_COUNTS_10000(
215 std::string(internal::kHistogramDataReductionProxyPrefix)
216 .append("Experimental.Requests.Network.NonProxied"),
217 num_network_requests_ - num_data_reduction_proxy_requests_);
218
219 // Record the total KB of network bytes.
220 UMA_HISTOGRAM_CUSTOM_COUNTS(
221 std::string(internal::kHistogramDataReductionProxyPrefix)
222 .append("Experimental.Bytes.Network"),
tbansal1 2017/01/18 22:35:19 Use KB or KiloBytes in the histogram name to avoid
RyanSturm 2017/01/18 22:57:49 It's in the units on histograms.xml and I am stand
223 static_cast<int>(network_bytes_) / 1024, 1, 500 * 1024, 50);
224
225 // Record the total amount of bytes that went through the data reduction
226 // proxy.
227 UMA_HISTOGRAM_CUSTOM_COUNTS(
228 std::string(internal::kHistogramDataReductionProxyPrefix)
229 .append("Experimental.Bytes.Network.Proxied"),
230 static_cast<int>(network_bytes_proxied_) / 1024, 1, 500 * 1024, 50);
tbansal1 2017/01/18 22:35:19 Can you add a comment that upper bucket is 500 MB.
RyanSturm 2017/01/18 22:57:49 Done.
231
232 // Record the total amount of bytes that did not go through the data reduction
233 // proxy.
234 UMA_HISTOGRAM_CUSTOM_COUNTS(
235 std::string(internal::kHistogramDataReductionProxyPrefix)
236 .append("Experimental.Bytes.Network.NonProxied"),
237 static_cast<int>(network_bytes_proxied_) / 1024, 1, 500 * 1024, 50);
tbansal1 2017/01/18 22:35:19 s/network_bytes_proxied_/network_bytes_ - network_
RyanSturm 2017/01/18 22:57:49 Done.
238
239 // Record the total KB of network bytes that the user would have seen without
240 // using data reduction proxy.
241 UMA_HISTOGRAM_CUSTOM_COUNTS(
242 std::string(internal::kHistogramDataReductionProxyPrefix)
243 .append("Experimental.Bytes.Network.Original"),
244 static_cast<int>(original_network_bytes_) / 1024, 1, 500 * 1024, 50);
245
246 // Record the savings the user saw by using data reduction proxy. If there was
247 // inflation instead, record that.
248 if (network_bytes_ < original_network_bytes_) {
tbansal1 2017/01/18 22:35:19 s/</<=/
RyanSturm 2017/01/18 22:57:49 Done.
249 UMA_HISTOGRAM_CUSTOM_COUNTS(
250 std::string(internal::kHistogramDataReductionProxyPrefix)
251 .append("Experimental.Bytes.Network.Savings"),
252 static_cast<int>(original_network_bytes_ - network_bytes_) / 1024, 1,
253 500 * 1024, 50);
254 } else {
255 UMA_HISTOGRAM_CUSTOM_COUNTS(
256 std::string(internal::kHistogramDataReductionProxyPrefix)
257 .append("Experimental.Bytes.Network.Inflation"),
258 static_cast<int>(network_bytes_proxied_ - original_network_bytes_) /
259 1024,
260 1, 500 * 1024, 50);
261 }
262 }
263
153 void DataReductionProxyMetricsObserver::SendPingback( 264 void DataReductionProxyMetricsObserver::SendPingback(
154 const page_load_metrics::PageLoadTiming& timing, 265 const page_load_metrics::PageLoadTiming& timing,
155 const page_load_metrics::PageLoadExtraInfo& info) { 266 const page_load_metrics::PageLoadExtraInfo& info) {
156 // TODO(ryansturm): Move to OnFirstBackgroundEvent to handle some fast 267 // TODO(ryansturm): Move to OnFirstBackgroundEvent to handle some fast
157 // shutdown cases. crbug.com/618072 268 // shutdown cases. crbug.com/618072
158 if (!browser_context_) 269 if (!browser_context_)
159 return; 270 return;
160 if (data_reduction_proxy::params::IsIncludedInHoldbackFieldTrial() || 271 if (data_reduction_proxy::params::IsIncludedInHoldbackFieldTrial() ||
161 data_reduction_proxy::params::IsIncludedInTamperDetectionExperiment()) { 272 data_reduction_proxy::params::IsIncludedInTamperDetectionExperiment()) {
162 return; 273 return;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 const page_load_metrics::PageLoadExtraInfo& info) { 388 const page_load_metrics::PageLoadExtraInfo& info) {
278 base::TimeDelta parse_duration = 389 base::TimeDelta parse_duration =
279 timing.parse_stop.value() - timing.parse_start.value(); 390 timing.parse_stop.value() - timing.parse_start.value();
280 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, parse_duration, 391 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, parse_duration,
281 internal::kHistogramParseDurationSuffix); 392 internal::kHistogramParseDurationSuffix);
282 RECORD_HISTOGRAMS_FOR_SUFFIX( 393 RECORD_HISTOGRAMS_FOR_SUFFIX(
283 data_, timing.parse_blocked_on_script_load_duration.value(), 394 data_, timing.parse_blocked_on_script_load_duration.value(),
284 internal::kHistogramParseBlockedOnScriptLoadSuffix); 395 internal::kHistogramParseBlockedOnScriptLoadSuffix);
285 } 396 }
286 397
398 void DataReductionProxyMetricsObserver::OnLoadedResource(
399 const page_load_metrics::ExtraRequestInfo& extra_request_info) {
400 if (extra_request_info.was_cached)
401 return;
402 original_network_bytes_ += extra_request_info.original_network_content_length;
403 network_bytes_ += extra_request_info.raw_body_bytes;
404 num_network_requests_++;
405 if (!extra_request_info.data_reduction_proxy_used)
406 return;
407 num_data_reduction_proxy_requests_++;
408 network_bytes_proxied_ += extra_request_info.raw_body_bytes;
409 }
410
287 DataReductionProxyPingbackClient* 411 DataReductionProxyPingbackClient*
288 DataReductionProxyMetricsObserver::GetPingbackClient() const { 412 DataReductionProxyMetricsObserver::GetPingbackClient() const {
289 return DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 413 return DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
290 browser_context_) 414 browser_context_)
291 ->data_reduction_proxy_service() 415 ->data_reduction_proxy_service()
292 ->pingback_client(); 416 ->pingback_client();
293 } 417 }
294 418
295 } // namespace data_reduction_proxy 419 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698