Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[android] build and ship libmono-profiler-aot.so #57511

Closed

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Aug 16, 2021

Context: xamarin/xamarin-android#6171
Fixes: #56989

In order for the Android workload to be able to record
.aotprof/.aotprofile files, we need libmono-profiler-aot.so
to be available. Down the road this feature could be provided by the
Mono diagnostics component, but will probably not happen in .NET 6.

These changes build libmono-profiler-aot.so for Android, and includes
it in the Microsoft.NETCore.App.Runtime.Mono.android-* runtime packs.
In the Android workload's MSBuild targets we exclude this native library
unless the app is configured to record an AOT profile.

I also included in CMakeLists.txt:

target_compile_definitions(mono-profiler-aot PRIVATE -DMONO_DLL_EXPORT)

Otherwise, the AOT profiler cannot be loaded:

08-12 16:01:39.817  3003  3003 I monodroid-assembly: Trying to load shared library '/data/app/com.microsoft.net6.helloandroid-4u8tNHoPAh4zSZMaf2FsnA==/lib/x86_64/libmono-profiler-aot.so'
08-12 16:01:39.818  3003  3003 W monodroid: Looking for profiler init symbol 'mono_profiler_init_aot'? 0x0
08-12 16:01:39.818  3003  3003 W monodroid: The 'aot' profiler wasn't found in the main executable nor could it be loaded from 'libmono-profiler-aot.so'.

With these changes, I can successfully record an AOT profile on Android:

Reading from '127.0.0.1:9999'...
Read 4096 bytes...
...
Read 2671 bytes...
Read total 72303 bytes...
Summary:
        Modules:          8
        Types:          197
        Methods:        910
Going to write the profile to 'custom.aprof'

When using the profile, I get improved startup times:

08-12 16:56:33.940  1624  1874 I ActivityTaskManager: Displayed com.microsoft.net6.helloandroid/crc6490bfc84a0f5dff7a.MainActivity: +217ms

Context: xamarin/xamarin-android#6171
Fixes: dotnet#56989

In order for the Android workload to be able to record
`.aotprof`/`.aotprofile` files, we need `libmono-profiler-aot.so`
to be available. Down the road this feature could be provided by the
Mono diagnostics component, but will probably not happen in .NET 6.

These changes build `libmono-profiler-aot.so` for Android, and includes
it in the `Microsoft.NETCore.App.Runtime.Mono.android-*` runtime packs.
In the Android workload's MSBuild targets we exclude this native library
unless the app is configured to record an AOT profile.

I also included in `CMakeLists.txt`:

    target_compile_definitions(mono-profiler-aot PRIVATE -DMONO_DLL_EXPORT)

Otherwise, the AOT profiler cannot be loaded:

    08-12 16:01:39.817  3003  3003 I monodroid-assembly: Trying to load shared library '/data/app/com.microsoft.net6.helloandroid-4u8tNHoPAh4zSZMaf2FsnA==/lib/x86_64/libmono-profiler-aot.so'
    08-12 16:01:39.818  3003  3003 W monodroid: Looking for profiler init symbol 'mono_profiler_init_aot'? 0x0
    08-12 16:01:39.818  3003  3003 W monodroid: The 'aot' profiler wasn't found in the main executable nor could it be loaded from 'libmono-profiler-aot.so'.

With these changes, I can successfully record an AOT profile on Android:

    Reading from '127.0.0.1:9999'...
    Read 4096 bytes...
    ...
    Read 2671 bytes...
    Read total 72303 bytes...
    Summary:
            Modules:          8
            Types:          197
            Methods:        910
    Going to write the profile to 'custom.aprof'

When using the profile, I get improved startup times:

    08-12 16:56:33.940  1624  1874 I ActivityTaskManager: Displayed com.microsoft.net6.helloandroid/crc6490bfc84a0f5dff7a.MainActivity: +217ms
@jonathanpeppers
Copy link
Member Author

jonathanpeppers commented Aug 16, 2021

Is there a build artifact I can double-check the contents of the Microsoft.NETCore.App.Runtime.Mono.android-* runtime packs?

I tried to find it, but there are 100+ artifacts.

@jonathanpeppers
Copy link
Member Author

Closing this, as we've gone the route of not supporting custom profiles in .NET 6. In some future release, support for custom profiles with the dotnet trace infrastructure is probably the way to go.

To record a profile now, I've setup a repo:

https://github.com/jonathanpeppers/android-profiled-aot

We setup premade profiles for dotnet new android and dotnet new maui that are shipped in each workload.

@dotnet dotnet locked as resolved and limited conversation to collaborators Nov 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for Android "Profiled AOT" in .NET 6
4 participants