Add TSF_SuspensionTrapped flag to NativeAOT for accurate sample profiler reporting#125764
Conversation
…ler reporting Implement TSF_SuspensionTrapped in the NativeAOT runtime to distinguish managed from external code in EventPipe sample profiler events, matching CoreCLR's TS_SuspensionTrapped behavior. The flag is set in WaitForGC before entering preemptive mode and cleared after the wait loop completes. All suspension paths (DisablePreemptiveMode, InlineSuspend, Redirect, hijack stubs) funnel through WaitForGC, ensuring complete coverage. Fixes dotnet#125217 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run runtime-nativeaot-outerloop |
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Implements a new NativeAOT thread-state flag (TSF_SuspensionTrapped) to let EventPipe SampleProfiler correctly label samples as Managed vs External while threads are trapped during suspension, aligning NativeAOT behavior with CoreCLR and re-enabling the previously skipped validation test.
Changes:
- Add
TSF_SuspensionTrappedthread-state flag and exposeThread::IsSuspensionTrapped(). - Set/clear the flag around
Thread::WaitForGCto mark threads trapped for suspension. - Use the flag in NativeAOT EventPipe sample-profiler payload classification and unskip the
SampleProfilerSampleTypetest for NativeAOT.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/tests/tracing/eventpipe/eventsvalidation/SampleProfilerSampleType.cs | Removes NativeAOT ActiveIssue skip so the SampleType validation runs on NativeAOT again. |
| src/coreclr/nativeaot/Runtime/thread.h | Adds TSF_SuspensionTrapped flag value and declares IsSuspensionTrapped(). |
| src/coreclr/nativeaot/Runtime/thread.inl | Adds inline IsSuspensionTrapped() implementation. |
| src/coreclr/nativeaot/Runtime/thread.cpp | Sets/clears TSF_SuspensionTrapped in WaitForGC. |
| src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp | Uses IsSuspensionTrapped() to set SampleProfiler sample type to Managed vs External. |
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR implements a NativeAOT equivalent of CoreCLR’s TS_SuspensionTrapped behavior to correctly classify EventPipe SampleProfiler ThreadSample events as Managed vs External, enabling accurate reporting and re-enabling the previously skipped validation test.
Changes:
- Add
TSF_SuspensionTrappedthread state flag and accessor in the NativeAOT runtime. - Set/clear
TSF_SuspensionTrappedaroundThread::WaitForGCso suspension/trap paths can be identified as originating from cooperative (managed) execution. - Update the NativeAOT EventPipe SampleProfiler payload to emit
MANAGEDwhen the target thread is suspension-trapped, and remove the NativeAOT ActiveIssue skip from the test.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/tests/tracing/eventpipe/eventsvalidation/SampleProfilerSampleType.cs | Removes NativeAOT skip so the test runs now that managed/external sample typing is fixed. |
| src/coreclr/nativeaot/Runtime/thread.h | Introduces TSF_SuspensionTrapped flag and declares IsSuspensionTrapped(). |
| src/coreclr/nativeaot/Runtime/thread.inl | Implements Thread::IsSuspensionTrapped() inline via IsStateSet. |
| src/coreclr/nativeaot/Runtime/thread.cpp | Sets TSF_SuspensionTrapped on entry to WaitForGC and clears it after the trap loop completes. |
| src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp | Uses IsSuspensionTrapped() to choose EP_SAMPLE_PROFILER_SAMPLE_TYPE_MANAGED vs EXTERNAL for samples. |
You can also share your feedback on Copilot code review. Take the survey.
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Implement TSF_SuspensionTrapped in the NativeAOT runtime to distinguish managed from external code in EventPipe sample profiler events, matching CoreCLR's TS_SuspensionTrapped behavior.
The flag is set in WaitForGC before entering preemptive mode and cleared after the wait loop completes. All suspension paths (DisablePreemptiveMode, InlineSuspend, Redirect, hijack stubs) funnel through WaitForGC, ensuring complete coverage.
Fixes #125217