authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-09-20 15:53:04 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-09-20 15:53:04 -07:00
log00a7cdb7d1fc8936a070e44c311b07a4aa4c464f
tree765e3e0e69b3d1acb4385941ab4d3641209c086c
parent57975651a2dfee8b4f688b0d0b33344efa824913

add example program


3 files changed, 29 insertions(+), 13 deletions(-)

README.md+1-1
......@@ -14,7 +14,7 @@ in your program:
1414```zig
1515const std = @import("std");
1616const tracer = @import("tracer");
17const build_options = @import("build_options");
17pub const build_options = @import("build_options");
1818
1919pub const tracer_impl = tracer.spall; // supports none, log, spall out of the box
2020
build.zig+8-11
......@@ -4,22 +4,19 @@ pub fn build(b: *std.Build) void {
44 const target = b.standardTargetOptions(.{});
55 const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug;
66
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
712 const exe = b.addExecutable(.{
813 .name = "test",
914 .root_source_file = .{ .path = "src/main.zig" },
1015 .target = target,
1116 .optimize = mode,
1217 });
18 exe.linkLibC();
19 exe.addModule("tracer", mod);
20 exe.addOptions("build_options", options);
1321 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);
2522}
src/main.zig+20-1
......@@ -1,5 +1,24 @@
11const std = @import("std");
2const tracer = @import("tracer");
3pub const build_options = @import("build_options");
4
5pub const tracer_impl = tracer.spall;
26
37pub 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
21fn handler() void {
22 const t = tracer.trace(@src());
23 defer t.end();
524}