xref: /aosp_15_r20/external/perfetto/docs/visualization/large-traces.md (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1*6dbdd20aSAndroid Build Coastguard Worker# Visualising large traces
2*6dbdd20aSAndroid Build Coastguard Worker
3*6dbdd20aSAndroid Build Coastguard WorkerBrowsers often limit the amount of memory a site can use.
4*6dbdd20aSAndroid Build Coastguard WorkerThis can cause problems when visualising large traces.
5*6dbdd20aSAndroid Build Coastguard Worker
6*6dbdd20aSAndroid Build Coastguard Worker## Using TraceProcessor as a native accelerator
7*6dbdd20aSAndroid Build Coastguard Worker
8*6dbdd20aSAndroid Build Coastguard WorkerPerfetto UI supports offloading the parsing and processing of the trace to a
9*6dbdd20aSAndroid Build Coastguard Worker'server' instance of TraceProcessor running natively on your local machine.
10*6dbdd20aSAndroid Build Coastguard WorkerThis server process can take full advantage of the RAM of your machine as well
11*6dbdd20aSAndroid Build Coastguard Workeras running at full native (rather than WebAssembly) performance, leveraging
12*6dbdd20aSAndroid Build Coastguard WorkerSSE on modern x86_64 machines.
13*6dbdd20aSAndroid Build Coastguard Worker
14*6dbdd20aSAndroid Build Coastguard Worker```bash
15*6dbdd20aSAndroid Build Coastguard Workercurl -LO https://get.perfetto.dev/trace_processor
16*6dbdd20aSAndroid Build Coastguard Workerchmod +x ./trace_processor
17*6dbdd20aSAndroid Build Coastguard Worker./trace_processor --httpd /path/to/trace.pftrace
18*6dbdd20aSAndroid Build Coastguard Worker```
19*6dbdd20aSAndroid Build Coastguard Worker
20*6dbdd20aSAndroid Build Coastguard WorkerThen open https://ui.perfetto.dev as usual.
21*6dbdd20aSAndroid Build Coastguard Worker
22*6dbdd20aSAndroid Build Coastguard WorkerThe Perfetto UI will automatically detect the presence of
23*6dbdd20aSAndroid Build Coastguard Worker`trace_processor --httpd` by probing http://127.0.0.1:9001 . When detected it
24*6dbdd20aSAndroid Build Coastguard Workerwill prompt a dialog that asks if you want to use the external accelerator via
25*6dbdd20aSAndroid Build Coastguard Workera WebSocket or the built-in WebAssembly runtime that runs in the browser.
26*6dbdd20aSAndroid Build Coastguard Worker
27*6dbdd20aSAndroid Build Coastguard Worker## Using more than one instance in parallel
28*6dbdd20aSAndroid Build Coastguard Worker
29*6dbdd20aSAndroid Build Coastguard WorkerNOTE: this is a temporary workaround until getting to a better solution as
30*6dbdd20aSAndroid Build Coastguard Workerdescribed in [b/317076350](http://b/317076350) (Googlers only).
31*6dbdd20aSAndroid Build Coastguard Worker
32*6dbdd20aSAndroid Build Coastguard WorkerAs per [r.android.com/2940133](https://r.android.com/2940133) (Feb 2024) it is
33*6dbdd20aSAndroid Build Coastguard Workerpossible to run different instances of trace_processor on different ports, and
34*6dbdd20aSAndroid Build Coastguard Workerpoint the UI to them.
35*6dbdd20aSAndroid Build Coastguard Worker
36*6dbdd20aSAndroid Build Coastguard Worker**Pre-requisite:** Enable the
37*6dbdd20aSAndroid Build Coastguard Worker[Relax CSP flag](https://ui.perfetto.dev/#!/flags/cspAllowAnyWebsocketPort). You
38*6dbdd20aSAndroid Build Coastguard Workerneed to do this only once. If the flag is not displayed, the CL above has not
39*6dbdd20aSAndroid Build Coastguard Workermade it into the release channel you are using (try Canary or Autopush)
40*6dbdd20aSAndroid Build Coastguard Worker
41*6dbdd20aSAndroid Build Coastguard Worker```bash
42*6dbdd20aSAndroid Build Coastguard Worker./trace_processor --httpd --http-port 9001 trace1.pftrace
43*6dbdd20aSAndroid Build Coastguard Worker./trace_processor --httpd --http-port 9002 trace2.pftrace
44*6dbdd20aSAndroid Build Coastguard Worker./trace_processor --httpd --http-port 9003 trace3.pftrace
45*6dbdd20aSAndroid Build Coastguard Worker```
46*6dbdd20aSAndroid Build Coastguard Worker
47*6dbdd20aSAndroid Build Coastguard WorkerThen open the UI in three tabs as follows:
48*6dbdd20aSAndroid Build Coastguard Worker* https://ui.perfetto.dev/#!/?rpc_port=9001
49*6dbdd20aSAndroid Build Coastguard Worker* https://ui.perfetto.dev/#!/?rpc_port=9002
50*6dbdd20aSAndroid Build Coastguard Worker* https://ui.perfetto.dev/#!/?rpc_port=9003
51*6dbdd20aSAndroid Build Coastguard Worker
52*6dbdd20aSAndroid Build Coastguard Worker## How big is too big?
53*6dbdd20aSAndroid Build Coastguard Worker
54*6dbdd20aSAndroid Build Coastguard WorkerThe exact memory limit can vary by browser, architecture, and OS however 2GB is
55*6dbdd20aSAndroid Build Coastguard Workertypical. This limit is a limit on the total memory used at runtime, not on the
56*6dbdd20aSAndroid Build Coastguard Workerbinary size of the trace.
57*6dbdd20aSAndroid Build Coastguard WorkerThe `trace_processor` (and hence the UI) representation of a trace at runtime is
58*6dbdd20aSAndroid Build Coastguard Workernormally larger than the binary size of that trace.
59*6dbdd20aSAndroid Build Coastguard WorkerThis is because the representation is optimized for query performance rather
60*6dbdd20aSAndroid Build Coastguard Workerthan size. The exact inflation factor varies depending on the trace format but
61*6dbdd20aSAndroid Build Coastguard Workercan be 2-4x for uncompressed proto traces.
62