Skip to content

Latest commit

 

History

History
317 lines (240 loc) · 21.4 KB

cli-reference.md

File metadata and controls

317 lines (240 loc) · 21.4 KB

CLI reference

xprobe has four public commands:

Command What it does
doctor Reports what this host and container allow xprobe to collect.
discover Lists CUDA processes under a process tree without attaching.
validate Checks a target and selectors read-only, before anything attaches.
measure Collects, correlates, and writes results and artifacts.

Output

When stdout is not a terminal, every command writes one versioned JSON document to stdout. On a terminal it prints a readable report. --json and --human force one or the other and cannot be combined.

xprobe never prompts and never colors output; --non-interactive and --no-color are accepted for scripts that pass them. Diagnostics and injection warnings go to stderr.

A live measure first prints the defaults it used for options you did not set, as one stderr line such as xprobe: defaults: --max-groups 256 --max-inflight 1024 --timeout-ms 30000. xprobe --help lists every mode with an example; xprobe measure --help groups the options by mode.

Schema version Documents
3.0 Measurement and measurement-graph (spec, validate, result), GPU --aggregate, --python-sample, --triage, and --trigger-* results
2.0 doctor, discover, single-edge validate and MeasurementSpec, --cpu-sample, --syscall-aggregate, errors, and Event JSONL lines
1.0 Capture manifests (<artifact>.manifest.json)

Unknown JSON fields and unsupported versions fail deserialization.

Exit code Meaning
0 Command succeeded and printed a result
1 Validation, collection, decode, export, cleanup, or internal error
2 Invalid CLI syntax (Clap)
3 Target missing, exited, or reused
4 Permission denied for inspection, eBPF, or ptrace

Runtime errors follow schemas/error.schema.json: a stable code, a message, recoverable, and machine-readable details and hints.

doctor

xprobe doctor

Reports kernel and OS identity, BTF, BPF and perf permissions, lockdown, ptrace policy, the NVIDIA driver, the CUDA toolkit and driver, each installed CUPTI major with its path, namespaces, and capability booleans. ok: true means the diagnostics ran, not that every collector is available.

Privilege checks read CapEff (the effective capability set), not the UID. Root in a container without CAP_BPF and CAP_PERFMON (or CAP_SYS_ADMIN) reports eBPF as restricted. Live injection needs CAP_SYS_PTRACE unless ptrace_scope allows tracing a process of the same user.

discover

xprobe discover --pid 4242 --limit 200

Asks NVML for active CUDA compute processes under the process tree rooted at --pid, without attaching. Each result is a confirmed CUDA context holder with its PID, procfs start time, parent PID, executable, command line, and GPU UUIDs. --limit must be positive; total_candidates and truncated show whether the list was cut. discover does not choose a worker and does not list CPU-only or Python-only processes.

NVML lists processes from every container that shares a GPU:

  • PIDs this PID namespace cannot see, or that exited during inspection, are reported in nvml_pids with NVML_PROCESS_UNAVAILABLE instead of failing the command.
  • When none are visible, NVML_PID_NAMESPACE_MISMATCH notes that NVML returned host PIDs, and procfs_hints lists the processes at or below the root that map libcuda (libcuda_mapped) or hold /dev/nvidia* files open (nvidia_device_fds). Each loaded CUDA or opened a device, which does not show a CUDA context; pass the namespace-local PID to validate and measure.
  • A failed NVML query or a missing root PID is an error.

Selectors

Selectors are validated before anything attaches:

