Skip to content

Profiling .NET MAUI Apps

Jonathan Peppers edited this page Jul 7, 2022 · 27 revisions

Other Platforms

For details about using dotnet trace on specific platforms, see:

Windows & PerfView

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:

PerfView Collect Screen

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:

PerfView CPU Stacks

Use the Flame Graph tab for a graphical view:

PerfView Flame Graph

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.

Controls.Sample.Profiling Sample

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=true

This 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.slnf

Physical Devices

If 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:9001

This 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.

Clone this wiki locally