Skip to content

Commit f7a0f32

Browse files
committed
Updates
1 parent e7f5715 commit f7a0f32

4 files changed

Lines changed: 159 additions & 63 deletions

File tree

aspnetcore/blazor/performance/app-download-size.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,21 @@ After an app is deployed, verify that the app serves compressed files. Inspect t
6666

6767
Blazor WebAssembly's runtime includes the following .NET features that can be disabled for a smaller payload size.
6868

69-
Blazor WebAssembly carries globalization resources required to display values, such as dates and currency, in the user's culture. If the app doesn't require localization, you may [configure the app to support the invariant culture](xref:blazor/globalization-localization#invariant-globalization), which is based on the `en-US` culture.
69+
Blazor WebAssembly carries globalization resources required to display values, such as dates and currency, in the user's culture. If the app doesn't require localization, you may configure the app to [support the invariant culture](xref:blazor/globalization-localization#invariant-globalization), which is based on the `en-US` culture. Apply the `<InvariantGlobalization>` MSBuild property with a value of `true` in the app's project file (`.csproj`):
70+
71+
```xml
72+
<PropertyGroup>
73+
<InvariantGlobalization>true</InvariantGlobalization>
74+
</PropertyGroup>
75+
```
7076

7177
:::moniker range=">= aspnetcore-8.0"
7278

73-
Adopting [invariant globalization](xref:blazor/globalization-localization#invariant-globalization) only results in using non-localized timezone names. To trim timezone code and data from the app, apply the `<InvariantTimezone>` MSBuild property with a value of `true` in the app's project file:
79+
Adopting [invariant globalization](xref:blazor/globalization-localization#invariant-globalization) only results in using non-localized timezone names. To trim timezone code and data from the app, apply the `<InvariantTimezone>` MSBuild property with a value of `true` in the app's project file (`.csproj`):
7480

7581
```xml
7682
<PropertyGroup>
77-
<InvariantTimezone>true</InvariantTimezone>
83+
<InvariantTimezone>true</InvariantTimezone>
7884
</PropertyGroup>
7985
```
8086

@@ -89,7 +95,7 @@ A data file is included to make timezone information correct. If the app doesn't
8995

9096
```xml
9197
<PropertyGroup>
92-
<BlazorEnableTimeZoneSupport>false</BlazorEnableTimeZoneSupport>
98+
<BlazorEnableTimeZoneSupport>false</BlazorEnableTimeZoneSupport>
9399
</PropertyGroup>
94100
```
95101

@@ -101,8 +107,12 @@ Collation information is included to make APIs such as <xref:System.StringCompar
101107

102108
```xml
103109
<PropertyGroup>
104-
<BlazorWebAssemblyPreserveCollationData>false</BlazorWebAssemblyPreserveCollationData>
110+
<BlazorWebAssemblyPreserveCollationData>false</BlazorWebAssemblyPreserveCollationData>
105111
</PropertyGroup>
106112
```
107113

108114
:::moniker-end
115+
116+
## Additional resources
117+
118+
[Configuring and hosting .NET WebAssembly applications](https://github.com/dotnet/runtime/blob/main/src/mono/wasm/features.md)

aspnetcore/blazor/performance/profiling.md renamed to aspnetcore/blazor/performance/developer-tools-profiling.md

Lines changed: 21 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
---
2-
title: ASP.NET Core Blazor WebAssembly performance profiling and diagnostic counters
2+
title: ASP.NET Core Blazor WebAssembly developer tools performance profiling and diagnostic counters
33
author: guardrex
4-
description: Learn about performance profiling and diagnostic counters in ASP.NET Core Blazor WebAssembly apps.
4+
description: Learn about developer tools performance profiling and diagnostic counters in ASP.NET Core Blazor WebAssembly apps.
55
monikerRange: '>= aspnetcore-10.0'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 04/16/2025
9-
uid: blazor/performance/profiling
8+
ms.date: 04/29/2025
9+
uid: blazor/performance/developer-tools-profiling
1010
---
11-
# ASP.NET Core Blazor WebAssembly performance profiling and diagnostic counters
11+
# ASP.NET Core Blazor WebAssembly developer tools performance profiling and diagnostic counters
1212

1313
<!-- UPDATE 10.0 - Activate ...
1414
1515
[!INCLUDE[](~/includes/not-latest-version.md)]
1616
1717
-->
1818

19-
This article describes performance profiling tools and diagnostic counters for Blazor WebAssembly apps.
19+
This article describes developer tools performance profiling tools and diagnostic counters for Blazor WebAssembly apps.
2020

2121
## Prerequisite
2222

@@ -34,10 +34,9 @@ Built-in performance counters are available to track:
3434

3535
* [Ahead-of-time (AOT) compilation](xref:blazor/tooling/webassembly#ahead-of-time-aot-compilation)
3636
* Code interpolation
37-
* [JIT (Just-In-Time) interpolation](https://developer.mozilla.org/docs/Glossary/Just_In_Time_Compilation)
3837
* Call specification (":::no-loc text="callspec":::", sequence and timing of function calls) and instrumentation
3938

40-
Enable integration with the browser's developer tools profiler using the `<WasmProfilers>` property in the app's project file (`.csproj`). Include the additional properties in the following table.
39+
The MSBuild properties in the following table enable profiler integration.
4140

4241
Property | Default | Set value to&hellip; | Description
4342
--- | :---: | :---: | ---
@@ -48,8 +47,12 @@ Property | Default | Set value to&hellip; | Description
4847
`<WasmNativeDebugSymbols>` | `true` | `true` | Controls building with native debug symbols.
4948
`<WasmBuildNative>` | `false` | `true` | Controls building the native executable.
5049

50+
Enabling profilers has negative size and performance impact, so don't publish an app for production with profilers enabled. In the following example, a condition is set on a property group section that only enables profiling when the app is built with `/p:ProfilingEnabled=true` (.NET CLI) or `<ProfilingEnabled>true</ProfilingEnabled>` in a Visual Studio publish profile.
51+
52+
In the app's project file (`.csproj`):
53+
5154
```xml
52-
<PropertyGroup>
55+
<PropertyGroup Condition="'$(ProfilingEnabled)' == 'true'">
5356
<WasmProfilers>browser;</WasmProfilers>
5457
<RunAOTCompilation>true</RunAOTCompilation>
5558
<RunAOTCompilationAfterBuild>true</RunAOTCompilationAfterBuild>
@@ -59,7 +62,15 @@ Property | Default | Set value to&hellip; | Description
5962
</PropertyGroup>
6063
```
6164

62-
Add Blazor start configuration in `wwwroot/index.html`, using the [fingerprinted location of the Blazor WebAssembly script](xref:blazor/fundamentals/static-files#fingerprint-client-side-static-assets-in-standalone-blazor-webassembly-apps). In the following example, the `sampleIntervalMs` option is set to 10 seconds, which is the default setting if `sampleIntervalMs` isn't specified:
65+
Setting WebAssembly profilers with `<WasmProfilers>browser;</WasmProfilers>` doesn't require AOT (`<RunAOTCompilation>`/`<RunAOTCompilationAfterBuild>` set to `false` or removed from the preceding properity group).
66+
67+
The browser developer tools profiler can be used with AOT (`<RunAOTCompilation>`/`<RunAOTCompilationAfterBuild>` set to `true`) and without WebAssembly profilers (`<WasmProfilers>browser;</WasmProfilers>` removed from the preceding property group).
68+
69+
To see AOT method names in the developer tools console, install [DWARF chrome extension](https://chromewebstore.google.com/detail/cc++-devtools-support-dwa/pdcpmagijalfljmkmjngeonclgbbannb).
70+
71+
## Set the sample interval
72+
73+
To set the sample interval, add the following Blazor start configuration in `wwwroot/index.html` and add `autostart="false"` to the Blazor `<script>` tag. In the following example, the `sampleIntervalMs` option is set to 10 seconds, which is the default setting if `sampleIntervalMs` isn't specified:
6374

6475
```html
6576
<script src="_framework/blazor.webassembly#[.{fingerprint}].js"
@@ -105,57 +116,12 @@ Configure `callSpec` in `browserProfilerOptions`. Replace the `{APP NAMESPACE}`
105116
</script>
106117
```
107118

108-
## Log profiling for memory troubleshooting
109-
110-
Enable integration with the log profiler using the `<WasmProfilers>` and `<WasmBuildNative>` properties in the app's project file (`.csproj`):
111-
112-
```xml
113-
<PropertyGroup>
114-
<WasmProfilers>log</WasmProfilers>
115-
<WasmBuildNative>true</WasmBuildNative>
116-
</PropertyGroup>
117-
```
118-
119-
To trigger a heap shot, add the following, where the `{APP NAMESPACE}` placeholder is the app's namespace:
120-
121-
```csharp
122-
namespace {APP NAMESPACE};
123-
124-
public class Profiling
125-
{
126-
[JSExport]
127-
[MethodImpl(MethodImplOptions.NoInlining)]
128-
public static void TakeHeapshot() { }
129-
}
130-
```
131-
132-
Invoke `TakeHeapshot` to create a memory heap shot and flush the contents of the profile to the file system. Download the resulting `.mpld` file to analyze the data.
133-
134-
## EventPipe profiler
135-
136-
[EventPipe](/dotnet/core/diagnostics/eventpipe) is a runtime component used to collect tracing data, similar to [ETW](/windows/win32/etw/event-tracing-portal) and [perf_events](https://wikipedia.org/wiki/Perf_%28Linux%29).
137-
138-
* Manual testing
139-
* Browser developer tools: Download the `.json` output file, open the file in Visual Studio, and find the expected method calls.
140-
* [`dotnet-trace`](/dotnet/core/diagnostics/dotnet-trace): Open the `.nettrace` output file in Visual Studio and find the expected method calls.
141-
* Web-based testing
142-
* Use the JavaScript API to obtain a [promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) of NetTrace (`.nettrace`) bytes.
143-
* Upload the file via HTTP.
144-
* Parse and validate that the trace contains the expected method calls.
145-
146-
Built-in performance counters are available to track:
147-
148-
* [Ahead-of-time (AOT) compilation](xref:blazor/tooling/webassembly#ahead-of-time-aot-compilation)
149-
* Code interpolation
150-
* [JIT (Just-In-Time) interpolation](https://developer.mozilla.org/docs/Glossary/Just_In_Time_Compilation)
151-
152119
## GC (Garbage Collector) dumps
153120

154121
* Manual testing
155122
* Browser developer tools: Download the `.json` output file, open the file in Visual Studio, and find the expected classes.
156123
* [`dotnet-gcdump` (`collect`/convert` options)](/dotnet/core/diagnostics/dotnet-gcdump): To view the captured GC dump files, see [View the GC dump captured from dotnet-gcdump](/dotnet/core/diagnostics/dotnet-gcdump#view-the-gc-dump-captured-from-dotnet-gcdump).
157124
* Web-based testing
158-
* Use the JavaScript API to obtain a [promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) of NetTrace (`.nettrace`) bytes.
159125
* Upload the file via HTTP.
160126
* Parse and validate that the trace contains the expected classes.
161127

@@ -165,7 +131,6 @@ Built-in performance counters are available to track:
165131
* Browser developer tools: Download the `.json` output file, open the file in Visual Studio, and find the expected counters.
166132
* [`dotnet-counters collect`](/dotnet/core/diagnostics/dotnet-counters): Open the `.csv`/`.json` output file in Visual Studio and find the expected counters.
167133
* Web-based testing
168-
* Use the JavaScript API to obtain a [promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) of NetTrace (`.nettrace`) bytes.
169134
* Upload the file via HTTP.
170135
* Parse and validate that the trace contains the expected counters.
171136

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
title: ASP.NET Core Blazor WebAssembly Event Pipe performance profiling and diagnostic counters
3+
author: guardrex
4+
description: Learn about Event Pipe performance profiling and diagnostic counters in ASP.NET Core Blazor WebAssembly apps.
5+
monikerRange: '>= aspnetcore-10.0'
6+
ms.author: riande
7+
ms.custom: mvc
8+
ms.date: 04/29/2025
9+
uid: blazor/performance/event-pipe-profiling
10+
---
11+
# ASP.NET Core Blazor WebAssembly Event Pipe performance profiling and diagnostic counters
12+
13+
<!-- UPDATE 10.0 - Activate ...
14+
15+
[!INCLUDE[](~/includes/not-latest-version.md)]
16+
17+
-->
18+
19+
This article describes Event Pipe performance profiling tools and diagnostic counters for Blazor WebAssembly apps.
20+
21+
## Prerequisite
22+
23+
Install the [.NET WebAssembly build tools](xref:blazor/tooling/webassembly#net-webassembly-build-tools):
24+
25+
```dotnetcli
26+
dotnet workload install wasm-tools
27+
```
28+
29+
## EventPipe profiler
30+
31+
[EventPipe](/dotnet/core/diagnostics/eventpipe) is a runtime component used to collect tracing data, similar to [ETW](/windows/win32/etw/event-tracing-portal) and [perf_events](https://wikipedia.org/wiki/Perf_%28Linux%29).
32+
33+
* Manual testing
34+
* Browser developer tools: Download the `.nettrace` output file, open the file in Visual Studio, and find the expected method calls.
35+
* [`dotnet-trace`](/dotnet/core/diagnostics/dotnet-trace): Open the `.nettrace` output file in Visual Studio and find the expected method calls.
36+
* Web-based testing
37+
* Upload the file via HTTP.
38+
* Parse and validate that the trace contains the expected method calls.
39+
40+
Built-in performance counters are available to track:
41+
42+
* [Ahead-of-time (AOT) compilation](xref:blazor/tooling/webassembly#ahead-of-time-aot-compilation)
43+
* Code interpolation
44+
45+
## GC (Garbage Collector) dumps
46+
47+
* Manual testing
48+
* Browser developer tools: Download the `.json` output file, open the file in Visual Studio, and find the expected classes.
49+
* [`dotnet-gcdump` (`collect`/convert` options)](/dotnet/core/diagnostics/dotnet-gcdump): To view the captured GC dump files, see [View the GC dump captured from dotnet-gcdump](/dotnet/core/diagnostics/dotnet-gcdump#view-the-gc-dump-captured-from-dotnet-gcdump).
50+
* Web-based testing
51+
* Upload the file via HTTP.
52+
* Parse and validate that the trace contains the expected classes.
53+
54+
## Counters trace
55+
56+
* Manual testing
57+
* Browser developer tools: Download the `.json` output file, open the file in Visual Studio, and find the expected counters.
58+
* [`dotnet-counters collect`](/dotnet/core/diagnostics/dotnet-counters): Open the `.csv`/`.json` output file in Visual Studio and find the expected counters.
59+
* Web-based testing
60+
* Upload the file via HTTP.
61+
* Parse and validate that the trace contains the expected counters.
62+
63+
## .NET Core Diagnostics Client Library example
64+
65+
Parse and validate NetTrace (`.nettrace`) messages using the .NET Core Diagnostics Client Library:
66+
67+
* [`dotnet/diagnostics` GitHub repository](https://github.com/dotnet/diagnostics)
68+
* [`Microsoft.Diagnostics.NETCore.Client` NuGet package](https://www.nuget.org/packages/Microsoft.Diagnostics.NETCore.Client)
69+
70+
For more information, see the [.NET Core diagnostics documentation](/dotnet/core/diagnostics/) and the [`IpcMessage` API (reference source)](https://github.com/dotnet/diagnostics/blob/main/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcMessage.cs).
71+
72+
[!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)]
73+
74+
The following example:
75+
76+
* Collects a GC (Garbage Collector) dump of the live .NET process.
77+
* Collects performance counters for 60 seconds.
78+
* Collects CPU counters for 60 seconds.
79+
80+
The MSBuild properties in the following table enable profiler integration.
81+
82+
Property | Default | Set value to&hellip; | Description
83+
--- | :---: | :---: | ---
84+
`<WasmPerfTracing>` | `false` | `true` | Controls diagnostic server tracing.
85+
`<WasmPerfInstrumentation>` | `false` | `true` | Controls CPU sampling instrumentation for diagnostic server. Not necessary for memory dump or counters. **Makes the app execute slower. Only set this to `true` for performance profiling.
86+
`<MetricsSupport>` | `false` | `true` | Controls `System.Diagnostics.Metrics` support. For more information, see the [`System.Diagnostics.Metrics` namespace](/dotnet/api/system.diagnostics.metrics).
87+
`<EventSourceSupport>` | `false`| `true` | Controls `EventPipe` support. For more information, see [Diagnostics and instrumentation: Observability and telemetry](/dotnet/core/deploying/native-aot/diagnostics#observability-and-telemetry).
88+
89+
Enabling profilers has negative size and performance impact, so don't publish an app for production with profilers enabled. In the following example, a condition is set on a property group section that only enables profiling when the app is built with `/p:ProfilingEnabled=true` (.NET CLI) or `<ProfilingEnabled>true</ProfilingEnabled>` in a Visual Studio publish profile.
90+
91+
In the app's project file (`.csproj`):
92+
93+
```xml
94+
<PropertyGroup Condition="'$(ProfilingEnabled)' == 'true'">
95+
<WasmPerfTracing>true</WasmPerfTracing>
96+
<WasmPerfInstrumentation>true</WasmPerfInstrumentation>
97+
<MetricsSupport>true</MetricsSupport>
98+
<EventSourceSupport>true</EventSourceSupport>
99+
</PropertyGroup>
100+
```
101+
102+
The [`Timing-Allow-Origin` HTTP header](https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/Timing-Allow-Origin) allows for more precise time measurements.
103+
104+
Browser developer tools console calls in the following example that trigger profiling:
105+
106+
* `collectGcDump`: Collect a GC (Garbage Collector) dump.
107+
* `collectPerfCounters(durationSeconds)`: Collect general performance counters.
108+
* `collectCpuSamples(durationSeconds)`: Collect CPU performance counters.
109+
110+
```javascript
111+
globalThis.getDotnetRuntime(0).collectGcDump();
112+
globalThis.getDotnetRuntime(0).collectPerfCounters({durationSeconds: 60});
113+
globalThis.getDotnetRuntime(0).collectCpuSamples({durationSeconds: 60});
114+
```
115+
116+
## Additional resources
117+
118+
* [What diagnostic tools are available in .NET Core?](/dotnet/core/diagnostics/)
119+
* [.NET diagnostic tools](/dotnet/core/diagnostics/tools-overview)

aspnetcore/toc.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,10 @@ items:
660660
uid: blazor/performance/app-download-size
661661
- name: JavaScript interop
662662
uid: blazor/performance/js-interop
663-
- name: WebAssembly profiling
664-
uid: blazor/performance/profiling
663+
- name: WebAssembly developer tools profiling
664+
uid: blazor/performance/developer-tools-profiling
665+
- name: WebAssembly Event Pipe profiling
666+
uid: blazor/performance/event-pipe-profiling
665667
- name: Test components
666668
uid: blazor/test
667669
- name: Progressive Web Applications

0 commit comments

Comments
 (0)