[release/10.0] Fix SampleType field in ThreadSample event from Sample Profiler#124084
Merged
steveisok merged 1 commit intodotnet:release/10.0from Feb 6, 2026
Merged
[release/10.0] Fix SampleType field in ThreadSample event from Sample Profiler#124084steveisok merged 1 commit intodotnet:release/10.0from
steveisok merged 1 commit intodotnet:release/10.0from
Conversation
…Profiler Backport of dotnet#124019 to release/10.0 ## Customer Impact - [X] Customer reported - [ ] Found internally The SampleType field in ThreadSample events from SampleProfiler was always reporting EP_SAMPLE_PROFILER_SAMPLE_TYPE_EXTERNAL even when threads were executing managed code. This causes incorrect profiling data for customers using diagnostics tools that rely on this event. Fixes dotnet#123996 ## Regression - [X] Yes - [ ] No This regressed in .NET 9 when SuspendAllThreads was ported from NativeAOT to CoreCLR (commit 00a8973). ## Testing The fix was verified by building CoreCLR with Debug/Checked configuration which validates the asmconstants offsets via compile-time assertions. ## Risk Low The change is minimal and self-contained: - Adds a new thread state flag (TS_SuspensionTrapped) using a previously unused bit - Sets/clears the flag in RareDisablePreemptiveGC when threads voluntarily suspend - Uses the flag instead of the removed m_gcModeOnSuspension field for sample type detection - The change is pay-for-play: only threads that were actually executing managed code participate
Contributor
There was a problem hiding this comment.
Pull request overview
This PR is a backport of #124019 to the release/10.0 branch, fixing a regression in the SampleProfiler's ThreadSample event. In .NET 9+, the SampleType field incorrectly reported all samples as EP_SAMPLE_PROFILER_SAMPLE_TYPE_EXTERNAL instead of properly distinguishing managed code execution (EP_SAMPLE_PROFILER_SAMPLE_TYPE_MANAGED). The regression occurred when SuspendAllThreads was ported from NativeAOT to CoreCLR in commit 00a8973.
Changes:
- Introduces a new thread state flag
TS_SuspensionTrappedto track when threads voluntarily suspend while in managed (cooperative) mode - Removes the obsolete
m_gcModeOnSuspensionfield and related methods from the Thread class - Updates assembly offset constants for ARM64 and AMD64 platforms to reflect the reduced Thread structure size
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/coreclr/vm/threads.h | Adds TS_SuspensionTrapped flag using previously unused bit 0x00000002; removes m_gcModeOnSuspension field and its accessor methods |
| src/coreclr/vm/threadsuspend.cpp | Sets TS_SuspensionTrapped when thread traps for suspension in cooperative mode; clears flag on resume |
| src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.cpp | Uses HasThreadState(TS_SuspensionTrapped) to determine sample type instead of deleted GetGCModeOnSuspension() |
| src/coreclr/vm/arm64/asmconstants.h | Adjusts m_pInterpThreadContext offset down by 8 bytes (0xb78→0xb70 Unix, 0xba0→0xb98 non-Unix) due to removed field |
| src/coreclr/vm/amd64/asmconstants.h | Adjusts m_pInterpThreadContext offset down by 8 bytes (0xb50→0xb48 Unix, 0xba8→0xba0 non-Unix) due to removed field |
jkotas
approved these changes
Feb 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #124019 to release/10.0
Customer Impact
The SampleType field in ThreadSample events from SampleProfiler was always reporting EP_SAMPLE_PROFILER_SAMPLE_TYPE_EXTERNAL even when threads were executing managed code. This causes incorrect profiling data for customers using diagnostics tools that rely on this event.
Fixes #123996
Regression
This regressed in .NET 9 when SuspendAllThreads was ported from NativeAOT to CoreCLR (commit 00a8973).
Testing
Manual
Risk
Low
The change is minimal and self-contained: