Bug 1488206 - TelemetryStopwatch: error requesting elapsed time for nonexisting stopwatch r=Honza
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Thu, 20 Sep 2018 11:06:58 +0000
changeset 437429 705f3c3d5d60ed20c255fbe33d79e0fc8f1e4526
parent 437428 9d400e7fa5e6e48cde2f7927e05bcdb8295cb933
child 437430 c5b3caf36ddf3e451feef98e271fea2107af6811
push id34683
push userapavel@mozilla.com
push dateThu, 20 Sep 2018 21:54:05 +0000
treeherdermozilla-central@4d3cd0ab7277 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1488206
milestone64.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 1488206 - TelemetryStopwatch: error requesting elapsed time for nonexisting stopwatch r=Honza Because firefox can be closed with the toolbox in a half initialized state telemetry can throw if it expects a tool to be closing when no tools are fully initialized although this is completely expected. Here we simply choose not to report those errors because this is expected behaviour. Differential Revision: https://phabricator.services.mozilla.com/D4869
devtools/client/shared/telemetry.js
--- a/devtools/client/shared/telemetry.js
+++ b/devtools/client/shared/telemetry.js
@@ -132,17 +132,25 @@ class Telemetry {
    *        fire when a stopwatch is finished after being canceled.
    *        Defaults to false.
    *
    * @returns {Boolean}
    *          True if the timer was succesfully stopped and the data was added
    *          to the histogram, False otherwise.
    */
   finish(histogramId, obj, canceledOkay) {
-    return TelemetryStopwatch.finish(histogramId, obj, canceledOkay);
+    // Avoid errors caused by the toolbox not being properly initialized.
+    this.ignoreStopwatchErrors(true);
+
+    const result = TelemetryStopwatch.finish(histogramId, obj, canceledOkay);
+
+    // Watch for errors again.
+    this.ignoreStopwatchErrors(false);
+
+    return result;
   }
 
   /**
    * Stops the timer associated with the given keyed histogram (and object),
    * calculates the time delta between start and finish, and adds the value
    * to the keyed histogram.
    *
    * @param {String} histogramId
@@ -157,17 +165,38 @@ class Telemetry {
    *        fire when a stopwatch is finished after being canceled.
    *        Defaults to false.
    *
    * @returns {Boolean}
    *          True if the timer was succesfully stopped and the data was added
    *          to the histogram, False otherwise.
    */
   finishKeyed(histogramId, key, obj, canceledOkay) {
-    return TelemetryStopwatch.finishKeyed(histogramId, key, obj, canceledOkay);
+    // Avoid errors caused by the toolbox not being properly initialized.
+    this.ignoreStopwatchErrors(true);
+
+    const result = TelemetryStopwatch.finishKeyed(histogramId, key, obj, canceledOkay);
+
+    // Watch for errors again.
+    this.ignoreStopwatchErrors(false);
+
+    return result;
+  }
+
+  /**
+   * Set a flag to ignore TelemetryStopwatch errors.
+   *
+   * @param {Boolean} testing
+   *        Flag to select whether to ignore TelemetryStopwatch errors.
+   */
+  ignoreStopwatchErrors(testing) {
+    // FIXME: https://bugzil.la/1491879 - Fix telemetry support for multiple
+    //        tabs / windows. This method should be removed as it is hiding
+    //        a problem with using telemetry in multiple tabs / windows.
+    TelemetryStopwatch.setTestModeEnabled(testing);
   }
 
   /**
    * Log a value to a histogram.
    *
    * @param  {String} histogramId
    *         Histogram in which the data is to be stored.
    */
@@ -612,16 +641,23 @@ class Telemetry {
 
     if (!charts) {
       return;
     }
 
     if (charts.useTimedEvent) {
       const sig = `devtools.main,tool_timer,${id},null`;
       const event = PENDING_EVENTS.get(sig);
+
+      if (!event) {
+        // FIXME: https://bugzil.la/1491879 - Fix telemetry support for multiple
+        //        tabs / windows. For the moment we need to bail out.
+        return;
+      }
+
       const time = this.msSystemNow() - event.extra.time_open;
 
       this.addEventProperties("devtools.main", "tool_timer", id, null, {
         "time_open": time,
         "os": this.osNameAndVersion,
         "session_id": sessionId
       });
     }