Documentation
¶
Overview ¶
Package gputrace parses Metal .gputrace bundles.
A .gputrace file is a directory bundle containing Metal GPU capture data. Use Open to read a bundle:
trace, err := gputrace.Open("mytrace.gputrace")
if err != nil {
log.Fatal(err)
}
The returned Trace contains the parsed metadata, capture data, command buffers, timing data, counters, and shaders.
The command-line tool is in cmd/gputrace.
Index ¶
- Constants
- Variables
- func CompareBuffers(info1, info2 *analysis.BufferSizeInfo) *analysis.BufferDiff
- func CompareTraces(baseline, current *TimingMetrics) *timing.TimingComparison
- func CorrelateShaderMetrics(t *Trace) (*shader.ShaderCorrelationReport, error)
- func DumpCommandBuffer(t *Trace, w io.Writer, cbIndex int) error
- func ExportShaderMetricsCSV(w io.Writer, report *ShaderMetricsReport) error
- func ExportShaderMetricsJSON(w io.Writer, report *ShaderMetricsReport) error
- func ExportTimingMetricsCSV(w io.Writer, metrics *TimingMetrics) error
- func ExportTimingMetricsJSON(w io.Writer, metrics *TimingMetrics) error
- func ExtractBufferSizes(t *Trace) (*analysis.BufferSizeInfo, error)
- func ExtractShaderSourceAttribution(t *Trace, shaderName string) (*shader.ShaderSourceAttribution, error)
- func ExtractStore0Timing(t *Trace) (*timing.Store0TimingData, error)
- func FormatBufferAccessReport(a *BufferAccessAnalysis, verbose bool) string
- func FormatBufferDiff(diff *analysis.BufferDiff, trace1Path, trace2Path string) string
- func FormatBufferTimelineASCII(a *BufferTimelineAnalysis, width int) string
- func FormatBufferTimelineSummary(a *BufferTimelineAnalysis) string
- func FormatCorrelationReport(report *shader.ShaderCorrelationReport) string
- func FormatCounterSamplingResult(result *counter.CounterSamplingResult) string
- func FormatCounterSamplingSimulation(sim *replay.CounterSamplingSimulation) string
- func FormatInsightsReport(report *InsightsReport) string
- func FormatShaderSourceAttribution(attr *shader.ShaderSourceAttribution, showHints bool) string
- func FormatShaderSourceAttributionHTML(attr *shader.ShaderSourceAttribution) string
- func FormatShadersSimple(w io.Writer, report *ShaderMetricsReport) error
- func FormatShadersXcodeStyle(w io.Writer, report *ShaderMetricsReport, t *Trace, showEstimates bool) error
- func FormatTimingComparison(comp *timing.TimingComparison) string
- func FormatTimingMetrics(metrics *TimingMetrics) string
- func NewCountersCSVExporter(t *Trace) *counter.CountersCSVExporter
- func NewReplayEngine(t *Trace) *replay.ReplayEngine
- func NewTimingExtractorProfilerRaw(t *Trace) *timing.TimingExtractorProfilerRaw
- func ParseDetailedCommandBuffer(t *Trace, cbIndex int) (*command.DetailedCommandBuffer, error)
- func ToPprof(t *Trace, timings []*EncoderTiming) (*profile.Profile, error)
- func ToPprofWithMetrics(t *Trace, mapper *ShaderSourceMapper, stats *PerfCounterStats) (*profile.Profile, error)
- func ToPprofWithSource(t *Trace, timings []*EncoderTiming, mapper *ShaderSourceMapper) (*profile.Profile, error)
- type APICallList
- type BufferAccessAnalysis
- type BufferAccessInfo
- type BufferAlias
- type BufferLifecycle
- type BufferTimelineAnalysis
- type CommandBuffer
- type CommandBufferCalls
- type CommandBufferTiming
- type ComputeEncoder
- type CounterSamplingConfig
- type EncoderAccessInfo
- type EncoderTiming
- type EncoderTimingInfo
- type FormattedAPICall
- type InitCall
- type InsightSeverity
- type InsightType
- type InsightsReport
- type KernelStat
- type KernelTiming
- type Metadata
- type PerfCounterStats
- type PerformanceInsight
- type PipelineStats
- type RecordType
- type ShaderHardwareMetrics
- type ShaderMetrics
- type ShaderMetricsReport
- type ShaderSourceMapper
- type StreamDataStats
- type TimingMetrics
- type TimingMetricsExtractor
- type TimingStat
- type Trace
- type TraceStatistics
- type XcodeCounterData
- type XcodeEncoderCounters
Examples ¶
Constants ¶
const ( RecordTypeCommand = trace.RecordTypeCommand RecordTypeString = trace.RecordTypeString RecordTypeFunction = trace.RecordTypeFunction RecordTypeInteger = trace.RecordTypeInteger RecordTypeUnsignedLong = trace.RecordTypeUnsignedLong )
Re-export constants
const ( MagicMTSP = trace.MagicMTSP MagicXDIC = trace.MagicXDIC MagicBPList = trace.MagicBPList )
Re-export magic constants
const ( InsightBottleneck = analysis.InsightBottleneck InsightOptimization = analysis.InsightOptimization InsightAntiPattern = analysis.InsightAntiPattern InsightInfo = analysis.InsightInfo )
Re-export insight type constants (gputrace-97)
const ( SeverityCritical = analysis.SeverityCritical SeverityHigh = analysis.SeverityHigh SeverityMedium = analysis.SeverityMedium SeverityLow = analysis.SeverityLow SeverityInfo = analysis.SeverityInfo )
Re-export insight severity constants (gputrace-97)
Variables ¶
var ( ErrInvalidTrace = trace.ErrInvalidTrace ErrInvalidMagic = trace.ErrInvalidMagic ErrMissingMetadata = trace.ErrMissingMetadata )
Re-export errors
Functions ¶
func CompareBuffers ¶
func CompareBuffers(info1, info2 *analysis.BufferSizeInfo) *analysis.BufferDiff
CompareBuffers compares two sets of buffer size information.
func CompareTraces ¶
func CompareTraces(baseline, current *TimingMetrics) *timing.TimingComparison
CompareTraces compares baseline and current timing metrics.
func CorrelateShaderMetrics ¶
func CorrelateShaderMetrics(t *Trace) (*shader.ShaderCorrelationReport, error)
CorrelateShaderMetrics correlates shader metrics for t.
func DumpCommandBuffer ¶
DumpCommandBuffer writes command buffer cbIndex from t to w.
func ExportShaderMetricsCSV ¶
func ExportShaderMetricsCSV(w io.Writer, report *ShaderMetricsReport) error
ExportShaderMetricsCSV writes shader metrics as CSV.
func ExportShaderMetricsJSON ¶
func ExportShaderMetricsJSON(w io.Writer, report *ShaderMetricsReport) error
ExportShaderMetricsJSON writes shader metrics as JSON.
func ExportTimingMetricsCSV ¶
func ExportTimingMetricsCSV(w io.Writer, metrics *TimingMetrics) error
ExportTimingMetricsCSV writes timing metrics as CSV.
func ExportTimingMetricsJSON ¶
func ExportTimingMetricsJSON(w io.Writer, metrics *TimingMetrics) error
ExportTimingMetricsJSON writes timing metrics as JSON.
func ExtractBufferSizes ¶
func ExtractBufferSizes(t *Trace) (*analysis.BufferSizeInfo, error)
ExtractBufferSizes extracts buffer size information from t.
func ExtractShaderSourceAttribution ¶
func ExtractShaderSourceAttribution(t *Trace, shaderName string) (*shader.ShaderSourceAttribution, error)
ExtractShaderSourceAttribution extracts source attribution for shaderName.
func ExtractStore0Timing ¶
func ExtractStore0Timing(t *Trace) (*timing.Store0TimingData, error)
ExtractStore0Timing extracts timing data from the store0 capture stream.
func FormatBufferAccessReport ¶
func FormatBufferAccessReport(a *BufferAccessAnalysis, verbose bool) string
FormatBufferAccessReport formats a buffer access report.
func FormatBufferDiff ¶
func FormatBufferDiff(diff *analysis.BufferDiff, trace1Path, trace2Path string) string
FormatBufferDiff formats a buffer comparison.
func FormatBufferTimelineASCII ¶
func FormatBufferTimelineASCII(a *BufferTimelineAnalysis, width int) string
FormatBufferTimelineASCII formats a buffer timeline with the given width.
func FormatBufferTimelineSummary ¶
func FormatBufferTimelineSummary(a *BufferTimelineAnalysis) string
FormatBufferTimelineSummary formats a buffer timeline summary.
func FormatCorrelationReport ¶
func FormatCorrelationReport(report *shader.ShaderCorrelationReport) string
FormatCorrelationReport formats a shader correlation report.
func FormatCounterSamplingResult ¶
func FormatCounterSamplingResult(result *counter.CounterSamplingResult) string
FormatCounterSamplingResult formats a counter sampling result.
func FormatCounterSamplingSimulation ¶
func FormatCounterSamplingSimulation(sim *replay.CounterSamplingSimulation) string
FormatCounterSamplingSimulation formats a counter sampling simulation.
func FormatInsightsReport ¶
func FormatInsightsReport(report *InsightsReport) string
FormatInsightsReport formats a performance insights report.
func FormatShaderSourceAttribution ¶
func FormatShaderSourceAttribution(attr *shader.ShaderSourceAttribution, showHints bool) string
FormatShaderSourceAttribution formats shader source attribution.
func FormatShaderSourceAttributionHTML ¶
func FormatShaderSourceAttributionHTML(attr *shader.ShaderSourceAttribution) string
FormatShaderSourceAttributionHTML formats shader source attribution as HTML.
func FormatShadersSimple ¶
func FormatShadersSimple(w io.Writer, report *ShaderMetricsReport) error
FormatShadersSimple writes a simple shader report to w.
func FormatShadersXcodeStyle ¶
func FormatShadersXcodeStyle(w io.Writer, report *ShaderMetricsReport, t *Trace, showEstimates bool) error
FormatShadersXcodeStyle writes an Xcode-style shader report to w.
func FormatTimingComparison ¶
func FormatTimingComparison(comp *timing.TimingComparison) string
FormatTimingComparison formats a timing comparison.
func FormatTimingMetrics ¶
func FormatTimingMetrics(metrics *TimingMetrics) string
FormatTimingMetrics formats timing metrics.
func NewCountersCSVExporter ¶
func NewCountersCSVExporter(t *Trace) *counter.CountersCSVExporter
NewCountersCSVExporter returns a counter CSV exporter for t.
func NewReplayEngine ¶
func NewReplayEngine(t *Trace) *replay.ReplayEngine
NewReplayEngine returns a replay engine for t.
func NewTimingExtractorProfilerRaw ¶
func NewTimingExtractorProfilerRaw(t *Trace) *timing.TimingExtractorProfilerRaw
NewTimingExtractorProfilerRaw returns a raw profiler timing extractor for t.
func ParseDetailedCommandBuffer ¶
func ParseDetailedCommandBuffer(t *Trace, cbIndex int) (*command.DetailedCommandBuffer, error)
ParseDetailedCommandBuffer parses command buffer cbIndex from t.
func ToPprof ¶
func ToPprof(t *Trace, timings []*EncoderTiming) (*profile.Profile, error)
ToPprof converts timing data to a pprof profile.
func ToPprofWithMetrics ¶
func ToPprofWithMetrics(t *Trace, mapper *ShaderSourceMapper, stats *PerfCounterStats) (*profile.Profile, error)
ToPprofWithMetrics converts counter metrics to a pprof profile.
func ToPprofWithSource ¶
func ToPprofWithSource(t *Trace, timings []*EncoderTiming, mapper *ShaderSourceMapper) (*profile.Profile, error)
ToPprofWithSource converts timing data and source mappings to a pprof profile.
Types ¶
type BufferAccessAnalysis ¶
type BufferAccessAnalysis = analysis.BufferAccessAnalysis
Buffer access analysis types (gputrace-93)
func AnalyzeBufferAccess ¶
func AnalyzeBufferAccess(t *Trace) (*BufferAccessAnalysis, error)
AnalyzeBufferAccess analyzes buffer access in t.
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 BufferLifecycle ¶
type BufferLifecycle = analysis.BufferLifecycle
Re-export main types from internal packages
type BufferTimelineAnalysis ¶
type BufferTimelineAnalysis = analysis.BufferTimelineAnalysis
Buffer timeline types (gputrace-94)
func ExtractBufferTimeline ¶
func ExtractBufferTimeline(t *Trace) (*BufferTimelineAnalysis, error)
ExtractBufferTimeline extracts the buffer timeline from t.
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 ComputeEncoder ¶
type ComputeEncoder = trace.ComputeEncoder
Re-export main types from internal packages
type CounterSamplingConfig ¶
type CounterSamplingConfig = counter.CounterSamplingConfig
Counter sampling types (gputrace-104)
type EncoderAccessInfo ¶
type EncoderAccessInfo = analysis.EncoderAccessInfo
Re-export main types from internal packages
type EncoderTiming ¶
type EncoderTiming = trace.EncoderTiming
Re-export main types from internal packages
func ConvertStore0ToEncoderTimings ¶
func ConvertStore0ToEncoderTimings(t *Trace, store0Data *timing.Store0TimingData) []*EncoderTiming
ConvertStore0ToEncoderTimings converts store0 timing data to encoder timings.
func ExtractTimingData ¶
func ExtractTimingData(t *Trace) ([]*EncoderTiming, error)
ExtractTimingData extracts encoder timing data from t.
func GenerateSyntheticTiming ¶
func GenerateSyntheticTiming(t *Trace) []*EncoderTiming
GenerateSyntheticTiming generates synthetic timing data for t.
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 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
func GenerateInsights ¶
func GenerateInsights(t *Trace) (*InsightsReport, error)
GenerateInsights generates performance insights for t.
type KernelTiming ¶
type KernelTiming = timing.KernelTiming
Re-export main types from internal packages
type PerfCounterStats ¶
type PerfCounterStats = counter.PerfCounterStats
Re-export main types from internal packages
func ParsePerfCounters ¶
func ParsePerfCounters(t *Trace) (*PerfCounterStats, error)
ParsePerfCounters parses performance counters from t.
type PerformanceInsight ¶
type PerformanceInsight = analysis.PerformanceInsight
Insights types (gputrace-97)
type PipelineStats ¶
type PipelineStats = counter.PipelineStats
PipelineStats contains shader compilation statistics from streamData.
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
func ExtractShaderMetrics ¶
func ExtractShaderMetrics(t *Trace) (*ShaderMetricsReport, error)
ExtractShaderMetrics extracts shader metrics from t.
type ShaderSourceMapper ¶
type ShaderSourceMapper = shader.ShaderSourceMapper
Re-export main types from internal packages
func NewShaderSourceMapper ¶
func NewShaderSourceMapper(searchPaths ...string) *ShaderSourceMapper
NewShaderSourceMapper returns a source mapper that searches searchPaths.
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 TimingMetricsExtractor ¶
type TimingMetricsExtractor = timing.TimingMetricsExtractor
Re-export main types from internal packages
func NewTimingMetricsExtractor ¶
func NewTimingMetricsExtractor(t *Trace) *TimingMetricsExtractor
NewTimingMetricsExtractor returns a timing metrics extractor for t.
type Trace ¶
Re-export main types from internal packages
func Open ¶
Open opens and parses a .gputrace bundle.
Example ¶
package main
import (
"fmt"
"os"
"path/filepath"
)
func main() {
dir, err := os.MkdirTemp("", "gputrace-example-*")
if err != nil {
fmt.Println(err)
return
}
defer os.RemoveAll(dir)
tracePath := filepath.Join(dir, "minimal.gputrace")
if err := writeMinimalTraceBundle(tracePath); err != nil {
fmt.Println(err)
return
}
trace, err := Open(tracePath)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(trace.Metadata.UUID)
fmt.Println(len(trace.CaptureData))
}
func writeMinimalTraceBundle(path string) error {
if err := os.Mkdir(path, 0o777); err != nil {
return err
}
if err := os.WriteFile(filepath.Join(path, "metadata"), []byte(minimalMetadataPlist), 0o666); err != nil {
return err
}
return os.WriteFile(filepath.Join(path, "capture"), []byte(MagicMTSP), 0o666)
}
const minimalMetadataPlist = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>(uuid)</key>
<string>minimal-test-trace</string>
<key>DYCaptureSession.capture_version</key>
<integer>1</integer>
<key>DYCaptureSession.graphics_api</key>
<integer>1</integer>
<key>DYCaptureSession.deviceId</key>
<integer>0</integer>
<key>DYCaptureSession.nativePointerSize</key>
<integer>8</integer>
<key>DYCaptureEngine.captured_frames_count</key>
<integer>1</integer>
</dict>
</plist>
`
Output: minimal-test-trace 4
type TraceStatistics ¶
type TraceStatistics = analysis.TraceStatistics
Re-export main types from internal packages
func ExtractStatistics ¶
func ExtractStatistics(t *Trace) (*TraceStatistics, error)
ExtractStatistics extracts summary statistics from t.
type XcodeCounterData ¶
type XcodeCounterData = counter.XcodeCounterData
Re-export main types from internal packages
func ParseXcodeCountersCSV ¶
func ParseXcodeCountersCSV(t *Trace, csvPath string) (*XcodeCounterData, error)
ParseXcodeCountersCSV parses an Xcode counters CSV file for t.
type XcodeEncoderCounters ¶
type XcodeEncoderCounters = counter.XcodeEncoderCounters
Re-export main types from internal packages
Source Files
¶
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. |
|
fmtutil
Package fmtutil provides small formatting helpers shared by internal packages.
|
Package fmtutil provides small formatting helpers shared by internal packages. |
|
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. |
|
profilerraw
Package profilerraw reads records from Xcode GPU profiler counter files.
|
Package profilerraw reads records from Xcode GPU profiler counter files. |
|
trace
Package gputrace provides parsing for .gputrace GPU trace files from Metal.
|
Package gputrace provides parsing for .gputrace GPU trace files from Metal. |
|
xcodebindings
Package xcodebindings probes the private Xcode GTShaderProfiler runtime surface without constructing profiler objects.
|
Package xcodebindings probes the private Xcode GTShaderProfiler runtime surface without constructing profiler objects. |