From 8c285223e3fcd827e6c22bd88ffb4cb6ae934141 Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Wed, 20 Jul 2022 13:25:33 +0000 Subject: [PATCH] Bug 1657197 - Support enabling MOZ_LOG profilermarkers mirroring at runtime. r=mstange Differential Revision: https://phabricator.services.mozilla.com/D152166 --- toolkit/content/aboutNetworking.js | 7 +++++++ xpcom/base/LogModulePrefWatcher.cpp | 4 ++++ xpcom/base/Logging.cpp | 6 ++++++ xpcom/base/Logging.h | 6 ++++++ 4 files changed, 23 insertions(+) diff --git a/toolkit/content/aboutNetworking.js b/toolkit/content/aboutNetworking.js index 8cb51e630629..c2892b3c1bc3 100644 --- a/toolkit/content/aboutNetworking.js +++ b/toolkit/content/aboutNetworking.js @@ -378,6 +378,11 @@ function updateLogModules() { activeLogModules.push("sync"); } } catch (e) {} + try { + if (Services.prefs.getBoolPref("logging.config.profilermarkers")) { + activeLogModules.push("profilermarkers"); + } + } catch (e) {} let children = Services.prefs.getBranch("logging.").getChildList(""); @@ -444,6 +449,8 @@ function setLogModules() { // XXX: append is not yet supported. } else if (module == "sync") { Services.prefs.setBoolPref("logging.config.sync", true); + } else if (module == "profilermarkers") { + Services.prefs.setBoolPref("logging.config.profilermarkers", true); } else { let lastColon = module.lastIndexOf(":"); let key = module.slice(0, lastColon); diff --git a/xpcom/base/LogModulePrefWatcher.cpp b/xpcom/base/LogModulePrefWatcher.cpp index d2841c590aca..3aa19be2f2fc 100644 --- a/xpcom/base/LogModulePrefWatcher.cpp +++ b/xpcom/base/LogModulePrefWatcher.cpp @@ -23,6 +23,7 @@ static const char kLoggingPrefClearOnStartup[] = static const char kLoggingPrefLogFile[] = "logging.config.LOG_FILE"; static const char kLoggingPrefAddTimestamp[] = "logging.config.add_timestamp"; static const char kLoggingPrefSync[] = "logging.config.sync"; +static const char kLoggingPrefMarkers[] = "logging.config.profilermarkers"; namespace mozilla { @@ -82,6 +83,9 @@ static void LoadPrefValue(const char* aName) { } else if (prefName.EqualsLiteral(kLoggingPrefSync)) { bool sync = Preferences::GetBool(aName, false); LogModule::SetIsSync(sync); + } else if (prefName.EqualsLiteral(kLoggingPrefMarkers)) { + bool enableMarkers = Preferences::GetBool(aName, false); + LogModule::SetRecordMarkers(enableMarkers); } return; } diff --git a/xpcom/base/Logging.cpp b/xpcom/base/Logging.cpp index 2612173137cf..ba967c4e16d1 100644 --- a/xpcom/base/Logging.cpp +++ b/xpcom/base/Logging.cpp @@ -520,6 +520,8 @@ class LogModuleManager { void SetIsSync(bool aIsSync) { mIsSync = aIsSync; } + void SetRecordMarkers(bool aRecordMarkers) { mAddProfilerMarker = aRecordMarkers; } + void SetAddTimestamp(bool aAddTimestamp) { mAddTimestamp = aAddTimestamp; } detail::LogFile* OpenFile(bool aShouldAppend, uint32_t aFileNum, @@ -812,6 +814,10 @@ void LogModule::SetIsSync(bool aIsSync) { sLogModuleManager->SetIsSync(aIsSync); } +void LogModule::SetRecordMarkers(bool aRecordMarkers) { + sLogModuleManager->SetRecordMarkers(aRecordMarkers); +} + // This function is defined in gecko_logger/src/lib.rs // We mirror the level in rust code so we don't get forwarded all of the // rust logging and have to create an LogModule for each rust component. diff --git a/xpcom/base/Logging.h b/xpcom/base/Logging.h index c417bdbf770b..0a2653c7b75a 100644 --- a/xpcom/base/Logging.h +++ b/xpcom/base/Logging.h @@ -119,6 +119,12 @@ class LogModule { */ static void SetIsSync(bool aIsSync); + /** + * @param aRecordMarkers If we should add Firefox Profiler markers for each + * log entry. + */ + static void SetRecordMarkers(bool aRecordMarkers); + /** * Indicates whether or not the given log level is enabled. */