Skip to content

Commit 8ff3668

Browse files
authored
[Startup] Bump PerfMap ahead of DiagnosticServer (#123226)
Fixes #122472 From some inspection, it looks like `PerfMap::Initialize` does not depend on the methods right above it. ``` #ifdef FEATURE_PERFTRACING DiagnosticServerAdapter::Initialize(); DiagnosticServerAdapter::PauseForDiagnosticsMonitor(); #endif // FEATURE_PERFTRACING #ifdef FEATURE_GDBJIT // Initialize gdbjit NotifyGdb::Initialize(); #endif // FEATURE_GDBJIT #ifdef FEATURE_EVENT_TRACE // Initialize event tracing early so we can trace CLR startup time events. InitializeEventTracing(); // Fire the EE startup ETW event ETWFireEvent(EEStartupStart_V1); #endif // FEATURE_EVENT_TRACE InitGSCookie(); #ifdef LOGGING InitializeLogging() #endif ``` `PerfMap::Initialize` depends on `SString::Startup()` which occurs earlier in startup and some PAL/OS services. Instead of adding more logic to handle a racing DiagnosticServer IPC [`EnablePerfMap` command](https://github.com/dotnet/diagnostics/blob/main/documentation/design-docs/ipc-protocol.md#enableperfmap) and `PerfMap::Initialize` (e.g. lazy-init/queued commands), bump the PerfMap initialization ahead of the DiagnosticServer initialization. The DiagnosticServer also doesn't depend on PerfMap being initialized afterwards, and PerfMap's `CrstStatic` and `PerfMap::Enable(type, sendExisting)` suggests that the IPC enable perfmap command should occur after `PerfMap::Initialize`. This way, DiagnosticServer is still early in startup, and its `PerfMap::Enable` will not crash the runtime. As for the IPC command to set environment variables, it is unlikely that it was used to `DOTNET_PerfMapEnabled` because that would either not have applied early enough or have crashed the runtime like in the issue. Instead, the `EnablePerfMap`/`DisablePerfMap` commands should be used to toggle PerfMap status.
1 parent d37862b commit 8ff3668

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/coreclr/vm/ceemain.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,10 @@ void EEStartupHelper()
706706
}
707707
#endif
708708

709+
#ifdef FEATURE_PERFMAP
710+
PerfMap::Initialize();
711+
#endif
712+
709713
#ifdef FEATURE_PERFTRACING
710714
DiagnosticServerAdapter::Initialize();
711715
DiagnosticServerAdapter::PauseForDiagnosticsMonitor();
@@ -731,7 +735,6 @@ void EEStartupHelper()
731735
#endif
732736

733737
#ifdef FEATURE_PERFMAP
734-
PerfMap::Initialize();
735738
InitThreadManagerPerfMapData();
736739
#endif
737740

0 commit comments

Comments
 (0)