[release/10.0] Configurable EventPipe CPU sampling rate#128843
[release/10.0] Configurable EventPipe CPU sampling rate#128843steveisok wants to merge 2 commits into
Conversation
Add configurable EventPipe CPU sampling rate via DOTNET_EventPipeThreadSamplingRate for CoreCLR and NativeAOT. This is a partial backport of dotnet#127292 (4e8ab2d) including: - src/coreclr/inc/clrconfigvalues.h: register INTERNAL_EventPipeThreadSamplingRate - src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h: CoreCLR implementation + PROFILING_SUPPORTED guard fix on ep_rt_notify_profiler_provider_created - src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h: NativeAOT implementation - src/native/eventpipe/ep-rt.h: shared declaration - src/native/eventpipe/ep.c: consume configured rate in ep_init - src/mono/mono/eventpipe/ep-rt-mono.h: minimal stub so Mono build of ep.c stays green Excluded from this backport: Browser/WASM build integration (WasmApp.InTree.props, Microsoft.NET.Sdk.WebAssembly.Browser.targets), ep-rt-mono-runtime-provider.c cleanup, ds-ipc-pal-websocket.h browser fixes, and the ep-session.c assert. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
I need to change the PR description to the typical backport template |
There was a problem hiding this comment.
Pull request overview
This PR backports the CoreCLR/NativeAOT portion of #127292 onto release/10.0, adding a DOTNET_EventPipeThreadSamplingRate configuration knob so the EventPipe CPU sample profiler interval can be overridden from the default (1ms).
Changes:
- Adds a new CoreCLR config value (
INTERNAL_EventPipeThreadSamplingRate) and runtime-specific implementations to read the sampling interval (ms). - Updates EventPipe initialization to apply the configured sampling rate (ms → ns), falling back to platform defaults when unset/0.
- Includes a small CoreCLR
PROFILING_SUPPORTEDguard adjustment forep_rt_notify_profiler_provider_created, plus a Mono stub implementation to keep shared native EventPipe code building.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/inc/clrconfigvalues.h | Registers INTERNAL_EventPipeThreadSamplingRate CoreCLR knob (ms, 0 = default). |
| src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h | Implements CoreCLR getter via CLRConfig and adjusts profiler-provider notification guard. |
| src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h | Implements NativeAOT getter via RhConfig::Environment::TryGetIntegerValue (decimal). |
| src/native/eventpipe/ep-rt.h | Declares ep_rt_config_value_get_sampling_rate() in the shared runtime abstraction. |
| src/native/eventpipe/ep.c | Reads the configured sampling rate in ep_init and applies it (ms → ns). |
| src/mono/mono/eventpipe/ep-rt-mono.h | Adds a Mono implementation reading DOTNET_/COMPlus_EventPipeThreadSamplingRate for build compatibility. |
|
It would be good to test it on Net11 on non-wasm OS before we backport it. |
Adds a CoreCLR runtime test under src/tests/tracing/eventpipe/samplingrate
that verifies the new DOTNET_EventPipeThreadSamplingRate config knob actually
changes the EventPipe CPU sample profiler interval.
Design:
- Two-process: parent spawns a child with DOTNET_EventPipeThreadSamplingRate=50
set in the child process environment (the runtime reads the value in ep_init
during startup, so it must be set before the .NET process launches).
- Child runs IpcTraceTest.RunAndValidateEventCounts against itself, subscribes
to Microsoft-DotNETCore-SampleProfiler, burns CPU for ~3 seconds, then
inspects ThreadSample events.
- Validation on the busiest sampled thread:
* count >= 30 (sanity: sampling actually happened)
* count <= 600 (rejects the default ~1ms rate which produces ~1500/3s)
* median inter-sample interval >= 20ms (rejects the default ~1ms rate)
Verified locally on osx-arm64:
with env var: 36 samples/thread, median 85ms -> PASS
without env var: 1573 samples/thread -> FAIL (correct rejection)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Note This comment was authored with assistance from GitHub Copilot. Added a regression test in 8277aea covering the new Test: Design — two-process, same binary:
Local verification on osx-arm64:
This is intended to be upstreamed to |
Note
This pull request was prepared with assistance from GitHub Copilot.
Backport of the CoreCLR / NativeAOT portion of #127292 to
release/10.0.Customer Impact
Cosmic has reported dramatic overhead when trying to enable the sample profiler due to our default sampling rate being too high. They saw this change land in main and requested we backport to 10 so that they can override to a lower sampling rate.
Regression
Testing
Added a functional test to change the default sampling rate and make sure it lines up with what was expected.
Risk
Low - this only activates with the
DOTNET_EventPipeThreadSamplingRateenvironment variable.