iOS/macOS 27 introduces the StateReporting API and look-back trace collection tools, letting developers annotate game state (levels, graphics settings, network) directly into Metal performance traces and retroactively collect hours of performance data without pre-instrumentation.
⢠StateReporting lets you contextualize FPS drops with real game state (e.g., which level, which graphics preset) so you know exactly what the game was doing when a hitch occurred
⢠Look-back collection on iOS and the new `metalperftrace` CLI on macOS let you pull hours of already-recorded performance data after a session ends ā no need to plan ahead
⢠JSON output from `metalperftrace` enables automated regression pipelines and AI-assisted triage of performance regressions across builds
Demonstrates how to create a StateReporting domain that tracks level transitions and player position, annotating Metal performance traces with structured game context.
import Metal
import MetalStateReporting // Part of Metal tooling in iOS/macOS 27
// MARK: - StateReporting Domain Setup
class GameStateReporter {
// Create a domain using reverse-DNS naming convention
private let levelReporter: MTLStateReporter
private let graphicsReporter: MTLStateReporter
init() {
// Obtain reporters for each domain (finite state machines)
levelReporter = MTLStateReporter(domain: "com.mygame.level")
graphicsReporter = MTLStateReporter(domain: "com.mygame.graphics")
}
// Call when the player enters a new level
func playerEnteredLevel(id: Int, biome: String) {
levelReporter.reportTransition(
label: "Level \(id)",
stableMetadata: [
"biome": biome,
"id": String(id)
]
)
}
// Call each frame or on timer to update mutable state
func updatePlayerPosition(x: Float, y: Float, z: Float) {
levelReporter.reportVolatileMetadataUpdate([
"playerX": String(format: "%.1f", x),
"playerY": String(format: "%.1f", y),
"playerZ": String(format: "%.1f", z)
])
}
// Call when graphics quality changes
func graphicsQualityChanged(to preset: String, resolutionScale: Float) {
graphicsReporter.reportTransition(
label: preset,
stableMetadata: [
"resolutionScale": String(format: "%.2f", resolutionScale)
]
)
}
}
// MARK: - Usage in Game Loop
let reporter = GameStateReporter()
// On level load:
reporter.playerEnteredLevel(id: 3, biome: "Arctic")
reporter.graphicsQualityChanged(to: "High", resolutionScale: 1.0)
// Each frame or on position change:
reporter.updatePlayerPosition(x: 128.5, y: 0.0, z: -64.3)
// The Metal Performance HUD, Instruments, and metalperftrace CLI
// will now annotate all FPS/GPU metrics with this game context,
// allowing correlation like:
// $ metalperftrace overview --aggregate-state com.mygame.graphics:High game.ptraceMetricKit has been rebuilt from the ground up in iOS 27 with a contextually rich, Swift-first API that delivers metrics and diagnostics as async streams, plus new capabilities like Metal frame rate metrics, memory exception diagnostics, and per-state metric breakdowns via the StateReporting framework.
iOS 26+ introduces a Deferred Start API for AVCaptureSession that postpones initialization of non-preview outputs (like photo and movie outputs) until after the first preview frame renders, dramatically cutting camera app launch times.
Instruments 27 introduces Run Comparisons ā a new mode that directly diffs two profiling traces side-by-side in a single document to calculate exact performance deltas ā alongside the new Top Functions analysis mode that merges scattered call-tree nodes by self-weight to instantly surface the costliest functions regardless of call hierarchy.
StateReporting domains use reverse-DNS strings as identifiers ā collisions across libraries could corrupt traces. Volatile metadata updates are throttled to once per second in the HUD overlay. The `metalperftrace` CLI is macOS-only; iOS collection is done via Control Center and then transferred to Mac. Per-frame metrics storage has a configurable retention window (hours to days).
Look-back collection on iOS requires Developer Mode enabled and one-time device setup via Developer Settings. No additional hardware required.
iOS 27 rebuilds MetricKit from the ground up with a modern, Swift-first API that delivers metric and diagnostic reports via async streams, adds Metal frame rate metrics, memory exception diagnostics, and crash termination categories, plus a new StateReporting framework to contextualize metrics by app state.