Skip to content

Add native Perfetto (.pftrace) export to torch.profiler - #1

Open
ajassani wants to merge 1 commit into
mainfrom
pftrace-export
Open

Add native Perfetto (.pftrace) export to torch.profiler#1
ajassani wants to merge 1 commit into
mainfrom
pftrace-export

Conversation

@ajassani

Copy link
Copy Markdown
Owner

Summary

Adds a native Perfetto (.pftrace) export path to torch.profiler, so users can write Perfetto protobuf traces directly from a profiling session instead of exporting Chrome JSON and converting afterwards.

  • New export_pftrace(path) on torch.profiler.profile (_KinetoProfile) and on the legacy torch.autograd.profiler.profile, mirroring export_chrome_trace (including .gz handling).
  • C++ bindings: ProfilerResult::savePftrace / ActivityTraceWrapper::savePftrace, routed through Kineto's pftrace:// save protocol, exposed to Python as save_pftrace.
  • Build gated behind a new USE_KINETO_PERFETTO CMake option (default OFF), plumbed to Kineto's KINETO_ENABLE_PERFETTO.

When Kineto is built without Perfetto support, behavior is unchanged and the existing JSON path is untouched.

This is the PyTorch-side companion to the Kineto change that implements the actual Perfetto trace logger and the pftrace:// protocol registration.

Usage

with torch.profiler.profile(activities=[...]) as prof:
    run_workload()
prof.export_pftrace("trace.pftrace")

Test plan

  • Builds with USE_KINETO_PERFETTO=ON against a Kineto built with Perfetto support (MI300-class GPU, ROCm).
  • CPU-only smoke workload produces a non-empty .pftrace that loads in the Perfetto UI.
  • GPU smoke workload produces a non-empty .pftrace with device track events.
  • CI build with default USE_KINETO_PERFETTO=OFF (JSON path unchanged).

Expose a new `export_pftrace()` API on both `torch.profiler.profile`
(`_KinetoProfile`) and the legacy `torch.autograd.profiler.profile`,
letting users write Perfetto protobuf traces directly instead of going
through Chrome JSON conversion.

Python side mirrors `export_chrome_trace`, including `.gz` handling.
C++ side adds `ProfilerResult::savePftrace` /
`ActivityTraceWrapper::savePftrace`, which route through Kineto's
`pftrace://` save protocol, plus the pybind binding `save_pftrace`.

Build is gated behind the new `USE_KINETO_PERFETTO` option (default OFF),
which is plumbed to Kineto's `KINETO_ENABLE_PERFETTO`. When Kineto is
built without Perfetto support the existing JSON path is unaffected.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant