trace: add backing file handle
This commit is contained in:
+2
-4
@@ -1,9 +1,7 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const Node = @import("node.zig");
|
const Node = @import("node.zig");
|
||||||
const trace = @import("trace.zig");
|
const Trace = @import("trace.zig").Trace;
|
||||||
const Trace = trace.Trace;
|
|
||||||
const TraceTaskState = trace.TraceTaskState;
|
|
||||||
|
|
||||||
const Scheduler = @This();
|
const Scheduler = @This();
|
||||||
|
|
||||||
@@ -98,7 +96,7 @@ pub fn deinit(self: *Scheduler) void {
|
|||||||
self.tasks.deinit(self.gpa);
|
self.tasks.deinit(self.gpa);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn traceTaskState(self: *Scheduler, task: *const Task, state: TraceTaskState, reason: []const u8) void {
|
fn traceTaskState(self: *Scheduler, task: *const Task, state: Trace.TaskState, reason: []const u8) void {
|
||||||
self.trace.taskState(task.id, task.node, state, reason);
|
self.trace.taskState(task.id, task.node, state, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ real_io: std.Io,
|
|||||||
|
|
||||||
pub fn init(self: *Simulator, gpa: Allocator, real_io: std.Io, seed: u64) void {
|
pub fn init(self: *Simulator, gpa: Allocator, real_io: std.Io, seed: u64) void {
|
||||||
self.gpa = gpa;
|
self.gpa = gpa;
|
||||||
self.trace.init();
|
self.trace.init(real_io);
|
||||||
self.prng = std.Random.DefaultPrng.init(seed);
|
self.prng = std.Random.DefaultPrng.init(seed);
|
||||||
self.scheduler.init(gpa, &self.trace, &self.prng);
|
self.scheduler.init(gpa, &self.trace, &self.prng);
|
||||||
self.network.init(gpa);
|
self.network.init(gpa);
|
||||||
|
|||||||
+45
-24
@@ -1,53 +1,70 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const Io = std.Io;
|
||||||
const Node = @import("node.zig");
|
const Node = @import("node.zig");
|
||||||
const TaskID = @import("scheduler.zig").TaskID;
|
const TaskID = @import("scheduler.zig").TaskID;
|
||||||
|
|
||||||
const PendingTrace = struct {};
|
const PendingTrace = struct {};
|
||||||
|
|
||||||
pub const TraceTaskState = enum {
|
|
||||||
ready,
|
|
||||||
running,
|
|
||||||
sleeping,
|
|
||||||
waiting_futex,
|
|
||||||
waiting_task,
|
|
||||||
failed,
|
|
||||||
returned,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const Trace = struct {
|
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 {
|
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 {
|
pub fn enterTask(self: *Trace, task_id: TaskID, node: *Node) void {
|
||||||
_ = self;
|
if (self.file == null) return;
|
||||||
|
|
||||||
_ = task_id;
|
_ = task_id;
|
||||||
_ = node;
|
_ = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn leaveTask(self: *Trace) void {
|
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 {
|
pub fn taskSpawned(self: *Trace, task_id: TaskID, node: *Node, parent_id: ?TaskID) void {
|
||||||
_ = self;
|
if (self.file == null) return;
|
||||||
|
|
||||||
_ = task_id;
|
_ = task_id;
|
||||||
_ = node;
|
_ = node;
|
||||||
_ = parent_id;
|
_ = parent_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn taskRemoved(self: *Trace, task_id: TaskID, node: *Node) void {
|
pub fn taskRemoved(self: *Trace, task_id: TaskID, node: *Node) void {
|
||||||
_ = self;
|
if (self.file == null) return;
|
||||||
|
|
||||||
_ = task_id;
|
_ = task_id;
|
||||||
_ = node;
|
_ = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn taskState(self: *Trace, task_id: TaskID, node: *Node, state: TraceTaskState, reason: []const u8) void {
|
pub fn taskState(self: *Trace, task_id: TaskID, node: *Node, state: Trace.TaskState, reason: []const u8) void {
|
||||||
_ = self;
|
if (self.file == null) return;
|
||||||
|
|
||||||
_ = task_id;
|
_ = task_id;
|
||||||
_ = node;
|
_ = node;
|
||||||
_ = state;
|
_ = state;
|
||||||
@@ -55,26 +72,30 @@ pub const Trace = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn timeAdvanced(self: *Trace, from: u64, to: u64) void {
|
pub fn timeAdvanced(self: *Trace, from: u64, to: u64) void {
|
||||||
_ = self;
|
if (self.file == null) return;
|
||||||
|
|
||||||
_ = from;
|
_ = from;
|
||||||
_ = to;
|
_ = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn beginIO(self: *Trace, disk: bool, source: std.builtin.SourceLocation) PendingTrace {
|
pub fn beginIO(self: *Trace, disk: bool, source: std.builtin.SourceLocation) PendingTrace {
|
||||||
_ = self;
|
if (self.file == null) return .{};
|
||||||
|
|
||||||
_ = disk;
|
_ = disk;
|
||||||
_ = source;
|
_ = source;
|
||||||
return .{};
|
return .{};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn failIO(self: *Trace, pending_trace: PendingTrace, e: anyerror) void {
|
pub fn failIO(self: *Trace, pending_trace: PendingTrace, e: anyerror) void {
|
||||||
_ = self;
|
if (self.file == null) return;
|
||||||
|
|
||||||
_ = pending_trace;
|
_ = pending_trace;
|
||||||
_ = e;
|
_ = e catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn completeIO(self: *Trace, pending_trace: PendingTrace, result: anytype) void {
|
pub fn completeIO(self: *Trace, pending_trace: PendingTrace, result: anytype) void {
|
||||||
_ = self;
|
if (self.file == null) return;
|
||||||
|
|
||||||
_ = pending_trace;
|
_ = pending_trace;
|
||||||
_ = result;
|
_ = result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user