aji/libtracer

语言: C

git: https://github.com/aji/libtracer

跟踪级调试日志框架
trace-level debug logging framework
README.md (中文)

libtracer:跟踪级调试日志框架

libtracer是一个库,可以很容易地包含跟踪级调试日志 通过在一个中存储可配置数量的最近条目来生产系统 磁盘上的环形缓冲区。环形缓冲区大小可以通过条目数限制。

这意味着你可以自由地追踪,而不必担心你的混乱 主日志或使用宝贵的磁盘空间。如果发生意外崩溃,你 立即进行所有printf调试,你可能会很容易 可用。如果事情顺利进行而没有任何事情崩溃,那么你就是这样 牺牲了一个容易配置的磁盘空间。

如果您只想在某些配置中包含跟踪,则可以简单地进行 跳过对tracer_start的调用,并且跟踪器宏的所有调用都将 变为无操作,减去调用函数的成本。

Tracer也是线程安全的。将条目提交到磁盘的行为是 完全原子化并完成内线程序,以便条目安全地进入 返回前操作系统的写缓冲区。由于大部分 跟踪器调用是序列化的,但是,高度过度使用它 并发代码可能会导致锁争用,从而降低代码的速度 显著。

API

void tracer_config_default(tracer_config_t*);
void tracer_config_set_path(tracer_config_t*, const char *path);
void tracer_config_set_max_entries(tracer_config_t*, long max_entries);

void tracer_start(tracer_t*, tracer_config_t*);

#define tracer(T, FORMAT...)

用法示例

#include <tracer.h>

tracer_config_t my_tracer_config;
tracer_t my_tracer;

...

int main(int argc, char *argv[]) {
        tracer_config_default(&my_tracer_config);
        tracer_config_set_path(&my_tracer_config, "tracer.log");
        tracer_config_set_max_entries(&my_tracer_config, 1000);

        tracer_start(&my_tracer, &my_tracer_config);

        tracer(&my_tracer, "opened tracer with %d entries", 1000);

        ...

        tracer(&my_tracer, "iterating over %d values", count);
        for (i=0; i<count; i++) {
                tracer(&my_tracer, "iteration=%d", i);
                tracer(&my_tracer, "  value=%p", values[i]);
                tracer(&my_tracer, "    name=%s", values[i]->name);

                ...

                tracer(&my_tracer, "done, next iteration");
        }
        tracer(&my_tracer, "processing finished");
}

示踪工具

tracer是用于与libtracer输出文件交互的命令行工具。 它的用法可能最好在帮助输出中捕获:

usage: tracer dump FILE

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

libtracer: trace-level debug logging framework

libtracer is a library that makes it easy to include trace-level debug logs in
production systems by storing a configurable number of recent entries in an
on-disk ring buffer. The ring buffer size can be limited by entry count.

This means that you can trace freely without worrying about cluttering your
main logs or using valuable disk space. If an unexpected crash happens, you
instantly have all the printf debugging you probably would have done readily
available. If things run smoothly and nothing crashes, then you've only
sacrificed an easily configurable amount of disk space.

If you only want to include tracing in certain configurations, you can simply
skip the call to tracer_start and all invocations of the tracer macro will
become no-ops, minus the cost of invoking a function.

Tracer is thread-safe as well. The act of committing an entry to disk is
entirely atomic and completed in-thread so that entries are safely in the
operating system's write buffers before returning. Since large parts of
tracer invocations are serialized, however, excessive use of it in highly
concurrent code can cause lock contention that slows your code down
significantly.

API

void tracer_config_default(tracer_config_t*);
void tracer_config_set_path(tracer_config_t*, const char *path);
void tracer_config_set_max_entries(tracer_config_t*, long max_entries);

void tracer_start(tracer_t*, tracer_config_t*);

#define tracer(T, FORMAT...)

Example usage

#include <tracer.h>

tracer_config_t my_tracer_config;
tracer_t my_tracer;

...

int main(int argc, char *argv[]) {
        tracer_config_default(&my_tracer_config);
        tracer_config_set_path(&my_tracer_config, "tracer.log");
        tracer_config_set_max_entries(&my_tracer_config, 1000);

        tracer_start(&my_tracer, &my_tracer_config);

        tracer(&my_tracer, "opened tracer with %d entries", 1000);

        ...

        tracer(&my_tracer, "iterating over %d values", count);
        for (i=0; i<count; i++) {
                tracer(&my_tracer, "iteration=%d", i);
                tracer(&my_tracer, "  value=%p", values[i]);
                tracer(&my_tracer, "    name=%s", values[i]->name);

                ...

                tracer(&my_tracer, "done, next iteration");
        }
        tracer(&my_tracer, "processing finished");
}

The tracer tool

tracer is the command line tool for interacting with libtracer output files.
Its usage is perhaps best captured in the help output:

usage: tracer dump FILE