summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-08 20:56:25 -0300
committerGabriel Schneider <[email protected]>2026-11-08 21:48:19 -0300
commit9a7eb67ba60fed36a65db3d68ab22abf40807682 (patch)
treeb75b8850827357dbcfd1a892817a7506128fea8f
parentb3504bcd020e43d160538d44650bf86627abc21d (diff)
downloadpardes-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
-rw-r--r--src/FrameStats.zig20
-rw-r--r--src/draw.zig2
2 files changed, 19 insertions, 3 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);
diff --git a/src/draw.zig b/src/draw.zig
index c45f7b15..b0ba6687 100644
--- a/src/draw.zig
+++ b/src/draw.zig
@@ -324,7 +324,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
var ov_buf: [384]u8 = undefined;
// The probe's last second (FrameStats); under a virtual clock its
// real-time numbers would make every golden of this box differ.
- var frames_buf: [96]u8 = undefined;
+ var frames_buf: [pardes.FrameStats.summary_max]u8 = undefined;
const virtual = std.c.getenv("PARDES_TEST_CLOCK") != null;
const timings = if (virtual) "frame virtual clock\n" else p.frames.summary(&frames_buf);
const text = std.fmt.bufPrint(