uprobe:<binary>:<symbol>:entry
uprobe:<binary>:<symbol>:return
uprobe:<binary>:symbol=<full-demangled-c++-signature>:entry
uprobe:<binary>:symbol=<full-demangled-c++-signature>:return
uprobe:<binary>:+0x<file-offset>:entry
uprobe:<binary>:+0x<file-offset>:return
syscall:<name>:entry
syscall:<name>:exit
tracepoint:<category>:<name>
python:gc_start
python:gc_end
cuda:runtime_api:<name>:entry|exit
cuda:driver_api:<name>:entry|exit
cuda:launch_api:entry|exit
cuda:kernel_start|kernel_end[:name~REGEX]
cuda:memcpy_start|memcpy_end[:kind=HtoD|DtoH|DtoD|HtoH|PtoP]
cuda:memset_start|memset_end
cuda:nvtx_range_start|nvtx_range_end:name~REGEX
  • Host C/C++: symbol= takes a full demangled C++ signature, including :: and punctuation. Validation returns the mangled ELF name to attach (symbol) and symbol_demangled. Uprobes do not resolve Python frames.
  • Syscalls: Linux x86_64 only. BPF filters on PID and syscall number before it reads the six scalar entry registers or the scalar return value. Pointer arguments are never read.
  • Tracepoints record identity and timestamp only. Unsupported names fail explicitly.
  • CPython GC: chosen by what the target maps, not its process name. validate checks the Python or libpython ELF for both the python:gc__start and python:gc__done USDT markers. Records hold identity, timestamp, binary, provider, and marker name only.
  • CUDA launch: cuda:launch_api:entry|exit matches the Runtime launch APIs (cudaLaunchKernel, cudaLaunchKernelExC, cudaLaunchCooperativeKernel) and the Driver ones (cuLaunchKernel, cuLaunchKernelEx, cuLaunchCooperativeKernel), so it covers cuBLAS, Triton, and Driver callers. A Runtime call and the Driver call inside it count once, as the Runtime call. It uses 2 of the 8 Agent filters.
  • NVTX and kernel names: an NVTX name~REGEX must reduce to one nonempty exact, prefix, suffix, or contains literal shorter than 128 bytes. A kernel regex that reduces the same way is filtered in the CUPTI Agent's hot path; a more complex one is filtered in Rust after a broader capture.

validate

xprobe validate --pid 4242 \
  --from 'cuda:launch_api:exit' \
  --to 'cuda:kernel_start:name~flash.*' \
  --match exact

A read-only check of target identity, probe resolution, CUDA filters, correlation, and runtime requirements (schemas/validate.schema.json).

  • --cpu-sample checks target threads, perf-event access, and whether Python perf-map symbols are available.
  • --syscall-aggregate checks the eBPF syscall aggregate path.
  • --spec graph.json validates a measurement graph without --pid (schemas/measurement-graph-validate.schema.json, schema 3.0). Each issue is scoped to the graph, an endpoint, or an edge.
  • policy_recommendation gives the strongest compatible policy, a machine-readable reason, and the compatible alternatives. It never changes --match for you.
  • requirements.agent_activation is one of:
    • not_required
    • already_loaded
    • injection_required: measure will inject the Agent; sets target_mutation: true and warns TARGET_PROCESS_WILL_BE_MODIFIED.
    • startup_required: an NVTX selector needs the Agent loaded at startup; valid: false.
  • The CUDA major comes from the target's loaded libcupti (by file name, or by SONAME for calendar-versioned files), or from its libcudart when no CUPTI is loaded. A libcudart of another major beside a loaded libcupti gives the warning EXTRA_CUDA_RUNTIME. A major other than 12 or 13, or two majors of the deciding library, returns UNSUPPORTED_CUDA_VERSION.

Correlation policies

Policy Pairs
exact A CUDA API call ↔ each kernel, copy, or memset it issued (by CUPTI correlation ID; a cudaGraphLaunch pairs with every node it replays), same CUDA API entry ↔ exit, kernel/memcpy/memset start ↔ end, NVTX range kind and ID, same-thread syscall entry and exit, or same-thread CPython GC start and end
stack-nested Same-thread host function entry and return, innermost first
stream-order A GPU activity end with the next kernel, copy, or memset start on the same device, context, and stream
first-after, nearest By time across unrelated sources; always warned as heuristic

stream-order records all GPU activity, uses 6 of the 8 Agent filters, and warns STREAM_ORDER_CAPTURES_ALL_ACTIVITY. Overlapping ends, tied successors, and names too truncated to decide the selector are marked ambiguous.

measure

A run reads from exactly one source: --pid (live), one or more --input files (offline), or --spec. Live runs need --samples or --duration-ms; a duration ends the capture even when an edge has no pair yet, and the result then reports NO_MATCHED_SAMPLES. Offline --input correlates every event when neither is set. Defaults: --timeout-ms 30000, --max-events 100000.

Examples

