• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Quickstart: Record traces on Linux
2
3Perfetto can capture system traces on Linux. All ftrace-based data sources
4and most other procfs / sysfs-based data sources are supported.
5
6Currently there are no packages or prebuilts for Linux. In order to run Perfetto
7on Linux you need to build it from source.
8
9## Building from source
10
111. Check out the code:
12```bash
13git clone https://android.googlesource.com/platform/external/perfetto/ && cd perfetto
14```
15
162. Download and extract build dependencies:
17```bash
18tools/install-build-deps
19```
20_If the script fails with SSL errors, try invoking it as `python3 tools/install-build-deps`, or upgrading your openssl libraries._
21
223. Generate all most common GN build configurations:
23```bash
24tools/build_all_configs.py
25```
26
274. Build the Linux tracing binaries (On Linux it uses a hermetic clang toolchain, downloaded as part of step 2):
28```bash
29tools/ninja -C out/linux_clang_release traced traced_probes perfetto
30```
31_This step is optional when using the convenience `tools/tmux` script below._
32
33## Capturing a trace
34
35Due to Perfetto's [service-based architecture](/docs/concepts/service-model.md),
36in order to capture a trace, the `traced` (session daemon) and `traced_probes`
37(probes and ftrace-interop daemon) need to be running.
38
39For a quick start, the [tools/tmux](/tools/tmux) script takes care of building,
40setting up and running everything.
41As an example, let's look at the process scheduling data, which will be obtained
42from the Linux kernel via the [ftrace] interface.
43
44[ftrace]: https://www.kernel.org/doc/Documentation/trace/ftrace.txt
45
461. Run the convenience script with an example tracing config (10s duration):
47```
48OUT=out/linux_clang_release CONFIG=test/configs/scheduling.cfg tools/tmux -n
49```
50This will open a tmux window with three panes, one per the binary involved in
51tracing: `traced`, `traced_probes` and the `perfetto` client cmdline.
52
532. Start the tracing session by running the pre-filled `perfetto` command in
54   the down-most [consumer] pane.
55
563. Detach from the tmux session with `Ctrl-B D`,or shut it down with
57   `tmux kill-session -t demo`. The script will then copy the trace to
58   `/tmp/trace.protobuf`, as a binary-encoded protobuf (see
59   [TracePacket reference](/docs/reference/trace-packet-proto.autogen)).
60
61## Visualizing the trace
62
63We can now explore the captured trace visually by using a dedicated web-based UI.
64
65NOTE: The UI runs fully in-browser using JavaScript + Web Assembly. The trace
66      file is **not** uploaded anywhere by default, unless you explicitly click
67      on the 'Share' link.
68
691. Navigate to [ui.perfetto.dev](https://ui.perfetto.dev) in a browser.
70
712. Click the **Open trace file** on the left-hand menu, and load the captured
72   trace (by default at `/tmp/trace.protobuf`).
73
743. Explore the trace by zooming/panning using WASD, and mouse for expanding
75   process tracks (rows) into their constituent thread tracks.
76   Press "?" for further navigation controls.
77
78Alternatively, you can explore the trace contents issuing SQL queries through
79the [trace processor](/docs/analysis/trace-processor).
80