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

Unified Diff: components/page_load_metrics/browser/metrics_web_contents_observer.cc

Issue 1384213002: Page Abort Events for relevant navigations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More errors, minimum histogram bucket_num is 3 Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: components/page_load_metrics/browser/metrics_web_contents_observer.cc
diff --git a/components/page_load_metrics/browser/metrics_web_contents_observer.cc b/components/page_load_metrics/browser/metrics_web_contents_observer.cc
index 2961f1ecb5dd766e48da0cd1dc87bd6f8ba53cb7..5785c3f0b1e13a213df2f04c9a05555614449c8f 100644
--- a/components/page_load_metrics/browser/metrics_web_contents_observer.cc
+++ b/components/page_load_metrics/browser/metrics_web_contents_observer.cc
@@ -64,45 +64,52 @@ base::Time WallTimeFromTimeTicks(base::TimeTicks time) {
base::TimeDelta::FromMinutes(10), 100)
PageLoadTracker::PageLoadTracker(bool in_foreground)
- : has_commit_(false), started_in_foreground_(in_foreground) {
- RecordEvent(PAGE_LOAD_STARTED);
-}
+ : has_commit_(false), started_in_foreground_(in_foreground) {}
PageLoadTracker::~PageLoadTracker() {
- // Even a load that failed a provisional load should log
- // that it aborted before first layout.
- if (timing_.first_layout.is_zero())
- RecordEvent(PAGE_LOAD_ABORTED_BEFORE_FIRST_LAYOUT);
-
if (has_commit_)
RecordTimingHistograms();
}
void PageLoadTracker::WebContentsHidden() {
// Only log the first time we background in a given page load.
- if (background_time_.is_null()) {
+ if (started_in_foreground_ && background_time_.is_null())
background_time_ = base::TimeTicks::Now();
- }
+}
+
+void PageLoadTracker::WebContentsShown() {
+ // Only log the first time we foreground in a given page load.
+ // Don't log foreground time if we started foregrounded.
+ if (!started_in_foreground_ && foreground_time_.is_null())
+ foreground_time_ = base::TimeTicks::Now();
}
void PageLoadTracker::Commit() {
has_commit_ = true;
+ // This is one special case where we aren't checking if we backgrounded NOW,
+ // but at the start of the navigation.
Bryan McQuade 2015/10/12 16:39:22 let's add a little more detail to explain why we c
Charlie Harrison 2015/10/12 18:39:51 Done.
+ RecordCommittedEvent(COMMITTED_LOAD_STARTED, !started_in_foreground_);
}
-bool PageLoadTracker::UpdateTiming(const PageLoadTiming& timing) {
+bool PageLoadTracker::UpdateTiming(const PageLoadTiming& new_timing) {
// Throw away IPCs that are not relevant to the current navigation.
- if (!timing_.navigation_start.is_null() &&
- timing_.navigation_start != timing.navigation_start) {
- // TODO(csharrison) uma log a counter here
- return false;
- }
- if (IsValidPageLoadTiming(timing)) {
- timing_ = timing;
+ // Two timing structures cannot refer to the same navigation if they indicate
+ // that a navigation started at different times, so a new timing struct with a
+ // different start time from an earlier struct is considered invalid.
+ bool valid_timing_descendent =
+ timing_.navigation_start.is_null() ||
+ timing_.navigation_start == new_timing.navigation_start;
+ if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent) {
+ timing_ = new_timing;
return true;
}
Bryan McQuade 2015/10/12 16:39:23 can we add an else along with a new error enum ent
Charlie Harrison 2015/10/12 18:39:51 We do this one frame up the stack, per Randy's rev
return false;
}
+bool PageLoadTracker::HasBackgrounded() {
+ return !(started_in_foreground_ && background_time_.is_null());
+}
+
void PageLoadTracker::RecordTimingHistograms() {
DCHECK(has_commit_);
// This method is similar to how blink converts TimeTicks to epoch time.
@@ -135,15 +142,18 @@ void PageLoadTracker::RecordTimingHistograms() {
timing_.load_event_start);
}
}
- if (!timing_.first_layout.is_zero()) {
+ if (timing_.first_layout.is_zero()) {
+ RecordCommittedEvent(COMMITTED_LOAD_ABORTED_BEFORE_FIRST_LAYOUT,
+ HasBackgrounded());
+ } else {
if (timing_.first_layout < background_delta) {
PAGE_LOAD_HISTOGRAM("PageLoad.Timing2.NavigationToFirstLayout",
timing_.first_layout);
- RecordEvent(PAGE_LOAD_SUCCESSFUL_FIRST_LAYOUT_FOREGROUND);
+ RecordCommittedEvent(COMMITTED_LOAD_SUCCESSFUL_FIRST_LAYOUT, false);
} else {
PAGE_LOAD_HISTOGRAM("PageLoad.Timing2.NavigationToFirstLayout.BG",
timing_.first_layout);
- RecordEvent(PAGE_LOAD_SUCCESSFUL_FIRST_LAYOUT_BACKGROUND);
+ RecordCommittedEvent(COMMITTED_LOAD_SUCCESSFUL_FIRST_LAYOUT, true);
}
}
if (!timing_.first_text_paint.is_zero()) {
@@ -155,11 +165,40 @@ void PageLoadTracker::RecordTimingHistograms() {
timing_.first_text_paint);
}
}
+ // Log time to first foreground / time to first background. Log counts that we
+ // started a relevant page load in the foreground / background.
+ if (!background_time_.is_null()) {
+ PAGE_LOAD_HISTOGRAM("PageLoad.Timing2.NavigationToFirstBackground",
+ background_delta);
+ } else if (!foreground_time_.is_null()) {
+ PAGE_LOAD_HISTOGRAM(
+ "PageLoad.Timing2.NavigationToFirstForeground",
+ WallTimeFromTimeTicks(foreground_time_) - timing_.navigation_start);
+ }
+}
+
+void PageLoadTracker::RecordProvisionalEvent(ProvisionalLoadEvent event) {
+ if (HasBackgrounded()) {
+ UMA_HISTOGRAM_ENUMERATION("PageLoad.Events.Provisional.BG", event,
+ PROVISIONAL_LOAD_LAST_ENTRY);
+ } else {
+ UMA_HISTOGRAM_ENUMERATION("PageLoad.Events.Provisional", event,
+ PROVISIONAL_LOAD_LAST_ENTRY);
+ }
}
-void PageLoadTracker::RecordEvent(PageLoadEvent event) {
- UMA_HISTOGRAM_ENUMERATION(
- "PageLoad.EventCounts", event, PAGE_LOAD_LAST_ENTRY);
+// RecordCommittedEvent needs a backgrounded input because we need to special
+// case a few events that need either precise timing measurements, or different
+// logic than simply "Did I background before logging this event?"
+void PageLoadTracker::RecordCommittedEvent(CommittedLoadEvent event,
+ bool backgrounded) {
+ if (backgrounded) {
+ UMA_HISTOGRAM_ENUMERATION("PageLoad.Events.Committed.BG", event,
+ COMMITTED_LOAD_LAST_ENTRY);
+ } else {
+ UMA_HISTOGRAM_ENUMERATION("PageLoad.Events.Committed", event,
+ COMMITTED_LOAD_LAST_ENTRY);
+ }
}
MetricsWebContentsObserver::MetricsWebContentsObserver(
@@ -205,11 +244,13 @@ void MetricsWebContentsObserver::DidFinishNavigation(
// Handle a pre-commit error here. Navigations that result in an error page
// will be ignored.
if (!navigation_handle->HasCommitted()) {
- finished_nav->RecordEvent(PAGE_LOAD_FAILED_BEFORE_COMMIT);
if (navigation_handle->GetNetErrorCode() == net::ERR_ABORTED)
- finished_nav->RecordEvent(PAGE_LOAD_ABORTED_BEFORE_COMMIT);
+ finished_nav->RecordProvisionalEvent(PROVISIONAL_LOAD_ABORTED);
+ else
+ finished_nav->RecordProvisionalEvent(PROVISIONAL_LOAD_FAILED_NON_ABORT);
return;
}
+ finished_nav->RecordProvisionalEvent(PROVISIONAL_LOAD_COMMITTED);
// Don't treat a same-page nav as a new page load.
if (navigation_handle->IsSamePage())
@@ -228,6 +269,11 @@ void MetricsWebContentsObserver::DidFinishNavigation(
void MetricsWebContentsObserver::WasShown() {
in_foreground_ = true;
+ if (committed_load_)
+ committed_load_->WebContentsShown();
+ for (const auto& kv : provisional_loads_) {
+ kv.second->WebContentsShown();
+ }
}
void MetricsWebContentsObserver::WasHidden() {
@@ -250,21 +296,40 @@ void MetricsWebContentsObserver::RenderProcessGone(
void MetricsWebContentsObserver::OnTimingUpdated(
content::RenderFrameHost* render_frame_host,
const PageLoadTiming& timing) {
- if (!committed_load_)
- return;
+ bool error = false;
+ if (!committed_load_) {
+ UMA_HISTOGRAM_ENUMERATION("PageLoad.Events.Error",
Bryan McQuade 2015/10/12 16:39:22 Is there a name we could use to convey that these
+ ERR_IPC_WITH_NO_COMMITTED_LOAD, ERR_LAST_ENTRY);
+ error = true;
+ }
// We may receive notifications from frames that have been navigated away
// from. We simply ignore them.
- if (render_frame_host != web_contents()->GetMainFrame())
- return;
+ if (render_frame_host != web_contents()->GetMainFrame()) {
+ UMA_HISTOGRAM_ENUMERATION("PageLoad.Events.Error", ERR_IPC_FROM_WRONG_FRAME,
+ ERR_LAST_ENTRY);
+ error = true;
+ }
// For urls like chrome://newtab, the renderer and browser disagree,
// so we have to double check that the renderer isn't sending data from a
// bad url like https://www.google.com/_/chrome/newtab.
- if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS())
+ if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) {
+ UMA_HISTOGRAM_ENUMERATION("PageLoad.Events.Error",
+ ERR_IPC_FROM_BAD_URL_SCHEME, ERR_LAST_ENTRY);
+ error = true;
+ }
+
+ if (error)
return;
- committed_load_->UpdateTiming(timing);
+ if (!committed_load_->UpdateTiming(timing)) {
+ // If the page load tracker cannot update its timing, something is wrong
+ // with the IPC (it's from another load, or it's invalid in some other way).
+ // We expect this to be a rare occurrence.
+ UMA_HISTOGRAM_ENUMERATION("PageLoad.Events.Error", ERR_BAD_TIMING_IPC,
+ ERR_LAST_ENTRY);
+ }
}
bool MetricsWebContentsObserver::IsRelevantNavigation(

Powered by Google App Engine
This is Rietveld 408576698