Metadata-Version: 2.1
Name: xprobe
Version: 0.7.0.dev2
Summary: Find out why your CPU, Python, or CUDA process is slow in two commands: a bounded Linux profiler for AI coding agents.
Home-page: https://github.com/itdevwu/xprobe
Author: itdevwu
License: Apache-2.0
Keywords: profiler,profiling,performance,latency,gpu,cuda,cupti,ebpf,perf,pytorch,python,linux,ai-agent,claude-code,codex,cursor
Requires-Python: >=3.8
Project-URL: Source, https://github.com/itdevwu/xprobe
Project-URL: Documentation, https://github.com/itdevwu/xprobe/tree/master/docs
Project-URL: Issues, https://github.com/itdevwu/xprobe/issues
Project-URL: Changelog, https://github.com/itdevwu/xprobe/releases
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Environment :: GPU :: NVIDIA CUDA :: 12
Classifier: Environment :: GPU :: NVIDIA CUDA :: 13
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Rust
Classifier: Topic :: Software Development :: Debuggers
Classifier: Topic :: System :: Monitoring
Description-Content-Type: text/markdown

<div align="center">
  <h1>xprobe</h1>
  <p><strong>ML infra profiler built for AI agents and RSI loops.</strong></p>
  <p>Live Linux CPU, Python, syscall, and CUDA profiling in one CLI — eBPF, perf, and CUPTI to JSON/JSONL.</p>
  <p>
    <a href="https://github.com/itdevwu/xprobe/actions/workflows/ci.yml"><img alt="CI status" src="https://img.shields.io/github/actions/workflow/status/itdevwu/xprobe/ci.yml?branch=master&amp;style=for-the-badge&amp;label=CI"></a>
    <a href="https://github.com/itdevwu/xprobe/releases"><img alt="Latest release" src="https://img.shields.io/github/v/release/itdevwu/xprobe?style=for-the-badge&amp;sort=semver"></a>
    <a href="LICENSE"><img alt="Apache-2.0 license" src="https://img.shields.io/github/license/itdevwu/xprobe?style=for-the-badge&amp;label=License"></a>
    <a href="#-support"><img alt="CUDA 12.x and 13.x" src="https://img.shields.io/badge/CUDA-12.x%20%7C%2013.x-76B900?style=for-the-badge&amp;logo=nvidia&amp;logoColor=white"></a>
  </p>
</div>

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/itdevwu/xprobe/master/docs/assets/xprobe-flow-dark.svg">
    <img alt="One xprobe measurement graph reports request to launch 1.14 ms, launch to kernel 99 µs, and kernel 1.2 µs on CPU and GPU timelines, keeping every raw event for offline analysis" src="https://raw.githubusercontent.com/itdevwu/xprobe/master/docs/assets/xprobe-flow-light.svg" width="860">
  </picture>
</p>

<p align="center"><sub>Real numbers from the v0.6.0 release gate on an RTX 3060: a request → launch → kernel path.</sub></p>

## ⚡ Why xprobe?

| Capability | `xprobe` | `perf` / `uprobe` | `py-spy` | `nsys` | `torch.profiler` |
| --- | :---: | :---: | :---: | :---: | :---: |
| Live attach to running processes (no launch wrapper) | ✅<sup>1</sup> | ✅ | ✅ | ⚠️ | ❌ |
| 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 | ❌<sup>2</sup> | ❌ | ❌ | ✅ | ✅ |

<sub>1. CPU, CPython stacks/GIL, syscalls, uprobes, and CUDA kernels/copies/APIs attach live; NVTX ranges require `NVTX_INJECTION64_PATH` before the first NVTX call.<br>2. Once a bottleneck is isolated inside a single GPU kernel or needs GUI inspection, hand off to `ncu` or `nsys`.</sub>

## 📦 Install

### CLI (Linux x86_64, glibc ≥ 2.34)

```bash
pip install xprobe
```

Or install the standalone release archive to `~/.local` (no Python required):

