Bug 1645862: Part 1 - Split TelemetryController into parent and content modules. r=chutten

Most of TelemetryController is only used in the parent process, but is
currently loaded in all processes, where it needlessly consumes tens of KB of
memory. This patch splits the parent- and content-specific parts, and only
loads each in the processes where they're needed.

Differential Revision: https://phabricator.services.mozilla.com/D79870
This commit is contained in:
Kris Maglione 2020-06-24 17:33:49 +00:00
Родитель 16ae869cfe
Коммит 977f86fb80
7 изменённых файлов: 1600 добавлений и 1473 удалений

Просмотреть файл

@ -26,9 +26,7 @@ const known_scripts = {
// General utilities
"resource://gre/modules/AppConstants.jsm",
"resource://gre/modules/AsyncShutdown.jsm",
"resource://gre/modules/DeferredTask.jsm",
"resource://gre/modules/PromiseUtils.jsm",
"resource://gre/modules/Services.jsm", // bug 1464542
"resource://gre/modules/Timer.jsm",
"resource://gre/modules/XPCOMUtils.jsm",
@ -51,6 +49,8 @@ const known_scripts = {
// Telemetry
"resource://gre/modules/TelemetryController.jsm", // bug 1470339
"resource://gre/modules/TelemetryControllerBase.jsm", // bug 1470339
"resource://gre/modules/TelemetryControllerContent.jsm", // bug 1470339
"resource://gre/modules/TelemetryUtils.jsm", // bug 1470339
// Extensions

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,109 @@
/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */
/* 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 = ["TelemetryControllerBase"];
const { Log } = ChromeUtils.import("resource://gre/modules/Log.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { TelemetryUtils } = ChromeUtils.import(
"resource://gre/modules/TelemetryUtils.jsm"
);
const LOGGER_NAME = "Toolkit.Telemetry";
const LOGGER_PREFIX = "TelemetryController::";
const PREF_BRANCH_LOG = "toolkit.telemetry.log.";
/**
* Setup Telemetry logging. This function also gets called when loggin related
* preferences change.
*/
var gLogger = null;
var gLogAppenderDump = null;
var TelemetryControllerBase = Object.freeze({
// Whether the FHR/Telemetry unification features are enabled.
// Changing this pref requires a restart.
IS_UNIFIED_TELEMETRY: Services.prefs.getBoolPref(
TelemetryUtils.Preferences.Unified,
false
),
get log() {
return (
gLogger ||
Log.repository.getLoggerWithMessagePrefix(LOGGER_NAME, LOGGER_PREFIX)
);
},
configureLogging() {
if (!gLogger) {
gLogger = Log.repository.getLoggerWithMessagePrefix(
LOGGER_NAME,
LOGGER_PREFIX
);
// Log messages need to go to the browser console.
let consoleAppender = new Log.ConsoleAppender(new Log.BasicFormatter());
gLogger.addAppender(consoleAppender);
Services.prefs.addObserver(PREF_BRANCH_LOG, this.configureLogging);
}
// Make sure the logger keeps up with the logging level preference.
gLogger.level =
Log.Level[
Services.prefs.getStringPref(
TelemetryUtils.Preferences.LogLevel,
"Warn"
)
];
// If enabled in the preferences, add a dump appender.
let logDumping = Services.prefs.getBoolPref(
TelemetryUtils.Preferences.LogDump,
false
);
if (logDumping != !!gLogAppenderDump) {
if (logDumping) {
gLogAppenderDump = new Log.DumpAppender(new Log.BasicFormatter());
gLogger.addAppender(gLogAppenderDump);
} else {
gLogger.removeAppender(gLogAppenderDump);
gLogAppenderDump = null;
}
}
},
/**
* Perform telemetry initialization for either chrome or content process.
* @return {Boolean} True if Telemetry is allowed to record at least base (FHR) data,
* false otherwise.
*/
enableTelemetryRecording: function enableTelemetryRecording() {
// Configure base Telemetry recording.
// Unified Telemetry makes it opt-out. If extended Telemetry is enabled, base recording
// is always on as well.
if (this.IS_UNIFIED_TELEMETRY) {
TelemetryUtils.setTelemetryRecordingFlags();
} else {
// We're not on unified Telemetry, stick to the old behaviour for
// supporting Fennec.
Services.telemetry.canRecordBase = Services.telemetry.canRecordExtended =
TelemetryUtils.isTelemetryEnabled;
}
this.log.config(
"enableTelemetryRecording - canRecordBase:" +
Services.telemetry.canRecordBase +
", canRecordExtended: " +
Services.telemetry.canRecordExtended
);
return Services.telemetry.canRecordBase;
},
});

Просмотреть файл

@ -0,0 +1,101 @@
/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */
/* 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";
const { DeferredTask } = ChromeUtils.import(
"resource://gre/modules/DeferredTask.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { TelemetryControllerBase } = ChromeUtils.import(
"resource://gre/modules/TelemetryControllerBase.jsm"
);
// Delay before intializing telemetry (ms)
const TELEMETRY_DELAY =
Services.prefs.getIntPref("toolkit.telemetry.initDelay", 60) * 1000;
// Delay before initializing telemetry if we're testing (ms)
const TELEMETRY_TEST_DELAY = 1;
var EXPORTED_SYMBOLS = ["TelemetryController"];
var TelemetryController = Object.freeze({
/**
* Used only for testing purposes.
*/
testInitLogging() {
TelemetryControllerBase.configureLogging();
},
/**
* Used only for testing purposes.
*/
testSetupContent() {
return Impl.setupContentTelemetry(true);
},
/**
* Send a notification.
*/
observe(aSubject, aTopic, aData) {
return Impl.observe(aSubject, aTopic, aData);
},
});
var Impl = {
// This is true when running in the test infrastructure.
_testMode: false,
get _log() {
return TelemetryControllerBase.log;
},
/**
* This triggers basic telemetry initialization for content processes.
* @param {Boolean} [testing=false] True if we are in test mode, false otherwise.
*/
setupContentTelemetry(testing = false) {
this._testMode = testing;
// The thumbnail service also runs in a content process, even with e10s off.
// We need to check if e10s is on so we don't submit child payloads for it.
// We still need xpcshell child tests to work, so we skip this if test mode is enabled.
if (testing || Services.appinfo.browserTabsRemoteAutostart) {
// We call |enableTelemetryRecording| here to make sure that Telemetry.canRecord* flags
// are in sync between chrome and content processes.
if (!TelemetryControllerBase.enableTelemetryRecording()) {
this._log.trace(
"setupContentTelemetry - Content process recording disabled."
);
return;
}
}
Services.telemetry.earlyInit();
// FIXME: This is a terrible abuse of DeferredTask.
let delayedTask = new DeferredTask(
() => {
Services.telemetry.delayedInit();
},
testing ? TELEMETRY_TEST_DELAY : TELEMETRY_DELAY,
testing ? 0 : undefined
);
delayedTask.arm();
},
/**
* This observer drives telemetry.
*/
observe(aSubject, aTopic, aData) {
if (aTopic == "app-startup") {
TelemetryControllerBase.configureLogging();
this._log.trace(`observe - ${aTopic} notified.`);
this.setupContentTelemetry();
}
},
};

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -104,6 +104,9 @@ EXTRA_JS_MODULES += [
'app/ClientID.jsm',
'app/TelemetryArchive.jsm',
'app/TelemetryController.jsm',
'app/TelemetryControllerBase.jsm',
'app/TelemetryControllerContent.jsm',
'app/TelemetryControllerParent.jsm',
'app/TelemetryEnvironment.jsm',
'app/TelemetryReportingPolicy.jsm',
'app/TelemetryScheduler.jsm',

Просмотреть файл

@ -351,7 +351,10 @@ function fakeNow(...args) {
const modules = [
ChromeUtils.import("resource://gre/modules/TelemetrySession.jsm", null),
ChromeUtils.import("resource://gre/modules/TelemetryEnvironment.jsm", null),
ChromeUtils.import("resource://gre/modules/TelemetryController.jsm", null),
ChromeUtils.import(
"resource://gre/modules/TelemetryControllerParent.jsm",
null
),
ChromeUtils.import("resource://gre/modules/TelemetryStorage.jsm", null),
ChromeUtils.import("resource://gre/modules/TelemetrySend.jsm", null),
ChromeUtils.import(
@ -398,7 +401,7 @@ function fakeMidnightPingFuzzingDelay(delayMs) {
function fakeGeneratePingId(func) {
let module = ChromeUtils.import(
"resource://gre/modules/TelemetryController.jsm",
"resource://gre/modules/TelemetryControllerParent.jsm",
null
);
module.Policy.generatePingId = func;
@ -406,7 +409,7 @@ function fakeGeneratePingId(func) {
function fakeCachedClientId(uuid) {
let module = ChromeUtils.import(
"resource://gre/modules/TelemetryController.jsm",
"resource://gre/modules/TelemetryControllerParent.jsm",
null
);
module.Policy.getCachedClientID = () => uuid;