Bug 1301346 - Add telemetry to collect how much time was spent in handling beforeunload and unload event. r=bsmedberg,smaug
authorKan-Ru Chen <kanru@kanru.info>
Fri, 09 Sep 2016 12:06:36 +0800
changeset 319912 466b0de6dfcbb27630de8ddfe66db89951a2dc34
parent 319911 4537bb4cfb82972e3c88b73e1b7c48e98e667348
child 319913 bb8f38a1583fcb632acf1941bf8063c7d0e7dd73
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg, smaug
bugs1301346
milestone52.0a1
Bug 1301346 - Add telemetry to collect how much time was spent in handling beforeunload and unload event. r=bsmedberg,smaug MozReview-Commit-ID: 3jCsBcDncGC
layout/base/nsDocumentViewer.cpp
toolkit/components/telemetry/Histograms.json
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -1136,18 +1136,21 @@ nsDocumentViewer::PermitUnloadInternal(b
     // Never permit dialogs from the beforeunload handler
     nsGlobalWindow* globalWindow = nsGlobalWindow::Cast(window);
     dialogsAreEnabled = globalWindow->AreDialogsEnabled();
     nsGlobalWindow::TemporarilyDisableDialogs disableDialogs(globalWindow);
 
     nsIDocument::PageUnloadingEventTimeStamp timestamp(mDocument);
 
     mInPermitUnload = true;
-    EventDispatcher::DispatchDOMEvent(window, nullptr, event, mPresContext,
-                                      nullptr);
+    {
+      Telemetry::AutoTimer<Telemetry::HANDLE_BEFOREUNLOAD_MS> telemetryTimer;
+      EventDispatcher::DispatchDOMEvent(window, nullptr, event, mPresContext,
+                                        nullptr);
+    }
     mInPermitUnload = false;
   }
 
   nsCOMPtr<nsIDocShell> docShell(mContainer);
   nsAutoString text;
   beforeUnload->GetReturnValue(text);
 
   // NB: we nullcheck mDocument because it might now be dead as a result of
@@ -1320,17 +1323,20 @@ nsDocumentViewer::PageHide(bool aIsUnloa
     event.mTarget = mDocument;
 
     // Never permit popups from the unload handler, no matter how we get
     // here.
     nsAutoPopupStatePusher popupStatePusher(openAbused, true);
 
     nsIDocument::PageUnloadingEventTimeStamp timestamp(mDocument);
 
-    EventDispatcher::Dispatch(window, mPresContext, &event, nullptr, &status);
+    {
+      Telemetry::AutoTimer<Telemetry::HANDLE_UNLOAD_MS> telemetryTimer;
+      EventDispatcher::Dispatch(window, mPresContext, &event, nullptr, &status);
+    }
   }
 
 #ifdef MOZ_XUL
   // look for open menupopups and close them after the unload event, in case
   // the unload event listeners open any new popups
   nsContentUtils::HidePopupsInDocument(mDocument);
 #endif
 
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -10369,10 +10369,28 @@
     "alert_emails": ["eisaacson@mozilla.com"],
     "bug_numbers": [1308030],
     "releaseChannelCollection": "opt-out",
     "expires_in_version": "56",
     "kind": "linear",
     "high": 300000,
     "n_buckets": 30,
     "description": "Time in MS that content is narrated in 10 second increments up to 5 minutes"
+  },
+  "HANDLE_UNLOAD_MS": {
+    "alert_emails": ["kchen@mozilla.com"],
+    "expires_in_version": "55",
+    "kind": "exponential",
+    "high": 10000,
+    "n_buckets": 50,
+    "bug_numbers": [1301346],
+    "description": "The time spent handling unload event in milliseconds. It measures all documents and subframes separately. If there are multiple handlers for the unload event in a document, this will record a single value across all handlers in the document."
+  },
+  "HANDLE_BEFOREUNLOAD_MS": {
+    "alert_emails": ["kchen@mozilla.com"],
+    "expires_in_version": "55",
+    "kind": "exponential",
+    "high": 10000,
+    "n_buckets": 50,
+    "bug_numbers": [1301346],
+    "description": "The time spent handling beforeunload event in milliseconds. It measures all documents and subframes separately. If there are multiple handlers for the unload event in a document, this will record a single value across all handlers in the document."
   }
 }