# Live CUDA launch-to-kernel latency
xprobe measure --pid 4242 \
  --from 'cuda:launch_api:exit' --to 'cuda:kernel_start:name~flash.*' \
  --match exact --samples 100 --timeout-ms 30000 --events-out /tmp/xprobe-events.jsonl

# Syscall duration
xprobe measure --pid 4242 \
  --from 'syscall:mmap:entry' --to 'syscall:mmap:exit' \
  --match exact --samples 100 --max-events 1000

# CPython GC duration
xprobe measure --pid 4242 \
  --from python:gc_start --to python:gc_end --match exact --samples 100 --max-events 1000

# NVTX range (target started with NVTX_INJECTION64_PATH)
xprobe measure --pid 4242 \
  --from 'cuda:nvtx_range_start:name~^forward$' \
  --to 'cuda:nvtx_range_end:name~^forward$' --match exact --samples 100 --max-events 1000

# CPU callchain hotspot inventory
xprobe measure --pid 4242 --cpu-sample --duration-ms 2000 \
  --max-groups 256 --stack-depth 64 --max-threads 1024 --events-out cpu-samples.jsonl

# External CPython stacks & GIL holder
xprobe measure --pid 4242 --python-sample --duration-ms 2000

# Syscall totals inventory
xprobe measure --pid 4242 --syscall-aggregate --duration-ms 1000 \
  --max-groups 256 --max-inflight 1024

# GPU kernel or memcpy totals inventory (one activity kind per run)
xprobe measure --pid 4242 --from 'cuda:kernel_start' --to 'cuda:kernel_end' \
  --match exact --aggregate --duration-ms 1000 --max-groups 4096
xprobe measure --pid 4242 --from 'cuda:memcpy_start' --to 'cuda:memcpy_end' \
  --match exact --aggregate --duration-ms 1000 --max-groups 4096

# Same-window multi-source snapshot
xprobe measure --pid 4242 --triage --duration-ms 2000

# Offline re-correlation of saved captures
xprobe measure --input host.json --input cupti.bin \
  --from 'uprobe:/srv/app/server:request:entry' \
  --to 'cuda:kernel_start:name~flash.*' --match first-after --samples 100

# Versioned spec or measurement graph
xprobe measure --spec measurement.json

Latency results

schemas/measurement-result.schema.json, schema 3.0:

  • status
  • measurement.latency_ns and measurement.samples
  • quality: good, or caution with coded issues
  • correlation and clock
  • collection: completeness, CUPTI utilization and drops, cuda_devices, wall_clock
  • evidence: exemplars at min, p50, p90, p99, and max, the artifact path, and every pair with --evidence full
  • warnings

Error codes include CUPTI_AGENT_BUSY, NO_MATCHED_SAMPLES, CLOCK_ALIGNMENT_FAILED, EVENT_RATE_TOO_HIGH, EVENTS_DROPPED, TRIGGER_NOT_OBSERVED, TARGET_EXITED, TARGET_REUSED, and CLEANUP_FAILED.

Inventories

Each inventory is a live mode that runs for --duration-ms and reports totals instead of pairs.

Mode Collects Schema
--cpu-sample PID-scoped userspace callchains from perf events 2.0
--python-sample CPython stacks and the GIL holder, read from outside the process 3.0
--syscall-aggregate Per-syscall counts and durations in BPF maps 2.0
--aggregate Agent-side totals for one kernel, memcpy, or memset start/end pair 3.0

--syscall-aggregate and --aggregate write no Event JSONL, so their output cannot be passed to --input or --events-out.

--cpu-sample defaults to 999 Hz, depth 64, and 1,024 threads. Every sample is kept and written with its CLOCK_MONOTONIC time to --events-out (or a private file) as JSONL (schemas/cpu-sample-record.schema.json): each stack once, before the first sample that uses it, then samples that name it. --max-groups (default 256) sets how many stack groups and hotspots are listed; every sample is counted. Each group and hotspot gives estimated_ns, the on-CPU time summed from perf periods, and collection.cpu_time_ns the total. It resolves ELF symbols and /tmp/perf-<pid>.map Python frames separately; when python_status is unsupported (CPython <3.12) or inactive (no -X perf), use --python-sample instead.

