xref: /aosp_15_r20/system/extras/simpleperf/scripts/purgatorio/README.md (revision 288bf5226967eb3dac5cce6c939ccc2a7f2b4fe5)
1*288bf522SAndroid Build Coastguard Worker# Purgatorio
2*288bf522SAndroid Build Coastguard Worker
3*288bf522SAndroid Build Coastguard Worker[link on wikipedia](https://en.wikipedia.org/wiki/Purgatorio)
4*288bf522SAndroid Build Coastguard Worker
5*288bf522SAndroid Build Coastguard Worker![user interface](images/user_interface.png)
6*288bf522SAndroid Build Coastguard Worker
7*288bf522SAndroid Build Coastguard WorkerPurgatorio is a visualization tool for simpleperf traces. It's based on [libsimpleperf](https://source.corp.google.com/android/system/extras/simpleperf/;l=1?q=simpleperf&sq=package:%5Eandroid$),
8*288bf522SAndroid Build Coastguard Worker[Bokeh](https://bokeh.org/) and [D3 flamegraphs](https://github.com/spiermar/d3-flame-graph).
9*288bf522SAndroid Build Coastguard Worker
10*288bf522SAndroid Build Coastguard WorkerThe main difference from [Inferno](https://source.corp.google.com/android/system/extras/simpleperf/scripts/inferno/;l=1) is that Purgatorio focuses on visualizing system-wide traces (the ones with the `-a` argument) on a time-organized sequence, and allow the user to interact with the graph by zooming, hovering on samples and visualize a flame graph for specific samples (be it restricted by time interval, set of threads or whatever subset).
11*288bf522SAndroid Build Coastguard Worker
12*288bf522SAndroid Build Coastguard Worker## Obtaining the sources
13*288bf522SAndroid Build Coastguard Worker
14*288bf522SAndroid Build Coastguard Worker    git clone sso://user/balejs/purgatorio
15*288bf522SAndroid Build Coastguard Worker
16*288bf522SAndroid Build Coastguard Worker## Getting ready
17*288bf522SAndroid Build Coastguard Worker
18*288bf522SAndroid Build Coastguard Worker**NOTE**: In theory it should work on most OSes, but Purgatorio has been tested on gLinux only. Any feedback, recommendations and patches to get it work elsewhere will be welcome (balejs@).
19*288bf522SAndroid Build Coastguard Worker
20*288bf522SAndroid Build Coastguard WorkerPurgatorio tends to be self-contained, but Bokeh and some of its dependencies aren't shipped with the default python libraries, hence they require to be installed with pip3. Assuming they already have python3 installed, Purgatorio hopefuls should follow these steps:
21*288bf522SAndroid Build Coastguard Worker
22*288bf522SAndroid Build Coastguard Worker    $ sudo apt-get install python3-pip
23*288bf522SAndroid Build Coastguard Worker    $ pip3 install jinja2 bokeh pandas
24*288bf522SAndroid Build Coastguard Worker
25*288bf522SAndroid Build Coastguard WorkerRun `python3 purgatorio.py -h` for a list of command-line arguments.
26*288bf522SAndroid Build Coastguard Worker
27*288bf522SAndroid Build Coastguard Worker## Example
28*288bf522SAndroid Build Coastguard Worker
29*288bf522SAndroid Build Coastguard WorkerOne can trace a Camera warm launch with:
30*288bf522SAndroid Build Coastguard Worker
31*288bf522SAndroid Build Coastguard Worker    $ adb shell simpleperf record --trace-offcpu --call-graph fp -o /data/local/camera_warm_launch.data -a
32*288bf522SAndroid Build Coastguard Worker    [launch camera here, then press ctrl + c]
33*288bf522SAndroid Build Coastguard Worker    $ adb pull /data/local/camera_warm_launch.data
34*288bf522SAndroid Build Coastguard Worker
35*288bf522SAndroid Build Coastguard WorkerAnd then run:
36*288bf522SAndroid Build Coastguard Worker
37*288bf522SAndroid Build Coastguard Worker    python3 purgatorio.py camera_warm_launch.data
38*288bf522SAndroid Build Coastguard Worker
39*288bf522SAndroid Build Coastguard WorkerIf you get lots of "Failed to read symbols" messages, and backtraces in the diagram don't show the symbols you're interested into, you might want to try [building a symbols cache](https://chromium.googlesource.com/android_ndk/+/refs/heads/master/simpleperf/doc/README.md#how-to-solve-missing-symbols-in-report) for the trace, then run purgatorio again with:
40*288bf522SAndroid Build Coastguard Worker
41*288bf522SAndroid Build Coastguard Worker    python3 purgatorio.py camera_warm_launch.data -u [symbols cache]
42*288bf522SAndroid Build Coastguard Worker
43*288bf522SAndroid Build Coastguard Worker# Purgatorio interface
44*288bf522SAndroid Build Coastguard WorkerThe Purgatorio User Interface is divided in three areas:
45*288bf522SAndroid Build Coastguard Worker
46*288bf522SAndroid Build Coastguard Worker## Main Graph
47*288bf522SAndroid Build Coastguard WorkerIt's the area to the left, including process names and color-coded dots grouped by process. It's used to navigate throungh the trace and identify samples of ineterest. By hovering on a sample (or set of samples) their callstacks will be visualized over the graph. When selecting a et of samples, their aggregated data will be visualized in the other sections of the UI. Multiple sections of the graph can be aggregated by holding down the [ctrl] button during selection.
48*288bf522SAndroid Build Coastguard Worker
49*288bf522SAndroid Build Coastguard WorkerThe toolbox to the right can be used to configure interactions with the graph:
50*288bf522SAndroid Build Coastguard Worker
51*288bf522SAndroid Build Coastguard Worker![toolbox description](images/toolbox.png)
52*288bf522SAndroid Build Coastguard Worker
53*288bf522SAndroid Build Coastguard Worker## Flame graph
54*288bf522SAndroid Build Coastguard WorkerThe flame graph is located in the upper right portion. Once samples are selected in the main graph, the flame graph will show an interactive visualization for their aggregated callstacks. In this case the selection included mostly samples for com.google.android.GoogleCamera
55*288bf522SAndroid Build Coastguard Worker
56*288bf522SAndroid Build Coastguard Worker![flame graph](images/flame_graph.png)
57*288bf522SAndroid Build Coastguard Worker
58*288bf522SAndroid Build Coastguard WorkerIt's possible to select a given stack entry to zoom on it and look at entry deeper in the callstack
59*288bf522SAndroid Build Coastguard Worker
60*288bf522SAndroid Build Coastguard Worker![flame graph](images/flame_graph_zoomed.png)
61*288bf522SAndroid Build Coastguard Worker
62*288bf522SAndroid Build Coastguard WorkerWhen studiyng system issues it's often useful to visualize an inverted callstack. This can be done by clicking the related check box. The graph below is the same as in the first flame graph above, but with call stack inverted. In this case, inverted visualization directly points at [possible issues with io](http://b/158783580#comment12)
63*288bf522SAndroid Build Coastguard Worker
64*288bf522SAndroid Build Coastguard Worker![inverted flame graph](images/inverted_flame_graph.png)
65*288bf522SAndroid Build Coastguard Worker
66*288bf522SAndroid Build Coastguard Worker## Sample table
67*288bf522SAndroid Build Coastguard WorkerIt's located in the lower right and counts samples by thread (for direct flame graphs) or symbol (for inverted flame graphs). Table columns can be sorted by clicking on their respective layers, and selecting specific lines filters the contents of the flame graph to the selected threads or symbols. Multiple lines can be selected at the same time.
68*288bf522SAndroid Build Coastguard Worker
69*288bf522SAndroid Build Coastguard Worker![table](images/table.png)
70