From 97dfb547ef3a86c0db0322e24e3272a501974bdb Mon Sep 17 00:00:00 2001 From: Bob Owen Date: Fri, 7 Feb 2025 20:23:56 +0000 Subject: [PATCH] Bug 1943586: Don't collect information in profiler_shutdown when we won't use it. a=dmeehan Original Revision: https://phabricator.services.mozilla.com/D236346 Differential Revision: https://phabricator.services.mozilla.com/D237235 --- tools/profiler/core/platform.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/profiler/core/platform.cpp b/tools/profiler/core/platform.cpp index d5b137929756..ca861b262a2f 100644 --- a/tools/profiler/core/platform.cpp +++ b/tools/profiler/core/platform.cpp @@ -5889,8 +5889,13 @@ void profiler_shutdown(IsFastShutdown aIsFastShutdown) { } invoke_profiler_state_change_callbacks(ProfilingState::ShuttingDown); - const auto preRecordedMetaInformation = - PreRecordMetaInformation(/* aShutdown = */ true); + // We collect information here to be used below so it can be done outside of + // the lock. We only need it if MOZ_PROFILER_SHUTDOWN is set and not empty. + const char* filename = getenv("MOZ_PROFILER_SHUTDOWN"); + PreRecordedMetaInformation preRecordedMetaInformation = {}; + if (filename && filename[0] != '\0') { + preRecordedMetaInformation = PreRecordMetaInformation(/* aShutdown */ true); + } ProfilerParent::ProfilerWillStopIfStarted(); @@ -5902,7 +5907,6 @@ void profiler_shutdown(IsFastShutdown aIsFastShutdown) { // Save the profile on shutdown if requested. if (ActivePS::Exists(lock)) { - const char* filename = getenv("MOZ_PROFILER_SHUTDOWN"); if (filename && filename[0] != '\0') { locked_profiler_save_profile_to_file(lock, filename, preRecordedMetaInformation,