Perfetto sql improvements#66
Conversation
Updates: - Replaces local stdlib documentation for schema discovery with runtime discovery using native tables. - Adds support for long-running RPC mode. - Introduces a fail-fast mechanism to stop execution if the trace file is not a system trace. - Enforces stricter SQL rules and guideline improvements.
There was a problem hiding this comment.
Code Review
This pull request updates the Perfetto trace querying documentation, adding a new guide on obtaining the trace processor and Python client, and detailing best practices such as using long-running RPC mode, intrinsic table-functions, and trace type validation. The review feedback suggests fixing Python code snippets to use f-strings for resolved port variables, correcting a grammatically incomplete phrase, and formatting a file reference as a markdown link.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| # Terminal B (or any Python process): connect to the running server. | ||
| # PORT is the value chosen in Terminal A. | ||
| from perfetto.trace_processor import TraceProcessor | ||
|
|
||
| tp = TraceProcessor(addr='127.0.0.1:PORT') |
There was a problem hiding this comment.
The Python code snippet uses the literal string '127.0.0.1:PORT', which will fail to run because PORT is not resolved as a variable. Defining PORT as a variable and using an f-string makes the code snippet directly copy-pasteable and functional.
| # Terminal B (or any Python process): connect to the running server. | |
| # PORT is the value chosen in Terminal A. | |
| from perfetto.trace_processor import TraceProcessor | |
| tp = TraceProcessor(addr='127.0.0.1:PORT') | |
| # Terminal B (or any Python process): connect to the running server. | |
| from perfetto.trace_processor import TraceProcessor | |
| PORT = 9100 # Replace with the port chosen in Terminal A | |
| tp = TraceProcessor(addr=f'127.0.0.1:{PORT}') |
|
|
||
| This skill is one *answer* to the question "where does `trace_processor` | ||
| come from?". It is intentionally **orthogonal** to the | ||
| [`sql`](sql.md): that one teaches what to do once you have a |
There was a problem hiding this comment.
In fact, I would avoid using orthogonal altogether. Use "unrelated" or "independent"
| seconds, every time. When you expect to run more than a couple of queries, start | ||
| the shell once as an HTTP RPC server and drive it from the Python client. (If | ||
| the Python client is not installed yet, the | ||
| `getting-trace-processor.md` guidelines |
| # Terminal B (or any Python process): connect to the running server. | ||
| # PORT is the value chosen in Terminal A. | ||
| from perfetto.trace_processor import TraceProcessor | ||
|
|
||
| tp = TraceProcessor(addr='127.0.0.1:PORT') |
There was a problem hiding this comment.
The Python code snippet uses the literal string '127.0.0.1:PORT', which will fail to run because PORT is not resolved as a variable. Defining PORT as a variable and using an f-string makes the code snippet directly copy-pasteable and functional.
| # Terminal B (or any Python process): connect to the running server. | |
| # PORT is the value chosen in Terminal A. | |
| from perfetto.trace_processor import TraceProcessor | |
| tp = TraceProcessor(addr='127.0.0.1:PORT') | |
| # Terminal B (or any Python process): connect to the running server. | |
| from perfetto.trace_processor import TraceProcessor | |
| PORT = 9100 # Replace with the port chosen in Terminal A | |
| tp = TraceProcessor(addr=f'127.0.0.1:{PORT}') |
|
@YasserDbeis to review. |
|
|
||
| You must follow these steps sequentially, mirroring a multi-agent pipeline: | ||
|
|
||
| ### Step 0: Trace Type Validation (Fail Fast) |
There was a problem hiding this comment.
@YasserDbeis, @emrekultursay to review
emrekultursay
left a comment
There was a problem hiding this comment.
LGTM modulo a couple questions.
| > This is the intended behavior. This script handles lazy-loading the | ||
| > precompiled binary automatically on its first run. Use it directly. | ||
|
|
||
| ## Part 2 — The Python client (for long-running RPC mode) |
|
|
||
| A one-shot end-to-end check that the binary and the client agree: | ||
|
|
||
| ```sh |
There was a problem hiding this comment.
What about windows? Do we require WSL? Can the agent figure out the cmd.exe equivalent steps?
| - **Documentation:** The Perfetto Standard Library documentation is in [`perfetto-stdlib.md`](references/perfetto-stdlib.md). Use this file as a reference to discover available modules, find schemas (columns and types) for specific tables or views, or determine the `INCLUDE PERFETTO MODULE` statements required before drafting SQL query. | ||
| - **Execution Tool:** Queries are executed using the official `trace_processor` wrapper script downloaded directly from Perfetto. Output is returned in pure CSV format. | ||
| This skill teaches you how to extract data from a Perfetto trace file | ||
| (`.pftrace`, `.perfetto-trace`, `.pb`) using `trace_processor` and PerfettoSQL. |
There was a problem hiding this comment.
Is .perfetto not a valid file extension for perfetto traces?
| WHERE slice.name GLOB '*{name_pattern}*'; | ||
| ``` | ||
|
|
||
| ## Execution Protocol |
There was a problem hiding this comment.
Is there any reason why we are not using the exact same "execution protocol" as perfetto's skill at this point since we merged our changes into theirs? I would like to minimize the delta as much as possible.
| ``` | ||
|
|
||
| Multiple statements separated by `;` are supported in one invocation. | ||
|
|
There was a problem hiding this comment.
I noticed that the perfetto skill had this block here--should we include it as well to minimize the delta (see other comment):
`TRACE_FILE` can be a local path, an `http(s)://` URL, or a Perfetto UI
share link (`https://ui.perfetto.dev/#!/?s=<hash>`) — in the last two
cases trace_processor downloads the trace for you, resolving the share
link to its underlying trace first:
```sh
trace_processor query "https://ui.perfetto.dev/#!/?s=<hash>" \
"SELECT name, dur FROM slice ORDER BY dur DESC LIMIT 10"
Downloaded traces are cached locally (under ~/.cache/perfetto/, or the
platform equivalent), so re-running on the same URL doesn't re-download.
The same URL/share-link form works anywhere a trace path is accepted
(query, server, the interactive shell, etc.).
Updates:
runtime discovery using native tables.
trace file is not a system trace.