Skip to content

Commit c9cd030

Browse files
[One .NET] fix libmono-profiler-aot.so recording
I found when I went to update the AOT profile in .NET MAUI: https://github.com/jonathanpeppers/android-profiled-aot dotnet/maui#4355 The profiler crashed with: 01-27 11:10:16.119 28922 28922 W monodroid: Creating public update directory: `/data/user/0/com.androidaot.MauiApp1/files/.__override__` ... 01-27 11:10:16.119 28922 28922 W monodroid: Initializing profiler with options: aot:port=9999output=/data/user/0/com.androidaot.MauiApp1/files/.__override__/profile.aotprofile 01-27 11:10:16.119 28922 28922 W monodroid: Looking for profiler init symbol 'mono_profiler_init_aot'? 0x7325b6355c 01-27 11:10:16.119 28922 28922 E mono-prof: Could not create AOT profiler output file 'output.aotprofile': Read-only file system But the directory was writeable? adb shell run-as com.androidaot.MauiApp1 touch files/.__override__/foo After some digging, it turned out appending `,` to this line fixed the issue: https://github.com/xamarin/xamarin-android/blob/b7a368a27667c69117f64be81050403f2d5c8560/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Application.targets#L45 What happened was we lost a `,` somewhere in this commit: dotnet@f73a323 To fix this: 1. Prepend a `,` 2. I found a way to actually enable tests for Profiled AOT in .NET 6 by downloading binaries from my Github repo.
1 parent b7a368a commit c9cd030

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

build-tools/automation/azure-pipelines.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ variables:
4343
- name: RunAllTests
4444
value: $[or(eq(variables['XA.RunAllTests'], true), eq(variables['IsMonoBranch'], true))]
4545
- name: DotNetNUnitCategories
46-
value: '& TestCategory != DotNetIgnore & TestCategory != HybridAOT & TestCategory != ProfiledAOT & TestCategory != MkBundle & TestCategory != MonoSymbolicate & TestCategory != PackagesConfig & TestCategory != StaticProject & TestCategory != Debugger & TestCategory != SystemApplication'
46+
value: '& TestCategory != DotNetIgnore & TestCategory != HybridAOT & TestCategory != MkBundle & TestCategory != MonoSymbolicate & TestCategory != PackagesConfig & TestCategory != StaticProject & TestCategory != Debugger & TestCategory != SystemApplication'
4747
- ${{ if eq(variables['Build.DefinitionName'], 'Xamarin.Android-Private') }}:
4848
- group: AzureDevOps-Artifact-Feeds-Pats
4949
- group: DotNet-MSRC-Storage

src/monodroid/jni/monodroid-glue.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,7 @@ MonodroidRuntime::set_profile_options ()
16861686
.append (AOT_EXT);
16871687

16881688
value
1689+
.append (",")
16891690
.append (OUTPUT_ARG)
16901691
.append (output_path.get (), output_path.length ());
16911692
}

tests/MSBuildDeviceIntegration/Tests/AotProfileTests.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using NUnit.Framework;
1+
using NUnit.Framework;
22
using System;
33
using System.IO;
4+
using System.Net;
45
using Xamarin.ProjectTools;
56

67
namespace Xamarin.Android.Build.Tests
@@ -26,6 +27,7 @@ public void BuildBasicApplicationAndAotProfileIt ()
2627
IsRelease = true,
2728
};
2829
proj.SetAndroidSupportedAbis ("armeabi-v7a", "x86");
30+
AddDotNetProfilerNativeLibraries (proj);
2931
var port = 9000 + new Random ().Next (1000);
3032
proj.SetProperty ("AndroidAotProfilerPort", port.ToString ());
3133
proj.AndroidManifest = string.Format (PermissionManifest, proj.PackageName);
@@ -40,5 +42,33 @@ public void BuildBasicApplicationAndAotProfileIt ()
4042
FileAssert.Exists (customProfile);
4143
}
4244
}
45+
46+
void AddDotNetProfilerNativeLibraries (XamarinAndroidApplicationProject proj)
47+
{
48+
// TODO: only needed in .NET 6+
49+
// See https://github.com/dotnet/runtime/issues/56989
50+
if (!Builder.UseDotNet)
51+
return;
52+
53+
// Files are built from dotnet/runtime & stored at:
54+
const string github = "https://github.com/jonathanpeppers/android-profiled-aot";
55+
56+
string extension = IsWindows ? ".exe" : "";
57+
proj.Sources.Add (new BuildItem ("None", $"aprofutil{extension}") {
58+
WebContent = $"{github}/raw/main/binaries/aprofutil{extension}"
59+
});
60+
proj.Sources.Add (new BuildItem ("None", "Mono.Profiler.Log.dll") {
61+
WebContent = $"{github}/raw/main/binaries/Mono.Profiler.Log.dll"
62+
});
63+
proj.SetProperty ("AProfUtilToolPath", "$(MSBuildThisFileDirectory)");
64+
65+
foreach (var rid in proj.GetProperty (KnownProperties.RuntimeIdentifiers).Split (';')) {
66+
//NOTE: each rid has the same file name, so using WebClient directly
67+
var bytes = new WebClient ().DownloadData ($"{github}/raw/main/binaries/{rid}/libmono-profiler-aot.so");
68+
proj.Sources.Add (new AndroidItem.AndroidNativeLibrary ($"{rid}\\libmono-profiler-aot.so") {
69+
BinaryContent = () => bytes,
70+
});
71+
}
72+
}
4373
}
4474
}

0 commit comments

Comments
 (0)