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

Side by Side Diff: components/page_load_metrics/browser/metrics_web_contents_observer.cc

Issue 1423263003: Add time-to-first-contentful-paint to PageLoadMetrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: naming Created 5 years, 1 month 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/page_load_metrics/browser/metrics_web_contents_observer.h" 5 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "components/page_load_metrics/browser/page_load_metrics_macros.h" 10 #include "components/page_load_metrics/browser/page_load_metrics_macros.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 base::Time WallTimeFromTimeTicks(base::TimeTicks time) { 77 base::Time WallTimeFromTimeTicks(base::TimeTicks time) {
78 return base::Time::FromDoubleT( 78 return base::Time::FromDoubleT(
79 (time - base::TimeTicks::UnixEpoch()).InSecondsF()); 79 (time - base::TimeTicks::UnixEpoch()).InSecondsF());
80 } 80 }
81 81
82 void RecordInternalError(InternalErrorLoadEvent event) { 82 void RecordInternalError(InternalErrorLoadEvent event) {
83 UMA_HISTOGRAM_ENUMERATION( 83 UMA_HISTOGRAM_ENUMERATION(
84 "PageLoad.Events.InternalError", event, ERR_LAST_ENTRY); 84 "PageLoad.Events.InternalError", event, ERR_LAST_ENTRY);
85 } 85 }
86 86
87 base::TimeDelta GetFirstContentfulPaint(const PageLoadTiming& timing) {
88 if (timing.first_text_paint.is_zero())
89 return timing.first_image_paint;
90 if (timing.first_image_paint.is_zero())
91 return timing.first_text_paint;
92 return std::min(timing.first_text_paint, timing.first_image_paint);
93 }
94
87 } // namespace 95 } // namespace
88 96
89 PageLoadTracker::PageLoadTracker( 97 PageLoadTracker::PageLoadTracker(
90 bool in_foreground, 98 bool in_foreground,
91 base::ObserverList<PageLoadMetricsObserver, true>* observers) 99 base::ObserverList<PageLoadMetricsObserver, true>* observers)
92 : has_commit_(false), 100 : has_commit_(false),
93 started_in_foreground_(in_foreground), 101 started_in_foreground_(in_foreground),
94 observers_(observers) {} 102 observers_(observers) {}
95 103
96 PageLoadTracker::~PageLoadTracker() { 104 PageLoadTracker::~PageLoadTracker() {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 if (!timing_.first_image_paint.is_zero()) { 242 if (!timing_.first_image_paint.is_zero()) {
235 if (timing_.first_image_paint < background_delta) { 243 if (timing_.first_image_paint < background_delta) {
236 PAGE_LOAD_HISTOGRAM("PageLoad.Timing2.NavigationToFirstImagePaint", 244 PAGE_LOAD_HISTOGRAM("PageLoad.Timing2.NavigationToFirstImagePaint",
237 timing_.first_image_paint); 245 timing_.first_image_paint);
238 } else { 246 } else {
239 PAGE_LOAD_HISTOGRAM( 247 PAGE_LOAD_HISTOGRAM(
240 "PageLoad.Timing2.NavigationToFirstImagePaint.Background", 248 "PageLoad.Timing2.NavigationToFirstImagePaint.Background",
241 timing_.first_image_paint); 249 timing_.first_image_paint);
242 } 250 }
243 } 251 }
252 base::TimeDelta first_contentful_paint = GetFirstContentfulPaint(timing_);
253 if (!first_contentful_paint.is_zero()) {
254 if (first_contentful_paint < background_delta) {
255 PAGE_LOAD_HISTOGRAM("PageLoad.Timing2.NavigationToFirstContentfulPaint",
256 first_contentful_paint);
257 } else {
258 PAGE_LOAD_HISTOGRAM(
259 "PageLoad.Timing2.NavigationToFirstContentfulPaint.Background",
260 first_contentful_paint);
261 }
262 }
263
244 // Log time to first foreground / time to first background. Log counts that we 264 // Log time to first foreground / time to first background. Log counts that we
245 // started a relevant page load in the foreground / background. 265 // started a relevant page load in the foreground / background.
246 if (!background_time_.is_null()) { 266 if (!background_time_.is_null()) {
247 PAGE_LOAD_HISTOGRAM("PageLoad.Timing2.NavigationToFirstBackground", 267 PAGE_LOAD_HISTOGRAM("PageLoad.Timing2.NavigationToFirstBackground",
248 background_delta); 268 background_delta);
249 } else if (!foreground_time_.is_null()) { 269 } else if (!foreground_time_.is_null()) {
250 PAGE_LOAD_HISTOGRAM( 270 PAGE_LOAD_HISTOGRAM(
251 "PageLoad.Timing2.NavigationToFirstForeground", 271 "PageLoad.Timing2.NavigationToFirstForeground",
252 WallTimeFromTimeTicks(foreground_time_) - timing_.navigation_start); 272 WallTimeFromTimeTicks(foreground_time_) - timing_.navigation_start);
253 } 273 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 459
440 if (!committed_load_->UpdateTiming(timing)) { 460 if (!committed_load_->UpdateTiming(timing)) {
441 // If the page load tracker cannot update its timing, something is wrong 461 // If the page load tracker cannot update its timing, something is wrong
442 // with the IPC (it's from another load, or it's invalid in some other way). 462 // with the IPC (it's from another load, or it's invalid in some other way).
443 // We expect this to be a rare occurrence. 463 // We expect this to be a rare occurrence.
444 RecordInternalError(ERR_BAD_TIMING_IPC); 464 RecordInternalError(ERR_BAD_TIMING_IPC);
445 } 465 }
446 } 466 }
447 467
448 } // namespace page_load_metrics 468 } // namespace page_load_metrics
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698