Bug 1437551 - [1.4] Add GeckoRuntime telemetry API. r=snorp,jchen CLOSED TREE
☠☠ backed out by cac46e410f99 ☠ ☠
authorEugen Sawin <esawin@mozilla.com>
Mon, 23 Apr 2018 22:52:58 +0200
changeset 415103 5582b64d4a8b25276cfe1f4e035e37fbd7701f6b
parent 415102 5724b08c3cbd1e09b415b6205f97eb8e3506127d
child 415104 6badc13e1d210c59ee161e7dc52b9e5a34811cce
push id102499
push useresawin@mozilla.com
push dateMon, 23 Apr 2018 21:22:45 +0000
treeherdermozilla-inbound@2f30bed54236 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, jchen
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 - [1.4] Add GeckoRuntime telemetry API. r=snorp,jchen CLOSED TREE
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntime.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/RuntimeTelemetry.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntime.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntime.java
@@ -15,16 +15,17 @@ import android.util.Log;
 
 import org.mozilla.gecko.EventDispatcher;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoThread;
 import org.mozilla.gecko.PrefsHelper;
 import org.mozilla.gecko.util.BundleEventListener;
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.GeckoBundle;
+import org.mozilla.gecko.util.ThreadUtils;
 
 public final class GeckoRuntime implements Parcelable {
     private static final String LOGTAG = "GeckoRuntime";
     private static final boolean DEBUG = false;
 
     private static GeckoRuntime sDefaultRuntime;
 
     /**
@@ -45,16 +46,17 @@ public final class GeckoRuntime implemen
             sDefaultRuntime.init(new GeckoRuntimeSettings());
         }
 
         return sDefaultRuntime;
     }
 
     private GeckoRuntimeSettings mSettings;
     private Delegate mDelegate;
+    private RuntimeTelemetry mTelemetry;
 
     /**
      * Attach the runtime to the given context.
      *
      * @param context The new context to attach to.
      */
     public void attachTo(final @NonNull Context context) {
         if (DEBUG) {
@@ -189,16 +191,31 @@ public final class GeckoRuntime implemen
     public GeckoRuntimeSettings getSettings() {
         return mSettings;
     }
 
     /* package */ void setPref(final String name, final Object value) {
         PrefsHelper.setPref(name, value, /* flush */ false);
     }
 
+    /**
+     * Return the telemetry object for this runtime.
+     *
+     * @return The telemetry object.
+     */
+    public RuntimeTelemetry getTelemetry() {
+        ThreadUtils.assertOnUiThread();
+
+        if (mTelemetry == null) {
+            mTelemetry = new RuntimeTelemetry(this);
+        }
+        return mTelemetry;
+
+    }
+
     @Override // Parcelable
     public int describeContents() {
         return 0;
     }
 
     @Override // Parcelable
     public void writeToParcel(Parcel out, int flags) {
         out.writeParcelable(mSettings, flags);
new file mode 100644
--- /dev/null
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/RuntimeTelemetry.java
@@ -0,0 +1,130 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * vim: ts=4 sw=4 expandtab:
+ * 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/. */
+
+package org.mozilla.geckoview;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import android.support.annotation.IntDef;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.util.Log;
+
+import org.mozilla.gecko.EventDispatcher;
+import org.mozilla.gecko.util.GeckoBundle;
+import org.mozilla.gecko.util.EventCallback;
+
+/**
+ * The telemetry API gives access to telemetry data of the Gecko runtime.
+ */
+public final class RuntimeTelemetry {
+    private final static String LOGTAG = "GeckoViewTelemetry";
+    private final static boolean DEBUG = false;
+
+    private final GeckoRuntime mRuntime;
+    private final EventDispatcher mEventDispatcher;
+
+    @Retention(RetentionPolicy.SOURCE)
+    @IntDef({ DATASET_BASE, DATASET_EXTENDED })
+    public @interface DatasetType {}
+
+    // Match with nsITelemetry.
+    /**
+     * The base dataset suitable for release builds.
+     */
+    public static final int DATASET_BASE = 0;
+    /**
+     * The extended dataset suitable for pre-release builds.
+     */
+    public static final int DATASET_EXTENDED = 1;
+
+    @IntDef(flag = true,
+            value = { SNAPSHOT_HISTOGRAMS, SNAPSHOT_KEYED_HISTOGRAMS,
+                      SNAPSHOT_SCALARS, SNAPSHOT_KEYED_SCALARS,
+                      SNAPSHOT_ALL })
+    public @interface SnapshotType {}
+
+    // Match with GeckoViewTelemetryController.
+    /**
+     * Adds a "histogram" object entry to the snapshot response.
+     */
+    public static final int SNAPSHOT_HISTOGRAMS = 1 << 0;
+    /**
+     * Adds a "keyedHistogram" object entry to the snapshot response.
+     */
+    public static final int SNAPSHOT_KEYED_HISTOGRAMS = 1 << 1;
+    /**
+     * Adds a "scalars" object entry to the snapshot response.
+     */
+    public static final int SNAPSHOT_SCALARS = 1 << 2;
+    /**
+     * Adds a "keyedScalars" object entry to the snapshot response.
+     */
+    public static final int SNAPSHOT_KEYED_SCALARS = 1 << 3;
+    /**
+     * Adds all snapshot types to the response.
+     */
+    public static final int SNAPSHOT_ALL = (1 << 4) - 1;
+
+    /* package */ RuntimeTelemetry(final @NonNull GeckoRuntime runtime) {
+        mRuntime = runtime;
+        mEventDispatcher = EventDispatcher.getInstance();
+    }
+
+    /**
+     * Retrieve all telemetry snapshots.
+     *
+     * @param dataset The dataset type to retreive.
+     *                One of {@link #RuntimeTelemetry.DATASET_BASE DATASET_*} flags.
+     * @param clear Whether the retrieved snapshots should be cleared.
+     * @param response Used to return the async response.
+     */
+    public void getSnapshots(
+          final @DatasetType int dataset,
+          final boolean clear,
+          final @NonNull GeckoResponse<GeckoBundle> response) {
+        getSnapshots(SNAPSHOT_ALL, dataset, clear, response);
+    }
+
+    /**
+     * Retrieve the requested telemetry snapshots.
+     *
+     * @param types The requested snapshot types.
+     *              One or more of {@link #RuntimeTelemetry.SNAPSHOT_HISTOGRAMS SNAPSHOT_*} flags.
+     * @param dataset The dataset type to retreive.
+     *                One of {@link #RuntimeTelemetry.DATASET_BASE DATASET_*} flags.
+     * @param clear Whether the retrieved snapshots should be cleared.
+     * @param response Used to return the async response.
+     */
+    public void getSnapshots(
+          final @SnapshotType int types,
+          final @DatasetType int dataset,
+          final boolean clear,
+          final @NonNull GeckoResponse<GeckoBundle> response) {
+        final GeckoBundle msg = new GeckoBundle(3);
+        msg.putInt("types", types);
+        msg.putInt("dataset", dataset);
+        msg.putBoolean("clear", clear);
+
+        mEventDispatcher.dispatch("GeckoView:TelemetrySnapshots", msg,
+            new EventCallback() {
+                @Override
+                public void sendSuccess(final Object result) {
+                    response.respond((GeckoBundle) result);
+                }
+
+                @Override
+                public void sendError(final Object error) {
+                    Log.e(LOGTAG, "getSnapshots failed: " + error);
+                    response.respond(null);
+                }
+            });
+    }
+}