Giter Club home page Giter Club logo

zig-tracer's Introduction

zig-tracer

Generic tracing library for Zig, supports multiple backends.

Install

  • Supports Zigmod
  • Supports Zig package manager

Usage

in your program:

const std = @import("std");
const tracer = @import("tracer");
pub const build_options = @import("build_options");

pub const tracer_impl = tracer.spall; // see 'Backends' section below

pub fn main() !void {
    try tracer.init();
    defer tracer.deinit();

    // main loop
    while (true) {
        try tracer.init_thread();
        defer tracer.deinit_thread();

        handler();
    }
}

fn handler() void {
    const t = tracer.trace(@src());
    defer t.end();
}

@src() values are sometimes absolute paths so backends may use this value to trim it to only log relative paths

exe_options.addOption(usize, "src_file_trimlen", std.fs.path.dirname(std.fs.path.dirname(@src().file).?).?.len);

Backends

  • none this is the default and causes tracing calls to become a no-op so that tracer can be added to libraries transparently
  • log uses std.log to print on function entrance.
  • chrome writes a json file in the chrome://tracing format described here and here.
  • spall writes a binary file compatible with the Spall profiler.
  • more? feel free to open an issue with requests!

Any custom backend may also be used that defines the following functions:

  • pub fn init() !void
  • pub fn deinit() void
  • pub fn init_thread(dir: std.fs.Dir) !void
  • pub fn deinit_thread() void
  • pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void
  • pub inline fn trace_end(ctx: tracer.Ctx) void

License

MIT

zig-tracer's People

Contributors

nektro avatar rexicon226 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.