Skip to content

[browser] managed Diagnostics.Metrics and Diagnostics.Tracing single-threaded #113524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Mar 21, 2025

Conversation

pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented Mar 14, 2025

This change enables Diagnostics.Metrics and Diagnostics.Tracing in single-threaded browser.

The behavior is slightly different from desktop/server dotnet because the events are only propagated on the same thread as application logic. That's when the user code yields to the browser event loop. In well behaved applications, this is often, because that's how you allow the browser to re-render the page. If the user code is running long synchronous loop, the events would be only delivered later.

Implementation

  • excuded CounterGroup and RuntimeEventSource from browser build
  • split EventPipeEventDispatcher.Threads.cs and EventPipeEventDispatcher.Wasm.cs - make it Task based
  • updated AggregationManager - make it timer based for WASM

Other

  • fix nullable argument in BeginInstrumentReporting, EndInstrumentReporting and InstrumentPublished

Tests

  • enable EventSourceSupport, MetricsSupport MSBuild props for unit tests which need it
  • enabled WasmPerfTracing for ActivityTracking test to work, because EventPipeEventProvider.EventActivityIdControl is in libmono-component-diagnostics_tracing which need to be linked in
  • enable TestSubscriptionManagerDisposal
  • enable RuntimeMetricsTests, ActivityTracking
  • MetricEventSourceTests are OuterLoop, but I made them work locally by rewriting them to async.

Fixes #93754
Contributes to #76316

- split AggregationManager.Threads.cs and AggregationManager.Wasm.cs - make it timer based for WASM
- split CounterGroup.Threads.cs and CounterGroup.Wasm.cs - make it timer based for WASM
- split EventPipeEventDispatcher.Threads.cs and EventPipeEventDispatcher.Wasm.cs - make it Task based
- add switch System.Net.Http.EnableMetrics and use it in HTTP client to make MetricsHandler optional
-

Api
- remove UnsupportedOSPlatform("browser")] on diagnostic API

Tests
- enable WasmPerfTracing, EventSourceSupport, MetricsSupport for unit tests which need it
- fix ActiveIssue dotnet#93754
- enable TestSubscriptionManagerDisposal
- fix nullable argument in BeginInstrumentReporting, EndInstrumentReporting and InstrumentPublished
- enable MetricEventSourceTests, RuntimeMetricsTests, ActivityTracking
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture area-Diagnostics-mono os-browser Browser variant of arch-wasm labels Mar 14, 2025
@pavelsavara pavelsavara added this to the 10.0.0 milestone Mar 14, 2025
@pavelsavara pavelsavara self-assigned this Mar 14, 2025
@ghost
Copy link

ghost commented Mar 14, 2025

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

1 similar comment
@ghost
Copy link

ghost commented Mar 14, 2025

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

pavelsavara added a commit to pavelsavara/runtime that referenced this pull request Mar 14, 2025
@pavelsavara
Copy link
Member Author

/azp run runtime-libraries-coreclr outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara
Copy link
Member Author

@noahfalk I believe I processed all your feedback. Please have another look.

@tarekgh I executed coreCLR outerloop pipeline and there are quite few timeouts I'm not familiar with.
It seems to me most of them are completely unrelated, because I think I made no change to CoreCLR.

Some of them are about System.Diagnostics.DiagnosticSource.Tests,
passing and timeout
https://helixr1107v0xdcypoyl9e7f.blob.core.windows.net/dotnet-runtime-refs-pull-113524-merge-4ce231f817134eeeb1/System.Diagnostics.DiagnosticSource.Tests/1/console.97f0f45e.log?helixlogtype=result
https://helixr1107v0xdcypoyl9e7f.blob.core.windows.net/dotnet-runtime-refs-pull-113524-merge-d64bee06b6904cb984/System.Diagnostics.DiagnosticSource.Tests/1/console.b25b5eaf.log?helixlogtype=result

timeout during test
https://helixr1107v0xdcypoyl9e7f.blob.core.windows.net/dotnet-runtime-refs-pull-113524-merge-8849796b28c94bb8af/System.Diagnostics.DiagnosticSource.Tests/1/console.e5a2c1aa.log?helixlogtype=result
https://helixr1107v0xdcypoyl9e7f.blob.core.windows.net/dotnet-runtime-refs-pull-113524-merge-1db6ed0772b4439aae/System.Diagnostics.DiagnosticSource.Tests/1/console.6866e220.log?helixlogtype=result

If you guys believe that my changes in MetricEventSourceTests.cs to make it async are causing that I could revert the changes in that file and exclude the test on browser. It's outerloop anyway.

please advise, thanks

@tarekgh
Copy link
Member

tarekgh commented Mar 20, 2025

It seems to me most of them are completely unrelated, because I think I made no change to CoreCLR.

I am seeing this timeout https://helixr1107v0xdcypoyl9e7f.blob.core.windows.net/dotnet-runtime-refs-pull-113524-merge-1db6ed0772b4439aae/System.Diagnostics.DiagnosticSource.Tests/1/console.6866e220.log?helixlogtype=result, looks these failing in slow platforms (like Debug and Linux Musl). These outer loop tests take a long time so on slow platforms can timeout I guess. I don't recall seeing such failures, but I can see why it can time out. I have re-run the failing tests hopefully it passes. If it is still failing, you may ignore them for now as it is time out and passing in other platforms.

Copy link
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.

👍

# Conflicts:
#	src/libraries/Microsoft.Extensions.Diagnostics/tests/Microsoft.Extensions.Diagnostics.Tests.csproj
@pavelsavara
Copy link
Member Author

/ba-g CI issues are known

@pavelsavara pavelsavara merged commit 2218335 into dotnet:main Mar 21, 2025
144 of 149 checks passed
@pavelsavara pavelsavara deleted the browser_managed_diag_events branch March 21, 2025 16:24
@github-actions github-actions bot locked and limited conversation to collaborators Apr 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Diagnostics-mono os-browser Browser variant of arch-wasm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[wasm] MeterDisposeTest is failing
10 participants