Metal GPU Trace

v0.33.0
io.github.partprogramming09/metal-gpu-trace Checked 3 days ago Published 8 days ago

Measure Wine and macOS GPU use on Apple silicon (Metal System Trace) and Windows (PresentMon)

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

perf_record Record a program

Records `program` (an .exe under Wine, or a macOS binary with wine="native") or a test `workload` for `seconds` with Metal System Trace and returns its summary: GPU ms per frame, frame intervals, FPS, Metal and resident memory. It then stops every program of that Wine prefix (wineserver -k), or with native the program it launched and its children. tier sets memory and counters together; compare recordings of the same tier.

ParameterTypeDescription
label *stringrun name: letters, digits, '.', '_', '-'
apistringwith workload: mtl, mtl-x64 (Metal under Rosetta), vk (needs METAL_TRACE_MOLTENVK), d3d11 or d3d12 (under wine)
argsstringprogram arguments as in a shell
backgroundbooleanmacOS, default false; true throttles the program hard and unevenly (taskpolicy -b): repeat the run
countersbooleandefault false; true adds gpu_counters; not on Windows; about 40 s of read-back per second
dimintegerwith drawstress: cube grid side, dim^3 draws per frame
envstringNAME=VALUE pairs separated by spaces; MTL_SHADER_VALIDATION=1 or MTL_DEBUG_LAYER=1 adds `validation`
examplestringwith a workload that lists examples: the one to run
fieldsarrayresult paths to keep, dotted: common.frame_pacing
fingerprint_pathsarrayfiles to hash into the summary; compare shows changes
memorybooleandefault true; false skips the slowest table, Metal memory (no metal_mib_peak)
memory_free_pctintegermacOS, 20 to 60: holds the whole Mac at this % RAM free while recording; lower can freeze it
prefixstringWine prefix, default WINEPREFIX or ~/.wine; ignored with native
programstringpath of the .exe, or of the macOS binary with wine=native
secondsintegerseconds, default 20; 30 under Wine (start-up eats part); the export takes minutes under Wine
sizestringwith drawstress: window size, such as 1920x1080
tierstringdefault standard. light: no memory or counters; standard: memory; deep: also counters and a kept .trace (macOS). memory and counters given alone override
winestringWine directory holding bin/wine, or native
workdirstringdirectory to start in, default the program's own
workloadstringa test program from workload_list (fetch it first) instead of program

perf_baseline_record Record a reference

Records the same program `count` times with perf_record's arguments and saves the runs as the reference `name` for perf_check, returning the range each number spans. Runs are `name`-1, `name`-2, ... Each takes its seconds plus about a minute of read-back.

ParameterTypeDescription
name *stringname: letters, digits, '.', '_', '-'
apistring
argsstring
backgroundboolean
cooldown_snumberseconds to rest between recordings, 0 to 600, default 0; 60 on a laptop is a start, thermal_state_share says if it throttled
countintegerequal recordings to make, default 3
countersboolean
diminteger
envstring
examplestring
fieldsarrayresult paths to keep, dotted: common.frame_pacing
memoryboolean
memory_free_pctinteger
prefixstring
programstring
secondsinteger
sizestring
skip_snumberseconds to leave out at the start (shaders compile, resources load), default 0; GPU numbers, hitches and Metal memory are recomputed without them; perf_check applies the same cut
tierstring
winestring
workdirstring
workloadstring

perf_sweep Record one run per value of a variable

Records the same program once per value of one variable and returns, per value, the median FPS, 1 % low, GPU ms per frame and stutter; with 3 or more numeric values also the line GPU ms follows (fixed ms plus ms per unit) with its r2. With rounds above 1 the values run in reverse every other round, so drift hits all alike. Runs are `name`-<value number>-r<round>; each takes its seconds plus about a minute of read-back. `metric` app_metrics.<column> adds that telemetry column per value, with a fit.

