This page documents Perfetto UI's stable command surface specifically for automation use cases. These commands have backwards compatibility guarantees and can be safely used in automated workflows, startup configurations, macros, and deep linking.
While Perfetto UI uses commands internally for all user interactions, this reference focuses exclusively on the subset of commands that are stable for automation purposes. These stable automation commands are designed for:
Commands outside this automation reference are internal implementation details with no backwards compatibility guarantees and may change without warning.
For automation commands listed in this reference, Perfetto UI guarantees:
dev.perfetto.RunQuery) will not changeOptional parameters may be added to commands without notice, but will not affect existing usage.
These commands control how tracks are displayed in the timeline view.
dev.perfetto.PinTracksByRegexPins tracks matching a regular expression pattern to the top of the timeline.
Arguments:
pattern (string, required): Regular expression to match track namesExample:
{ "id": "dev.perfetto.PinTracksByRegex", "args": [".*surfaceflinger.*"] }
Common patterns:
".*CPU \\d+$"".*com\\.example\\.app.*"".*(system_server|surfaceflinger).*"dev.perfetto.ExpandTracksByRegexExpands track groups matching a regular expression pattern.
Arguments:
pattern (string, required): Regular expression to match track group namesExample:
{ "id": "dev.perfetto.ExpandTracksByRegex", "args": [".*system_server.*"] }
dev.perfetto.CollapseTracksByRegexCollapses track groups matching a regular expression pattern.
Arguments:
pattern (string, required): Regular expression to match track group namesExample:
{ "id": "dev.perfetto.CollapseTracksByRegex", "args": ["CPU Scheduling"] }
Tip: Use ".*" to collapse all tracks as a starting point for focused analysis.
Create custom visualization tracks from SQL queries. Debug tracks are overlaid on the timeline and update automatically when the view changes.
dev.perfetto.AddDebugSliceTrackCreates a slice track from a SQL query returning time intervals.
Arguments:
query (string, required): SQL query that must return:ts (number): Timestamp in nanosecondsdur (number): Duration in nanosecondsname (string): Slice name to displaytitle (string, required): Display name for the trackExample:
{ "id": "dev.perfetto.AddDebugSliceTrack", "args": [ "SELECT ts, dur, name FROM slice WHERE dur > 10000000 ORDER BY dur DESC LIMIT 100", "Long Slices (>10ms)" ] }
dev.perfetto.AddDebugSliceTrackWithPivotCreates multiple slice tracks grouped by a pivot column. Each unique value in the pivot column gets its own track.
Arguments:
query (string, required): SQL query that must return:ts (number): Timestamp in nanosecondsdur (number): Duration in nanosecondsname (string): Slice name to displaypivotColumn (string, required): Column name to group tracks bytitle (string, required): Base title for the track groupExample:
{ "id": "dev.perfetto.AddDebugSliceTrackWithPivot", "args": [ "SELECT ts, dur, name, IFNULL(category, '[NULL]') as category FROM slice WHERE dur > 1000000", "category", "Slices by Category" ] }
Note: Use IFNULL() to handle NULL values in the pivot column, as NULLs will cause the command to fail.
dev.perfetto.AddDebugCounterTrackCreates a counter track from a SQL query returning time-series data.
Arguments:
query (string, required): SQL query that must return:ts (number): Timestamp in nanosecondsvalue (number): Counter valuetitle (string, required): Display name for the trackExample:
{ "id": "dev.perfetto.AddDebugCounterTrack", "args": ["SELECT ts, value FROM counter WHERE track_id = 42", "Memory Usage"] }
dev.perfetto.AddDebugCounterTrackWithPivotCreates multiple counter tracks grouped by a pivot column.
Arguments:
query (string, required): SQL query that must return:ts (number): Timestamp in nanosecondsvalue (number): Counter valuepivotColumn (string, required): Column name to group tracks bytitle (string, required): Base title for the track groupExample:
{ "id": "dev.perfetto.AddDebugCounterTrackWithPivot", "args": [ "SELECT ts, value, name FROM counter JOIN counter_track ON counter.track_id = counter_track.id", "name", "System Counters" ] }
Workspaces allow you to create custom views of your trace data by organizing specific tracks together.
dev.perfetto.CreateWorkspaceCreates a new empty workspace.
Arguments:
title (string, required): Name for the new workspaceExample:
{ "id": "dev.perfetto.CreateWorkspace", "args": ["Memory Analysis"] }
dev.perfetto.SwitchWorkspaceSwitches to an existing workspace by name.
Arguments:
title (string, required): Name of the workspace to switch toExample:
{ "id": "dev.perfetto.SwitchWorkspace", "args": ["Memory Analysis"] }
Note: The workspace must exist before switching to it.
dev.perfetto.CopyTracksToWorkspaceByRegexCopies tracks matching a pattern to a workspace.
Arguments:
pattern (string, required): Regular expression to match track namesworkspaceTitle (string, required): Target workspace nameExample:
{ "id": "dev.perfetto.CopyTracksToWorkspaceByRegex", "args": ["(Expected|Actual) Timeline", "Frame Analysis"] }
dev.perfetto.CopyTracksToWorkspaceByRegexWithAncestorsCopies tracks matching a pattern to a workspace, including their parent track groups for context.
Arguments:
pattern (string, required): Regular expression to match track namesworkspaceTitle (string, required): Target workspace nameExample:
{ "id": "dev.perfetto.CopyTracksToWorkspaceByRegexWithAncestors", "args": ["RenderThread", "Rendering Analysis"] }
dev.perfetto.RunQueryExecutes a PerfettoSQL query without displaying results.
Arguments:
query (string, required): PerfettoSQL query to executeExample:
{ "id": "dev.perfetto.RunQuery", "args": [ "CREATE PERFETTO FUNCTION my_func(x INT) RETURNS INT AS SELECT $x * 2" ] }
dev.perfetto.RunQueryAndShowTabExecutes a PerfettoSQL query and displays results in a new query tab.
Arguments:
query (string, required): PerfettoSQL query to executeExample:
{ "id": "dev.perfetto.RunQueryAndShowTab", "args": ["SELECT ts, dur, name FROM slice LIMIT 50"] }
Macros are user-defined sequences of commands that execute in order. They provide a way to automate complex, multi-step analysis workflows.
Macros can be defined through the UI settings and automatically get stable command IDs.
Command Pattern:
dev.perfetto.UserMacro.{macroName} - Executes a user-defined macroArguments:
None (macro commands and arguments are pre-configured)
Example:
{ "id": "dev.perfetto.UserMacro.MyAnalysisWorkflow", "args": [] }
Notes:
These stable automation commands can be used in several contexts:
For practical automation examples and recipes, see the UI Automation guide.
To request a command be added to the stable automation surface:
Commands are prioritized based on: