[release/10.0] Backport CoreCLR portion of #127292: configurable EventPipe CPU sampling rate#128843
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.Adds
DOTNET_EventPipeThreadSamplingRateconfig so the EventPipe CPU sample profiler interval can be overridden from the default. Useful for diagnostic scenarios where the default 1ms interval is too aggressive.Files included (6)
src/coreclr/inc/clrconfigvalues.h— registerINTERNAL_EventPipeThreadSamplingRatesrc/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h— CoreCLR implementation reading viaCLRConfig::GetConfigValue. Also picks up the smallPROFILING_SUPPORTEDguard fix onep_rt_notify_profiler_provider_createdthat was bundled in the original PR.src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h— NativeAOT implementation reading viaRhConfig::Environment::TryGetIntegerValue.src/native/eventpipe/ep-rt.h— shared declaration ofep_rt_config_value_get_sampling_rate.src/native/eventpipe/ep.c—ep_initreads the configured rate (ms) and converts to ns, falling back to the per-platform default when 0.src/mono/mono/eventpipe/ep-rt-mono.h— minimal Mono implementation so the sharedep.ccontinues to compile for Mono. Without this stub the Mono build would break.Excluded from this backport
The Browser/WASM-specific pieces from #127292 are intentionally omitted:
src/mono/browser/build/WasmApp.InTree.propssrc/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targetssrc/mono/mono/eventpipe/ep-rt-mono-runtime-provider.ccleanupsrc/native/eventpipe/ds-ipc-pal-websocket.hbrowser-onlyextern "C"/ signature fixsrc/native/eventpipe/ep-session.cassert tidy-upValidation
Built locally on osx-arm64:
./build.sh -s clr.runtime+clr.nativeaotruntime -c Release→ succeeded, 0 warnings, 0 errors./build.sh -s mono.runtime -c Release→ succeeded, 0 warnings, 0 errorsOriginal PR
#127292 — Add configurable EventPipe CPU sampling rate via
DOTNET_EventPipeThreadSamplingRateby @pavelsavara, merged tomainas 4e8ab2d.