Cotton code
38 lines · 1.6 KB · SwiftRaw
// A page's open timeline, as log lines (subsystem `com.cottondb.page`,// category `open`; lane threadload, 16 Oct 2026), the way `SwitchClock` logs// a database switch: the moment a screen is pushed — the tap, or a link// arriving — and then, once each, the milliseconds since then at which its// record is drawn (`record`), its conversation's messages are drawn// (`messages`) and everything the page draws has been read (`settled`).// `scripts/perf/pages.py times` reads them off a run.import OSLog@MainActorenum PageClock {    private static var asked: (route: String, at: ContinuousClock.Instant)?    private static var marked: Set<String> = []    private static let log = Logger(subsystem: "com.cottondb.page", category: "open")    /// A screen was asked for: its open starts now.    static func asked(_ route: String) {        asked = (route, .now)        marked = []        log.notice("open: \(route, privacy: .public) asked")    }    /// `what` happened for the open under way, once: logged with the    /// milliseconds since the screen was asked for.    static func mark(_ what: String) {        guard let asked, !marked.contains(what) else { return }        marked.insert(what)        let elapsed = ContinuousClock.now - asked.at        let ms = Int((Double(elapsed.components.seconds) * 1000 + Double(elapsed.components.attoseconds) / 1e15).rounded())        log.notice("open: \(asked.route, privacy: .public) \(what, privacy: .public) \(ms) ms")    }    /// The same, on the frame after this one: what was just set is drawn.    static func markDrawn(_ what: String) {        DispatchQueue.main.async { mark(what) }    }}