1# Running Perfetto 2 3In 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`: 7The unprivileged trace daemon that owns the log buffers and maintains 8a registry of Producers and Consumers connected. 9 10`traced_probes`: 11The 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 14protobuf-translated contents into `traced`. 15 16`perfetto`: 17A command line utility client that drive the trace and save back 18the results (either to a file or to [Android's Dropbox][dropbox]) 19 20Running from a standalone checkout (Linux, Mac or Android) 21------------------------------------------------------------- 22A convenience script allows to run Perfetto daemons (`traced`, `traced_probes`) 23and the command line client (`perfetto`) in a tmux-based terminal: 24```bash 25CONFIG=ftrace.cfg OUT=out/default ./tools/tmux 26``` 27 28The 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. 30Furthermore it will automatically rebuild if necessary. 31 32Running from an Android P+ in-tree build 33---------------------------------------- 34Make sure that Perfetto daemons (`traced` / `traced_probes`) are running. 35They are enabled by default on Pixel and Pixel 2 (walleye, taimen, marlin, 36sailfish). On other devices start them manually by doing: 37```bash 38adb shell setprop persist.traced.enable 1 39``` 40 41If this works you will see something like this in the logs: 42```bash 43$ adb logcat -s perfetto 44perfetto: service.cc:45 Started traced, listening on /dev/socket/traced_producer /dev/socket/traced_consumer 45perfetto: probes.cc:25 Starting /system/bin/traced_probes service 46perfetto: probes_producer.cc:32 Connected to the service 47``` 48 49At 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 55For more advanced configurations see the [Trace Config](#trace-config) section. 56 57*** aside 58If the output file is not under `/data/misc/perfetto-traces`, tracing will 59fail due to SELinux. 60*** 61 62*** aside 63For security reasons the trace file is written with 0600 (rw-------) permissions 64and 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 66the trace out of the device, do the following: 67`adb shell cat /data/misc/perfetto-traces/trace > ~/trace` 68*** 69 70Trace config 71------------ 72`--config :test` uses a hard-coded test trace config. It is possible to pass 73an 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