Uh oh!
There was an error while loading. Please reload this page.
Add configurable EventPipe CPU sampling rate via DOTNET_EventPipeThreadSamplingRate - #127292
Conversation
Tagging subscribers to this area: @steveisok, @dotnet/area-system-diagnostics |
There was a problem hiding this comment.
Pull request overview
Adds a new runtime-configurable knob (DOTNET_EventPipeCpuSamplingRate) to override EventPipe CPU sample-profiler interval (intended to allow slower sampling on WASM/browser), and wires it through CoreCLR/NativeAOT/Mono plus browser WASM build plumbing.
Changes:
- Introduce
EventPipeCpuSamplingRateconfig/env var and consume it in EventPipe init (ms → ns conversion, 0 = default). - Implement
ep_rt_config_value_get_sampling_rate()for CoreCLR, NativeAOT, and Mono runtime layers. - Update browser WASM SDK targets to pass
DOTNET_EventPipeCpuSamplingRate(and related instrumentation env vars) and adjust websocket interop declarations.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/native/eventpipe/ep.c | Reads configurable sampling interval and applies it during ep_init(). |
| src/native/eventpipe/ep-session.c | Adds an assert in the no-threads streaming loop shutdown path. |
| src/native/eventpipe/ep-rt.h | Adds runtime abstraction API for sampling-rate config retrieval. |
| src/native/eventpipe/ds-ipc-pal-websocket.h | Adjusts websocket externs for C++/interop and fixes recv buffer constness. |
| src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets | Adds EnableDiagnostics gating and parses WasmPerformanceInstrumentation for optional interval. |
| src/mono/mono/eventpipe/ep-rt-mono.h | Mono implementation of sampling-rate config getter via env var. |
| src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h | CoreCLR implementation of sampling-rate config getter; minor preprocessor cleanup. |
| src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h | NativeAOT implementation of sampling-rate config getter. |
| src/coreclr/inc/clrconfigvalues.h | Registers new CoreCLR config knob INTERNAL_EventPipeCpuSamplingRate. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…oft.NET.Sdk.WebAssembly.Browser.targets Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jkotas
commented
Apr 24, 2026
noahfalk
left a comment
There was a problem hiding this comment.
Looks good to me modulo comments inline.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
DOTNET_EventPipeCpuSamplingRateDOTNET_EventPipeThreadSamplingRate
Summary
This change introduces a new
DOTNET_EventPipeThreadSamplingRateenvironment variable that allows overriding the default EventPipe CPU sample profiler interval.The default 1ms is too quick for WASM/browser.
This split from #126324 for smaller code review.
Changes
New config:
DOTNET_EventPipeThreadSamplingRatesrc/coreclr/inc/clrconfigvalues.h— Register the newINTERNAL_EventPipeThreadSamplingRateDWORD config (default 0).src/native/eventpipe/ep-rt.h— Declareep_rt_config_value_get_sampling_rate()in the shared EventPipe runtime abstraction header.src/native/eventpipe/ep.c— Inep_init(), read the configured rate and convert from milliseconds to nanoseconds. Falls back to the per-platform default when the value is 0.Per-runtime implementations of
ep_rt_config_value_get_sampling_ratesrc/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h— CoreCLR: reads viaCLRConfig::GetConfigValue.src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h— NativeAOT: reads viaRhConfig::Environment::TryGetIntegerValue.src/mono/mono/eventpipe/ep-rt-mono.h— Mono: reads viag_getenv("DOTNET_EventPipeThreadSamplingRate").Blazor/Browser WASM build integration
src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets_AddWasmDiagnosticPortsEnvironmentVariabletarget onEnableDiagnostics=true.WasmPerformanceInstrumentationto extract an optional,interval=<ms>suffix.DOTNET_WasmPerformanceInstrumentationand the interval (if present) asDOTNET_EventPipeThreadSamplingRate.Miscellaneous fixes
src/native/eventpipe/ds-ipc-pal-websocket.hextern "C"to prevent C++ name mangling (needed for JS interop in browser WASM).ds_rt_websocket_recvsignature: remove incorrectconstfrom the receive buffer parameter.src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.hPROFILING_SUPPORTEDpreprocessor guard aroundep_rt_notify_profiler_provider_createdbody.#endifcomments for clarity.src/native/eventpipe/ep-session.cEP_ASSERT(session->buffer_manager != NULL)invariant check in the streaming loop shutdown path.