```bash
curl --proto '=https' --tlsv1.2 -fsSL \
  https://raw.githubusercontent.com/itdevwu/xprobe/v0.7.0-dev.2/install.sh | sh
```

Both ship the CLI plus CUDA 12 and CUDA 13 CUPTI Agents. See [Installation](https://github.com/itdevwu/xprobe/blob/master/docs/installation.md) for SHA-256 checksums, SPDX SBOMs, and GitHub build attestations.

### AI Agent Skill (Claude Code, Codex, Cursor)

```bash
npx skills@1 add \
  https://github.com/itdevwu/xprobe/tree/v0.7.0-dev.2/skills/xprobe-perf-profiling \
  --global
```

Installs the [`xprobe-perf-profiling`](https://github.com/itdevwu/xprobe/blob/master/skills/xprobe-perf-profiling/SKILL.md) skill with exact JSON/JSONL artifact layouts, one-off scripting recipes, RSI comparison patterns, and the bundled `analyze_trace.py` analyzer.

## 🚀 Quick examples

```bash
# 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 one-off scripts & RSI loops

When stdout is piped, every command emits one strict JSON object alongside raw JSONL traces and a `.manifest.json` (`CLOCK_MONOTONIC` window, UTC `wall_clock` anchors, and `cuda_devices` GPU UUIDs):

```bash
# Capture once, diff metrics across optimization iterations, or join traces in Python
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')

# Slice a GPU bubble alongside concurrent Python GIL samples, or compare multi-GPU ranks
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
```

Because concurrent captures on one host share `CLOCK_MONOTONIC`, you can also join traces across different processes (for example, an API/scheduler process and its GPU workers) in a few lines of Python, or re-correlate saved Event JSONL offline with `xprobe measure --input`.

## 🛠️ Commands & runtime notes

| Command | Purpose |
| --- | --- |
| `doctor` | Check local eBPF, ptrace, NVIDIA driver, CUDA, and CUPTI availability |
| `discover` | List NVML-confirmed CUDA context holders under a process-tree root |
| `validate` | Dry-run selectors, policies, or graph specs without attaching |
| `measure` | Capture latency pairs, measurement graphs, inventories, triggers, or offline `--input` traces |

- **Live CUDA attach**: `measure --pid` automatically loads the matching CUDA 12 or 13 CUPTI Agent via ptrace (requires same mount namespace and ptrace permission), reports the injection on stderr and in JSON, disables collection on stop, and leaves the `.so` mapped for safe reuse.
- **NVTX ranges**: set `NVTX_INJECTION64_PATH` before the target's first NVTX call (CUDA's NVTX dispatch cannot be retrofitted after initialization).
- **Clock safety**: GPU-only durations work on all supported CUDA majors; cross CPU/GPU subtraction enforces runtime clock alignment and returns `CLOCK_ALIGNMENT_FAILED` instead of silently mixing unaligned clocks.

## 📋 Support

| 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 |
| Correlation | `exact`, `stack-nested`, `stream-order`, `first-after`, `nearest` |

## 📚 Documentation

- [Installation](https://github.com/itdevwu/xprobe/blob/master/docs/installation.md)
- [CLI contract](https://github.com/itdevwu/xprobe/blob/master/docs/cli-contract.md)
- [Agent integration](https://github.com/itdevwu/xprobe/blob/master/docs/agent-integration.md)
- [Architecture](https://github.com/itdevwu/xprobe/blob/master/docs/architecture.md)
- [CUPTI agent and injection](https://github.com/itdevwu/xprobe/blob/master/docs/cupti-agent.md)
- [Benchmarks](https://github.com/itdevwu/xprobe/blob/master/docs/benchmarks.md)
- [Development and hardware tests](https://github.com/itdevwu/xprobe/blob/master/docs/development.md)
- [Releasing](https://github.com/itdevwu/xprobe/blob/master/docs/releasing.md)
- [JSON Schemas](https://github.com/itdevwu/xprobe/blob/master/schemas/)

Implemented behavior is defined by code, tests, and schemas. Licensed under Apache-2.0.
