Bug 1205845 - Implement telemetry measure to track toolbox docking setting; r=jryans p=bsmedberg

MozReview-Commit-ID: 7Zl1ggZDbde
This commit is contained in:
Sunny 2016-08-28 22:35:18 +05:30 коммит произвёл J. Ryan Stinnett
Родитель 0c0f1a9ecf
Коммит f4e6ea33b9
6 изменённых файлов: 122 добавлений и 38 удалений

Просмотреть файл

@ -47,6 +47,7 @@ support-files =
[browser_toolbox_highlight.js]
[browser_toolbox_hosts.js]
[browser_toolbox_hosts_size.js]
[browser_toolbox_hosts_telemetry.js]
[browser_toolbox_keyboard_navigation.js]
skip-if = os == "mac" # Full keyboard navigation on OSX only works if Full Keyboard Access setting is set to All Control in System Keyboard Preferences
[browser_toolbox_minimize.js]

Просмотреть файл

@ -0,0 +1,50 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const {Toolbox} = require("devtools/client/framework/toolbox");
const {SIDE, BOTTOM, WINDOW} = Toolbox.HostType;
const URL = "data:text/html;charset=utf8,browser_toolbox_hosts_telemetry.js";
function getHostHistogram() {
return Services.telemetry.getHistogramById("DEVTOOLS_TOOLBOX_HOST");
}
add_task(function* () {
// Reset it to make counting easier
getHostHistogram().clear();
info("Create a test tab and open the toolbox");
let tab = yield addTab(URL);
let target = TargetFactory.forTab(tab);
let toolbox = yield gDevTools.showToolbox(target, "webconsole");
yield changeToolboxHost(toolbox);
yield checkResults();
yield toolbox.destroy();
toolbox = target = null;
gBrowser.removeCurrentTab();
// Cleanup
getHostHistogram().clear();
});
function* changeToolboxHost(toolbox) {
info("Switch toolbox host");
yield toolbox.switchHost(SIDE);
yield toolbox.switchHost(WINDOW);
yield toolbox.switchHost(BOTTOM);
yield toolbox.switchHost(SIDE);
yield toolbox.switchHost(WINDOW);
yield toolbox.switchHost(BOTTOM);
}
function checkResults() {
let counts = getHostHistogram().snapshot().counts;
is(counts[0], 3, "Toolbox HostType bottom has 3 successful entries");
is(counts[1], 2, "Toolbox HostType side has 2 successful entries");
is(counts[2], 2, "Toolbox HostType window has 2 successful entries");
}

Просмотреть файл

@ -504,3 +504,50 @@ var closeToolbox = Task.async(function* () {
let target = TargetFactory.forTab(gBrowser.selectedTab);
yield gDevTools.closeToolbox(target);
});
/**
* Load the Telemetry utils, then stub Telemetry.prototype.log and
* Telemetry.prototype.logKeyed in order to record everything that's logged in
* it.
* Store all recordings in Telemetry.telemetryInfo.
* @return {Telemetry}
*/
function loadTelemetryAndRecordLogs() {
info("Mock the Telemetry log function to record logged information");
let Telemetry = require("devtools/client/shared/telemetry");
Telemetry.prototype.telemetryInfo = {};
Telemetry.prototype._oldlog = Telemetry.prototype.log;
Telemetry.prototype.log = function (histogramId, value) {
if (!this.telemetryInfo) {
// Telemetry instance still in use after stopRecordingTelemetryLogs
return;
}
if (histogramId) {
if (!this.telemetryInfo[histogramId]) {
this.telemetryInfo[histogramId] = [];
}
this.telemetryInfo[histogramId].push(value);
}
};
Telemetry.prototype._oldlogKeyed = Telemetry.prototype.logKeyed;
Telemetry.prototype.logKeyed = function (histogramId, key, value) {
this.log(`${histogramId}|${key}`, value);
};
return Telemetry;
}
/**
* Stop recording the Telemetry logs and put back the utils as it was before.
* @param {Telemetry} Required Telemetry
* Telemetry object that needs to be stopped.
*/
function stopRecordingTelemetryLogs(Telemetry) {
info("Stopping Telemetry");
Telemetry.prototype.log = Telemetry.prototype._oldlog;
Telemetry.prototype.logKeyed = Telemetry.prototype._oldlogKeyed;
delete Telemetry.prototype._oldlog;
delete Telemetry.prototype._oldlogKeyed;
delete Telemetry.prototype.telemetryInfo;
}

Просмотреть файл

