Bug 1381988 - Switch talos tpaint test to measure time until timeToNonBlankPaint, rather than until MozAfterPaint. draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Mon, 31 Jul 2017 15:05:42 -0700
changeset 642066 870bc4e3d1c80a22d436e6b9551900abb08027a8
parent 621327 bc829569880635c52d6e3d54f51cd7d3df180186
child 724896 da0c0c5c193b4e5b3e23fa76ad9001eaa5cbd919
push id72638
push userbmo:gandalf@aviary.pl
push dateMon, 07 Aug 2017 16:49:46 +0000
bugs1381988
milestone57.0a1
Bug 1381988 - Switch talos tpaint test to measure time until timeToNonBlankPaint, rather than until MozAfterPaint. MozReview-Commit-ID: AZsfKMjf8mk
testing/talos/talos/test.py
testing/talos/talos/tests/tpaint/tpaint.html
--- a/testing/talos/talos/test.py
+++ b/testing/talos/talos/test.py
@@ -267,19 +267,22 @@ class tpaint(PageloaderTest):
     display a window in the running instance of the browser.
     (Measures ctrl-n performance.)
     """
     tpmanifest = '${talos}/tests/tpaint/tpaint.manifest'
     tppagecycles = 20
     timeout = 300
     gecko_profile_interval = 1
     gecko_profile_entries = 2000000
-    tpmozafterpaint = True
+    tpmozafterpaint = False
     filters = filter.ignore_first.prepare(5) + filter.median.prepare()
     unit = 'ms'
+    preferences = {
+        'dom.performance.time_to_non_blank_paint.enabled': True
+    }
 
 
 @register_test()
 class tabpaint(PageloaderTest):
     """
     Tests the amount of time it takes to open new tabs, triggered from
     both the parent process and the content process.
     """
--- a/testing/talos/talos/tests/tpaint/tpaint.html
+++ b/testing/talos/talos/tests/tpaint/tpaint.html
@@ -44,33 +44,53 @@ async function reportTimes() {
   if (window.tpRecordTime)
     window.tpRecordTime(openTime);
 
   if (auto) {
     dumpLog("openingTime=" + openTime + "\n");
   }
 }
 
-async function childIsOpen() {
-  kidEndTime = window.performance.now();
+async function childIsOpen(delay) {
+  kidEndTime = window.performance.now() - delay;
   openTime = kidEndTime - kidStartTime;
   await TalosContentProfiler.pause("tpaint", true);
 
   window.setTimeout(reportTimes, 0);
 }
 
+/**
+ * We're going to calculate the difference between when the done() function
+ * is called, and when timeToNonBlankPaint happened.
+ *
+ * This difference, called `delay` will be transferred back to the childIsOpen
+ * and subtracted from the measurement.
+ *
+ * The end result is that openTime should hold the high precision difference
+ * between when window.open has been called, and when the timeToNonBlankPaint
+ * has been measured in the child window.
+ */
+
 /* eslint-disable no-useless-concat */
 var kidHTML = "<html><meta charset='utf-8'><script>" +
-              "var e = 'MozAfterPaint';" +
-              "function done() {" +
-              "  window.removeEventListener(e, done, true);" +
-              "  window.opener.childIsOpen();" +
-              "  window.close();" +
+              "function readFNBPaint() {" +
+              "  const fnbp = performance.timing.timeToNonBlankPaint;" +
+              "  if (fnbp === undefined) {" +
+              "    window.removeEventListener('MozAfterPaint', readFNBPaint, true);" +
+              "    throw new Error('FNBPaint not available');" +
+              "  }" +
+              "  if (fnbp !== 0) {" +
+              "    window.removeEventListener('MozAfterPaint', readFNBPaint, true);" +
+              "    const epochNow = performance.timing.navigationStart + performance.now();" +
+              "    const delay = epochNow - fnbp;" +
+              "    window.opener.childIsOpen(delay);" +
+              "    window.close();" +
+              "  }" +
               "}" +
-              "window.addEventListener(e, done, true);" +
+              "window.addEventListener('MozAfterPaint', readFNBPaint, true);" +
               "</" + "script>TPAINT</html>";
 /* eslint-enable no-useless-concat */
 var kidURI = "data:text/html," + encodeURI(kidHTML);
 
 async function openWindow() {
   await TalosContentProfiler.resume("tpaint");
   kidStartTime = window.performance.now();
   kid = window.open(kidURI);