Bug 1268104 - Consolidate telemetry logging in UITelemetry.js. r=mcomella,gfritzsche
MozReview-Commit-ID: Hn2vOMJCSOb
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -845,16 +845,19 @@ pref("reader.color_scheme.values", "[\"d
// Whether to use a vertical or horizontal toolbar.
pref("reader.toolbar.vertical", false);
// Telemetry settings.
// Whether to use the unified telemetry behavior, requires a restart.
pref("toolkit.telemetry.unified", false);
+// Whether to enable UI telemetry logging
+pref("toolkit.telemetry.uiTelemetryLogging", true);
+
// Unified AccessibleCarets (touch-caret and selection-carets).
pref("layout.accessiblecaret.enabled", true);
// AccessibleCaret CSS for the Android L style assets.
pref("layout.accessiblecaret.width", "22.0");
pref("layout.accessiblecaret.height", "22.0");
pref("layout.accessiblecaret.margin-left", "-11.5");
--- a/mobile/android/base/java/org/mozilla/gecko/Telemetry.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Telemetry.java
@@ -115,31 +115,29 @@ public class Telemetry {
protected long now() {
return Telemetry.uptime();
}
}
public static void startUISession(final Session session, final String sessionNameSuffix) {
final String sessionName = getSessionName(session, sessionNameSuffix);
- Log.d(LOGTAG, "StartUISession: " + sessionName);
final GeckoEvent geckoEvent =
GeckoEvent.createTelemetryUISessionStartEvent(sessionName, realtime());
GeckoAppShell.sendEventToGecko(geckoEvent);
}
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);
final GeckoEvent geckoEvent = GeckoEvent.createTelemetryUISessionStopEvent(
sessionName, reason.toString(), realtime());
GeckoAppShell.sendEventToGecko(geckoEvent);
}
public static void stopUISession(final Session session, final Reason reason) {
stopUISession(session, null, reason);
}
@@ -164,21 +162,16 @@ public class Telemetry {
* @param method A non-null method (if null is desired, consider using Method.NONE)
*/
private 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 (!AppConstants.RELEASE_BUILD) {
- final String logString = "SendUIEvent: event = " + eventName + " method = " + method + " timestamp = " +
- timestamp + " extras = " + extras;
- Log.d(LOGTAG, logString);
- }
final GeckoEvent geckoEvent = GeckoEvent.createTelemetryUIEvent(
eventName, method.toString(), timestamp, extras);
GeckoAppShell.sendEventToGecko(geckoEvent);
}
public static void sendUIEvent(final Event event, final Method method, final long timestamp,
final String extras) {
sendUIEvent(event.toString(), method, timestamp, extras);
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -858,16 +858,18 @@ pref("toolkit.telemetry.server", "https:
pref("toolkit.telemetry.server_owner", "Mozilla");
// Information page about telemetry (temporary ; will be about:telemetry in the end)
pref("toolkit.telemetry.infoURL", "https://www.mozilla.org/legal/privacy/firefox.html#telemetry");
// Determines whether full SQL strings are returned when they might contain sensitive info
// i.e. dynamically constructed SQL strings or SQL executed by addons against addon DBs
pref("toolkit.telemetry.debugSlowSql", false);
// Whether to use the unified telemetry behavior, requires a restart.
pref("toolkit.telemetry.unified", true);
+// Whether to enable UI telemetry logging
+pref("toolkit.telemetry.uiTelemetryLogging", false);
// Identity module
pref("toolkit.identity.enabled", false);
pref("toolkit.identity.debug", false);
// AsyncShutdown delay before crashing in case of shutdown freeze
pref("toolkit.asyncshutdown.crash_timeout", 60000);
// Extra logging for AsyncShutdown barriers and phases
--- a/toolkit/components/telemetry/UITelemetry.jsm
+++ b/toolkit/components/telemetry/UITelemetry.jsm
@@ -3,73 +3,91 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const Cu = Components.utils;
const PREF_BRANCH = "toolkit.telemetry.";
const PREF_ENABLED = PREF_BRANCH + "enabled";
+const PREF_LOGGING_ENABLED = PREF_BRANCH + "uiTelemetryLogging";
this.EXPORTED_SYMBOLS = [
"UITelemetry",
];
Cu.import("resource://gre/modules/Services.jsm", this);
/**
* UITelemetry is a helper JSM used to record UI specific telemetry events.
*
* It implements nsIUITelemetryObserver, defined in nsIAndroidBridge.idl.
*/
this.UITelemetry = {
_enabled: undefined,
+ _loggingEnabled: undefined,
_activeSessions: {},
_measurements: [],
+ _log(msg) {
+ if (this._loggingEnabled) {
+ Services.console.logStringMessage("UITelemetry: " + msg);
+ }
+ },
+
// 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(PREF_ENABLED, this, false);
+ Services.prefs.addObserver(PREF_LOGGING_ENABLED, this, false);
Services.obs.addObserver(this, "profile-before-change", false);
// Pick up the current value.
try {
this._enabled = Services.prefs.getBoolPref(PREF_ENABLED);
+ this._loggingEnabled = Services.prefs.getBoolPref(PREF_LOGGING_ENABLED);
} catch (e) {
this._enabled = false;
+ this._loggingEnabled = false;
}
return this._enabled;
},
observe: function(aSubject, aTopic, aData) {
if (aTopic == "profile-before-change") {
Services.obs.removeObserver(this, "profile-before-change");
Services.prefs.removeObserver(PREF_ENABLED, this);
+ Services.prefs.removeObserver(PREF_LOGGING_ENABLED, this);
this._enabled = undefined;
+ this._loggingEnabled = undefined;
return;
}
if (aTopic == "nsPref:changed") {
switch (aData) {
- case PREF_ENABLED:
+ case PREF_ENABLED: {
let on = Services.prefs.getBoolPref(PREF_ENABLED);
this._enabled = on;
// Wipe ourselves if we were just disabled.
if (!on) {
this._activeSessions = {};
this._measurements = [];
}
break;
+ }
+ case PREF_LOGGING_ENABLED: {
+ this._loggingEnabled = Services.prefs.getBoolPref(PREF_LOGGING_ENABLED);
+ break;
+ }
}
}
},
/**
* This exists exclusively for testing -- our events are not intended to
* be retrieved via an XPCOM interface.
*/
@@ -102,16 +120,18 @@ this.UITelemetry = {
*
* All extant sessions will be recorded by name for each event.
*/
addEvent: function(aAction, aMethod, aTimestamp, aExtras) {
if (!this.enabled) {
return;
}
+ this._log(`addEvent: action = ${aAction}, method = ${aMethod}, timestamp = ${aTimestamp}, extras = ${aExtras}`);
+
let sessions = Object.keys(this._activeSessions);
let aEvent = {
type: "event",
action: aAction,
method: aMethod,
sessions: sessions,
timestamp: (aTimestamp == undefined) ? this.uptimeMillis() : aTimestamp,
};
@@ -126,31 +146,35 @@ this.UITelemetry = {
/**
* Begins tracking a session by storing a timestamp for session start.
*/
startSession: function(aName, aTimestamp) {
if (!this.enabled) {
return;
}
+ this._log(`startSession: ${aName}`);
+
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: function(aName, aReason, aTimestamp) {
if (!this.enabled) {
return;
}
+ this._log(`stopSession: ${aName}`);
+
let sessionStart = this._activeSessions[aName];
delete this._activeSessions[aName];
if (!sessionStart) {
return;
}
let aEvent = {