You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!-- do not enable diagnostics in production, as it has a negative performance impact -->
35
+
<PropertyGroup>
36
+
<EnableDiagnostics>true</EnableDiagnostics>
37
+
</PropertyGroup>
38
+
```
35
39
36
-
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).
40
+
> [!WARNING]
41
+
> Don't enable diagnostics in production because it has a negative performance impact.
The MSBuild properties in the following table enable profiler integration.
45
+
Open the app in a browser and navigate to problematic pages or components.
41
46
42
-
Property | Default | Set value to… | Description
43
-
--- | :---: | :---: | ---
44
-
`<WasmPerfTracing>` | `false` | `true` | Enables support for WebAssembly performance tracing.
45
-
`<WasmPerfInstrumentation>` | No value | See table† | Enables instrumentation necessary for the sampling profiler. The property follows the :::no-loc text="callspec"::: syntax. †For permissible values, see the following table.
46
-
`<MetricsSupport>` | `false` | `true` | Enables `System.Diagnostics.Metrics` support. For more information, see the [`System.Diagnostics.Metrics` namespace](/dotnet/api/system.diagnostics.metrics).
47
-
`<EventSourceSupport>` | `false`| `true` | Enables `EventPipe` support. For more information, see [Diagnostics and instrumentation: Observability and telemetry](/dotnet/core/deploying/native-aot/diagnostics#observability-and-telemetry).
47
+
Take a managed memory dump by calling `collectGcDump` JavaScript API:
48
48
49
-
The following table describes permissable `<WasmPerfInstrumentation>` values.
49
+
```javascript
50
+
globalThis.getDotnetRuntime(0).collectGcDump();
51
+
```
50
52
51
-
`<WasmPerfInstrumentation>` value | Description
52
-
--- | ---
53
-
`all` | All assemblies
54
-
`program` | Entry point assembly
55
-
`{ASSEMBLY}` | Specifies an assembly (`{ASSEMBLY}`)
56
-
`M:Type:{METHOD}` | Specifies a method (`{METHOD}`)
57
-
`N:{NAMESPACE}` | Specifies a namespace (`{NAMESPACE}`)
58
-
`T:{TYPE}` | Specifies a type (`{TYPE}`)
59
-
`+EXPR` | Includes expression
60
-
`-EXPR` | Excludes expression
53
+
Call the preceding API from either a browser devoloper tools console or JavaScript code of the app.
54
+
55
+
A `.nettrace` file is downloaded from the browser into a local folder.
56
+
57
+
Convert the dump to `.gcdump` format using the `dotnet-gcdump` tool. To view the converted `.gcdump` file, use Visual Studio or PrefView.
58
+
59
+
For more information, see [View the GC dump captured from dotnet-gcdump](/dotnet/core/diagnostics/dotnet-gcdump#view-the-gc-dump-captured-from-dotnet-gcdump).
61
60
62
-
Enabling profilers has negative size and performance impacts, 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:BlazorSampleProfilingEnabled=true` (.NET CLI) or `<BlazorSampleProfilingEnabled>true</BlazorSampleProfilingEnabled>` in a Visual Studio publish profile, where "`BlazorSampleProfilingEnabled`" is a custom symbol name that you choose and doesn't conflict with other symbol names.
61
+
## How a WebAssembly app uses CPU and how to find slow or hot methods
63
62
64
-
In the app's project file (`.csproj`):
63
+
In the app's project file (`.csproj`), add following properties for the duration of the investigation:
Alternatively, enable features when the app is built with the .NET CLI. The following options passed to the `dotnet build` command mirror the preceding MS Build property configuration:
76
+
> [!WARNING]
77
+
> Don't enable diagnostics in production because it has a negative performance impact.
The [`Timing-Allow-Origin` HTTP header](https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/Timing-Allow-Origin) allows for more precise time measurements.
89
+
Call the preceding API from either a browser devoloper tools console or JavaScript code of the app.
81
90
82
-
## EventPipe profiler
91
+
Start using the app to run problematic code.
83
92
84
-
[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).
93
+
After the predefined period, the browser downloads a `.nettrace` file into a local folder. To view the `.nettrace` file, use Visual Studio or PrefView.
85
94
86
-
Use the `<WasmPerfInstrumentation>` property to enable CPU sampling instrumentation for diagnostic server. This setting isn't necessary for memory dump or counters. **Makes the app execute slower. Only enable this for performance profiling.**
95
+
For more information, see [Use EventPipe to trace your .NET application](/dotnet/core/diagnostics/eventpipe#use-eventpipe-to-trace-your-net-application).
87
96
88
-
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:BlazorSampleProfilingEnabled=true` (.NET CLI) or `<BlazorSampleProfilingEnabled>true</BlazorSampleProfilingEnabled>` in a Visual Studio publish profile, where "`BlazorSampleProfilingEnabled`" is a custom symbol name that you choose and doesn't conflict with other symbol names.
97
+
The [`Timing-Allow-Origin` HTTP header](https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/Timing-Allow-Origin) allows for more precise time measurements.
<!-- do not enable diagnostics in production, as it has a negative performance impact -->
105
+
<PropertyGroup>
106
+
<EnableDiagnostics>true</EnableDiagnostics>
107
+
<MetricsSupport>true</MetricsSupport>
108
+
<EventSourceSupport>true</EventSourceSupport>
109
+
</PropertyGroup>
100
110
```
101
111
102
-
To view the trace, see [Use EventPipe to trace your .NET application](/dotnet/core/diagnostics/eventpipe#use-eventpipe-to-trace-your-net-application).
112
+
> [!WARNING]
113
+
> Don't enable diagnostics in production because it has a negative performance impact.
103
114
104
-
## GC (Garbage Collector) dumps
115
+
Build the app with the `wasm-tools` workload.
105
116
106
-
The [`dotnet-gcdump` (`collect`/convert` options)](/dotnet/core/diagnostics/dotnet-gcdump) global tool collects GC (Garbage Collector) dumps of live .NET processes using [EventPipe](/dotnet/core/diagnostics/eventpipe).
117
+
Open the app in a browser and navigate to problematic pages or components.
107
118
108
-
Collect a GC (Garbage Collector) dump of the live .NET process with `collectGcDump`:
119
+
Start colllecting metrics for 60 seconds by calling the `collectMetrics` JavaScript API:
To view the captured GC dump, see [View the GC dump captured from dotnet-gcdump](/dotnet/core/diagnostics/dotnet-gcdump#view-the-gc-dump-captured-from-dotnet-gcdump).
125
+
Call the preceding API from either a browser devoloper tools console or JavaScript code of the app.
115
126
116
-
## Counters trace
127
+
After the predefined period, the browser downloads a `.nettrace` file into a local folder. To view the `.nettrace` file, use Visual Studio or PrefView.
117
128
118
-
[`dotnet-counters collect`](/dotnet/core/diagnostics/dotnet-counters) is a performance monitoring tool for ad-hoc health monitoring and first-level performance investigation.
129
+
For more information, see [Use EventPipe to trace your .NET application](/dotnet/core/diagnostics/eventpipe#use-eventpipe-to-trace-your-net-application).
119
130
120
-
Collect diagnostic counters for 60 seconds with `collectPerfCounters(durationSeconds)`:
131
+
## MSBuild properties that enable diagnostic integration
Property | Default | Set value to… | Description
134
+
--- | :---: | :---: | ---
135
+
`<EnableDiagnostics>` | `false` | `true` | Enables support for WebAssembly performance tracing.
136
+
`<WasmPerformanceInstrumentation>` | No value | See table† | Enables instrumentation necessary for the sampling profiler. The property follows the :::no-loc text="callspec"::: syntax. †For permissible values, see the following table.
137
+
`<MetricsSupport>` | `false` | `true` | Enables `System.Diagnostics.Metrics` support. For more information, see the [`System.Diagnostics.Metrics` namespace](/dotnet/api/system.diagnostics.metrics).
138
+
`<EventSourceSupport>` | `false`| `true` | Enables `EventPipe` support. For more information, see [Diagnostics and instrumentation: Observability and telemetry](/dotnet/core/deploying/native-aot/diagnostics#observability-and-telemetry).
139
+
140
+
The following table describes permissable `<WasmPerformanceInstrumentation>` values.
141
+
142
+
`<WasmPerformanceInstrumentation>` value | Description
143
+
--- | ---
144
+
`all` | All assemblies
145
+
`program` | Entry point assembly
146
+
`{ASSEMBLY}` | Specifies an assembly (`{ASSEMBLY}`)
147
+
`M:Type:{METHOD}` | Specifies a method (`{METHOD}`)
148
+
`N:{NAMESPACE}` | Specifies a namespace (`{NAMESPACE}`)
149
+
`T:{TYPE}` | Specifies a type (`{TYPE}`)
150
+
`+EXPR` | Includes expression
151
+
`-EXPR` | Excludes expression
152
+
153
+
Your code should yield to main browser loop often to allow the trace to be collected. When executing long running loops, the internal diagnostic buffers could overflow.
125
154
126
-
To view the trace, see [Use EventPipe to trace your .NET application](/dotnet/core/diagnostics/eventpipe#use-eventpipe-to-trace-your-net-application).
155
+
**Enabling profilers and diagnostic tools has negative size and performance impacts, so don't publish an app for production with profilers enabled.**
127
156
128
157
## Additional resources
129
158
159
+
*[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).
130
160
*[What diagnostic tools are available in .NET Core?](/dotnet/core/diagnostics/)
0 commit comments