refactor: improve usefullness of trace-level 1
This commit is contained in:
parent
a1df51a16c
commit
0f6be55dbd
6 changed files with 49 additions and 40 deletions
|
@ -273,6 +273,7 @@ pub fn build_exe(
|
|||
.imports = &.{
|
||||
.{ .name = "thespian", .module = thespian_mod },
|
||||
.{ .name = "log", .module = log_mod },
|
||||
.{ .name = "cbor", .module = cbor_mod },
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
.hash = "1220220dbc7fe91c1c54438193ca765cebbcb7d58f35cdcaee404a9d2245a42a4362",
|
||||
},
|
||||
.thespian = .{
|
||||
.url = "https://github.com/neurocyte/thespian/archive/fdf7a0c3bb9738b68895cbde63dbae00b74f5a73.tar.gz",
|
||||
.hash = "1220042d96513aec54ec3c78dcb28e2529d5f45d0c37bf676860f77f26dce590f9f8",
|
||||
.url = "https://github.com/neurocyte/thespian/archive/448d130c7c772cd09a0de7a197a7866954716fe1.tar.gz",
|
||||
.hash = "1220c289ad35fb2ee0eb82cc66e000af003259d8bf70a9de6d41ae18a68939d9ac82",
|
||||
},
|
||||
.themes = .{
|
||||
.url = "https://github.com/neurocyte/flow-themes/releases/download/master-8b79cf6d79373c142393ec26a81b19f4701f4372/flow-themes.tar.gz",
|
||||
|
|
|
@ -80,13 +80,13 @@ pub fn write_state(self: *Self, writer: anytype) !void {
|
|||
}
|
||||
|
||||
pub fn write_state_v1(self: *Self, writer: anytype) !void {
|
||||
tp.trace(tp.channel.event, .{"write_state_v1"});
|
||||
tp.trace(tp.channel.debug, .{"write_state_v1"});
|
||||
try cbor.writeValue(writer, self.name);
|
||||
var visited: usize = 0;
|
||||
for (self.files.items) |file| {
|
||||
if (file.visited) visited += 1;
|
||||
}
|
||||
tp.trace(tp.channel.event, .{ "write_state_v1", "files", visited });
|
||||
tp.trace(tp.channel.debug, .{ "write_state_v1", "files", visited });
|
||||
try cbor.writeArrayHeader(writer, visited);
|
||||
for (self.files.items) |file| {
|
||||
if (!file.visited) continue;
|
||||
|
@ -95,15 +95,15 @@ pub fn write_state_v1(self: *Self, writer: anytype) !void {
|
|||
try cbor.writeValue(writer, file.mtime);
|
||||
try cbor.writeValue(writer, file.row);
|
||||
try cbor.writeValue(writer, file.col);
|
||||
tp.trace(tp.channel.event, .{ "write_state_v1", "file", file.path, file.mtime, file.row, file.col });
|
||||
tp.trace(tp.channel.debug, .{ "write_state_v1", "file", file.path, file.mtime, file.row, file.col });
|
||||
}
|
||||
try cbor.writeArrayHeader(writer, self.tasks.items.len);
|
||||
tp.trace(tp.channel.event, .{ "write_state_v1", "tasks", self.tasks.items.len });
|
||||
tp.trace(tp.channel.debug, .{ "write_state_v1", "tasks", self.tasks.items.len });
|
||||
for (self.tasks.items) |task| {
|
||||
try cbor.writeArrayHeader(writer, 2);
|
||||
try cbor.writeValue(writer, task.command);
|
||||
try cbor.writeValue(writer, task.mtime);
|
||||
tp.trace(tp.channel.event, .{ "write_state_v1", "task", task.command, task.mtime });
|
||||
tp.trace(tp.channel.debug, .{ "write_state_v1", "task", task.command, task.mtime });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,29 +120,29 @@ pub fn write_state_v0(self: *Self, writer: anytype) !void {
|
|||
}
|
||||
|
||||
pub fn restore_state(self: *Self, data: []const u8) !void {
|
||||
tp.trace(tp.channel.event, .{"restore_state"});
|
||||
errdefer |e| tp.trace(tp.channel.event, .{ "restore_state", "abort", e });
|
||||
tp.trace(tp.channel.debug, .{"restore_state"});
|
||||
errdefer |e| tp.trace(tp.channel.debug, .{ "restore_state", "abort", e });
|
||||
defer self.sort_files_by_mtime();
|
||||
defer self.sort_tasks_by_mtime();
|
||||
var iter: []const u8 = data;
|
||||
_ = cbor.matchValue(&iter, tp.string) catch {};
|
||||
_ = cbor.decodeArrayHeader(&iter) catch |e| switch (e) {
|
||||
error.InvalidType => return self.restore_state_v0(data),
|
||||
else => return tp.trace(tp.channel.event, .{ "restore_state", "unknown format", data }),
|
||||
else => return tp.trace(tp.channel.debug, .{ "restore_state", "unknown format", data }),
|
||||
};
|
||||
return self.restore_state_v1(data);
|
||||
}
|
||||
|
||||
pub fn restore_state_v1(self: *Self, data: []const u8) !void {
|
||||
tp.trace(tp.channel.event, .{"restore_state_v1"});
|
||||
tp.trace(tp.channel.debug, .{"restore_state_v1"});
|
||||
var iter: []const u8 = data;
|
||||
|
||||
var name: []const u8 = undefined;
|
||||
_ = cbor.matchValue(&iter, tp.extract(&name)) catch {};
|
||||
tp.trace(tp.channel.event, .{ "restore_state_v1", "name", name });
|
||||
tp.trace(tp.channel.debug, .{ "restore_state_v1", "name", name });
|
||||
|
||||
var files = try cbor.decodeArrayHeader(&iter);
|
||||
tp.trace(tp.channel.event, .{ "restore_state_v1", "files", files });
|
||||
tp.trace(tp.channel.debug, .{ "restore_state_v1", "files", files });
|
||||
while (files > 0) : (files -= 1) {
|
||||
var path: []const u8 = undefined;
|
||||
var mtime: i128 = undefined;
|
||||
|
@ -157,7 +157,7 @@ pub fn restore_state_v1(self: *Self, data: []const u8) !void {
|
|||
try cbor.skipValue(&iter);
|
||||
continue;
|
||||
}
|
||||
tp.trace(tp.channel.event, .{ "restore_state_v1", "file", path, mtime, row, col });
|
||||
tp.trace(tp.channel.debug, .{ "restore_state_v1", "file", path, mtime, row, col });
|
||||
self.longest_file_path = @max(self.longest_file_path, path.len);
|
||||
const stat = std.fs.cwd().statFile(path) catch continue;
|
||||
switch (stat.kind) {
|
||||
|
@ -167,7 +167,7 @@ pub fn restore_state_v1(self: *Self, data: []const u8) !void {
|
|||
}
|
||||
|
||||
var tasks = try cbor.decodeArrayHeader(&iter);
|
||||
tp.trace(tp.channel.event, .{ "restore_state_v1", "tasks", tasks });
|
||||
tp.trace(tp.channel.debug, .{ "restore_state_v1", "tasks", tasks });
|
||||
while (tasks > 0) : (tasks -= 1) {
|
||||
var command: []const u8 = undefined;
|
||||
var mtime: i64 = undefined;
|
||||
|
@ -178,7 +178,7 @@ pub fn restore_state_v1(self: *Self, data: []const u8) !void {
|
|||
try cbor.skipValue(&iter);
|
||||
continue;
|
||||
}
|
||||
tp.trace(tp.channel.event, .{ "restore_state_v1", "task", command, mtime });
|
||||
tp.trace(tp.channel.debug, .{ "restore_state_v1", "task", command, mtime });
|
||||
(try self.tasks.addOne()).* = .{
|
||||
.command = try self.allocator.dupe(u8, command),
|
||||
.mtime = mtime,
|
||||
|
@ -187,7 +187,7 @@ pub fn restore_state_v1(self: *Self, data: []const u8) !void {
|
|||
}
|
||||
|
||||
pub fn restore_state_v0(self: *Self, data: []const u8) error{ OutOfMemory, IntegerTooLarge, IntegerTooSmall, InvalidType, TooShort }!void {
|
||||
tp.trace(tp.channel.event, .{"restore_state_v0"});
|
||||
tp.trace(tp.channel.debug, .{"restore_state_v0"});
|
||||
defer self.sort_files_by_mtime();
|
||||
var name: []const u8 = undefined;
|
||||
var path: []const u8 = undefined;
|
||||
|
@ -196,7 +196,7 @@ pub fn restore_state_v0(self: *Self, data: []const u8) error{ OutOfMemory, Integ
|
|||
var col: usize = undefined;
|
||||
var iter: []const u8 = data;
|
||||
_ = cbor.matchValue(&iter, tp.extract(&name)) catch {};
|
||||
tp.trace(tp.channel.event, .{ "restore_state_v0", "name", name });
|
||||
tp.trace(tp.channel.debug, .{ "restore_state_v0", "name", name });
|
||||
while (cbor.matchValue(&iter, .{
|
||||
tp.extract(&path),
|
||||
tp.extract(&mtime),
|
||||
|
@ -206,7 +206,7 @@ pub fn restore_state_v0(self: *Self, data: []const u8) error{ OutOfMemory, Integ
|
|||
error.TooShort => return,
|
||||
else => return e,
|
||||
}) {
|
||||
tp.trace(tp.channel.event, .{ "restore_state_v0", "file", path, mtime, row, col });
|
||||
tp.trace(tp.channel.debug, .{ "restore_state_v0", "file", path, mtime, row, col });
|
||||
self.longest_file_path = @max(self.longest_file_path, path.len);
|
||||
const stat = std.fs.cwd().statFile(path) catch continue;
|
||||
switch (stat.kind) {
|
||||
|
|
39
src/main.zig
39
src/main.zig
|
@ -153,30 +153,41 @@ pub fn main() anyerror!void {
|
|||
}
|
||||
} else {
|
||||
if (args.trace_level != 0) {
|
||||
env.enable_all_channels();
|
||||
var threshold: usize = 1;
|
||||
if (args.trace_level < threshold) {
|
||||
env.disable(thespian.channel.widget);
|
||||
if (args.trace_level >= threshold) {
|
||||
env.enable(thespian.channel.debug);
|
||||
}
|
||||
threshold += 1;
|
||||
if (args.trace_level < threshold) {
|
||||
env.disable(thespian.channel.receive);
|
||||
if (args.trace_level >= threshold) {
|
||||
env.enable(thespian.channel.widget);
|
||||
}
|
||||
threshold += 1;
|
||||
if (args.trace_level < threshold) {
|
||||
env.disable(thespian.channel.event);
|
||||
if (args.trace_level >= threshold) {
|
||||
env.enable(thespian.channel.event);
|
||||
}
|
||||
threshold += 1;
|
||||
if (args.trace_level < threshold) {
|
||||
env.disable(thespian.channel.metronome);
|
||||
env.disable(thespian.channel.execute);
|
||||
env.disable(thespian.channel.link);
|
||||
if (args.trace_level >= threshold) {
|
||||
env.enable(thespian.channel.input);
|
||||
}
|
||||
threshold += 1;
|
||||
if (args.trace_level < threshold) {
|
||||
env.disable(thespian.channel.input);
|
||||
env.disable(thespian.channel.send);
|
||||
if (args.trace_level >= threshold) {
|
||||
env.enable(thespian.channel.receive);
|
||||
}
|
||||
threshold += 1;
|
||||
if (args.trace_level >= threshold) {
|
||||
env.enable(thespian.channel.metronome);
|
||||
env.enable(thespian.channel.execute);
|
||||
env.enable(thespian.channel.link);
|
||||
}
|
||||
threshold += 1;
|
||||
if (args.trace_level >= threshold) {
|
||||
env.enable(thespian.channel.send);
|
||||
}
|
||||
threshold += 1;
|
||||
if (args.trace_level >= threshold) {
|
||||
env.enable_all_channels();
|
||||
}
|
||||
|
||||
env.on_trace(trace_to_file);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -607,7 +607,7 @@ const Process = struct {
|
|||
}
|
||||
|
||||
fn persist_project(self: *Process, project: *Project) !void {
|
||||
tp.trace(tp.channel.event, .{ "persist_project", project.name });
|
||||
tp.trace(tp.channel.debug, .{ "persist_project", project.name });
|
||||
self.logger.print("saving: {s}", .{project.name});
|
||||
const file_name = try get_project_state_file_path(self.allocator, project);
|
||||
defer self.allocator.free(file_name);
|
||||
|
@ -619,7 +619,7 @@ const Process = struct {
|
|||
}
|
||||
|
||||
fn restore_project(self: *Process, project: *Project) !void {
|
||||
tp.trace(tp.channel.event, .{ "restore_project", project.name });
|
||||
tp.trace(tp.channel.debug, .{ "restore_project", project.name });
|
||||
const file_name = try get_project_state_file_path(self.allocator, project);
|
||||
defer self.allocator.free(file_name);
|
||||
var file = std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }) catch |e| switch (e) {
|
||||
|
|
|
@ -74,9 +74,6 @@ const TabBar = struct {
|
|||
}
|
||||
|
||||
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||
tp.trace(tp.channel.widget, .{"receive"});
|
||||
tp.trace(tp.channel.widget, m);
|
||||
|
||||
const buffer_manager = tui.get_buffer_manager() orelse @panic("tabs no buffer manager");
|
||||
var file_path: []const u8 = undefined;
|
||||
if (try m.match(.{"next_tab"})) {
|
||||
|
@ -159,7 +156,7 @@ const TabBar = struct {
|
|||
}
|
||||
|
||||
fn select_next_tab(self: *Self) void {
|
||||
tp.trace(tp.channel.widget, .{"select_next_tab"});
|
||||
tp.trace(tp.channel.debug, .{"select_next_tab"});
|
||||
var activate_next = false;
|
||||
var first: ?*const TabBarTab = null;
|
||||
for (self.tabs) |*tab| {
|
||||
|
@ -175,7 +172,7 @@ const TabBar = struct {
|
|||
}
|
||||
|
||||
fn select_previous_tab(self: *Self) void {
|
||||
tp.trace(tp.channel.widget, .{"select_previous_tab"});
|
||||
tp.trace(tp.channel.debug, .{"select_previous_tab"});
|
||||
var goto: ?*const TabBarTab = if (self.tabs.len > 0) &self.tabs[self.tabs.len - 1] else null;
|
||||
for (self.tabs) |*tab| {
|
||||
if (tab.buffer == self.active_buffer)
|
||||
|
|
Loading…
Add table
Reference in a new issue