Skip to content

[browser] Fix EventPipe CPU sampling stall under coarse browser timer resolution#129848

Open
pavelsavara wants to merge 1 commit into
dotnet:mainfrom
pavelsavara:fix-mono-eventpipe-sampling-129584
Open

[browser] Fix EventPipe CPU sampling stall under coarse browser timer resolution#129848
pavelsavara wants to merge 1 commit into
dotnet:mainfrom
pavelsavara:fix-mono-eventpipe-sampling-129584

Conversation

@pavelsavara

Copy link
Copy Markdown
Member

Fixes #129584.

Problem

On WebAssembly the EventPipe CPU sample profiler could permanently stop emitting samples. update_sample_frequency recomputes skips_per_period by dividing sample_skip_counter by ms_since_last_sample. With the coarse browser timer resolution, ms_since_last_sample can round to 0 during a burst of instrumentation callbacks. Dividing by 0 yields +Inf, which — once cast to int under WASM's saturating, non-trapping float-to-int conversion — pins skips_per_period at INT_MAX, permanently disabling sampling.

Fix

  • Only recompute when wall-clock time actually advanced (ms_since_last_sample > 0); otherwise keep the previous skips_per_period.
  • Clamp the averaged skip count to a sane range ([1, 10000]) so sampling stays responsive, matching the CoreCLR single-threaded sampler behavior.

This re-enables the EventPipe CPU sample Blazor tests (BlazorEventPipeTestWithCpuSamplesAOT and BlazorEventPipeTestWithCpuSamples) that were disabled by the issue.

Note

This PR description was generated with assistance from GitHub Copilot.

…esolution

update_sample_frequency divided by ms_since_last_sample which can round to 0 with coarse browser timer resolution, producing +Inf that saturates skips_per_period to INT_MAX and permanently disables sampling. Skip recompute when no wall-clock time elapsed and clamp the averaged skip count. Re-enables the EventPipe CPU sample tests previously disabled by dotnet#129584.
Copilot AI review requested due to automatic review settings June 25, 2026 13:17
@pavelsavara pavelsavara self-assigned this Jun 25, 2026
@pavelsavara pavelsavara added this to the 11.0.0 milestone Jun 25, 2026
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture os-browser Browser variant of arch-wasm labels Jun 25, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts Mono’s browser EventPipe CPU sampling skip-calculation to avoid pathological behavior when the browser’s performance.now() resolution is coarse (e.g., repeated 0 deltas), and re-enables the previously-disabled Blazor EventPipe CPU sampling tests.

Changes:

  • Guard update_sample_frequency() to only recompute skips_per_period when ms_since_last_sample > 0, and clamp the computed skip range.
  • Re-enable Blazor EventPipe CPU sampling tests by removing the ActiveIssue skips.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/mono/mono/eventpipe/ep-rt-mono-runtime-provider.c Adds elapsed-time guard and clamps adaptive skip computation for single-threaded browser sampling.
src/mono/wasm/Wasm.Build.Tests/Blazor/EventPipeDiagnosticsTests.cs Removes ActiveIssue attributes to re-enable CPU sampling test coverage.

Comment thread src/mono/mono/eventpipe/ep-rt-mono-runtime-provider.c
@pavelsavara pavelsavara enabled auto-merge (squash) June 25, 2026 14:09
@pavelsavara pavelsavara changed the title Fix Mono EventPipe CPU sampling stall under coarse browser timer resolution [browser] Fix EventPipe CPU sampling stall under coarse browser timer resolution Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Tracing-mono os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[wasm] Wasm.Build.Tests EventPipeDiagnosticsTests CPU-sampling tests fail after emsdk 5.0.6 / LLVM 23 legacy-EH change

3 participants