Raw SQL Queries¶
Execute PerfettoSQL queries directly against trace data.
Overview¶
When built-in analysis commands don't cover your specific need, you can run raw PerfettoSQL queries. This gives you full access to the trace data model.
Commands¶
query sql¶
Execute a PerfettoSQL query.
# Inline query
perfetto-cli -t trace.perfetto-trace query sql --query "SELECT * FROM slice LIMIT 10"
# Query from file
perfetto-cli -t trace.perfetto-trace query sql --file query.sql
Options:
| Option | Description |
|---|---|
--query <sql> |
SQL query string |
--file <path> |
Path to SQL file |
query find-slices¶
Search for trace slices by name pattern.
Options:
| Option | Description | Default |
|---|---|---|
--pattern <text> |
Search pattern | Required |
--match-type <type> |
Match type: contains, exact, glob |
contains |
query slice-info¶
Get detailed information about a specific slice.
Common Queries¶
-- List all processes in the trace
SELECT pid, name FROM process ORDER BY name;
-- Find long-running slices
SELECT name, dur/1e6 as dur_ms FROM slice WHERE dur > 16000000 ORDER BY dur DESC LIMIT 20;
-- Count slices by name
SELECT name, COUNT(*) as cnt FROM slice GROUP BY name ORDER BY cnt DESC LIMIT 20;
Tips¶
- Use
find-slicesto discover slice names before writing complex queries - PerfettoSQL documentation: perfetto.dev/docs/analysis/sql-tables
- Combine
--filewith version-controlled.sqlfiles for repeatable analysis