ParameterTypeDescription
name *stringname: letters, digits, '.', '_', '-'
values *array2 to 8 values of the variable, such as [10, 20, 30] for dim
variable *stringwhat changes: dim, example, api, size, or env:NAME
apistring
argsstring
backgroundboolean
cooldown_snumberseconds to rest between recordings, 0 to 600, default 0; 60 on a laptop is a start, thermal_state_share says if it throttled
countersboolean
diminteger
envstring
examplestring
fieldsarrayresult paths to keep, dotted: common.frame_pacing
memoryboolean
memory_free_pctinteger
metricstringapp_metrics.<column>, a column of the program's telemetry
prefixstring
programstring
roundsintegerdefault 1, at most 5 and 24 recordings in all
secondsinteger
sizestring
skip_snumberseconds to leave out at the start (shaders compile, resources load), default 0; GPU numbers, hitches and Metal memory are recomputed without them
tierstring
winestring
workdirstring
workloadstring

perf_ab Record two settings in A B B A order

Records the same program with two environments in the order A B B A (`rounds` times) and says per metric whether B is better, worse or the same as A, with every value behind it. Runs are `name`-a1, `name`-b1, ... Each takes its seconds plus about a minute of read-back. `fingerprint_paths` stops it before the next recording if one of those files changed.

ParameterTypeDescription
env_a *stringNAME=VALUE pairs for side A, the reference (empty: none)
env_b *stringNAME=VALUE pairs for side B, the change under test (empty: none)
name *stringname: letters, digits, '.', '_', '-'
apistring
argsstring
backgroundboolean
cooldown_snumberseconds to rest between recordings, 0 to 600, default 0; 60 on a laptop is a start, thermal_state_share says if it throttled
countersboolean
diminteger
examplestring
fieldsarrayresult paths to keep, dotted: common.frame_pacing
fingerprint_pathsarrayfiles to hash into the summary; compare shows changes
memoryboolean
memory_free_pctinteger
prefixstring
programstring
roundsintegerA B B A rounds, default 1 (4 recordings), at most 5
secondsinteger
sizestring
skip_snumberseconds to leave out at the start (shaders compile, resources load), default 0; GPU numbers, hitches and Metal memory are recomputed without them
tierstring
winestring
workdirstring
workloadstring

perf_cold_warm Record a run twice to find first-seen shader stutter

Records the same program twice and says what the first run suffers that the second does not: shader-compile hitches (first minus second, never below 0), each run's hitch count and compiler time. macOS only. Runs are `name`-first and `name`-second.

ParameterTypeDescription
name *stringname: letters, digits, '.', '_', '-'
apistring
argsstring
backgroundboolean
countersboolean
diminteger
envstring
examplestring
fieldsarrayresult paths to keep, dotted: common.frame_pacing
memoryboolean
memory_free_pctinteger
prefixstring
programstring
secondsinteger
sizestring
tierstring
winestring
workdirstring
workloadstring

perf_attach Record a running program

Records a program that is already running, by pid or by a name in its command line, for `seconds`, and returns perf_record's summary; the program keeps running. For games from Steam, CrossOver or any launcher: start the game first.

ParameterTypeDescription
label *stringname: letters, digits, '.', '_', '-'
process *stringpid, or a name in the program's command line such as Game.exe
fieldsarrayresult paths to keep, dotted: common.frame_pacing
secondsintegerrecording length, default 20

project_info Show the active project

Says which project is active: its name, baseline and format, the folder its recordings go to and where that folder comes from (the project file, METAL_TRACE_OUT or the default ./perf-runs). Without a project file, project and baseline are null.

ParameterTypeDescription
fieldsarrayresult paths to keep, dotted: common.frame_pacing

perf_runs List recordings

Lists the saved recordings, newest first, with frames, FPS, GPU ms per frame, memory peaks and the translation layer each ran on; project names the project they belong to.

ParameterTypeDescription
fieldsarrayresult paths to keep, dotted: common.frame_pacing
limitintegerdefault 50, at most 500
offsetintegerdefault 0

