Automated PyTorch Trace Analysis Tools for Performance

Best Automated PyTorch Trace Analysis Tools for ML (2026)

Written by: Nimesh Chakravarthi, Co-founder & CTO, Struct | Last updated: October 3, 2026

Key Takeaways

  • Automated trace analysis tools read PyTorch Kineto JSON files and surface bottlenecks such as GPU starvation, communication-bound execution, kernel-launch overhead, or host-side stalls without manual timeline review.
  • HTA, TraceLens, Perfetto SQL, and gpu-idle each focus on specific outputs such as idle-time breakdowns, communication-compute overlap, roofline metrics, or plain-English bottleneck labels.
  • torch.profiler and Dynolog handle trace collection, while tools like HTA and TraceLens convert raw traces into structured findings such as DataFrames or Markdown reports.
  • Nsight Systems and Nsight Compute provide kernel-level escalation with queue-time analysis and hardware counters when torch.profiler granularity is not enough.
  • Struct turns trace findings into maintained monitors, automated triage, root cause analysis, and fixes, with production performance metrics detailed below.

Run Struct In Shadow Mode →

Comparison Table: PyTorch Trace Analysis Tools At A Glance

The table below maps each tool to the trace format it ingests, the primary bottleneck class it targets, and the output it produces. This view shows where each tool sits in the trace-to-finding pipeline.

Tool Trace Format Ingested Primary Bottleneck Class Detected Output Type
torch.profiler / Kineto Exports collected events to Chrome TraceEvent JSON (Chrome JSON format) Operator-level hotspots and per-operator CPU/CUDA time Chrome trace JSON, profiler table, TensorBoard artifact
Holistic Trace Analysis (HTA) PyTorch Profiler (Kineto) traces from a directory containing all per-rank trace files for a job Distributed bottlenecks such as GPU idle time, communication exposure, and kernel-launch overhead Pandas DataFrames, plots
TraceLens PyTorch profiler JSON, JAX traces, AMD RocProf JSON Roofline efficiency, collective bandwidth and skew, and cross-run trace shape changes Markdown report, Excel workbook, Python SDK objects
Perfetto + SQL Chrome TraceEvent JSON, .perfetto-trace, simpleperf protobufs Custom bottleneck classes defined by your SQL detection logic SQL result sets, CSV, Python DataFrames via perfetto package
Dynolog Triggers Kineto capture on running processes; Kineto generates one trace file per GPU On-demand trace collection coverage for distributed jobs Kineto trace files (consumed by HTA or Perfetto downstream)
Nsight Systems / Compute Nsight Systems ingests its proprietary .nsys-rep report format (and .qdstrm intermediate files, which it converts to .nsys-rep), not Kineto JSON Kernel-level queue-time, execution-time, and hardware-counter bottlenecks SQLite-backed reports, CLI summary tables

Once you have identified the bottleneck class, the table above narrows to a specific tool for each one:

How To Analyze PyTorch Profiler Traces Automatically

You collect a Kineto trace with torch.profiler, then run a tool that parses the Chrome TraceEvent JSON and computes the bottleneck as a structured finding such as a DataFrame row, a Markdown report section, or a SQL result set. Manual timeline reading in Perfetto UI does not scale across dozens of ranks or hundreds of jobs, so automated parsing and computation become essential.

The pipeline has four stages:

  • Collection, using torch.profiler (inline schedule) or Dynolog (daemon-side, no code changes).
  • Parsing, where Kineto JSON becomes an event tree (HTA, TraceLens) or SQL tables (Perfetto TraceProcessor).
  • Computation, which produces temporal breakdowns, idle categories, overlap percentages, or roofline metrics.
  • Finding, which appears as a DataFrame, Markdown report, SQL row, or plain-English diagnosis from gpu-idle.

HTA and gpu-idle sit at the computation and finding stages. Perfetto TraceProcessor sits at parsing and computation. Dynolog sits at collection. Nsight Systems operates on a separate capture format and escalates to kernel-level detail that torch.profiler cannot reach.

What A PyTorch Trace Is And How The Kineto Trace Format Works

Every tool in that pipeline depends on the same input format. torch.profiler emits Kineto/Chrome TraceEvent JSON: a root object whose traceEvents array holds every instrumented event from CPU operators, GPU kernels, and memory operations. Each event carries the fields downstream analyzers depend on:

PyTorch 2.12 added a seq_num field that correlates NCCL collective traces across ranks. All ranks in the same collective share the same sequence number within a process group. Every downstream analyzer such as HTA, TraceLens, Perfetto, or gpu-idle depends on this schema. The Kineto library collects hardware-level events via CUPTI (NVIDIA), ROCTRACER (AMD), and ITT (Intel) before serializing them into this format.

Tool-By-Tool Breakdown: How Each PyTorch Trace Analyzer Works

torch.profiler / Kineto

torch.profiler is the collection layer. It is a high-level Python wrapper over the autograd profiler and the Kineto library. It registers callbacks in the PyTorch dispatcher and uses hardware-specific tracing APIs to capture GPU kernels, CPU operators, and memory events, then exports them to Chrome TraceEvent JSON.

The profiler schedule (wait, warmup, active, repeat) controls which steps appear in the trace. The wait phase skips noisy initialization, warmup runs the profiler without recording, and only active steps appear in the exported JSON. This pattern keeps the captured data representative of steady-state execution. For long distributed jobs, Dynolog provides the daemon-side path so the profiler can be triggered on demand without modifying model source code.

Limitation: torch.profiler uses CUPTI to trace on-device CUDA kernels but provides only high-level, kernel-level granularity. Understanding kernel-level performance such as SM occupancy, register pressure, and memory throughput requires a low-level hardware-counter tool like NVIDIA Nsight Compute. Best for: initial collection and operator-level hotspot identification.

Holistic Trace Analysis (HTA)

HTA, open-sourced by Meta, extends single-machine PyTorch profiling to multi-rank distributed training by ingesting a directory of per-rank Kineto JSON files and computing cross-rank breakdowns. It is invoked via a TraceAnalysis object and returns Pandas DataFrames.

HTA computes temporal breakdowns across compute, communication, memory, and idle time per rank. It also computes idle-time breakdowns across host-wait, kernel-wait, and unknown categories, plus communication-compute overlap and CUDA kernel launch statistics. If NCCL kernels and compute kernels execute sequentially rather than overlapping on the timeline, HTA’s overlap metric shows low overlap. That pattern signals a communication bottleneck.

Limitation: HTA does not compute roofline metrics or per-shape efficiency. Best for: multi-rank distributed training bottleneck identification.

TraceLens

TraceLens is an open-source AMD tool that converts flat PyTorch profiler traces into a hierarchical event tree (Trace2Tree). It links high-level Python operations to mid-level CPU dispatches and down to individual GPU kernels. It then computes roofline metrics from operator shapes without requiring reruns.

Its GPU Timeline report classifies total time into computation_time, exposed_comm_time, exposed_memcpy_time, busy_time, and idle_time. For GEMMs, it applies FLOPs = 2·M·N·K and bytes = (M·K + K·N + M·N) × element size to compute achieved TFLOPS/s and TB/s. The TraceLens Agent wraps this into an agentic report with findings tiered as Compute Kernel Optimizations, Kernel Fusion Opportunities, and System-Level Optimizations. It supports any backend the PyTorch profiler supports, including CUDA and ROCm, as well as JAX.

Limitation: Compute metrics are theoretical estimates from operator semantics, not hardware counters. Best for: roofline analysis, collective bandwidth measurement, and cross-run morphological diff.

Perfetto + SQL

Perfetto TraceProcessor parses Chrome TraceEvent JSON into columnar SQL tables such as slice, track, thread, process, and counter. It exposes a SQL interface for programmatic analysis. This path lets you build your own analyzer: you write the detection logic, and Perfetto provides the storage and query engine.

The trace_processor CLI can load a trace and execute SQL without opening the UI, which enables batch analysis across a directory of traces. The Python perfetto package exposes TraceProcessor and BatchTraceProcessor for CI-style workflows.

Limitation: Perfetto requires writing and maintaining detection queries and does not provide out-of-the-box bottleneck classification. Best for: custom detection logic, regression pipelines, and teams with specific query requirements.

Dynolog

Dynolog is the daemon-side collection layer that enables on-demand Kineto trace capture on running distributed training jobs without modifying model source code. A profiling request is broadcast to monitoring daemons on target hosts. Kineto generates one trace per GPU and writes it to a shared location for downstream analysis by HTA or Perfetto.

The key operational distinction involves response fields. Dynolog’s response exposes processesMatched and activityProfilersTriggered as separate fields. A process can be matched without the profiler being triggered if the profiler slot is busy, so treating “matched” as success can report a capture that never produces a file.

Limitation: Dynolog handles collection only, and analysis requires a downstream tool. Best for: production distributed training fleets where hand-instrumenting every job is not feasible.

