trace: add backing file handle

This commit is contained in:
2026-06-08 10:59:31 +02:00
parent 57527c270e
commit 4b2c103e71
3 changed files with 48 additions and 29 deletions
+45 -24
View File
@@ -1,53 +1,70 @@
const std = @import("std");
const Io = std.Io;
const Node = @import("node.zig");
const TaskID = @import("scheduler.zig").TaskID;
const PendingTrace = struct {};
pub const TraceTaskState = enum {
ready,
running,
sleeping,
waiting_futex,
waiting_task,
failed,
returned,
};
pub const Trace = struct {
pub fn init(self: *Trace) void {
_ = self;
pub const TaskState = enum {
ready,
running,
sleeping,
waiting_futex,
waiting_task,
failed,
returned,
};
io: Io,
file: ?Io.File,
pub fn init(self: *Trace, io: Io) void {
self.io = io;
self.file = null;
}
pub fn deinit(self: *Trace) void {
_ = self;
if (self.file == null) return;
self.file.?.close(self.io);
}
pub fn setOutputFile(self: *Trace, path: []const u8) void {
self.file = try Io.Dir.cwd().createFile(self.io, path, .{});
}
pub fn enterTask(self: *Trace, task_id: TaskID, node: *Node) void {
_ = self;
if (self.file == null) return;
_ = task_id;
_ = node;
}
pub fn leaveTask(self: *Trace) void {
_ = self;
if (self.file == null) return;
}
pub fn taskSpawned(self: *Trace, task_id: TaskID, node: *Node, parent_id: ?TaskID) void {
_ = self;
if (self.file == null) return;
_ = task_id;
_ = node;
_ = parent_id;
}
pub fn taskRemoved(self: *Trace, task_id: TaskID, node: *Node) void {
_ = self;
if (self.file == null) return;
_ = task_id;
_ = node;
}
pub fn taskState(self: *Trace, task_id: TaskID, node: *Node, state: TraceTaskState, reason: []const u8) void {
_ = self;
pub fn taskState(self: *Trace, task_id: TaskID, node: *Node, state: Trace.TaskState, reason: []const u8) void {
if (self.file == null) return;
_ = task_id;
_ = node;
_ = state;
@@ -55,26 +72,30 @@ pub const Trace = struct {
}
pub fn timeAdvanced(self: *Trace, from: u64, to: u64) void {
_ = self;
if (self.file == null) return;
_ = from;
_ = to;
}
pub fn beginIO(self: *Trace, disk: bool, source: std.builtin.SourceLocation) PendingTrace {
_ = self;
if (self.file == null) return .{};
_ = disk;
_ = source;
return .{};
}
pub fn failIO(self: *Trace, pending_trace: PendingTrace, e: anyerror) void {
_ = self;
if (self.file == null) return;
_ = pending_trace;
_ = e;
_ = e catch {};
}
pub fn completeIO(self: *Trace, pending_trace: PendingTrace, result: anytype) void {
_ = self;
if (self.file == null) return;
_ = pending_trace;
_ = result;
}