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

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: tbansal comments, tests, small const var refactor. 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 const char kHistogramFirstImagePaintSuffix[] = 69 const char kHistogramFirstImagePaintSuffix[] =
69 "PaintTiming.NavigationToFirstImagePaint"; 70 "PaintTiming.NavigationToFirstImagePaint";
70 const char kHistogramFirstPaintSuffix[] = "PaintTiming.NavigationToFirstPaint"; 71 const char kHistogramFirstPaintSuffix[] = "PaintTiming.NavigationToFirstPaint";
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
79 const char kRequestsPercentProxied[] =
80 "Experimental.Requests.Network.PercentProxied";
81 const char kBytesPercentProxied[] = "Experimental.Bytes.Network.PercentProxied";
82 const char kBytesCompressionRatio[] =
83 "Experimental.Bytes.Network.CompressionRatio";
84 const char kBytesInflationPercent[] =
85 "Experimental.Bytes.Network.InflationPercent";
86 const char kNetworkRequests[] = "Experimental.Requests.Network";
87 const char kRequestsProxied[] = "Experimental.Requests.Network.Proxied";
88 const char kRequestsNotProxied[] = "Experimental.Requests.Network.NonProxied";
89 const char kNetworkBytes[] = "Experimental.Bytes.Network";
90 const char kBytesProxied[] = "Experimental.Bytes.Network.Proxied";
91 const char kBytesNotProxied[] = "Experimental.Bytes.Network.NonProxied";
92 const char kBytesOriginal[] = "Experimental.Bytes.Network.Original";
93 const char kBytesSavings[] = "Experimental.Bytes.Network.Savings";
94 const char kBytesInflation[] = "Experimental.Bytes.Network.Inflation";
95
78 } // namespace internal 96 } // namespace internal
79 97
80 DataReductionProxyMetricsObserver::DataReductionProxyMetricsObserver() 98 DataReductionProxyMetricsObserver::DataReductionProxyMetricsObserver()
81 : browser_context_(nullptr) {} 99 : browser_context_(nullptr),
100 num_data_reduction_proxy_requests_(0),
101 num_network_requests_(0),
102 original_network_bytes_(0),
103 network_bytes_proxied_(0),
104 network_bytes_(0) {}
82 105
83 DataReductionProxyMetricsObserver::~DataReductionProxyMetricsObserver() {} 106 DataReductionProxyMetricsObserver::~DataReductionProxyMetricsObserver() {}
84 107
85 // Check if the NavigationData indicates anything about the DataReductionProxy. 108 // Check if the NavigationData indicates anything about the DataReductionProxy.
86 page_load_metrics::PageLoadMetricsObserver::ObservePolicy 109 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
87 DataReductionProxyMetricsObserver::OnCommit( 110 DataReductionProxyMetricsObserver::OnCommit(
88 content::NavigationHandle* navigation_handle) { 111 content::NavigationHandle* navigation_handle) {
89 // This BrowserContext is valid for the lifetime of 112 // This BrowserContext is valid for the lifetime of
90 // DataReductionProxyMetricsObserver. BrowserContext is always valid and 113 // DataReductionProxyMetricsObserver. BrowserContext is always valid and
91 // non-nullptr in NavigationControllerImpl, which is a member of WebContents. 114 // non-nullptr in NavigationControllerImpl, which is a member of WebContents.
(...skipping 29 matching lines...) Expand all
121 bool started_in_foreground) { 144 bool started_in_foreground) {
122 if (!started_in_foreground) 145 if (!started_in_foreground)
123 return STOP_OBSERVING; 146 return STOP_OBSERVING;
124 return CONTINUE_OBSERVING; 147 return CONTINUE_OBSERVING;
125 } 148 }
126 149
127 page_load_metrics::PageLoadMetricsObserver::ObservePolicy 150 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
128 DataReductionProxyMetricsObserver::OnHidden( 151 DataReductionProxyMetricsObserver::OnHidden(
129 const page_load_metrics::PageLoadTiming& timing, 152 const page_load_metrics::PageLoadTiming& timing,
130 const page_load_metrics::PageLoadExtraInfo& info) { 153 const page_load_metrics::PageLoadExtraInfo& info) {
154 RecordPageSizeUMA();
131 SendPingback(timing, info); 155 SendPingback(timing, info);
132 return STOP_OBSERVING; 156 return STOP_OBSERVING;
133 } 157 }
134 158
135 page_load_metrics::PageLoadMetricsObserver::ObservePolicy 159 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
136 DataReductionProxyMetricsObserver::FlushMetricsOnAppEnterBackground( 160 DataReductionProxyMetricsObserver::FlushMetricsOnAppEnterBackground(
137 const page_load_metrics::PageLoadTiming& timing, 161 const page_load_metrics::PageLoadTiming& timing,
138 const page_load_metrics::PageLoadExtraInfo& info) { 162 const page_load_metrics::PageLoadExtraInfo& info) {
139 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the 163 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the
140 // app is about to be backgrounded, as part of the Activity.onPause() 164 // 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 165 // 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. 166 // notification, so we send a pingback with data collected up to this point.
167 RecordPageSizeUMA();
143 SendPingback(timing, info); 168 SendPingback(timing, info);
144 return STOP_OBSERVING; 169 return STOP_OBSERVING;
145 } 170 }
146 171
147 void DataReductionProxyMetricsObserver::OnComplete( 172 void DataReductionProxyMetricsObserver::OnComplete(
148 const page_load_metrics::PageLoadTiming& timing, 173 const page_load_metrics::PageLoadTiming& timing,
149 const page_load_metrics::PageLoadExtraInfo& info) { 174 const page_load_metrics::PageLoadExtraInfo& info) {
175 RecordPageSizeUMA();
150 SendPingback(timing, info); 176 SendPingback(timing, info);
151 } 177 }
152 178
179 void DataReductionProxyMetricsObserver::RecordPageSizeUMA() const {
180 // If the first request didn't complete, don't record UMA.
181 if (num_network_requests_ == 0) {
182 return;
183 }
184
185 // The percent of requests that went through the data reduction proxy.
186 UMA_HISTOGRAM_PERCENTAGE(
187 std::string(internal::kHistogramDataReductionProxyPrefix)
188 .append(internal::kRequestsPercentProxied),
189 (100 * num_data_reduction_proxy_requests_) / num_network_requests_);
190
191 // The percent of bytes that went through the data reduction proxy.
192 if (network_bytes_ > 0) {
193 UMA_HISTOGRAM_PERCENTAGE(
194 std::string(internal::kHistogramDataReductionProxyPrefix)
195 .append(internal::kBytesPercentProxied),
196 static_cast<int>((100 * network_bytes_proxied_) / network_bytes_));
197 }
198
199 // If the data reduction proxy caused savings, record the compression ratio;
200 // otherwise, record the inflation ratio.
201 if (original_network_bytes_ > 0 &&
202 original_network_bytes_ >= network_bytes_) {
203 UMA_HISTOGRAM_PERCENTAGE(
204 std::string(internal::kHistogramDataReductionProxyPrefix)
205 .append(internal::kBytesCompressionRatio),
206 static_cast<int>((100 * network_bytes_) / original_network_bytes_));
207 } else if (network_bytes_ > 0) {
tbansal1 2017/01/18 23:34:49 s/network_bytes_ > 0/original_network_bytes_ > 0/
RyanSturm 2017/01/18 23:54:19 Done.
208 // Inflation should never be above one hundred percent.
209 UMA_HISTOGRAM_PERCENTAGE(
210 std::string(internal::kHistogramDataReductionProxyPrefix)
211 .append(internal::kBytesInflationPercent),
212 static_cast<int>((100 * network_bytes_) / original_network_bytes_ -
213 100));
214 }
215
216 // Record the number of network requests seen.
217 UMA_HISTOGRAM_COUNTS_10000(
218 std::string(internal::kHistogramDataReductionProxyPrefix)
219 .append(internal::kNetworkRequests),
220 num_network_requests_);
221
222 // Record the number of requests that used data reduction proxy.
223 UMA_HISTOGRAM_COUNTS_10000(
224 std::string(internal::kHistogramDataReductionProxyPrefix)
225 .append(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 std::string(internal::kHistogramDataReductionProxyPrefix)
231 .append(internal::kRequestsNotProxied),
232 num_network_requests_ - num_data_reduction_proxy_requests_);
233
234 // Record the total KB of network bytes. Capped at 500 MB.
235 UMA_HISTOGRAM_CUSTOM_COUNTS(
236 std::string(internal::kHistogramDataReductionProxyPrefix)
237 .append(internal::kNetworkBytes),
238 static_cast<int>(network_bytes_ / 1024), 1, 500 * 1024, 50);
239
240 // Record the total amount of bytes that went through the data reduction
241 // proxy. Capped at 500 MB.
242 UMA_HISTOGRAM_CUSTOM_COUNTS(
243 std::string(internal::kHistogramDataReductionProxyPrefix)
244 .append(internal::kBytesProxied),
245 static_cast<int>(network_bytes_proxied_ / 1024), 1, 500 * 1024, 50);
246
247 // Record the total amount of bytes that did not go through the data reduction
248 // proxy. Capped at 500 MB.
249 UMA_HISTOGRAM_CUSTOM_COUNTS(
250 std::string(internal::kHistogramDataReductionProxyPrefix)
251 .append(internal::kBytesNotProxied),
252 static_cast<int>((network_bytes_ - network_bytes_proxied_) / 1024), 1,
253 500 * 1024, 50);
254
255 // Record the total KB of network bytes that the user would have seen without
256 // using data reduction proxy. Capped at 500 MB.
257 UMA_HISTOGRAM_CUSTOM_COUNTS(
258 std::string(internal::kHistogramDataReductionProxyPrefix)
259 .append(internal::kBytesOriginal),
260 static_cast<int>(original_network_bytes_ / 1024), 1, 500 * 1024, 50);
261
262 // Record the savings the user saw by using data reduction proxy. If there was
263 // inflation instead, record that. Capped at 500 MB.
264 if (network_bytes_ <= original_network_bytes_) {
265 UMA_HISTOGRAM_CUSTOM_COUNTS(
266 std::string(internal::kHistogramDataReductionProxyPrefix)
267 .append(internal::kBytesSavings),
268 static_cast<int>((original_network_bytes_ - network_bytes_) / 1024), 1,
269 500 * 1024, 50);
270 } else {
271 UMA_HISTOGRAM_CUSTOM_COUNTS(
272 std::string(internal::kHistogramDataReductionProxyPrefix)
273 .append(internal::kBytesInflation),
274 static_cast<int>((network_bytes_proxied_ - original_network_bytes_) /
275 1024),
276 1, 500 * 1024, 50);
277 }
278 }
279
153 void DataReductionProxyMetricsObserver::SendPingback( 280 void DataReductionProxyMetricsObserver::SendPingback(
154 const page_load_metrics::PageLoadTiming& timing, 281 const page_load_metrics::PageLoadTiming& timing,
155 const page_load_metrics::PageLoadExtraInfo& info) { 282 const page_load_metrics::PageLoadExtraInfo& info) {
156 // TODO(ryansturm): Move to OnFirstBackgroundEvent to handle some fast 283 // TODO(ryansturm): Move to OnFirstBackgroundEvent to handle some fast
157 // shutdown cases. crbug.com/618072 284 // shutdown cases. crbug.com/618072
158 if (!browser_context_) 285 if (!browser_context_)
159 return; 286 return;
160 if (data_reduction_proxy::params::IsIncludedInHoldbackFieldTrial() || 287 if (data_reduction_proxy::params::IsIncludedInHoldbackFieldTrial() ||
161 data_reduction_proxy::params::IsIncludedInTamperDetectionExperiment()) { 288 data_reduction_proxy::params::IsIncludedInTamperDetectionExperiment()) {
162 return; 289 return;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 const page_load_metrics::PageLoadExtraInfo& info) { 404 const page_load_metrics::PageLoadExtraInfo& info) {
278 base::TimeDelta parse_duration = 405 base::TimeDelta parse_duration =
279 timing.parse_stop.value() - timing.parse_start.value(); 406 timing.parse_stop.value() - timing.parse_start.value();
280 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, parse_duration, 407 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, parse_duration,
281 internal::kHistogramParseDurationSuffix); 408 internal::kHistogramParseDurationSuffix);
282 RECORD_HISTOGRAMS_FOR_SUFFIX( 409 RECORD_HISTOGRAMS_FOR_SUFFIX(
283 data_, timing.parse_blocked_on_script_load_duration.value(), 410 data_, timing.parse_blocked_on_script_load_duration.value(),
284 internal::kHistogramParseBlockedOnScriptLoadSuffix); 411 internal::kHistogramParseBlockedOnScriptLoadSuffix);
285 } 412 }
286 413
414 void DataReductionProxyMetricsObserver::OnLoadedResource(
415 const page_load_metrics::ExtraRequestInfo& extra_request_info) {
416 if (extra_request_info.was_cached)
417 return;
418 original_network_bytes_ += extra_request_info.original_network_content_length;
419 network_bytes_ += extra_request_info.raw_body_bytes;
420 num_network_requests_++;
421 if (!extra_request_info.data_reduction_proxy_used)
422 return;
423 num_data_reduction_proxy_requests_++;
424 network_bytes_proxied_ += extra_request_info.raw_body_bytes;
425 }
426
287 DataReductionProxyPingbackClient* 427 DataReductionProxyPingbackClient*
288 DataReductionProxyMetricsObserver::GetPingbackClient() const { 428 DataReductionProxyMetricsObserver::GetPingbackClient() const {
289 return DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 429 return DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
290 browser_context_) 430 browser_context_)
291 ->data_reduction_proxy_service() 431 ->data_reduction_proxy_service()
292 ->pingback_client(); 432 ->pingback_client();
293 } 433 }
294 434
295 } // namespace data_reduction_proxy 435 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698