Nsight Systems vs Nsight Compute

Nsight Systems captures the full interaction timeline among CPU, GPU, and OS scheduling and writes it to a .nsys-rep file, not Kineto JSON. It breaks each kernel launch into API time, queue time, and kernel time. Queue time indicates the GPU was busy when a new kernel was scheduled. Zero queue time everywhere can indicate an idle GPU.

Nsight Compute goes one level deeper and exposes SM occupancy, register pressure, memory throughput, and roofline analysis at the individual kernel level. CPU-GPU synchronizations appear in Nsight Systems as long “CUDA stream synchronize” bars on the CPU timeline. These bars correlate with visible GPU utilization gaps, which torch.profiler records but does not automatically flag.

Limitation: Nsight requires a separate capture and does not ingest Kineto JSON. Best for: kernel-level escalation after torch.profiler and HTA have identified the bottleneck operator.

Runnable Example: torch.profiler Schedule And Perfetto SQL Query

This example shows a practical schedule and a matching SQL query. The schedule captures three steady-state steps after one wait and one warmup, following the pattern documented in the Hugging Face torch.profiler guide and used in PrizePicks’ production profiling setup:

import torch from torch.profiler import profile, schedule, ProfilerActivity, tensorboard_trace_handler with profile( activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA], schedule=schedule(wait=1, warmup=1, active=3, repeat=1), on_trace_ready=tensorboard_trace_handler("./traces"), record_shapes=True, profile_memory=True, with_stack=True, ) as prof: for step, batch in enumerate(dataloader): train_step(batch) prof.step() 

Once the trace is exported, you can load it into Perfetto TraceProcessor and query for GPU gaps. The following query, using the Perfetto SQL slice table, finds CPU-side slices longer than 5 ms that are not covered by GPU kernel activity, which serves as a proxy for host-side stalls:

-- Run with: ./trace_processor query trace.json "SELECT ..." SELECT s.name, ROUND(s.dur / 1e6, 3) AS dur_ms, t.name AS thread_name FROM slice s JOIN thread_track tt ON s.track_id = tt.id JOIN thread t ON tt.utid = t.utid WHERE s.dur > 5000000 -- 5 ms in nanoseconds AND s.name NOT LIKE '%kernel%' ORDER BY s.dur DESC LIMIT 20; 

In PerfettoSQL, ts and dur are in nanoseconds, so ROUND(dur / 1e6, 3) converts durations to milliseconds for display.

Detection Logic: Signals For GPU Starvation, Communication-Bound Work, And Kernel-Launch Overhead

The thresholds and queries below illustrate how tools convert traces into machine-readable findings.

  • GPU Starvation (Dataloader Bottleneck): gpu-idle flags this when enumerate(DataLoader) dominates step time while the GPU idles. In its A100 calibration set, a num_workers=0 run measured 33.8% GPU busy with 92.5% of step time in the loader. The healthy control run measured 97.4% GPU busy, which provides the contrast that defines the threshold.
  • Small-Batch Or Kernel-Launch Overhead: gpu-idle uses a mean kernel duration threshold of 25 µs on A100-SXM-64GB. Below this threshold, launch overhead dominates useful work. HTA’s CUDA kernel launch statistics surface the distribution of excessively short kernels across ranks, which confirms the pattern.
  • Communication-Bound Work: HTA’s get_comm_comp_overlap() calculates the percentage of time during which communication overlaps computation. This percentage quantifies how much communication remains hidden versus exposed. Low overlap indicates exposed communication and signals a communication bottleneck. TraceLens collective analysis adds inter-rank skew. In a Llama 70B FSDP example, reduce_scatter showed a mean skew of 60,238 µs, which measured the time one GPU waited for another before communication could proceed.
  • Host-Side Stall (CPU-GPU Sync): In Nsight Systems, CPU-GPU synchronizations appear as long “CUDA stream synchronize” bars. In Perfetto SQL, you can query the slice table for cudaDeviceSynchronize or cudaStreamSynchronize events with dur > time_from_ms(1) as the threshold for a meaningful stall.

Where Struct Fits: Production Automation For PyTorch Trace Findings

Struct sits on top of the tools above and turns their findings into a production feedback loop. It converts trace-derived insights into maintained monitors, triage workflows, root cause analysis, and concrete fixes that stay aligned with your evolving model and cluster.

