diff options
Diffstat (limited to 'src/lib/trace')
-rw-r--r-- | src/lib/trace/.may_include | 3 | ||||
-rw-r--r-- | src/lib/trace/debug.h | 30 | ||||
-rw-r--r-- | src/lib/trace/events.h | 45 | ||||
-rw-r--r-- | src/lib/trace/include.am | 18 | ||||
-rw-r--r-- | src/lib/trace/trace.c | 17 | ||||
-rw-r--r-- | src/lib/trace/trace.h | 14 |
6 files changed, 127 insertions, 0 deletions
diff --git a/src/lib/trace/.may_include b/src/lib/trace/.may_include new file mode 100644 index 0000000000..45cd13676b --- /dev/null +++ b/src/lib/trace/.may_include @@ -0,0 +1,3 @@ +orconfig.h +lib/log/*.h +lib/trace/*.h diff --git a/src/lib/trace/debug.h b/src/lib/trace/debug.h new file mode 100644 index 0000000000..e35616cf50 --- /dev/null +++ b/src/lib/trace/debug.h @@ -0,0 +1,30 @@ +/* Copyright (c) 2017-2019, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file debug.h + * \brief Macros for debugging our event-trace support. + **/ + +#ifndef TOR_TRACE_LOG_DEBUG_H +#define TOR_TRACE_LOG_DEBUG_H + +#include "lib/log/log.h" + +/* Stringify pre-processor trick. */ +#define XSTR(d) STR(d) +#define STR(s) #s + +/* Send every event to a debug log level. This is useful to debug new trace + * events without implementing them for a specific event tracing framework. + * Note that the arguments are ignored since at this step we do not know the + * types and amount there is. */ + +/* Example on how to map a tracepoint to log_debug(). */ +#undef tor_trace +#define tor_trace(subsystem, name, args...) \ + log_debug(LD_GENERAL, "Trace event \"" XSTR(name) "\" from " \ + "\"" XSTR(subsystem) "\" hit. " \ + "(line "XSTR(__LINE__) ")") + +#endif /* TOR_TRACE_LOG_DEBUG_H */ diff --git a/src/lib/trace/events.h b/src/lib/trace/events.h new file mode 100644 index 0000000000..1e1e7b9d16 --- /dev/null +++ b/src/lib/trace/events.h @@ -0,0 +1,45 @@ +/* Copyright (c) 2017-2019, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file events.h + * \brief Header file for Tor event tracing. + **/ + +#ifndef TOR_TRACE_EVENTS_H +#define TOR_TRACE_EVENTS_H + +/* + * The following defines a generic event tracing function name that has to be + * used to trace events in the code base. + * + * That generic function is then defined by a event tracing framework. For + * instance, the "log debug" framework sends all trace events to log_debug() + * which is defined in src/trace/debug.h which can only be enabled at compile + * time (--enable-event-tracing-debug). + * + * By default, every trace events in the code base are replaced by a NOP. See + * doc/HACKING/Tracing.md for more information on how to use event tracing or + * add events. + */ + +#ifdef TOR_EVENT_TRACING_ENABLED +/* Map every trace event to a per subsystem macro. */ +#define tor_trace(subsystem, name, ...) \ + tor_trace_##subsystem(name, __VA_ARGS__) + +/* Enable event tracing for the debug framework where all trace events are + * mapped to a log_debug(). */ +#ifdef USE_EVENT_TRACING_DEBUG +#include "lib/trace/debug.h" +#endif + +#else /* TOR_EVENT_TRACING_ENABLED */ + +/* Reaching this point, we NOP every event declaration because event tracing + * is not been enabled at compile time. */ +#define tor_trace(subsystem, name, args...) + +#endif /* TOR_EVENT_TRACING_ENABLED */ + +#endif /* TOR_TRACE_EVENTS_H */ diff --git a/src/lib/trace/include.am b/src/lib/trace/include.am new file mode 100644 index 0000000000..6f10c98744 --- /dev/null +++ b/src/lib/trace/include.am @@ -0,0 +1,18 @@ + +noinst_LIBRARIES += \ + src/lib/libtor-trace.a + +TRACEHEADERS = \ + src/lib/trace/trace.h \ + src/lib/trace/events.h + +if USE_EVENT_TRACING_DEBUG +TRACEHEADERS += \ + src/lib/trace/debug.h +endif + +# Library source files. +src_lib_libtor_trace_a_SOURCES = \ + src/lib/trace/trace.c + +noinst_HEADERS+= $(TRACEHEADERS) diff --git a/src/lib/trace/trace.c b/src/lib/trace/trace.c new file mode 100644 index 0000000000..18be63c5a8 --- /dev/null +++ b/src/lib/trace/trace.c @@ -0,0 +1,17 @@ +/* Copyright (c) 2017-2019, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file trace.c + * \brief Common functions for event-tracing implementation + * + * See trace.h and doc/HACKING/Tracing.md for more information. + **/ + +#include "lib/trace/trace.h" + +/** Initialize the tracing library. */ +void +tor_trace_init(void) +{ +} diff --git a/src/lib/trace/trace.h b/src/lib/trace/trace.h new file mode 100644 index 0000000000..606d435568 --- /dev/null +++ b/src/lib/trace/trace.h @@ -0,0 +1,14 @@ +/* Copyright (c) 2017-2019, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file trace.h + * \brief Header for trace.c + **/ + +#ifndef TOR_TRACE_TRACE_H +#define TOR_TRACE_TRACE_H + +void tor_trace_init(void); + +#endif // TOR_TRACE_TRACE_H |