Bug 1456194 - Fix toolbox startup telemetry measurement when using more than one top level window. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 25 Apr 2018 03:01:13 -0700
changeset 790533 2e0a87d3bc0c91446c832c1fc43a4067991a6c10
parent 790523 2d7e932e057a67d00ab5705dfa8354ad75526445
push id108535
push userbmo:poirot.alex@gmail.com
push dateWed, 02 May 2018 13:24:32 +0000
reviewersjryans
bugs1456194
milestone61.0a1
Bug 1456194 - Fix toolbox startup telemetry measurement when using more than one top level window. r=jryans MozReview-Commit-ID: Ic1qw8amjki
devtools/client/framework/browser-menus.js
devtools/client/framework/devtools-browser.js
devtools/client/framework/devtools.js
devtools/client/menus.js
devtools/startup/DevToolsShim.jsm
devtools/startup/devtools-startup.js
--- a/devtools/client/framework/browser-menus.js
+++ b/devtools/client/framework/browser-menus.js
@@ -7,16 +7,17 @@
 /**
  * This module inject dynamically menu items into browser UI.
  *
  * Menu definitions are fetched from:
  * - devtools/client/menus for top level entires
  * - devtools/client/definitions for tool-specifics entries
  */
 
+const {Cu} = require("chrome");
 const {LocalizationHelper} = require("devtools/shared/l10n");
 const MENUS_L10N = new LocalizationHelper("devtools/client/locales/menus.properties");
 
 loader.lazyRequireGetter(this, "gDevTools", "devtools/client/framework/devtools", true);
 loader.lazyRequireGetter(this, "gDevToolsBrowser", "devtools/client/framework/devtools-browser", true);
 
 // Keep list of inserted DOM Elements in order to remove them on unload
 // Maps browser xul document => list of DOM Elements
