metal-gpu-trace
Server Configuration
Describes the environment variables required to run the server.
| Name | Required | Description | Default |
|---|---|---|---|
| PERF_ENV | No | `NAME=VALUE` pairs, separated by spaces, set for the recorded program. | |
| KEEP_RUNS | No | Keeps only the newest N recordings. | |
| KEEP_TRACE | No | `1` keeps each recording's `.trace`, for `trace_tables`, `trace_query` or Instruments. | |
| WINEPREFIX | No | The Wine prefix used when the call names none; `~/.wine` otherwise. | |
| METAL_TRACE_LOG | No | `off` silences the one-line stderr log per call. | |
| METAL_TRACE_OUT | No | Where recordings go. Give an absolute path: the default, `./perf-runs`, depends on the client's working directory. | |
| METAL_TRACE_READ | No | More directories the tools may read, separated by `:`. | |
| METAL_TRACE_WINE | No | The Wine directory (holding `bin/wine`) that `perf_record` uses when the call names none. |
Instructions
Guidance the server publishes about itself, which clients place ahead of the tool catalog so the model reads it before choosing anything.
Records GPU use on Apple silicon with Metal System Trace, and native Windows programs with PresentMon. A metal-gpu-trace.json in the repository gives each project its own recordings folder; project_info says which project is active. One recording runs at a time; keep other GPU work off the Mac while it records, and keep the program's window visible: a hidden window stops presenting, and the work after that is left out of the frames (gpu.unpresented; perf_gate fails such a run). Under Wine record 30 s or more: Wine's start-up takes part of the recording. A recording needs about 0.8 GB of free disk per second for Instruments' temporary files (26 GB for 30 s, 50 GB for 60 s); perf_record refuses to start without it. Reading a recording back takes 1 to 14 s per recorded second. Compare only recordings with 100 frames or more, and repeat a run before calling a change real. perf_baseline (or perf_baseline_record, which records them) saves several equal runs as a named reference and perf_check says whether a new run regressed against their range. perf_diagnose says whether a run splits its GPU work into too many short encoders, as translation layers do; perf_compare says how much two runs differ; skip_s on perf_compare and perf_gate leaves out the first seconds (start-up) of each run; perf_history follows FPS, hitches and memory across runs with one name prefix, oldest first; perf_gate says whether a run meets budgets you set (FPS floor, hitch or memory ceiling). trace_tables, trace_count and trace_query read the .trace when KEEP_TRACE=1 kept it, else the run's tables file (.tables.sqlite, written at every recording: perf_runs tables_kept); trace_query's where, columns, order_by, group_by and aggregates filter that file without SQL. When perf_record ends it stops every program of its Wine prefix, or the native program it launched and that program's children. To compare native Metal with a translation layer without a game of one's own: workload_list, workload_fetch, then perf_record with workload and api (and example, for a workload that lists examples), or the compare-layer prompt. The diagnose-stutter prompt tells first-seen shader stutter from steady stutter; bisect-regression finds the commit that slowed a program. perf_sweep records one run per value of dim, example, api or an environment variable and fits GPU ms per frame on the value. trace_query with window_ms sums a long table by time window instead of listing rows. memory_free_pct holds the whole Mac short of memory while recording (keep other work off it) and background throttles the program: repeat a run that uses either. Use tier light to iterate, standard to decide, deep for GPU counters and a kept .trace (METAL_TRACE_MAX_DISK_MB may drop it); compare recordings of the same tier. perf_diagnose and perf_compare return suggested_actions: when it is not empty, run the first one that fits. On a laptop set cooldown_s on perf_baseline_record, perf_ab and perf_sweep so the Mac cools between recordings; a run whose summary has noisy_environment (another process was loading the GPU) is repeated before it is trusted. A recording is refused before it starts when its program, xcrun, the disk or the lock is not ready, or when the screen is locked (METAL_TRACE_ALLOW_LOCKED=1 allows that). When memory spikes or a run stalls, perf_memory_breakdown says which resource types it allocates and drops. A program may write its own numbers to the CSV named in METAL_TRACE_APP_METRICS (first column t_ms, then numeric columns); they come back as the summary's app_metrics, never comparable between programs.
Capabilities
Features and capabilities supported by this server
Protocol revision2025-11-25
| Capability | Details |
|---|---|
| tools | {} |
| prompts | {} |
| resources | {} |
Tools
Functions exposed to the LLM to take actions
| Name | Description |
|---|---|
| perf_recordA | Records |
| perf_baseline_recordA | Records the same program |
| perf_sweepA | 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 |
| perf_abA | Records the same program with two environments in the order A B B A ( |
| perf_cold_warmB | 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 |
| perf_attachA | Records a program that is already running, by pid or by a name in its command line, for |
| project_infoA | 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. |
| perf_runsB | 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. |
| perf_compareA | 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. |
| perf_baselineA | 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 |
| perf_checkA | 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. |
| perf_export_traceA | Writes a recording's GPU frames as |
| perf_gateA | 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 ( |
| perf_historyA | Lists the recordings whose name starts with |
| perf_diagnoseA | 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). |
| perf_memory_breakdownA | Breaks down the Metal allocations of a saved recording by type (texture, buffer, heap...): allocated, still live and
|
| trace_tablesB | Lists the data tables of a recording: those of its .trace when kept, else those its tables file stored. |
| trace_countA | 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. |
| trace_queryA | 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. |
| capture_summaryA | Reads a Metal .gputrace capture without Xcode: command buffers, encoders, draws, debug groups, and the 100 most frequent call ids out of calls_total. |
| capture_diffB | 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. |
| capture_recordsB | Returns one page of the records of a .gputrace command stream, with their Metal call names when known. |
| screenshots_checkA | Flags screenshots that show nothing useful: black, uniform (one flat colour) and, with |
| wine_log_censusA | 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. |
| gpu_familyA | 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. |
| workload_listA | 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. |
| workload_fetchA | 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 |
| presentmon_installA | 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. |
Prompts
Interactive templates invoked by user choice
| Name | Description |
|---|---|
| compare-layer | Records a test program in native Metal and under a translation layer, then diagnoses and compares both runs |
| diagnose-stutter | Records a program twice to tell first-seen shader stutter from steady stutter, then diagnoses it |
| bisect-regression | Finds the commit that made a workload slower: git bisect, with a recording and a check at each step. The recordings use a workload, so a commit must change what the workload runs (its arguments or environment) |
Resources
Contextual data attached and managed by the client
| Name | Description |
|---|---|
| Apple GPU families | Apple silicon GPU families Apple7 to Apple10: chips, first family with each feature, and limits that differ. Facts restated from Apple's public documents, not Apple's text. Check a device with MTLDevice.supportsFamily; families nest, so an Apple9 GPU also supports Apple7 and Apple8. |
| Apple7 GPU family | Apple's published facts for Apple7 |
| Apple8 GPU family | Apple's published facts for Apple8 |
| Apple9 GPU family | Apple's published facts for Apple9 |
| Apple10 GPU family | Apple's published facts for Apple10 |
TDQS
Scored across 28 tools
Most tools cover distinct stages (record, compare, gate, trace query, capture analysis), but the set has genuine clusters of near-siblings: perf_record / perf_attach / perf_baseline_record / perf_sweep / perf_ab / perf_cold_warm all record, and perf_check / perf_gate / perf_compare all judge a run against something. perf_runs vs perf_history and perf_baseline vs perf_baseline_record are easy to confuse at a glance, though the long descriptions do spell out the distinctions.
Everything is snake_case and grouped by domain prefix (perf_, trace_, capture_, workload_), which gives an agent a reliable mental map. Within perf_ most names are verb_noun (perf_record, perf_compare, perf_gate) with a few noun-only outliers (perf_runs, perf_history, perf_ab, perf_cold_warm), and singletons like project_info and gpu_family sit outside any prefix.
28 tools is above the comfortable band for a single MCP server and pushes the agent's selection burden. Nearly every tool is substantive rather than filler, but a few (gpu_family, screenshots_check, wine_log_census, presentmon_install) are peripheral reference/setup helpers that could be folded into docs or a smaller surface.
The measurement lifecycle is unusually well covered: capture, attach, sweep, A/B, baseline, compare, gate, diagnose, memory breakdown, trace tables/query/export, plus workload and environment setup. The main gaps are lifecycle hygiene — no delete/cleanup for saved recordings, workloads, or cached downloads, and no tool to enumerate .gputrace captures, which every capture_* tool requires as input.