39#if !defined(_TEC_TRACE_RES)
40#define _TEC_TRACE_RES MilliSec
59 static std::mutex&
mtx() {
60 static std::mutex __mtx_trace;
76template <
typename Duration = _TEC_TRACE_RES>
83 using Lock = std::lock_guard<std::mutex>;
91 Tracer(
const char* name, std::ostream* out)
103 auto tp = now<Duration>();
104 *out_ <<
"[" << tp.count() <<
"] - " << name_ <<
" exited.\n";
114 auto tp = now<Duration>();
115 *out_ <<
"[" << tp.count() <<
"] + " << name_ <<
" entered.\n";
125 template <
typename T>
128 auto tp = now<Duration>().count();
129 *out_ <<
"[" << tp <<
"] " << name_ <<
": ";
130 println<>(out_, arg);
143 template <
typename T,
typename... Targs>
144 void trace(
const char* fmt,
const T& value, Targs&&... Args) {
146 auto tp = now<Duration>().count();
147 *out_ <<
"[" << tp <<
"] " << name_ <<
": ";
148 println<>(out_, fmt, value, Args...);
171#if defined(_DEBUG) || defined(DEBUG)
175#if defined(_TEC_TRACE_ON)
184#if defined(__TEC_WINDOWS__)
185 #define TEC_ENTER(name) Tracer<> tracer__(name, &std::cout); tracer__.enter()
187 #define TEC_ENTER(name) tec::Tracer<> tracer__(name, &std::cout); tracer__.enter()
198#define TEC_TRACE(...) tracer__.trace(__VA_ARGS__)
211#define TEC_ENTER(name)
222#define TEC_TRACE(...)
A thread-safe tracer for logging entry, exit, and custom messages.
Definition tec_trace.hpp:77
Tracer(const char *name, std::ostream *out)
Constructs a tracer with a name and output stream.
Definition tec_trace.hpp:91
void enter()
Logs an entry message for the tracer.
Definition tec_trace.hpp:112
void trace(const char *fmt, const T &value, Targs &&... Args)
Logs variadic arguments as a formatted trace message.
Definition tec_trace.hpp:144
void trace(const T &arg)
Logs a single argument as a trace message.
Definition tec_trace.hpp:126
~Tracer()
Destructor that logs the exit of the tracer.
Definition tec_trace.hpp:101
std::lock_guard< std::mutex > Lock
Alias for lock guard used for thread safety.
Definition tec_trace.hpp:83
Provides a global mutex for synchronizing trace output.
Definition tec_trace.hpp:53
static std::mutex & mtx()
Retrieves the global trace mutex.
Definition tec_trace.hpp:59
Common definitions and utilities for the tec namespace.
auto name(const Message &msg) noexcept
Retrieves the type name of a message's content for registering the corresponding message handler.
Definition tec_message.hpp:84
Provides variadic print and format utilities for the tec namespace. Implemented for compatibility wit...
Provides time-related utilities and system information functions for the tec namespace.