Metadata-Version: 2.1
Name: xprobe
Version: 0.7.1
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>Minimizing friction on the path to RSI.</strong></p>
  <p>Live Linux CPU, Python, syscall, and CUDA profiler for AI agents and engineers.</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="Live xprobe captures align a GPU idle bubble with Python GIL stacks on CLOCK_MONOTONIC, feed JSONL into an agent script, and verify an RSI optimization loop" src="https://raw.githubusercontent.com/itdevwu/xprobe/master/docs/assets/xprobe-flow-light.svg" width="880">
  </picture>
</p>

<p align="center"><sub>Illustrative RSI loop: live GPU bubble + Python GIL capture aligned on <code>CLOCK_MONOTONIC</code>, sliced in JSONL, patched, and re-verified.</sub></p>

## ⚡ 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) | ✅<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.1/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 custom prefixes, upgrades, and verification.

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

```bash
npx skills add itdevwu/xprobe
```

Installs the [`xprobe-perf-profiling`](https://github.com/itdevwu/xprobe/blob/master/skills/xprobe-perf-profiling/SKILL.md) skill from [skills.sh](https://skills.sh) with artifact layouts, scripting recipes, and the bundled `analyze_trace.py` analyzer. To pin a release, see [Installation](https://github.com/itdevwu/xprobe/blob/master/docs/installation.md#ai-agent-skill).

## 🚀 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 (memcpy splits by pageable vs pinned)
xprobe measure --pid 4242 --from cuda:kernel_start --to cuda:kernel_end \
  --match exact --aggregate --duration-ms 2000
xprobe measure --pid 4242 --from cuda:memcpy_start --to cuda:memcpy_end \
  --match exact --aggregate --duration-ms 2000

# 3. Measure exact latency from a CUDA API call to the GPU work it issued
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 JSON object alongside raw trace files and a `.manifest.json` (`CLOCK_MONOTONIC` window, UTC `wall_clock` anchors, and `cuda_devices` GPU UUIDs):

```bash
# Capture once, diff metrics across iterations, or join traces in Python
before=$(xprobe measure --spec kernel.json | jq '.measurement.latency_ns.p95')
# ... apply change ...
after=$(xprobe measure --spec kernel.json | jq '.measurement.latency_ns.p95')

# Slice a GPU bubble alongside concurrent Python & CPU samples, or compare multi-GPU ranks
skills/xprobe-perf-profiling/scripts/analyze_trace.py trace.jsonl \
  --slice-gap 1 --python-samples py.jsonl --cpu-samples cpu.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`.

## 📊 Measured overhead

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/itdevwu/xprobe/master/docs/assets/xprobe-bench-dark.svg">
    <img alt="Measured xprobe profiling overhead across Python external sampling, CPU sampling, uprobes, CUPTI, perf, and py-spy" src="https://raw.githubusercontent.com/itdevwu/xprobe/master/docs/assets/xprobe-bench-light.svg" width="880">
  </picture>
</p>

<p align="center"><sub>2 s runs per case; lower is better (1.00x = zero overhead). See <a href="docs/benchmarks.md">Benchmarks</a> for full methodology, stress numbers, and reproducible recipes.</sub></p>

## 🛠️ 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

Full documentation: [English](https://docs.itdevwu.com/en/xprobe) · [中文](https://docs.itdevwu.com/xprobe)

- [Installation](https://github.com/itdevwu/xprobe/blob/master/docs/installation.md)
- [CLI reference](https://github.com/itdevwu/xprobe/blob/master/docs/cli-reference.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. README visuals embed subsets of [Maple Mono](https://github.com/subframe7536/maple-font) and [Geist](https://vercel.com/font) (SIL OFL-1.1).
