Profiler proposal
Which tool is slowing the machine down?.
A proposal for a lightweight Linux profiler that connects tool calls in an agent trace to CPU use, I/O and contention on the host.
In the workspace tracing example, the benchmark occupies 25 seconds. Before I optimize the benchmark, I’d like to know what else was running on that machine. A search tool in another workspace could be scanning the same build directory. The benchmark would own the long span, while changing the search tool might be the cheaper fix.
I’d start with a small collector on the Linux host that actually runs the tools. The browser would display the measurements alongside the existing timeline. Here’s the design I’d like to try.
You can try PID-level profiling today. The Orca, Jaeger and eBPF walkthrough takes one command from an agent trace to sampled Linux stacks.
You can also run the continuous profiling PoC to investigate a command after it exits. Get codeperf-agent on GitHub (opens new window). The lab stores worker CPU profiles in Pyroscope, spans in Tempo and tool counters in Prometheus.
# Give each tool call an identity
When the agent runner launches a command, it would register the trace ID, span ID, workspace, agent and tool name with the collector. The runner would start that invocation in its own cgroup. A build tool can fork dozens of short-lived compiler processes. Those children inherit the group, so their work can be charged to the build even if the compiler exits between samples. A shared daemon serving several clients would need its own request spans for finer attribution. Until then its work would be labeled as shared. Linux cgroup v2 documentation (opens new window).
# Start with counters, then sample a specific tool
- At each tool boundary, read the change in cgroup CPU time and block I/O bytes. For example, 12 CPU-seconds in a four-second tool call means the process group used three cores on average. Group repeated calls by tool as well as by invocation. Hundreds of short searches can cost more CPU in total than a single build.
- During overlapping calls, read CPU, I/O and memory pressure at a coarse interval, initially once per second, both on the host and in the active groups where supported. The change in the PSI
sometotal tells us how long at least one task was stalled on that resource. The group experiencing stalls may be the victim of contention elsewhere. Linux pressure stall information (opens new window). - On a repeat run, enable a short, targeted profile for the suspect tool. I’d use sampled on-CPU stacks to find expensive functions, or an eBPF scheduler probe to measure how long runnable threads waited for a CPU. If threads are sleeping, an off-CPU stack can identify the wait site. A remote API call would also need a client span to explain the time spent beyond this host. BCC CPU sampling example (opens new window) · BCC run queue latency (opens new window) · BCC off-CPU example (opens new window).
# Which change would I try first?
Suppose the trace shows repeated search calls overlapping the benchmark. The searches account for most of the block reads, and I/O pressure rises in the benchmark’s cgroup during that window. I’d narrow the search to the source directory, skip generated build output, and repeat the same task. I’d compare search results for correctness, bytes read across all search calls, benchmark duration, and the time until the lead agent receives its final result.
If reads fall and the benchmark finishes sooner across repeated, interleaved runs, there’s evidence for keeping the change. If only the read count improves, the change saved machine resources. The end-to-end delay still needs an explanation. The proposed viewer would therefore show two rankings side by side. One would rank tools by resource use, the other by the delay each experienced. Each row would link back to its time window.
# What would qualify as lightweight?
For a first prototype, I’d compare three modes on the same host and inputs. I’d run tracing alone, then add boundary counters and pressure sampling, then repeat with a short eBPF capture. I’d record the collector’s CPU time, peak memory, output size and lost samples alongside workload throughput and p50/p95 completion times. Repeating the tracing-only run establishes how much those timings vary on their own. Those measurements would determine which collection mode to leave on by default.
The first deliverable I’d aim for is one summary per tool span that a person or agent can read. A deeper CPU investigation could then continue in topdown-profiler.