tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit b9c976f8352afd38ed02994dc8128572b6d99587
parent 277143444995b7e65f9222e5eff8f6ea3fba7516
Author: Alexandre Poirot <poirot.alex@gmail.com>
Date:   Tue, 18 Nov 2025 10:02:51 +0000

Bug 1994951 - [devtools] Toggle console and PageMessages MOZ_LOG when using the Web Compat profiler preset. r=canaltinova,profiler-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D269242

Diffstat:
Mdevtools/client/performance-new/@types/perf.d.ts | 2++
Mdevtools/client/performance-new/shared/background.sys.mjs | 56+++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mdevtools/shared/performance-new/prefs-presets.sys.mjs | 2++
3 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/devtools/client/performance-new/@types/perf.d.ts b/devtools/client/performance-new/@types/perf.d.ts @@ -203,6 +203,7 @@ export interface RecordingSettings { objdirs: string[]; // The duration is currently not wired up to the UI yet. See Bug 1587165. duration?: number; + mozLogs?: string; } /** @@ -447,6 +448,7 @@ export interface PresetDefinition { threads: string[]; duration: number; profilerViewMode?: ProfilerViewMode; + mozLogs?: string; l10nIds: { popup: { label: string; diff --git a/devtools/client/performance-new/shared/background.sys.mjs b/devtools/client/performance-new/shared/background.sys.mjs @@ -89,6 +89,9 @@ const lazy = createLazyLoaders({ .PlacesUtils, }); +/** @type {{[key:string]: number} | null} */ +let gPreviousMozLogValues = null; + /** * This function is called when the profile is captured with the shortcut keys, * with the profiler toolbarbutton, with the button inside the popup, or with @@ -110,6 +113,7 @@ export async function captureProfile(pageContext) { const { profileCaptureResult, additionalInformation } = await lazy .RecordingUtils() .getProfileDataAsGzippedArrayBufferThenStop(); + cleanupMozLogs(); const profilerViewMode = lazy .PrefsPresets() .getProfilerViewModeForCurrentPreset(pageContext); @@ -142,7 +146,7 @@ export async function captureProfile(pageContext) { * @param {PageContext} pageContext */ export function startProfiler(pageContext) { - const { entries, interval, features, threads, duration } = lazy + const { entries, interval, features, threads, mozLogs, duration } = lazy .PrefsPresets() .getRecordingSettings(pageContext, Services.profiler.GetFeatures()); @@ -150,6 +154,10 @@ export function startProfiler(pageContext) { const { getActiveBrowserID } = lazy.RecordingUtils(); const activeTabID = getActiveBrowserID(); + if (typeof mozLogs == "string") { + updateMozLogs(mozLogs); + } + Services.profiler.StartProfiler( entries, interval, @@ -161,6 +169,31 @@ export function startProfiler(pageContext) { } /** + * Given a MOZ_LOG string, toggles the expected preferences to enable the + * LogModules mentioned in the string at the expected level of logging. + * This will also record preference values in order to reset them on stop. + * `mozLogs` is a string similar to the one passed as MOZ_LOG env variable. + * + * @param {string} mozLogs + */ +function updateMozLogs(mozLogs) { + gPreviousMozLogValues = {}; + for (const module of mozLogs.split(",")) { + const lastColon = module.lastIndexOf(":"); + const logName = module.slice(0, lastColon).trim(); + const value = parseInt(module.slice(lastColon + 1).trim(), 10); + const prefName = `logging.${logName}`; + gPreviousMozLogValues[prefName] = Services.prefs.getIntPref( + prefName, + undefined + ); + // MOZ_LOG aren't profiler specific and enabled globally in Firefox. + // Preferences are the easiest (only?) way to toggle them from JavaScript. + Services.prefs.setIntPref(prefName, value); + } +} + +/** * This function is called directly by devtools/startup/DevToolsStartup.jsm when * using the shortcut keys to capture a profile. * @@ -168,6 +201,27 @@ export function startProfiler(pageContext) { */ export function stopProfiler() { Services.profiler.StopProfiler(); + + cleanupMozLogs(); +} + +/** + * This function should be called when we are done profiler in order to reset + * the MOZ_LOG enabled while profiling. + * + * @type {() => void} + */ +export function cleanupMozLogs() { + if (gPreviousMozLogValues) { + for (const [prefName, value] of Object.entries(gPreviousMozLogValues)) { + if (typeof value == "number") { + Services.prefs.setIntPref(prefName, value); + } else { + Services.prefs.clearUserPref(prefName); + } + } + gPreviousMozLogValues = null; + } } /** diff --git a/devtools/shared/performance-new/prefs-presets.sys.mjs b/devtools/shared/performance-new/prefs-presets.sys.mjs @@ -298,6 +298,7 @@ export const presets = { interval: 1, features: ["screenshots", "js", "stackwalk", "nostacksampling", "tracing"], threads: ["GeckoMain", "DOM Worker"], + mozLogs: "console: 5, PageMessages: 5", duration: 0, profilerViewMode: "active-tab", l10nIds: { @@ -539,6 +540,7 @@ export function getRecordingSettingsFromPreset( supportedFeatures.includes(feature) ), threads: preset.threads, + mozLogs: preset.mozLogs, objdirs, duration: preset.duration, };