I have multiple Android application that require retrieving the CPU and memory average when running on a physical device. All applications can be open within Android Studio but not all are native, there are Flutter and React Native projects as well. Android Studio has a profiler but doesn’t allow any export of usage metrics.
I have experience with the Xcode Instruments which allows to gather any metrics like CPU, RAM, network within a table view that you can copy and paste into Excel. After that, any graphs can be made, alongside calculations for averages, minimums, maximums, etc. This is the idea.
If there isn’t functionality within Android Studio, is there with another program which can hook into the device metrics?
2
Answers
Unfortunately I haven't managed to find a tool to streamline this task. However, as a universal method for any Android app, you can use an
sh
script to capture and export the information into an .csv file through the use ofadb shell
. Here is mine:Above is the implementation where the only argument is the package name (e.g.
sh record.sh com.facebook.katana
). The script will create a .csv file at the same directory which will be named after the app package name (e.g.com.facebook.katana.csv
). CPU and memory usage is written to the .csv every second but that is customisable by changing thesleep
argument.Below is a result of what the data looks like after opening it in Excel, in addition to some graphs that are possible with this data.
For CPU usage, you can record a System Trace in Android Studio profiler and export the trace file, which can be analyzed using the Perfetto Trace Processor, a SQL-interface for querying data events and slices. See https://perfetto.dev/docs/data-sources/cpu-freq#sql for the CPU-related SQL tables.