summaryrefslogtreecommitdiff
path: root/src/FrameStats.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/FrameStats.zig')
-rw-r--r--src/FrameStats.zig20
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);