summaryrefslogtreecommitdiff
path: root/src/FrameStats.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 23:53:14 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:21:29 -0300
commitb5f8c6d173ccebefb6f08192873a96bcc9f86cd9 (patch)
tree895ef81f75b64e4167f3812391965b4e7fe8a8d7 /src/FrameStats.zig
parentdbdd21d8ebfaaedb5675a457aa385b97450237f5 (diff)
downloadpardes-b5f8c6d173ccebefb6f08192873a96bcc9f86cd9.tar.gz
pardes-b5f8c6d173ccebefb6f08192873a96bcc9f86cd9.zip
FrameStats: the timedemos leave the binary: PARDES_FRAMES_DEMO names a text script (parseScript: `<ms> [<n>x<every>] <action>` a line, a wheel, touch, key, keys, phase, click, rail_wheel, paste, exec or end), the fifteen compiled ones are tools/demos/*.txt, each read back step for step identical to its builder before the builders went (11,401 steps the binary no longer carries: the Debug binary's .data.rel.ro 8,566,256 to 7,944,088 bytes, an idle detached session's RSS 38.3 to 37.3 MB), and the keystroke one is test/perf.zig's own data, parsed for its tty and written beside its files for its window; a window whose script does not read does not start; a test reads every script in tools/demos
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/FrameStats.zig')
-rw-r--r--src/FrameStats.zig844
1 files changed, 115 insertions, 729 deletions
diff --git a/src/FrameStats.zig b/src/FrameStats.zig
index 33ffd300..fb882d69 100644
--- a/src/FrameStats.zig
+++ b/src/FrameStats.zig
@@ -16,10 +16,11 @@
//! 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.
+//! `PARDES_FRAMES_DEMO=<file>` runs a timed script of inputs (`parseScript`;
+//! the ones the notes measured with are in tools/demos/) 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");
@@ -100,9 +101,9 @@ shaped: u16 = 0,
rastered: u16 = 0,
bytes: u32 = 0,
landed: u16 = 0,
-/// When the timedemo started, monotonic ns (0: none ran), and which.
+/// When the timedemo started, monotonic ns (0: none ran), and its steps.
demo_ns: u64 = 0,
-demo_name: []const u8 = "",
+demo: []const Step = &.{},
/// The frame being timed: its marks, the monotonic clock's ns.
mark_start: u64 = 0,
mark_update: u64 = 0,
@@ -272,7 +273,7 @@ pub fn dump(stats: *const FrameStats, path: [:0]const u8) void {
// up with the frames' by this.
write.line(fd, &buf, "# t0_ns {d}\n", .{t0});
// 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) {
+ for (stats.demo) |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 => {},
};
@@ -289,7 +290,7 @@ pub fn dump(stats: *const FrameStats, path: [:0]const u8) void {
};
}
-/// One input of the scroll timedemo, `at_ms` after the first frame.
+/// One input of a timedemo, `at_ms` after the first frame.
pub const Step = struct {
at_ms: u32,
act: union(enum) {
@@ -316,732 +317,97 @@ 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 (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, "pdf-scroll")) return &pdf_scroll;
- if (std.mem.eql(u8, name, "pdf-sdm")) return &pdf_sdm;
- if (std.mem.eql(u8, name, "one")) return &one;
- if (std.mem.eql(u8, name, "keys")) return &keystrokes;
- 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 } };
- n += 1;
- t += 8;
- }
- t += 800;
- }
- const ctrl = struct {
- fn key(cp: u21) pardes.Key {
- return .{ .cp = cp, .ctrl = true };
+/// A timedemo's script, the file PARDES_FRAMES_DEMO names (tools/demos/): an
+/// input a line, `<ms> <action> [<arg>]` at `ms` after the first frame, or
+/// `<ms> <n>x<every> <action> [<arg>]` for n of them `every` ms apart; a
+/// line that starts with `#` says what the script is. The actions: `wheel
+/// <notches>` (down positive), `touch <lines>`, `key <k>`, `keys <k>...`
+/// (its keys in turn, each `every` ms after the one before, n times over),
+/// `phase <name>`, `click <button> <at> rail` or `text`, `rail_wheel
+/// <notches>`, `paste <text>` and `exec <line>` (in both `\n` is a newline
+/// and `\\` a backslash), and `end`. A key is a character (its text typed),
+/// `space`, `^<c>` (with Ctrl) or a pardes.Key name (enter, page_down, ...).
+/// The steps' strings are `text`'s, or `arena`'s where an escape was undone.
+pub fn parseScript(arena: std.mem.Allocator, text: []const u8) error{ OutOfMemory, BadScript }![]Step {
+ var steps: std.ArrayList(Step) = .empty;
+ var lines = std.mem.splitScalar(u8, text, '\n');
+ while (lines.next()) |raw| {
+ const line = std.mem.trimEnd(u8, raw, "\r");
+ if (line.len == 0 or line[0] == '#') continue;
+ var words = std.mem.tokenizeScalar(u8, line, ' ');
+ const at = std.fmt.parseInt(u32, words.next() orelse return error.BadScript, 10) catch return error.BadScript;
+ var word = words.next() orelse return error.BadScript;
+ var count: u32 = 1;
+ var every: u32 = 0;
+ if (std.ascii.isDigit(word[0])) {
+ const x = std.mem.indexOfScalar(u8, word, 'x') orelse return error.BadScript;
+ count = std.fmt.parseInt(u32, word[0..x], 10) catch return error.BadScript;
+ every = std.fmt.parseInt(u32, word[x + 1 ..], 10) catch return error.BadScript;
+ word = words.next() orelse return error.BadScript;
}
- };
- 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;
- }
- 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] } } };
- n += 1;
- t += run[2];
- }
- t += 400;
- }
- steps[n] = .{ .at_ms = t, .act = .{ .key = .{ .cp = 'i', .text = "i" } } };
- n += 1;
- t += 300;
- for ([_]struct { u21, u32 }{ .{ pardes.Key.right, 60 }, .{ pardes.Key.down, 100 } }) |run| {
- for (0..8) |_| {
- steps[n] = .{ .at_ms = t, .act = .{ .key = .{ .cp = run[0] } } };
- n += 1;
- t += run[1];
- }
- t += 300;
- }
- steps[n] = .{ .at_ms = t, .act = .{ .key = .{ .cp = pardes.Key.escape } } };
- steps[n + 1] = .{ .at_ms = t + 1000, .act = .end };
- n += 2;
- const out = steps[0..n].*;
- 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;
+ const arg = words.rest();
+ if (std.mem.eql(u8, word, "keys")) {
+ var k: u32 = 0;
+ for (0..count) |_| {
+ var names = std.mem.tokenizeScalar(u8, arg, ' ');
+ while (names.next()) |name| : (k += 1) try steps.append(arena, .{ .at_ms = at + k * every, .act = .{ .key = keyOf(name) orelse return error.BadScript } });
+ }
+ continue;
}
- };
- 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;
+ const Act = @FieldType(Step, "act");
+ const act: Act = switch (std.meta.stringToEnum(std.meta.Tag(Act), word) orelse return error.BadScript) {
+ .wheel => .{ .wheel = std.fmt.parseInt(i8, arg, 10) catch return error.BadScript },
+ .rail_wheel => .{ .rail_wheel = std.fmt.parseInt(i8, arg, 10) catch return error.BadScript },
+ .touch => .{ .touch = std.fmt.parseFloat(f32, arg) catch return error.BadScript },
+ .key => .{ .key = keyOf(arg) orelse return error.BadScript },
+ .phase => .{ .phase = arg },
+ .click => click: {
+ var parts = std.mem.tokenizeScalar(u8, arg, ' ');
+ const button = std.meta.stringToEnum(pardes.Mouse.Button, parts.next() orelse "") orelse return error.BadScript;
+ const where = std.fmt.parseFloat(f32, parts.next() orelse "") catch return error.BadScript;
+ const on = parts.next() orelse "";
+ if (!std.mem.eql(u8, on, "rail") and !std.mem.eql(u8, on, "text")) return error.BadScript;
+ break :click .{ .click = .{ .button = button, .at = where, .rail = std.mem.eql(u8, on, "rail") } };
+ },
+ .paste => .{ .paste = try unescaped(arena, arg) },
+ .exec => .{ .exec = try unescaped(arena, arg) },
+ .end => .end,
+ };
+ for (0..count) |i| try steps.append(arena, .{ .at_ms = at + @as(u32, @intCast(i)) * every, .act = act });
}
- t.* += 500;
+ if (steps.items.len == 0) return error.BadScript;
+ return steps.toOwnedSlice(arena);
}
-/// A PDF's strip put through what moves it (anim 11): a wheel's notches,
-/// then spun; PageDown held; the far jumps ge and gg; a Look at a page and
-/// Back; then slow: a notch at a time, and a touchpad's drag a pixel or so
-/// a frame.
-pub const pdf_scroll = blk: {
- @setEvalBranchQuota(20_000);
- var steps: [512]Step = undefined;
- var n: usize = 0;
- var t: u32 = 1500;
- 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;
- }
- };
- at.add(&steps, &n, t, .{ .exec = "Look ../../docs/design.pdf" });
- t += 2000;
- at.add(&steps, &n, t, .{ .phase = "spin" });
- for (0..6) |_| {
- at.add(&steps, &n, t, .{ .wheel = 1 });
- t += 150;
- }
- for (0..60) |_| {
- at.add(&steps, &n, t, .{ .wheel = 1 });
- t += 8;
- }
- t += 600;
- for (0..30) |_| {
- at.add(&steps, &n, t, .{ .wheel = -1 });
- t += 8;
- }
- t += 600;
- at.add(&steps, &n, t, .{ .phase = "held-pagedown" });
- for (0..20) |_| {
- at.add(&steps, &n, t, .{ .key = .{ .cp = pardes.Key.page_down } });
- t += 33;
- }
- t += 600;
- at.add(&steps, &n, t, .{ .phase = "far-jump" });
- 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 += 800;
- }
- at.add(&steps, &n, t, .{ .exec = "Look ../../docs/design.pdf:12" });
- t += 800;
- at.add(&steps, &n, t, .{ .key = .{ .cp = 'o', .ctrl = true } });
- t += 800;
- at.add(&steps, &n, t, .{ .phase = "slow-notches" });
- for (0..8) |_| {
- at.add(&steps, &n, t, .{ .wheel = 1 });
- t += 300;
- }
- at.add(&steps, &n, t, .{ .phase = "slow-touch" });
- for (0..120) |_| {
- at.add(&steps, &n, t, .{ .touch = 0.06 });
- t += 16;
- }
- t += 600;
- at.add(&steps, &n, t, .{ .phase = "done" });
- at.add(&steps, &n, t, .end);
- const out = steps[0..n].*;
- break :blk out;
-};
-
-/// The same, on a manual of 5363 pages (the Intel SDM, combined volumes,
-/// 27 MB: run where `sdm.pdf` is, a copy): its open, a wheel spun both
-/// ways, PageDown held five seconds, a far Look to page 3000 and Back, gg,
-/// a Look at page 4500, then slow notches and a touchpad's drag.
-pub const pdf_sdm = blk: {
- @setEvalBranchQuota(40_000);
- var steps: [512]Step = undefined;
- var n: usize = 0;
- var t: u32 = 1500;
- 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;
- }
- };
- at.add(&steps, &n, t, .{ .phase = "open" });
- at.add(&steps, &n, t, .{ .exec = "Look sdm.pdf" });
- t += 3000;
- at.add(&steps, &n, t, .{ .phase = "spin" });
- for (0..6) |_| {
- at.add(&steps, &n, t, .{ .wheel = 1 });
- t += 150;
- }
- for (0..60) |_| {
- at.add(&steps, &n, t, .{ .wheel = 1 });
- t += 8;
- }
- t += 600;
- for (0..30) |_| {
- at.add(&steps, &n, t, .{ .wheel = -1 });
- t += 8;
- }
- t += 600;
- at.add(&steps, &n, t, .{ .phase = "held-pagedown" });
- for (0..150) |_| {
- at.add(&steps, &n, t, .{ .key = .{ .cp = pardes.Key.page_down } });
- t += 33;
- }
- t += 800;
- at.add(&steps, &n, t, .{ .phase = "far-jump" });
- at.add(&steps, &n, t, .{ .exec = "Look sdm.pdf:3000" });
- t += 1200;
- at.add(&steps, &n, t, .{ .key = .{ .cp = 'o', .ctrl = true } });
- t += 1200;
- at.add(&steps, &n, t, .{ .key = .{ .cp = 'g', .text = "g" } });
- at.add(&steps, &n, t + 20, .{ .key = .{ .cp = 'g', .text = "g" } });
- t += 1200;
- at.add(&steps, &n, t, .{ .phase = "look-deep" });
- at.add(&steps, &n, t, .{ .exec = "Look sdm.pdf:4500" });
- t += 1500;
- at.add(&steps, &n, t, .{ .phase = "slow-notches" });
- for (0..8) |_| {
- at.add(&steps, &n, t, .{ .wheel = 1 });
- t += 300;
- }
- at.add(&steps, &n, t, .{ .phase = "slow-touch" });
- for (0..120) |_| {
- at.add(&steps, &n, t, .{ .touch = 0.06 });
- t += 16;
- }
- t += 600;
- at.add(&steps, &n, t, .{ .phase = "done" });
- at.add(&steps, &n, t, .end);
- const out = steps[0..n].*;
- break :blk out;
-};
-
-/// Keystroke-to-present, a phase a gesture, on the file the session opened:
-/// test/perf.zig's --live sends these same steps to the tty through a pty
-/// and --live-gui runs them here, so the two frontends are timed alike.
-pub const keystrokes = blk: {
- @setEvalBranchQuota(50_000);
- var steps: [1024]Step = undefined;
- var n: usize = 0;
- var t: u32 = 1500;
- 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;
- }
- };
- at.add(&steps, &n, t, .{ .phase = "key-down" });
- for (0..150) |_| {
- at.add(&steps, &n, t, .{ .key = .{ .cp = 'j', .text = "j" } });
- t += 30;
- }
- at.add(&steps, &n, t, .{ .phase = "key-right" });
- for (0..150) |i| {
- at.add(&steps, &n, t, .{ .key = if (i % 2 == 0) .{ .cp = 'l', .text = "l" } else .{ .cp = 'h', .text = "h" } });
- t += 30;
- }
- at.add(&steps, &n, t, .{ .phase = "edit-char" });
- at.add(&steps, &n, t, .{ .key = .{ .cp = 'i', .text = "i" } });
- t += 30;
- for (0..150) |_| {
- at.add(&steps, &n, t, .{ .key = .{ .cp = 'x', .text = "x" } });
- t += 30;
- }
- at.add(&steps, &n, t, .{ .key = .{ .cp = pardes.Key.escape } });
- t += 300;
- at.add(&steps, &n, t, .{ .phase = "page-down" });
- for (0..60) |_| {
- at.add(&steps, &n, t, .{ .key = .{ .cp = pardes.Key.page_down } });
- t += 50;
- }
- at.add(&steps, &n, t, .{ .phase = "wheel" });
- for (0..150) |_| {
- at.add(&steps, &n, t, .{ .wheel = 1 });
- t += 30;
- }
- t += 500;
- at.add(&steps, &n, t, .{ .phase = "done" });
- at.add(&steps, &n, t, .end);
- const out = steps[0..n].*;
- break :blk out;
-};
-
-/// `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 } }),
+/// A script's key: `<c>`, `space`, `^<c>` or a pardes.Key name.
+fn keyOf(word: []const u8) ?pardes.Key {
+ if (std.mem.eql(u8, word, "space")) return .{ .cp = ' ', .text = " " };
+ if (word.len == 2 and word[0] == '^') return .{ .cp = word[1], .ctrl = true };
+ if (word.len == 1) return .{ .cp = word[0], .text = word };
+ inline for (@typeInfo(pardes.Key).@"struct".decl_names) |name| {
+ if (@TypeOf(@field(pardes.Key, name)) == u21 and std.mem.eql(u8, word, name)) return .{ .cp = @field(pardes.Key, name) };
}
- t += 800;
- add.step(steps, &n, &t, 0, .end);
- return n;
+ return null;
}
-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);
+/// `text` with `\n` a newline and `\\` a backslash.
+fn unescaped(arena: std.mem.Allocator, text: []const u8) error{OutOfMemory}![]const u8 {
+ if (std.mem.indexOfScalar(u8, text, '\\') == null) return text;
+ var out: std.ArrayList(u8) = .empty;
+ var i: usize = 0;
+ while (i < text.len) : (i += 1) {
+ if (text[i] == '\\' and i + 1 < text.len) {
+ i += 1;
+ try out.append(arena, if (text[i] == 'n') '\n' else text[i]);
+ } else try out.append(arena, text[i]);
}
- 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;
-};
+ return out.items;
+}
-/// 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;
-};
+/// The script at `path` (PARDES_FRAMES_DEMO), read and parsed into `arena`.
+pub fn readScript(arena: std.mem.Allocator, io: std.Io, path: []const u8) ![]Step {
+ return parseScript(arena, try std.Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(1 << 22)));
+}
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 };
@@ -1085,11 +451,6 @@ 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);
- // 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;
@@ -1100,3 +461,28 @@ test "frame stats: gaps into a motion count as jank, idle gaps do not, and the r
stats.record(t + 4 * ms, false, false);
try std.testing.expectEqual(@as(u32, 0), stats.last(1)[0][0].latency_us);
}
+
+test "every script in tools/demos reads, its steps in time order, and ends the run" {
+ const io = std.testing.io;
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ var dir = try std.Io.Dir.cwd().openDir(io, "tools/demos", .{ .iterate = true });
+ defer dir.close(io);
+ var it = dir.iterate();
+ var scripts: usize = 0;
+ while (try it.next(io)) |entry| {
+ const steps = try parseScript(arena.allocator(), try dir.readFileAlloc(io, entry.name, arena.allocator(), .limited(1 << 22)));
+ 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);
+ scripts += 1;
+ }
+ try std.testing.expect(scripts > 0);
+ // A line it cannot read is refused, not skipped.
+ try std.testing.expectError(error.BadScript, parseScript(arena.allocator(), "100 key\n200 end\n"));
+ try std.testing.expectError(error.BadScript, parseScript(arena.allocator(), "# nothing\n"));
+ const typed = try parseScript(arena.allocator(), "10 2x5 keys a ^n\n30 paste x\\ny\n");
+ try std.testing.expectEqual(@as(usize, 5), typed.len);
+ try std.testing.expectEqual(@as(u32, 25), typed[3].at_ms);
+ try std.testing.expect(typed[3].act.key.ctrl and typed[3].act.key.cp == 'n');
+ try std.testing.expectEqualStrings("x\ny", typed[4].act.paste);
+}