| author | |
| committer | |
| log | 00a7cdb7d1fc8936a070e44c311b07a4aa4c464f |
| tree | 765e3e0e69b3d1acb4385941ab4d3641209c086c |
| parent | 57975651a2dfee8b4f688b0d0b33344efa824913 |
3 files changed, 29 insertions(+), 13 deletions(-)
README.md+1-1| ... | ... | @@ -14,7 +14,7 @@ in your program: |
| 14 | 14 | ```zig |
| 15 | 15 | const std = @import("std"); |
| 16 | 16 | const tracer = @import("tracer"); |
| 17 | const build_options = @import("build_options"); | |
| 17 | pub const build_options = @import("build_options"); | |
| 18 | 18 | |
| 19 | 19 | pub const tracer_impl = tracer.spall; // supports none, log, spall out of the box |
| 20 | 20 |
build.zig+8-11| ... | ... | @@ -4,22 +4,19 @@ pub fn build(b: *std.Build) void { |
| 4 | 4 | const target = b.standardTargetOptions(.{}); |
| 5 | 5 | const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug; |
| 6 | 6 | |
| 7 | const mod = b.addModule("tracer", .{ .source_file = .{ .path = "src/mod.zig" } }); | |
| 8 | ||
| 9 | const options = b.addOptions(); | |
| 10 | options.addOption(usize, "src_file_trimlen", std.fs.path.dirname(std.fs.path.dirname(@src().file).?).?.len); | |
| 11 | ||
| 7 | 12 | const exe = b.addExecutable(.{ |
| 8 | 13 | .name = "test", |
| 9 | 14 | .root_source_file = .{ .path = "src/main.zig" }, |
| 10 | 15 | .target = target, |
| 11 | 16 | .optimize = mode, |
| 12 | 17 | }); |
| 18 | exe.linkLibC(); | |
| 19 | exe.addModule("tracer", mod); | |
| 20 | exe.addOptions("build_options", options); | |
| 13 | 21 | b.installArtifact(exe); |
| 14 | ||
| 15 | const run_cmd = b.addRunArtifact(exe); | |
| 16 | ||
| 17 | run_cmd.step.dependOn(b.getInstallStep()); | |
| 18 | ||
| 19 | if (b.args) |args| { | |
| 20 | run_cmd.addArgs(args); | |
| 21 | } | |
| 22 | ||
| 23 | const run_step = b.step("run", "Run the app"); | |
| 24 | run_step.dependOn(&run_cmd.step); | |
| 25 | 22 | } |
src/main.zig+20-1| ... | ... | @@ -1,5 +1,24 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const tracer = @import("tracer"); | |
| 3 | pub const build_options = @import("build_options"); | |
| 4 | ||
| 5 | pub const tracer_impl = tracer.spall; | |
| 2 | 6 | |
| 3 | 7 | pub fn main() !void { |
| 4 | std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); | |
| 8 | try tracer.init(); | |
| 9 | defer tracer.deinit(); | |
| 10 | ||
| 11 | // main loop | |
| 12 | var go = false; | |
| 13 | while (go) { | |
| 14 | try tracer.init2(); | |
| 15 | defer tracer.deinit2(); | |
| 16 | ||
| 17 | handler(); | |
| 18 | } | |
| 19 | } | |
| 20 | ||
| 21 | fn handler() void { | |
| 22 | const t = tracer.trace(@src()); | |
| 23 | defer t.end(); | |
| 5 | 24 | } |