-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Profiling .NET MAUI Apps
For details about using dotnet trace on specific platforms, see:
PerfView is probably the simplest way to profile a .NET MAUI application running on Windows. We recommend using a Release build with ReadyToRun enabled. See our Windows Publishing Documentation for details about building a Release version of your app.
Begin by selecting the Collect > Collect menu. For a project named hellomaui, you can filter on hellomaui.exe:

Click Start Collection and manually launch your app.
Click Stop Collection when your app has launched and reached the point you are finished profiling.
Open CPU Stacks to view timing information of methods inside your app:

Use the Flame Graph tab for a graphical view:

You can also do File > Save View As to save the file in SpeedScope format. This allows you to open the file in https://speedscope.app/ as we recommend for iOS/Android projects.
To build the profiling app from source, use the local dotnet instance:
./bin/dotnet/dotnet build src/Controls/samples/Controls.Sample.Profiling -f net6.0-android -t:run -c Release -p:IsEmulator=trueThis builds the app and runs it on the device/emulator.
The IsEmulator property can be used to control the environment variables of the app. The main reason is that it uses different ports on the Android device depending on whether it is a local emulator or a connected device.
You may have to build the build tasks for the first run:
./bin/dotnet/dotnet build Microsoft.Maui.BuildTasks-net6.slnfIf a physical device is to be used, then there needs to be a port opened on the Android device via adb:
adb reverse tcp:9000 tcp:9001This commands forwards port 9000 from the device to port 9001 on the host machine.
The same run command can be used for emulators, except that the IsEmulator property should be set to false.