libkineto: native Perfetto (.pftrace) trace export#5
Open
ajassani wants to merge 1 commit into
Open
Conversation
Add an optional PerfettoTraceLogger that writes traces directly in the
Perfetto protobuf (.pftrace) format, so PyTorch profiler output can be
consumed natively by Perfetto/TraceLens pipelines without a JSON->pftrace
conversion step.
- New output_perfetto.{h,cpp} implementing ActivityLogger on top of the
Perfetto in-process tracing SDK, mapping each Kineto ActivityType to a
registered TrackEvent category and emitting flows for linked activities.
- Register a "pftrace://" protocol in the ActivityLoggerFactory and route
any save() target ending in .pftrace to it.
- Gate the whole path behind a new KINETO_ENABLE_PERFETTO CMake option
(OFF by default). When ON, the build compiles the Perfetto SDK amalgam
from PERFETTO_SOURCE_DIR and links it into libkineto.
- Add a gated unit test asserting a non-empty .pftrace is produced.
The feature is fully optional: with KINETO_ENABLE_PERFETTO=OFF the new
source compiles to nothing and behavior is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds native Perfetto protobuf (
.pftrace) export to libkineto, so PyTorch profiler traces can be written directly in the same format consumed by Perfetto and TraceLens pipelines, with no intermediate Chrome-JSON → pftrace conversion.output_perfetto.{h,cpp}: aPerfettoTraceLoggerimplementingActivityLoggeron top of the Perfetto in-process tracing SDK. Each KinetoActivityTypemaps to a compile-time-registeredTrackEventcategory; linked activities are emitted as Perfetto flows; activity metadata is attached as debug annotations.pftrace://protocol inActivityLoggerFactoryand routes anysave()target ending in.pftraceto it (existing.jsonbehavior is untouched).KINETO_ENABLE_PERFETTO(defaultOFF). WhenON, the build compiles the Perfetto SDK amalgamation fromPERFETTO_SOURCE_DIRinto a statickineto_perfettotarget and links it into libkineto.PerfettoTraceLoggerTest) asserting a non-empty.pftraceis produced.The path is fully optional. With
KINETO_ENABLE_PERFETTO=OFFthe new translation unit compiles to nothing and there is no behavior or dependency change.Why
.pftraceis the native Perfetto format; emitting it directly avoids a lossy/slow JSON round-trip and lets profiler output drop straight into Perfetto-based analysis.Validation
Built into a full PyTorch profiler stack with
KINETO_ENABLE_PERFETTO=ONand exercised end-to-end viatorch.profileron both CPU and GPU (MI210) workloads:.pftrace(~8.7 KB)[CPU, CUDA]activities) → non-empty.pftrace(~33 KB)Both files open in Perfetto with per-thread/per-device tracks and flows.
Build
PERFETTO_SOURCE_DIRmust containsdk/perfetto.handsdk/perfetto.cc.Notes / follow-ups
KINETO_ENABLE_PERFETTO; wiring it into the default test target matrix can be a follow-up.