Skip to content

Commit 2df0344

Browse files
[One .NET] Profiled AOT support
Fixes: dotnet#6053 This is still WIP. Still a few pieces missing on the dotnet/runtime to enable this: dotnet/runtime#56989 We will need a `libmono-profiler-aot.so` from dotnet/runtime to be able to record AOT profiles. For now, I could: 1. Use the `startup.aotprofile` we're already shipping in "legacy" Xamarin.Android. 2. Pass this in when `$(AndroidEnableProfiledAot)` is `true`. ~~ Results ~~ All tests: 1. Were running on a [Google Pixel 5][0], and 2. Enabled two architectures, arm64 and x86, and 3. **AOT time** was average of 10 runs with `-c Release -p:RunAOTCompilation=true`, with the`Activity: Displayed` time 4. **Profiled AOT time** was average of 10 runs with `-c Release -p:RunAOTCompilation=true -p:AndroidEnableProfiledAot=true` with the `Activity: Displayed` time. | Test | AOT time | Profiled AOT time | AOT apk size | Profiled AOT apk size | | ------------------- | ------------: | ----------------: | ------------: | --------------------: | | [HelloAndroid][1] | 00:00:00.246 | 00:00:00.288 | 12,151,755 | 9,161,675 | | [HelloMaui][2] | 00:00:00.619 | 00:00:01.131 | 43,442,233 | 19,992,633 | From these results, we see that Profiled AOT is AOT'ing *some* of the assemblies. We are not getting the best startup time yet, because some methods are still using the JIT: 08-06 14:12:34.985 30817 30817 D Mono : AOT: FOUND method Android.Runtime.JNIEnv:NewGlobalRef (intptr) [0x7ae3c8c620 - 0x7ae3c8c6a0 0x7ae3c9849c] 08-06 14:12:34.985 30817 30817 D Mono : AOT: NOT FOUND: intptr:op_Explicit (intptr). 08-06 14:12:34.985 30817 30817 D Mono : AOT: NOT FOUND: intptr:op_Explicit (int). 08-06 14:12:34.986 30817 30817 D Mono : AOT: FOUND method System.WeakReference`1:.ctor (T,bool) [0x7ae3d8c580 - 0x7ae3d8c5d0 0x7ae3ddaec1] 08-06 14:12:34.986 30817 30817 D Mono : AOT: FOUND method System.WeakReference`1:Create (T,bool) [0x7ae3d8c4c0 - 0x7ae3d8c580 0x7ae3ddaebd] 08-06 14:12:34.986 30817 30817 D Mono : AOT: NOT FOUND: System.Runtime.InteropServices.GCHandle:Alloc (object,System.Runtime.InteropServices.GCHandleType). 08-06 14:12:34.986 30817 30817 D Mono : AOT: NOT FOUND: System.Runtime.InteropServices.GCHandle:Alloc (object,System.Runtime.InteropServices.GCHandleType). 08-06 14:12:34.986 30817 30817 D Mono : AOT: NOT FOUND: System.Runtime.InteropServices.GCHandle:.ctor (object,System.Runtime.InteropServices.GCHandleType). Overall, seems promising, though. [0]: store.google.com/us/product/pixel_5_specs?hl=en-US [1]: dotnet/maui-samples@7144604/HelloAndroid [2]: dotnet/maui-samples@7144604/HelloMaui
1 parent 2866832 commit 2df0344

File tree

5 files changed

+8
-20
lines changed

5 files changed

+8
-20
lines changed

build-tools/create-packs/Microsoft.Android.Sdk.proj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ core workload SDK packs imported by WorkloadManifest.targets.
7474
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\Microsoft.Android.Sdk\Sdk\**" PackagePath="Sdk" />
7575
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Microsoft.Android.Sdk.ILLink\PreserveLists\**" PackagePath="PreserveLists" />
7676
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\Microsoft.Android.Sdk\targets\**" PackagePath="targets" />
77+
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\dotnet.aotprofile" PackagePath="targets" />
7778
<_PackageFiles Include="$(IntermediateOutputPath)UnixFilePermissions.xml" PackagePath="data" Condition=" '$(HostOS)' != 'Windows' " />
7879
<None Include="$(MSBuildThisFileDirectory)SignList.xml" CopyToOutputDirectory="PreserveNewest" />
7980
</ItemGroup>

