Bug 1356223 - Support scalar telemetry probe types in Telemetry.js r=pbro
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Wed, 19 Apr 2017 12:44:54 +0100
changeset 354041 91c19f2d71f35f1bb4ee5325870275d648b0c2db
parent 354040 ad7d2ae91ce67d5cdc71e36293d8978235269c10
child 354042 2fddfb975738d2196b40df878a1f60262f431fe8
push id31685
push userkwierso@gmail.com
push dateThu, 20 Apr 2017 21:45:29 +0000
treeherdermozilla-central@5e3dc7e1288a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbro
bugs1356223
milestone55.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 1356223 - Support scalar telemetry probe types in Telemetry.js r=pbro MozReview-Commit-ID: A2SMdvjy4jp
devtools/client/commandline/test/browser_gcli_telemetry.js
devtools/client/framework/test/shared-head.js
devtools/client/shared/telemetry.js
--- 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.
    *