Architecture
How xprobe is structured and how data moves through it.
Overview
human or AI agent
|
| doctor | discover | validate | measure
| versioned JSON + raw JSONL
v
xprobe CLI
|
+-- core: procfs identity, ELF/symbol/layout resolution, validation, ptrace injection, clock anchors
+-- collector: PID-scoped eBPF, perf CPU sampling, external CPython reading, CUPTI Agent control & ABI
+-- correlator: pairing policies, span evaluation, statistics, quality verdicts
+-- exporter: Event JSONL, capture manifests, Chrome Trace Event Format
v
live Linux process or saved capture files
xprobe has no daemon and no persistent session API. Each foreground measure owns attachment, collection, correlation, logical CUPTI stop, and cleanup.
Workspace layout
| Path | Role |
|---|---|
xprobe/cli | Public commands (doctor, discover, validate, measure), rendering, exit codes, orchestration |
xprobe/core | doctor, process identity, discover, ELF/USDT/Python layout resolution, validate, ptrace injection, wall-clock anchoring, triage rules |
xprobe/protocol | Strict serde types and generated JSON Schemas (schemas/) |
xprobe/collector | eBPF uprobes/syscalls/tracepoints/USDT, perf CPU sampling, external CPython sampling, CUPTI control protocol & ABI decoding |
xprobe/correlator | Pairing policies, trigger span evaluation, statistics, quality verdicts |
xprobe/exporter | Event JSONL, .manifest.json, and Chrome Trace Event Format |
bpf/ | PID-scoped eBPF programs (uprobe, USDT, syscall, tracepoint, syscall aggregate) |
cupti/ | Reusable in-process CUPTI callback, activity, ring, and aggregate Agent (libxprobe-cupti.so) |
Process identity and discovery
- Target processes are identified by
(pid, /proc/<pid>/stat start_time)and re-verified around metadata inspection and attach. Reuse returnsTARGET_REUSED; exit returnsTARGET_EXITED. discover --pid ROOTqueries NVML for compute processes, verifies ancestry underROOT, and returns confirmed CUDA context holders with process identity, parent PID, command line, and GPU UUIDs.- Multi-process and multi-GPU runs invoke one
measureper PID; concurrent captures on the same host shareCLOCK_MONOTONIC(and map GPUs by UUID viacuda_devices), while CLI correlation stays single-process.
Symbol, probe, and layout resolution
- Native ELF: converts ELF virtual addresses through load segments to file offsets, then through
/proc/<pid>/mapsto runtime addresses (supporting executables, PIE, and shared libraries). Plain names match raw ELF symbols; C++symbol=checks exported dynamic symbols first and falls back to the full symbol table. - CPU stacks: resolves sampled instruction pointers from mapped ELF load segments and text-symbol tables (only loading modules that appear in samples). CPython frames are resolved separately from
/tmp/perf-<pid>.mapwhen active; native frames remain available otherwise. - CPython GC: parses
.note.stapsdtin the mapped interpreter orlibpythonand requires bothpython:gc__startandpython:gc__donemarkers in one ELF. - External CPython layout: built-in CPython 3.9–3.14 interpreter offsets are checked against
_Py_DebugOffsetson 3.13+.
Validation
validate is read-only. It resolves host/USDT/syscall probes, parses tracepoint and CUDA selectors, checks policy compatibility, and reports required capabilities. CUPTI activation is one of not_required, already_loaded, injection_required (target_mutation: true + TARGET_PROCESS_WILL_BE_MODIFIED), or startup_required (NVTX selector without preloaded Agent — fails explicitly).
Collection paths
Host eBPF (bpf/, xprobe/collector)
- Uprobes: one PID-scoped
uprobe/uretprobeper unique endpoint. - Syscalls: shared raw
sys_enter/sys_exitlinks filtering PID and up to two x86_64 syscall numbers before reading the six scalar ABI registers (entry) and return value (exit). Pointer arguments are never dereferenced. - Tracepoints & CPython GC USDT: record identity and timestamps only; both endpoint links attach before arming so setup events cannot leak in.
- Syscall aggregate: PID-filtered raw entry/exit programs aggregating into a fixed LRU in-flight map and per-CPU hash map, merged in userspace with selector hints.
- Rust ownership detaches all links on every return path.
CPU and external Python sampling
--cpu-sample: opens software CPU-clock perf events per target thread, groups exact raw callchains before top-group truncation, and resolves native ELF + optional/tmp/perf-<pid>.mapframes while keeping loss, truncation, and symbol-coverage counters visible.--python-sample: reads CPython 3.9–3.14 interpreter memory from outside the target viaprocess_vm_readv(no perf events, eBPF,-X perf, or injection; needs ptrace access). Samples the GIL holder at--python-hz(default 2000) and all threads at--python-threads-hz(default 100), discarding inconsistent reads and reading/proc/<pid>/task/<tid>/syscallfor blocked threads' native waits.
CUDA / CUPTI (cupti/, xprobe/collector/src/cupti.rs)
- Separate
libxprobe-cupti.sobuilds linklibcupti.so.12andlibcupti.so.13from one source and ABI. - Control protocol v6 sends
ARM,SNAPSHOT,STOP, andCLOSEover a mode-0600 Unix socket with up to eight endpoint filters and three capture modes (Exact, Aggregate, Ring). - Online injection uses Linux x86_64 ptrace (same mount namespace required) to remotely call
malloc,free,dlopen,dlsym, andxprobe_cupti_agent_start, restoring registers and touched stack words on every path.STOP/CLOSEdisable CUPTI logically without ever callingdlclose. - See CUPTI Agent and Online Injection for ABI and lifecycle details.
Triage snapshot (--triage)
Runs procfs schedstat, cgroup cpu.stat, CPU sampling, external Python sampling (when CPython), syscall aggregate, NVML device health, and CUDA kernel aggregate concurrently in one window. Each full inventory is written to its own artifact; rule-based findings in xprobe/core/src/triage.rs are optional hints over those summaries.
Correlation, manifests, and schemas
Single-edge and measurement-graph live runs share one capture loop (attach, poll, timeout, CUPTI stop, cleanup, artifact write). A graph validates once and correlates each edge independently without implying cross-edge causality.
Live event captures always write Event JSONL (or Chrome trace with --format chrome) plus <artifact>.manifest.json (schema 1.0) recording target identity, CLOCK_MONOTONIC window, wall_clock UTC anchors, all_gpu_activity, cuda_devices UUIDs, losses, and SHA-256. Offline measure --input verifies the manifest and re-correlates deterministically.