Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778import Carbonimport Foundation
struct TabViewLatencySummary: Codable, Sendable { let samplesNanoseconds: [UInt64] let p50Milliseconds: Double let p95Milliseconds: Double
static func samples(log: String) throws -> [UInt64] { struct Entry: Decodable { let eventMessage: String? let count: Int? let finished: Int? } let expression = try Regex("latency_ns=([0-9]+)") var samples: [UInt64] = [] for line in log.split(separator: "\n") where line.first == "{" { let entry = try JSONDecoder().decode(Entry.self, from: Data(line.utf8)) if let message = entry.eventMessage { guard let match = try expression.firstMatch(in: message), let capture = match.output[1].substring, let value = UInt64(capture) else { throw RealityError("Invalid presentation measurement: \(message)") } samples.append(value) } else { guard entry.count == samples.count, entry.finished == 1 else { throw RealityError("Unexpected presentation log metadata") } } } return samples }
init(samples: [UInt64]) throws { guard !samples.isEmpty else { throw RealityError("No first-display-link samples were recorded") } samplesNanoseconds = samples let sorted = samples.sorted() func percentile(_ fraction: Double) -> Double { let index = max(0, Int(ceil(Double(sorted.count) * fraction)) - 1) return Double(sorted[index]) / 1_000_000 } p50Milliseconds = percentile(0.5) p95Milliseconds = percentile(0.95) }}
@MainActorfunc checkTabViewLatency(_ session: RealitySession) async throws { try TabViewConsoleSession.requireUnlockedConsole() try requireTabViewModifierReleaseRouting() try session.configure() let owned = try await session.startingWindows([.textEdit, .textEdit, .textEdit]) try await session.start() try await session.tiles(owned) try await session.apps.focus(owned[0]) for sample in 0..<30 { try await tabViewInput(session, arrow: UInt16(kVK_Escape), stage: "latency-\(sample)", holdMilliseconds: 500) } guard let parcel = session.parcel else { throw RealityError("No tested Parcel process") } let logs = try await RealityProcess.run( "/usr/bin/log", [ "show", "--last", "10m", "--style", "ndjson", "--predicate", "processIdentifier == \(parcel.processIdentifier) AND category == 'TabViewPresentation'", ], directory: session.directory) guard logs.status == 0 else { throw RealityError("Presentation log read failed: \(logs.errors)") } try Data(logs.output.utf8).write(to: session.directory.appendingPathComponent("presentation-log.ndjson")) let samples = try TabViewLatencySummary.samples(log: logs.output) guard samples.count == 30 else { throw RealityError("Expected 30 real key-to-display-link samples, recorded \(samples.count)") } let summary = try TabViewLatencySummary(samples: samples) try encodeJSON(summary, to: session.directory.appendingPathComponent("key-to-first-frame.json")) print("Tab View key → first display link: n=30 p50=\(summary.p50Milliseconds)ms p95=\(summary.p95Milliseconds)ms") guard summary.p95Milliseconds <= 50 else { throw RealityError("Tab View first-frame p95 exceeded 50ms: \(summary.p95Milliseconds)ms") }}