xprobe
Minimizing friction on the path to RSI.
xprobe (v0.7.0) is a live Linux CPU, CPython, syscall, and CUDA profiler built for AI agents and performance engineers — emitting strict JSON and raw JSONL from eBPF, perf, external CPython memory reading, and CUPTI on one shared timeline.
Illustrative RSI loop: live GPU bubble + Python GIL capture aligned on CLOCK_MONOTONIC, sliced in JSONL, patched, and re-verified.
Why xprobe?
Traditional profilers are built for human eyes and GUIs: bulky traces, slow exports, heavy overhead, and noise that burns an agent's context window. Recursive self-improvement (RSI) needs the opposite — a live, low-friction sensor that emits compact, script-ready data on one shared timeline and turns profiling into a fast, honest feedback loop.
| Capability | xprobe | perf / uprobe | py-spy | nsys | torch.profiler |
|---|---|---|---|---|---|
| Live attach to running processes (no launch wrapper) | ✅1 | ✅ | ✅ | ⚠️ | ❌ |
CPU + CPython GIL + syscall + CUDA on one CLOCK_MONOTONIC | ✅ | ❌ | ❌ | ⚠️ | ⚠️ |
| Wait & trigger on rare GPU idle bubbles / stream gaps / spikes | ✅ | ❌ | ❌ | ❌ | ❌ |
| Direct JSON / JSONL output for one-off scripts & RSI loops | ✅ | ❌ | ⚠️ | ❌ | ⚠️ |
| Multi-process & multi-GPU timeline alignment / rank budgets | ✅ | ⚠️ | ❌ | ✅ | ⚠️ |
| Visual GUI / kernel roofline & hardware counters | ❌2 | ❌ | ❌ | ✅ | ✅ |
- CPU, CPython stacks/GIL, syscalls, uprobes, and CUDA kernels/copies/APIs attach live; NVTX ranges require
NVTX_INJECTION64_PATHbefore the first NVTX call.- Once a bottleneck is isolated inside a single GPU kernel or needs GUI inspection, hand off to
ncuornsys.
Core Design Concepts
This section expands on the architectural ideas behind xprobe so you can compose custom measurements and analysis scripts without being limited to canned examples.
1. Stateless, Daemon-less Sensor
xprobe exposes four public commands (doctor, discover, validate, measure), with no daemon and no persistent session service. Each foreground measure owns attachment, collection, correlation, logical CUPTI stop, and cleanup.
- Read-only validation:
validatenever mutates a target; onlymeasureinjects CUPTI viaptracewhen required, logging the mutation on stderr and in JSON. - Logical stop, never
dlclose: stopping disables CUPTI callbacks and activity while leavinglibxprobe-cupti.somapped for safe reuse.
2. One Shared Timeline: CLOCK_MONOTONIC + UTC Anchors
Every aligned collector on a host shares kernel CLOCK_MONOTONIC nanoseconds:
- Host eBPF events (uprobes, syscalls, tracepoints, CPython GC USDT) use
host_monotonic. - External CPython samples (
--python-sample) emitCLOCK_MONOTONICtimestamp_ns. - Normalized CUPTI activity uses
cupti_normalized_to_host_monotonic. - Every Event JSONL is paired with
<artifact>.manifest.json, carryingwall_clockUTC anchors (monotonic_ns,realtime_ns,uncertainty_ns) andcuda_devicesphysical GPU UUIDs.
That enables direct joins across sources (GPU idle bubble + concurrent Python GIL stacks), across processes or multi-GPU ranks on one host (grouped by physical GPU UUID regardless of CUDA_VISIBLE_DEVICES), and against external UTC application logs.
3. Composable Primitives Over Fixed Playbooks
Performance bottlenecks vary, so xprobe deliberately avoids prescribing a fixed investigation procedure. Instead, it provides orthogonal building blocks you can combine freely:
| Axis | Primitives |
|---|---|
| Observation sources | Native ELF functions (uprobe / C++ symbol= / +0x offset), Linux syscall / tracepoint, external CPython 3.9–3.14 stacks & GIL (--python-sample), CPython GC USDT, CPU perf callchains (--cpu-sample), CUDA Runtime/Driver APIs (cuda:launch_api), GPU kernel/memcpy/memset, ASCII NVTX, procfs/cgroup/NVML |
| Capture shapes | Exact A → B pairs (--from/--to + 5 --match policies), 1–8 edge measurement graphs (--spec), low-overhead aggregates (--aggregate / --syscall-aggregate / --cpu-sample), ring-buffered triggers (--trigger-idle-ms / -gap-ms / -duration-ms / -latency-ms), same-window snapshot (--triage), offline re-correlation (--input) |
| Post-capture composition | Piped strict JSON (jq/Python), analyze_trace.py interval unions and vertical slices, cross-process CLOCK_MONOTONIC joins, wall_clock log alignment, repeatable --spec RSI before/after diffs |
Examples of diverse compositions (as inspiration, not rules):
- Run
--trigger-idle-ms 10on a GPU worker concurrently with--python-sampleon the same worker or an API process, then slice the Python stacks around the triggered bubble'sCLOCK_MONOTONICwindow. - Capture
request → launch_api → kernel_start → kernel_endin one 1–8 edge measurement graph, then re-correlate the saved Event JSONL offline withmeasure --inputfor additional hypotheses. - Run concurrent
stream-ordercaptures across multi-GPU ranks and compare shared-windowcompute_share,communication_only, andidlebudgets withanalyze_trace.py rank0.jsonl rank1.jsonl .... - Pin a fixed
--specJSON before and after each optimization candidate in an RSI loop, guarding every comparison onok, zero drops, andquality.verdict.
4. Honest Accounting & Explicit Failures
Rather than silently dropping events or mixing unaligned clocks, xprobe fails explicitly with structured JSON errors (code, message, details, hints) while preserving written artifacts whenever possible:
- Cross CPU/GPU subtraction enforces runtime clock alignment and returns
CLOCK_ALIGNMENT_FAILEDinstead of mixing unaligned clocks (GPU-only spans remain usable in rawcuptitime). - Process identity is checked via
(pid, procfs start_time)around inspection and attach (TARGET_EXITED/TARGET_REUSED). - A single-stream gap is not device idle time, and summed concurrent kernel durations are not wall time. Manifest
all_gpu_activityexplicitly marks when device-wide idle math is valid.
Quick Examples
# 1. Sample CPython 3.9–3.14 stacks & GIL holder from outside the process (no -X perf)
xprobe measure --pid 4242 --python-sample --duration-ms 2000
# 2. Aggregate GPU kernels or memcpy (including pageable vs pinned transfers)
xprobe measure --pid 4242 --from cuda:kernel_start --to cuda:kernel_end \
--match exact --aggregate --duration-ms 2000
# 3. Measure exact launch-to-kernel latency (or up to 8 edges via --spec graph.json)
xprobe measure --pid 4242 --from cuda:launch_api:exit \
--to 'cuda:kernel_start:name~flash.*' --match exact --samples 200
# 4. Wait for a rare >=10 ms GPU idle bubble and keep ±50 ms of context around it
xprobe measure --pid 4242 --trigger-idle-ms 10 --pre-ms 50 --post-ms 50 \
--timeout-ms 300000 --events-out spikes
Pipe into scripts & RSI loops:
before=$(xprobe measure --spec kernel.json | jq '.measurement.latency_ns.p95')
# ... apply kernel / runtime change ...
after=$(xprobe measure --spec kernel.json | jq '.measurement.latency_ns.p95')
skills/xprobe-perf-profiling/scripts/analyze_trace.py trace.jsonl --slice-gap 1 --python-samples py.jsonl
skills/xprobe-perf-profiling/scripts/analyze_trace.py rank0.jsonl rank1.jsonl rank2.jsonl rank3.jsonl
Support Matrix
| Surface | Support |
|---|---|
| Platform | Linux x86_64, glibc ≥ 2.34, CUDA/CUPTI 12.x & 13.x |
| Python | External CPython 3.9–3.14 stacks, GIL holder, blocked native waits, and GC USDT |
| CPU & Linux | PID-scoped perf callchains (ELF + perf-map), uprobes (symbol/C++/offset), syscalls, tracepoints |
| GPU & CUDA | Runtime/Driver APIs (cuda:launch_api), kernels, memcpy (pageable/pinned), memset, ASCII NVTX |
| Modes | Exact pairs, 8-edge measurement graphs, coarse aggregates, triggered ring capture, --triage snapshot, offline --input |
| Correlation | exact, stack-nested, stream-order, first-after, nearest |
Documentation Map
- Installation — PyPI wheel, standalone archive, SHA-256 / SBOM / attestation, Agent Skill, and
doctor. - CLI Reference — option-by-option flags, types, defaults, mutual exclusions, mode matrix, env vars, exit codes, and all 24 error codes.
- JSON Interfaces & Schemas — field-by-field input specs, stdout responses, shared enums, and all 26 JSON Schemas.
- Selectors, Policies & Limits — full selector syntax, symbol/offset resolution, match policies, specs, filter pushdown, and overhead limits.
- Data Format, Clocks & Scripting — stdout/artifact paths, real JSONL shapes, manifest, clock math,
analyze_trace.py, scripting recipes, and all 26 JSON Schemas. - Agent Integration — official Skill, command-to-evidence table, hard constraints, and automated verification.
- Benchmarks — observed overheads and reproducible benchmark suites.
- Architecture / CUPTI Agent / Development & Releasing — internals, ABI, hardware tests, and release process.