androidtracesystraceperfetto

Running android systrace inside application


I am trying to develop an app that allows the user to record system traces using systrace, i want to be able to run this inside a regular Android application, without the need of a PC or ROOT access to use the ADB.

From Android 9, there is an option to record system traces from the Developer Options, this works perfectly on the device without any external tools, but i need to have more control over this, because i will be running the systrace command over a period of time and then uploading the results to a server automatically (everything happens in the app)

Is there any way that i can do this from an Android Application ?

I tried using python inside an app and then running systrace, but it fails with an error because it can't find ADB.


Solution

  • This is not possible and that's by design. System Trace data is considered personal data because it may include information like what apps the users was using (all processes are dumped in a trace). When you use the on-device trace app you'll get a prompt to confirm before sharing a trace. By allowing automatic trace uploading it would bypass the privacy protections put in place.

    p.s. the systrace Python script is just a wrapper around some adb commands so it's only supposed to be run from a PC.