Skip to content

Add configurable EventPipe CPU sampling rate via DOTNET_EventPipeThreadSamplingRate#127292

Merged
pavelsavara merged 12 commits intodotnet:mainfrom
pavelsavara:browser_EP_sample_rate
Apr 29, 2026
Merged

Add configurable EventPipe CPU sampling rate via DOTNET_EventPipeThreadSamplingRate#127292
pavelsavara merged 12 commits intodotnet:mainfrom
pavelsavara:browser_EP_sample_rate

Conversation

@pavelsavara
Copy link
Copy Markdown
Member

@pavelsavara pavelsavara commented Apr 22, 2026

Summary

This change introduces a new DOTNET_EventPipeThreadSamplingRate 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_EventPipeThreadSamplingRate

  • src/coreclr/inc/clrconfigvalues.h — Register the new INTERNAL_EventPipeThreadSamplingRate 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_EventPipeThreadSamplingRate").

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_EventPipeThreadSamplingRate.

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 Outdated
Copilot AI review requested due to automatic review settings April 23, 2026 21:59
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Comment thread src/native/eventpipe/ep.c
Comment thread src/native/eventpipe/ep-session.c Outdated
Copilot AI review requested due to automatic review settings April 24, 2026 09:19
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 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread src/native/eventpipe/ep.c Outdated
Comment thread src/native/eventpipe/ep.c Outdated
Copy link
Copy Markdown
Member

@lateralusX lateralusX left a comment

Choose a reason for hiding this comment

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

LGTM!

@jkotas
Copy link
Copy Markdown
Member

jkotas commented Apr 24, 2026

Copy link
Copy Markdown
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

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

Looks good to me modulo comments inline.

Comment thread src/coreclr/inc/clrconfigvalues.h Outdated
Comment thread src/coreclr/inc/clrconfigvalues.h Outdated
Comment thread src/coreclr/inc/clrconfigvalues.h Outdated
# Conflicts:
#	src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets
Copilot AI review requested due to automatic review settings April 27, 2026 17:44
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 10 out of 10 changed files in this pull request and generated 6 comments.

Comment thread src/native/eventpipe/ep.c
Comment thread src/coreclr/inc/clrconfigvalues.h
Comment thread src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h
Comment thread src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h
@pavelsavara pavelsavara changed the title Add configurable EventPipe CPU sampling rate via DOTNET_EventPipeCpuSamplingRate Add configurable EventPipe CPU sampling rate via DOTNET_EventPipeThreadSamplingRate Apr 27, 2026
@pavelsavara
Copy link
Copy Markdown
Member Author

@pavelsavara pavelsavara merged commit 4e8ab2d into dotnet:main Apr 29, 2026
158 of 160 checks passed
@pavelsavara pavelsavara deleted the browser_EP_sample_rate branch April 29, 2026 07:15
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.

6 participants