Skip to content

Perfetto sql improvements#66

Open
JoseAlcerreca wants to merge 4 commits into
android:github-skillsfrom
harshitrawatjgd:perfetto-sql-improvements
Open

Perfetto sql improvements#66
JoseAlcerreca wants to merge 4 commits into
android:github-skillsfrom
harshitrawatjgd:perfetto-sql-improvements

Conversation

@JoseAlcerreca
Copy link
Copy Markdown
Collaborator

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.

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.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +68 to +72
# 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')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
# 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The phrase 'orthogonal to the sql' is grammatically incomplete. It should be updated to 'orthogonal to the sql guidelines' or 'orthogonal to the sql skill' for better clarity.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The reference to getting-trace-processor.md is plain text. It should be formatted as a markdown link [getting-trace-processor.md](getting-trace-processor.md) to match the style used elsewhere in the document (such as on line 13).

Comment on lines +47 to +51
# 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')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
# 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}')

@harshitrawatjgd
Copy link
Copy Markdown

@YasserDbeis to review.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update last-updated

@JoseAlcerreca JoseAlcerreca requested a review from YasserDbeis June 5, 2026 13:11

You must follow these steps sequentially, mirroring a multi-agent pipeline:

### Step 0: Trace Type Validation (Fail Fast)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown

@emrekultursay emrekultursay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this tested on windows?


A one-shot end-to-end check that the binary and the client agree:

```sh
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is .perfetto not a valid file extension for perfetto traces?

WHERE slice.name GLOB '*{name_pattern}*';
```

## Execution Protocol
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants