Bug 1356223 - Support scalar telemetry probe types in Telemetry.js r?pbro
MozReview-Commit-ID: A2SMdvjy4jp
--- a/devtools/client/commandline/test/browser_gcli_telemetry.js
+++ b/devtools/client/commandline/test/browser_gcli_telemetry.js
@@ -74,49 +74,52 @@ function* spawnTest() {
* 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._oldlogScalar = Telemetry.prototype.logScalar;
+ Telemetry.prototype.logScalar = Telemetry.prototype.log;
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.logScalar = Telemetry.prototype._oldlogScalar;
Telemetry.prototype.logKeyed = Telemetry.prototype._oldlogKeyed;
delete Telemetry.prototype._oldlog;
+ delete Telemetry.prototype._oldlogScalar;
delete Telemetry.prototype._oldlogKeyed;
delete Telemetry.prototype.telemetryInfo;
}
function checkTelemetryResults(results) {
let prefix = COMMAND_HISTOGRAM_ID + "|";
let keys = Object.keys(results).filter(result => {
return result.startsWith(prefix);
--- a/devtools/client/framework/test/shared-head.js
+++ b/devtools/client/framework/test/shared-head.js
@@ -579,34 +579,38 @@ function loadTelemetryAndRecordLogs() {
}
if (histogramId) {
if (!this.telemetryInfo[histogramId]) {
this.telemetryInfo[histogramId] = [];
}
this.telemetryInfo[histogramId].push(value);
}
};
+ Telemetry.prototype._oldlogScalar = Telemetry.prototype.logScalar;
+ Telemetry.prototype.logScalar = Telemetry.prototype.log;
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.logScalar = Telemetry.prototype._oldlogScalar;
Telemetry.prototype.logKeyed = Telemetry.prototype._oldlogKeyed;
delete Telemetry.prototype._oldlog;
+ delete Telemetry.prototype._oldlogScalar;
delete Telemetry.prototype._oldlogKeyed;
delete Telemetry.prototype.telemetryInfo;
}
/**
* Clean the logical clipboard content. This method only clears the OS clipboard on
* Windows (see Bug 666254).
*/
--- a/devtools/client/shared/telemetry.js
+++ b/devtools/client/shared/telemetry.js
@@ -194,16 +194,19 @@ Telemetry.prototype = {
let charts = this._histograms[id] || this._histograms.custom;
if (charts.histogram) {
this.log(charts.histogram, true);
}
if (charts.timerHistogram) {
this.startTimer(charts.timerHistogram);
}
+ if (charts.scalar) {
+ this.logScalar(charts.scalar, 1);
+ }
},
/**
* 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) {
@@ -255,24 +258,54 @@ Telemetry.prototype = {
* Log a value to a histogram.
*
* @param {String} histogramId
* Histogram in which the data is to be stored.
* @param value
* Value to store.
*/
log: function (histogramId, value) {
- if (histogramId) {
- 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");
+ if (!histogramId) {
+ return;
+ }
+
+ 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`);
+ }
+ },
+
+ /**
+ * Log a value to a scalar.
+ *
+ * @param {String} scalarId
+ * Scalar in which the data is to be stored.
+ * @param value
+ * Value to store.
+ */
+ logScalar: function (scalarId, value) {
+ if (!scalarId) {
+ return;
+ }
+
+ try {
+ if (isNaN(value)) {
+ dump(`Warning: An attempt was made to write a non-numeric value ` +
+ `${value} to the ${scalarId} scalar. Only numeric values are ` +
+ `allowed.`);
+
+ return;
}
+ Services.telemetry.scalarSet(scalarId, value);
+ } catch (e) {
+ dump(`Warning: An attempt was made to write to the ${scalarId} ` +
+ `scalar, which is not defined in Scalars.yaml\n`);
}
},
/**
* Log a value to a keyed histogram.
*
* @param {String} histogramId
* Histogram in which the data is to be stored.
@@ -287,18 +320,18 @@ Telemetry.prototype = {
let histogram = Services.telemetry.getKeyedHistogramById(histogramId);
if (typeof value === "undefined") {
histogram.add(key);
} else {
histogram.add(key, value);
}
} catch (e) {
- dump("Warning: An attempt was made to write to the " + histogramId +
- " histogram, which is not defined in Histograms.json\n");
+ dump(`Warning: An attempt was made to write to the ${histogramId} ` +
+ `histogram, which is not defined in Histograms.json\n`);
}
}
},
/**
* 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.
*