After using simpleperf record
or app_profiler.py
, we get a profile data file. The file contains a list of samples. Each sample has a timestamp, a thread id, a callstack, events (like cpu-cycles or cpu-clock) used in this sample, etc. We have many choices for viewing the profile. We can show samples in chronological order, or show aggregated flamegraphs. We can show reports in text format, or in some interactive UIs.
Below shows some recommended UIs to view the profile. Google developers can find more examples in go/gmm-profiling.
PProf is a mature profiling technology used extensively on Google servers, with a powerful flamegraph UI, with strong drilldown, search, pivot, profile diff, and graph visualisation.
We can use pprof_proto_generator.py
to convert profiles into pprof.profile protobufs for use in pprof.
# Output all threads, broken down by threadpool. ./pprof_proto_generator.py # Use proguard mapping. ./pprof_proto_generator.py --proguard-mapping-file proguard.map # Just the main (UI) thread (query by thread name): ./pprof_proto_generator.py --comm com.example.android.displayingbitmaps
This will print some debug logs about Failed to read symbols: this is usually OK, unless those symbols are hotspots.
The continuous pprof server has a file upload size limit of 50MB. To get around this limit, compress the profile before uploading:
gzip pprof.profile
After compressing, you can upload the pprof.profile.gz
file to http://pprof/. The website has an ‘Upload’ tab for this purpose. Alternatively, you can use the following pprof
command to upload the compressed profile:
# Upload all threads in profile, grouped by threadpool. # This is usually a good default, combining threads with similar names. pprof --flame --tagroot threadpool pprof.profile.gz # Upload all threads in profile, grouped by individual thread name. pprof --flame --tagroot thread pprof.profile.gz # Upload all threads in profile, without grouping by thread. pprof --flame pprof.profile.gz This will output a URL, example: https://pprof.corp.google.com/?id=589a60852306144c880e36429e10b166
We can view Android profiles using Firefox Profiler: https://profiler.firefox.com/. This does not require Firefox installation -- Firefox Profiler is just a website, you can open it in any browser. There is also an internal Google-Hosted Firefox Profiler, at go/profiler or go/firefox-profiler.