Bug 1261738: Try to avoid overlapping FX_TAB_SWITCH_TOTAL_MS stopwatches. r?mconley
MozReview-Commit-ID: JSSvsbL6q1n
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -1013,36 +1013,50 @@
<method name="updateTitlebar">
<body>
<![CDATA[
this.ownerDocument.title = this.getWindowTitleForBrowser(this.mCurrentBrowser);
]]>
</body>
</method>
+ <field name="_tabSwitchID">null</field>
+
<method name="updateCurrentBrowser">
<parameter name="aForceUpdate"/>
<body>
<![CDATA[
var newBrowser = this.getBrowserAtIndex(this.tabContainer.selectedIndex);
if (this.mCurrentBrowser == newBrowser && !aForceUpdate)
return;
if (!aForceUpdate) {
TelemetryStopwatch.start("FX_TAB_SWITCH_UPDATE_MS");
if (!gMultiProcessBrowser) {
// old way of measuring tab paint which is not valid with e10s.
// Waiting until the next MozAfterPaint ensures that we capture
// the time it takes to paint, upload the textures to the compositor,
// and then composite.
+ if (this._tabSwitchID) {
+ TelemetryStopwatch.cancel("FX_TAB_SWITCH_TOTAL_MS");
+ }
+
+ let tabSwitchID = Symbol();
+
TelemetryStopwatch.start("FX_TAB_SWITCH_TOTAL_MS");
- window.addEventListener("MozAfterPaint", function onMozAfterPaint() {
- TelemetryStopwatch.finish("FX_TAB_SWITCH_TOTAL_MS");
+ this._tabSwitchID = tabSwitchID;
+
+ let onMozAfterPaint = () => {
+ if (this._tabSwitchID === tabSwitchID) {
+ TelemetryStopwatch.finish("FX_TAB_SWITCH_TOTAL_MS");
+ this._tabSwitchID = null;
+ }
window.removeEventListener("MozAfterPaint", onMozAfterPaint);
- });
+ }
+ window.addEventListener("MozAfterPaint", onMozAfterPaint);
}
}
var oldTab = this.mCurrentTab;
// Preview mode should not reset the owner
if (!this._previewMode && !oldTab.selected)
oldTab.owner = null;