@ -9,6 +9,7 @@ const SPLITCONSOLE_ENABLED_PREF = "devtools.toolbox.splitconsoleEnabled";
const SPLITCONSOLE_HEIGHT_PREF = "devtools.toolbox.splitconsoleHeight";
const OS_HISTOGRAM = "DEVTOOLS_OS_ENUMERATED_PER_USER";
const OS_IS_64_BITS = "DEVTOOLS_OS_IS_64_BITS_PER_USER";
const HOST_HISTOGRAM = "DEVTOOLS_TOOLBOX_HOST";
const SCREENSIZE_HISTOGRAM = "DEVTOOLS_SCREEN_RESOLUTION_ENUMERATED_PER_USER";
const HTML_NS = "http://www.w3.org/1999/xhtml";
const { SourceMapService } = require("./source-map-service");
@ -488,6 +489,17 @@ Toolbox.prototype = {
return this.browserRequire("devtools/client/shared/vendor/react-dom");
},
// Return HostType id for telemetry
_getTelemetryHostId: function () {
switch (this.hostType) {
case Toolbox.HostType.BOTTOM: return 0;
case Toolbox.HostType.SIDE: return 1;
case Toolbox.HostType.WINDOW: return 2;
case Toolbox.HostType.CUSTOM: return 3;
default: return 9;
}
},
_pingTelemetry: function () {
this._telemetry.toolOpened("toolbox");
@ -495,6 +507,7 @@ Toolbox.prototype = {
this._telemetry.logOncePerBrowserVersion(OS_IS_64_BITS,
Services.appinfo.is64Bit ? 1 : 0);
this._telemetry.logOncePerBrowserVersion(SCREENSIZE_HISTOGRAM, system.getScreenDimensions());
this._telemetry.log(HOST_HISTOGRAM, this._getTelemetryHostId());
},
/**
@ -1836,6 +1849,8 @@ Toolbox.prototype = {
this.focusTool(this.currentToolId, true);
this.emit("host-changed");
this._telemetry.log(HOST_HISTOGRAM, this._getTelemetryHostId());
});
},

Просмотреть файл

@ -118,44 +118,6 @@ Task.async(function* (type = "bottom", src = "data:text/html;charset=utf-8,") {
return [host, iframe.contentWindow, iframe.contentDocument];
});
/**
* Load the Telemetry utils, then stub Telemetry.prototype.log in order to
* record everything that's logged in it.
* Store all recordings on Telemetry.telemetryInfo.
* @return {Telemetry}
*/
function loadTelemetryAndRecordLogs() {
info("Mock the Telemetry log function to record logged information");
let Telemetry = require("devtools/client/shared/telemetry");
Telemetry.prototype.telemetryInfo = {};
Telemetry.prototype._oldlog = Telemetry.prototype.log;
Telemetry.prototype.log = function (histogramId, value) {
if (!this.telemetryInfo) {
// Can be removed when Bug 992911 lands (see Bug 1011652 Comment 10)
return;
}
if (histogramId) {
if (!this.telemetryInfo[histogramId]) {
this.telemetryInfo[histogramId] = [];
}
this.telemetryInfo[histogramId].push(value);
}
};
return Telemetry;
}
/**
* Stop recording the Telemetry logs and put back the utils as it was before.
*/
function stopRecordingTelemetryLogs(Telemetry) {
Telemetry.prototype.log = Telemetry.prototype._oldlog;
delete Telemetry.prototype._oldlog;
delete Telemetry.prototype.telemetryInfo;
}
/**
* Check the correctness of the data recorded in Telemetry after
* loadTelemetryAndRecordLogs was called.

Просмотреть файл

@ -7387,6 +7387,15 @@
"keyed": true,
"description": "Measures whether a particular JavaScript error has been displayed in the webconsole."
},
"DEVTOOLS_TOOLBOX_HOST": {
"alert_emails": ["dev-developer-tools@lists.mozilla.org"],
"expires_in_version": "58",
"kind": "enumerated",
"bug_numbers": [1205845],
"n_values": 9,
"releaseChannelCollection": "opt-out",
"description": "Records DevTools toolbox host each time the toolbox is opened and when the host is changed (0:Bottom, 1:Side, 2:Window, 3:Custom, 9:Unknown)."
},
"VIEW_SOURCE_IN_BROWSER_OPENED_BOOLEAN": {
"alert_emails": ["mozilla-dev-developer-tools@lists.mozilla.org", "jryans@mozilla.com"],
"expires_in_version": "53",