@@ -71,17 +72,17 @@ function createToolMenuElements(toolDefi
 
   // Prevent multiple entries for the same tool.
   if (doc.getElementById(menuId)) {
     return;
   }
 
   let oncommand = function(id, event) {
     let window = event.target.ownerDocument.defaultView;
-    gDevToolsBrowser.selectToolCommand(window.gBrowser, id, window.performance.now());
+    gDevToolsBrowser.selectToolCommand(window.gBrowser, id, Cu.now());
   }.bind(null, id);
 
   let menuitem = createMenuItem({
     doc,
     id: "menuitem_" + id,
     label: toolDefinition.menuLabel || toolDefinition.label,
     accesskey: toolDefinition.accesskey
   });
--- a/devtools/client/framework/devtools-browser.js
+++ b/devtools/client/framework/devtools-browser.js
@@ -245,17 +245,17 @@ var gDevToolsBrowser = exports.gDevTools
    *         Key object describing the key shortcut being pressed. It comes
    *         from devtools-startup.js's KeyShortcuts array. The useful fields here
    *         are:
    *         - `toolId` used to identify a toolbox's panel like inspector or webconsole,
    *         - `id` used to identify any other key shortcuts like scratchpad or
    *         about:debugging
    * @param {Number} startTime
    *        Optional, indicates the time at which the key event fired. This is a
-   *        `performance.now()` timing.
+   *        `Cu.now()` timing.
    */
   onKeyShortcut(window, key, startTime) {
     // If this is a toolbox's panel key shortcut, delegate to selectToolCommand
     if (key.toolId) {
       gDevToolsBrowser.selectToolCommand(window.gBrowser, key.toolId, startTime);
       return;
     }
     // Otherwise implement all other key shortcuts individually here
--- a/devtools/client/framework/devtools.js
+++ b/devtools/client/framework/devtools.js
@@ -441,17 +441,17 @@ DevTools.prototype = {
    * @param {string} toolId
    *        The id of the tool to show
    * @param {Toolbox.HostType} hostType
    *        The type of host (bottom, window, side)
    * @param {object} hostOptions
    *        Options for host specifically
    * @param {Number} startTime
    *        Optional, indicates the time at which the user event related to this toolbox
-   *        opening started. This is a `performance.now()` timing.
+   *        opening started. This is a `Cu.now()` timing.
    *
    * @return {Toolbox} toolbox
    *        The toolbox that was opened
    */
   async showToolbox(target, toolId, hostType, hostOptions, startTime) {
     let toolbox = this._toolboxes.get(target);
     if (toolbox) {
       if (hostType != null && toolbox.hostType != hostType) {
@@ -495,21 +495,20 @@ DevTools.prototype = {
    * toolbox. This one includes devtools framework loading. And a second one for all
    * subsequent toolbox opening, which should all be faster.
    * These two probes are indexed by Tool ID.
    *
    * @param {String} toolId
    *        The id of the opened tool.
    * @param {Number} startTime
    *        Indicates the time at which the user event related to the toolbox
-   *        opening started. This is a `performance.now()` timing.
+   *        opening started. This is a `Cu.now()` timing.
    */
   logToolboxOpenTime(toolId, startTime) {
-    let { performance } = Services.appShell.hiddenDOMWindow;
-    let delay = performance.now() - startTime;
+    let delay = Cu.now() - startTime;
 
     let telemetryKey = this._firstShowToolbox ?
       "DEVTOOLS_COLD_TOOLBOX_OPEN_DELAY_MS" : "DEVTOOLS_WARM_TOOLBOX_OPEN_DELAY_MS";
     this._telemetry.logKeyed(telemetryKey, toolId, delay);
 
     this._telemetry.addEventProperty(
       "devtools.main", "open", "tools", null, "first_panel",
       this.makeToolIdHumanReadable(toolId));
@@ -667,17 +666,17 @@ DevTools.prototype = {
    *        The browser tab on which inspect node was used.
    * @param {Array} selectors
    *        An array of CSS selectors to find the target node. Several selectors can be
    *        needed if the element is nested in frames and not directly in the root
    *        document. The selectors are ordered starting with the root document and
    *        ending with the deepest nested frame.
    * @param {Number} startTime
    *        Optional, indicates the time at which the user event related to this node
-   *        inspection started. This is a `performance.now()` timing.
+   *        inspection started. This is a `Cu.now()` timing.
    * @return {Promise} a promise that resolves when the node is selected in the inspector
    *         markup view.
    */
   async inspectNode(tab, nodeSelectors, startTime) {
     let target = TargetFactory.forTab(tab);
 
     let toolbox = await gDevTools.showToolbox(target, "inspector", null, null, startTime);
     let inspector = toolbox.getCurrentPanel();
@@ -706,17 +705,17 @@ DevTools.prototype = {
    * @param {XULTab} tab
    *        The browser tab on which inspect accessibility was used.
    * @param {Array} selectors
    *        An array of CSS selectors to find the target accessible object.
    *        Several selectors can be needed if the element is nested in frames
    *        and not directly in the root document.
    * @param {Number} startTime
    *        Optional, indicates the time at which the user event related to this
-   *        node inspection started. This is a `performance.now()` timing.
+   *        node inspection started. This is a `Cu.now()` timing.
    * @return {Promise} a promise that resolves when the accessible object is
    *         selected in the accessibility inspector.
    */
   async inspectA11Y(tab, nodeSelectors, startTime) {
     let target = TargetFactory.forTab(tab);
 
     let toolbox = await gDevTools.showToolbox(
       target, "accessibility", null, null, startTime);
--- a/devtools/client/menus.js
+++ b/devtools/client/menus.js
@@ -23,30 +23,32 @@
  * - disabled:
  *   If true, the menuitem and key shortcut are going to be hidden and disabled
  *   on startup, until some runtime code eventually enable them.
  * - checkbox:
  *   If true, the menuitem is prefixed by a checkbox and runtime code can
  *   toggle it.
  */
 
+const { Cu } = require("chrome");
+
 loader.lazyRequireGetter(this, "gDevToolsBrowser", "devtools/client/framework/devtools-browser", true);
 loader.lazyRequireGetter(this, "CommandUtils", "devtools/client/shared/developer-toolbar", true);
 loader.lazyRequireGetter(this, "TargetFactory", "devtools/client/framework/target", true);
 loader.lazyRequireGetter(this, "ResponsiveUIManager", "devtools/client/responsive.html/manager", true);
 
 loader.lazyImporter(this, "BrowserToolboxProcess", "resource://devtools/client/framework/ToolboxProcess.jsm");
 loader.lazyImporter(this, "ScratchpadManager", "resource://devtools/client/scratchpad/scratchpad-manager.jsm");
 
 exports.menuitems = [
   { id: "menu_devToolbox",
     l10nKey: "devToolboxMenuItem",
     oncommand(event) {
       let window = event.target.ownerDocument.defaultView;
-      gDevToolsBrowser.toggleToolboxCommand(window.gBrowser, window.performance.now());
+      gDevToolsBrowser.toggleToolboxCommand(window.gBrowser, Cu.now());
     },
     keyId: "toggleToolbox",
     checkbox: true
   },
   { id: "menu_devtools_separator",
     separator: true },
   { id: "menu_devToolbar",
     l10nKey: "devToolbarMenu",
--- a/devtools/startup/DevToolsShim.jsm
+++ b/devtools/startup/DevToolsShim.jsm
@@ -195,18 +195,17 @@ this.DevToolsShim = {
         DevtoolsStartup.openInstallPage("ContextMenu");
       }
       return Promise.resolve();
     }
 
     // Record the timing at which this event started in order to compute later in
     // gDevTools.showToolbox, the complete time it takes to open the toolbox.
     // i.e. especially take `DevtoolsStartup.initDevTools` into account.
-    let { performance } = Services.appShell.hiddenDOMWindow;
-    let startTime = performance.now();
+    let startTime = Cu.now();
 
     this.initDevTools("ContextMenu");
 
     return this._gDevTools.inspectA11Y(tab, selectors, startTime);
   },
 
   /**
    * Called from nsContextMenu.js in mozilla-central when using the Inspect Element
@@ -228,18 +227,17 @@ this.DevToolsShim = {
         DevtoolsStartup.openInstallPage("ContextMenu");
       }
       return Promise.resolve();
     }
 
     // Record the timing at which this event started in order to compute later in
     // gDevTools.showToolbox, the complete time it takes to open the toolbox.
     // i.e. especially take `DevtoolsStartup.initDevTools` into account.
-    let { performance } = Services.appShell.hiddenDOMWindow;
-    let startTime = performance.now();
+    let startTime = Cu.now();
 
     this.initDevTools("ContextMenu");
 
     return this._gDevTools.inspectNode(tab, selectors, startTime);
   },
 
   _onDevToolsRegistered: function() {
     // Register all pending event listeners on the real gDevTools object.
--- a/devtools/startup/devtools-startup.js
+++ b/devtools/startup/devtools-startup.js
@@ -590,17 +590,17 @@ DevToolsStartup.prototype = {
   onKey(window, key) {
     if (!Services.prefs.getBoolPref(DEVTOOLS_ENABLED_PREF)) {
       let id = key.toolId || key.id;
       this.openInstallPage("KeyShortcut", id);
     } else {
       // Record the timing at which this event started in order to compute later in
       // gDevTools.showToolbox, the complete time it takes to open the toolbox.
       // i.e. especially take `initDevTools` into account.
-      let startTime = window.performance.now();
+      let startTime = Cu.now();
       let require = this.initDevTools("KeyShortcut");
       let { gDevToolsBrowser } = require("devtools/client/framework/devtools-browser");
       gDevToolsBrowser.onKeyShortcut(window, key, startTime);
     }
   },
 
   // Create a <xul:key> DOM Element
   createKey(doc, { id, toolId, shortcut, modifiers: mod }, oncommand) {