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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
564f130
Begin migration from https://github.com/xamarin/xamarin-android/pull/…
grendello Apr 4, 2024
8554fed
Bumps LLVM to v18.1.3 and XA utils version to 8.0.0 (#8852)
grendello Apr 5, 2024
42e199a
Bump external/Java.Interop from `651de42` to `e1c7832` (#8836)
dependabot[bot] Apr 8, 2024
b9b0571
[ci] Update dependabot ignore list (#8864)
pjcollins Apr 9, 2024
e085755
Merge branch 'main' into dev/grendel/native-tracing
grendello Apr 10, 2024
842d3c3
Update apkdesc files
grendello Apr 11, 2024
9cf8516
[WIP] Migration to new native sources layout
grendello Apr 11, 2024
7ad1a7a
Merge branch 'main' into dev/grendel/native-tracing
grendello Apr 12, 2024
37c2108
[WIP] xaprepare generates cmake presets
grendello Apr 12, 2024
eb0628f
[WIP] cmake stuff
grendello Apr 12, 2024
5756ecd
Refactoring + cleanup continue
grendello Apr 15, 2024
8355440
Merge branch 'main' into dev/grendel/native-tracing
grendello Apr 16, 2024
d6ba624
Most libs are built from separate directories now
grendello Apr 16, 2024
ccfe36e
All libraries are built in their own directories
grendello Apr 16, 2024
c45283b
Should fully build now
grendello Apr 17, 2024
4a317bb
A few more build tweaks, mostly for analyzer builds
grendello Apr 17, 2024
8de9732
Merge branch 'main' into dev/grendel/native-tracing
grendello Apr 18, 2024
f09a839
Update apkdesc files
grendello Apr 18, 2024
fe32008
Fix a handful of tests, plus...
grendello Apr 19, 2024
ce05433
Don't put the native tracing library in apk by default
grendello Apr 22, 2024
ec09869
Update apkdesc + use anonymous namespace
grendello Apr 22, 2024
e4a8eff
Update policheck/source.gdnsuppress
pjcollins Apr 22, 2024
e1c3c8f
Drop use of some macros
grendello Apr 22, 2024
8986fc2
Cleanup
grendello Apr 22, 2024
ff9b068
Merge branch 'main' into dev/grendel/native-tracing
grendello Apr 23, 2024
48cb44d
Hopefully final cleanup steps
grendello Apr 23, 2024
506d175
Merge branch 'main' into dev/grendel/native-tracing
grendello Apr 23, 2024
13e63bd
Merge branch 'main' into dev/grendel/native-tracing
grendello Apr 24, 2024
ece8a68
Remove unneded include dirs
grendello Apr 24, 2024
c9e5ebd
Merge branch 'main' into dev/grendel/native-tracing
grendello Apr 24, 2024
4d5f110
Added perfetto submodule
grendello Apr 24, 2024
e9ca94c
Added perfetto
grendello Apr 24, 2024
988f969
Build and package monodroid runtime which includes the Perfetto SDK
grendello Apr 24, 2024
297aacd
[Mono.Android] fix potential leak of RunnableImplementors (#8900)
jonathanpeppers Apr 25, 2024
7d0165e
Figuring out how to trace events
grendello Apr 25, 2024
d1c22e8
Merge branch 'main' into dev/grendel/perfetto-integration
grendello Apr 26, 2024
7a6697c
More research + some managed runtime events implemented
grendello Apr 26, 2024
9d5bf64
Merge branch 'main' into dev/grendel/perfetto-integration
grendello Apr 26, 2024
fe18f2d
Merge branch 'main' into dev/grendel/perfetto-integration
grendello Apr 30, 2024
0ec8677
Package only one runtime, either with or without Perfetto support
grendello Apr 30, 2024
3c8a7e1
Better, I hope
grendello Apr 30, 2024
771db6a
Merge branch 'main' into dev/grendel/perfetto-integration
grendello May 6, 2024
dcb742b
Merge branch 'main' into dev/grendel/perfetto-integration
grendello May 7, 2024
a698859
Experimenting with events
grendello May 7, 2024
cf4a8f6
Now we're talkin'
grendello May 8, 2024
d3138f8
Merge branch 'main' into dev/grendel/perfetto-integration
grendello May 9, 2024
e201598
Some events don't show up and I don't know why
grendello May 9, 2024
23246ff
Merge branch 'main' into dev/grendel/perfetto-integration
grendello May 10, 2024
acd70e3
Trying to figure out why some events aren't recorded
grendello May 10, 2024
7060c43
Add some configuration options
grendello May 13, 2024
9760427
Merge branch 'main' into dev/grendel/perfetto-integration
grendello May 13, 2024
c162ad0
Merge branch 'main' into dev/grendel/perfetto-integration
grendello May 14, 2024
f711191
Merge branch 'main' into dev/grendel/perfetto-integration
grendello May 15, 2024
5c218e3
Merge branch 'main' into dev/grendel/perfetto-integration
grendello May 16, 2024
59290b3
Post-merge fixups
grendello May 16, 2024
2934099
Merge branch 'main' into dev/grendel/perfetto-integration
grendello May 23, 2024
3b25208
Merge branch 'main' into dev/grendel/perfetto-integration
grendello Jun 3, 2024
f44cb4a
Add Perfetto v45.0 SDK sources
grendello Jun 3, 2024
ac0fa82
Remove perfetto submodule
grendello Jun 3, 2024
892e796
Use Perfetto SDK copy
grendello Jun 3, 2024
819f3ef
Fix a typo
grendello Jun 3, 2024
01d35d5
Merge branch 'main' into dev/grendel/perfetto-integration
grendello Jun 4, 2024
d70e06f
Some docs + dependabot cleanup
grendello Jun 4, 2024
1676bc0
Formatting
grendello Jun 4, 2024
c9a25d8
Merge branch 'main' into dev/grendel/perfetto-integration
grendello Jun 21, 2024
369f07d
Update perfetto to v46
grendello Jun 21, 2024
7f3fc6a
Merge branch 'main' into dev/grendel/perfetto-integration
grendello Jun 27, 2024
c78a7f0
Address feedback
grendello Jun 27, 2024
c75c724
Add perfetto updating docs
grendello Jun 28, 2024
960bc58
Merge branch 'main' into dev/grendel/perfetto-integration
grendello Jul 5, 2024
37c8656
Merge branch 'main' into dev/grendel/perfetto-integration
grendello Jul 23, 2024
534432d
Post-merge updates
grendello Jul 23, 2024
fb2caa9
Merge branch 'main' into dev/grendel/perfetto-integration
grendello Jul 24, 2024
c0d2402
Merge branch 'main' into dev/grendel/perfetto-integration
grendello Jul 24, 2024
78bc662
post-merge adjustments
grendello Jul 24, 2024
3b98086
Fix builds
grendello Jul 24, 2024
2895307
hush some build warnings
grendello Jul 24, 2024
b3d9bad
Merge branch 'main' into dev/grendel/perfetto-integration
grendello Jul 24, 2024
d42ce6b
Merge branch 'main' into dev/grendel/perfetto-integration
grendello Jul 26, 2024
9554fb6
Merge branch 'main' into dev/grendel/perfetto-integration
grendello Jul 26, 2024
9d10266
Merge branch 'main' into dev/grendel/perfetto-integration
grendello Aug 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions Documentation/guides/profiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,43 @@ See further details on `simpleperf`'s [README][simpleperf-readme].
[simpleperf]: https://developer.android.com/ndk/guides/simpleperf
[simpleperf-readme]: https://android.googlesource.com/platform/system/extras/+/master/simpleperf/doc/README.md

## Profiling with Perfetto

[Perfetto](https://perfetto.dev/) 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](https://ui.perfetto.dev/) (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](https://perfetto.dev/docs/quickstart/android-tracing)
2. [Capture a system trace on a device](https://developer.android.com/topic/performance/tracing/on-device)

After recording the trace using whichever method, location of the trace file to download from device (e.g.
using [`adb pull`](https://developer.android.com/topic/performance/tracing/on-device#download_report_using_adb))
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
```

# Profiling MSBuild

At a high level, you can get a performance summary from MSBuild via:
Expand All @@ -441,7 +478,7 @@ target:
Project Evaluation Performance Summary:
12 ms samples\HelloWorld\HelloLibrary\HelloLibrary.csproj 1 calls
98 ms samples\HelloWorld\HelloWorld.csproj 1 calls

Target Performance Summary:
275 ms _UpdateAndroidResgen 2 calls
354 ms _GenerateJavaStubs 1 calls
Expand All @@ -450,7 +487,7 @@ target:
865 ms _ResolveSdks 2 calls
953 ms ResolveProjectReferences 2 calls
1219 ms _CompileToDalvikWithD8 1 calls

Task Performance Summary:
681 ms Csc 2 calls
809 ms ValidateJavaVersion 2 calls
Expand Down
2 changes: 2 additions & 0 deletions build-tools/create-packs/Microsoft.Android.Runtime.proj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ projects that use the Microsoft.Android framework in .NET 6+.
<_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETOutputRoot)$(AndroidLatestStableApiLevel)\Mono.Android.Export.dll" />
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libmono-android.debug.so" />
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libmono-android.release.so" />
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libmono-android-perfetto.debug.so" />
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libmono-android-perfetto.release.so" />
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libxamarin-debug-app-helper.so" />
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libxamarin-native-tracing.so" />
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libunwind_xamarin.a" />
Expand Down
24 changes: 24 additions & 0 deletions src-ThirdParty/perfetto/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Introduction

This directory contains a copy of the [Perfetto](https://perfetto.dev/) SDK, which is
an amalgamate of the Perfetto header and source files meant to be used in client
applications. We chose copying the sources over adding a Perfetto submodule in order
to save time and space.

The SDK should be updated manually, whenever it is deemed necessary.

# Updating

Whenever Perfetto is released, the SDK is generated in their release branch and placed
in the [sdk](https://github.com/google/perfetto/tree/v46.0/sdk) directory. Every release
is accompanied by a tag whose name is the released Perfetto version (e.g. `v46.0`). This
tag needs to be checked out on one's local machine, and the contents of the `sdk` directory
copied to the `src-ThirdParty/perfetto/` in our repository.

In order to learn what is the current version of our Perfetto copy, one needs to open
the `src-ThirdParty/perfetto/perfetto.cc` file and find the definition of the `PERFETTO_VERSION_STRING()`
macro:

```c++
#define PERFETTO_VERSION_STRING() "v46.0-7114ea53e"
```
Loading
Loading