build-tools/installers/create-installers.targets

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@
116116
<ItemGroup>
117117
<_MSBuildFiles Include="$(MSBuildSrcDir)\android-support-multidex.jar" />
118118
<_MSBuildFiles Include="$(MSBuildSrcDir)\apksigner.jar" />
119-
<_MSBuildFiles Include="$(MSBuildSrcDir)\aprofutil.exe" ExcludeFromAndroidNETSdk="true" />
120-
<_MSBuildFiles Include="$(MSBuildSrcDir)\aprofutil.pdb" ExcludeFromAndroidNETSdk="true" />
119+
<_MSBuildFiles Include="$(MSBuildSrcDir)\aprofutil.exe" />
120+
<_MSBuildFiles Include="$(MSBuildSrcDir)\aprofutil.pdb" />
121121
<_MSBuildFiles Include="$(MSBuildSrcDir)\cil-strip.exe" ExcludeFromAndroidNETSdk="true" />
122122
<_MSBuildFiles Include="$(MSBuildSrcDir)\cil-strip.pdb" ExcludeFromAndroidNETSdk="true" />
123123
<_MSBuildFiles Include="$(MSBuildSrcDir)\class-parse.exe" ExcludeFromAndroidNETSdk="true" />
@@ -355,7 +355,7 @@
355355
<_MSBuildFilesUnixSignAndHarden Include="$(MSBuildSrcDir)\$(HostOS)\ndk\x86_64-linux-android-strip" />
356356
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\illinkanalyzer" Permission="755" />
357357
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\jit-times" Permission="755" />
358-
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\aprofutil" ExcludeFromAndroidNETSdk="true" />
358+
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\aprofutil" Permission="755" />
359359
<_MSBuildFilesUnixSignAndHarden Include="$(MSBuildSrcDir)\$(HostOS)\mono" ExcludeFromAndroidNETSdk="true" />
360360
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\mono.config" />
361361
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\mono-symbolicate" ExcludeFromAndroidNETSdk="true" />

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ They run in a context of an inner build with a single $(RuntimeIdentifier).
6969
TempDirectory="$([MSBuild]::EnsureTrailingSlash($(_AotOutputDirectory)))%(FileName)"
7070
AotArguments="$(_AotArguments),temp-path=$([System.IO.Path]::GetFullPath(%(_MonoAOTAssemblies.TempDirectory)))"
7171
/>
72+
<_AotProfiles Include="$(MSBuildThisFileDirectory)dotnet.aotprofile" Condition=" '$(AndroidEnableProfiledAot)' == 'true' " />
7273
</ItemGroup>
7374
<MakeDir Directories="$(IntermediateOutputPath)aot\;@(_MonoAOTAssemblies->'%(TempDirectory)')" />
7475
<MonoAOTCompiler
7576
Assemblies="@(_MonoAOTAssemblies)"
7677
CompilerBinaryPath="$(_MonoAOTCompilerPath)"
78+
AotProfilePath="@(_AotProfiles)"
7779
DisableParallelAot="$(_DisableParallelAot)"
7880
LibraryFormat="So"
7981
Mode="$(AndroidAotMode)"
Binary file not shown.

src/monodroid/jni/monodroid-glue.cc

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,6 @@ MonodroidRuntime::set_trace_options (void)
15671567
mono_jit_set_trace_options (value.get ());
15681568
}
15691569

1570-
#if defined (NET6)
15711570
inline void
15721571
MonodroidRuntime::set_profile_options ()
15731572
{
@@ -1582,23 +1581,10 @@ MonodroidRuntime::set_profile_options ()
15821581
value.assign (prop_value);
15831582
}
15841583

1584+
#if defined (NET6)
15851585
// setenv(3) makes copies of its arguments
15861586
setenv ("DOTNET_DiagnosticPorts", value.get (), 1);
1587-
}
1588-
#else // def NET6
1589-
inline void
1590-
MonodroidRuntime::set_profile_options ()
1591-
{
1592-
// We want to avoid dynamic allocation, thus let’s create a buffer that can take both the property value and a
1593-
// path without allocation
1594-
dynamic_local_string<SENSIBLE_PATH_MAX + PROPERTY_VALUE_BUFFER_LEN> value;
1595-
{
1596-
dynamic_local_string<PROPERTY_VALUE_BUFFER_LEN> prop_value;
1597-
if (androidSystem.monodroid_get_system_property (Debug::DEBUG_MONO_PROFILE_PROPERTY, prop_value) == 0)
1598-
return;
1599-
1600-
value.assign (prop_value.get (), prop_value.length ());
1601-
}
1587+
#endif // def NET6
16021588

16031589
constexpr char OUTPUT_ARG[] = "output=";
16041590
constexpr size_t OUTPUT_ARG_LEN = sizeof(OUTPUT_ARG) - 1;
@@ -1673,7 +1659,6 @@ MonodroidRuntime::set_profile_options ()
16731659
log_warn (LOG_DEFAULT, "Initializing profiler with options: %s", value.get ());
16741660
debug.monodroid_profiler_load (androidSystem.get_runtime_libdir (), value.get (), output_path.get ());
16751661
}
1676-
#endif // ndef NET6
16771662

16781663
/*
16791664
Disable LLVM signal handlers.

0 commit comments

Comments
 (0)