Support for the Mono AOT profiler in .NET 6+ Android applications
Use a Debug build, or set -p:AndroidEnableAotProfiler=true:
> dotnet add package Mono.AotProfiler.Android
> dotnet build -t:BuildAndStartAotProfiling
# Wait until app launches, or you navigate to a screen
> dotnet build -t:FinishAotProfiling
This will produce a custom.aprof in your project directory.
To use custom.aprof going forward, you can do:
<PropertyGroup>
<AndroidUseDefaultAotProfile>false</AndroidUseDefaultAotProfile>
<!-- Or if it is a .NET MAUI project -->
<MauiUseDefaultAotProfile>false</MauiUseDefaultAotProfile>
</PropertyGroup>
<ItemGroup>
<AndroidAotProfile Include="custom.aprof" />
</ItemGroup>-p:RunAOTCompilation=true and -p:AndroidEnableProfiledAot=true are
required to enable Profiled AOT. This should be enabled by default
for Release builds.
If you have issues recording an AOT profile, such as:
Xamarin.Android.Application.targets(53,5): error MSB3075: The command ""aprofutil" -s -v -p 9999 -o "custom.aprof"" exited with code 5. Please verify that you have sufficient rights to run this command.Check the following settings:
- If your app does not have the
INTERNETpermission, pass-p:AndroidNeedsInternetPermission=true.
The app will need to talk to aprofutil, so this permission is required.
- If you are running a
Releasebuild, make sure you have AOT turned off:-p:RunAOTCompilation=false
The Mono runtime can only report the list of JIT'd methods if the JIT is actually enabled. Turning off AOT is currently required when recording profiles.
-
$(AndroidMonoProfilers): list of Mono profilers to run. Defaults tocalls,alloc,nocounters. -
$(AndroidMonoProfilerOutput): temporary location to saveprofile.mlpdon the Android device or emulator. Defaults to/sdcard/Download/profile.mlpd. -
$(AndroidMonoProfilerEnvironmentFile): location of the generated@(AndroidEnvironment)file. Defaults to$(IntermediateOutputPath)Mono.Profiler.Android.env.
> dotnet build -c Release
> dotnet build -c Release samples/hellomaui/hellomaui.csproj -t:StartProfiling
> dotnet build -c Release samples/hellomaui/hellomaui.csproj -t:StopProfiling