2013-05-24 14:26:17 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Telemetry.
|
|
|
|
*
|
|
|
|
* To add metrics for a tool:
|
|
|
|
*
|
2016-02-17 18:57:57 +03:00
|
|
|
* 1. Create count, flag, and exponential entries in
|
2013-05-24 14:26:17 +04:00
|
|
|
* toolkit/components/telemetry/Histograms.json. Each type is optional but it
|
|
|
|
* is best if all three can be included.
|
|
|
|
*
|
2015-09-21 20:07:31 +03:00
|
|
|
* 2. Add your chart entries to devtools/client/shared/telemetry.js
|
2013-05-24 14:26:17 +04:00
|
|
|
* (Telemetry.prototype._histograms):
|
|
|
|
* mytoolname: {
|
2016-02-17 18:57:57 +03:00
|
|
|
* histogram: "DEVTOOLS_MYTOOLNAME_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
* userHistogram: "DEVTOOLS_MYTOOLNAME_OPENED_PER_USER_FLAG",
|
|
|
|
* timerHistogram: "DEVTOOLS_MYTOOLNAME_TIME_ACTIVE_SECONDS"
|
|
|
|
* },
|
|
|
|
*
|
|
|
|
* 3. Include this module at the top of your tool. Use:
|
2015-09-21 20:04:18 +03:00
|
|
|
* let Telemetry = require("devtools/client/shared/telemetry")
|
2013-05-24 14:26:17 +04:00
|
|
|
*
|
|
|
|
* 4. Create a telemetry instance in your tool's constructor:
|
|
|
|
* this._telemetry = new Telemetry();
|
|
|
|
*
|
|
|
|
* 5. When your tool is opened call:
|
|
|
|
* this._telemetry.toolOpened("mytoolname");
|
|
|
|
*
|
|
|
|
* 6. When your tool is closed call:
|
|
|
|
* this._telemetry.toolClosed("mytoolname");
|
|
|
|
*
|
|
|
|
* Note:
|
|
|
|
* You can view telemetry stats for your local Firefox instance via
|
|
|
|
* about:telemetry.
|
|
|
|
*
|
|
|
|
* You can view telemetry stats for large groups of Firefox users at
|
2014-10-01 18:04:00 +04:00
|
|
|
* telemetry.mozilla.org.
|
2013-05-24 14:26:17 +04:00
|
|
|
*/
|
|
|
|
|
2016-05-19 17:35:45 +03:00
|
|
|
"use strict";
|
|
|
|
|
2013-05-24 14:26:17 +04:00
|
|
|
const TOOLS_OPENED_PREF = "devtools.telemetry.tools.opened.version";
|
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
this.Telemetry = function () {
|
2013-05-24 14:26:17 +04:00
|
|
|
// Bind pretty much all functions so that callers do not need to.
|
|
|
|
this.toolOpened = this.toolOpened.bind(this);
|
|
|
|
this.toolClosed = this.toolClosed.bind(this);
|
|
|
|
this.log = this.log.bind(this);
|
|
|
|
this.logOncePerBrowserVersion = this.logOncePerBrowserVersion.bind(this);
|
|
|
|
this.destroy = this.destroy.bind(this);
|
|
|
|
|
|
|
|
this._timers = new Map();
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Telemetry;
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var {Cc, Ci, Cu} = require("chrome");
|
2016-02-27 15:51:10 +03:00
|
|
|
var Services = require("Services");
|
2015-09-15 21:19:45 +03:00
|
|
|
var {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
|
2013-05-24 14:26:17 +04:00
|
|
|
|
|
|
|
Telemetry.prototype = {
|
|
|
|
_histograms: {
|
|
|
|
toolbox: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_TOOLBOX_OPENED_COUNT",
|
2014-04-15 14:01:27 +04:00
|
|
|
userHistogram: "DEVTOOLS_TOOLBOX_OPENED_PER_USER_FLAG",
|
2013-05-24 14:26:17 +04:00
|
|
|
timerHistogram: "DEVTOOLS_TOOLBOX_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
|
|
|
options: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_OPTIONS_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
userHistogram: "DEVTOOLS_OPTIONS_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_OPTIONS_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
|
|
|
webconsole: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_WEBCONSOLE_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
userHistogram: "DEVTOOLS_WEBCONSOLE_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_WEBCONSOLE_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
|
|
|
browserconsole: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_BROWSERCONSOLE_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
userHistogram: "DEVTOOLS_BROWSERCONSOLE_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_BROWSERCONSOLE_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
|
|
|
inspector: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_INSPECTOR_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
userHistogram: "DEVTOOLS_INSPECTOR_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_INSPECTOR_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
|
|
|
ruleview: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_RULEVIEW_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
userHistogram: "DEVTOOLS_RULEVIEW_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_RULEVIEW_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
|
|
|
computedview: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_COMPUTEDVIEW_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
userHistogram: "DEVTOOLS_COMPUTEDVIEW_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_COMPUTEDVIEW_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
|
|
|
fontinspector: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_FONTINSPECTOR_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
userHistogram: "DEVTOOLS_FONTINSPECTOR_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_FONTINSPECTOR_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
2015-01-10 21:51:46 +03:00
|
|
|
animationinspector: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_ANIMATIONINSPECTOR_OPENED_COUNT",
|
2015-01-10 21:51:46 +03:00
|
|
|
userHistogram: "DEVTOOLS_ANIMATIONINSPECTOR_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_ANIMATIONINSPECTOR_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
2013-05-24 14:26:17 +04:00
|
|
|
jsdebugger: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_JSDEBUGGER_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
userHistogram: "DEVTOOLS_JSDEBUGGER_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_JSDEBUGGER_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
|
|
|
jsbrowserdebugger: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_JSBROWSERDEBUGGER_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
userHistogram: "DEVTOOLS_JSBROWSERDEBUGGER_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_JSBROWSERDEBUGGER_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
|
|
|
styleeditor: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_STYLEEDITOR_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
userHistogram: "DEVTOOLS_STYLEEDITOR_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_STYLEEDITOR_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
2013-10-25 11:18:41 +04:00
|
|
|
shadereditor: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_SHADEREDITOR_OPENED_COUNT",
|
2013-10-25 11:18:41 +04:00
|
|
|
userHistogram: "DEVTOOLS_SHADEREDITOR_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_SHADEREDITOR_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
2014-06-14 03:19:26 +04:00
|
|
|
webaudioeditor: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_WEBAUDIOEDITOR_OPENED_COUNT",
|
2014-06-14 03:19:26 +04:00
|
|
|
userHistogram: "DEVTOOLS_WEBAUDIOEDITOR_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_WEBAUDIOEDITOR_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
2014-06-14 03:48:30 +04:00
|
|
|
canvasdebugger: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_CANVASDEBUGGER_OPENED_COUNT",
|
2014-06-14 03:48:30 +04:00
|
|
|
userHistogram: "DEVTOOLS_CANVASDEBUGGER_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_CANVASDEBUGGER_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
2015-03-31 18:28:43 +03:00
|
|
|
performance: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_JSPROFILER_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
userHistogram: "DEVTOOLS_JSPROFILER_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_JSPROFILER_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
2015-12-11 09:36:00 +03:00
|
|
|
memory: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_MEMORY_OPENED_COUNT",
|
2015-12-11 09:36:00 +03:00
|
|
|
userHistogram: "DEVTOOLS_MEMORY_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_MEMORY_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
2013-05-24 14:26:17 +04:00
|
|
|
netmonitor: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_NETMONITOR_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
userHistogram: "DEVTOOLS_NETMONITOR_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_NETMONITOR_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
2014-11-08 02:06:00 +03:00
|
|
|
storage: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_STORAGE_OPENED_COUNT",
|
2015-08-18 02:44:13 +03:00
|
|
|
userHistogram: "DEVTOOLS_STORAGE_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_STORAGE_TIME_ACTIVE_SECONDS"
|
2014-11-08 02:06:00 +03:00
|
|
|
},
|
2013-05-24 14:26:17 +04:00
|
|
|
paintflashing: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_PAINTFLASHING_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
userHistogram: "DEVTOOLS_PAINTFLASHING_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_PAINTFLASHING_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
|
|
|
scratchpad: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_SCRATCHPAD_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
userHistogram: "DEVTOOLS_SCRATCHPAD_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_SCRATCHPAD_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
2016-02-04 13:20:55 +03:00
|
|
|
"scratchpad-window": {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_SCRATCHPAD_WINDOW_OPENED_COUNT",
|
2016-02-04 13:20:55 +03:00
|
|
|
userHistogram: "DEVTOOLS_SCRATCHPAD_WINDOW_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_SCRATCHPAD_WINDOW_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
2013-05-24 14:26:17 +04:00
|
|
|
responsive: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_RESPONSIVE_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
userHistogram: "DEVTOOLS_RESPONSIVE_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_RESPONSIVE_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
2014-12-17 19:04:00 +03:00
|
|
|
eyedropper: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_EYEDROPPER_OPENED_COUNT",
|
2014-12-17 19:04:00 +03:00
|
|
|
userHistogram: "DEVTOOLS_EYEDROPPER_OPENED_PER_USER_FLAG",
|
|
|
|
},
|
|
|
|
menueyedropper: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_MENU_EYEDROPPER_OPENED_COUNT",
|
2014-12-17 19:04:00 +03:00
|
|
|
userHistogram: "DEVTOOLS_MENU_EYEDROPPER_OPENED_PER_USER_FLAG",
|
|
|
|
},
|
|
|
|
pickereyedropper: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_PICKER_EYEDROPPER_OPENED_COUNT",
|
2014-12-17 19:04:00 +03:00
|
|
|
userHistogram: "DEVTOOLS_PICKER_EYEDROPPER_OPENED_PER_USER_FLAG",
|
|
|
|
},
|
2013-05-24 14:26:17 +04:00
|
|
|
developertoolbar: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_DEVELOPERTOOLBAR_OPENED_COUNT",
|
2013-05-24 14:26:17 +04:00
|
|
|
userHistogram: "DEVTOOLS_DEVELOPERTOOLBAR_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_DEVELOPERTOOLBAR_TIME_ACTIVE_SECONDS"
|
2014-02-11 00:54:30 +04:00
|
|
|
},
|
2015-10-27 11:42:00 +03:00
|
|
|
aboutdebugging: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_ABOUTDEBUGGING_OPENED_COUNT",
|
2015-10-27 11:42:00 +03:00
|
|
|
userHistogram: "DEVTOOLS_ABOUTDEBUGGING_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_ABOUTDEBUGGING_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
2014-10-01 18:04:00 +04:00
|
|
|
webide: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_WEBIDE_OPENED_COUNT",
|
2014-10-01 18:04:00 +04:00
|
|
|
userHistogram: "DEVTOOLS_WEBIDE_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_WEBIDE_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
2015-08-18 02:44:13 +03:00
|
|
|
webideProjectEditor: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_WEBIDE_PROJECT_EDITOR_OPENED_COUNT",
|
2015-08-18 02:44:13 +03:00
|
|
|
userHistogram: "DEVTOOLS_WEBIDE_PROJECT_EDITOR_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_WEBIDE_PROJECT_EDITOR_TIME_ACTIVE_SECONDS"
|
|
|
|
},
|
|
|
|
webideProjectEditorSave: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_WEBIDE_PROJECT_EDITOR_SAVE_COUNT",
|
2015-08-18 02:44:13 +03:00
|
|
|
userHistogram: "DEVTOOLS_WEBIDE_PROJECT_EDITOR_SAVE_PER_USER_FLAG",
|
|
|
|
},
|
|
|
|
webideNewProject: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_WEBIDE_NEW_PROJECT_COUNT",
|
2015-08-18 02:44:13 +03:00
|
|
|
userHistogram: "DEVTOOLS_WEBIDE_NEW_PROJECT_PER_USER_FLAG",
|
|
|
|
},
|
|
|
|
webideImportProject: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_WEBIDE_IMPORT_PROJECT_COUNT",
|
2015-08-18 02:44:13 +03:00
|
|
|
userHistogram: "DEVTOOLS_WEBIDE_IMPORT_PROJECT_PER_USER_FLAG",
|
|
|
|
},
|
2014-02-11 00:54:30 +04:00
|
|
|
custom: {
|
2016-02-17 18:57:57 +03:00
|
|
|
histogram: "DEVTOOLS_CUSTOM_OPENED_COUNT",
|
2014-02-11 00:54:30 +04:00
|
|
|
userHistogram: "DEVTOOLS_CUSTOM_OPENED_PER_USER_FLAG",
|
|
|
|
timerHistogram: "DEVTOOLS_CUSTOM_TIME_ACTIVE_SECONDS"
|
2016-03-02 13:32:05 +03:00
|
|
|
},
|
|
|
|
reloadAddonInstalled: {
|
|
|
|
histogram: "DEVTOOLS_RELOAD_ADDON_INSTALLED_COUNT",
|
|
|
|
userHistogram: "DEVTOOLS_RELOAD_ADDON_INSTALLED_PER_USER_FLAG",
|
|
|
|
},
|
|
|
|
reloadAddonReload: {
|
|
|
|
histogram: "DEVTOOLS_RELOAD_ADDON_RELOAD_COUNT",
|
|
|
|
userHistogram: "DEVTOOLS_RELOAD_ADDON_RELOAD_PER_USER_FLAG",
|
|
|
|
},
|
2013-05-24 14:26:17 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an entry to a histogram.
|
|
|
|
*
|
|
|
|
* @param {String} id
|
|
|
|
* Used to look up the relevant histogram ID and log true to that
|
|
|
|
* histogram.
|
|
|
|
*/
|
2016-05-17 21:25:54 +03:00
|
|
|
toolOpened: function (id) {
|
2014-02-11 00:54:30 +04:00
|
|
|
let charts = this._histograms[id] || this._histograms.custom;
|
2013-05-24 14:26:17 +04:00
|
|
|
|
|
|
|
if (charts.histogram) {
|
|
|
|
this.log(charts.histogram, true);
|
|
|
|
}
|
|
|
|
if (charts.userHistogram) {
|
|
|
|
this.logOncePerBrowserVersion(charts.userHistogram, true);
|
|
|
|
}
|
|
|
|
if (charts.timerHistogram) {
|
2014-10-01 18:04:00 +04:00
|
|
|
this.startTimer(charts.timerHistogram);
|
2013-05-24 14:26:17 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-08-18 02:44:13 +03:00
|
|
|
/**
|
|
|
|
* Record that an action occurred. Aliases to `toolOpened`, so it's just for
|
|
|
|
* readability at the call site for cases where we aren't actually opening
|
|
|
|
* tools.
|
|
|
|
*/
|
|
|
|
actionOccurred(id) {
|
|
|
|
this.toolOpened(id);
|
|
|
|
},
|
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
toolClosed: function (id) {
|
2013-05-24 14:26:17 +04:00
|
|
|
let charts = this._histograms[id];
|
|
|
|
|
|
|
|
if (!charts || !charts.timerHistogram) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-01 18:04:00 +04:00
|
|
|
this.stopTimer(charts.timerHistogram);
|
|
|
|
},
|
2013-05-24 14:26:17 +04:00
|
|
|
|
2014-10-01 18:04:00 +04:00
|
|
|
/**
|
|
|
|
* Record the start time for a timing-based histogram entry.
|
|
|
|
*
|
|
|
|
* @param String histogramId
|
|
|
|
* Histogram in which the data is to be stored.
|
|
|
|
*/
|
2016-05-17 21:25:54 +03:00
|
|
|
startTimer: function (histogramId) {
|
2014-10-01 18:04:00 +04:00
|
|
|
this._timers.set(histogramId, new Date());
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop the timer and log elasped time for a timing-based histogram entry.
|
|
|
|
*
|
|
|
|
* @param String histogramId
|
|
|
|
* Histogram in which the data is to be stored.
|
2015-09-10 01:20:12 +03:00
|
|
|
* @param String key [optional]
|
|
|
|
* Optional key for a keyed histogram.
|
2014-10-01 18:04:00 +04:00
|
|
|
*/
|
2016-05-17 21:25:54 +03:00
|
|
|
stopTimer: function (histogramId, key) {
|
2014-10-01 18:04:00 +04:00
|
|
|
let startTime = this._timers.get(histogramId);
|
2013-05-24 14:26:17 +04:00
|
|
|
if (startTime) {
|
|
|
|
let time = (new Date() - startTime) / 1000;
|
2015-09-10 01:20:12 +03:00
|
|
|
if (!key) {
|
|
|
|
this.log(histogramId, time);
|
|
|
|
} else {
|
|
|
|
this.logKeyed(histogramId, key, time);
|
|
|
|
}
|
2014-10-01 18:04:00 +04:00
|
|
|
this._timers.delete(histogramId);
|
2013-05-24 14:26:17 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log a value to a histogram.
|
|
|
|
*
|
|
|
|
* @param {String} histogramId
|
|
|
|
* Histogram in which the data is to be stored.
|
|
|
|
* @param value
|
|
|
|
* Value to store.
|
|
|
|
*/
|
2016-05-17 21:25:54 +03:00
|
|
|
log: function (histogramId, value) {
|
2013-05-24 14:26:17 +04:00
|
|
|
if (histogramId) {
|
|
|
|
try {
|
|
|
|
let histogram = Services.telemetry.getHistogramById(histogramId);
|
|
|
|
histogram.add(value);
|
2016-05-17 21:25:54 +03:00
|
|
|
} catch (e) {
|
2013-05-24 14:26:17 +04:00
|
|
|
dump("Warning: An attempt was made to write to the " + histogramId +
|
|
|
|
" histogram, which is not defined in Histograms.json\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-05-08 01:10:49 +03:00
|
|
|
/**
|
|
|
|
* Log a value to a keyed histogram.
|
|
|
|
*
|
|
|
|
* @param {String} histogramId
|
|
|
|
* Histogram in which the data is to be stored.
|
|
|
|
* @param {String} key
|
|
|
|
* The key within the single histogram.
|
|
|
|
* @param value
|
|
|
|
* Value to store.
|
|
|
|
*/
|
2016-05-17 21:25:54 +03:00
|
|
|
logKeyed: function (histogramId, key, value) {
|
2015-05-08 01:10:49 +03:00
|
|
|
if (histogramId) {
|
|
|
|
try {
|
|
|
|
let histogram = Services.telemetry.getKeyedHistogramById(histogramId);
|
|
|
|
histogram.add(key, value);
|
2016-05-17 21:25:54 +03:00
|
|
|
} catch (e) {
|
2015-05-08 01:10:49 +03:00
|
|
|
dump("Warning: An attempt was made to write to the " + histogramId +
|
|
|
|
" histogram, which is not defined in Histograms.json\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-05-24 14:26:17 +04:00
|
|
|
/**
|
|
|
|
* Log info about usage once per browser version. This allows us to discover
|
|
|
|
* how many individual users are using our tools for each browser version.
|
|
|
|
*
|
|
|
|
* @param {String} perUserHistogram
|
|
|
|
* Histogram in which the data is to be stored.
|
|
|
|
*/
|
2016-05-17 21:25:54 +03:00
|
|
|
logOncePerBrowserVersion: function (perUserHistogram, value) {
|
2013-05-24 14:26:17 +04:00
|
|
|
let currentVersion = appInfo.version;
|
|
|
|
let latest = Services.prefs.getCharPref(TOOLS_OPENED_PREF);
|
|
|
|
let latestObj = JSON.parse(latest);
|
|
|
|
|
|
|
|
let lastVersionHistogramUpdated = latestObj[perUserHistogram];
|
|
|
|
|
|
|
|
if (typeof lastVersionHistogramUpdated == "undefined" ||
|
|
|
|
lastVersionHistogramUpdated !== currentVersion) {
|
|
|
|
latestObj[perUserHistogram] = currentVersion;
|
|
|
|
latest = JSON.stringify(latestObj);
|
|
|
|
Services.prefs.setCharPref(TOOLS_OPENED_PREF, latest);
|
|
|
|
this.log(perUserHistogram, value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
destroy: function () {
|
2014-10-01 18:04:00 +04:00
|
|
|
for (let histogramId of this._timers.keys()) {
|
|
|
|
this.stopTimer(histogramId);
|
2013-05-24 14:26:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "appInfo", function () {
|
2013-05-24 14:26:17 +04:00
|
|
|
return Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo);
|
|
|
|
});
|