Part of the docs are here:
But this expands on this, with a list of steps I do to profile .NET MAUI.
An overview:
- Build & Run the Device Tests on Catalyst
- Attach
dotnet-trace
with some settings - Run a memory-related test in the app, by clicking some UI
- Convert the resulting
.nettrace
file to a.gcdump
file - Open the
.gcdump
file in Visual Studio on Windows
I normally do this on Catalyst, just because the setup for dotnet-trace
is easier (dotnet-dsrouter
not needed). I end up with the same result as iOS mostly.
Once you've built MAUI, you can build the device tests:
$ ./bin/dotnet/dotnet build ~/src/maui/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj -f net7.0-maccatalyst
Then launch the app with $DOTNET_DiagnosticPorts
set:
$ DOTNET_DiagnosticPorts=~/my-dev-port,suspend ./src/Controls/tests/DeviceTests/bin/Debug/net7.0-maccatalyst/maccatalyst-x64/Microsoft.Maui.Controls.DeviceTests.app/Contents/MacOS/Microsoft.Maui.Controls.DeviceTests
Then launch dotnet-trace
:
$ dotnet-trace collect --diagnostic-port ~/my-dev-port --providers Microsoft-DotNETRuntimeMonoProfiler:0xC900001:4
At this point, switch to the Device Tests app and click the UI to run a memory-related test.
After it fails, press enter to stop dotnet-trace
. This will output a .nettrace
file in the current directory.
I have a network share mounted on my Windows machine mounted at /Volumes/Shared/
, so I actually run this:
$ dotnet-trace collect --diagnostic-port ~/my-dev-port --providers Microsoft-DotNETRuntimeMonoProfiler:0xC900001:4 -o /Volumes/Shared/my-dev-port-$(date +%s).nettrace
Then I move over to Windows to be able to open the .gcdump
file in Visual Studio
I use a tool from Filip Navara:
https://github.com/filipnavara/mono-gcdump
Where I do dotnet run -- convert C:\Shared\my-dev-port.nettrace
. It should output my-dev-port.gcdump
you can open in Visual Studio.
Ok yes, I do end up running
dotnet-trace
multiple times. One to get the app to launch as$DOTNET_DiagnosticPorts
causes it to pause, Ctrl+C the firstdotnet-trace
, then do one later at the point I want to record a memory dump.I think I normally use the same provider, though?
0xC900001:4