Bug 1503074 - Only touch the FX_TAB_SWITCH_COMPOSITE_E10S_MS stopwatch when we have actually started it in the past
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 26 Nov 2018 19:16:09 +0000
changeset 504616 63cbd79e897de14cb164992d37b15700fec420f0
parent 504615 e3a074ae3f0c18a5329c23099c5169f135885852
child 504617 d5a15c64bd401768c581663b1b13f45e66080616
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1503074
milestone65.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 1503074 - Only touch the FX_TAB_SWITCH_COMPOSITE_E10S_MS stopwatch when we have actually started it in the past Differential Revision: https://phabricator.services.mozilla.com/D12966
browser/modules/AsyncTabSwitcher.jsm
--- a/browser/modules/AsyncTabSwitcher.jsm
+++ b/browser/modules/AsyncTabSwitcher.jsm
@@ -131,16 +131,18 @@ class AsyncTabSwitcher {
     // For telemetry, keeps track of what most recently cleared
     // the loadTimer, which can tell us something about the cause
     // of tab switch spinners.
     this._loadTimerClearedBy = "none";
 
     this._useDumpForLogging = false;
     this._logInit = false;
 
+    this._tabSwitchStopWatchRunning = false;
+
     this.window.addEventListener("MozAfterPaint", this);
     this.window.addEventListener("MozLayerTreeReady", this);
     this.window.addEventListener("MozLayerTreeCleared", this);
     this.window.addEventListener("TabRemotenessChange", this);
     this.window.addEventListener("sizemodechange", this);
     this.window.addEventListener("occlusionstatechange", this);
     this.window.addEventListener("SwapDocShells", this, true);
     this.window.addEventListener("EndSwapDocShells", this, true);
@@ -430,16 +432,17 @@ class AsyncTabSwitcher {
             // completion.
             this.switchPaintId = this.window.windowUtils.lastTransactionId + 1;
           } else {
             // We're making the tab visible even though we haven't yet got layers for it.
             // It's hard to know which composite the layers will first be available in (and
             // the parent process might not even get MozAfterPaint delivered for it), so just
             // give up measuring this for now. :(
             TelemetryStopwatch.cancel("FX_TAB_SWITCH_COMPOSITE_E10S_MS", this.window);
+            this._tabSwitchStopWatchRunning = false;
           }
 
           this.tabbrowser._adjustFocusAfterTabSwitch(showTab);
           this.maybeActivateDocShell(this.requestedTab);
         }
       }
 
       // This doesn't necessarily exist if we're a new window and haven't switched tabs yet
@@ -735,20 +738,22 @@ class AsyncTabSwitcher {
   }
 
   // Fires when we paint the screen. Any tab switches we initiated
   // previously are done, so there's no need to keep the old layers
   // around.
   onPaint(event) {
     if (this.switchPaintId != -1 &&
         event.transactionId >= this.switchPaintId) {
-      let time = TelemetryStopwatch.timeElapsed("FX_TAB_SWITCH_COMPOSITE_E10S_MS", this.window);
-      if (time != -1) {
-        TelemetryStopwatch.finish("FX_TAB_SWITCH_COMPOSITE_E10S_MS", this.window);
-        this.log("DEBUG: tab switch time including compositing = " + time);
+      if (this._tabSwitchStopWatchRunning) {
+        let time = TelemetryStopwatch.timeElapsed("FX_TAB_SWITCH_COMPOSITE_E10S_MS", this.window);
+        if (time != -1) {
+          TelemetryStopwatch.finish("FX_TAB_SWITCH_COMPOSITE_E10S_MS", this.window);
+          this.log("DEBUG: tab switch time including compositing = " + time);
+        }
       }
       this.addMarker("AsyncTabSwitch:Composited");
       this.switchPaintId = -1;
     }
 
     this.maybeVisibleTabs.clear();
   }
 
@@ -1070,18 +1075,21 @@ class AsyncTabSwitcher {
    * Telemetry and Profiler related helpers for recording tab switch
    * timing.
    */
 
   startTabSwitch() {
     TelemetryStopwatch.cancel("FX_TAB_SWITCH_TOTAL_E10S_MS", this.window);
     TelemetryStopwatch.start("FX_TAB_SWITCH_TOTAL_E10S_MS", this.window);
 
-    TelemetryStopwatch.cancel("FX_TAB_SWITCH_COMPOSITE_E10S_MS", this.window);
+    if (this._tabSwitchStopWatchRunning) {
+      TelemetryStopwatch.cancel("FX_TAB_SWITCH_COMPOSITE_E10S_MS", this.window);
+    }
     TelemetryStopwatch.start("FX_TAB_SWITCH_COMPOSITE_E10S_MS", this.window);
+    this._tabSwitchStopWatchRunning = true;
     this.addMarker("AsyncTabSwitch:Start");
     this.switchInProgress = true;
   }
 
   /**
    * Something has occurred that might mean that we've completed
    * the tab switch (layers are ready, paints are done, spinners
    * are hidden). This checks to make sure all conditions are