⚠️ CRITICAL RULES * Path & Session Resolution: Pass the log directory
path, direct profile run folder, or individual .xplane.pb file directly as a
positional argument (e.g. xprof <subcommand> /path/to/logdir or xprof <subcommand> /path/to/logdir/plugins/profile/<run_name>), or use explicit
--logdir=<path> and --session_id=<run_name> flags. * Timeline
Coverage: ALWAYS specify --max_events=200000 (or --max_events=-1) when
calling list_xplane_events to ensure complete trace capture across
iterations. * Asynchronous Execution: NEVER block on long-running
operations. Delegate to a subagent.
xprof
This skill consolidates various tools related to XProf operations and analysis.
CLI
The primary tool for interacting with XProf data is the XProf CLI bundled with
the xprof package.
xprof <subcommand> [flags]
All xprof subcommands emit JSON to stdout. There is no output-format flag;
pipe the output to jq or redirect it to a file if you need another
representation.
Discovery of Workflows
CRITICAL for Agents: Many advanced workflows (like diffing sessions,
numerical verification, or mapping architecture blocks) are documented in this
skill's markdown files but are NOT visible by running xprof -h.
- DO NOT rely solely on
xprof -h to discover capabilities.
- Always read the
Supported Capabilities section
below and the linked reference files to find complex analysis workflows.
Referring to Sessions & Inputs
xprof tools accept trace inputs through multiple flexible formats:
Base Log Directory (Auto-Discovery): Pass the root directory where
profiles are stored. xprof automatically discovers the latest profile run
under plugins/profile/:
xprof get_overview /path/to/logdir
Direct Run Directory: Pass the direct session run folder containing the
trace data:
xprof get_overview /path/to/logdir/plugins/profile/2026_08_17_22_58_50
Direct Trace File: Pass an individual .xplane.pb file directly:
xprof get_overview /path/to/logdir/plugins/profile/2026_08_17_22_58_50/worker0.xplane.pb
Explicit Named Flags: Pass explicit --logdir and --session_id flags:
xprof get_overview --logdir=/path/to/logdir --session_id=2026_08_17_22_58_50
Best Practices
- Asynchronous Execution: Some operations (such as processing large traces
or running complex queries) can take a long time. For these, consider
spawning a subagent. However, for quick lookups like
get_hosts or
get_overview, execute the command directly.
- Trace Buffer Overflows: If traces show dropped events or truncated
steps, shorten the profiling duration (e.g. 2–5 steps instead of 20) or
filter targeted event types using
--plane_regex in timeline tools.
- When running commands that get sent to the background as tasks, DO NOT
attempt to guess the log file path or use
grep manually to poll for
completion.
Workflows
Bottleneck Analysis (7-Phase Protocol)
When asked to find or analyze performance bottlenecks for an XProf session,
follow the structured 7-Phase Performance Analysis Protocol detailed in
references/analysis.md (Turn-1 Parallel Triage,
Macro-to-Micro Op Drilldown, Headroom & EIC Quantification, Actionable Code
Proposal, Empirical Validation, Numerical Parity, and Artifact Closure).
Profile Collection & Ingestion
When collecting a performance trace or preparing an external trace for
analysis:
- Collect Profile: For JAX, PyTorch, or TensorFlow workloads, capture
traces programmatically or via remote profiler servers (see
Profile Collection Guide).
- Import Standalone Traces: For pre-existing trace files (
.xplane.pb or
.xspace.pb), run xprof upload_trace to stage them into your
<logdir> (see Import Trace File).
Low Level Optimizer (LLO) & Custom Call Profiling
⚠️ EXPERIMENTAL FEATURE: Low Level Optimizer (LLO) analysis and custom
call profiling are experimental. To access these features and all CLI
subcommands (verify_numerical_parity, get_kernel_stats,
get_llo_analysis, get_llo_debug_string), users MUST install
xprof-nightly (pip install xprof-nightly or uv pip install xprof-nightly 'jax[tpu]'), as the main xprof PyPI release (2.23.1) lacks
these subcommands.
When capturing or analyzing fine-grained LLO traces for custom kernels (e.g.
Pallas or Mosaic):
Toolchain Prerequisites: Workload VMs must run Python 3.11+ (Python
3.12 recommended via uv) and JAX >= 0.11.0. (Default Cloud TPU VM
images running Python 3.10 cap JAX at 0.6.2 and pull libtpu 0.0.17 which
lacks LLO flag support and causes ERROR: Unknown command line flag).
Environment Initialization: LIBTPU_INIT_ARGS must be exported
strictly before import jax:
export LIBTPU_INIT_ARGS="--xla_xprof_enable_custom_call_tracing=true --xla_xprof_register_llo_debug_info=true"
python your_jax_workload.py
Hardware Compatibility:
- LLO analysis, disassembly, and custom call tracing work on any
supported TPU (v6e, v5e, v4, etc.) — it is NOT gated to v7x.
- Periodic hardware runtime counters
(
tpu_enable_periodic_counter_sampling) require Ironwood TPU7x+.
Flag Symbol Verification (Optional Diagnostic): Inspect installed
*libtpu*.so to verify supported flags before launching:
import glob, libtpu, os
so = glob.glob(os.path.dirname(libtpu.__file__) + "/*libtpu*.so")[0]
blob = open(so, "rb").read()
for f in (b"xla_xprof_register_llo_debug_info", b"xla_xprof_enable_custom_call_tracing"):
print(f.decode(), "PRESENT" if f in blob else "ABSENT")
Canonical Flags:
--xla_xprof_enable_custom_call_tracing=true: Canonical flag
(reconciles legacy --xla_enable_custom_call_region_trace=true).
--xla_xprof_register_llo_debug_info=true: Registers LLO debug info and
disassembly in XProf traces.
Analysis Execution & Metrics Interpretation:
xprof get_llo_analysis <logdir_or_session_id>: Extracts instruction
counts, cycle estimates, and execution schedules.
xprof get_llo_debug_string <logdir_or_session_id>: Disassembles Low
Level Optimizer (LLO) instructions (inner loops appear as // Loop body not available in lite proto).
xprof get_kernel_stats <logdir_or_session_id>: Provides kernel
latency. (Note: get_roofline_model and get_overview will report 0.0
GFLOP/s and 0% MXU for tpu_custom_call because XLA has no cost model
for custom calls; use get_kernel_stats for latency and
get_llo_analysis for instruction counts).
- Trace Validation: Test LLO presence by calling
get_llo_analysis
and reading success, not by inspecting trace line names.
- Get Graph Viewer Data: Get graph
viewer data (HLO text) and source line mappings from XProf.
- Get Session Overview: Get a comprehensive
overview (Performance Summary, Run Environment) of an XProf session.
- Get Memory Profile: Get a detailed
memory profile analysis (Peak/device memory details) of an XProf session.
- Get Peak Allocations: Get HLO
modules and buffers ordered by memory usage.
- Get Top HLO Operations: Identify top
HLO operations by time, FLOPs, or bytes accessed.
- Get KPI Metrics: Fetch consolidated KPI
metrics (step time, duty cycle, MXU utilization, roofline) for a session.
- Get Roofline Model: Identify
compute vs memory bandwidth bottlenecks at program and per-operation level.
- Get HLO Neighborhood: Fetch the
BFS neighborhood of an HLO instruction to identify fusion blockers.
- Get Utilization Viewer: Fetch
utilization metrics filtered by host, device, or node.
- Analyze XLA Module Performance: Analyze XLA
module performance, inspect HLO operations, and query timeline events.
- Architecture Mapping: Map model
architecture blocks to the HLO ops and timeline events that implement them.
- Import Trace File: Import raw trace files
into an xprof logdir for analysis.
- Collect XProf Profile: Collect
performance profiles across JAX, PyTorch, and TensorFlow workloads via
programmatic tracing or remote capture.
- Diff Sessions: Compare performance, kernel
execution times, top operations, and HLO graphs between baseline and
candidate sessions.
- Numerical Verification: Verify
reference grounding (detecting lossy baselines via Float64 Oracle) and
refactor equivalence (exact/tight ULP bitwise checks for cleanups and
reshapes). Note: Do not use as an automated merge gate to block
reassociating kernel optimizations ($a + (b + c) \ne (a + b) + c$).
- Custom Call & LLO Profiling: Trace custom kernel
execution, instruction metrics, and register LLO debug info.
1---2name: xprof3description: Central entry point for ALL XProf operations and analyses. Use this skill first for any task involving XProf traces, performance, memory, HLO ops, collecting/triggering XProf profiles, or numerical correctness verification.4---56> ⚠️ **CRITICAL RULES** * **Path & Session Resolution**: Pass the log directory7> path, direct profile run folder, or individual `.xplane.pb` file directly as a8> positional argument (e.g. `xprof <subcommand> /path/to/logdir` or `xprof9> <subcommand> /path/to/logdir/plugins/profile/<run_name>`), or use explicit10> `--logdir=<path>` and `--session_id=<run_name>` flags. * **Timeline11> Coverage**: ALWAYS specify `--max_events=200000` (or `--max_events=-1`) when12> calling `list_xplane_events` to ensure complete trace capture across13> iterations. * **Asynchronous Execution**: **NEVER** block on long-running14> operations. Delegate to a subagent.1516# xprof1718This skill consolidates various tools related to XProf operations and analysis.1920## CLI2122The primary tool for interacting with XProf data is the XProf CLI bundled with23the `xprof` package.2425```bash26xprof <subcommand> [flags]27```2829All `xprof` subcommands emit **JSON** to stdout. There is no output-format flag;30pipe the output to `jq` or redirect it to a file if you need another31representation.3233## Discovery of Workflows3435**CRITICAL for Agents**: Many advanced workflows (like diffing sessions,36numerical verification, or mapping architecture blocks) are documented in this37skill's markdown files but are NOT visible by running `xprof -h`.3839- **DO NOT rely solely on `xprof -h`** to discover capabilities.40- **Always read the41 [Supported Capabilities](#supported-capabilities--references)** section42 below and the linked reference files to find complex analysis workflows.4344## Referring to Sessions & Inputs4546`xprof` tools accept trace inputs through multiple flexible formats:47481. **Base Log Directory (Auto-Discovery)**: Pass the root directory where49 profiles are stored. `xprof` automatically discovers the latest profile run50 under `plugins/profile/`:5152 ```bash53 xprof get_overview /path/to/logdir54 ```552. **Direct Run Directory**: Pass the direct session run folder containing the56 trace data:5758 ```bash59 xprof get_overview /path/to/logdir/plugins/profile/2026_08_17_22_58_5060 ```613. **Direct Trace File**: Pass an individual `.xplane.pb` file directly:6263 ```bash64 xprof get_overview /path/to/logdir/plugins/profile/2026_08_17_22_58_50/worker0.xplane.pb65 ```664. **Explicit Named Flags**: Pass explicit `--logdir` and `--session_id` flags:6768 ```bash69 xprof get_overview --logdir=/path/to/logdir --session_id=2026_08_17_22_58_5070 ```7172## Best Practices7374- **Asynchronous Execution**: Some operations (such as processing large traces75 or running complex queries) can take a long time. For these, consider76 spawning a subagent. However, for quick lookups like `get_hosts` or77 `get_overview`, execute the command directly.78- **Trace Buffer Overflows**: If traces show dropped events or truncated79 steps, shorten the profiling duration (e.g. 2–5 steps instead of 20) or80 filter targeted event types using `--plane_regex` in timeline tools.81- When running commands that get sent to the background as tasks, **DO NOT**82 attempt to guess the log file path or use `grep` manually to poll for83 completion.8485## Workflows8687### Bottleneck Analysis (7-Phase Protocol)8889When asked to find or analyze performance bottlenecks for an XProf session,90follow the structured **7-Phase Performance Analysis Protocol** detailed in91[references/analysis.md](references/analysis.md) (Turn-1 Parallel Triage,92Macro-to-Micro Op Drilldown, Headroom & EIC Quantification, Actionable Code93Proposal, Empirical Validation, Numerical Parity, and Artifact Closure).9495### Profile Collection & Ingestion9697When collecting a performance trace or preparing an external trace for98analysis:991001. **Collect Profile**: For JAX, PyTorch, or TensorFlow workloads, capture101 traces programmatically or via remote profiler servers (see102 [Profile Collection Guide](references/collect_profile.md)).1032. **Import Standalone Traces**: For pre-existing trace files (`.xplane.pb` or104 `.xspace.pb`), run `xprof upload_trace` to stage them into your105 `<logdir>` (see [Import Trace File](references/upload_trace.md)).106107### Low Level Optimizer (LLO) & Custom Call Profiling108109> ⚠️ **EXPERIMENTAL FEATURE**: Low Level Optimizer (LLO) analysis and custom110> call profiling are **experimental**. To access these features and all CLI111> subcommands (`verify_numerical_parity`, `get_kernel_stats`,112> `get_llo_analysis`, `get_llo_debug_string`), users **MUST install113> `xprof-nightly`** (`pip install xprof-nightly` or `uv pip install114> xprof-nightly 'jax[tpu]'`), as the main `xprof` PyPI release (2.23.1) lacks115> these subcommands.116117When capturing or analyzing fine-grained LLO traces for custom kernels (e.g.118Pallas or Mosaic):1191201. **Toolchain Prerequisites**: Workload VMs must run **Python 3.11+** (Python121 3.12 recommended via `uv`) and **JAX >= 0.11.0**. (Default Cloud TPU VM122 images running Python 3.10 cap JAX at 0.6.2 and pull `libtpu` 0.0.17 which123 lacks LLO flag support and causes `ERROR: Unknown command line flag`).1242. **Environment Initialization**: `LIBTPU_INIT_ARGS` must be exported125 **strictly before `import jax`**:126127 ```bash128 export LIBTPU_INIT_ARGS="--xla_xprof_enable_custom_call_tracing=true --xla_xprof_register_llo_debug_info=true"129 python your_jax_workload.py130 ```1313. **Hardware Compatibility**:132133 * LLO analysis, disassembly, and custom call tracing work on **any134 supported TPU** (v6e, v5e, v4, etc.) — it is **NOT** gated to v7x.135 * Periodic hardware runtime counters136 (`tpu_enable_periodic_counter_sampling`) require Ironwood TPU7x+.1374. **Flag Symbol Verification (Optional Diagnostic)**: Inspect installed138 `*libtpu*.so` to verify supported flags before launching:139140 ```python141 import glob, libtpu, os142 so = glob.glob(os.path.dirname(libtpu.__file__) + "/*libtpu*.so")[0]143 blob = open(so, "rb").read()144 for f in (b"xla_xprof_register_llo_debug_info", b"xla_xprof_enable_custom_call_tracing"):145 print(f.decode(), "PRESENT" if f in blob else "ABSENT")146 ```1475. **Canonical Flags**:148149 * `--xla_xprof_enable_custom_call_tracing=true`: Canonical flag150 (reconciles legacy `--xla_enable_custom_call_region_trace=true`).151 * `--xla_xprof_register_llo_debug_info=true`: Registers LLO debug info and152 disassembly in XProf traces.1536. **Analysis Execution & Metrics Interpretation**:154155 * `xprof get_llo_analysis <logdir_or_session_id>`: Extracts instruction156 counts, cycle estimates, and execution schedules.157 * `xprof get_llo_debug_string <logdir_or_session_id>`: Disassembles Low158 Level Optimizer (LLO) instructions (inner loops appear as `// Loop body159 not available in lite proto`).160 * `xprof get_kernel_stats <logdir_or_session_id>`: Provides kernel161 latency. *(Note: `get_roofline_model` and `get_overview` will report 0.0162 GFLOP/s and 0% MXU for `tpu_custom_call` because XLA has no cost model163 for custom calls; use `get_kernel_stats` for latency and164 `get_llo_analysis` for instruction counts).*165 * **Trace Validation**: Test LLO presence by calling `get_llo_analysis`166 and reading `success`, not by inspecting trace line names.167168<h2 id="supported-capabilities--references">Supported Capabilities & References</h2>169170- **[Get Graph Viewer Data](references/get_graph_viewer.md)**: Get graph171 viewer data (HLO text) and source line mappings from XProf.172- **[Get Session Overview](references/get_overview.md)**: Get a comprehensive173 overview (Performance Summary, Run Environment) of an XProf session.174- **[Get Memory Profile](references/get_memory_profile.md)**: Get a detailed175 memory profile analysis (Peak/device memory details) of an XProf session.176- **[Get Peak Allocations](references/get_peak_allocations.md)**: Get HLO177 modules and buffers ordered by memory usage.178- **[Get Top HLO Operations](references/get_top_hlo_ops.md)**: Identify top179 HLO operations by time, FLOPs, or bytes accessed.180- **[Get KPI Metrics](references/get_kpi_metrics.md)**: Fetch consolidated KPI181 metrics (step time, duty cycle, MXU utilization, roofline) for a session.182- **[Get Roofline Model](references/get_roofline_model.md)**: Identify183 compute vs memory bandwidth bottlenecks at program and per-operation level.184- **[Get HLO Neighborhood](references/get_hlo_neighborhood.md)**: Fetch the185 BFS neighborhood of an HLO instruction to identify fusion blockers.186- **[Get Utilization Viewer](references/get_utilization_viewer.md)**: Fetch187 utilization metrics filtered by host, device, or node.188- **[Analyze XLA Module Performance](references/analysis.md)**: Analyze XLA189 module performance, inspect HLO operations, and query timeline events.190- **[Architecture Mapping](references/architecture_mapping.md)**: Map model191 architecture blocks to the HLO ops and timeline events that implement them.192- **[Import Trace File](references/upload_trace.md)**: Import raw trace files193 into an xprof logdir for analysis.194- **[Collect XProf Profile](references/collect_profile.md)**: Collect195 performance profiles across JAX, PyTorch, and TensorFlow workloads via196 programmatic tracing or remote capture.197- **[Diff Sessions](references/diff_session.md)**: Compare performance, kernel198 execution times, top operations, and HLO graphs between baseline and199 candidate sessions.200- **[Numerical Verification](references/numerical_correctness.md)**: Verify201 reference grounding (detecting lossy baselines via Float64 Oracle) and202 refactor equivalence (exact/tight ULP bitwise checks for cleanups and203 reshapes). *Note*: Do not use as an automated merge gate to block204 reassociating kernel optimizations ($a + (b + c) \ne (a + b) + c$).205- **[Custom Call & LLO Profiling][custom-call-doc]**: Trace custom kernel206 execution, instruction metrics, and register LLO debug info.207208[custom-call-doc]: https://openxla.org/xprof/custom_call_profiling