Bug 974171 - Add DEVTOOLS_TOOLBOX_* flags r=jwalker
☠☠ backed out by 9b8649f58614 ☠ ☠
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Tue, 08 Apr 2014 12:53:58 +0100
changeset 196856 e6b103b4369ec3d3267a00dde9f4f1f9c1ccbe05
parent 196855 5033a4da6a1e4e4289dc8241c16704c30bd35eb9
child 196857 c3cec8a150a02b7b2ed2cc1fbe0cc4b7507723b5
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalker
bugs974171
milestone31.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 974171 - Add DEVTOOLS_TOOLBOX_* flags r=jwalker
browser/devtools/framework/toolbox.js
browser/devtools/shared/telemetry.js
browser/devtools/shared/test/browser.ini
browser/devtools/shared/test/browser_telemetry_toolbox.js
toolkit/components/telemetry/Histograms.json
--- a/browser/devtools/framework/toolbox.js
+++ b/browser/devtools/framework/toolbox.js
@@ -1215,16 +1215,17 @@ Toolbox.prototype = {
       }
     });
     // Remove the host UI
     outstanding.push(this.destroyHost());
 
     if (this.target.isLocalTab) {
       this._requisition.destroy();
     }
+    this._telemetry.toolClosed("toolbox");
     this._telemetry.destroy();
 
     return this._destroyer = promise.all(outstanding).then(() => {
       // Targets need to be notified that the toolbox is being torn down.
       // This is done after other destruction tasks since it may tear down
       // fronts and the debugger transport which earlier destroy methods may
       // require to complete.
       if (!this._target) {
--- a/browser/devtools/shared/telemetry.js
+++ b/browser/devtools/shared/telemetry.js
@@ -56,16 +56,18 @@ module.exports = Telemetry;
 
 let {Cc, Ci, Cu} = require("chrome");
 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
 
 Telemetry.prototype = {
   _histograms: {
     toolbox: {
+      histogram: "DEVTOOLS_TOOLBOX_OPENED_BOOLEAN",
+      userHistogram: "DEVTOOLS_TOOLBOX_OPENED_PER_USER_FLAG",
       timerHistogram: "DEVTOOLS_TOOLBOX_TIME_ACTIVE_SECONDS"
     },
     options: {
       histogram: "DEVTOOLS_OPTIONS_OPENED_BOOLEAN",
       userHistogram: "DEVTOOLS_OPTIONS_OPENED_PER_USER_FLAG",
       timerHistogram: "DEVTOOLS_OPTIONS_TIME_ACTIVE_SECONDS"
     },
     webconsole: {
@@ -207,18 +209,16 @@ Telemetry.prototype = {
    *
    * @param  {String} histogramId
    *         Histogram in which the data is to be stored.
    * @param  value
    *         Value to store.
    */
   log: function(histogramId, value) {
     if (histogramId) {
-      let histogram;
-
       try {
         let histogram = Services.telemetry.getHistogramById(histogramId);
         histogram.add(value);
       } catch(e) {
         dump("Warning: An attempt was made to write to the " + histogramId +
              " histogram, which is not defined in Histograms.json\n");
       }
     }
--- a/browser/devtools/shared/test/browser.ini
+++ b/browser/devtools/shared/test/browser.ini
@@ -16,16 +16,17 @@ support-files =
 [browser_observableobject.js]
 [browser_outputparser.js]
 [browser_require_basic.js]
 [browser_telemetry_button_paintflashing.js]
 [browser_telemetry_button_responsive.js]
 [browser_telemetry_button_scratchpad.js]
 [browser_telemetry_button_tilt.js]
 [browser_telemetry_sidebar.js]
+[browser_telemetry_toolbox.js]
 [browser_telemetry_toolboxtabs_inspector.js]
 [browser_telemetry_toolboxtabs_jsdebugger.js]
 [browser_telemetry_toolboxtabs_jsprofiler.js]
 [browser_telemetry_toolboxtabs_netmonitor.js]
 [browser_telemetry_toolboxtabs_options.js]
 [browser_telemetry_toolboxtabs_styleeditor.js]
 [browser_telemetry_toolboxtabs_webconsole.js]
 [browser_templater_basic.js]
new file mode 100644
--- /dev/null
+++ b/browser/devtools/shared/test/browser_telemetry_toolbox.js
@@ -0,0 +1,103 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+const TEST_URI = "data:text/html;charset=utf-8,<p>browser_telemetry_toolbox.js</p>";
+
+// Because we need to gather stats for the period of time that a tool has been
+// opened we make use of setTimeout() to create tool active times.
+const TOOL_DELAY = 200;
+
+let {Promise: promise} = Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {});
+let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
+
+let require = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools.require;
+let Telemetry = require("devtools/shared/telemetry");
+
+function init() {
+  Telemetry.prototype.telemetryInfo = {};
+  Telemetry.prototype._oldlog = Telemetry.prototype.log;
+  Telemetry.prototype.log = function(histogramId, value) {
+    if (histogramId) {
+      if (!this.telemetryInfo[histogramId]) {
+        this.telemetryInfo[histogramId] = [];
+      }
+
+      this.telemetryInfo[histogramId].push(value);
+    }
+  };
+
+  openToolboxThreeTimes();
+}
+
+let pass = 0;
+function openToolboxThreeTimes() {
+  let target = TargetFactory.forTab(gBrowser.selectedTab);
+
+  gDevTools.showToolbox(target, "inspector").then(function(toolbox) {
+    info("Toolbox opened");
+
+    toolbox.once("destroyed", function() {
+      if (pass++ === 3) {
+        checkResults();
+      } else {
+        openToolboxThreeTimes();
+      }
+    });
+    // We use a timeout to check the toolbox's active time
+    setTimeout(function() {
+      gDevTools.closeToolbox(target);
+    }, TOOL_DELAY);
+  }).then(null, console.error);
+}
+
+function checkResults() {
+  let result = Telemetry.prototype.telemetryInfo;
+
+  for (let [histId, value] of Iterator(result)) {
+    if (histId.endsWith("OPENED_PER_USER_FLAG")) {
+      ok(value.length === 1 && value[0] === true,
+         "Per user value " + histId + " has a single value of true");
+    } else if (histId.endsWith("OPENED_BOOLEAN")) {
+      ok(value.length > 1, histId + " has more than one entry");
+
+      let okay = value.every(function(element) {
+        return element === true;
+      });
+
+      ok(okay, "All " + histId + " entries are === true");
+    } else if (histId.endsWith("TIME_ACTIVE_SECONDS")) {
+      ok(value.length > 1, histId + " has more than one entry");
+
+      let okay = value.every(function(element) {
+        return element > 0;
+      });
+
+      ok(okay, "All " + histId + " entries have time > 0");
+    }
+  }
+
+  finishUp();
+}
+
+function finishUp() {
+  gBrowser.removeCurrentTab();
+
+  Telemetry.prototype.log = Telemetry.prototype._oldlog;
+  delete Telemetry.prototype._oldlog;
+  delete Telemetry.prototype.telemetryInfo;
+
+  TargetFactory = Services = promise = require = null;
+
+  finish();
+}
+
+function test() {
+  waitForExplicitFinish();
+  gBrowser.selectedTab = gBrowser.addTab();
+  gBrowser.selectedBrowser.addEventListener("load", function() {
+    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
+    waitForFocus(init, content);
+  }, true);
+
+  content.location = TEST_URI;
+}
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -5227,16 +5227,21 @@
   },
   "DEVTOOLS_DEBUGGER_RDP_REMOTE_ASSIGN_MS": {
     "expires_in_version": "never",
     "kind": "exponential",
     "high": "10000",
     "n_buckets": "1000",
     "description": "The time (in milliseconds) that it took an 'assign' request to go round trip."
   },
+  "DEVTOOLS_TOOLBOX_OPENED_BOOLEAN": {
+    "expires_in_version": "never",
+    "kind": "boolean",
+    "description": "How many times has the devtool's toolbox been opened?"
+  },
   "DEVTOOLS_OPTIONS_OPENED_BOOLEAN": {
     "expires_in_version": "never",
     "kind": "boolean",
     "description": "How many times has the devtool's Options panel been opened?"
   },
   "DEVTOOLS_WEBCONSOLE_OPENED_BOOLEAN": {
     "expires_in_version": "never",
     "kind": "boolean",
@@ -5327,16 +5332,21 @@
     "kind": "boolean",
     "description": "How many times has the devtool's Developer Toolbar been opened via the toolbox button?"
   },
   "DEVTOOLS_CUSTOM_OPENED_BOOLEAN": {
     "expires_in_version": "never",
     "kind": "boolean",
     "description": "How many times has a custom developer tool been opened via the toolbox button?"
   },
+  "DEVTOOLS_TOOLBOX_OPENED_PER_USER_FLAG": {
+    "expires_in_version": "never",
+    "kind": "flag",
+    "description": "How many times has the devtool's toolbox been opened?"
+  },
   "DEVTOOLS_OPTIONS_OPENED_PER_USER_FLAG": {
     "expires_in_version": "never",
     "kind": "flag",
     "description": "How many times has the devtool's Options panel been opened?"
   },
   "DEVTOOLS_WEBCONSOLE_OPENED_PER_USER_FLAG": {
     "expires_in_version": "never",
     "kind": "flag",