Skip to content

Add configurable EventPipe CPU sampling rate via DOTNET_EventPipeCpuSamplingRate#127292

Draft
pavelsavara wants to merge 4 commits intodotnet:mainfrom
pavelsavara:browser_EP_sample_rate
Draft

Add configurable EventPipe CPU sampling rate via DOTNET_EventPipeCpuSamplingRate#127292
pavelsavara wants to merge 4 commits intodotnet:mainfrom
pavelsavara:browser_EP_sample_rate

Conversation

@pavelsavara
Copy link
Copy Markdown
Member

Summary

This change introduces a new DOTNET_EventPipeCpuSamplingRate environment 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_EventPipeCpuSamplingRate

  • src/coreclr/inc/clrconfigvalues.h — Register the new INTERNAL_EventPipeCpuSamplingRate DWORD config (default 0).
  • src/native/eventpipe/ep-rt.h — Declare ep_rt_config_value_get_sampling_rate() in the shared EventPipe runtime abstraction header.
  • src/native/eventpipe/ep.c — In ep_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_rate

  • src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h — CoreCLR: reads via CLRConfig::GetConfigValue.
  • src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h — NativeAOT: reads via RhConfig::Environment::TryGetIntegerValue.
  • src/mono/mono/eventpipe/ep-rt-mono.h — Mono: reads via g_getenv("DOTNET_EventPipeCpuSamplingRate").

Blazor/Browser WASM build integration

  • src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets
    • Gate _AddWasmDiagnosticPortsEnvironmentVariable target on EnableDiagnostics=true.
    • Parse WasmPerformanceInstrumentation to extract an optional ,interval=<ms> suffix.
    • Pass the filter portion as DOTNET_WasmPerformanceInstrumentation and the interval (if present) as DOTNET_EventPipeCpuSamplingRate.

Miscellaneous fixes

  • src/native/eventpipe/ds-ipc-pal-websocket.h

    • Wrap websocket extern declarations in extern "C" to prevent C++ name mangling (needed for JS interop in browser WASM).
    • Fix ds_rt_websocket_recv signature: remove incorrect const from the receive buffer parameter.
  • src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h

    • Add PROFILING_SUPPORTED preprocessor guard around ep_rt_notify_profiler_provider_created body.
    • Update #endif comments for clarity.
  • src/native/eventpipe/ep-session.c

    • Add EP_ASSERT(session->buffer_manager != NULL) invariant check in the streaming loop shutdown path.

@pavelsavara pavelsavara added this to the 11.0.0 milestone Apr 22, 2026
@pavelsavara pavelsavara self-assigned this Apr 22, 2026
Copilot AI review requested due to automatic review settings April 22, 2026 17:55
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @dotnet/area-system-diagnostics
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 EventPipeCpuSamplingRate config/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.

Comment thread src/native/eventpipe/ep-session.c Outdated
Comment thread src/mono/mono/eventpipe/ep-rt-mono.h
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 22, 2026 18:31
…oft.NET.Sdk.WebAssembly.Browser.targets

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment thread src/mono/mono/eventpipe/ep-rt-mono.h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants