capturing perfetto trace on Android 10

590 views
Skip to first unread message

mahdi hamzeh

unread,
Oct 10, 2022, 4:08:23 PM10/10/22
to Perfetto Development - www.perfetto.dev
Hello,

I would like to run a few performance where I need to run perfetto on a device running an older android (10). I am seeking advice as to how to proceed with running into least issues/challenges.

I need a (perfetto) feature introduced right after  Android 10 cut. The feature I need captures a few CPU counters define under protos/perfetto/config/profiling/perf_event_config.proto ( HW_CPU_CYCLES  and HW_INSTRUCTIONS)

My first attempt was to just build perfetto from master, Android 12 or 11 and load on device which did not work (copy perfetto, traced, traced_probes and libperfetto.so from perfetto standalone build). I assume there is something fundamental I am missing and it seems this approach does not work.

My second attempt was to cherry pick those commits that introduce CPU counters on top of android 10 (and build android 10) but there is quite a bit of dependency and so far did not get me anywhere. If I simply checkout to those commits, the build system is incompatible and I run into build issues ("libprotobuf-cpp-full" missing variant linux_glibc_x86_64, link:static)

It seems like there is a substantial change in the build system such that just checking out perfetto from Android 12 repo and building the whole android could not work. So I am seeking advice how to proceed. 

Your help is greatly appreciated.

Lalit Maganti

unread,
Oct 10, 2022, 4:24:25 PM10/10/22
to mahdi hamzeh, Ryan Savitski, Perfetto Development - www.perfetto.dev
> My first attempt was to just build perfetto from master, Android 12 or 11 and load on device which did not work (copy perfetto, traced, traced_probes and libperfetto.so from perfetto standalone build). I assume there is something fundamental I am missing and it seems this approach does not work.
When you say this, what exactly does not work? Also note, you need to sideload traced_perf as well - that's the daemon which is actually interacting with the kernel to collect perf events.

+Ryan Savitski would probably have thoughts on whether sideloading (i.e. compiling on head and running on older versions) would be possible at all for traced_perf.

If this is not possible, I don't think there's any another approach would work TBH. You've tried all the options I might suggest.


--
You received this message because you are subscribed to the Google Groups "Perfetto Development - www.perfetto.dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to perfetto-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/perfetto-dev/f427a121-53fc-4655-a46f-9992ed79fdd4n%40googlegroups.com.

mahdi hamzeh

unread,
Oct 10, 2022, 4:38:05 PM10/10/22
to Lalit Maganti, Ryan Savitski, Perfetto Development - www.perfetto.dev
Lalit, 

On Mon, Oct 10, 2022 at 1:24 PM Lalit Maganti <lal...@google.com> wrote:
> My first attempt was to just build perfetto from master, Android 12 or 11 and load on device which did not work (copy perfetto, traced, traced_probes and libperfetto.so from perfetto standalone build). I assume there is something fundamental I am missing and it seems this approach does not work.
When you say this, what exactly does not work? Also note, you need to sideload traced_perf as well - that's the daemon which is actually interacting with the kernel to collect perf events.
Good point. What I mean is, I can collect a trace with the side loaded perfetto but I dont see any CPU counter events in the trace file. When I also query track table, there is no instance of  perf_counter_track. 
Do you mean traced_probes? I dont see any traced_perf anywhere!

+Ryan Savitski would probably have thoughts on whether sideloading (i.e. compiling on head and running on older versions) would be possible at all for traced_perf.

If this is not possible, I don't think there's any another approach would work TBH. You've tried all the options I might suggest.

Thanks 

Lalit Maganti

unread,
Oct 10, 2022, 4:52:52 PM10/10/22
to mahdi hamzeh, Ryan Savitski, Perfetto Development - www.perfetto.dev
On Mon, 10 Oct 2022 at 21:38, mahdi hamzeh <mahdy....@gmail.com> wrote:
Lalit, 

On Mon, Oct 10, 2022 at 1:24 PM Lalit Maganti <lal...@google.com> wrote:
> My first attempt was to just build perfetto from master, Android 12 or 11 and load on device which did not work (copy perfetto, traced, traced_probes and libperfetto.so from perfetto standalone build). I assume there is something fundamental I am missing and it seems this approach does not work.
When you say this, what exactly does not work? Also note, you need to sideload traced_perf as well - that's the daemon which is actually interacting with the kernel to collect perf events.
Good point. What I mean is, I can collect a trace with the side loaded perfetto but I dont see any CPU counter events in the trace file. When I also query track table, there is no instance of  perf_counter_track. 
Do you mean traced_probes? I dont see any traced_perf anywhere!

Right but a lack of those things can be for many reasons. Do you have logcat from the device for example? 

And I definitely mean traced_perf (the target here). Without having traced_perf, there's no way you're going to be able to collect perf events.

mahdi hamzeh

unread,
Oct 10, 2022, 4:59:44 PM10/10/22
to Lalit Maganti, Ryan Savitski, Perfetto Development - www.perfetto.dev
You are right. I do see the traced_perf in my build file but I wonder why standalone build does not build it. Is it expected?

Let me work on the logcat part.

Lalit Maganti

unread,
Oct 10, 2022, 5:43:14 PM10/10/22
to mahdi hamzeh, Ryan Savitski, Perfetto Development - www.perfetto.dev
On Mon, 10 Oct 2022 at 21:59, mahdi hamzeh <mahdy....@gmail.com> wrote:
You are right. I do see the traced_perf in my build file but I wonder why standalone build does not build it. Is it expected?


Not sure whether we support building traced_perf standalone. +Ryan Savitski would have to comment on that. 

mahdi hamzeh

unread,
Oct 10, 2022, 7:37:55 PM10/10/22
to Lalit Maganti, Ryan Savitski, Perfetto Development - www.perfetto.dev
There is this option to build raced_perf in standalone build, enable_perfetto_traced_perf = true, but I run into build error when enable it

Thanks


Ryan Savitski

unread,
Oct 12, 2022, 8:09:22 PM10/12/22
to mahdi hamzeh, Lalit Maganti, Perfetto Development - www.perfetto.dev
If you're trying to sideload the traced_perf on an older Android build (and can run it as root), I'd consider using the "tracebox" target which will bundle all the daemons together as a single binary that can be run as you would the "perfetto" commandline interface. For traced_perf to be included in the tracebox, it needs to be a build config where enable_perfetto_traced_perf=true as you say. There's some clumsiness involved with gn variables, but the following should work:
1) pull newest "master" perfetto git branch
2) tools/install-build-deps --android
3) tools/build_all_configs.py --android # (will generate a bunch of predefined gn configurations in out/, won't actually build anything yet)
4) ninja -C out/android_release_incl_heapprofd_arm64 tracebox # (this has the right gn vars for enable_perfetto_traced_perf)
5) adb push out/android_release_incl_heapprofd_arm64/tracebox /data/local/tests/tracebox 
6) adb shell su root /data/local/tests/tracebox -c /data/local/tmp/cfg --txt -o /data/local/tmp/trace # (assuming you've pushed the config to that path)

Example config for two hw counters: https://pastebin.com/raw/H1CC6Ub7. For local counter recording I'd recommend using "period" with a reasonable value as in this example instead of "frequency" since the latter will give you less predictable sampling intervals. (If you're also interested in callstacks, then do be aware that standalone traced_perf won't handle interpreted ART java frames since it doesn't link in the necessary dexfile libraries.)

Do tell if this works or if you have other questions. I understand that the documentation surrounding this feature is lacking.
Reply all
Reply to author
Forward
0 new messages