Bug 1301346 - Add telemetry to collect how much time was spent in handling beforeunload and unload event. r=smaug,bsmedberg draft
authorKan-Ru Chen <kanru@kanru.info>
Fri, 09 Sep 2016 12:06:36 +0800
changeset 430702 7ec81d75d4253c675981f0c763390e038247ef56
parent 430701 944cb0fd05526894fcd90fbe7d1e625ee53cd73d
child 535243 c333308c68dd3bb63104cad7a935e63f8abf281b
push id33866
push userbmo:kchen@mozilla.com
push dateFri, 28 Oct 2016 02:36:58 +0000
reviewerssmaug, bsmedberg
bugs1301346
milestone52.0a1
Bug 1301346 - Add telemetry to collect how much time was spent in handling beforeunload and unload event. r=smaug,bsmedberg 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."
   }
 }