agent2perfetto
Don't build a viewer — put agent traces in the best one.
agent2perfetto converts agent session logs into
Perfetto / Chrome Trace Event JSON that loads in
ui.perfetto.dev — the free, browser-based trace viewer Google built
for Chrome and Android profiling. You get hierarchical slices, counter time series, flow
arrows, and PerfettoSQL over your agent session without anyone writing a line of viewer code.
Supported inputs: Claude Code session JSONL and Codex CLI rollout logs (auto-detected;
--format to override).
The problem
Agent observability today is bipolar:
- Vendor SaaS dashboards (LangSmith, LangFuse): cloud accounts, proprietary UIs, your traces leaving your machine.
- Text dumps and aggregators (ccusage): totals and averages, no time axis.
But an agent session is a hierarchical event stream on a timeline: session → turns → tool calls → results. The one local UI that renders exactly that shape — millions of events, layered slices, counter tracks, flows — already exists, is free, runs in your browser, and officially accepts arbitrary trace-like data. Nobody was sending agent traces to it. This project is exactly that adapter.
Quickstart
Requires Python 3.10+, stdlib only, zero runtime network calls.
# from PyPI
pip install agent2perfetto
# or from a checkout
pip install .
# convert the checked-in example
agent2perfetto examples/sample_session.jsonl
# -> examples/sample_session.perfetto.json
# convert one of your own sessions and open the viewer
agent2perfetto ~/.claude/projects/<project>/session.jsonl --open
# Codex CLI rollout logs work too (format is auto-detected)
agent2perfetto ~/.codex/sessions/2026/09/05/rollout-*.jsonl --open
--open runs macOS open https://ui.perfetto.dev (falls back to your browser elsewhere),
then prints drag-and-drop instructions. Drag the generated .perfetto.json into the UI —
the trace is parsed in your browser's memory and never uploaded. (For a fully offline
setup, Perfetto's UI also ships as a WASM bundle you can serve from localhost.)
Self-check a trace file any time:
python scripts/validate_trace.py examples/sample_session.perfetto.json
What the trace looks like (track map)
| Agent concept | Perfetto element |
|---|---|
| Session | process (one process per sessionId, named agent session <id>) |
| Assistant turns | complete slices (X) on the turns thread |
| Tool calls | complete slices named by tool (Bash, Read, …) on the tools thread |
| Tool results | complete slices (result <tool>) on the tools thread |
| Call → result | flow arrows (s/f events paired by tool_use_id) |
| Context occupancy | counter tracks ctx_total, ctx_input, ctx_cache_read, ctx_cache_create — per-call occupancy |
| Session spend | counter tracks spend_total, spend_input, spend_cache_read, spend_cache_create — cumulative |
| User prompts | instant markers on the turns thread |
Timeline rules (deterministic — same log in, same trace out):
ts= microseconds since the earliest timestamp in the file; the original epoch time and ISO base timestamp are kept inmetadata.- A turn/tool slice runs from its message timestamp to the next event's timestamp (for a
tool call, to its result's arrival). The final slice of a stream has nothing to bound it,
so it gets a 1 s estimate flagged
"dur_estimated": truein its args. - Counters are emitted at every assistant message.
ctx_*is per-call occupancy: theinput_tokens,cache_read_input_tokens,cache_creation_input_tokensthat that single call reported (plus their total) — the model's context on that turn.spend_*is the cumulative sum of the same fields across the session — the billing trajectory.
Approximation honesty
The context lane is an approximation. ctx_* counters report the usage fields each API
call claimed; they do not reproduce the provider-side context window (cache lifetime,
truncation, and system-prompt composition are not observable from the log). spend_*
counters re-bill cached tokens every call, so they grow monotonically and are not context
size. Slice durations that had no bounding event are estimates. This note ships inside every
trace under metadata.approximation_note, and the caveats above live in metadata.
Privacy: local by construction
The converter is a file-to-file transform with zero network calls. --open merely opens
a URL in your browser; the trace itself travels by drag-and-drop and is processed in the
browser locally. Nothing is uploaded, no account exists, no telemetry exists.
How this differs from adjacent tools
| Adjacent tool | Difference |
|---|---|
| LangSmith / LangFuse | Web SaaS with their own UIs and cloud storage. Here: local file → a standard format; viewer cost = 0. |
| ccusage / tokscale | Aggregates (how much was spent). Here: a time-space map (what ate context, when). |
| Perfetto itself | Provides the viewer and format but has no agent-domain adapter — that gap is exactly this project. |
| Perfetto MCP servers | The reverse direction (LLMs analyzing Perfetto traces). Here a human looks. |
| One-off "LLM trace JSON" scripts | A maintained adapter with golden-fixture tests against schema drift, plus lane semantics. |
Limits & roadmap
- v0.1 supported Claude Code JSONL only. v0.2 introduces the vendor-neutral
Agent Trace IR (docs/agent-trace-ir.md): new agent
logs enter as adapters into the same IR, so the same viewer, lanes, and
PerfettoSQL work across harnesses. The Codex CLI rollout adapter landed in
v0.2.1 (cross-validated against the yield-audit Codex parser on shared
fixtures; codex
cached_input_tokensmaps tocache_read, codex reports no cache-creation counter, and codex shell tools render asBashwith list commands joined). Subagent/async slices are also planned. - Perfetto's JSON format is the legacy entry point; a proto-format exporter is on the roadmap.
- Multiple
sessionIds in one file become multiple processes; per-subagent processes and context-composition lanes (system prompt / files / MCP schemas) are future work.
Development
python3 -m venv /tmp/a2p-venv && . /tmp/a2p-venv/bin/activate
pip install -e .
pip install pytest # test-only dependency; the package itself needs nothing
pytest
Layout: src/agent2perfetto/ — a three-stage pipeline (parser adapter →
ir Agent Trace IR → trace Perfetto emitter → cli), synthetic fixtures and
a frozen golden trace under tests/fixtures/, the example session and its
generated trace under examples/, and the IR schema at
docs/agent-trace-ir.md.
License
Apache-2.0. See LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agent2perfetto-0.2.2.tar.gz.
File metadata
- Download URL: agent2perfetto-0.2.2.tar.gz
- Upload date:
- Size: 32.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abc4bc871d73491a112776142748315c473a036c08efae5ee8729b57cb3e8cd5
|
|
| MD5 |
4b610e2fdc8ecdc7c73e2b822433e8a7
|
|
| BLAKE2b-256 |
10f792cb1b1a997c1ab576dfdfa1fd04f929472f2774fd8d5c1e10b550523bf6
|
Provenance
The following attestation bundles were made for agent2perfetto-0.2.2.tar.gz:
Publisher:
pypi.yml on ictechgy/agent2perfetto
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agent2perfetto-0.2.2.tar.gz -
Subject digest:
abc4bc871d73491a112776142748315c473a036c08efae5ee8729b57cb3e8cd5 - Sigstore transparency entry: 2728534532
- Sigstore integration time:
-
Permalink:
ictechgy/agent2perfetto@c7c8ac11d4b86d10eff2f056b267680652e61006 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/ictechgy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@c7c8ac11d4b86d10eff2f056b267680652e61006 -
Trigger Event:
release
-
Statement type:
File details
Details for the file agent2perfetto-0.2.2-py3-none-any.whl.
File metadata
- Download URL: agent2perfetto-0.2.2-py3-none-any.whl
- Upload date:
- Size: 26.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edaed5752b4ab40f6f66a7f4980561a81348d7bc3301db165633c2d8debc248f
|
|
| MD5 |
8cacf9fc07b11356b123ed8a4daec9cb
|
|
| BLAKE2b-256 |
56fc2cbc2804adc43ad0d329ad8696f2d94b7960ebb87d1c2bb58702caa2c4b3
|
Provenance
The following attestation bundles were made for agent2perfetto-0.2.2-py3-none-any.whl:
Publisher:
pypi.yml on ictechgy/agent2perfetto
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agent2perfetto-0.2.2-py3-none-any.whl -
Subject digest:
edaed5752b4ab40f6f66a7f4980561a81348d7bc3301db165633c2d8debc248f - Sigstore transparency entry: 2728535967
- Sigstore integration time:
-
Permalink:
ictechgy/agent2perfetto@c7c8ac11d4b86d10eff2f056b267680652e61006 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/ictechgy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@c7c8ac11d4b86d10eff2f056b267680652e61006 -
Trigger Event:
release
-
Statement type: