gputrace

package module
v0.0.0-...-30eb2b7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 8 Imported by: 0

README

gputrace

gputrace parses and analyzes Apple Metal GPU trace files (.gputrace bundles).

Installation

go install github.com/tmc/gputrace/cmd/gputrace@latest

Verify installation:

gputrace version

Quick Start

# Show trace statistics (dispatch counts, kernel names, timing)
gputrace stats trace.gputrace

# Full profiler breakdown (timing, pipelines, execution cost)
gputrace profiler trace.gputrace

# Export to pprof format for use with go tool pprof
gputrace pprof trace.gputrace -o trace.pb
go tool pprof -http=:8080 trace.pb

# Export Chrome/Perfetto timeline
gputrace timeline trace.gputrace -o trace.json

# Compare two traces
gputrace diff A.gputrace B.gputrace --explain

Commands

Group Command Description
Overview stats Comprehensive trace statistics
api-calls API call sequences
dump Raw API call dump
Kernel & Shader shaders Shader performance metrics
kernels Kernel functions and pipeline mappings
shader-source Source-level performance attribution
Timing & Profiling timing Timing metrics export
profiler GPU profiler data extraction
pprof pprof format export
correlate Correlate timing with hardware metrics
Command Buffers command-buffers Command buffer analysis
encoders Compute encoder listing
Buffer Analysis buffers Buffer listing and properties
buffer-access Buffer access patterns
buffer-timeline Buffer allocation timeline
Visualization timeline Chrome/Perfetto timeline export
graph Graph visualization
tree Execution tree view
diff Compare two traces
insights Actionable performance insights
Capture capture Capture GPU trace from a command
xcode-profile Xcode GPU profiler automation
Utilities serve Web server for trace browsing
mtlb Metal Library Binary inspection
clear-buffers Zero out buffers to reduce trace size
version Print build version

Run gputrace [command] --help for details on any command.

Trace Diff

Compare two profiled traces and explain performance deltas at dispatch, kernel, encoder, and timeline-window levels:

# Human-readable summary
gputrace diff A.gputrace B.gputrace --explain

# Function and encoder views
gputrace diff A.gputrace B.gputrace --by function,encoder --limit 25

# Dispatch outliers (with source indices)
gputrace diff A.gputrace B.gputrace --by dispatch --min-delta-us 30 --limit 50

# JSON or CSV output
gputrace diff A.gputrace B.gputrace --json > diff.json
gputrace diff A.gputrace B.gputrace --csv --by function > function_deltas.csv

# Auto-discover newest trace pair and run quick triage
gputrace diff --bench-dir /path/to/bench-traces --quick

# Write markdown report
gputrace diff A.gputrace B.gputrace --md-out /tmp/report.md

See docs/TRACE_DIFF_WORKFLOW.md for the full workflow and sample output.

Testing

go test ./...

The repository includes a small canonical fixture set under testdata/traces:

  • 01-single-encoder for basic parsing and diff smoke tests
  • 06-six-encoders for multi-encoder parsing and shader/debug coverage

Some success paths require capabilities that are not shipped in the small in-repo fixtures:

  • profiler requires traces with .gpuprofiler_raw
  • shader-source requires traces with source attribution data

Documentation

Detailed format and workflow documentation lives in docs/:

Reverse-engineering notes and implementation status documents live in docs/research/.

GPU Timing Methodology

.gputrace files do not contain pre-computed timing percentages. Xcode Instruments derives shader cost by replaying captured GPU workloads with performance counters enabled. This library extracts timing from profiler streamData (dispatch/kernel duration, execution cost sampling, and GPRWCNTR encoder profiles) when a .gpuprofiler_raw directory is present. For traces without profiler data, only structural information (kernels, encoders, buffers) is available.

Developer Convenience

For local macOS reinstall and permission setup:

make reinstall

License

MIT License. See LICENSE for details.

Documentation

Overview

Package gputrace provides parsing and analysis for .gputrace GPU trace files from Metal.

A .gputrace file is a directory bundle containing multiple files that represent Metal GPU capture data. This package provides utilities to parse trace metadata, extract kernel names, labels, and timing information.

The main entry point is the Open function which returns a Trace:

trace, err := gputrace.Open("path/to/trace.gputrace")
if err != nil {
	log.Fatal(err)
}

The Trace struct provides access to all parsed data and analysis capabilities.

For command-line usage, see cmd/gputrace which provides various subcommands for analyzing traces, exporting to different formats, and generating insights.

Index

Constants

View Source
const (
	RecordTypeCommand      = trace.RecordTypeCommand
	RecordTypeString       = trace.RecordTypeString
	RecordTypeFunction     = trace.RecordTypeFunction
	RecordTypeInteger      = trace.RecordTypeInteger
	RecordTypeUnsignedLong = trace.RecordTypeUnsignedLong
)

Re-export constants

View Source
const (
	MagicMTSP   = trace.MagicMTSP
	MagicXDIC   = trace.MagicXDIC
	MagicBPList = trace.MagicBPList
)

Re-export magic constants

View Source
const (
	InsightBottleneck   = analysis.InsightBottleneck
	InsightOptimization = analysis.InsightOptimization
	InsightAntiPattern  = analysis.InsightAntiPattern
	InsightInfo         = analysis.InsightInfo
)

Re-export insight type constants (gputrace-97)

View Source
const (
	SeverityCritical = analysis.SeverityCritical
	SeverityHigh     = analysis.SeverityHigh
	SeverityMedium   = analysis.SeverityMedium
	SeverityLow      = analysis.SeverityLow
	SeverityInfo     = analysis.SeverityInfo
)

Re-export insight severity constants (gputrace-97)

Variables

View Source
var (
	ErrInvalidTrace    = trace.ErrInvalidTrace
	ErrInvalidMagic    = trace.ErrInvalidMagic
	ErrMissingMetadata = trace.ErrMissingMetadata
)

Re-export errors

View Source
var (
	ExtractTimingData             = timing.ExtractTimingData
	ExtractStore0Timing           = timing.ExtractStore0Timing
	ConvertStore0ToEncoderTimings = timing.ConvertStore0ToEncoderTimings
	GenerateSyntheticTiming       = timing.GenerateSyntheticTiming
	ExtractShaderMetrics          = shader.ExtractShaderMetrics
	NewShaderSourceMapper         = shader.NewShaderSourceMapper
	FormatShadersSimple           = shader.FormatShadersSimple
	FormatShadersXcodeStyle       = shader.FormatShadersXcodeStyle
	ParseDetailedCommandBuffer    = command.ParseDetailedCommandBuffer
	DumpCommandBuffer             = command.DumpCommandBuffer
	ToPprof                       = export.ToPprof
	ToPprofWithSource             = export.ToPprofWithSource
	ToPprofWithSourceLines        = export.ToPprofWithSourceLines
	ToPprofWithMetrics            = export.ToPprofWithMetrics
	ParseXcodeCountersCSV         = counter.ParseXcodeCountersCSV
	ExtractStatistics             = analysis.ExtractStatistics
	NewTimingMetricsExtractor     = timing.NewTimingMetricsExtractor
	ParsePerfCounters             = counter.ParsePerfCounters

	// Buffer access analysis functions (gputrace-93)
	AnalyzeBufferAccess      = analysis.AnalyzeBufferAccess
	FormatBufferAccessReport = analysis.FormatBufferAccessReport

	// Buffer timeline functions (gputrace-94)
	ExtractBufferTimeline       = analysis.ExtractBufferTimeline
	FormatBufferTimelineASCII   = analysis.FormatBufferTimelineASCII
	FormatBufferTimelineSummary = analysis.FormatBufferTimelineSummary

	// Buffer diff functions (gputrace-95)
	ExtractBufferSizes = analysis.ExtractBufferSizes
	CompareBuffers     = analysis.CompareBuffers
	FormatBufferDiff   = analysis.FormatBufferDiff

	// Counter export functions (gputrace-101)
	NewCountersCSVExporter = counter.NewCountersCSVExporter

	// Counter sampling functions (gputrace-104)
	FormatCounterSamplingSimulation = replay.FormatCounterSamplingSimulation
	FormatCounterSamplingResult     = counter.FormatCounterSamplingResult

	// Replay engine functions (gputrace-103, gputrace-104)
	NewReplayEngine        = replay.NewReplayEngine
	FormatReplayPlan       = replay.FormatReplayPlan
	FormatReplayValidation = replay.FormatReplayValidation
	FormatReplayAnalysis   = replay.FormatReplayAnalysis

	// Shader source attribution functions (gputrace-105)
	ExtractShaderSourceAttribution    = shader.ExtractShaderSourceAttribution
	FormatShaderSourceAttribution     = shader.FormatShaderSourceAttribution
	FormatShaderSourceAttributionHTML = shader.FormatShaderSourceAttributionHTML

	// Timing metrics functions (gputrace-106)
	FormatTimingMetrics     = timing.FormatTimingMetrics
	ExportTimingMetricsJSON = timing.ExportTimingMetricsJSON
	ExportTimingMetricsCSV  = timing.ExportTimingMetricsCSV
	CompareTraces           = timing.CompareTraces
	FormatTimingComparison  = timing.FormatTimingComparison

	// Timing profiler functions (gputrace-107)
	NewTimingExtractorProfilerRaw = timing.NewTimingExtractorProfilerRaw

	// Shader export functions (gputrace-98)
	FormatShaderMetricsReport = shader.FormatShaderMetricsReport
	ExportShaderMetricsCSV    = shader.ExportShaderMetricsCSV
	ExportShaderMetricsJSON   = shader.ExportShaderMetricsJSON

	// Correlation functions (gputrace-96)
	CorrelateShaderMetrics  = shader.CorrelateShaderMetrics
	FormatCorrelationReport = shader.FormatCorrelationReport

	// Insights functions (gputrace-97)
	GenerateInsights     = analysis.GenerateInsights
	FormatInsightsReport = analysis.FormatInsightsReport
)

Re-export functions

Functions

This section is empty.

Types

type APICallList

type APICallList = trace.APICallList

API Call types (for buffer extraction)

type BufferAccessAnalysis

type BufferAccessAnalysis = analysis.BufferAccessAnalysis

Buffer access analysis types (gputrace-93)

type BufferAccessInfo

type BufferAccessInfo = analysis.BufferAccessInfo

Re-export main types from internal packages

type BufferAlias

type BufferAlias = analysis.BufferAlias

Re-export main types from internal packages

type BufferChange

type BufferChange = analysis.BufferChange

Re-export main types from internal packages

type BufferDiff

type BufferDiff = analysis.BufferDiff

Re-export main types from internal packages

type BufferLifecycle

type BufferLifecycle = analysis.BufferLifecycle

Re-export main types from internal packages

type BufferMetadata

type BufferMetadata = analysis.BufferMetadata

Re-export main types from internal packages

type BufferSizeInfo

type BufferSizeInfo = analysis.BufferSizeInfo

Buffer diff types (gputrace-95)

type BufferTimelineAnalysis

type BufferTimelineAnalysis = analysis.BufferTimelineAnalysis

Buffer timeline types (gputrace-94)

type BufferTimelineEvent

type BufferTimelineEvent = analysis.BufferTimelineEvent

Re-export main types from internal packages

type CommandBuffer

type CommandBuffer = trace.CommandBuffer

Re-export main types from internal packages

type CommandBufferCalls

type CommandBufferCalls = trace.CommandBufferCalls

Re-export main types from internal packages

type CommandBufferTiming

type CommandBufferTiming = timing.CommandBufferTiming

Re-export main types from internal packages

type CommandQueueInfo

type CommandQueueInfo = replay.CommandQueueInfo

Re-export main types from internal packages

type ComputeEncoder

type ComputeEncoder = trace.ComputeEncoder

Re-export main types from internal packages

type CorrelatedShaderMetrics

type CorrelatedShaderMetrics = shader.CorrelatedShaderMetrics

Correlation types (gputrace-96)

type CounterSamplingConfig

type CounterSamplingConfig = counter.CounterSamplingConfig

Counter sampling types (gputrace-104)

type CounterSamplingResult

type CounterSamplingResult = counter.CounterSamplingResult

Re-export main types from internal packages

type CounterSamplingSimulation

type CounterSamplingSimulation = replay.CounterSamplingSimulation

Re-export main types from internal packages

type CountersCSVExporter

type CountersCSVExporter = counter.CountersCSVExporter

Counter export types (gputrace-101)

type EncoderAccessInfo

type EncoderAccessInfo = analysis.EncoderAccessInfo

Re-export main types from internal packages

type EncoderProfile

type EncoderProfile = counter.EncoderProfile

Re-export main types from internal packages

type EncoderTiming

type EncoderTiming = trace.EncoderTiming

Re-export main types from internal packages

type EncoderTimingInfo

type EncoderTimingInfo = counter.EncoderTimingInfo

Encoder timing from profiler data (streamData plist)

func ExtractEncoderTimingsFromProfiler

func ExtractEncoderTimingsFromProfiler(t *Trace) ([]EncoderTimingInfo, int, error)

ExtractEncoderTimingsFromProfiler extracts real timing data from .gpuprofiler_raw streamData. Returns per-encoder timing info, total time in microseconds, and any error.

type FormattedAPICall

type FormattedAPICall = trace.FormattedAPICall

Re-export main types from internal packages

type GPRWCNTRTimestamp

type GPRWCNTRTimestamp = counter.GPRWCNTRTimestamp

Re-export main types from internal packages

type InitCall

type InitCall = trace.InitCall

Re-export main types from internal packages

type InsightSeverity

type InsightSeverity = analysis.InsightSeverity

Re-export main types from internal packages

type InsightType

type InsightType = analysis.InsightType

Re-export main types from internal packages

type InsightsReport

type InsightsReport = analysis.InsightsReport

Re-export main types from internal packages

type KernelStat

type KernelStat = trace.KernelStat

Kernel analysis types

type KernelTiming

type KernelTiming = timing.KernelTiming

Re-export main types from internal packages

type Metadata

type Metadata = trace.Metadata

Re-export main types from internal packages

type PerfCounterStats

type PerfCounterStats = counter.PerfCounterStats

Re-export main types from internal packages

type PerformanceInsight

type PerformanceInsight = analysis.PerformanceInsight

Insights types (gputrace-97)

type PipelineFunctionMap

type PipelineFunctionMap = trace.PipelineFunctionMap

Pipeline function mapping types

type PipelineStats

type PipelineStats = counter.PipelineStats

PipelineStats contains shader compilation statistics from streamData.

type ProfilerRawTiming

type ProfilerRawTiming = timing.ProfilerRawTiming

Re-export main types from internal packages

type RecordType

type RecordType = trace.RecordType

Re-export main types from internal packages

type ReplayCommand

type ReplayCommand = replay.ReplayCommand

Re-export main types from internal packages

type ReplayEncoderInfo

type ReplayEncoderInfo = replay.ReplayEncoderInfo

Re-export main types from internal packages

type ReplayEngine

type ReplayEngine = replay.ReplayEngine

Replay engine types (gputrace-103, gputrace-104)

type ReplayPlan

type ReplayPlan = replay.ReplayPlan

Re-export main types from internal packages

type ReplayValidation

type ReplayValidation = replay.ReplayValidation

Re-export main types from internal packages

type ShaderCorrelationReport

type ShaderCorrelationReport = shader.ShaderCorrelationReport

Re-export main types from internal packages

type ShaderHardwareMetrics

type ShaderHardwareMetrics = counter.ShaderHardwareMetrics

Re-export main types from internal packages

type ShaderMetrics

type ShaderMetrics = shader.ShaderMetrics

Re-export main types from internal packages

type ShaderMetricsReport

type ShaderMetricsReport = shader.ShaderMetricsReport

Re-export main types from internal packages

type ShaderSourceAttribution

type ShaderSourceAttribution = shader.ShaderSourceAttribution

Shader source attribution types (gputrace-105)

type ShaderSourceMapper

type ShaderSourceMapper = shader.ShaderSourceMapper

Re-export main types from internal packages

type SourceLineAttribution

type SourceLineAttribution = shader.SourceLineAttribution

Re-export main types from internal packages

type Store0Encoder

type Store0Encoder = timing.Store0Encoder

Re-export main types from internal packages

type Store0TimingData

type Store0TimingData = timing.Store0TimingData

Re-export main types from internal packages

type StreamDataStats

type StreamDataStats = counter.StreamDataStats

StreamDataStats contains all parsed statistics from streamData.

func ExtractPipelineStats

func ExtractPipelineStats(t *Trace) (*StreamDataStats, error)

ExtractPipelineStats extracts pipeline compilation stats from .gpuprofiler_raw streamData. This provides instruction counts, register allocation, and other compilation metrics.

type TimelineInfo

type TimelineInfo = counter.TimelineInfo

APSTimelineData types (gputrace-new)

type TimingComparison

type TimingComparison = timing.TimingComparison

Re-export main types from internal packages

type TimingExtractorProfilerRaw

type TimingExtractorProfilerRaw = timing.TimingExtractorProfilerRaw

Timing profiler types (gputrace-107)

type TimingMetrics

type TimingMetrics = timing.TimingMetrics

Timing metrics types (gputrace-106)

type TimingMetricsExtractor

type TimingMetricsExtractor = timing.TimingMetricsExtractor

Re-export main types from internal packages

type TimingStat

type TimingStat = trace.TimingStat

Re-export main types from internal packages

type Trace

type Trace = trace.Trace

Re-export main types from internal packages

func Open

func Open(path string) (*Trace, error)

Open opens and parses a .gputrace bundle.

type TraceStatistics

type TraceStatistics = analysis.TraceStatistics

Re-export main types from internal packages

type XcodeCounterData

type XcodeCounterData = counter.XcodeCounterData

Re-export main types from internal packages

type XcodeEncoderCounters

type XcodeEncoderCounters = counter.XcodeEncoderCounters

Re-export main types from internal packages

Directories

Path Synopsis
cmd
axperms command
axperms is a utility to check and manage Accessibility permissions on macOS.
axperms is a utility to check and manage Accessibility permissions on macOS.
gputrace command
Command gputrace provides tools for analyzing and converting GPU trace files.
Command gputrace provides tools for analyzing and converting GPU trace files.
gputrace/cmd
Package cmd implements the gputrace CLI commands.
Package cmd implements the gputrace CLI commands.
mlxprof command
examples
source_mapping command
internal
agxps
Package agxps provides a small adapter over github.com/tmc/apple/private/xcode/gtshaderprofiler.
Package agxps provides a small adapter over github.com/tmc/apple/private/xcode/gtshaderprofiler.
buildinfo
Package buildinfo exposes build metadata for release binaries.
Package buildinfo exposes build metadata for release binaries.
graph
Package graph provides graph visualization generation for GPU traces.
Package graph provides graph visualization generation for GPU traces.
osa
Package osa provides in-process AppleScript execution via CGO.
Package osa provides in-process AppleScript execution via CGO.
trace
Package gputrace provides parsing for .gputrace GPU trace files from Metal.
Package gputrace provides parsing for .gputrace GPU trace files from Metal.
pkg
axuiautomation
Package axuiautomation is a compatibility shim.
Package axuiautomation is a compatibility shim.
axuiautomation/cmd/axperms command
Command axperms automates granting accessibility permissions.
Command axperms automates granting accessibility permissions.
axuiautomation/cmd/axui command
Command axui is a CLI for macOS accessibility UI automation.
Command axui is a CLI for macOS accessibility UI automation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL