diff options
Diffstat (limited to 'src/FrameStats.zig')
| -rw-r--r-- | src/FrameStats.zig | 619 |
1 files changed, 597 insertions, 22 deletions
diff --git a/src/FrameStats.zig b/src/FrameStats.zig index 74f875df..0b252ff9 100644 --- a/src/FrameStats.zig +++ b/src/FrameStats.zig @@ -9,19 +9,25 @@ //! `Debug` shows the last second of it in its box, and `PARDES_FRAMES=path` //! writes the whole ring and its summary there when the session ends. //! -//! `PARDES_FRAMES_DEMO=scroll` runs `demo`, a timed script of scroll -//! inputs, in a pixel shell (the GUI feeds them through its own wheel and -//! key paths) and then ends the session: a timedemo, so two builds are -//! compared on the same motion, on a real display. +//! Each frame also carries its input-to-present latency (from the first +//! input it answers, the shell's timestamp of the key or wheel event, to +//! the end of its present), where its work went (`Zone`: the core's body +//! text, rows and colours; the shell's instance build, word shaping and +//! glyph rasterizing) and the view it showed, so a spike is attributed and +//! a scroll's throughput is counted in rows actually presented. +//! +//! `PARDES_FRAMES_DEMO=scroll` (or `stress`) runs a timed script of scroll +//! inputs (`named`) in a pixel shell (the GUI feeds them through its own +//! wheel and key paths) and then ends the session: a timedemo, so two +//! builds are compared on the same motion, on a real display. const std = @import("std"); const pardes = @import("pardes.zig"); const animation = @import("animation.zig"); const FrameStats = @This(); -/// 68 s at 60 Hz: a scripted run fits whole. -/// ponytail: a fixed ring, a file-backed log if a session's whole history matters. -pub const capacity = 4096; +/// 4.5 minutes at 60 Hz: the longest timedemo fits whole (1.3 MB). +pub const capacity = 16384; pub const Frame = struct { /// When the frame's step began, the input that woke it read: the @@ -41,8 +47,26 @@ pub const Frame = struct { /// The shell's motion in it: a scroll's picture offset from the text, /// rows (0 at rest). scroll: f32 = 0, + /// From the first input this frame answers to its present's end, µs; + /// 0 when it answers none. + latency_us: u32 = 0, + /// The focused pane's first line: with `scroll`, where the picture is. + view: i32 = 0, + /// µs a frame spent in each zone, and how many words the shell shaped + /// and glyphs it rasterized anew. + zones: [zone_count]u32 = @splat(0), + shaped: u16 = 0, + rastered: u16 = 0, + /// Bytes a cell shell wrote to its terminal for the frame. + bytes: u32 = 0, }; +/// Where a frame's work goes, as a game's profiler splits its budget. +/// The gui's are nested: shape and raster inside build; a soft present's +/// wait for the GPU, its upload of the frame and its flip after it. +pub const Zone = enum(u8) { body_text, body_rows, body_color, gui_build, gui_shape, gui_raster, gui_wait, gui_upload, gui_flip }; +pub const zone_count = std.enums.values(Zone).len; + ring: [capacity]Frame = @splat(.{}), /// Frames recorded since the start; the ring holds the last `capacity`. count: u64 = 0, @@ -57,13 +81,45 @@ armed: bool = false, jank: u64 = 0, over_budget: u64 = 0, skipped: u64 = 0, -/// What the shell sets while it draws the frame (Frame.scroll). +/// What the shell sets while it draws the frame (Frame.scroll), and the +/// pump (view). scroll: f32 = 0, +view: i32 = 0, +/// The first input not yet answered by a drawn frame, monotonic ns. +input_ns: u64 = 0, +/// This frame's zones so far. +zone_us: [zone_count]u32 = @splat(0), +shaped: u16 = 0, +rastered: u16 = 0, +bytes: u32 = 0, +/// When the timedemo started, monotonic ns (0: none ran), and which. +demo_ns: u64 = 0, +demo_name: []const u8 = "", /// The frame being timed: its marks, the monotonic clock's ns. mark_start: u64 = 0, mark_update: u64 = 0, mark_render: u64 = 0, +/// An input arrived at `at_ns`: the next drawn frame answers it. +pub fn input(stats: *FrameStats, at_ns: u64) void { + if (stats.input_ns == 0 or at_ns < stats.input_ns) stats.input_ns = at_ns; +} + +/// The pump had nothing to draw: what came in changed nothing on screen, +/// so no frame answers it. +pub fn idle(stats: *FrameStats) void { + stats.input_ns = 0; + // Nor was a frame owed after all (a motion that ended between frames): + // the next frame's gap is no motion's. + stats.armed = false; +} + +/// Adds the time since `from_ns` to `which`. +pub fn zone(stats: *FrameStats, which: Zone, from_ns: u64) void { + const us: u32 = @intCast(@min(std.math.maxInt(u32), (nowNs() -| from_ns) / std.time.ns_per_us)); + stats.zone_us[@backingInt(which)] +|= us; +} + pub fn nowNs() u64 { if (comptime !pardes.hosted) return 0; var ts: std.c.timespec = undefined; @@ -90,7 +146,18 @@ pub fn record(stats: *FrameStats, end_ns: u64, moving: bool, skipped: bool) void .moving = stats.armed, .skipped = skipped, .scroll = stats.scroll, + .latency_us = if (stats.input_ns == 0) 0 else @max(1, us.of(stats.input_ns, end_ns)), + .view = stats.view, + .zones = stats.zone_us, + .shaped = stats.shaped, + .rastered = stats.rastered, + .bytes = stats.bytes, }; + stats.bytes = 0; + stats.input_ns = 0; + stats.zone_us = @splat(0); + stats.shaped = 0; + stats.rastered = 0; // Half a period late is a refresh the motion missed. if (stats.armed and @as(u64, gap) * std.time.ns_per_us * 2 > stats.period_ns * 3) stats.jank += 1; if (@as(u64, frame.update_us + frame.render_us + frame.present_us) * std.time.ns_per_us > stats.period_ns) stats.over_budget += 1; @@ -120,7 +187,7 @@ pub const Spread = struct { max: u32 = 0, mean: f64 = 0, - pub const What = enum { work, update, render, present, gap }; + pub const What = enum { work, update, render, present, gap, latency }; pub fn of(frames: [2][]const Frame, comptime what: What) Spread { var values: [capacity]u32 = undefined; @@ -133,6 +200,7 @@ pub const Spread = struct { .render => f.render_us, .present => f.present_us, .gap => if (f.moving) f.gap_us else continue, + .latency => if (f.latency_us != 0) f.latency_us else continue, }; values[n] = v; n += 1; @@ -151,15 +219,20 @@ pub const Spread = struct { } }; -/// The Debug box's lines: the last second's work and gaps, and the -/// counters since the start, in ms. +/// The Debug box's lines: the last second's work, gaps and input latency, +/// and the jank counter since the start, in ms. pub fn summary(stats: *const FrameStats, buf: []u8) []const u8 { const recent = stats.last(@intCast(@max(1, std.time.ns_per_s / @max(1, stats.period_ns)))); const work = Spread.of(recent, .work); const gap = Spread.of(recent, .gap); - return std.fmt.bufPrint(buf, "frame {d:.2}/{d:.2}/{d:.2} ms\ngap {d:.2}/{d:.2} ms jank {d}", .{ - @as(f64, @floatFromInt(work.p50)) / 1000, @as(f64, @floatFromInt(work.p99)) / 1000, @as(f64, @floatFromInt(work.max)) / 1000, - @as(f64, @floatFromInt(gap.p50)) / 1000, @as(f64, @floatFromInt(gap.max)) / 1000, stats.jank, + const latency = Spread.of(stats.last(capacity / 16), .latency); + const ms = struct { + fn of(v: u32) f64 { + return @as(f64, @floatFromInt(v)) / 1000; + } + }; + return std.fmt.bufPrint(buf, "frame {d:.2}/{d:.2}/{d:.2} ms\ngap {d:.2}/{d:.2} ms jank {d}\ninput {d:.2}/{d:.2} ms", .{ + ms.of(work.p50), ms.of(work.p99), ms.of(work.max), ms.of(gap.p50), ms.of(gap.max), stats.jank, ms.of(latency.p50), ms.of(latency.p90), }) catch ""; } @@ -185,11 +258,21 @@ pub fn dump(stats: *const FrameStats, path: [:0]const u8) void { } write.line(fd, &buf, "# start_ms\tupdate_us\trender_us\tpresent_us\tgap_us\tmoving\tskipped\tscroll\n", .{}); const t0 = if (all[0].len != 0) all[0][0].start_ns else 0; + // The timedemo's phases, on the frames' clock. + if (stats.demo_ns != 0) if (named(stats.demo_name)) |steps| for (steps) |step| switch (step.act) { + .phase => |name| write.line(fd, &buf, "# phase {s} {d:.1}\n", .{ name, @as(f64, @floatFromInt((stats.demo_ns + @as(u64, step.at_ms) * std.time.ns_per_ms) -| t0)) / std.time.ns_per_ms }), + else => {}, + }; + write.line(fd, &buf, "# start_ms\tupdate_us\trender_us\tpresent_us\tgap_us\tmoving\tskipped\tscroll\tlatency_us\tview", .{}); + inline for (comptime std.enums.values(Zone)) |which| write.line(fd, &buf, "\t{t}_us", .{which}); + write.line(fd, &buf, "\tshaped\trastered\tbytes\n", .{}); for (all) |part| for (part) |f| { - write.line(fd, &buf, "{d:.3}\t{d}\t{d}\t{d}\t{d}\t{d}\t{d}\t{d:.4}\n", .{ + write.line(fd, &buf, "{d:.3}\t{d}\t{d}\t{d}\t{d}\t{d}\t{d}\t{d:.4}\t{d}\t{d}", .{ @as(f64, @floatFromInt(f.start_ns -| t0)) / std.time.ns_per_ms, f.update_us, f.render_us, f.present_us, f.gap_us, - @intFromBool(f.moving), @intFromBool(f.skipped), f.scroll, + @intFromBool(f.moving), @intFromBool(f.skipped), f.scroll, f.latency_us, f.view, }); + for (f.zones) |us| write.line(fd, &buf, "\t{d}", .{us}); + write.line(fd, &buf, "\t{d}\t{d}\t{d}\n", .{ f.shaped, f.rastered, f.bytes }); }; } @@ -200,6 +283,19 @@ pub const Step = struct { /// Wheel notches, down positive, as a mouse's. wheel: i8, key: pardes.Key, + /// A named stretch of the run starts (the dump lists them). + phase: []const u8, + /// A press and release of `button` over the focused pane, `at` of + /// the way down its body, on its rail or in its text. + click: struct { button: pardes.Mouse.Button, at: f32, rail: bool }, + /// Wheel notches over the focused pane's rail (the gutter). + rail_wheel: i8, + /// Text pasted (bracketed, as a terminal's paste arrives). + paste: []const u8, + /// A line run as Exec runs it, in the focused pane (a builtin, a + /// setting, else a shell command), the pane it opens focused: what + /// opens the other kinds of pane. + exec: []const u8, /// The run is over: the session ends. end, }, @@ -208,19 +304,41 @@ pub const Step = struct { /// Every kind of scroll a user makes, on a long file from its top: single /// notches, a fast spin of the wheel both ways (notches 8 ms apart, two a /// frame: each retargets the one before), half pages, pages, the far jumps -/// to the end and back, half pages faster than they settle, and the cursor +/// to the end (ge) and back (gg), half pages faster than they settle, and the cursor /// moving a line, a word and, in insert mode, a column at a time. +/// The timedemo PARDES_FRAMES_DEMO names, if any. +pub fn named(name: []const u8) ?[]const Step { + if (std.mem.eql(u8, name, "scroll")) return &demo; + if (std.mem.eql(u8, name, "stress")) return &stress; + if (std.mem.eql(u8, name, "kinds")) return &kinds; + if (std.mem.eql(u8, name, "panes")) return &panes; + if (std.mem.eql(u8, name, "one")) return &one; + if (std.mem.eql(u8, name, "jumps")) return &jumps; + if (std.mem.eql(u8, name, "longlines")) return &longlines; + if (std.mem.eql(u8, name, "clip-flick")) return &clip_flick; + if (std.mem.eql(u8, name, "clip-far")) return &clip_far; + if (std.mem.eql(u8, name, "clip-cursor")) return &clip_cursor; + if (std.mem.eql(u8, name, "clip-query")) return &clip_query; + if (std.mem.eql(u8, name, "clip-terminal")) return &clip_terminal; + if (std.mem.eql(u8, name, "clip-pages")) return &clip_pages; + return null; +} + pub const demo = blk: { @setEvalBranchQuota(20_000); var steps: [128]Step = undefined; var n: usize = 0; var t: u32 = 1500; + steps[n] = .{ .at_ms = t, .act = .{ .phase = "notches" } }; + n += 1; for (0..10) |_| { steps[n] = .{ .at_ms = t, .act = .{ .wheel = 1 } }; n += 1; t += 150; } t += 400; + steps[n] = .{ .at_ms = t, .act = .{ .phase = "spin" } }; + n += 1; for ([_]i8{ 1, -1 }) |dir| { for (0..24) |_| { steps[n] = .{ .at_ms = t, .act = .{ .wheel = dir } }; @@ -234,25 +352,33 @@ pub const demo = blk: { return .{ .cp = cp, .ctrl = true }; } }; + steps[n] = .{ .at_ms = t, .act = .{ .phase = "pages" } }; + n += 1; for ([_]u21{ 'd', 'd', 'd', 'u', 'u', 'f', 'b' }) |cp| { steps[n] = .{ .at_ms = t, .act = .{ .key = ctrl.key(cp) } }; n += 1; t += 600; } - steps[n] = .{ .at_ms = t, .act = .{ .key = .{ .cp = 'G', .text = "G" } } }; - n += 1; + for ([_]u21{ 'g', 'e' }, [_][]const u8{ "g", "e" }, 0..) |cp, text, i| { + steps[n] = .{ .at_ms = t + 20 * i, .act = .{ .key = .{ .cp = cp, .text = text } } }; + n += 1; + } t += 800; for (0..2) |i| { steps[n] = .{ .at_ms = t + 20 * i, .act = .{ .key = .{ .cp = 'g', .text = "g" } } }; n += 1; } t += 800; + steps[n] = .{ .at_ms = t, .act = .{ .phase = "retarget" } }; + n += 1; for (0..4) |_| { steps[n] = .{ .at_ms = t, .act = .{ .key = ctrl.key('d') } }; n += 1; t += 80; } t += 700; + steps[n] = .{ .at_ms = t, .act = .{ .phase = "cursor" } }; + n += 1; for ([_]struct { u21, []const u8, u32 }{ .{ 'j', "j", 60 }, .{ 'w', "w", 90 } }) |run| { for (0..10) |_| { steps[n] = .{ .at_ms = t, .act = .{ .key = .{ .cp = run[0], .text = run[1] } } }; @@ -279,6 +405,444 @@ pub const demo = blk: { break :blk out; }; +/// The scrolls every kind of text and pane is put through (`kinds`, +/// `panes`), from `t`: notches, a spin, half pages, PageDown held, the far +/// jumps, the cursor down a held j. 7.5 s. +fn scrollSet(steps: []Step, n: *usize, t: *u32) void { + const at = struct { + fn add(s: []Step, k: *usize, ms: u32, act: @FieldType(Step, "act")) void { + s[k.*] = .{ .at_ms = ms, .act = act }; + k.* += 1; + } + }; + for (0..6) |_| { + at.add(steps, n, t.*, .{ .wheel = 1 }); + t.* += 150; + } + for (0..100) |_| { + at.add(steps, n, t.*, .{ .wheel = 1 }); + t.* += 8; + } + t.* += 500; + for (0..3) |_| { + at.add(steps, n, t.*, .{ .key = .{ .cp = 'd', .ctrl = true } }); + t.* += 400; + } + for (0..45) |_| { + at.add(steps, n, t.*, .{ .key = .{ .cp = pardes.Key.page_down } }); + t.* += 33; + } + t.* += 400; + for ([_][]const u8{ "e", "g" }) |second| { + at.add(steps, n, t.*, .{ .key = .{ .cp = 'g', .text = "g" } }); + at.add(steps, n, t.* + 20, .{ .key = .{ .cp = second[0], .text = second } }); + t.* += 600; + } + for (0..30) |_| { + at.add(steps, n, t.*, .{ .key = .{ .cp = 'j', .text = "j" } }); + t.* += 33; + } + t.* += 500; +} + +/// `scrollSet` alone, on the file the session opened: one kind, for a +/// profiler's run. +pub const one = blk: { + @setEvalBranchQuota(20_000); + var steps: [512]Step = undefined; + var n: usize = 0; + var t: u32 = 1500; + steps[n] = .{ .at_ms = t, .act = .{ .phase = "one" } }; + n += 1; + scrollSet(&steps, &n, &t); + steps[n] = .{ .at_ms = t, .act = .end }; + n += 1; + const out = steps[0..n].*; + break :blk out; +}; + +/// The samples' scenes (docs/next-anim.md), a few seconds each, recorded +/// with PARDES_FRAMES_CAPTURE: a wheel spun hard; Ctrl-d held then ge and +/// gg; j held then the thin caret typing and arrowing; a `/` typed and its +/// places stepped with Ctrl-n; a command's output then the wheel over it; +/// Ctrl-f a page at a time. +fn clipSteps(comptime which: usize, steps: *[256]Step) usize { + @setEvalBranchQuota(100_000); + var n: usize = 0; + var t: u32 = 1200; + const add = struct { + fn step(s: []Step, k: *usize, at: *u32, gap: u32, act: @FieldType(Step, "act")) void { + s[k.*] = .{ .at_ms = at.*, .act = act }; + k.* += 1; + at.* += gap; + } + }; + switch (which) { + 0 => for (0..150) |_| add.step(steps, &n, &t, 12, .{ .wheel = 1 }), + 1 => { + for (0..36) |_| add.step(steps, &n, &t, 33, .{ .key = .{ .cp = 'd', .ctrl = true } }); + t += 600; + add.step(steps, &n, &t, 20, .{ .key = .{ .cp = 'g', .text = "g" } }); + add.step(steps, &n, &t, 900, .{ .key = .{ .cp = 'e', .text = "e" } }); + add.step(steps, &n, &t, 20, .{ .key = .{ .cp = 'g', .text = "g" } }); + add.step(steps, &n, &t, 900, .{ .key = .{ .cp = 'g', .text = "g" } }); + }, + 2 => { + for (0..45) |_| add.step(steps, &n, &t, 33, .{ .key = .{ .cp = 'j', .text = "j" } }); + t += 300; + add.step(steps, &n, &t, 300, .{ .key = .{ .cp = 'i', .text = "i" } }); + for ("the quick brown fox jumps") |ch| add.step(steps, &n, &t, 60, .{ .key = .{ .cp = ch, .text = &.{ch} } }); + for (0..10) |_| add.step(steps, &n, &t, 70, .{ .key = .{ .cp = pardes.Key.left } }); + for (0..4) |_| add.step(steps, &n, &t, 90, .{ .key = .{ .cp = pardes.Key.up } }); + add.step(steps, &n, &t, 400, .{ .key = .{ .cp = pardes.Key.escape } }); + }, + 3 => { + for ("/pane.") |ch| add.step(steps, &n, &t, 180, .{ .key = .{ .cp = ch, .text = &.{ch} } }); + t += 300; + for (0..8) |_| add.step(steps, &n, &t, 300, .{ .key = .{ .cp = 'n', .ctrl = true } }); + }, + 4 => { + add.step(steps, &n, &t, 1800, .{ .exec = "cat stress.zig" }); + for (0..60) |_| add.step(steps, &n, &t, 16, .{ .wheel = -1 }); + t += 400; + for (0..12) |_| add.step(steps, &n, &t, 150, .{ .wheel = 1 }); + }, + else => for (0..8) |_| add.step(steps, &n, &t, 450, .{ .key = .{ .cp = 'f', .ctrl = true } }), + } + t += 800; + add.step(steps, &n, &t, 0, .end); + return n; +} + +const clip_flick = blk: { + var steps: [256]Step = undefined; + const n = clipSteps(0, &steps); + const out = steps[0..n].*; + break :blk out; +}; +const clip_far = blk: { + var steps: [256]Step = undefined; + const n = clipSteps(1, &steps); + const out = steps[0..n].*; + break :blk out; +}; +const clip_cursor = blk: { + var steps: [256]Step = undefined; + const n = clipSteps(2, &steps); + const out = steps[0..n].*; + break :blk out; +}; +const clip_query = blk: { + var steps: [256]Step = undefined; + const n = clipSteps(3, &steps); + const out = steps[0..n].*; + break :blk out; +}; +const clip_terminal = blk: { + var steps: [256]Step = undefined; + const n = clipSteps(4, &steps); + const out = steps[0..n].*; + break :blk out; +}; +const clip_pages = blk: { + var steps: [256]Step = undefined; + const n = clipSteps(5, &steps); + const out = steps[0..n].*; + break :blk out; +}; + +/// The cursor along long lines (a minified JS, a one-line JSON, six 360 KB +/// lines), Wrap on and then off (off, the view scrolls sideways): w and e +/// held, l held, $ and 0, f and t, gl and gh, typing at a line's end and in +/// its middle, a selection swept with held L and W. +pub const longlines = blk: { + @setEvalBranchQuota(1_000_000); + var steps: [8192]Step = undefined; + var n: usize = 0; + var t: u32 = 1500; + const add = struct { + fn step(s: []Step, k: *usize, at: *u32, gap: u32, act: @FieldType(Step, "act")) void { + s[k.*] = .{ .at_ms = at.*, .act = act }; + k.* += 1; + at.* += gap; + } + fn keys(s: []Step, k: *usize, at: *u32, gap: u32, text: []const u8, times: usize) void { + for (0..times) |_| for (text, 0..) |_, i| step(s, k, at, gap, .{ .key = .{ .cp = text[i], .text = text[i .. i + 1] } }); + } + }; + for ([_][]const u8{ "wrap", "nowrap" }) |mode| { + if (std.mem.eql(u8, mode, "nowrap")) add.step(&steps, &n, &t, 300, .{ .exec = "Wrap" }); + for ([_][]const u8{ "minified.js", "oneline.json", "hugelines.txt" }) |file| { + add.step(&steps, &n, &t, 1500, .{ .exec = "Look kinds/" ++ file }); + const tag = file ++ "-" ++ mode; + add.keys(&steps, &n, &t, 400, "gg", 1); + add.step(&steps, &n, &t, 0, .{ .phase = "w-held-" ++ tag }); + add.keys(&steps, &n, &t, 33, "w", 60); + add.step(&steps, &n, &t, 0, .{ .phase = "e-held-" ++ tag }); + add.keys(&steps, &n, &t, 33, "e", 60); + add.step(&steps, &n, &t, 0, .{ .phase = "l-held-" ++ tag }); + add.keys(&steps, &n, &t, 33, "l", 90); + add.step(&steps, &n, &t, 0, .{ .phase = "dollar-zero-" ++ tag }); + add.keys(&steps, &n, &t, 600, "$0", 2); + add.step(&steps, &n, &t, 0, .{ .phase = "f-t-" ++ tag }); + add.keys(&steps, &n, &t, 150, "f,", 8); + add.keys(&steps, &n, &t, 150, "t ", 8); + add.step(&steps, &n, &t, 0, .{ .phase = "gl-gh-" ++ tag }); + add.keys(&steps, &n, &t, 500, "glgh", 3); + add.step(&steps, &n, &t, 0, .{ .phase = "insert-end-" ++ tag }); + add.keys(&steps, &n, &t, 300, "$a", 1); + add.keys(&steps, &n, &t, 45, "typed at the end ", 2); + add.step(&steps, &n, &t, 300, .{ .key = .{ .cp = pardes.Key.escape } }); + add.step(&steps, &n, &t, 0, .{ .phase = "insert-middle-" ++ tag }); + add.keys(&steps, &n, &t, 40, "0", 1); + add.keys(&steps, &n, &t, 40, "40000l", 1); + add.keys(&steps, &n, &t, 300, "i", 1); + add.keys(&steps, &n, &t, 45, "typed in the middle ", 2); + add.step(&steps, &n, &t, 300, .{ .key = .{ .cp = pardes.Key.escape } }); + add.step(&steps, &n, &t, 0, .{ .phase = "sweep-L-W-" ++ tag }); + add.keys(&steps, &n, &t, 33, "L", 40); + add.keys(&steps, &n, &t, 33, "W", 30); + // Del twice: the second throws the typing away. + add.step(&steps, &n, &t, 300, .{ .exec = "Del" }); + add.step(&steps, &n, &t, 600, .{ .exec = "Del" }); + } + } + add.step(&steps, &n, &t, 0, .end); + const out = steps[0..n].*; + break :blk out; +}; + +/// What insert mode's paste pastes: 200 lines. +const pasted = blk: { + const line = "a pasted line, one of two hundred\n"; + var out: [line.len * 200]u8 = undefined; + for (0..200) |i| @memcpy(out[i * line.len ..][0..line.len], line); + break :blk out; +}; + +/// Every other way a view moves, each its own phase, on the session's file +/// (a big one) and then on a small one: the counted jumps (12G, 9000G, gg), +/// the upward pages, a search's n/N, a query's Ctrl-n moving its owner's +/// view, `*`, Looks at `:40`, at a far line and at another file (a new +/// pane: nothing to glide from), the jumplist both ways, the rail's +/// buttons and the wheel over it, and insert mode: typing, arrows, Enter at +/// the bottom of the view, a 200-line paste. +pub const jumps = blk: { + @setEvalBranchQuota(400_000); + var steps: [2048]Step = undefined; + var n: usize = 0; + var t: u32 = 1500; + const add = struct { + fn step(s: []Step, k: *usize, at: *u32, gap: u32, act: @FieldType(Step, "act")) void { + s[k.*] = .{ .at_ms = at.*, .act = act }; + k.* += 1; + at.* += gap; + } + fn text(s: []Step, k: *usize, at: *u32, gap: u32, keys: []const u8) void { + for (keys, 0..) |_, i| step(s, k, at, gap, .{ .key = .{ .cp = keys[i], .text = keys[i .. i + 1] } }); + } + fn key(s: []Step, k: *usize, at: *u32, gap: u32, cp: u21, ctrl: bool, times: usize) void { + for (0..times) |_| step(s, k, at, gap, .{ .key = .{ .cp = cp, .ctrl = ctrl } }); + } + }; + for ([_][]const u8{ "big", "small" }) |size| { + if (std.mem.eql(u8, size, "small")) add.step(&steps, &n, &t, 1200, .{ .exec = "Look kinds/guide.typ" }); + add.step(&steps, &n, &t, 0, .{ .phase = "counted-G-" ++ size }); + for ([_][]const u8{ "12G", "300G", "9000G", "gg", "ge", "gg" }) |keys| { + add.text(&steps, &n, &t, 20, keys); + t += 700; + } + add.step(&steps, &n, &t, 0, .{ .phase = "pages-up-" ++ size }); + add.text(&steps, &n, &t, 700, "ge"); + add.key(&steps, &n, &t, 500, 'u', true, 3); + add.key(&steps, &n, &t, 500, 'b', true, 3); + add.key(&steps, &n, &t, 500, pardes.Key.page_up, false, 3); + add.step(&steps, &n, &t, 0, .{ .phase = "search-n-" ++ size }); + add.text(&steps, &n, &t, 700, "gg"); + add.text(&steps, &n, &t, 120, "/const "); + add.key(&steps, &n, &t, 600, pardes.Key.enter, false, 1); + add.text(&steps, &n, &t, 400, "nnnnnnNNNNNN"); + add.step(&steps, &n, &t, 0, .{ .phase = "rail-" ++ size }); + add.text(&steps, &n, &t, 700, "ge"); + for ([_]pardes.Mouse.Button{ .left, .left, .right, .right, .middle }, [_]f32{ 0.8, 0.3, 0.6, 0.9, 0.5 }) |button, at| + add.step(&steps, &n, &t, 600, .{ .click = .{ .button = button, .at = at, .rail = true } }); + for (0..8) |_| add.step(&steps, &n, &t, 120, .{ .rail_wheel = 1 }); + t += 500; + add.step(&steps, &n, &t, 0, .{ .phase = "query-ctrl-n-" ++ size }); + add.text(&steps, &n, &t, 120, "/pub fn"); + add.key(&steps, &n, &t, 250, 'n', true, 8); + add.key(&steps, &n, &t, 250, 'p', true, 4); + add.key(&steps, &n, &t, 700, pardes.Key.escape, false, 1); + add.step(&steps, &n, &t, 0, .{ .phase = "star-" ++ size }); + add.text(&steps, &n, &t, 300, "ggww*"); + add.text(&steps, &n, &t, 500, "nnnn"); + add.step(&steps, &n, &t, 0, .{ .phase = "look-" ++ size }); + add.step(&steps, &n, &t, 900, .{ .exec = "Look :40" }); + add.step(&steps, &n, &t, 900, .{ .exec = "Look :7000" }); + add.step(&steps, &n, &t, 900, .{ .exec = "Look :200" }); + add.step(&steps, &n, &t, 0, .{ .phase = "jumplist-" ++ size }); + add.key(&steps, &n, &t, 600, 'o', true, 3); + add.key(&steps, &n, &t, 600, 'i', true, 3); + add.text(&steps, &n, &t, 40, " jo"); + t += 600; + add.text(&steps, &n, &t, 40, " ji"); + t += 600; + add.step(&steps, &n, &t, 0, .{ .phase = "insert-" ++ size }); + add.text(&steps, &n, &t, 300, "ggi"); + for (0..4) |_| add.text(&steps, &n, &t, 45, "the quick brown fox "); + add.key(&steps, &n, &t, 60, pardes.Key.left, false, 12); + add.key(&steps, &n, &t, 60, pardes.Key.right, false, 12); + add.key(&steps, &n, &t, 60, pardes.Key.down, false, 6); + // Enter after Enter until the view has to follow, a line at a time. + add.key(&steps, &n, &t, 70, pardes.Key.enter, false, 60); + add.step(&steps, &n, &t, 600, .{ .paste = &pasted }); + add.key(&steps, &n, &t, 700, pardes.Key.escape, false, 1); + } + add.step(&steps, &n, &t, 0, .{ .phase = "look-new-pane" }); + add.step(&steps, &n, &t, 1500, .{ .exec = "Look ../../src/layout.zig:9000" }); + add.step(&steps, &n, &t, 0, .end); + const out = steps[0..n].*; + break :blk out; +}; + +/// Each file of the corpus (`.scratch/tools/corpus.sh`) is opened by name, +/// relative to the first file's directory, and put through `scrollSet`; +/// the long-line ones a second time with Wrap off. +pub const kinds = blk: { + @setEvalBranchQuota(200_000); + var steps: [4096]Step = undefined; + var n: usize = 0; + var t: u32 = 1500; + const files = [_][]const u8{ "generated-parser.c", "commands.rs", "tables.py", "jquery.js", "minified.js", "grammar.json", "oneline.json", "CHANGELOG.md", "cascade.html", "simdutf.cpp", "parser.ts", "fcnal-test.sh", "data.go", "guide.typ", "unicode.txt", "big.log", "words.txt", "hugelines.txt" }; + for (files ++ [_][]const u8{ "minified.js!", "oneline.json!", "hugelines.txt!" }) |file| { + const unwrapped = file[file.len - 1] == '!'; + const name = if (unwrapped) file[0 .. file.len - 1] else file; + // Wrap goes off once, before the second round. + if (unwrapped and std.mem.eql(u8, name, "minified.js")) { + steps[n] = .{ .at_ms = t, .act = .{ .exec = "Wrap" } }; + n += 1; + t += 200; + } + steps[n] = .{ .at_ms = t, .act = .{ .exec = "Look kinds/" ++ name } }; + n += 1; + t += 1200; + steps[n] = .{ .at_ms = t, .act = .{ .phase = file } }; + n += 1; + scrollSet(&steps, &n, &t); + steps[n] = .{ .at_ms = t, .act = .{ .exec = "Del" } }; + n += 1; + t += 400; + } + steps[n] = .{ .at_ms = t, .act = .end }; + n += 1; + const out = steps[0..n].*; + break :blk out; +}; + +/// The other kinds of pane, opened from the first file's directory, each +/// put through `scrollSet`: a command's fast output (the stress file, then +/// `yes`), a +Pager, a directory, a PDF, a picture, Help's output pane, a +/// +Diff, and the query pane typed into (its rows refilled each key, its +/// owner's places drawn). +pub const panes = blk: { + @setEvalBranchQuota(200_000); + var steps: [4096]Step = undefined; + var n: usize = 0; + var t: u32 = 1500; + const Kind = struct { name: []const u8, open: []const u8, settle: u32 }; + for ([_]Kind{ + .{ .name = "command-cat", .open = "cat stress.zig", .settle = 300 }, + .{ .name = "command-yes", .open = "yes | head -200000", .settle = 300 }, + .{ .name = "pager", .open = "cat stress.zig | pardes -", .settle = 2500 }, + .{ .name = "directory", .open = "Look kinds/", .settle = 1200 }, + .{ .name = "pdf", .open = "Look ../../docs/design.pdf", .settle = 2000 }, + .{ .name = "image", .open = "Look ../../docs/screenshots/atelier.png", .settle = 1200 }, + .{ .name = "help", .open = "Help", .settle = 1200 }, + .{ .name = "changelog", .open = "Changelog", .settle = 1200 }, + }) |kind| { + steps[n] = .{ .at_ms = t, .act = .{ .phase = kind.name } }; + n += 1; + steps[n] = .{ .at_ms = t, .act = .{ .exec = kind.open } }; + n += 1; + // A command's output streams in while it is scrolled. + t += kind.settle; + scrollSet(&steps, &n, &t); + steps[n] = .{ .at_ms = t, .act = .{ .exec = "Del" } }; + n += 1; + t += 600; + } + steps[n] = .{ .at_ms = t, .act = .{ .phase = "query-typing" } }; + n += 1; + steps[n] = .{ .at_ms = t, .act = .{ .key = .{ .cp = '/', .text = "/" } } }; + n += 1; + t += 300; + for ("pane.vie") |ch| { + steps[n] = .{ .at_ms = t, .act = .{ .key = .{ .cp = ch, .text = &.{ch} } } }; + n += 1; + t += 150; + } + for (0..12) |_| { + steps[n] = .{ .at_ms = t, .act = .{ .key = .{ .cp = 'n', .ctrl = true } } }; + n += 1; + t += 120; + } + steps[n] = .{ .at_ms = t, .act = .{ .key = .{ .cp = pardes.Key.escape } } }; + n += 1; + t += 800; + steps[n] = .{ .at_ms = t, .act = .end }; + n += 1; + const out = steps[0..n].*; + break :blk out; +}; + +/// Throughput on a big file (layout.zig x23, 30k lines): each input held +/// for three seconds at a keyboard's repeat (33 ms) or a wheel spun hard (a +/// notch every 8 ms), so the picture has to keep up with more than it can +/// show: a spin, held Ctrl-d, held j, held PageDown, then the far jumps. +pub const stress = blk: { + @setEvalBranchQuota(100_000); + var steps: [1024]Step = undefined; + var n: usize = 0; + var t: u32 = 1500; + const Held = struct { name: []const u8, key: ?pardes.Key, every: u32 }; + for ([_]Held{ + .{ .name = "spin", .key = null, .every = 8 }, + .{ .name = "held-ctrl-d", .key = .{ .cp = 'd', .ctrl = true }, .every = 33 }, + .{ .name = "held-j", .key = .{ .cp = 'j', .text = "j" }, .every = 33 }, + .{ .name = "held-pagedown", .key = .{ .cp = pardes.Key.page_down }, .every = 33 }, + }) |held| { + // Each from the top. + for ([_]u32{ 0, 20 }) |dt| { + steps[n] = .{ .at_ms = t + dt, .act = .{ .key = .{ .cp = 'g', .text = "g" } } }; + n += 1; + } + t += 800; + steps[n] = .{ .at_ms = t, .act = .{ .phase = held.name } }; + n += 1; + const end = t + 3000; + while (t < end) : (t += held.every) { + steps[n] = .{ .at_ms = t, .act = if (held.key) |key| .{ .key = key } else .{ .wheel = 1 } }; + n += 1; + } + t += 1000; + } + steps[n] = .{ .at_ms = t, .act = .{ .phase = "far" } }; + n += 1; + for (0..3) |_| { + for ([_][]const u8{ "e", "g" }) |second| { + for ([_][]const u8{ "g", second }, 0..) |text, i| { + steps[n] = .{ .at_ms = t + 20 * @as(u32, i), .act = .{ .key = .{ .cp = text[0], .text = text } } }; + n += 1; + } + t += 700; + } + } + steps[n] = .{ .at_ms = t + 500, .act = .end }; + n += 1; + const out = steps[0..n].*; + break :blk out; +}; + test "frame stats: gaps into a motion count as jank, idle gaps do not, and the ring keeps the last frames" { var stats: FrameStats = .{ .period_ns = 16 * std.time.ns_per_ms }; const ms = std.time.ns_per_ms; @@ -321,7 +885,18 @@ test "frame stats: gaps into a motion count as jank, idle gaps do not, and the r try std.testing.expectEqual(@as(usize, 10), tail[0].len + tail[1].len); const newest = if (tail[1].len != 0) tail[1][tail[1].len - 1] else tail[0][tail[0].len - 1]; try std.testing.expectEqual(@as(f32, capacity + 4), newest.scroll); - // The demo ends, and its steps are in time order. - try std.testing.expect(demo[demo.len - 1].act == .end); - for (demo[1..], demo[0 .. demo.len - 1]) |b, a| try std.testing.expect(b.at_ms >= a.at_ms); + // Each timedemo ends, and its steps are in time order. + for ([_][]const Step{ &demo, &stress, &kinds, &panes, &one, &jumps, &longlines }) |steps| { + try std.testing.expect(steps[steps.len - 1].act == .end); + for (steps[1..], steps[0 .. steps.len - 1]) |b, a| try std.testing.expect(b.at_ms >= a.at_ms); + } + // An input is answered by the next drawn frame, and only by it. + stats.input(t - 2 * ms); + stats.mark_start = t; + stats.mark_update = t; + stats.mark_render = t; + stats.record(t + 3 * ms, false, false); + try std.testing.expectEqual(@as(u32, 5000), stats.last(1)[0][0].latency_us); + stats.record(t + 4 * ms, false, false); + try std.testing.expectEqual(@as(u32, 0), stats.last(1)[0][0].latency_us); } |
