agentpprof
agentpprof turns local AI coding-agent sessions into pprof-compatible semantic
profiles. It reads Codex and Claude Code JSONL history through AgentSight's
agent-session crate, assigns one-word tags to sessions, prompts, and LLM
calls, and writes one explicit output file.
The profiles are not CPU profiles. They are projections over agent activity: tool events, file effects, network effects, or token usage.
Install
From this repository:
pprof Output
Generate a semantic task profile for the current repository:
Open it with standard Go pprof:
Each sample is an operation field bag. The default stack is
task,skill,phase,action,object,repeat,result,outcome (plus token for the
tokens view). project/agent/session are pprof sample labels rather than
default stack frames (go tool pprof -tags). Override the stack with --stack,
rewrite fields with --op-map / --op-map-file, and select a subset with
--where. Folded, SVG, and JSON outputs keep the full operation stack for
drilldown.
Views
Use --view to choose the projection:
Widths mean different things by view:
operations: one count per prompt, tool, or LLM operation.tokens: token count when reported by the agent log; otherwise bounded text estimates. Very large unsafe estimates are recorded asunknown=1so one replayed transcript cannot dominate the profile with bogus token width.files: file/path effect count.network: network/domain effect count.time: duration in seconds between successive timestamped events.
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 prefix-merged flamegraph built from the folded stacks. 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-example/ for a flamegraph 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 private investigations, use explicit --session-file inputs.
Useful selectors:
No output directory is created unless the explicit -o/--output path contains
one.
Development