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

[WIP] new Profiled AOT support #7216

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Jul 28, 2022

Context: dotnet/runtime#71787
Context: https://dev.azure.com/dnceng/public/_artifacts/feed/7.0.100-preview.7.22377.5-nonshipping/NuGet/dotnet-pgo/overview/7.0.0-preview.7.22375.6

  1. Record a .nettrace file:
adb reverse tcp:9000 tcp:9001
adb shell setprop debug.mono.profile '127.0.0.1:9000,suspend'
dotnet-dsrouter client-server -tcps 127.0.0.1:9001 -ipcc /tmp/maui-app --verbose debug
dotnet-trace collect --diagnostic-port /tmp/maui-app --providers Microsoft-Windows-DotNETRuntime:0x1F000080018:5 --output android.nettrace
  1. Install dotnet-pgo:
dotnet tool install -g dotnet-pgo --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/7.0.100-preview.7.22377.5-nonshipping/nuget/v3/index.json --version 7.0.0-preview.7.22375.6
  1. Convert to .mibc:
dotnet-pgo create-mibc --trace android.nettrace  --output android.mibc --reference "src/profiled-aot/obj/android/obj/Release/net7.0-android/android-arm64/linked/shrunk/*.dll"

To test this, I made a dotnet new android app and added:

<PropertyGroup>
  <AndroidUseDefaultAotProfile>false</AndroidUseDefaultAotProfile>
</PropertyGroup>
<ItemGroup>
  <AndroidMibcProfile Include="android.mibc" />
</ItemGroup>

Open Questions

  1. If you have to use a weird feed for dotnet-pgo is that OK? Are we
    not recommending users record their own profiles yet?

  2. How do we make an MSBuild target to make recording profiles easier?
    I have not been able to programmatically control dotnet-trace in
    a nice way.

For example:

$ dotnet build -t:BuildAndStartTracing -c Release -r android-arm64

Do stuff in the app, then:

$ dotnet build -t:FinishTracing

See: #7087

  1. How do we get a list of method names from either the .nettrace or
    .mibc file? We track the methods in a text file in source control.

See:

https://github.com/xamarin/xamarin-android/blob/9b378e578fa4ff878281da113388f05a4027d484/src/profiled-aot/dotnet.aotprofile.txt
https://github.com/dotnet/maui/blob/08ca198145f27af96e0738853c341dbf33d47804/.nuspec/maui.aotprofile.txt

  1. Is @(AndroidMibcProfile) the right name for the item group? Or
    should we use @(AndroidAotProfile) and just detect the .mibc
    file extension? .mibc files could pass mibc-profile= to the AOT
    compiler.

  2. Is it OK if all methods are present in the .mibc file? With AOT
    profiles we did:

$ aotprofile-tool -sd --filter-module="^(?!android).+" custom.aprof -o dotnet.aotprofile

This removed all methods from android.dll, which is the main
assembly of the app recorded.

https://github.com/radekdoulik/aotprofile-tool

TODO

Some things TODO even after the above questions are answered:

  • ship a .mibc file in our workload, setup defaults to use it
  • update src/profiled-aot/build.proj to record .mibc
    profiles. I just did them manually right now.
  • update dotnet/maui after this goes in

Sample project with .mibc file: doo.zip

Context: dotnet/runtime#71787
Context: https://dev.azure.com/dnceng/public/_artifacts/feed/7.0.100-preview.7.22377.5-nonshipping/NuGet/dotnet-pgo/overview/7.0.0-preview.7.22375.6

1. Record a `.nettrace` file:

    adb reverse tcp:9000 tcp:9001
    adb shell setprop debug.mono.profile '127.0.0.1:9000,suspend'
    dotnet-dsrouter client-server -tcps 127.0.0.1:9001 -ipcc /tmp/maui-app --verbose debug
    dotnet-trace collect --diagnostic-port /tmp/maui-app --providers Microsoft-Windows-DotNETRuntime:0x1F000080018:5 --output android.nettrace

2. Install `dotnet-pgo`:

    dotnet tool install -g dotnet-pgo --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/7.0.100-preview.7.22377.5-nonshipping/nuget/v3/index.json --version 7.0.0-preview.7.22375.6

3. Convert to `.mibc`:

    dotnet-pgo create-mibc --trace android.nettrace  --output android.mibc --reference "src/profiled-aot/obj/android/obj/Release/net7.0-android/android-arm64/linked/shrunk/*.dll"

To test this, I made a `dotnet new android` app and added:

    <PropertyGroup>
      <AndroidUseDefaultAotProfile>false</AndroidUseDefaultAotProfile>
    </PropertyGroup>
    <ItemGroup>
      <AndroidMibcProfile Include="android.mibc" />
    </ItemGroup>

~~ Open Questions ~~

1. If you have to use a weird feed for `dotnet-pgo` is that OK? Are we
   not recommending users record their own profiles yet?

2. How do we make an MSBuild target to make recording profiles easier?
   I have not been able to programmatically control `dotnet-trace` in
   a nice way.

For example:

    $ dotnet build -t:BuildAndStartTracing -c Release -r android-arm64

Do stuff in the app, then:

    $ dotnet build -t:FinishTracing

See:

dotnet#7087

3. How do we get a list of method names from either the `.nettrace` or
   `.mibc` file? We track the methods in a text file in source control.

See:

https://github.com/xamarin/xamarin-android/blob/9b378e578fa4ff878281da113388f05a4027d484/src/profiled-aot/dotnet.aotprofile.txt
https://github.com/dotnet/maui/blob/08ca198145f27af96e0738853c341dbf33d47804/.nuspec/maui.aotprofile.txt

4. Is `@(AndroidMibcProfile)` the right name for the item group? Or
   should we use `@(AndroidAotProfile)` and just detect the `.mibc`
   file extension? `.mibc` files could pass `mibc-profile=` to the AOT
   compiler.

5. Is it OK if all methods are present in the `.mibc` file? With AOT
   profiles we did:

    aotprofile-tool -sd --filter-module="^(?!android).+" custom.aprof -o dotnet.aotprofile

This removed all methods from `android.dll`, which is the main
assembly of the app recorded.

https://github.com/radekdoulik/aotprofile-tool

~~ TODO ~~

Some things TODO even after the above questions are answered:

- [ ] - ship a `.mibc` file in our workload, setup defaults to use it
- [ ] - update `src/profiled-aot/build.proj` to record `.mibc`
  profiles. I just did them manually right now.
- [ ] - update dotnet/maui after this goes in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant