Cotton code
32 lines · 1.5 KB · SwiftRaw
// A cold launch's steps, as log lines (subsystem `com.cottondb.launch`;// launch-fast, 20 Nov 2026): the Keychain read, the core opened, the shipped// catalogue taken, the personal connect, the gate open and the first content// drawn. Each line is `launch: <step> <ms>`, the milliseconds since the// kernel made this process (before dyld, Swift's globals and `main`), so a// walk reads the timeline straight off the log, on a simulator or a phone.// The splash's going is `SwitchClock`'s `splash-down`.import Darwinimport OSLogimport QuartzCorepublic enum LaunchMarks {    private static let log = Logger(subsystem: "com.cottondb.launch", category: "launch")    /// When the kernel made this process, on `CACurrentMediaTime`'s clock.    private static let processStart: CFTimeInterval? = {        var info = kinfo_proc()        var size = MemoryLayout<kinfo_proc>.stride        var mib: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]        guard sysctl(&mib, UInt32(mib.count), &info, &size, nil, 0) == 0 else { return nil }        let started = info.kp_proc.p_starttime        let wall = Double(started.tv_sec) + Double(started.tv_usec) / 1_000_000        return CACurrentMediaTime() - (Date().timeIntervalSince1970 - wall)    }()    /// `step` happened now.    public static func mark(_ step: StaticString) {        let ms = processStart.map { Int(((CACurrentMediaTime() - $0) * 1000).rounded()) } ?? -1        log.notice("launch: \(String(describing: step), privacy: .public) \(ms)")    }}