OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/core_page_load_metrics_obse rver.h" | 5 #include "chrome/browser/page_load_metrics/observers/core_page_load_metrics_obse rver.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "components/page_load_metrics/browser/page_load_metrics_util.h" | 12 #include "components/page_load_metrics/browser/page_load_metrics_util.h" |
13 #include "components/rappor/rappor_service.h" | 13 #include "components/rappor/rappor_service.h" |
14 #include "components/rappor/rappor_utils.h" | 14 #include "components/rappor/rappor_utils.h" |
15 #include "ui/base/page_transition_types.h" | |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // The number of buckets in the bitfield histogram. These buckets are described | 19 // The number of buckets in the bitfield histogram. These buckets are described |
19 // in rappor.xml in PageLoad.CoarseTiming.NavigationToFirstContentfulPaint. | 20 // in rappor.xml in PageLoad.CoarseTiming.NavigationToFirstContentfulPaint. |
20 // The bucket flag is defined by 1 << bucket_index, and is the bitfield | 21 // The bucket flag is defined by 1 << bucket_index, and is the bitfield |
21 // representing which timing bucket the page load falls into, i.e. 000010 | 22 // representing which timing bucket the page load falls into, i.e. 000010 |
22 // would be the bucket flag showing that the page took between 2 and 4 seconds | 23 // would be the bucket flag showing that the page took between 2 and 4 seconds |
23 // to load. | 24 // to load. |
24 const size_t kNumRapporHistogramBuckets = 6; | 25 const size_t kNumRapporHistogramBuckets = 6; |
25 | 26 |
26 uint64_t RapporHistogramBucketIndex(base::TimeDelta time) { | 27 uint64_t RapporHistogramBucketIndex(base::TimeDelta time) { |
27 int64_t seconds = time.InSeconds(); | 28 int64_t seconds = time.InSeconds(); |
28 if (seconds < 2) | 29 if (seconds < 2) |
29 return 0; | 30 return 0; |
30 if (seconds < 4) | 31 if (seconds < 4) |
31 return 1; | 32 return 1; |
32 if (seconds < 8) | 33 if (seconds < 8) |
33 return 2; | 34 return 2; |
34 if (seconds < 16) | 35 if (seconds < 16) |
35 return 3; | 36 return 3; |
36 if (seconds < 32) | 37 if (seconds < 32) |
37 return 4; | 38 return 4; |
38 return 5; | 39 return 5; |
39 } | 40 } |
40 | 41 |
42 // TODO(bmcquade): If other observers want to log histograms based on load type, | |
43 // promote this enum to page_load_metrics_observer.h. | |
44 enum PageLoadType { | |
45 LOAD_TYPE_NONE = 0, | |
46 LOAD_TYPE_RELOAD, | |
47 LOAD_TYPE_FORWARD_BACK, | |
48 LOAD_TYPE_NEW_NAVIGATION | |
49 }; | |
50 | |
51 PageLoadType GetPageLoadType(ui::PageTransition transition) { | |
52 if (ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD)) { | |
53 return LOAD_TYPE_RELOAD; | |
54 } | |
55 if (transition & ui::PAGE_TRANSITION_FORWARD_BACK) { | |
Bryan McQuade
2016/06/27 11:46:44
regarding your comment about incorrectly accountin
| |
56 return LOAD_TYPE_FORWARD_BACK; | |
57 } | |
58 if (ui::PageTransitionIsNewNavigation(transition)) { | |
59 return LOAD_TYPE_NEW_NAVIGATION; | |
60 } | |
61 NOTREACHED() << "Received PageTransition with no matching PageLoadType."; | |
62 return LOAD_TYPE_NONE; | |
63 } | |
64 | |
41 } // namespace | 65 } // namespace |
42 | 66 |
43 namespace internal { | 67 namespace internal { |
44 | 68 |
45 const char kHistogramCommit[] = "PageLoad.Timing2.NavigationToCommit"; | 69 const char kHistogramCommit[] = "PageLoad.Timing2.NavigationToCommit"; |
46 const char kHistogramFirstLayout[] = "PageLoad.Timing2.NavigationToFirstLayout"; | 70 const char kHistogramFirstLayout[] = "PageLoad.Timing2.NavigationToFirstLayout"; |
47 const char kHistogramFirstTextPaint[] = | 71 const char kHistogramFirstTextPaint[] = |
48 "PageLoad.Timing2.NavigationToFirstTextPaint"; | 72 "PageLoad.Timing2.NavigationToFirstTextPaint"; |
49 const char kHistogramDomContentLoaded[] = | 73 const char kHistogramDomContentLoaded[] = |
50 "PageLoad.Timing2.NavigationToDOMContentLoadedEventFired"; | 74 "PageLoad.Timing2.NavigationToDOMContentLoadedEventFired"; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 "PageLoad.ParseTiming.ParseBlockedOnScriptLoad"; | 170 "PageLoad.ParseTiming.ParseBlockedOnScriptLoad"; |
147 const char kBackgroundHistogramParseBlockedOnScriptLoadImmediate[] = | 171 const char kBackgroundHistogramParseBlockedOnScriptLoadImmediate[] = |
148 "PageLoad.ParseTiming.ParseBlockedOnScriptLoad.Background"; | 172 "PageLoad.ParseTiming.ParseBlockedOnScriptLoad.Background"; |
149 const char kHistogramParseBlockedOnScriptLoadDocumentWriteImmediate[] = | 173 const char kHistogramParseBlockedOnScriptLoadDocumentWriteImmediate[] = |
150 "PageLoad.ParseTiming.ParseBlockedOnScriptLoadFromDocumentWrite"; | 174 "PageLoad.ParseTiming.ParseBlockedOnScriptLoadFromDocumentWrite"; |
151 const char | 175 const char |
152 kBackgroundHistogramParseBlockedOnScriptLoadDocumentWriteImmediate[] = | 176 kBackgroundHistogramParseBlockedOnScriptLoadDocumentWriteImmediate[] = |
153 "PageLoad.ParseTiming.ParseBlockedOnScriptLoadFromDocumentWrite." | 177 "PageLoad.ParseTiming.ParseBlockedOnScriptLoadFromDocumentWrite." |
154 "Background"; | 178 "Background"; |
155 | 179 |
180 const char kHistogramLoadTypeFirstContentfulPaintReload[] = | |
181 "PageLoad.PaintTiming.NavigationToFirstContentfulPaint.LoadType." | |
182 "Reload"; | |
183 const char kHistogramLoadTypeFirstContentfulPaintReloadByGesture[] = | |
184 "PageLoad.PaintTiming.NavigationToFirstContentfulPaint.LoadType." | |
185 "Reload.UserGesture"; | |
186 const char kHistogramLoadTypeFirstContentfulPaintForwardBack[] = | |
187 "PageLoad.PaintTiming.NavigationToFirstContentfulPaint.LoadType." | |
188 "ForwardBackNavigation"; | |
189 const char kHistogramLoadTypeFirstContentfulPaintNewNavigation[] = | |
190 "PageLoad.PaintTiming.NavigationToFirstContentfulPaint.LoadType." | |
191 "NewNavigation"; | |
192 | |
156 const char kHistogramFirstContentfulPaintHigh[] = | 193 const char kHistogramFirstContentfulPaintHigh[] = |
157 "PageLoad.Timing2.NavigationToFirstContentfulPaint.HighResolutionClock"; | 194 "PageLoad.Timing2.NavigationToFirstContentfulPaint.HighResolutionClock"; |
158 const char kHistogramFirstContentfulPaintLow[] = | 195 const char kHistogramFirstContentfulPaintLow[] = |
159 "PageLoad.Timing2.NavigationToFirstContentfulPaint.LowResolutionClock"; | 196 "PageLoad.Timing2.NavigationToFirstContentfulPaint.LowResolutionClock"; |
160 | 197 |
161 const char kHistogramFirstBackground[] = | 198 const char kHistogramFirstBackground[] = |
162 "PageLoad.Timing2.NavigationToFirstBackground"; | 199 "PageLoad.Timing2.NavigationToFirstBackground"; |
163 const char kHistogramFirstForeground[] = | 200 const char kHistogramFirstForeground[] = |
164 "PageLoad.Timing2.NavigationToFirstForeground"; | 201 "PageLoad.Timing2.NavigationToFirstForeground"; |
165 | 202 |
166 const char kHistogramBackgroundBeforePaint[] = | 203 const char kHistogramBackgroundBeforePaint[] = |
167 "PageLoad.Timing2.NavigationToFirstBackground.AfterCommit.BeforePaint"; | 204 "PageLoad.Timing2.NavigationToFirstBackground.AfterCommit.BeforePaint"; |
168 const char kHistogramBackgroundBeforeCommit[] = | 205 const char kHistogramBackgroundBeforeCommit[] = |
169 "PageLoad.Timing2.NavigationToFirstBackground.BeforeCommit"; | 206 "PageLoad.Timing2.NavigationToFirstBackground.BeforeCommit"; |
170 const char kHistogramBackgroundDuringParse[] = | 207 const char kHistogramBackgroundDuringParse[] = |
171 "PageLoad.Timing2.NavigationToFirstBackground.DuringParse"; | 208 "PageLoad.Timing2.NavigationToFirstBackground.DuringParse"; |
172 const char kHistogramFailedProvisionalLoad[] = | 209 const char kHistogramFailedProvisionalLoad[] = |
173 "PageLoad.Timing2.NavigationToFailedProvisionalLoad"; | 210 "PageLoad.Timing2.NavigationToFailedProvisionalLoad"; |
174 | 211 |
175 const char kHistogramForegroundToFirstPaint[] = | 212 const char kHistogramForegroundToFirstPaint[] = |
176 "PageLoad.Timing2.ForegroundToFirstPaint"; | 213 "PageLoad.Timing2.ForegroundToFirstPaint"; |
177 | 214 |
178 const char kRapporMetricsNameCoarseTiming[] = | 215 const char kRapporMetricsNameCoarseTiming[] = |
179 "PageLoad.CoarseTiming.NavigationToFirstContentfulPaint"; | 216 "PageLoad.CoarseTiming.NavigationToFirstContentfulPaint"; |
180 | 217 |
181 } // namespace internal | 218 } // namespace internal |
182 | 219 |
183 CorePageLoadMetricsObserver::CorePageLoadMetricsObserver() {} | 220 CorePageLoadMetricsObserver::CorePageLoadMetricsObserver() |
221 : transition_(ui::PAGE_TRANSITION_LINK), | |
222 initiated_by_user_gesture_(false) {} | |
184 | 223 |
185 CorePageLoadMetricsObserver::~CorePageLoadMetricsObserver() {} | 224 CorePageLoadMetricsObserver::~CorePageLoadMetricsObserver() {} |
186 | 225 |
226 void CorePageLoadMetricsObserver::OnCommit( | |
227 content::NavigationHandle* navigation_handle) { | |
228 transition_ = navigation_handle->GetPageTransition(); | |
229 initiated_by_user_gesture_ = navigation_handle->HasUserGesture(); | |
230 } | |
231 | |
187 void CorePageLoadMetricsObserver::OnDomContentLoadedEventStart( | 232 void CorePageLoadMetricsObserver::OnDomContentLoadedEventStart( |
188 const page_load_metrics::PageLoadTiming& timing, | 233 const page_load_metrics::PageLoadTiming& timing, |
189 const page_load_metrics::PageLoadExtraInfo& info) { | 234 const page_load_metrics::PageLoadExtraInfo& info) { |
190 if (WasStartedInForegroundEventInForeground( | 235 if (WasStartedInForegroundEventInForeground( |
191 timing.dom_content_loaded_event_start, info)) { | 236 timing.dom_content_loaded_event_start, info)) { |
192 PAGE_LOAD_HISTOGRAM(internal::kHistogramDomContentLoadedImmediate, | 237 PAGE_LOAD_HISTOGRAM(internal::kHistogramDomContentLoadedImmediate, |
193 timing.dom_content_loaded_event_start); | 238 timing.dom_content_loaded_event_start); |
194 } else { | 239 } else { |
195 PAGE_LOAD_HISTOGRAM(internal::kBackgroundHistogramDomContentLoadedImmediate, | 240 PAGE_LOAD_HISTOGRAM(internal::kBackgroundHistogramDomContentLoadedImmediate, |
196 timing.dom_content_loaded_event_start); | 241 timing.dom_content_loaded_event_start); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 void CorePageLoadMetricsObserver::OnFirstContentfulPaint( | 305 void CorePageLoadMetricsObserver::OnFirstContentfulPaint( |
261 const page_load_metrics::PageLoadTiming& timing, | 306 const page_load_metrics::PageLoadTiming& timing, |
262 const page_load_metrics::PageLoadExtraInfo& info) { | 307 const page_load_metrics::PageLoadExtraInfo& info) { |
263 if (WasStartedInForegroundEventInForeground(timing.first_contentful_paint, | 308 if (WasStartedInForegroundEventInForeground(timing.first_contentful_paint, |
264 info)) { | 309 info)) { |
265 PAGE_LOAD_HISTOGRAM(internal::kHistogramFirstContentfulPaintImmediate, | 310 PAGE_LOAD_HISTOGRAM(internal::kHistogramFirstContentfulPaintImmediate, |
266 timing.first_contentful_paint); | 311 timing.first_contentful_paint); |
267 PAGE_LOAD_HISTOGRAM( | 312 PAGE_LOAD_HISTOGRAM( |
268 internal::kHistogramParseStartToFirstContentfulPaintImmediate, | 313 internal::kHistogramParseStartToFirstContentfulPaintImmediate, |
269 timing.first_contentful_paint - timing.parse_start); | 314 timing.first_contentful_paint - timing.parse_start); |
315 | |
316 switch (GetPageLoadType(transition_)) { | |
317 case LOAD_TYPE_RELOAD: | |
318 PAGE_LOAD_HISTOGRAM( | |
319 internal::kHistogramLoadTypeFirstContentfulPaintReload, | |
320 timing.first_contentful_paint); | |
321 if (initiated_by_user_gesture_) { | |
322 PAGE_LOAD_HISTOGRAM( | |
323 internal::kHistogramLoadTypeFirstContentfulPaintReloadByGesture, | |
324 timing.first_contentful_paint); | |
325 } | |
326 break; | |
327 case LOAD_TYPE_FORWARD_BACK: | |
328 PAGE_LOAD_HISTOGRAM( | |
329 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, | |
330 timing.first_contentful_paint); | |
331 break; | |
332 case LOAD_TYPE_NEW_NAVIGATION: | |
333 PAGE_LOAD_HISTOGRAM( | |
334 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, | |
335 timing.first_contentful_paint); | |
336 break; | |
337 case LOAD_TYPE_NONE: | |
338 NOTREACHED(); | |
339 break; | |
340 } | |
270 } else { | 341 } else { |
271 PAGE_LOAD_HISTOGRAM( | 342 PAGE_LOAD_HISTOGRAM( |
272 internal::kBackgroundHistogramFirstContentfulPaintImmediate, | 343 internal::kBackgroundHistogramFirstContentfulPaintImmediate, |
273 timing.first_contentful_paint); | 344 timing.first_contentful_paint); |
274 PAGE_LOAD_HISTOGRAM( | 345 PAGE_LOAD_HISTOGRAM( |
275 internal::kBackgroundHistogramParseStartToFirstContentfulPaintImmediate, | 346 internal::kBackgroundHistogramParseStartToFirstContentfulPaintImmediate, |
276 timing.first_contentful_paint - timing.parse_start); | 347 timing.first_contentful_paint - timing.parse_start); |
277 } | 348 } |
278 } | 349 } |
279 | 350 |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 RapporHistogramBucketIndex(timing.first_contentful_paint); | 643 RapporHistogramBucketIndex(timing.first_contentful_paint); |
573 sample->SetFlagsField("Bucket", uint64_t(1) << bucket_index, | 644 sample->SetFlagsField("Bucket", uint64_t(1) << bucket_index, |
574 kNumRapporHistogramBuckets); | 645 kNumRapporHistogramBuckets); |
575 // The IsSlow flag is just a one bit boolean if the first contentful paint | 646 // The IsSlow flag is just a one bit boolean if the first contentful paint |
576 // was > 10s. | 647 // was > 10s. |
577 sample->SetFlagsField("IsSlow", | 648 sample->SetFlagsField("IsSlow", |
578 timing.first_contentful_paint.InSecondsF() >= 10, 1); | 649 timing.first_contentful_paint.InSecondsF() >= 10, 1); |
579 rappor_service->RecordSampleObj(internal::kRapporMetricsNameCoarseTiming, | 650 rappor_service->RecordSampleObj(internal::kRapporMetricsNameCoarseTiming, |
580 std::move(sample)); | 651 std::move(sample)); |
581 } | 652 } |
OLD | NEW |