Skip to content

Perfetto integration #8899

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

Draft
wants to merge 81 commits into
base: main
Choose a base branch
from
Draft

Perfetto integration #8899

wants to merge 81 commits into from

Conversation

grendello
Copy link
Contributor

@grendello grendello commented Apr 24, 2024

Perfetto is a tracing/profiling system integrated into Android, that allows
application performance tracing within the context of entire operating system. This allows one to
see the full picture of how application performs within the larger environment, taking into account
contexts like GPU rendering time, windowing system compositing time, time spent sleeping in a thread etc.

.NET for Android includes support for recording several kinds of performace measurements using Perfetto:

  • Managed method invocation time
  • Class instantiation time
  • Assembly load time

These events are recorded together with other measurements supported by Perfetto itself and can be visualized
using the Perfetto UI (an offline in-browser JavaScript application). The UI also
supports converting the collected traces into other formats, including nettrace.

Perfetto support is not included in the .NET for Android runtime by default, since its inclusion increases
the runtime and APK size. In order to enable Perfetto support, it is necessary to set the "private" _AndroidEnablePerfetto
MSBuild property to true.

With that property set, the application can be used as usual, with Perfetto trace recording enabled at any
chosen point in time, using mechanisms external to .NET for Android and the application. The mechanisms are
described in detail on the following web pages:

  1. Quickstart: Record traces on Android
  2. Capture a system trace on a device

After recording the trace using whichever method, location of the trace file to download from device (e.g.
using adb pull)
can be determined by looking at the logcat output captured from the device. The location is logged by Android
component called Traceur, and looks similar to the entry below:

05-13 17:25:17.186  3705  9320 V Traceur : Saving perfetto trace to /data/local/traces/trace-raven-AP1A.240405.002-2024-05-13-17-25-16.perfetto-trace

grendello and others added 30 commits April 4, 2024 13:27
Changes: https://discourse.llvm.org/t/llvm-18-1-0-released/77448
Changes: https://discourse.llvm.org/t/llvm-18-1-1-released/77540
Changes: https://discourse.llvm.org/t/18-1-2-released/77821
Changes: https://discourse.llvm.org/t/18-1-3-released/78136

Changes interesting for us:

   * AArch64 backend
      * Added support for Cortex-A520, Cortex-A720 and Cortex-X4 CPUs.
      * Assembler/disassembler support has been added for 2023 architecture extensions.
      * Support has been added for Stack Clash Protection. During function frame creation
         and dynamic stack allocations, the compiler will issue memory accesses at regular
         intervals so that a guard area at the top of the stack can’t be skipped over.
   * x86 backend
       * The i128 type now matches GCC and clang’s __int128 type. This mainly benefits external
          projects such as Rust which aim to be binary compatible with C, but also fixes code
          generation where LLVM already assumed that the type matched and called into libgcc
          helper functions.

**Full Changelog**: dotnet/android-native-tools@L_17.0.6-7.2.1...L_18.1.3-8.0.0
Bumps [external/Java.Interop](https://github.com/xamarin/java.interop) from `651de42` to `e1c7832`.
- [Commits](dotnet/java-interop@651de42...e1c7832)

---
updated-dependencies:
- dependency-name: external/Java.Interop
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Updates the list of submodules that dependabot ignores when checking for
updates.  Repos which are no longer valid have been removed and recently
added xxhash repos have been added to this list.
* main:
  Bump to dotnet/installer@0bfd2dd757 9.0.100-preview.4.24208.2 (#8862)
  [ci] Update dependabot ignore list (#8864)
  Bump external/Java.Interop from `651de42` to `e1c7832` (#8836)
  Bumps LLVM to v18.1.3 and XA utils version to 8.0.0 (#8852)
* main:
  Don't use azureedge.net CDN (#8846)
Neither runtime nor other native libraries are built yet
Some libs build already. monodroid still not built.
* main:
  Bump to dotnet/installer@7380c301c1 9.0.100-preview.4.24215.2 (#8874)
  [Mono.Android] Commit baseline PublicAPI files for API-35 (#8840)
  Add a unit test to check environment processing (#8856)
* main:
  Bump external/xamarin-android-tools from `37d79c9` to `05f9a90` (#8869)
  Bump external/Java.Interop from `e1c7832` to `06214ff` (#8878)
...remove unused p/invoke + associated code (`monodroid_store_package_name`)
...fix endless recursion caused by a typo in `Util::ends_with` overload
...fix p/invoke include generation script
...update p/invoke dispatcher accordingly
To include `libxamarin-native-tracing.so`, one has to request it by
setting the `$(_AndroidEnableNativeStackTracing)` MSBuild property
to `true`
Using `std::source_location` we can now report on, well, source location
without having to resort to C macros.
* main:
  Bump to xamarin/xamarin-android-binutils/L_18.1.4-8.0.0@758d2e7 (#8885)
  [Mono.Android] Bind API-VanillaIceCream Beta 1 (#8891)
  [AndroidToolTask] Log tool output as error  (#8861)
  [Xamarin.Android.Build.Tasks] Remove "Xamarin" from messages (#8884)
  [Mono.Android] Bind API-VanillaIceCream Developer Preview 2 (#8741)
  Bump to dotnet/installer@22ffa42d6c 9.0.100-preview.4.24221.5 (#8887)
* main:
  Bump to xamarin/monodroid@a5742221b3 (#8893)
  Remove MonoArchive_BaseUri from Configurables.cs (#8890)
* main:
  [docs] Reorganize public Documentation (#8889)
  Bump external/Java.Interop from `06214ff` to `6cfa78c` (#8879)
  Localized file check-in by OneLocBuild Task (#8894)
  $(AndroidPackVersionSuffix)=preview.5; net9 is 34.99.0.preview.5 (#8896)
* main:
  [build] Bump $(AndroidNetPreviousVersion) to 34.0.95 (#8898)
@grendello grendello changed the title Dev/grendel/perfetto integration Perfetto integration Jun 4, 2024
@grendello grendello marked this pull request as ready for review June 4, 2024 10:56
* main: (26 commits)
  Make APK and shared library alignment configurable (#9046)
  [r8] update proguard rule to keep .NET runtime classes (#9044)
  Explicitly align to 4k (#9041)
  [trimming] preserve custom views and `$(AndroidHttpClientHandlerType)` (#8954)
  Ignore split configs when bundle config moves shared libraries to base.apk (#8987)
  Bump to dotnet/android-tools@1c09dcc (#9026)
  Bump to dotnet/java-interop@ccafbe6 (#9025)
  [Mono.Android-Tests] Fix repo URL in redirect tests (#9035)
  [ci] Update checkout path for nightly build (#9028)
  [ci] Fix android source path for MAUI test job (#9030)
  Link Code of Conduct (#9034)
  [ci] Update sdk-insertions trigger to manual only (#9029)
  Update java-interop and android-tools submodule mentions (#9023)
  LEGO: Merge pull request 9022
  [Xamarin.Android.Build.Tasks] fastdev works with aab files (#8990)
  Use new binutils URL (#9019)
  Localized file check-in by OneLocBuild Task: Build definition ID 17928: Build ID 9686669 (#9011)
  LEGO: Merge pull request 9015
  [api-merge] Update "constant" values to mirror latest API levels (#9004)
  [Mono.Android] Fix wrong value for `ApplicationExitInfoReason.Other` (#9003)
  ...
namespace xamarin::android {
namespace detail {
template<typename TMonoType>
concept SupportedMonoType = requires {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What odd syntax that requires { requires is a valid sequence of tokens. Wat?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not strictly required in this case, I just found it more expressive, but maybe the repetition does look weird. It represents a "nested requirement" which may make the concept a bit easier to read, instead of listing the requirements in the "main" constraint expression (which may take a form of, e.g., requires (TMonoType t, size_t some_size)), making it look less crammed. I'll remove the extra requires from here, since it isn't strictly necessary.

}

template<xamarin::android::PerfettoTrackId TTrack>
[[gnu::flatten]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::string name{};
const std::string_view *annotation_name = nullptr;

if constexpr (std::same_as<MonoAssembly, TMonoType>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One wonders why method overloads aren't valid/possible…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are both valid and possible, I just prefer this as a more compact form of the code. All the possible specializations are related here, are treated in the end in the same way and this way the code is drier than with overloads and easier to follow.

@jonpryor
Copy link
Contributor

Would be good to have instructions for how to update src-ThirdParty/perfetto/*: where do you get them from, etc.

grendello added 13 commits June 27, 2024 15:18
* main:
  Bump to dotnet/android-tools@9674590 (#9036)
  Bump to dotnet/android-libzipsharp@de57dccb (#9010)
  [Xamarin.Android.Build.Tasks] Support VS "Build Acceleration" (#9042)
  Bump to dotnet/sdk@ea9243f9cb 9.0.100-preview.7.24323.5 (#9031)
  Fix places still pointing to xamarin/xamarin-android (#9050)
  [xaprepare] skip download progress for `dotnet-install` script (#9053)
  $(AndroidPackVersionSuffix)=preview.7; net9 is 34.99.0.preview.7 (#9052)
* main:
  [tests] verify trimmer warnings where appropriate (#9076)
  Bump to jbevain/cecil@8c123e1 (#9078)
  [trimming] remove `$(NullabilityInfoContextSupport)` (#9069)
  [build] Bump `$(XABuildToolsVersion)`=35 (#9071)
  [ci] Move PR build to shared pool (#8854)
  Use AsyncTask from xamarin-android-tools (#9017)
  Bump to dotnet/sdk@02c06d398a 9.0.100-preview.7.24351.1 (#9067)
  [trimming] use public `$(MetricsSupport)` property (#9068)
  [ci] Update resourceManagement.yml (#9070)
  Bump to dotnet/android-api-docs@c14203771a (#8992)
  [trimming] remove `$(_AggressiveAttributeTrimming)` by default (#9062)
* main: (23 commits)
  Localized file check-in by OneLocBuild Task (#9129)
  [ci] Disable CodeQL on CI/PR pipelines (#9128)
  Refine 16k page alignment support (#9075)
  [build] fix `ConfigureLocalWorkload` target (#9124)
  Bump to NDK r27 (#9020)
  [ci] Use drop service for SDK insertion artifacts  (#9116)
  Fix up all mapping paths (#9121)
  [ci] Fix maestro publishing for stable packages (#9118)
  Bump to dotnet/sdk@2f14fea98b 9.0.100-preview.7.24367.21 (#9108)
  Missing androidx.window.[extensions|sidecar] warnings (#9085)
  [ci] Use sign-artifacts template for macOS signing (#9091)
  [ci] Use DotNetCoreCLI to sign macOS files (#9102)
  [ci] Disable CodeQL on macOS, Linux, non-main jobs (#9111)
  [tests] re-enable `JavaAbstractMethodTest` (#9097)
  [Microsoft.Android.Sdk.ILLink] preserve types with `IJniNameProviderAttribute` (#9099)
  [Mono.Android] Data sharing and Close() overrides (#9103)
  [AndroidManifest] Add `Android.App.PropertyAttribute` (#9016)
  [Mono.Android] Add support for AndroidMessageHandler ClientCertificates (#8961)
  [Mono.Android] Bind and enumify API-35 (#9043)
  Bump to dotnet/java-interop@7a058c0e (#9066)
  ...
* main:
  [trimming] remove our usage of `[Preserve]` (#9126)
  Bump lz4 to v1.10.0 (#9127)
* main:
  Native runtime reorganization (#9113)
* main:
  [native] Change name of static libraries in some cases (#9135)
  LEGO: Merge pull request 9134
* main:
  [Xamarin.Android.Build.Tasks] Fix `LogCodedWarning` usage (#9148)
  [xaprepare] Remove Mono as required component (#9144)
  $(AndroidPackVersionSuffix)=rc.1; net9 is 35.0.0-rc.1 (#9143)
  [monodroid] treat `LocalRefsAreIndirect` as always true (#9138)
  [Mono.Android] fix leaking lrefs in `TypeManager` (#9136)
  [ci] Ignore unsigned bundletool.jar content (#9139)
  Localized file check-in by OneLocBuild Task (#9140)
  [tests] fix 1,170 build warnings (#9137)
  LEGO: Merge pull request 9141
  Bump to xamarin/monodroid@d1d43ab161 (#9130)
@grendello grendello marked this pull request as draft July 26, 2024 09:21
@grendello grendello added this to the .NET 10 milestone Jul 26, 2024
* main:
  [Mono.Android] JavaCast<T>() should throw on unsupported types (#9145)
  Localized file check-in by OneLocBuild Task (#9149)
* main: (47 commits)
  Bump to dotnet/sdk@5642787dac 9.0.100-rc.2.24426.2 (#9247)
  LEGO: Merge pull request 9246
  Bump to 34.0.137 of the .NET 8 Android workload (#9243)
  Bump external/Java.Interop from `d30d554` to `51b784a` (#9241)
  Bump dotnet/android-tools@6575743 (#9235)
  Bump to mono/debugger-libs@d5664344 (#9238)
  [ci] Improve push_signed_nugets job condition (#9240)
  Bump to dotnet/android-tools@657574378a6 and xamarin/monodroid@8bd4bae7 (#9216)
  Bump to dotnet/java-interop@d30d554 (#9234)
  Localized file check-in by OneLocBuild Task (#9236)
  Bump to dotnet/sdk@e2b7b9d2b4 9.0.100-rc.2.24420.1 (#9228)
  $(AndroidPackVersionSuffix)=rc.2; net9 is 35.0.0-rc.2 (#9233)
  [Xamarin.Android.Build.Tasks] Scan for JCWs for each ABI in parallel (#9215)
  [Xamarin.Android.Build.Tasks] %(JavaArtifact) is a list (#9112)
  [native/monodroid] Fix error demangling satellite assembly names (#9166)
  [build] Update package metadata (#9230)
  [Xamarin.Android.Build.Tasks] Remove ILRepack (#9226)
  [Xamarin.Android.Build.Tasks] Fix an issue with incremental builds (#9183)
  [Xamarin.Android.Build.Tasks] remove `$XAMARIN_BUILD_ID` (#9223)
  [Mono.Android] Use .NET version of mdoc (#9225)
  ...
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.

4 participants