Skip to content

[Browser][coreCLR] Enable EventPipe for CoreCLR#128745

Open
pavelsavara wants to merge 6 commits into
dotnet:mainfrom
pavelsavara:browser_EP_coreclr_build
Open

[Browser][coreCLR] Enable EventPipe for CoreCLR#128745
pavelsavara wants to merge 6 commits into
dotnet:mainfrom
pavelsavara:browser_EP_coreclr_build

Conversation

@pavelsavara
Copy link
Copy Markdown
Member

This PR enables the EventPipe diagnostics infrastructure for CoreCLR running on single-threaded Browser WASM.
It will probably increase size of the .wasm file.

It is split from #126324 for smaller code review.
Remaining parts are the CPU sampling instrumentation and unit tests.

Changes

Feature enablement

  • Removed the FeaturePerfTracing=false override for WASM in clr.featuredefines.props. Previously EventPipe was disabled for CoreCLR on WASM pending single-threaded implementation.
  • Updated clrfeatures.cmake to enable FEATURE_PERFTRACING when FEATURE_PERFTRACING_DISABLE_THREADS is set (not just when FEATURE_EVENT_TRACE is set).
  • Updated clrdefinitions.cmake to define FEATURE_PERFTRACING in the elseif(FEATURE_PERFTRACING) case (EventPipe without full ETW event tracing).

Single-threaded EventPipe runtime (ep-rt-coreclr.h)

  • Added no-op stubs for wait events under PERFTRACING_DISABLE_THREADS — uses INVALID_HANDLE_VALUE as an "allocated" sentinel.
  • Added ep_rt_thread_create stub that hits EP_UNREACHABLE.
  • Added ep_rt_queue_job implementation for HOST_BROWSER — invokes the job callback inline and reschedules via SystemJS_DiagnosticServerQueueJob if the job returns "not done".
  • Made ep_rt_thread_sleep a no-op under PERFTRACING_DISABLE_THREADS.
  • Propagated PERFTRACING_DISABLE_THREADS compile definition to eventpipe_objs, eventpipe_gen_objs, cee_wks_core, and clrinterpreter_objects targets.

Eventing / ETW adaptations for Browser

  • Stripped LTTng/XplatEventLogger references for HOST_BROWSER/HOST_WASI in generated eventing code (genEventing.py) and runtime (eventtrace.cpp).
  • Simplified DOTNET_TRACE_CONTEXT struct for Browser/WASI (EventPipe-only, no LTTng context).
  • Updated ETW_EVENT_ENABLED/ETW_TRACING_ENABLED macros to avoid referencing LTTng on Browser/WASI (eventtracebase.h).
  • Passed nullptr callback to CreateProvider when FEATURE_EVENT_TRACE is not defined (genEventPipe.py).
  • Added EventPipeEventProvider.Callback reverse-call helper for managed provider callbacks (callhelpers-reverse.cpp).
  • Added new interp-to-managed call signatures needed by EventPipe (callhelpers-interp-to-managed.cpp).

GC diagnostics deferral

  • On single-threaded Browser, ForceGC (triggered by the GCHeapCollect keyword) cannot run synchronously during the provider callback. Deferred to the next event loop turn via SystemJS_DiagnosticServerQueueJob (eventtrace_gcheap.cpp).

GC profiling fix

  • Fixed DiagGCEnd to call GCProfileWalkHeap when FEATURE_EVENT_TRACE is defined (not only GC_PROFILING), enabling GC heap walk events on platforms without profiling support (gcenv.ee.cpp).

Build integration

  • BrowserWasmApp.CoreCLR.targets: auto-enable native relink (WasmBuildNative=true) when EnableDiagnostics=true.

Test adjustments

  • Excluded EventPipeListener test harness and TraceEvent/DiagnosticsClient NuGet packages from the browser test build (these require out-of-process diagnostics, not available in-browser).
  • Guarded EventPipeListener usage in TestsWrite.cs / TestsWriteEvent.cs with #if !TARGET_BROWSER.
  • Added TARGET_BROWSER define and WASM0066 warning suppression to the test project.

@pavelsavara pavelsavara added this to the 11.0.0 milestone May 29, 2026
@pavelsavara pavelsavara self-assigned this May 29, 2026
Copilot AI review requested due to automatic review settings May 29, 2026 06:59
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture area-Diagnostics-coreclr os-browser Browser variant of arch-wasm labels May 29, 2026
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

This PR enables CoreCLR EventPipe diagnostics for single-threaded Browser WASM by adjusting feature flags, generated eventing code, runtime EventPipe threading abstractions, GC diagnostics behavior, browser native relink behavior, and tracing tests.

Changes:

  • Enables CoreCLR perf tracing/EventPipe paths for WASM and adapts generated eventing code to avoid LTTng/XplatEventLogger on Browser/WASI.
  • Adds single-threaded EventPipe runtime stubs/queueing behavior and defers Browser GC collection requests through the diagnostic server job queue.
  • Updates WASM/browser tracing tests to avoid out-of-process diagnostics dependencies and define browser-specific test constants.

Reviewed changes

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

Show a summary per file
File Description
src/mono/browser/build/BrowserWasmApp.CoreCLR.targets Forces native relink when diagnostics are enabled for CoreCLR browser apps.
src/libraries/System.Diagnostics.Tracing/tests/System.Diagnostics.Tracing.Tests.csproj Adjusts browser/android target detection and excludes EventPipeListener/package dependencies on browser.
src/libraries/System.Diagnostics.Tracing/tests/BasicEventSourceTest/TestsWriteEvent.cs Guards EventPipeListener usage out of browser builds.
src/libraries/System.Diagnostics.Tracing/tests/BasicEventSourceTest/TestsWrite.cs Guards EventPipeListener usage out of browser builds.
src/coreclr/vm/wks/CMakeLists.txt Propagates single-threaded perf tracing define to workstation GC VM objects.
src/coreclr/vm/wasm/entrypoints.h Declares the browser diagnostic server job queue entrypoint for native CoreCLR code.
src/coreclr/vm/wasm/callhelpers-reverse.cpp Adds reverse thunk support for EventPipeEventProvider.Callback.
src/coreclr/vm/wasm/callhelpers-interp-to-managed.cpp Adds interpreter-to-managed thunk signatures needed by EventPipe event callbacks.
src/coreclr/vm/gcenv.ee.cpp Allows GC heap walking for EventPipe builds without profiler support.
src/coreclr/vm/eventtrace.cpp Adds Browser/WASI EventPipe-only provider contexts and excludes XplatEventLogger initialization.
src/coreclr/vm/eventtrace_gcheap.cpp Defers browser diagnostic ForceGC requests through the event-loop job queue.
src/coreclr/vm/eventtrace_bulktype.cpp Avoids firing Xplat bulk statics events on Browser/WASI while keeping EventPipe emission.
src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h Adds single-threaded wait-event/thread/job behavior for CoreCLR EventPipe.
src/coreclr/vm/eventing/eventpipe/CMakeLists.txt Defines perf tracing symbols for EventPipe object targets and propagates single-threaded mode.
src/coreclr/vm/eventing/CMakeLists.txt Makes eventing header dependencies conditional and preserves EventPipe subdirectory inclusion.
src/coreclr/scripts/genEventPipe.py Emits nullptr provider callbacks when CoreCLR EventTrace is unavailable.
src/coreclr/scripts/genEventing.py Generates Browser/WASI-safe EventPipe-only eventing structures and guards Xplat event emission.
src/coreclr/interpreter/CMakeLists.txt Propagates single-threaded perf tracing define to interpreter objects.
src/coreclr/inc/eventtracebase.h Defines Browser/WASI EventPipe-only tracing macros and excludes XplatEventLogger classes.
src/coreclr/clrfeatures.cmake Enables EventTrace for browser and perf tracing when single-threaded perf tracing is requested.
src/coreclr/clrdefinitions.cmake Defines FEATURE_PERFTRACING without requiring FEATURE_EVENT_TRACE and adds cross-component dummy headers target.
src/coreclr/clr.featuredefines.props Removes the WASM managed FeaturePerfTracing=false override.

Comment thread src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h
Copy link
Copy Markdown
Member

@maraf maraf left a comment

Choose a reason for hiding this comment

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

Parts I'm familiar with looks good to me 👍

Comment thread src/coreclr/inc/eventtracebase.h Outdated
Copilot AI review requested due to automatic review settings May 29, 2026 18:00
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 22 out of 22 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/vm/eventtrace_bulktype.cpp Outdated
Copilot AI review requested due to automatic review settings May 29, 2026 19:51
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 22 out of 22 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/clrfeatures.cmake
@pavelsavara pavelsavara requested a review from jkotas May 29, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Diagnostics-coreclr os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants