From 77530c1b098834d00abee26436c10cdeb95276c3 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Sun, 8 Jan 2023 19:48:30 -0600 Subject: [PATCH] feat: add scheduler ui --- src/platform.zig | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/platform.zig b/src/platform.zig index 62561f0..8b0a4d9 100644 --- a/src/platform.zig +++ b/src/platform.zig @@ -362,6 +362,28 @@ pub const Gui = struct { zgui.text(" 1% Low: {:0>3} fps", .{stats[2]}); } + { + _ = zgui.begin("Scheduler", .{}); + defer zgui.end(); + + const scheduler = cpu.sched; + + zgui.text("tick: {X:0>16}", .{scheduler.tick}); + zgui.separator(); + + const Event = std.meta.Child(@TypeOf(scheduler.queue.items)); + + var items: [20]Event = undefined; + const len = scheduler.queue.len; + + std.mem.copy(Event, &items, scheduler.queue.items); + std.sort.sort(Event, items[0..len], {}, widgets.eventDesc(Event)); + + for (items[0..len]) |event| { + zgui.text("{X:0>16} | {?}", .{ event.tick, event.kind }); + } + } + { zgui.showDemoWindow(null); } @@ -628,4 +650,12 @@ const widgets = struct { zgui.sameLine(.{}); zgui.text("{s}", .{mode}); } + + fn eventDesc(comptime T: type) fn (void, T, T) bool { + return struct { + fn inner(_: void, left: T, right: T) bool { + return left.tick > right.tick; + } + }.inner; + } };