Add configurable EventPipe CPU sampling rate via DOTNET_EventPipeCpuSamplingRate#127292
Draft
pavelsavara wants to merge 4 commits intodotnet:mainfrom
Draft
Add configurable EventPipe CPU sampling rate via DOTNET_EventPipeCpuSamplingRate#127292pavelsavara wants to merge 4 commits intodotnet:mainfrom
DOTNET_EventPipeCpuSamplingRate#127292pavelsavara wants to merge 4 commits intodotnet:mainfrom
Conversation
Contributor
|
Tagging subscribers to this area: @steveisok, @dotnet/area-system-diagnostics |
Contributor
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. |
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>
This was referenced Apr 23, 2026
Open
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.
Summary
This change introduces a new
DOTNET_EventPipeCpuSamplingRateenvironment 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_EventPipeCpuSamplingRatesrc/coreclr/inc/clrconfigvalues.h— Register the newINTERNAL_EventPipeCpuSamplingRateDWORD 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_EventPipeCpuSamplingRate").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_EventPipeCpuSamplingRate.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.