Bug 1466208 - part 33: Create PresShell::EventHandler::RecordEventHandlingResponsePerformance() r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 06 Mar 2019 06:03:54 +0000
changeset 520680 5ad056528954bd501ceedf8d69c1e2554a924664
parent 520679 d5fbe4f31e516480cad3a5040db11984cab08e9c
child 520681 b52eb25bbe9c8b4ecf2bdc807e0f71740ff0870c
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1466208
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1466208 - part 33: Create PresShell::EventHandler::RecordEventHandlingResponsePerformance() r=smaug `PresShell::EventHandler::HandleEventInternal()` recodes event handling response performance with telemetry after it dispatches the event. We can move it into new method simply. Differential Revision: https://phabricator.services.mozilla.com/D21334
layout/base/PresShell.cpp
layout/base/PresShell.h
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -7962,72 +7962,78 @@ nsresult PresShell::EventHandler::Handle
                 handlerStartTime);
           }
           break;
         default:
           break;
       }
     }
   }
-
-  if (Telemetry::CanRecordBase() && !aEvent->mTimeStamp.IsNull() &&
-      aEvent->mTimeStamp > mPresShell->mLastOSWake && aEvent->AsInputEvent()) {
-    TimeStamp now = TimeStamp::Now();
-    double millis = (now - aEvent->mTimeStamp).ToMilliseconds();
-    Telemetry::Accumulate(Telemetry::INPUT_EVENT_RESPONSE_MS, millis);
-    if (GetDocument() &&
-        GetDocument()->GetReadyStateEnum() != Document::READYSTATE_COMPLETE) {
-      Telemetry::Accumulate(Telemetry::LOAD_INPUT_EVENT_RESPONSE_MS, millis);
-    }
-
-    if (!sLastInputProcessed || sLastInputProcessed < aEvent->mTimeStamp) {
-      if (sLastInputProcessed) {
-        // This input event was created after we handled the last one.
-        // Accumulate the previous events' coalesced duration.
-        double lastMillis =
-            (sLastInputProcessed - sLastInputCreated).ToMilliseconds();
-        Telemetry::Accumulate(Telemetry::INPUT_EVENT_RESPONSE_COALESCED_MS,
-                              lastMillis);
-
-        if (MOZ_UNLIKELY(!PresShell::sProcessInteractable)) {
-          // For content process, we use the ready state of
-          // top-level-content-document to know if the process has finished the
-          // start-up.
-          // For parent process, see the topic
-          // 'sessionstore-one-or-no-tab-restored' in PresShell::Observe.
-          if (XRE_IsContentProcess() && GetDocument() &&
-              GetDocument()->IsTopLevelContentDocument()) {
-            switch (GetDocument()->GetReadyStateEnum()) {
-              case Document::READYSTATE_INTERACTIVE:
-              case Document::READYSTATE_COMPLETE:
-                PresShell::sProcessInteractable = true;
-                break;
-              default:
-                break;
-            }
+  RecordEventHandlingResponsePerformance(aEvent);
+  return rv;
+}
+
+void PresShell::EventHandler::RecordEventHandlingResponsePerformance(
+    const WidgetEvent* aEvent) {
+  if (!Telemetry::CanRecordBase() || aEvent->mTimeStamp.IsNull() ||
+      aEvent->mTimeStamp <= mPresShell->mLastOSWake ||
+      !aEvent->AsInputEvent()) {
+    return;
+  }
+
+  TimeStamp now = TimeStamp::Now();
+  double millis = (now - aEvent->mTimeStamp).ToMilliseconds();
+  Telemetry::Accumulate(Telemetry::INPUT_EVENT_RESPONSE_MS, millis);
+  if (GetDocument() &&
+      GetDocument()->GetReadyStateEnum() != Document::READYSTATE_COMPLETE) {
+    Telemetry::Accumulate(Telemetry::LOAD_INPUT_EVENT_RESPONSE_MS, millis);
+  }
+
+  if (!sLastInputProcessed || sLastInputProcessed < aEvent->mTimeStamp) {
+    if (sLastInputProcessed) {
+      // This input event was created after we handled the last one.
+      // Accumulate the previous events' coalesced duration.
+      double lastMillis =
+          (sLastInputProcessed - sLastInputCreated).ToMilliseconds();
+      Telemetry::Accumulate(Telemetry::INPUT_EVENT_RESPONSE_COALESCED_MS,
+                            lastMillis);
+
+      if (MOZ_UNLIKELY(!PresShell::sProcessInteractable)) {
+        // For content process, we use the ready state of
+        // top-level-content-document to know if the process has finished the
+        // start-up.
+        // For parent process, see the topic
+        // 'sessionstore-one-or-no-tab-restored' in PresShell::Observe.
+        if (XRE_IsContentProcess() && GetDocument() &&
+            GetDocument()->IsTopLevelContentDocument()) {
+          switch (GetDocument()->GetReadyStateEnum()) {
+            case Document::READYSTATE_INTERACTIVE:
+            case Document::READYSTATE_COMPLETE:
+              PresShell::sProcessInteractable = true;
+              break;
+            default:
+              break;
           }
         }
-        if (MOZ_LIKELY(PresShell::sProcessInteractable)) {
-          Telemetry::Accumulate(Telemetry::INPUT_EVENT_RESPONSE_POST_STARTUP_MS,
-                                lastMillis);
-        } else {
-          Telemetry::Accumulate(Telemetry::INPUT_EVENT_RESPONSE_STARTUP_MS,
-                                lastMillis);
-        }
-      }
-      sLastInputCreated = aEvent->mTimeStamp;
-    } else if (aEvent->mTimeStamp < sLastInputCreated) {
-      // This event was created before the last input. May be processing out
-      // of order, so coalesce backwards, too.
-      sLastInputCreated = aEvent->mTimeStamp;
-    }
-    sLastInputProcessed = now;
-  }
-
-  return rv;
+      }
+      if (MOZ_LIKELY(PresShell::sProcessInteractable)) {
+        Telemetry::Accumulate(Telemetry::INPUT_EVENT_RESPONSE_POST_STARTUP_MS,
+                              lastMillis);
+      } else {
+        Telemetry::Accumulate(Telemetry::INPUT_EVENT_RESPONSE_STARTUP_MS,
+                              lastMillis);
+      }
+    }
+    sLastInputCreated = aEvent->mTimeStamp;
+  } else if (aEvent->mTimeStamp < sLastInputCreated) {
+    // This event was created before the last input. May be processing out
+    // of order, so coalesce backwards, too.
+    sLastInputCreated = aEvent->mTimeStamp;
+  }
+  sLastInputProcessed = now;
 }
 
 // static
 already_AddRefed<nsIURI>
 PresShell::EventHandler::GetDocumentURIToCompareWithBlacklist(
     PresShell& aPresShell) {
   nsPresContext* presContext = aPresShell.GetPresContext();
   if (NS_WARN_IF(!presContext)) {
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -1046,16 +1046,24 @@ class PresShell final : public nsIPresSh
      */
     MOZ_CAN_RUN_SCRIPT
     nsresult HandleEventInternal(WidgetEvent* aEvent,
                                  nsEventStatus* aEventStatus,
                                  bool aIsHandlingNativeEvent,
                                  nsIContent* aOverrideClickTarget);
 
     /**
+     * RecordEventHandlingResponsePerformance() records event handling response
+     * performance with telemetry.
+     *
+     * @param aEvent            The handled event.
+     */
+    void RecordEventHandlingResponsePerformance(const WidgetEvent* aEvent);
+
+    /**
      * This and the next two helper methods are used to target and position the
      * context menu when the keyboard shortcut is used to open it.
      *
      * If another menu is open, the context menu is opened relative to the
      * active menuitem within the menu, or the menu itself if no item is active.
      * Otherwise, if the caret is visible, the menu is opened near the caret.
      * Otherwise, if a selectable list such as a listbox is focused, the
      * current item within the menu is opened relative to this item.