perf_compare Compare two recordings

Compares two saved recordings, a the reference and b the run after a change: headline numbers (FPS, GPU ms, frame pacing, memory), then the GPU work: encoders and command buffers per frame, share of short encoders, idle time, and each encoder label's change, largest first. `layer` says whether both ran on the same translation layer; `measure` marks Windows against Metal (use FPS, lows, stutter, jitter); runs under 100 frames are flagged. `screen`, `noisy_environment` flag runs that do not compare; `suggested_actions` says what to call next.

ParameterTypeDescription
a *stringrun name from perf_runs: the reference, such as the run before a change
b *stringrun name from perf_runs: the run to compare against a
fieldsarrayresult paths to keep, dotted: common.frame_pacing
markdownbooleanalso return the numbers as Markdown tables, default false
short_usintegeran encoder under this GPU time counts as short: 10, 25 (default), 50, 100, 250, 500 or 1000
skip_snumberseconds to leave out at the start (shaders compile, resources load), default 0; GPU numbers, hitches and Metal memory are recomputed without them

perf_baseline Name a reference

Names a reference for perf_check, or lists them. With name and runs (equal runs of one program) it saves their summaries as the reference, replacing a previous one, and returns each number's range and `spread_pct`: the noise a change must exceed. With name alone it shows that reference; with nothing it lists them.

ParameterTypeDescription
fieldsarrayresult paths to keep, dotted: common.frame_pacing
namestringreference name; alone, shows that reference
runsarrayrun names to save as this reference, ideally 3 or more equal runs
skip_snumberseconds to leave out at the start (shaders compile, resources load), default 0; GPU numbers, hitches and Metal memory are recomputed without them; perf_check applies the same cut

perf_check Check a run against a reference

Judges a recording against a reference from perf_baseline: regressed when FPS falls under the reference's lowest, or GPU ms per frame rises over its highest, by more than margin_pct, or encoders or command buffers per frame exceed its highest; improved when a number leaves the range the other way and none regressed; same otherwise. Windows against Metal is judged on FPS alone. Returns the reasons and perf_compare's comparison.

ParameterTypeDescription
baseline *stringa reference name from perf_baseline
run *stringa run name from perf_runs
fieldsarrayresult paths to keep, dotted: common.frame_pacing
margin_pctnumberhow far outside the reference's range FPS or GPU ms per frame may fall before counting, default 3

perf_export_trace Export frames to Perfetto

Writes a recording's GPU frames as `<run>.chrome-trace` in the runs directory, for ui.perfetto.dev and chrome://tracing: one slice per GPU frame. Returns the file name and the number of frames.

ParameterTypeDescription
run *stringa run name from perf_runs
fieldsarrayresult paths to keep, dotted: common.frame_pacing

perf_gate Check a run against budgets

Checks a recording against budgets and says pass or fail: FPS and 1% low floors, ceilings for stutter rate, p95 GPU ms per frame, hitches and peak Metal MiB. Give at least one. A number the recording lacks fails its budget (value null), and so does a run that stopped presenting (`unpresented`). Returns each budget with its limit, value and whether it held.

ParameterTypeDescription
run *stringa run name from perf_runs
fieldsarrayresult paths to keep, dotted: common.frame_pacing
fps_1pct_low_minnumberthe 1% low FPS must be at least this
fps_minnumberthe FPS must be at least this
gpu_ms_p95_maxnumberthe p95 GPU ms per frame at most this
hitches_maxnumberthe number of hitches at most this
metal_mib_maxnumberthe peak Metal memory in MiB at most this
skip_snumberseconds to leave out at the start (shaders compile, resources load), default 0; GPU numbers, hitches and Metal memory are recomputed without them
stutter_rate_pct_maxnumberthe share of stutter frames, in %, at most this

perf_history Follow a number across runs

Lists the recordings whose name starts with `prefix`, oldest first, with FPS, 1% low, GPU ms, stutter, hitches and peak Metal MiB, and the change from first to last. A trend is real only above the spread_pct of perf_baseline. Windows and Metal runs in one series are flagged.

ParameterTypeDescription
prefix *stringthe start of the run names to follow: letters, digits, '.', '_', '-'
fieldsarrayresult paths to keep, dotted: common.frame_pacing
limitintegernewest runs to keep, default 50
skip_snumberseconds to leave out at the start (shaders compile, resources load), default 0; GPU numbers, hitches and Metal memory are recomputed without them

perf_diagnose Diagnose encoder use

Says whether a saved recording splits its GPU work into too many short encoders (the pattern of translation layers such as DXMT, Mullion or MoltenVK), with the numbers: encoders and command buffers per frame, share of short encoders, labels with the most GPU time, idle time (read with the FPS: vsync idles too). `suggested_actions` says what to call next.

ParameterTypeDescription
run *stringa run name from perf_runs
fieldsarrayresult paths to keep, dotted: common.frame_pacing
min_encodersintegerencoders per frame (median) from which the verdict can be yes, default 4
short_sharenumbershare of short encoders from which the verdict is yes, default 0.25
short_usintegeran encoder under this GPU time counts as short: 10, 25 (default), 50, 100, 250, 500 or 1000

perf_memory_breakdown Break down Metal allocations by type

Breaks down the Metal allocations of a saved recording by type (texture, buffer, heap...): allocated, still live and `gone` per type. A small live share of a large allocated size is churn, the pattern behind a memory spike or a stall. Also totals, live memory by mode, allocation rate and peak. Needs a Metal recording above tier light.

ParameterTypeDescription
run *stringa run name from perf_runs
fieldsarrayresult paths to keep, dotted: common.frame_pacing
topintegerhow many resource types to keep, the largest allocated first, default 10

trace_tables List a trace's tables

Lists the data tables of a recording: those of its .trace when kept, else those its tables file stored.

ParameterTypeDescription
trace *stringa run name from perf_runs with trace_kept or tables_kept true, or a .trace path
fieldsarrayresult paths to keep, dotted: common.frame_pacing

trace_count Count a trace's rows

Counts the rows of tables of a recording, in all and per process: a table with 0 rows needs another instrument or Xcode, not a bigger page. Reads the .trace when kept, else the tables file.

ParameterTypeDescription
trace *stringa run name from perf_runs with trace_kept or tables_kept true, or a .trace path
fieldsarrayresult paths to keep, dotted: common.frame_pacing
tablesarraytable names from trace_tables; default the tables that matter for a translation layer

trace_query Read a trace table

Returns one page of rows of one table of a recording as {column: value}, optionally one process's. With window_ms the page holds time windows instead ({start_ms, count}, plus duration_ms when the table has a duration column). Rows come from the .trace when kept, else from the tables file; where, columns, order_by with descending, and group_by with aggregates filter and summarize the tables file (never SQL) and need it.

ParameterTypeDescription
schema *stringa table name that trace_tables lists, such as metal-gpu-intervals
trace *stringa run name from perf_runs with trace_kept or tables_kept true, or a .trace path
aggregatesarraytables file only: {fn, column}, fn count, sum, avg, min or max; named fn_column
columnsarraytables file only: keep these columns
descendingbooleanwith order_by, largest first
fieldsarrayresult paths to keep, dotted: common.frame_pacing
group_byarraytables file only: group rows by these columns (each group gets its count)
limitintegerdefault 50, at most 500
offsetintegerdefault 0
order_bystringtables file only: a column, or with group_by an aggregate name such as count or sum_duration
pidintegerkeep only this process's rows
wherearraytables file only, joined by AND: {column, op, value}, op one of = != < <= > >=; a time or size column holds its number as text: compare with a number
window_msinteger1 to 3600000: time windows of this many ms instead of rows (needs a start or time column)

capture_summary Summarize a capture

Reads a Metal .gputrace capture without Xcode: command buffers, encoders, draws, debug groups, and the 100 most frequent call ids out of calls_total.

