Bug 1694481 - Remove unused telemetry methods. r=aklotz

Differential Revision: https://phabricator.services.mozilla.com/D106174
This commit is contained in:
Agi Sferro 2021-03-10 22:43:05 +00:00
parent 0f483545c6
commit 83874acc8d
8 changed files with 0 additions and 424 deletions

View File

@ -6,10 +6,6 @@
package org.mozilla.gecko;
import org.mozilla.gecko.annotation.WrapForJNI;
import org.mozilla.gecko.TelemetryContract.Event;
import org.mozilla.gecko.TelemetryContract.Method;
import org.mozilla.gecko.TelemetryContract.Reason;
import org.mozilla.gecko.TelemetryContract.Session;
import android.os.SystemClock;
import android.util.Log;
@ -25,14 +21,10 @@ import android.util.Log;
* The majority of methods in this class are defined in terms of real time.
*/
public class TelemetryUtils {
private static final boolean DEBUG = false;
private static final String LOGTAG = "TelemetryUtils";
@WrapForJNI(stubName = "AddHistogram", dispatchTo = "gecko")
private static native void nativeAddHistogram(String name, int value);
@WrapForJNI(stubName = "AddKeyedHistogram", dispatchTo = "gecko")
private static native void nativeAddKeyedHistogram(String name, String key, int value);
public static long uptime() {
return SystemClock.uptimeMillis();
@ -53,15 +45,6 @@ public class TelemetryUtils {
}
}
public static void addToKeyedHistogram(final String name, final String key, final int value) {
if (GeckoThread.isRunning()) {
nativeAddKeyedHistogram(name, key, value);
} else {
GeckoThread.queueNativeCall(TelemetryUtils.class, "nativeAddKeyedHistogram",
String.class, name, String.class, key, value);
}
}
public abstract static class Timer {
private final long mStartTime;
private final String mName;
@ -108,17 +91,6 @@ public class TelemetryUtils {
}
}
public static class RealtimeTimer extends Timer {
public RealtimeTimer(final String name) {
super(name);
}
@Override
protected long now() {
return TelemetryUtils.realtime();
}
}
public static class UptimeTimer extends Timer {
public UptimeTimer(final String name) {
super(name);
@ -129,119 +101,4 @@ public class TelemetryUtils {
return TelemetryUtils.uptime();
}
}
@WrapForJNI(stubName = "StartUISession", dispatchTo = "gecko")
private static native void nativeStartUiSession(String name, long timestamp);
@WrapForJNI(stubName = "StopUISession", dispatchTo = "gecko")
private static native void nativeStopUiSession(String name, String reason, long timestamp);
@WrapForJNI(stubName = "AddUIEvent", dispatchTo = "gecko")
private static native void nativeAddUiEvent(String action, String method,
long timestamp, String extras);
public static void startUISession(final Session session, final String sessionNameSuffix) {
final String sessionName = getSessionName(session, sessionNameSuffix);
Log.d(LOGTAG, "StartUISession: " + sessionName);
if (GeckoThread.isRunning()) {
nativeStartUiSession(sessionName, realtime());
} else {
GeckoThread.queueNativeCall(TelemetryUtils.class, "nativeStartUiSession",
String.class, sessionName, realtime());
}
}
public static void startUISession(final Session session) {
startUISession(session, null);
}
public static void stopUISession(final Session session, final String sessionNameSuffix,
final Reason reason) {
final String sessionName = getSessionName(session, sessionNameSuffix);
Log.d(LOGTAG, "StopUISession: " + sessionName + ", reason=" + reason);
if (GeckoThread.isRunning()) {
nativeStopUiSession(sessionName, reason.toString(), realtime());
} else {
GeckoThread.queueNativeCall(TelemetryUtils.class, "nativeStopUiSession",
String.class, sessionName,
String.class, reason.toString(), realtime());
}
}
public static void stopUISession(final Session session, final Reason reason) {
stopUISession(session, null, reason);
}
public static void stopUISession(final Session session, final String sessionNameSuffix) {
stopUISession(session, sessionNameSuffix, Reason.NONE);
}
public static void stopUISession(final Session session) {
stopUISession(session, null, Reason.NONE);
}
private static String getSessionName(final Session session, final String sessionNameSuffix) {
if (sessionNameSuffix != null) {
return session.toString() + ":" + sessionNameSuffix;
} else {
return session.toString();
}
}
/**
* @param method A non-null method (if null is desired, consider using Method.NONE)
*/
/* package */ static void sendUIEvent(final String eventName, final Method method,
final long timestamp, final String extras) {
if (method == null) {
throw new IllegalArgumentException("Expected non-null method - use Method.NONE?");
}
if (DEBUG) {
final String logString = "SendUIEvent: event = " + eventName + " method = " + method + " timestamp = " +
timestamp + " extras = " + extras;
Log.d(LOGTAG, logString);
}
if (GeckoThread.isRunning()) {
nativeAddUiEvent(eventName, method.toString(), timestamp, extras);
} else {
GeckoThread.queueNativeCall(TelemetryUtils.class, "nativeAddUiEvent",
String.class, eventName, String.class, method.toString(),
timestamp, String.class, extras);
}
}
public static void sendUIEvent(final Event event, final Method method, final long timestamp,
final String extras) {
sendUIEvent(event.toString(), method, timestamp, extras);
}
public static void sendUIEvent(final Event event, final Method method, final long timestamp) {
sendUIEvent(event, method, timestamp, null);
}
public static void sendUIEvent(final Event event, final Method method, final String extras) {
sendUIEvent(event, method, realtime(), extras);
}
public static void sendUIEvent(final Event event, final Method method) {
sendUIEvent(event, method, realtime(), null);
}
public static void sendUIEvent(final Event event) {
sendUIEvent(event, Method.NONE, realtime(), null);
}
/**
* Sends a UIEvent with the given status appended to the event name.
*
* This method is a slight bend of the Telemetry framework so chances
* are that you don't want to use this: please think really hard before you do.
*
* Intended for use with data policy notifications.
*/
public static void sendUIEvent(final Event event, final boolean eventStatus) {
final String eventName = event + ":" + eventStatus;
sendUIEvent(eventName, Method.NONE, realtime(), null);
}
}

View File

@ -24,11 +24,6 @@ ChromeUtils.defineModuleGetter(
"NarrateControls",
"resource://gre/modules/narrate/NarrateControls.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"UITelemetry",
"resource://gre/modules/UITelemetry.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"PluralForm",
@ -1026,10 +1021,6 @@ AboutReader.prototype = {
return;
}
// Just pass the ID of the button as an extra and hope the ID doesn't change
// unless the context changes
UITelemetry.addEvent("action.1", "button", null, id);
let labels = segmentedButton.children;
for (let label of labels) {
label.removeAttribute("checked");

View File

@ -105,7 +105,6 @@ EXTRA_JS_MODULES += [
"app/TelemetryStorage.jsm",
"app/TelemetryTimestamps.jsm",
"app/TelemetryUtils.jsm",
"other/UITelemetry.jsm",
"pings/CoveragePing.jsm",
"pings/EcosystemTelemetry.jsm",
"pings/EventPing.jsm",

View File

@ -1,185 +0,0 @@
/* 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/. */
"use strict";
var EXPORTED_SYMBOLS = ["UITelemetry"];
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { TelemetryUtils } = ChromeUtils.import(
"resource://gre/modules/TelemetryUtils.jsm"
);
/**
* UITelemetry is a helper JSM used to record UI specific telemetry events.
*
* It implements nsIUITelemetryObserver, defined in nsIAndroidBridge.idl.
*/
var UITelemetry = {
_enabled: undefined,
_activeSessions: {},
_measurements: [],
// Lazily decide whether telemetry is enabled.
get enabled() {
if (this._enabled !== undefined) {
return this._enabled;
}
// Set an observer to watch for changes at runtime.
Services.prefs.addObserver(
TelemetryUtils.Preferences.TelemetryEnabled,
this
);
Services.obs.addObserver(this, "profile-before-change");
// Pick up the current value.
this._enabled = Services.prefs.getBoolPref(
TelemetryUtils.Preferences.TelemetryEnabled,
false
);
return this._enabled;
},
observe(aSubject, aTopic, aData) {
if (aTopic == "profile-before-change") {
Services.obs.removeObserver(this, "profile-before-change");
Services.prefs.removeObserver(
TelemetryUtils.Preferences.TelemetryEnabled,
this
);
this._enabled = undefined;
return;
}
if (aTopic == "nsPref:changed") {
switch (aData) {
case TelemetryUtils.Preferences.TelemetryEnabled:
let on = Services.prefs.getBoolPref(
TelemetryUtils.Preferences.TelemetryEnabled
);
this._enabled = on;
// Wipe ourselves if we were just disabled.
if (!on) {
this._activeSessions = {};
this._measurements = [];
}
break;
}
}
},
/**
* This exists exclusively for testing -- our events are not intended to
* be retrieved via an XPCOM interface.
*/
get wrappedJSObject() {
return this;
},
/**
* A hack to generate the relative timestamp from start when we don't have
* access to the Java timer.
* XXX: Bug 1007647 - Support realtime and/or uptime in JavaScript.
*/
uptimeMillis() {
return Date.now() - Services.startup.getStartupInfo().process;
},
/**
* Adds a single event described by a timestamp, an action, and the calling
* method.
*
* Optionally provide a string 'extras', which will be recorded as part of
* the event.
*
* All extant sessions will be recorded by name for each event.
*/
addEvent(aAction, aMethod, aTimestamp, aExtras) {
if (!this.enabled) {
return;
}
let sessions = Object.keys(this._activeSessions);
let aEvent = {
type: "event",
action: aAction,
method: aMethod,
sessions,
timestamp: aTimestamp == undefined ? this.uptimeMillis() : aTimestamp,
};
if (aExtras) {
aEvent.extras = aExtras;
}
this._recordEvent(aEvent);
},
/**
* Begins tracking a session by storing a timestamp for session start.
*/
startSession(aName, aTimestamp) {
if (!this.enabled) {
return;
}
if (this._activeSessions[aName]) {
// Do not overwrite a previous event start if it already exists.
return;
}
this._activeSessions[aName] =
aTimestamp == undefined ? this.uptimeMillis() : aTimestamp;
},
/**
* Tracks the end of a session with a timestamp.
*/
stopSession(aName, aReason, aTimestamp) {
if (!this.enabled) {
return;
}
let sessionStart = this._activeSessions[aName];
delete this._activeSessions[aName];
if (!sessionStart) {
return;
}
let aEvent = {
type: "session",
name: aName,
reason: aReason,
start: sessionStart,
end: aTimestamp == undefined ? this.uptimeMillis() : aTimestamp,
};
this._recordEvent(aEvent);
},
_recordEvent(aEvent) {
this._measurements.push(aEvent);
},
/**
* Called by TelemetrySession to populate the UI measurement
* blob.
*
* Optionally clears the set of measurements based on aClear.
*/
getUIMeasurements(aClear) {
if (!this.enabled) {
return [];
}
let measurements = this._measurements.slice();
if (aClear) {
this._measurements = [];
}
return measurements;
},
};

View File

@ -21,7 +21,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
AddonManagerPrivate: "resource://gre/modules/AddonManager.jsm",
TelemetryController: "resource://gre/modules/TelemetryController.jsm",
TelemetryStorage: "resource://gre/modules/TelemetryStorage.jsm",
UITelemetry: "resource://gre/modules/UITelemetry.jsm",
TelemetryEnvironment: "resource://gre/modules/TelemetryEnvironment.jsm",
TelemetryReportingPolicy:
"resource://gre/modules/TelemetryReportingPolicy.jsm",
@ -41,7 +40,6 @@ const REASON_ABORTED_SESSION = "aborted-session";
const REASON_DAILY = "daily";
const REASON_SAVED_SESSION = "saved-session";
const REASON_GATHER_PAYLOAD = "gather-payload";
const REASON_GATHER_SUBSESSION_PAYLOAD = "gather-subsession-payload";
const REASON_TEST_PING = "test-ping";
const REASON_ENVIRONMENT_CHANGE = "environment-change";
const REASON_SHUTDOWN = "shutdown";
@ -715,17 +713,6 @@ var Impl = {
AddonManagerPrivate.getTelemetryDetails()
);
let clearUIsession = !(
reason == REASON_GATHER_PAYLOAD ||
reason == REASON_GATHER_SUBSESSION_PAYLOAD
);
if (AppConstants.platform == "android") {
payloadObj.UIMeasurements = protect(() =>
UITelemetry.getUIMeasurements(clearUIsession)
);
}
if (
this._slowSQLStartup &&
!!Object.keys(this._slowSQLStartup).length &&

View File

@ -2079,10 +2079,6 @@ add_task(async function test_pingExtendedStats() {
"addonDetails",
];
if (AppConstants.platform == "android") {
EXTENDED_PAYLOAD_FIELDS.push("UIMeasurements");
}
// Reset telemetry and disable sending extended statistics.
await TelemetryStorage.testClearPendingPings();
PingServer.clearRequests();

View File

@ -18,66 +18,11 @@ namespace widget {
class Telemetry final : public java::TelemetryUtils::Natives<Telemetry> {
Telemetry() = delete;
static already_AddRefed<nsIUITelemetryObserver> GetObserver() {
nsAppShell* const appShell = nsAppShell::Get();
if (!appShell) {
return nullptr;
}
nsCOMPtr<nsIAndroidBrowserApp> browserApp = appShell->GetBrowserApp();
nsCOMPtr<nsIUITelemetryObserver> obs;
if (!browserApp ||
NS_FAILED(browserApp->GetUITelemetryObserver(getter_AddRefs(obs))) ||
!obs) {
return nullptr;
}
return obs.forget();
}
public:
static void AddHistogram(jni::String::Param aName, int32_t aValue) {
MOZ_ASSERT(aName);
mozilla::Telemetry::Accumulate(aName->ToCString().get(), aValue);
}
static void AddKeyedHistogram(jni::String::Param aName,
jni::String::Param aKey, int32_t aValue) {
MOZ_ASSERT(aName && aKey);
mozilla::Telemetry::Accumulate(aName->ToCString().get(), aKey->ToCString(),
aValue);
}
static void StartUISession(jni::String::Param aName, int64_t aTimestamp) {
MOZ_ASSERT(aName);
nsCOMPtr<nsIUITelemetryObserver> obs = GetObserver();
if (obs) {
obs->StartSession(aName->ToString().get(), aTimestamp);
}
}
static void StopUISession(jni::String::Param aName,
jni::String::Param aReason, int64_t aTimestamp) {
MOZ_ASSERT(aName);
nsCOMPtr<nsIUITelemetryObserver> obs = GetObserver();
if (obs) {
obs->StopSession(aName->ToString().get(),
aReason ? aReason->ToString().get() : nullptr,
aTimestamp);
}
}
static void AddUIEvent(jni::String::Param aAction, jni::String::Param aMethod,
int64_t aTimestamp, jni::String::Param aExtras) {
MOZ_ASSERT(aAction);
nsCOMPtr<nsIUITelemetryObserver> obs = GetObserver();
if (obs) {
obs->AddEvent(aAction->ToString().get(),
aMethod ? aMethod->ToString().get() : nullptr, aTimestamp,
aExtras ? aExtras->ToString().get() : nullptr);
}
}
};
} // namespace widget

View File

@ -11,24 +11,10 @@ interface nsIBrowserTab : nsISupports {
readonly attribute mozIDOMWindowProxy window;
};
[scriptable, uuid(08426a73-e70b-4680-9282-630932e2b2bb)]
interface nsIUITelemetryObserver : nsISupports {
void startSession(in wstring name,
in long long timestamp);
void stopSession(in wstring name,
in wstring reason,
in long long timestamp);
void addEvent(in wstring action,
in wstring method,
in long long timestamp,
in wstring extras);
};
[scriptable, uuid(0370450f-2e9c-4d16-b333-8ca6ce31a5ff)]
interface nsIAndroidBrowserApp : nsISupports {
readonly attribute nsIBrowserTab selectedTab;
nsIBrowserTab getBrowserTab(in int32_t tabId);
nsIUITelemetryObserver getUITelemetryObserver();
};
[scriptable, uuid(e64c39b8-b8ec-477d-aef5-89d517ff9219)]