How to Run a Perfetto Trace on Oculus Quest or Quest 2
James Leitch, Software Engineer, Facebook
UPDATE: The recommended way to run a Perfetto trace is using the Perfetto functionality now available in ODH.
Perfetto is an Android system-wide profiling tool (as of Android 10) that provides information on system events such as scheduling activity, in addition to app-level instrumentation for apps that integrate with Perfetto or ATrace. It is a replacement for systrace that supports a larger selection of events, longer traces, and offers better performance, in addition to adding support for counters. For more information on Perfetto, check out https://perfetto.dev/.
With our v27 OS update, we’ve enabled Perfetto by default on both Oculus Quest and Quest 2 when Developer Mode is turned on. The v27 OS update also shipped with both VrApi and GPU emitting metrics to Perfetto which can be enabled on your traces.
Quest developers can use Perfetto to profile their apps with additional context of the overall system it is executing on. Over time, we plan to expose more Oculus-specific data that will be available via Perfetto.
Emitting Data from your App
In order for events from your app to show up in a Perfetto trace, your app must be annotated either with Perfetto TrackEvents or with ATrace. If you need to annotate your app, we recommend choosing Perfetto TrackEvents as the more performant option. Make sure your Perfetto config (covered below) has the appropriate TrackEvent or ATrace data source.
For instructions on adding Perfetto TrackEvents, start here.
Perfetto Setup
To record a new trace, you'll first need to set up a few files. You will need to create a working directory. This is where you'll create a Perfetto config and where the trace will be written to. (We show a setup with a Python script below, but you can also use the Git Bash / WSL / Cygwin script provided at the end of this post.)
Create a working directory that will contain the Perfetto configuration, scripts, and trace output
For the purposes of this post, we'll call the directory perfetto_traces, but you can name it whatever you want.
Create your Perfetto configuration (config.txt)
Create a text file at perfetto_traces/config.txt.
Populate the file with your trace configuration. The best starting place is to use the Web UI (https://ui.perfetto.dev/) to generate a Perfetto configuration, and then tweak it from there.
In the Web UI, click Record new trace.
Select the various data sources you'd like to record.
Copy the config presented in the Trace command section. Make sure to only copy the configuration, not the entire command (see selected text).
NOTE: Both Perfetto app instrumentation and VrApi/GPU metrics are part of Perfetto TrackEvents, which is a data source the Web UI does not support generating configurations for. In order to record these, add the following to your config:
data_sources: {
config {
name: "track_event"
}
}
NOTE: GPU metrics require that adb shell ovrgpuprofiler -r is running in the background for the duration of the trace.
Example Config File
Below is an example config file that will record VrApi and GPU metrics, as well as any other Perfetto TrackEvents being emitted on the device.