wolfpld / tracy

Frame profiler
https://tracy.nereid.pl/
Other
8.61k stars 592 forks source link

No context switches & system tracing on Android #818

Open A-Kovalev-Playrix opened 1 week ago

A-Kovalev-Playrix commented 1 week ago

Hi,

I am trying to get context switches information in Tracy (ver 0.9.1) from Android device (Magisk rooted Samsung J6 with armv7a processor, running on Android 10). Unfortunately I can't make it work. I don't see any information from CPU data section as I can see on Win machines for example

I have executed this commands in su mode from shell on the device (from documentation):

setenforce 0
mount -o remount,hidepid=0 /proc
echo -1 > /proc/sys/kernel/perf_event_paranoid
echo 0 > /proc/sys/kernel/kptr_restrict

but it changed nothing, I still don't have context switches information in Tracy. I've found pretty close issue: https://github.com/wolfpld/tracy/issues/268 but there were no updates and no information, also approach of profiling has changed since that moment and that closed issue may be not relevant anymore. Also I've debugged launch and found that perf_event_open always returns -1 and SysTraceStart doesn't create any listeners in fact. I am ran out of ideas how to fix it or what's exactly is going wrong with this system calls. Any ideas how to make this advanced profiling work on Android devices? I would appreciate any information\help.

A-Kovalev-Playrix commented 5 days ago

Seems I have found some solution. There was a problem in SELinux rules, they were blocking access for some files in system call even with root privileges (I tried to start process under root user with am start -S ... --user current option under su and got permission errors). So, I added some debugfs_tracing access in sepolicy:

allow untrusted_app debugfs_tracing:dir { ioctl read lock open };
allow untrusted_app debugfs_tracing:file { ioctl read getattr lock map open };

trough magiskpolicy tool: (https://topjohnwu.github.io/Magisk/tools.html). Warning: it violated security policies as with this changes every app can get access to tracing calls that can cause some data leakage.

But after that I still received -1 results and got errors with invalid parameter (got in from errno). I found out that this errors were caused by use_clockid and clockid setting, seems that my version of kernel\android has no support CLOCK_MONOTONIC_RAW neither CLOCK_MONOTONIC (or maybe all modern Android devices have no access to use them?). After removing usage of this parameters I finally got system tracing\context switches information in tracy (but without call stacks, all zones were marked ???).

Hope this information will be useful for someone and there will be some general solution for use_clockid and type of clockid bu default