--python-sample reads CPython 3.9–3.14 memory with process_vm_readv. It needs ptrace access but no perf events, eBPF, -X perf, or injection.

  • It samples the GIL holder at --python-hz (default 999). By default it sweeps every thread up to 100 times a second, slower when the threads would take more than 6,400 stack reads a second (collection.sweep_reads_per_second); --python-threads-hz N fixes the sweep rate and 0 turns sweeps off. collection reports the requested and achieved rate of each.
  • Every sample is kept: memory grows by a few dozen bytes per sample plus each distinct stack, and the JSONL is written as it is produced.
  • On 3.13 and later it checks its offsets against _Py_DebugOffsets. Unsupported and free-threaded builds return UNSUPPORTED_PYTHON_VERSION.
  • Reads that race with the interpreter are discarded and counted in inconsistent_reads.
  • For blocked threads it reports native waits from /proc/<pid>/task/<tid>/syscall.
  • Every sample is written with its CLOCK_MONOTONIC time to a JSONL artifact (schemas/python-sample-record.schema.json).
  • Frames report first_line, the line where the function starts, not the current line.
  • Every stack group, hotspot, and native wait has estimated_ns. A GIL sample counts one average GIL tick (wall time of the GIL holder); a sweep sample counts the interval of its own sweep (thread time summed over threads).

--syscall-aggregate filters by PID in BPF maps sized by --max-inflight and --max-groups. It reports each syscall's count, errors, min, mean, max, and total duration, with selector hints. It records no per-call events and no pointer values.

--aggregate groups in the Agent, up to --max-groups (default 4,096).

  • The kernel regex must reduce to a literal the hot path can filter on.
  • Names cut at 127 bytes set name_complete: false and give a prefix hint.
  • Memcpy groups split by src_memory and dst_memory (pageable, pinned, device, managed, and others).
  • An activity still running on the GPU when the capture stops is not counted.

Triage

--triage runs for --duration-ms and collects, at the same time:

  • procfs thread times and cgroup CPU throttling
  • CPU samples, and external Python samples for a CPython target
  • the syscall aggregate
  • NVML device health
  • the CUDA kernel aggregate, which may inject CUPTI

Full inventories go to one artifact per source, and the top 5 entries of each are kept inline. Thread and cgroup counters span exactly --duration-ms (window_ms); every other source runs a window of the same length after its own setup, alongside, and elapsed_ms is the whole command. Rule-based findings are leads to check against the inventories, and not_covered lists what the triage cannot answer. A source that is unavailable or saturated is marked unavailable with TRIAGE_SOURCE_UNAVAILABLE instead of failing the run. Schema 3.0.

Triggered capture

xprobe measure --pid 4242 --trigger-idle-ms 10 --pre-ms 50 --post-ms 50 \
  --timeout-ms 300000 --max-events 400000 --events-out /tmp/spikes

Waits for a rare slow span. Records stay in a ring of --max-events inside the Agent. For each span that fires, xprobe writes window-N.events.jsonl and its manifest into the --events-out directory, covering --pre-ms before the span to --post-ms after it. It writes up to --windows windows (default 1), which never overlap.

Trigger Fires when
--trigger-idle-ms The device runs no kernel, copy, or memset of the target on any stream for this long
--trigger-gap-ms The gap between an activity end and the next kernel, copy, or memset on the same stream reaches this
--trigger-duration-ms One kernel, copy, or memset runs this long
--trigger-latency-ms The --from/--to CUDA edge under --match reaches this

Idle, gap, duration, and stream-order latency triggers record all GPU activity.

  • A window that overlaps overwritten or dropped records is not written and counts in lost_windows.
  • If a record read later shows activity inside an idle or gap window, that window is dropped and counts in revoked_windows. Capture keeps waiting for another span until the timeout.
  • Latency and duration windows are written as they fired.
  • observed counts every span seen, including those whose records the CLI no longer holds.
  • If no window is written, the timeout returns TRIGGER_NOT_OBSERVED with longest_ns in details. If every window lost records, it returns EVENTS_DROPPED.

Results follow schemas/trigger-result.schema.json (schema 3.0).

