diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-08 20:56:25 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-08 21:48:19 -0300 |
| commit | 9a7eb67ba60fed36a65db3d68ab22abf40807682 (patch) | |
| tree | b75b8850827357dbcfd1a892817a7506128fea8f /src/FrameStats.zig | |
| parent | b3504bcd020e43d160538d44650bf86627abc21d (diff) | |
| download | pardes-9a7eb67ba60fed36a65db3d68ab22abf40807682.tar.gz pardes-9a7eb67ba60fed36a65db3d68ab22abf40807682.zip | |
fix: the Debug box's frame timings blanked once their numbers passed draw.zig's 96-byte buffer (FrameStats.summary's bufPrint caught to ""): the widest summary is 132 bytes, FrameStats.summary_max, summary takes a buffer of that size and cannot fail, and draw's is one; a test fills the ring with the widest numbers
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/FrameStats.zig')
| -rw-r--r-- | src/FrameStats.zig | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/FrameStats.zig b/src/FrameStats.zig index d55b9269..2bbdd32c 100644 --- a/src/FrameStats.zig +++ b/src/FrameStats.zig @@ -244,7 +244,7 @@ pub const Spread = struct { /// 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 { +pub fn summary(stats: *const FrameStats, buf: *[summary_max]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); @@ -256,9 +256,13 @@ pub fn summary(stats: *const FrameStats, buf: []u8) []const u8 { }; 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 ""; + }) catch unreachable; // summary_max holds the widest } +/// `summary`'s widest: its words, seven u32 µs in ms with two places +/// (`4294967.30`) and a u64. +pub const summary_max = 132; + /// Writes the summary and every frame the ring holds to `path`: a header /// of `# ` lines, then one tab-separated line a frame. The long ring goes. pub fn dump(stats: *FrameStats, path: [:0]const u8) void { @@ -475,6 +479,18 @@ test "frame stats: gaps into a motion count as jank, idle gaps do not, and the r try std.testing.expectEqual(@as(u32, 0), stats.last(1)[0][0].latency_us); } +test "frame stats: the Debug box's lines hold the widest numbers, never blank" { + var stats: FrameStats = .{}; + const most = std.math.maxInt(u32); + for (&stats.ring) |*f| f.* = .{ .update_us = most, .gap_us = most, .moving = true, .latency_us = most }; + stats.count = capacity; + stats.jank = std.math.maxInt(u64); + var buf: [summary_max]u8 = undefined; + const said = stats.summary(&buf); + try std.testing.expect(std.mem.endsWith(u8, said, " ms")); + try std.testing.expect(std.mem.indexOf(u8, said, "jank 18446744073709551615\n") != null); +} + test "frame stats: PARDES_FRAMES's long ring takes every frame, up to long_capacity" { const long = try std.testing.allocator.create([long_capacity]Frame); defer std.testing.allocator.destroy(long); |
