-
Notifications
You must be signed in to change notification settings - Fork 7
L3‐LOC: Draft of submission of this work for external conferences
L3-LOC: Lightweight Logging Library: lock-free logging with C++20 source_location{} class, for debugging race conditions.
We present L3: a small, minimally intrusive, thread-safe C library designed for high-speed, printf-style logging. It uses lock-free primitives, does not need other synchronization, so is ideal for debugging race conditions. L3-log message takes less than 2ns if single-threaded and no worse than 30ns even in heavily-threaded and with very verbose logging. This is much faster and less intrusive than in-memory ring-buffer logging with spdlog or logging via buffered fprintf() / write() system-call logging. Both took about 80ns per log message in the single-threaded case, and 300ns per log message when multi-threaded.
L3 logging injected into a simple sender / receiver IPC-message application shows it adds less than 1% overhead even with extremely verbose logging. All benchmarks were run on Intel(R) Core(TM) i7-1365U on Ubuntu Linux 22-04.
Each log message includes the thread ID, and, optionally, the source-location generating the log message. C++20's source_location{} class may be used if it is available. We also present two alternative Line-Of-Code encoding schemes that are more compact (just 4 bytes of footprint for each source-location reference tracked), work with older C++ compilers and with C/C++ code. Messages are stored as raw / binary data in an mmap()'-ed file-based ring-buffer, which is then post-processed, along with the program-binary, to generate a human readable log. This guarantees a fully-flushed and consistent log even if the program crashes.
We believe that L3 is particularly useful for diagnosing race conditions where any added instrumentation perturbs timings to mask or change the problem.
L3-LOC tooling is supported on Ubuntu Linux and on Mac/OSX, with gcc, g++ and clang compilers.