1*288bf522SAndroid Build Coastguard Worker# View the profile 2*288bf522SAndroid Build Coastguard Worker 3*288bf522SAndroid Build Coastguard Worker[TOC] 4*288bf522SAndroid Build Coastguard Worker 5*288bf522SAndroid Build Coastguard Worker## Introduction 6*288bf522SAndroid Build Coastguard Worker 7*288bf522SAndroid Build Coastguard WorkerAfter using `simpleperf record` or `app_profiler.py`, we get a profile data 8*288bf522SAndroid Build Coastguard Workerfile. The file contains a list of samples. Each sample has a timestamp, a thread 9*288bf522SAndroid Build Coastguard Workerid, a callstack, events (like cpu-cycles or cpu-clock) used in this sample, etc. 10*288bf522SAndroid Build Coastguard WorkerWe have many choices for viewing the profile. We can show samples in 11*288bf522SAndroid Build Coastguard Workerchronological order, or show aggregated flamegraphs. We can show reports in text 12*288bf522SAndroid Build Coastguard Workerformat, or in some interactive UIs. 13*288bf522SAndroid Build Coastguard Worker 14*288bf522SAndroid Build Coastguard WorkerBelow shows some recommended UIs to view the profile. Google developers can find 15*288bf522SAndroid Build Coastguard Workermore examples in 16*288bf522SAndroid Build Coastguard Worker[go/gmm-profiling](go/gmm-profiling?polyglot=linux-workstation#viewing-the-profile). 17*288bf522SAndroid Build Coastguard Worker 18*288bf522SAndroid Build Coastguard Worker## Continuous PProf UI (great flamegraph UI, but only available internally) 19*288bf522SAndroid Build Coastguard Worker 20*288bf522SAndroid Build Coastguard Worker[PProf](https://github.com/google/pprof) is a mature profiling technology used 21*288bf522SAndroid Build Coastguard Workerextensively on Google servers, with a powerful flamegraph UI, with strong 22*288bf522SAndroid Build Coastguard Workerdrilldown, search, pivot, profile diff, and graph visualisation. 23*288bf522SAndroid Build Coastguard Worker 24*288bf522SAndroid Build Coastguard Worker 25*288bf522SAndroid Build Coastguard Worker 26*288bf522SAndroid Build Coastguard WorkerWe can use `pprof_proto_generator.py` to convert profiles into pprof.profile 27*288bf522SAndroid Build Coastguard Workerprotobufs for use in pprof. 28*288bf522SAndroid Build Coastguard Worker 29*288bf522SAndroid Build Coastguard Worker``` 30*288bf522SAndroid Build Coastguard Worker# Output all threads, broken down by threadpool. 31*288bf522SAndroid Build Coastguard Worker./pprof_proto_generator.py 32*288bf522SAndroid Build Coastguard Worker 33*288bf522SAndroid Build Coastguard Worker# Use proguard mapping. 34*288bf522SAndroid Build Coastguard Worker./pprof_proto_generator.py --proguard-mapping-file proguard.map 35*288bf522SAndroid Build Coastguard Worker 36*288bf522SAndroid Build Coastguard Worker# Just the main (UI) thread (query by thread name): 37*288bf522SAndroid Build Coastguard Worker./pprof_proto_generator.py --comm com.example.android.displayingbitmaps 38*288bf522SAndroid Build Coastguard Worker``` 39*288bf522SAndroid Build Coastguard Worker 40*288bf522SAndroid Build Coastguard WorkerThis will print some debug logs about Failed to read symbols: this is usually 41*288bf522SAndroid Build Coastguard WorkerOK, unless those symbols are hotspots. 42*288bf522SAndroid Build Coastguard Worker 43*288bf522SAndroid Build Coastguard WorkerThe continuous pprof server has a file upload size limit of 50MB. To get around 44*288bf522SAndroid Build Coastguard Workerthis limit, compress the profile before uploading: 45*288bf522SAndroid Build Coastguard Worker 46*288bf522SAndroid Build Coastguard Worker``` 47*288bf522SAndroid Build Coastguard Workergzip pprof.profile 48*288bf522SAndroid Build Coastguard Worker``` 49*288bf522SAndroid Build Coastguard Worker 50*288bf522SAndroid Build Coastguard WorkerAfter compressing, you can upload the `pprof.profile.gz` file to http://pprof/. 51*288bf522SAndroid Build Coastguard WorkerThe website has an 'Upload' tab for this purpose. Alternatively, you can use the 52*288bf522SAndroid Build Coastguard Workerfollowing `pprof` command to upload the compressed profile: 53*288bf522SAndroid Build Coastguard Worker 54*288bf522SAndroid Build Coastguard Worker``` 55*288bf522SAndroid Build Coastguard Worker# Upload all threads in profile, grouped by threadpool. 56*288bf522SAndroid Build Coastguard Worker# This is usually a good default, combining threads with similar names. 57*288bf522SAndroid Build Coastguard Workerpprof --flame --tagroot threadpool pprof.profile.gz 58*288bf522SAndroid Build Coastguard Worker 59*288bf522SAndroid Build Coastguard Worker# Upload all threads in profile, grouped by individual thread name. 60*288bf522SAndroid Build Coastguard Workerpprof --flame --tagroot thread pprof.profile.gz 61*288bf522SAndroid Build Coastguard Worker 62*288bf522SAndroid Build Coastguard Worker# Upload all threads in profile, without grouping by thread. 63*288bf522SAndroid Build Coastguard Workerpprof --flame pprof.profile.gz 64*288bf522SAndroid Build Coastguard WorkerThis will output a URL, example: https://pprof.corp.google.com/?id=589a60852306144c880e36429e10b166 65*288bf522SAndroid Build Coastguard Worker``` 66*288bf522SAndroid Build Coastguard Worker 67*288bf522SAndroid Build Coastguard Worker## Perfetto (preferred chronological UI and flamegraph UI for public) 68*288bf522SAndroid Build Coastguard Worker 69*288bf522SAndroid Build Coastguard WorkerThe [Perfetto UI](https://ui.perfetto.dev) is a web-based visualizer combining 70*288bf522SAndroid Build Coastguard Workerthe chronological view of the profile with a powerful flamegraph UI. 71*288bf522SAndroid Build Coastguard Worker 72*288bf522SAndroid Build Coastguard WorkerThe Perfetto UI shows stack samples over time, exactly as collected by perf and 73*288bf522SAndroid Build Coastguard Workerallows selecting both region of time and certain threads and/or processes to 74*288bf522SAndroid Build Coastguard Workeranalyse only matching samples. Moreover, it has a similar flamegraph UI to pprof 75*288bf522SAndroid Build Coastguard Workervery similar drilldown, search and pivot functionality. Finally, it also has an 76*288bf522SAndroid Build Coastguard WorkerSQL query language (PerfettoSQL) which allows programmatic queries on profiles. 77*288bf522SAndroid Build Coastguard Worker 78*288bf522SAndroid Build Coastguard Worker 79*288bf522SAndroid Build Coastguard Worker 80*288bf522SAndroid Build Coastguard WorkerWe can use `gecko_profile_generator.py` to convert raw perf.data files into a 81*288bf522SAndroid Build Coastguard WorkerGecko format; while Perfetto supports opening raw perf.data files as well, 82*288bf522SAndroid Build Coastguard Workersymbolization and deobfuscation does not work out of the box. 83*288bf522SAndroid Build Coastguard Worker 84*288bf522SAndroid Build Coastguard Worker``` 85*288bf522SAndroid Build Coastguard Worker# Create Gecko format profile 86*288bf522SAndroid Build Coastguard Worker./gecko_profile_generator.py > gecko_profile.json 87*288bf522SAndroid Build Coastguard Worker 88*288bf522SAndroid Build Coastguard Worker# Create Gecko format profile with Proguard map for deobfuscation 89*288bf522SAndroid Build Coastguard Worker./gecko_profile_generator.py --proguard-mapping-file proguard.map > gecko_profile.json 90*288bf522SAndroid Build Coastguard Worker``` 91*288bf522SAndroid Build Coastguard Worker 92*288bf522SAndroid Build Coastguard WorkerThen drag-and-drop `gecko_profile.json` into https://ui.perfetto.dev/. 93*288bf522SAndroid Build Coastguard WorkerAlternatively, to open from the command line, you can also do: 94*288bf522SAndroid Build Coastguard Worker 95*288bf522SAndroid Build Coastguard Worker``` 96*288bf522SAndroid Build Coastguard Workercurl -L https://github.com/google/perfetto/raw/main/tools/open_trace_in_ui | python - -i gecko_profile.json 97*288bf522SAndroid Build Coastguard Worker``` 98*288bf522SAndroid Build Coastguard Worker 99*288bf522SAndroid Build Coastguard WorkerNote: if running the above on a remote machine over SSH, you need to first port 100*288bf522SAndroid Build Coastguard Workerforward `9001` to your local machine. For example, you could do this by running: 101*288bf522SAndroid Build Coastguard Worker 102*288bf522SAndroid Build Coastguard Worker``` 103*288bf522SAndroid Build Coastguard Workerssh -fNT -L 9001:localhost:9001 <hostname> 104*288bf522SAndroid Build Coastguard Worker``` 105*288bf522SAndroid Build Coastguard Worker 106*288bf522SAndroid Build Coastguard Worker## Firefox Profiler (great chronological UI) 107*288bf522SAndroid Build Coastguard Worker 108*288bf522SAndroid Build Coastguard WorkerWe can view Android profiles using Firefox Profiler: 109*288bf522SAndroid Build Coastguard Workerhttps://profiler.firefox.com/. This does not require Firefox installation -- 110*288bf522SAndroid Build Coastguard WorkerFirefox Profiler is just a website, you can open it in any browser. There is 111*288bf522SAndroid Build Coastguard Workeralso an internal Google-Hosted Firefox Profiler, at go/profiler or 112*288bf522SAndroid Build Coastguard Workergo/firefox-profiler. 113*288bf522SAndroid Build Coastguard Worker 114*288bf522SAndroid Build Coastguard Worker 115*288bf522SAndroid Build Coastguard Worker 116*288bf522SAndroid Build Coastguard WorkerFirefox Profiler has a great chronological view, as it doesn't pre-aggregate 117*288bf522SAndroid Build Coastguard Workersimilar stack traces like pprof does. 118*288bf522SAndroid Build Coastguard Worker 119*288bf522SAndroid Build Coastguard WorkerWe can use `gecko_profile_generator.py` to convert raw perf.data files into a 120*288bf522SAndroid Build Coastguard WorkerFirefox Profile, with Proguard deobfuscation. 121*288bf522SAndroid Build Coastguard Worker 122*288bf522SAndroid Build Coastguard Worker``` 123*288bf522SAndroid Build Coastguard Worker# Create Gecko Profile 124*288bf522SAndroid Build Coastguard Worker./gecko_profile_generator.py | gzip > gecko_profile.json.gz 125*288bf522SAndroid Build Coastguard Worker 126*288bf522SAndroid Build Coastguard Worker# Create Gecko Profile using Proguard map 127*288bf522SAndroid Build Coastguard Worker./gecko_profile_generator.py --proguard-mapping-file proguard.map | gzip > gecko_profile.json.gz 128*288bf522SAndroid Build Coastguard Worker``` 129*288bf522SAndroid Build Coastguard Worker 130*288bf522SAndroid Build Coastguard WorkerThen drag-and-drop gecko_profile.json.gz into https://profiler.firefox.com/. 131*288bf522SAndroid Build Coastguard Worker 132*288bf522SAndroid Build Coastguard WorkerFirefox Profiler supports: 133*288bf522SAndroid Build Coastguard Worker 134*288bf522SAndroid Build Coastguard Worker1. Aggregated Flamegraphs 135*288bf522SAndroid Build Coastguard Worker2. Chronological Stackcharts 136*288bf522SAndroid Build Coastguard Worker 137*288bf522SAndroid Build Coastguard WorkerAnd allows filtering by: 138*288bf522SAndroid Build Coastguard Worker 139*288bf522SAndroid Build Coastguard Worker1. Individual threads 140*288bf522SAndroid Build Coastguard Worker2. Multiple threads (Ctrl+Click thread names to select many) 141*288bf522SAndroid Build Coastguard Worker3. Timeline period 142*288bf522SAndroid Build Coastguard Worker4. Stack frame text search 143*288bf522SAndroid Build Coastguard Worker 144*288bf522SAndroid Build Coastguard Worker## FlameScope (great jank-finding UI) 145*288bf522SAndroid Build Coastguard Worker 146*288bf522SAndroid Build Coastguard Worker[Netflix's FlameScope](https://github.com/Netflix/flamescope) is a rough, 147*288bf522SAndroid Build Coastguard Workerproof-of-concept UI that lets you spot repeating patterns of work by laying out 148*288bf522SAndroid Build Coastguard Workerthe profile as a subsecond heatmap. 149*288bf522SAndroid Build Coastguard Worker 150*288bf522SAndroid Build Coastguard WorkerBelow, each vertical stripe is one second, and each cell is 10ms. Redder cells 151*288bf522SAndroid Build Coastguard Workerhave more samples. See 152*288bf522SAndroid Build Coastguard Workerhttps://www.brendangregg.com/blog/2018-11-08/flamescope-pattern-recognition.html 153*288bf522SAndroid Build Coastguard Workerfor how to spot patterns. 154*288bf522SAndroid Build Coastguard Worker 155*288bf522SAndroid Build Coastguard WorkerThis is an example of a 60s DisplayBitmaps app Startup Profile. 156*288bf522SAndroid Build Coastguard Worker 157*288bf522SAndroid Build Coastguard Worker 158*288bf522SAndroid Build Coastguard Worker 159*288bf522SAndroid Build Coastguard WorkerYou can see: 160*288bf522SAndroid Build Coastguard Worker 161*288bf522SAndroid Build Coastguard WorkerThe thick red vertical line on the left is startup. The long white vertical 162*288bf522SAndroid Build Coastguard Workersections on the left shows the app is mostly idle, waiting for commands from 163*288bf522SAndroid Build Coastguard Workerinstrumented tests. Then we see periodically red blocks, which shows the app is 164*288bf522SAndroid Build Coastguard Workerperiodically busy handling commands from instrumented tests. 165*288bf522SAndroid Build Coastguard Worker 166*288bf522SAndroid Build Coastguard WorkerClick the start and end cells of a duration: 167*288bf522SAndroid Build Coastguard Worker 168*288bf522SAndroid Build Coastguard Worker 169*288bf522SAndroid Build Coastguard Worker 170*288bf522SAndroid Build Coastguard WorkerTo see a flamegraph for that duration: 171*288bf522SAndroid Build Coastguard Worker 172*288bf522SAndroid Build Coastguard Worker 173*288bf522SAndroid Build Coastguard Worker 174*288bf522SAndroid Build Coastguard WorkerInstall and run Flamescope: 175*288bf522SAndroid Build Coastguard Worker 176*288bf522SAndroid Build Coastguard Worker``` 177*288bf522SAndroid Build Coastguard Workergit clone https://github.com/Netflix/flamescope ~/flamescope 178*288bf522SAndroid Build Coastguard Workercd ~/flamescope 179*288bf522SAndroid Build Coastguard Workerpip install -r requirements.txt 180*288bf522SAndroid Build Coastguard Workernpm install 181*288bf522SAndroid Build Coastguard Workernpm run webpack 182*288bf522SAndroid Build Coastguard Workerpython3 run.py 183*288bf522SAndroid Build Coastguard Worker``` 184*288bf522SAndroid Build Coastguard Worker 185*288bf522SAndroid Build Coastguard WorkerThen open FlameScope in-browser: http://localhost:5000/. 186*288bf522SAndroid Build Coastguard Worker 187*288bf522SAndroid Build Coastguard WorkerFlameScope can read gzipped perf script format profiles. Convert simpleperf 188*288bf522SAndroid Build Coastguard Workerperf.data to this format with `report_sample.py`, and place it in Flamescope's 189*288bf522SAndroid Build Coastguard Workerexamples directory: 190*288bf522SAndroid Build Coastguard Worker 191*288bf522SAndroid Build Coastguard Worker``` 192*288bf522SAndroid Build Coastguard Worker# Create `Linux perf script` format profile. 193*288bf522SAndroid Build Coastguard Workerreport_sample.py | gzip > ~/flamescope/examples/my_simpleperf_profile.gz 194*288bf522SAndroid Build Coastguard Worker 195*288bf522SAndroid Build Coastguard Worker# Create `Linux perf script` format profile using Proguard map. 196*288bf522SAndroid Build Coastguard Workerreport_sample.py \ 197*288bf522SAndroid Build Coastguard Worker --proguard-mapping-file proguard.map \ 198*288bf522SAndroid Build Coastguard Worker | gzip > ~/flamescope/examples/my_simpleperf_profile.gz 199*288bf522SAndroid Build Coastguard Worker``` 200*288bf522SAndroid Build Coastguard Worker 201*288bf522SAndroid Build Coastguard WorkerOpen the profile "as Linux Perf", and click start and end sections to get a 202*288bf522SAndroid Build Coastguard Workerflamegraph of that timespan. 203*288bf522SAndroid Build Coastguard Worker 204*288bf522SAndroid Build Coastguard WorkerTo investigate UI Thread Jank, filter to UI thread samples only: 205*288bf522SAndroid Build Coastguard Worker 206*288bf522SAndroid Build Coastguard Worker``` 207*288bf522SAndroid Build Coastguard Workerreport_sample.py \ 208*288bf522SAndroid Build Coastguard Worker --comm com.example.android.displayingbitmaps \ # UI Thread 209*288bf522SAndroid Build Coastguard Worker | gzip > ~/flamescope/examples/uithread.gz 210*288bf522SAndroid Build Coastguard Worker``` 211*288bf522SAndroid Build Coastguard Worker 212*288bf522SAndroid Build Coastguard WorkerOnce you've identified the timespan of interest, consider also zooming into that 213*288bf522SAndroid Build Coastguard Workersection with Firefox Profiler, which has a more powerful flamegraph viewer. 214*288bf522SAndroid Build Coastguard Worker 215*288bf522SAndroid Build Coastguard Worker## Differential FlameGraph 216*288bf522SAndroid Build Coastguard Worker 217*288bf522SAndroid Build Coastguard WorkerSee Brendan Gregg's 218*288bf522SAndroid Build Coastguard Worker[Differential Flame Graphs](https://www.brendangregg.com/blog/2014-11-09/differential-flame-graphs.html) 219*288bf522SAndroid Build Coastguard Workerblog. 220*288bf522SAndroid Build Coastguard Worker 221*288bf522SAndroid Build Coastguard WorkerUse Simpleperf's `stackcollapse.py` to convert perf.data to Folded Stacks format 222*288bf522SAndroid Build Coastguard Workerfor the FlameGraph toolkit. 223*288bf522SAndroid Build Coastguard Worker 224*288bf522SAndroid Build Coastguard WorkerConsider diffing both directions: After minus Before, and Before minus After. 225*288bf522SAndroid Build Coastguard Worker 226*288bf522SAndroid Build Coastguard WorkerIf you've recorded before and after your optimisation as perf_before.data and 227*288bf522SAndroid Build Coastguard Workerperf_after.data, and you're only interested in the UI thread: 228*288bf522SAndroid Build Coastguard Worker 229*288bf522SAndroid Build Coastguard Worker``` 230*288bf522SAndroid Build Coastguard Worker# Generate before and after folded stacks from perf.data files 231*288bf522SAndroid Build Coastguard Worker./stackcollapse.py --kernel --jit -i perf_before.data \ 232*288bf522SAndroid Build Coastguard Worker --proguard-mapping-file proguard_before.map \ 233*288bf522SAndroid Build Coastguard Worker --comm com.example.android.displayingbitmaps \ 234*288bf522SAndroid Build Coastguard Worker > perf_before.folded 235*288bf522SAndroid Build Coastguard Worker./stackcollapse.py --kernel --jit -i perf_after.data \ 236*288bf522SAndroid Build Coastguard Worker --proguard-mapping-file proguard_after.map \ 237*288bf522SAndroid Build Coastguard Worker --comm com.example.android.displayingbitmaps \ 238*288bf522SAndroid Build Coastguard Worker > perf_after.folded 239*288bf522SAndroid Build Coastguard Worker 240*288bf522SAndroid Build Coastguard Worker# Generate diff reports 241*288bf522SAndroid Build Coastguard WorkerFlameGraph/difffolded.pl -n perf_before.folded perf_after.folded \ 242*288bf522SAndroid Build Coastguard Worker | FlameGraph/flamegraph.pl > diff1.svg 243*288bf522SAndroid Build Coastguard WorkerFlameGraph/difffolded.pl -n --negate perf_after.folded perf_before.folded \ 244*288bf522SAndroid Build Coastguard Worker | FlameGraph/flamegraph.pl > diff2.svg 245*288bf522SAndroid Build Coastguard Worker``` 246*288bf522SAndroid Build Coastguard Worker 247*288bf522SAndroid Build Coastguard Worker## Android Studio Profiler 248*288bf522SAndroid Build Coastguard Worker 249*288bf522SAndroid Build Coastguard WorkerAndroid Studio Profiler supports recording and reporting profiles of app 250*288bf522SAndroid Build Coastguard Workerprocesses. It supports several recording methods, including one using simpleperf 251*288bf522SAndroid Build Coastguard Workeras backend. You can use Android Studio Profiler for both recording and 252*288bf522SAndroid Build Coastguard Workerreporting. 253*288bf522SAndroid Build Coastguard Worker 254*288bf522SAndroid Build Coastguard WorkerIn Android Studio: Open View -> Tool Windows -> Profiler Click + -> Your Device 255*288bf522SAndroid Build Coastguard Worker-> Profileable Processes -> Your App 256*288bf522SAndroid Build Coastguard Worker 257*288bf522SAndroid Build Coastguard Worker 258*288bf522SAndroid Build Coastguard Worker 259*288bf522SAndroid Build Coastguard WorkerClick into "CPU" Chart 260*288bf522SAndroid Build Coastguard Worker 261*288bf522SAndroid Build Coastguard WorkerChoose Callstack Sample Recording. Even if you're using Java, this provides 262*288bf522SAndroid Build Coastguard Workerbetter observability, into ART, malloc, and the kernel. 263*288bf522SAndroid Build Coastguard Worker 264*288bf522SAndroid Build Coastguard Worker 265*288bf522SAndroid Build Coastguard Worker 266*288bf522SAndroid Build Coastguard WorkerClick Record, run your test on the device, then Stop when you're done. 267*288bf522SAndroid Build Coastguard Worker 268*288bf522SAndroid Build Coastguard WorkerClick on a thread track, and "Flame Chart" to see a chronological chart on the 269*288bf522SAndroid Build Coastguard Workerleft, and an aggregated flamechart on the right: 270*288bf522SAndroid Build Coastguard Worker 271*288bf522SAndroid Build Coastguard Worker 272*288bf522SAndroid Build Coastguard Worker 273*288bf522SAndroid Build Coastguard WorkerIf you want more flexibility in recording options, or want to add proguard 274*288bf522SAndroid Build Coastguard Workermapping file, you can record using simpleperf, and report using Android Studio 275*288bf522SAndroid Build Coastguard WorkerProfiler. 276*288bf522SAndroid Build Coastguard Worker 277*288bf522SAndroid Build Coastguard WorkerWe can use `simpleperf report-sample` to convert perf.data to trace files for 278*288bf522SAndroid Build Coastguard WorkerAndroid Studio Profiler. 279*288bf522SAndroid Build Coastguard Worker 280*288bf522SAndroid Build Coastguard Worker``` 281*288bf522SAndroid Build Coastguard Worker# Convert perf.data to perf.trace for Android Studio Profiler. 282*288bf522SAndroid Build Coastguard Worker# If on Mac/Windows, use simpleperf host executable for those platforms instead. 283*288bf522SAndroid Build Coastguard Workerbin/linux/x86_64/simpleperf report-sample --show-callchain --protobuf -i perf.data -o perf.trace 284*288bf522SAndroid Build Coastguard Worker 285*288bf522SAndroid Build Coastguard Worker# Convert perf.data to perf.trace using proguard mapping file. 286*288bf522SAndroid Build Coastguard Workerbin/linux/x86_64/simpleperf report-sample --show-callchain --protobuf -i perf.data -o perf.trace \ 287*288bf522SAndroid Build Coastguard Worker --proguard-mapping-file proguard.map 288*288bf522SAndroid Build Coastguard Worker``` 289*288bf522SAndroid Build Coastguard Worker 290*288bf522SAndroid Build Coastguard WorkerIn Android Studio: Open File -> Open -> Select perf.trace 291*288bf522SAndroid Build Coastguard Worker 292*288bf522SAndroid Build Coastguard Worker 293*288bf522SAndroid Build Coastguard Worker 294*288bf522SAndroid Build Coastguard Worker## Simpleperf HTML Report 295*288bf522SAndroid Build Coastguard Worker 296*288bf522SAndroid Build Coastguard WorkerSimpleperf can generate its own HTML Profile, which is able to show 297*288bf522SAndroid Build Coastguard WorkerAndroid-specific information and separate flamegraphs for all threads, with a 298*288bf522SAndroid Build Coastguard Workermuch rougher flamegraph UI. 299*288bf522SAndroid Build Coastguard Worker 300*288bf522SAndroid Build Coastguard Worker 301*288bf522SAndroid Build Coastguard Worker 302*288bf522SAndroid Build Coastguard WorkerThis UI is fairly rough; we recommend using the Continuous PProf UI or Firefox 303*288bf522SAndroid Build Coastguard WorkerProfiler instead. But it's useful for a quick look at your data. 304*288bf522SAndroid Build Coastguard Worker 305*288bf522SAndroid Build Coastguard WorkerEach of the following commands take as input ./perf.data and output 306*288bf522SAndroid Build Coastguard Worker./report.html. 307*288bf522SAndroid Build Coastguard Worker 308*288bf522SAndroid Build Coastguard Worker``` 309*288bf522SAndroid Build Coastguard Worker# Make an HTML report. 310*288bf522SAndroid Build Coastguard Worker./report_html.py 311*288bf522SAndroid Build Coastguard Worker 312*288bf522SAndroid Build Coastguard Worker# Make an HTML report with Proguard mapping. 313*288bf522SAndroid Build Coastguard Worker./report_html.py --proguard-mapping-file proguard.map 314*288bf522SAndroid Build Coastguard Worker``` 315*288bf522SAndroid Build Coastguard Worker 316*288bf522SAndroid Build Coastguard WorkerThis will print some debug logs about Failed to read symbols: this is usually 317*288bf522SAndroid Build Coastguard WorkerOK, unless those symbols are hotspots. 318*288bf522SAndroid Build Coastguard Worker 319*288bf522SAndroid Build Coastguard WorkerSee also [report_html.py's README](scripts_reference.md#report_htmlpy) and 320*288bf522SAndroid Build Coastguard Worker`report_html.py -h`. 321*288bf522SAndroid Build Coastguard Worker 322*288bf522SAndroid Build Coastguard Worker## PProf Interactive Command Line 323*288bf522SAndroid Build Coastguard Worker 324*288bf522SAndroid Build Coastguard WorkerUnlike Continuous PProf UI, [PProf](https://github.com/google/pprof) command 325*288bf522SAndroid Build Coastguard Workerline is publicly available, and allows drilldown, pivoting and filtering. 326*288bf522SAndroid Build Coastguard Worker 327*288bf522SAndroid Build Coastguard WorkerThe below session demonstrates filtering to stack frames containing 328*288bf522SAndroid Build Coastguard WorkerprocessBitmap. 329*288bf522SAndroid Build Coastguard Worker 330*288bf522SAndroid Build Coastguard Worker``` 331*288bf522SAndroid Build Coastguard Worker$ pprof pprof.profile 332*288bf522SAndroid Build Coastguard Worker(pprof) show=processBitmap 333*288bf522SAndroid Build Coastguard Worker(pprof) top 334*288bf522SAndroid Build Coastguard WorkerActive filters: 335*288bf522SAndroid Build Coastguard Worker show=processBitmap 336*288bf522SAndroid Build Coastguard WorkerShowing nodes accounting for 2.45s, 11.44% of 21.46s total 337*288bf522SAndroid Build Coastguard Worker flat flat% sum% cum cum% 338*288bf522SAndroid Build Coastguard Worker 2.45s 11.44% 11.44% 2.45s 11.44% com.example.android.displayingbitmaps.util.ImageFetcher.processBitmap 339*288bf522SAndroid Build Coastguard Worker``` 340*288bf522SAndroid Build Coastguard Worker 341*288bf522SAndroid Build Coastguard WorkerAnd then showing the tags of those frames, to tell what threads they are running 342*288bf522SAndroid Build Coastguard Workeron: 343*288bf522SAndroid Build Coastguard Worker 344*288bf522SAndroid Build Coastguard Worker``` 345*288bf522SAndroid Build Coastguard Worker(pprof) tags 346*288bf522SAndroid Build Coastguard Worker pid: Total 2.5s 347*288bf522SAndroid Build Coastguard Worker 2.5s ( 100%): 31112 348*288bf522SAndroid Build Coastguard Worker 349*288bf522SAndroid Build Coastguard Worker thread: Total 2.5s 350*288bf522SAndroid Build Coastguard Worker 1.4s (57.21%): AsyncTask #3 351*288bf522SAndroid Build Coastguard Worker 1.1s (42.79%): AsyncTask #4 352*288bf522SAndroid Build Coastguard Worker 353*288bf522SAndroid Build Coastguard Worker threadpool: Total 2.5s 354*288bf522SAndroid Build Coastguard Worker 2.5s ( 100%): AsyncTask #%d 355*288bf522SAndroid Build Coastguard Worker 356*288bf522SAndroid Build Coastguard Worker tid: Total 2.5s 357*288bf522SAndroid Build Coastguard Worker 1.4s (57.21%): 31174 358*288bf522SAndroid Build Coastguard Worker 1.1s (42.79%): 31175 359*288bf522SAndroid Build Coastguard Worker``` 360*288bf522SAndroid Build Coastguard Worker 361*288bf522SAndroid Build Coastguard WorkerContrast with another method: 362*288bf522SAndroid Build Coastguard Worker 363*288bf522SAndroid Build Coastguard Worker``` 364*288bf522SAndroid Build Coastguard Worker(pprof) show=addBitmapToCache 365*288bf522SAndroid Build Coastguard Worker(pprof) top 366*288bf522SAndroid Build Coastguard WorkerActive filters: 367*288bf522SAndroid Build Coastguard Worker show=addBitmapToCache 368*288bf522SAndroid Build Coastguard WorkerShowing nodes accounting for 1.05s, 4.88% of 21.46s total 369*288bf522SAndroid Build Coastguard Worker flat flat% sum% cum cum% 370*288bf522SAndroid Build Coastguard Worker 1.05s 4.88% 4.88% 1.05s 4.88% com.example.android.displayingbitmaps.util.ImageCache.addBitmapToCache 371*288bf522SAndroid Build Coastguard Worker``` 372*288bf522SAndroid Build Coastguard Worker 373*288bf522SAndroid Build Coastguard WorkerFor more information, see the 374*288bf522SAndroid Build Coastguard Worker[pprof README](https://github.com/google/pprof/blob/main/doc/README.md#interactive-terminal-use). 375*288bf522SAndroid Build Coastguard Worker 376*288bf522SAndroid Build Coastguard Worker## Simpleperf Report Command Line 377*288bf522SAndroid Build Coastguard Worker 378*288bf522SAndroid Build Coastguard WorkerThe simpleperf report command reports profiles in text format. 379*288bf522SAndroid Build Coastguard Worker 380*288bf522SAndroid Build Coastguard Worker 381*288bf522SAndroid Build Coastguard Worker 382*288bf522SAndroid Build Coastguard WorkerYou can call `simpleperf report` directly or call it via `report.py`. 383*288bf522SAndroid Build Coastguard Worker 384*288bf522SAndroid Build Coastguard Worker``` 385*288bf522SAndroid Build Coastguard Worker# Report symbols in table format. 386*288bf522SAndroid Build Coastguard Worker$ ./report.py --children 387*288bf522SAndroid Build Coastguard Worker 388*288bf522SAndroid Build Coastguard Worker# Report call graph. 389*288bf522SAndroid Build Coastguard Worker$ bin/linux/x86_64/simpleperf report -g -i perf.data 390*288bf522SAndroid Build Coastguard Worker``` 391*288bf522SAndroid Build Coastguard Worker 392*288bf522SAndroid Build Coastguard WorkerSee also 393*288bf522SAndroid Build Coastguard Worker[report command's README](executable_commands_reference.md#The-report-command) 394*288bf522SAndroid Build Coastguard Workerand `report.py -h`. 395*288bf522SAndroid Build Coastguard Worker 396*288bf522SAndroid Build Coastguard Worker## Custom Report Interface 397*288bf522SAndroid Build Coastguard Worker 398*288bf522SAndroid Build Coastguard WorkerIf the above View UIs can't fulfill your need, you can use 399*288bf522SAndroid Build Coastguard Worker`simpleperf_report_lib.py` to parse perf.data, extract sample information, and 400*288bf522SAndroid Build Coastguard Workerfeed it to any views you like. 401*288bf522SAndroid Build Coastguard Worker 402*288bf522SAndroid Build Coastguard WorkerSee 403*288bf522SAndroid Build Coastguard Worker[simpleperf_report_lib.py's README](scripts_reference.md#simpleperf_report_libpy) 404*288bf522SAndroid Build Coastguard Workerfor more details. 405