diff --git a/browser/devtools/framework/toolbox.js b/browser/devtools/framework/toolbox.js index d07238f7129d..dbfe7239a54e 100644 --- a/browser/devtools/framework/toolbox.js +++ b/browser/devtools/framework/toolbox.js @@ -1223,6 +1223,7 @@ Toolbox.prototype = { if (this.target.isLocalTab) { this._requisition.destroy(); } + this._telemetry.toolClosed("toolbox"); this._telemetry.destroy(); return this._destroyer = promise.all(outstanding).then(() => { diff --git a/browser/devtools/shared/telemetry.js b/browser/devtools/shared/telemetry.js index a2a3a0ffb345..b5832b3a368f 100644 --- a/browser/devtools/shared/telemetry.js +++ b/browser/devtools/shared/telemetry.js @@ -61,6 +61,8 @@ 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: { @@ -212,8 +214,6 @@ Telemetry.prototype = { */ log: function(histogramId, value) { if (histogramId) { - let histogram; - try { let histogram = Services.telemetry.getHistogramById(histogramId); histogram.add(value); diff --git a/browser/devtools/shared/test/browser.ini b/browser/devtools/shared/test/browser.ini index 158e1b5a112f..00e1362f7d4e 100644 --- a/browser/devtools/shared/test/browser.ini +++ b/browser/devtools/shared/test/browser.ini @@ -20,6 +20,7 @@ support-files = [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] diff --git a/browser/devtools/shared/test/browser_telemetry_sidebar.js b/browser/devtools/shared/test/browser_telemetry_sidebar.js index 381a8f5fc7e5..a3edf6b797e1 100644 --- a/browser/devtools/shared/test/browser_telemetry_sidebar.js +++ b/browser/devtools/shared/test/browser_telemetry_sidebar.js @@ -73,6 +73,8 @@ function checkResults() { 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 === "DEVTOOLS_TOOLBOX_OPENED_BOOLEAN") { + is(value.length, 1, histId + " has only one entry"); } else if (histId.endsWith("OPENED_BOOLEAN")) { ok(value.length > 1, histId + " has more than one entry"); diff --git a/browser/devtools/shared/test/browser_telemetry_toolbox.js b/browser/devtools/shared/test/browser_telemetry_toolbox.js new file mode 100644 index 000000000000..45c7ce45630d --- /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,

browser_telemetry_toolbox.js

"; + +// 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; +} diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index c39115f020ea..061990e78a99 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -5392,6 +5392,11 @@ "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", @@ -5492,6 +5497,11 @@ "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",