Skip to content

Commit c10694a

Browse files
committed
chore: Add log profiler docs
1 parent 5665edf commit c10694a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/mono/wasm/features.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,48 @@ import { dotnet } from './dotnet.js'
426426
await dotnet.withConfig({browserProfilerOptions: {}}).run();
427427
```
428428

429+
### Log Profiling for Memory Troubleshooting
430+
431+
You can enable integration with browser profiler via following elements in your .csproj:
432+
433+
```xml
434+
<PropertyGroup>
435+
<WasmProfilers>log;</WasmProfilers>
436+
</PropertyGroup>
437+
```
438+
439+
In simple browser template, you can add following to your `main.js`
440+
441+
```javascript
442+
import { dotnet } from './dotnet.js'
443+
await dotnet.withConfig({ logProfilerOptions: { configuration: "log:alloc,output=output.mlpd" }}).run();
444+
```
445+
446+
In order to trigger a heap shot, add the following:
447+
448+
```csharp
449+
using System.Runtime.CompilerServices;
450+
451+
namespace Mono.Profiler.Log
452+
{
453+
/// <summary>
454+
/// Internal calls to match with https://github.com/dotnet/runtime/blob/release/6.0/src/mono/mono/profiler/log.c#L4061-L4097
455+
/// </summary>
456+
internal class LogProfiler
457+
{
458+
[MethodImplAttribute(MethodImplOptions.InternalCall)]
459+
public extern static void TriggerHeapshot();
460+
461+
[DllImport("__Native")]
462+
public extern static private void mono_profiler_flush_log();
463+
}
464+
}
465+
```
466+
467+
Invoke `LogProfiler.TriggerHeapshot()` from your code in order to create a memory heap shot, then invoke `mono_profiler_flush_log` in order to flush the contents of the profile to the VFS.
468+
469+
You can download the mpld file to analyze it.
470+
429471
### Diagnostic tools
430472

431473
We have initial implementation of diagnostic server and [event pipe](https://learn.microsoft.com/dotnet/core/diagnostics/eventpipe)

0 commit comments

Comments
 (0)