Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
pavelsavara merged 1 commit into
dotnet:main from
pavelsavara:fix-mono-eventpipe-sampling-129584
Jun 26, 2026
Merged

[browser] Fix EventPipe CPU sampling stall under coarse browser timer resolution #129848
pavelsavara merged 1 commit into
dotnet:main from
pavelsavara:fix-mono-eventpipe-sampling-129584

Conversation

@pavelsavara

@pavelsavara pavelsavara commented Jun 25, 2026

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

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

Copy link
Copy Markdown
Member Author

Copy link
Copy Markdown
Member Author

/ba-g infra

@pavelsavara pavelsavara merged commit acb2256 into dotnet:main Jun 26, 2026
91 of 96 checks passed
@pavelsavara pavelsavara deleted the fix-mono-eventpipe-sampling-129584 branch June 26, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot Copilot left review comments
@maraf maraf maraf approved these changes
@ilonatommy ilonatommy Awaiting requested review from ilonatommy ilonatommy is a code owner
@lateralusX lateralusX Awaiting requested review from lateralusX lateralusX is a code owner
@steveisok steveisok Awaiting requested review from steveisok steveisok is a code owner
@vitek-karas vitek-karas Awaiting requested review from vitek-karas vitek-karas is a code owner

Labels

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

Projects

None yet

Milestone

11.0.0

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

AltStyle によって変換されたページ (->オリジナル) /