Bug 1451460 - Switch to using MozLayerTreeReady in the parent process to know when to stop the TPS stopwatch. r?rwood draft
authorMike Conley <mconley@mozilla.com>
Thu, 05 Apr 2018 15:01:44 -0400
changeset 779377 7ec74ab5bc2dcea33cb2c6ec6ba1c21360bfbf65
parent 779376 018d37d8a0f19ee73f8aa978c49da476c5db3e34
child 779378 5f853017deb3c7d8ed39ef72e0a1039db3d00561
push id105760
push usermconley@mozilla.com
push dateMon, 09 Apr 2018 20:21:39 +0000
reviewersrwood
bugs1451460
milestone61.0a1
Bug 1451460 - Switch to using MozLayerTreeReady in the parent process to know when to stop the TPS stopwatch. r?rwood MozLayerTreeReady is fired once the parent process hears from the compositor that the layers from a remote tab have been painted and uploaded. For tab switching, this is a far more accurate assessment of when the tab is actually presented to the user, since this is the event that the async tab switcher also listens for. MozReview-Commit-ID: 8oy5MqNwWNS
testing/talos/talos/tests/tabswitch/api.js
--- a/testing/talos/talos/tests/tabswitch/api.js
+++ b/testing/talos/talos/tests/tabswitch/api.js
@@ -150,20 +150,19 @@ function loadTPSContentScript(browser) {
 /**
  * For some <xul:tab> in a browser window, have that window switch
  * to that tab. Returns a Promise that resolves ones the tab content
  * has been presented to the user.
  */
 async function switchToTab(tab) {
   let browser = tab.linkedBrowser;
   let gBrowser = tab.ownerGlobal.gBrowser;
-  let window = tab.ownerGlobal;
 
   await loadTPSContentScript(browser);
-  let start = Math.floor(window.performance.timing.navigationStart + window.performance.now());
+  let start = Cu.now();
 
   // We need to wait for the TabSwitchDone event to make sure
   // that the async tab switcher has shut itself down.
   let switchDone = waitForTabSwitchDone(browser);
   // Set up our promise that will wait for the content to be
   // presented.
   let finishPromise = waitForContentPresented(browser);
   // Finally, do the tab switch.
@@ -203,21 +202,21 @@ function waitForTabSwitchDone(browser) {
  *
  * @returns Promise
  *        Resolves once the content has been presented. Resolves to
  *        the system time that the presentation occurred at, in
  *        milliseconds since midnight 01 January, 1970 UTC.
  */
 function waitForContentPresented(browser) {
   return new Promise((resolve) => {
-    let mm = browser.messageManager;
-    mm.addMessageListener("TPS:ContentSawPaint", function onContentPaint(msg) {
-      mm.removeMessageListener("TPS:ContentSawPaint", onContentPaint);
-      resolve(msg.data.time);
-    });
+    browser.addEventListener("MozLayerTreeReady", function onLayersReady(event) {
+      let now = Cu.now();
+      TalosParentProfiler.mark("MozLayerTreeReady seen by tps");
+      resolve(now);
+    }, { once: true });
   });
 }
 
 /**
  * Given some browser, do a garbage collect in the parent, and then
  * a garbage collection in the content process that the browser is
  * running in.
  *