Struct sits on top of your existing observability stack (Datadog, Grafana, Sentry, AWS CloudWatch, Azure Monitor, GCP) rather than replacing it. It reads every PR to create the monitors that each change needs, then baselines those monitors after deploy so regressions are measured against a known-good state. From there it audits each deploy for regressions, triages every alert so only real impact reaches you, and performs root-cause analysis and remediation for what breaks. For on-call engineering teams, production alerts arrive with a cited root cause and a proposed fix, instead of a raw trace and a timeline to read manually.

Production results show the impact. Orb reclaimed 160+ engineering hours per month. Arcana eliminated about 14 hours per week of Sentry triage and now runs more than 2,100 automated investigations per month. p50 time to root cause is under 4 minutes, and setup typically takes about 10 minutes. Struct is SOC 2 Type II and HIPAA compliant (trust.struct.ai). You can run it in shadow mode next to your existing alert channel with no cutover risk. For a deeper look at how AI connects traces to root cause, see How To Use AI For Root Cause Analysis From Traces.

See How Struct Triages Trace Findings →

Frequently Asked Questions

How To Get Started With HTA On An Existing PyTorch Trace

Install HTA with pip install HolisticTraceAnalysis (requires Python 3.10+, Linux or Mac). Point a TraceAnalysis object at the directory containing your per-rank Kineto JSON files, which is the same directory written by tensorboard_trace_handler. Call methods like get_temporal_breakdown(), get_idle_time_breakdown(), and get_comm_comp_overlap() to get DataFrames. HTA requires all traces collected from a single job to reside in one unique folder.

When Perfetto SQL Can Replace A Dedicated PyTorch Trace Analyzer

Perfetto SQL can replicate most of what HTA computes, but you write and maintain the detection queries yourself. HTA and TraceLens ship pre-built computations such as idle-time categories, overlap percentages, and roofline metrics that would each require a non-trivial SQL query to reproduce. Perfetto fits best when you need custom detection logic, want to integrate trace analysis into a CI pipeline with BatchTraceProcessor, or need to query fields that HTA does not expose. For standard distributed training bottleneck analysis, HTA provides a faster start. For bespoke regression detection, Perfetto SQL provides more flexibility.

How Dynolog Collects Traces Without Hand-Instrumenting Every Job

Dynolog runs as a daemon on each training host. When a profiling request arrives, it triggers Kineto capture on a running process without any code change to the training script, with Kineto using the job ID (for example SLURM_JOB_ID) to identify the job. The workload must be armed at creation time with a hook, environment variables, and a shared directory so Kineto enters daemon mode. Once armed, captures can be triggered repeatedly without interrupting training. The key operational detail is to check activityProfilersTriggered in Dynolog’s response, in addition to processesMatched, to confirm the profiler actually started capturing.

What torch.profiler Cannot See That Nsight Compute Can

torch.profiler records kernel launch timestamps and durations but does not collect the hardware counters needed to see inside a kernel’s execution. Kineto can collect GPU hardware performance counters and metrics such as SM occupancy, memory throughput, and cache metrics via CUPTI and supports counter events in Chrome Trace format, although some metrics may require specific configuration or may be limited by GPU architecture. Nsight Compute captures hardware performance counters at the kernel level and enables roofline analysis that determines whether a specific kernel is compute-bound or memory-bound and by how much. The standard workflow uses torch.profiler and HTA to identify the bottleneck operator, then escalates to Nsight Compute for that specific kernel.

How To Run Automated Trace Analysis In Production Without Adding Noise

Use a profiler schedule with a short active window (3–5 steps) rather than tracing entire jobs, and trigger collection on demand via Dynolog rather than instrumenting every run. For analysis, run HTA or gpu-idle in a CI job that reads the trace directory and emits a structured finding such as a DataFrame or JSON rather than a human-readable report. This structure makes the output actionable by downstream systems. Struct sits above this layer and ingests findings from your existing observability stack, triages them, and surfaces only alerts that represent real production impact, so the analysis pipeline stays quiet unless something meaningful breaks.

Conclusion: From Trace To Finding To Fix In Production

The end-to-end pipeline looks like this: collect with torch.profiler or Dynolog, parse with HTA, TraceLens, or Perfetto, compute the bottleneck class such as GPU starvation, communication-bound work, kernel-launch overhead, or host-side stall, output a machine-readable finding, then escalate to Nsight Compute for kernel-level detail when needed. Each tool owns a specific stage. None of them owns the production loop that keeps those findings current as the model and cluster change. Struct fills that gap as the maintenance layer that turns trace findings into maintained monitors, automated triage, and fixes.

Start Your Shadow-Mode Setup →

Read Next