1 # Running Perfetto 2 3 In order to run Perfetto and get a meaningful trace you need to build 4 (see [build instructions](build-instructions.md)) and run the following: 5 6 `traced`: 7 The unprivileged trace daemon that owns the log buffers and maintains 8 a registry of Producers and Consumers connected. 9 10 `traced_probes`: 11 The privileged daemon that has access to the Kernel tracefs 12 (typically mounted under `/sys/kernel/debug/tracing`). It drives 13 [Ftrace](https://source.android.com/devices/tech/debug/ftrace) and writes its 14 protobuf-translated contents into `traced`. 15 16 `perfetto`: 17 A command line utility client that drive the trace and save back 18 the results (either to a file or to [Android's Dropbox][dropbox]) 19 20 Running from a standalone checkout (Linux, Mac or Android) 21 ------------------------------------------------------------- 22 A convenience script allows to run Perfetto daemons (`traced`, `traced_probes`) 23 and the command line client (`perfetto`) in a tmux-based terminal: 24 ```bash 25 CONFIG=ftrace.cfg OUT=out/default ./tools/tmux 26 ``` 27 28 The script will automatically serialize the trace config defined in the 29 `CONFIG` variable (e.g., [this](https://android.googlesource.com/platform/external/perfetto/+/master/test/configs/ftrace.cfg)) into a protobuf and setup the right paths. 30 Furthermore it will automatically rebuild if necessary. 31 32 Running from an Android P+ in-tree build 33 ---------------------------------------- 34 Make sure that Perfetto daemons (`traced` / `traced_probes`) are running. 35 They are enabled by default on Pixel and Pixel 2 (walleye, taimen, marlin, 36 sailfish). On other devices start them manually by doing: 37 ```bash 38 adb shell setprop persist.traced.enable 1 39 ``` 40 41 If this works you will see something like this in the logs: 42 ```bash 43 $ adb logcat -s perfetto 44 perfetto: service.cc:45 Started traced, listening on /dev/socket/traced_producer /dev/socket/traced_consumer 45 perfetto: probes.cc:25 Starting /system/bin/traced_probes service 46 perfetto: probes_producer.cc:32 Connected to the service 47 ``` 48 49 At which point you can grab a trace by doing: 50 51 ```bash 52 $ adb shell perfetto --config :test --out /data/misc/perfetto-traces/trace 53 ``` 54 55 For more advanced configurations see the [Trace Config](#trace-config) section. 56 57 *** aside 58 If the output file is not under `/data/misc/perfetto-traces`, tracing will 59 fail due to SELinux. 60 *** 61 62 *** aside 63 For security reasons the trace file is written with 0600 (rw-------) permissions 64 and owned by shell. On rooted (`userbuild`) devices it is possible to just 65 `adb pull` the file after `adb root`. On `user` devices instead, in order to get 66 the trace out of the device, do the following: 67 `adb shell cat /data/misc/perfetto-traces/trace > ~/trace` 68 *** 69 70 Trace config 71 ------------ 72 `--config :test` uses a hard-coded test trace config. It is possible to pass 73 an arbitrary trace config. See instructions in the 74 [trace config](trace-config.md) page. 75 76 77 [dropbox]: https://developer.android.com/reference/android/os/DropBoxManager.html 78