ParameterTypeDescription
capture *stringa .gputrace bundle inside METAL_TRACE_OUT or METAL_TRACE_READ
fieldsarrayresult paths to keep, dotted: common.frame_pacing

capture_diff Compare two captures

Compares two .gputrace captures by their confirmed Metal calls: totals per call (a, b, delta) and the 100 debug groups with the largest change. Needs no Xcode.

ParameterTypeDescription
a *stringthe first .gputrace (usually the one before a change)
b *stringthe second .gputrace
fieldsarrayresult paths to keep, dotted: common.frame_pacing

capture_records Read a capture's records

Returns one page of the records of a .gputrace command stream, with their Metal call names when known.

ParameterTypeDescription
capture *stringa .gputrace bundle inside METAL_TRACE_OUT or METAL_TRACE_READ
fieldsarrayresult paths to keep, dotted: common.frame_pacing
limitintegerdefault 50, at most 500
offsetintegerdefault 0

screenshots_check Flag black, flat, frozen or flickering screenshots

Flags screenshots that show nothing useful: black, uniform (one flat colour) and, with `sequence` (the folder's PNGs in name order are frames of one run), frozen (3 identical frames in a row) and flicker. `ignore_rects` leaves out areas that change alone, such as a clock. Returns {"frames", "ok", "findings": [{"file", "problem"}]}.

ParameterTypeDescription
path *stringa PNG, or a folder of PNGs (in a readable folder), 100 at most
fieldsarrayresult paths to keep, dotted: common.frame_pacing
ignore_rectsarrayareas to leave out, [x0, y0, x1, y1] as fractions 0 to 1
sequencebooleantrue: the PNGs, in name order, are frames of one run; adds frozen and flicker

wine_log_census Count what a Wine log says is missing or wrong

Counts what a Wine debug log says is missing or wrong, by level, channel and message (numbers, paths and quoted text removed so repeats group), plus HRESULTs and the longest silence between +timestamp lines. No raw line leaves.

ParameterTypeDescription
path *stringa Wine debug log, or a folder of logs (in a readable folder), 50 at most
fieldsarrayresult paths to keep, dotted: common.frame_pacing
topintegermessages to list, 1 to 100, default 15

gpu_family Apple GPU family facts

Apple's published facts for one GPU family ("Apple7") or chip ("M1 Pro"): its chips, what it adds, its limits, the limits shared by all families, footnotes and source URLs.

ParameterTypeDescription
name *stringa family (Apple7 to Apple10) or a chip (M1 Pro, M2, M4 Max, A17 Pro)
fieldsarrayresult paths to keep, dotted: common.frame_pacing

workload_list List test programs

Lists the test programs workload_fetch can download, such as bgfx's drawstress: what each measures, its size, license and APIs, and whether it is already downloaded.

ParameterTypeDescription
fieldsarrayresult paths to keep, dotted: common.frame_pacing

workload_fetch Download a test program

Downloads a test program from this project's GitHub releases once, checks its SHA-256 against the one this package pins, and keeps it in ~/Library/Caches/metal-gpu-trace; later calls reuse it. The programs are built from source by the project's workloads workflow. A workload with `downloads` (Godot) also fetches each of those zip files from its own publisher, checks its SHA-512 against the one data/workloads.json pins and unzips it into the workload's folder.

ParameterTypeDescription
name *stringa workload name from workload_list, such as drawstress
fieldsarrayresult paths to keep, dotted: common.frame_pacing

presentmon_install Install PresentMon (Windows)

Windows only: downloads Intel's PresentMon console application (MIT) from its GitHub release, checks its SHA-256 against the one this package pins, and keeps it in %LOCALAPPDATA%\metal-gpu-trace, where perf_record and perf_attach find it; later calls reuse it. It needs administrator rights or the Performance Log Users group to run.

ParameterTypeDescription
fieldsarrayresult paths to keep, dotted: common.frame_pacing