| author | |
| committer | |
| log | c42ff8d7185789845d5986af43aa66f9fdd90c5a |
| tree | 2f495ef22f096092ac6cccf6bee0c9f3925495d6 |
| parent | ccbff4bf3ad50eaba9a89f8dffbd37fd8b5099ad |
| signature |
7 files changed, 31 insertions(+), 20 deletions(-)
README.md+3-2| ... | @@ -15,17 +15,18 @@ in your program: | ... | @@ -15,17 +15,18 @@ in your program: |
| 15 | ```zig | 15 | ```zig |
| 16 | const std = @import("std"); | 16 | const std = @import("std"); |
| 17 | const tracer = @import("tracer"); | 17 | const tracer = @import("tracer"); |
| 18 | const nfs = @import("nfs"); | ||
| 18 | pub const build_options = @import("build_options"); | 19 | pub const build_options = @import("build_options"); |
| 19 | 20 | ||
| 20 | pub const tracer_impl = tracer.spall; // see 'Backends' section below | 21 | pub const tracer_impl = tracer.spall; // see 'Backends' section below |
| 21 | 22 | ||
| 22 | pub fn main() !void { | 23 | pub fn main() !void { |
| 23 | try tracer.init(); | 24 | try tracer.init(.{}); |
| 24 | defer tracer.deinit(); | 25 | defer tracer.deinit(); |
| 25 | 26 | ||
| 26 | // main loop | 27 | // main loop |
| 27 | while (true) { | 28 | while (true) { |
| 28 | try tracer.init_thread(); | 29 | try tracer.init_thread(.{nfs.cwd()}); |
| 29 | defer tracer.deinit_thread(); | 30 | defer tracer.deinit_thread(); |
| 30 | 31 | ||
| 31 | handler(); | 32 | handler(); |
src/chrome.zig+4-2| ... | @@ -14,7 +14,8 @@ threadlocal var path: [:0]const u8 = undefined; | ... | @@ -14,7 +14,8 @@ threadlocal var path: [:0]const u8 = undefined; |
| 14 | threadlocal var file: nfs.File = undefined; | 14 | threadlocal var file: nfs.File = undefined; |
| 15 | threadlocal var buffered_writer: nio.BufferedWriter(4096, nfs.File) = undefined; | 15 | threadlocal var buffered_writer: nio.BufferedWriter(4096, nfs.File) = undefined; |
| 16 | 16 | ||
| 17 | pub fn init() !void { | 17 | pub fn init(args: struct {}) !void { |
| 18 | _ = args; | ||
| 18 | pid = linux.getpid(); | 19 | pid = linux.getpid(); |
| 19 | } | 20 | } |
| 20 | 21 | ||
| ... | @@ -22,7 +23,8 @@ pub fn deinit() void { | ... | @@ -22,7 +23,8 @@ pub fn deinit() void { |
| 22 | // | 23 | // |
| 23 | } | 24 | } |
| 24 | 25 | ||
| 25 | pub fn init_thread(dir: nfs.Dir) !void { | 26 | pub fn init_thread(args: struct { nfs.Dir }) !void { |
| 27 | const dir = args[0]; | ||
| 26 | tid = linux.gettid(); | 28 | tid = linux.gettid(); |
| 27 | 29 | ||
| 28 | path = try std.fmt.allocPrintZ(alloc, "trace.{d}.{d}.chrome.json", .{ pid, tid }); | 30 | path = try std.fmt.allocPrintZ(alloc, "trace.{d}.{d}.chrome.json", .{ pid, tid }); |
src/log.zig+5-4| ... | @@ -1,14 +1,15 @@ | ... | @@ -1,14 +1,15 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const tracer = @import("./mod.zig"); | 2 | const tracer = @import("./mod.zig"); |
| 3 | const log = std.log.scoped(.tracer); | 3 | const log = std.log.scoped(.tracer); |
| 4 | const nfs = @import("nfs"); | ||
| 5 | 4 | ||
| 6 | pub fn init() !void {} | 5 | pub fn init(args: struct {}) !void { |
| 6 | _ = args; | ||
| 7 | } | ||
| 7 | 8 | ||
| 8 | pub fn deinit() void {} | 9 | pub fn deinit() void {} |
| 9 | 10 | ||
| 10 | pub fn init_thread(dir: nfs.Dir) !void { | 11 | pub fn init_thread(args: struct {}) !void { |
| 11 | _ = dir; | 12 | _ = args; |
| 12 | } | 13 | } |
| 13 | 14 | ||
| 14 | pub fn deinit_thread() void {} | 15 | pub fn deinit_thread() void {} |
src/main.zig+6-2| ... | @@ -13,14 +13,18 @@ pub const tracer_impl = switch (build_options.backend) { | ... | @@ -13,14 +13,18 @@ pub const tracer_impl = switch (build_options.backend) { |
| 13 | }; | 13 | }; |
| 14 | 14 | ||
| 15 | pub fn main() !void { | 15 | pub fn main() !void { |
| 16 | try tracer.init(); | 16 | try tracer.init(.{}); |
| 17 | defer tracer.deinit(); | 17 | defer tracer.deinit(); |
| 18 | 18 | ||
| 19 | // main loop | 19 | // main loop |
| 20 | var go = false; | 20 | var go = false; |
| 21 | _ = &go; | 21 | _ = &go; |
| 22 | while (go) { | 22 | while (go) { |
| 23 | try tracer.init_thread(nfs.cwd()); | 23 | try tracer.init_thread(switch (build_options.backend) { |
| 24 | 0, 1 => .{}, | ||
| 25 | 2, 3 => .{nfs.cwd()}, | ||
| 26 | else => comptime unreachable, | ||
| 27 | }); | ||
| 24 | defer tracer.deinit_thread(); | 28 | defer tracer.deinit_thread(); |
| 25 | 29 | ||
| 26 | handler(); | 30 | handler(); |
src/mod.zig+4-4| ... | @@ -11,16 +11,16 @@ pub const log = @import("./log.zig"); | ... | @@ -11,16 +11,16 @@ pub const log = @import("./log.zig"); |
| 11 | pub const chrome = @import("./chrome.zig"); | 11 | pub const chrome = @import("./chrome.zig"); |
| 12 | pub const spall = @import("./spall.zig"); | 12 | pub const spall = @import("./spall.zig"); |
| 13 | 13 | ||
| 14 | pub fn init() !void { | 14 | pub fn init(args: @typeInfo(@TypeOf(impl.init)).@"fn".params[0].type.?) !void { |
| 15 | try impl.init(); | 15 | try impl.init(args); |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | pub fn deinit() void { | 18 | pub fn deinit() void { |
| 19 | impl.deinit(); | 19 | impl.deinit(); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | pub fn init_thread(dir: ?nfs.Dir) !void { | 22 | pub fn init_thread(args: @typeInfo(@TypeOf(impl.init_thread)).@"fn".params[0].type.?) !void { |
| 23 | try impl.init_thread(dir orelse nfs.cwd()); | 23 | try impl.init_thread(args); |
| 24 | started = true; | 24 | started = true; |
| 25 | } | 25 | } |
| 26 | 26 |
src/none.zig+5-4| ... | @@ -1,14 +1,15 @@ | ... | @@ -1,14 +1,15 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const tracer = @import("./mod.zig"); | 2 | const tracer = @import("./mod.zig"); |
| 3 | const log = std.log.scoped(.tracer); | 3 | const log = std.log.scoped(.tracer); |
| 4 | const nfs = @import("nfs"); | ||
| 5 | 4 | ||
| 6 | pub fn init() !void {} | 5 | pub fn init(args: struct {}) !void { |
| 6 | _ = args; | ||
| 7 | } | ||
| 7 | 8 | ||
| 8 | pub fn deinit() void {} | 9 | pub fn deinit() void {} |
| 9 | 10 | ||
| 10 | pub fn init_thread(dir: nfs.Dir) !void { | 11 | pub fn init_thread(args: struct {}) !void { |
| 11 | _ = dir; | 12 | _ = args; |
| 12 | } | 13 | } |
| 13 | 14 | ||
| 14 | pub fn deinit_thread() void {} | 15 | pub fn deinit_thread() void {} |
src/spall.zig+4-2| ... | @@ -14,7 +14,8 @@ threadlocal var path: [:0]const u8 = undefined; | ... | @@ -14,7 +14,8 @@ threadlocal var path: [:0]const u8 = undefined; |
| 14 | threadlocal var file: nfs.File = undefined; | 14 | threadlocal var file: nfs.File = undefined; |
| 15 | threadlocal var buffered_writer: nio.BufferedWriter(4096, nfs.File) = undefined; | 15 | threadlocal var buffered_writer: nio.BufferedWriter(4096, nfs.File) = undefined; |
| 16 | 16 | ||
| 17 | pub fn init() !void { | 17 | pub fn init(args: struct {}) !void { |
| 18 | _ = args; | ||
| 18 | pid = linux.getpid(); | 19 | pid = linux.getpid(); |
| 19 | } | 20 | } |
| 20 | 21 | ||
| ... | @@ -22,7 +23,8 @@ pub fn deinit() void { | ... | @@ -22,7 +23,8 @@ pub fn deinit() void { |
| 22 | // | 23 | // |
| 23 | } | 24 | } |
| 24 | 25 | ||
| 25 | pub fn init_thread(dir: nfs.Dir) !void { | 26 | pub fn init_thread(args: struct { nfs.Dir }) !void { |
| 27 | const dir = args[0]; | ||
| 26 | tid = linux.gettid(); | 28 | tid = linux.gettid(); |
| 27 | 29 | ||
| 28 | path = try std.fmt.allocPrintZ(alloc, "{d}.{d}.spall", .{ pid, tid }); | 30 | path = try std.fmt.allocPrintZ(alloc, "{d}.{d}.spall", .{ pid, tid }); |