Live capture and the CUDA Agent

  • Host endpoints attach every eBPF link before arming. A duration capture that reaches --max-events fails with EVENT_RATE_TOO_HIGH.
  • CUDA endpoints find the Agent from --agent, then XPROBE_CUPTI_AGENT_PATH, then ../lib/xprobe/cuda12|cuda13 and ../libexec/xprobe/cuda12|cuda13 next to the CLI, then the matching build path.
  • One xprobe session owns the Agent at a time. While it runs, another measure on the same target fails with CUPTI_AGENT_BUSY and leaves the capture alone; combine edges into one measurement graph instead. If torch.profiler or an Nsight tool holds the target's CUPTI subscriber, measure fails with CUPTI_NOT_AVAILABLE and a hint naming them.
  • Live injection needs Linux x86_64, the same mount namespace as the target, and ptrace permission. It prints a warning to stderr and emits CUPTI_AGENT_INJECTED. On stop it disables CUPTI and removes its private socket while leaving the .so mapped. On CUDA 12 it turns kernel tracing off between CUDA Graph launches to avoid a CUPTI deadlock; if it cannot, measure warns CUPTI_KERNEL_ACTIVITY_LEFT_ON (details in CUPTI Agent). A later measure reuses the mapped Agent, even if its file was deleted. validate warns CUPTI_AGENT_ALREADY_LOADED with agent_path and file_deleted when a target holds an Agent; see CUPTI Agent for what it keeps.
  • NVTX thread ranges are tracked by (tid, push_level) and process ranges by range_id across threads (start_tid). ASCII PushA/StartA and the Ex forms are supported; wide and registered strings and CUPTI Range Profiling are not.

Artifacts and offline input

  • A live capture always writes the full capture with mode 0600, to --events-out PATH or a private mode-0700 temporary directory. The default format is JSONL; --format chrome writes Chrome Trace Event Format.
  • Beside every Event JSONL, xprobe writes <artifact>.manifest.json (schemas/capture-manifest.schema.json, schema 1.0) with the target identity, the CLOCK_MONOTONIC window, selectors, all_gpu_activity, peer_copies, losses, cuda_devices UUIDs, wall_clock UTC start and end anchors (each between two monotonic reads, with uncertainty_ns), size, and SHA-256.
  • If correlation, clock, drop, or capacity checks fail after collection, the artifact is still written and its path is in the JSON error. TRACE_EXPORT_FAILED keeps the original error code in details.
  • --input accepts the CUPTI ABI binary, host-capture JSON, or Event JSONL. Several --input files are merged after rejecting mixed targets (one PID with different start times) and duplicate event content.
  • Offline input checks each manifest's size and SHA-256 and restores the recorded losses and coverage. Without a manifest, coverage is unverified (or unverified_merge for merged files), and stream-order falls back to a heuristic with a caution.

Measurement graphs

A graph measures 1–8 edges over 1–8 named endpoints from one capture (schemas/measurement-graph-spec.schema.json, schema 3.0):

{
  "schema_version": "3.0",
  "name": "request_path",
  "target": {"pid": 4242, "process_start_time": 123456},
  "endpoints": {
    "request": "uprobe:/srv/app/server:handle_request:entry",
    "launch_exit": "cuda:launch_api:exit",
    "kernel_start": "cuda:kernel_start:name~^flash",
    "kernel_end": "cuda:kernel_end:name~^flash"
  },
  "edges": [
    {"name": "request_to_launch", "from": "request", "to": "launch_exit",
     "match_policy": "first_after", "samples": 100},
    {"name": "launch_to_kernel", "from": "launch_exit", "to": "kernel_start",
     "match_policy": "exact", "samples": 100},
    {"name": "kernel_duration", "from": "kernel_start", "to": "kernel_end",
     "match_policy": "exact", "samples": 100}
  ],
  "duration_ms": null,
  "timeout_ms": 30000,
  "max_events": 20000
}
  • target.process_start_time is optional; measure reads it and checks it around attach.
  • Either every edge sets samples, or the graph sets duration_ms. max_events caps the capture.
  • Collectors attach once per unique endpoint. Uprobes have no limit; CUDA endpoints share the 8 Agent filters; syscall, tracepoint, and USDT endpoints share 2 Linux slots.
  • Each edge correlates on its own (schemas/measurement-graph-result.schema.json, schema 3.0). Validation errors on any edge fail before collection with no artifact written; if an edge fails after collection has run, the command fails with details.edge while still writing the shared Event JSONL for offline measure --input.