Bug 1437551 - [2.6] Add GeckoRuntime telemetry API backend. r=jchen,Dexter CLOSED TREE
☠☠ backed out by cac46e410f99 ☠ ☠
authorEugen Sawin <esawin@mozilla.com>
Mon, 23 Apr 2018 23:10:28 +0200
changeset 468699 6badc13e1d210c59ee161e7dc52b9e5a34811cce
parent 468698 5582b64d4a8b25276cfe1f4e035e37fbd7701f6b
child 468700 2f30bed5423644f54c7d8ef3115427f3f6e52382
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen, Dexter
bugs1437551
milestone61.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 1437551 - [2.6] Add GeckoRuntime telemetry API backend. r=jchen,Dexter CLOSED TREE
toolkit/components/telemetry/geckoview/GeckoViewTelemetryController.jsm
--- a/toolkit/components/telemetry/geckoview/GeckoViewTelemetryController.jsm
+++ b/toolkit/components/telemetry/geckoview/GeckoViewTelemetryController.jsm
@@ -3,32 +3,111 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/GeckoViewUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
+  EventDispatcher: "resource://gre/modules/Messaging.jsm",
   Services: "resource://gre/modules/Services.jsm",
   TelemetryUtils: "resource://gre/modules/TelemetryUtils.jsm",
 });
 
 GeckoViewUtils.initLogging("GeckoView.TelemetryController", this);
 
 var EXPORTED_SYMBOLS = ["GeckoViewTelemetryController"];
 
 /* global debug warn */
 
-let GeckoViewTelemetryController = {
+/**
+ * Telemetry snapshot API adaptors used to retrieve one or more snapshots
+ * for GeckoView:TelemetrySnapshots requests.
+ * Match with RuntimeTelemetry.SNAPSHOT_* and nsITelemetry.idl.
+ */
+const TelemetrySnapshots = [
+  {
+    type: "histograms",
+    flag: (1 << 0),
+    get: (dataset, clear) => Services.telemetry.snapshotHistograms(
+                               dataset, false, clear)
+  },
+  {
+    type: "keyedHistograms",
+    flag: (1 << 1),
+    get: (dataset, clear) => Services.telemetry.snapshotKeyedHistograms(
+                               dataset, false, clear)
+  },
+  {
+    type: "scalars",
+    flag: (1 << 2),
+    get: (dataset, clear) => Services.telemetry.snapshotScalars(
+                               dataset, clear)
+  },
+  {
+    type: "keyedScalars",
+    flag: (1 << 3),
+    get: (dataset, clear) => Services.telemetry.snapshotKeyedScalars(
+                               dataset, clear)
+  },
+];
+
+const GeckoViewTelemetryController = {
   /**
    * Setup the Telemetry recording flags. This must be called
    * in all the processes that need to collect Telemetry.
    */
   setup() {
     debug `setup`;
 
     TelemetryUtils.setTelemetryRecordingFlags();
 
     debug `setup - canRecordPrereleaseData ${Services.telemetry.canRecordPrereleaseData
           }, canRecordReleaseData ${Services.telemetry.canRecordReleaseData}`;
+
+    if (GeckoViewUtils.IS_PARENT_PROCESS) {
+      try {
+        EventDispatcher.instance.registerListener(this, [
+          "GeckoView:TelemetrySnapshots",
+        ]);
+      } catch (e) {
+        warn `Failed registering GeckoView:TelemetrySnapshots listener: ${e}`;
+      }
+    }
+  },
+
+  /**
+   * Handle GeckoView:TelemetrySnapshots requests.
+   * Match with RuntimeTelemetry.getSnapshots.
+   *
+   * @param aEvent Name of the event to dispatch.
+   * @param aData Optional object containing data for the event.
+   * @param aCallback Optional callback implementing nsIAndroidEventCallback.
+   */
+  onEvent(aEvent, aData, aCallback) {
+    debug `onEvent: aEvent=${aEvent}, aData=${aData}`;
+
+    if (aEvent !== "GeckoView:TelemetrySnapshots") {
+      warn `Received unexpected event ${aEvent}`;
+      return;
+    }
+
+    const { clear, types, dataset } = aData;
+    let snapshots = {};
+
+    // Iterate over all snapshot types, retreive and assemble results.
+    for (const tel of TelemetrySnapshots) {
+      if ((tel.flag & types) == 0) {
+        // This snapshot type has not been requested.
+        continue;
+      }
+      const snapshot = tel.get(dataset, clear);
+      if (!snapshot) {
+        aCallback.onError(`Failed retrieving ${tel.type} snapshot!`);
+        return;
+      }
+      snapshots[tel.type] = snapshot;
+    }
+
+    aCallback.onSuccess(snapshots);
   },
 };