Runnable proof of concept
Continuous profiling for an Orca workspace.
Rank agent tools across Orca worktrees with a Rust CLI, then inspect an example trace in Tempo, tool metrics in Prometheus and CPU samples in Pyroscope.
Two agents can each use a core for 18 seconds and finish together in 18 seconds. This lab runs exactly that experiment. The trace records each tool’s CPU and wall time. A continuous eBPF sampler on the Linux worker records what was executing while the agents overlapped. You can inspect the evidence after both processes exit.
Get the Rust CLI and Orca panel from the public repository (opens new window) or the v0.2.0 release (opens new window).
# Which tools should I optimize first?
Open the local leaderboard (opens new window) for all worktrees, or run codeperf-agent top for the current worktree. Each row links to an example on the provisioned Grafana dashboard. By default it ranks tools across the most recent 24 hours. Share s divides each interval equally among the distinct tools active in that trace. Two overlapping 18-second calls to different tools receive nine seconds each. Grouping both under the same executable gives it 18 seconds. Shares add up to observed tool time across the selected traces. They estimate where to investigate. Confirm actual savings by rerunning the same task after a change.
codeperf-agent top --all-worktrees --hours 48
codeperf-agent top --by operation --sort calls
codeperf-agent top --view commands --sort cpu
codeperf-agent top --trace TRACE_ID --json
- Many calls in a few runs suggest looking for repeated work, batching or result reuse. Use operation names to distinguish tools launched through the same interpreter.
- High CPU time points to machine cost. Follow the example trace into the worker profile. P95 ranks slow individual calls. It uses the nearest observed rank, so always read it alongside the call count.
- Active s counts each tool’s elapsed coverage once per trace. Solo s counts time when it was the only recorded tool type. Concurrent uninstrumented work or a model request can still affect completion time.
The executable ranking uses leaf command wrappers. The agent ranking counts recorded Claude and Codex tool invocations such as Bash and exec_command. Session wrappers, enclosing calls and internal dispatch spans are excluded. Both views can describe the same work. CPU measurements are available on command wrappers. The JSON includes a representative trace and span per tool. The CLI reports when the search exceeds its 100-trace cap. The window selects matching traces and the ranking uses their full recorded calls.
In one demo run, the two OpenSSL processes used 36.0 CPU-seconds and the dispatch finished in 18.2 seconds. That makes OpenSSL the place to inspect in this workload. Switching to operation names reveals how much of that window the SHA-256 and SHA-512 calls shared.
# Run the experiment
Use Rust 1.93 or later and Docker Compose with a Linux engine that supports eBPF and perf events. I tested it on an ARM64 Mac using OrbStack’s Linux VM. Run the commands below from the public repository root. If you download the v0.2.0 source bundle, extract it and enter codeperf-agent-0.2.0/ first.
./codeperf up
./codeperf demo
./codeperf top
./codeperf report latest --json
The demo launches two overlapping OpenSSL commands in a dedicated Linux worker. It prints a trace ID, a row per command, the hottest sampled frames, and Grafana links to the trace, metrics and flame graph. To revisit one command, copy its IDs from the report:
./codeperf report TRACE_ID --span SPAN_ID
The profile covers the worker during the selected interval. Both OpenSSL processes can contribute to the flame graph. Short tools may receive zero samples, and five-second collection windows can cross a span boundary. The span’s CPU counter also includes descendants the command waited for. Adding the coordinator’s CPU to its children’s CPU would count their work twice. Stripped binaries may resolve only to a library or a nearby exported symbol.
# Use it from an Orca worktree
Install the Rust CLI with cargo install --locked --path . from the public repository or extracted bundle. Keep the bundle for Compose and its configuration. Set CODEPERF_LAB_DIR to its location if you move it. In the worktree’s terminal, start an agent with one of these commands. The CLI enables native trace export for that session and preserves the agent’s terminal and exit status.
codeperf-agent trace -- claude
codeperf-agent trace -- codex
Use codeperf-agent worker at a tool launch boundary that can run Docker. It executes the command in the profiled worker image. The PoC includes Python and OpenSSL. To measure your own build, supply its dependencies and source inside the worker. To test a handoff without a model account, run:
codeperf-agent trace --agent lead --name handoff -- \
codeperf-agent worker --agent benchmark --name hash-4k -- \
openssl speed -seconds 18 -bytes 4096 -evp sha256
The host launcher passes W3C trace context to the worker. In a separate terminal, pass the active parent's full TRACEPARENT explicitly. The CLI labels spans with an opaque identifier derived from the originating host and worktree path. codeperf-agent report latest looks that identifier up in Tempo. Tempo can take several seconds to include a finished run in search. The printed trace ID opens that run directly, including from another worktree. Independent local agent tools need their own instrumentation. If a sandbox blocks localhost, buffer wrapper spans in a directory it can write. In my Codex CLI test, this delivered the tool span and the native agent trace without changing sandbox permissions.
codeperf-agent trace --buffer .codeperf/spool -- codex
The outer launcher sends completed batches after the agent exits. It removes each acknowledged batch and keeps failed batches for codeperf-agent flush .codeperf/spool. Each flush also expires pending files older than seven days. Keep this optional buffer out of commits. A lost acknowledgement can cause a retried batch to be counted twice.
The Tool priorities sidebar shows five candidates across worktrees. Choose the elapsed share, CPU, call count or tail latency view and open an example trace from the row. The panel reads the local service directly. The optional palette commands are Codeperf: Top tools to optimize and Codeperf: Show latest workspace profile. Both commands open a terminal in the active worktree. The terminal commands need codeperf-agent on the terminal’s PATH. For development, run these from the PoC directory and review Orca's prompt when loading the plugin:
orca plugin validate ./orca-plugin
orca plugin dev load ./orca-plugin
# Implementation
The CLI, command launcher, trace reader, ranking engine and loopback web service share one Rust binary. The crate forbids unsafe code. It launches programs using individual arguments, validates trace identifiers, escapes trace labels in HTML, limits backend response sizes, and runs the web service as an unprivileged user with a read-only filesystem. The Orca panel uses the host’s TypeScript components and a small JavaScript worker that requests rankings from a fixed loopback endpoint. Grafana Alloy supplies the Linux eBPF collector. The earlier standalone Python wrapper still emits compatible OTLP spans.
# Collection and retention
| Signal | Collection | Storage policy |
|---|---|---|
| Profiles | Grafana Alloy samples user stacks at 19 Hz and sends batches to Pyroscope every five seconds. Its target is the worker’s container ID. | Pyroscope compactor retention of 7 days |
| Traces | The collector accepts OTLP/HTTP at 127.0.0.1:14318 and forwards spans to Tempo. | Tempo block retention of 7 days |
| Metrics | Prometheus scrapes call counts, duration histograms, cumulative user and system CPU, and Linux host counters every five seconds. Tool names outside a short allowlist share the label other. | 30 days or 2 GiB, whichever is reached first |
Profiles, traces and metrics use separate named Docker volumes. Retention runs asynchronously at block granularity. The default CLI path sends spans directly without a disk buffer. A file explicitly requested through CODEPERF_TRACE_FILE belongs to the caller. Trace IDs, command arguments, PID and worktree identifiers stay out of tool metric labels. The metrics link opens aggregate counters for the host. For exact CPU time during one invocation, use the command’s span.
Grafana listens at http://127.0.0.1:13000. The services bind published ports to loopback. Alloy uses the Linux host PID namespace and profiling capabilities so it can resolve stacks in the worker. It runs in its own container, separate from the unprivileged workload. The sampler sees Linux worker activity, including offloaded commands you route there. Native macOS processes have timings and native agent traces. Linux pressure metrics depend on PSI support in the execution kernel.
In a local smoke run, two commands used about 18 CPU-seconds each in an 18.3-second dispatch. A separate six-run fixed-input check on this VM returned the same digest each time. Wall times ranged from 1.017 to 1.037 seconds across the profiler-on and profiler-off runs. That small check leaves the cost on a real build or benchmark open. Compare repeated runs of your workload and track disk growth before sizing a long-lived installation.
To stop collection and preserve the three data volumes:
./codeperf down
Alloy eBPF collector (opens new window) · Pyroscope retention settings (opens new window) · Tempo retention (opens new window) · Prometheus storage (opens new window)