diff --git a/build-tools/create-packs/Microsoft.Android.Sdk.proj b/build-tools/create-packs/Microsoft.Android.Sdk.proj
index 63beba4ef40..caa41f523c7 100644
--- a/build-tools/create-packs/Microsoft.Android.Sdk.proj
+++ b/build-tools/create-packs/Microsoft.Android.Sdk.proj
@@ -74,6 +74,7 @@ core workload SDK packs imported by WorkloadManifest.targets.
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\Microsoft.Android.Sdk\Sdk\**" PackagePath="Sdk" />
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Microsoft.Android.Sdk.ILLink\PreserveLists\**" PackagePath="PreserveLists" />
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\Microsoft.Android.Sdk\targets\**" PackagePath="targets" />
+ <_PackageFiles Include="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\dotnet.aotprofile" PackagePath="targets" />
<_PackageFiles Include="$(IntermediateOutputPath)UnixFilePermissions.xml" PackagePath="data" Condition=" '$(HostOS)' != 'Windows' " />
diff --git a/build-tools/installers/create-installers.targets b/build-tools/installers/create-installers.targets
index d05347d4e97..85e7a17c05e 100644
--- a/build-tools/installers/create-installers.targets
+++ b/build-tools/installers/create-installers.targets
@@ -116,8 +116,8 @@
<_MSBuildFiles Include="$(MSBuildSrcDir)\android-support-multidex.jar" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\apksigner.jar" />
- <_MSBuildFiles Include="$(MSBuildSrcDir)\aprofutil.exe" ExcludeFromAndroidNETSdk="true" />
- <_MSBuildFiles Include="$(MSBuildSrcDir)\aprofutil.pdb" ExcludeFromAndroidNETSdk="true" />
+ <_MSBuildFiles Include="$(MSBuildSrcDir)\aprofutil.exe" />
+ <_MSBuildFiles Include="$(MSBuildSrcDir)\aprofutil.pdb" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\cil-strip.exe" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\cil-strip.pdb" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\class-parse.exe" ExcludeFromAndroidNETSdk="true" />
@@ -355,7 +355,7 @@
<_MSBuildFilesUnixSignAndHarden Include="$(MSBuildSrcDir)\$(HostOS)\ndk\x86_64-linux-android-strip" />
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\illinkanalyzer" Permission="755" />
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\jit-times" Permission="755" />
- <_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\aprofutil" ExcludeFromAndroidNETSdk="true" />
+ <_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\aprofutil" Permission="755" />
<_MSBuildFilesUnixSignAndHarden Include="$(MSBuildSrcDir)\$(HostOS)\mono" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\mono.config" />
<_MSBuildFilesUnix Include="$(MSBuildSrcDir)\$(HostOS)\mono-symbolicate" ExcludeFromAndroidNETSdk="true" />
diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets
index e6ec675b479..bd26c120ba5 100644
--- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets
+++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets
@@ -69,11 +69,13 @@ They run in a context of an inner build with a single $(RuntimeIdentifier).
TempDirectory="$([MSBuild]::EnsureTrailingSlash($(_AotOutputDirectory)))%(FileName)"
AotArguments="$(_AotArguments),temp-path=$([System.IO.Path]::GetFullPath(%(_MonoAOTAssemblies.TempDirectory)))"
/>
+
diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ProcessNativeLibraries.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ProcessNativeLibraries.cs
index f853c2c98b2..91eb9fbe2c1 100644
--- a/src/Xamarin.Android.Build.Tasks/Tasks/ProcessNativeLibraries.cs
+++ b/src/Xamarin.Android.Build.Tasks/Tasks/ProcessNativeLibraries.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Android.Build.Tasks;
@@ -29,6 +30,8 @@ public class ProcessNativeLibraries : AndroidTask
public bool IncludeDebugSymbols { get; set; }
+ public string [] AndroidEmbedProfilers { get ; set; }
+
[Output]
public ITaskItem [] OutputLibraries { get; set; }
@@ -45,6 +48,8 @@ public override bool RunTask ()
}
var output = new List (InputLibraries.Length);
+ bool includeAotProfiler = AndroidEmbedProfilers != null &&
+ AndroidEmbedProfilers.Any (p => string.Equals ("aot", p, StringComparison.OrdinalIgnoreCase) || string.Equals ("all", p, StringComparison.OrdinalIgnoreCase));
foreach (var library in InputLibraries) {
var abi = AndroidRidAbiHelper.GetNativeLibraryAbi (library);
@@ -80,6 +85,11 @@ public override bool RunTask ()
if (!wantedComponents.Contains (fileName)) {
continue;
}
+ } else if (string.Equals ("libmono-profiler-aot", fileName, StringComparison.OrdinalIgnoreCase)) {
+ if (!includeAotProfiler) {
+ Log.LogDebugMessage ($"Excluding '{library.ItemSpec}'. Not included in $(AndroidEmbedProfilers).");
+ continue;
+ }
}
output.Add (library);
diff --git a/src/Xamarin.Android.Build.Tasks/dotnet.aotprofile b/src/Xamarin.Android.Build.Tasks/dotnet.aotprofile
new file mode 100644
index 00000000000..8986d2591eb
Binary files /dev/null and b/src/Xamarin.Android.Build.Tasks/dotnet.aotprofile differ
diff --git a/src/monodroid/jni/monodroid-glue.cc b/src/monodroid/jni/monodroid-glue.cc
index 9b1c56ee489..4a8565801e2 100644
--- a/src/monodroid/jni/monodroid-glue.cc
+++ b/src/monodroid/jni/monodroid-glue.cc
@@ -1567,7 +1567,6 @@ MonodroidRuntime::set_trace_options (void)
mono_jit_set_trace_options (value.get ());
}
-#if defined (NET6)
inline void
MonodroidRuntime::set_profile_options ()
{
@@ -1582,23 +1581,10 @@ MonodroidRuntime::set_profile_options ()
value.assign (prop_value);
}
+#if defined (NET6)
// setenv(3) makes copies of its arguments
setenv ("DOTNET_DiagnosticPorts", value.get (), 1);
-}
-#else // def NET6
-inline void
-MonodroidRuntime::set_profile_options ()
-{
- // We want to avoid dynamic allocation, thus let’s create a buffer that can take both the property value and a
- // path without allocation
- dynamic_local_string value;
- {
- dynamic_local_string prop_value;
- if (androidSystem.monodroid_get_system_property (Debug::DEBUG_MONO_PROFILE_PROPERTY, prop_value) == 0)
- return;
-
- value.assign (prop_value.get (), prop_value.length ());
- }
+#endif // def NET6
constexpr char OUTPUT_ARG[] = "output=";
constexpr size_t OUTPUT_ARG_LEN = sizeof(OUTPUT_ARG) - 1;
@@ -1673,7 +1659,6 @@ MonodroidRuntime::set_profile_options ()
log_warn (LOG_DEFAULT, "Initializing profiler with options: %s", value.get ());
debug.monodroid_profiler_load (androidSystem.get_runtime_libdir (), value.get (), output_path.get ());
}
-#endif // ndef NET6
/*
Disable LLVM signal handlers.