agentpprof
agentpprof turns local AI coding-agent sessions into pprof-compatible semantic
profiles. It reads Codex and Claude Code JSONL history, assigns short semantic
tags to sessions, prompts, LLM calls, and effects, and writes outputs that can
be inspected with standard pprof or flamegraph tooling.
The profiles are not CPU profiles. They are projections over agent activity: token usage, tool events, file effects, network effects, or elapsed session time.
Install
From this repository, matching the checked artifact smoke:
Published registry releases may lag this research branch. Use the source-tree install above when reproducing the paper artifacts.
For local development without installing:
Public Fixture Smoke
For a reproducible first run that does not read private local agent histories,
use the committed synthetic Codex fixture. Artifact reviewers should prefer
this explicit --session-file command because it avoids default discovery of
local Codex/Claude histories.
The fixture checks parser, projection, and pprof readback behavior only. It is not evidence of developer utility, tag adequacy, or real-history privacy.
pprof Output
Generate a semantic profile for the current repository:
Open it with standard Go pprof:
Views
Use --view to choose the projection:
Widths mean different things by view:
tokens: token count when reported by the agent log.files: file/path effect count.network: network/domain effect count.time: elapsed session time.
Other Formats
The default format is pprof protobuf, gzipped when the output path ends in
.gz. The output extension also selects common formats:
Folded stacks are compatible with common flamegraph tooling. SVG output is a
single quick-look stack chart built from the folded stacks; use folded output
with standard tools such as inferno or flamegraph.pl when you need canonical
merged-prefix flamegraphs. JSON output includes redacted session summaries and
the stack table. Passing --include-previews writes prompt, command, and
LLM-output previews into JSON; avoid it for public artifacts unless the source
sessions are already sanitized. Path frames outside the selected project root
are grouped into stable external/* buckets so home-directory names are not
emitted in public profiles. See ../docs/flamegraph/ for a public fixture
gallery and view-by-view usage examples.
Tags
The default tagger is deterministic:
Add project-specific deterministic rules with repeated --tag-rule
arguments. Rules use KIND:TAG=REGEX, are tried in command-line order before
the built-in rules, and support session, prompt, llm, or all as
KIND:
For model-produced one-word tags, run a llama.cpp-compatible server and use:
LLM tags are cached under the user cache directory by default, for example
$XDG_CACHE_HOME/agentpprof/tags.json. Override with --cache, or pass
--no-cache to avoid saving new entries.
Selecting Sessions
By default, agentpprof scans recent local Codex and Claude Code sessions that
match --project-root.
Those logs can contain prompts, paths, model outputs, and tool results. For
repeatable demos, tests, or public artifacts, prefer explicit --session-file
inputs like the fixture above.
Useful selectors:
No output directory is created unless the explicit -o/--output path contains
one.
Python Prototype
The earlier experimental Python exporter now lives under
docs/visexp/agentpprof-python/ as research material:
PYTHONPATH=docs/visexp/agentpprof-python/src
The export writes:
tokens.pb.gztools.pb.gzfiles.pb.gznetwork.pb.gz- matching folded stacks
*.flame.svgsemantic flamegraphsagentpprof.json- optional
*.top.txtreports whengo tool pprofis available
Open the generated flamegraphs directly:
Stack Projections
Token profile:
project:<repo>;agent:<codex|claude>;session:<tag>;prompt:<tag>;call:llm/<tag>;model:<model>;token:<kind>
Width: token count.
Tool/effect profile:
project:<repo>;agent:<codex|claude>;session:<tag>;prompt:<tag>;call:tool/<tag>;tool:<kind>;process:<cmd>;effect:<effect>;target:<group>;status:<status>
Width: observed tool event count.
File and network profiles use the same semantic session/prompt context, but
make file:<group> or domain:<domain> the leaf frame. Their widths are file
target event count and network target event count.
The Python pprof exporter reverses semantic stacks when serializing samples because pprof stores the leaf frame first.
Development
PYTHONPATH=docs/visexp/agentpprof-python/src