1 /* Copyright (c) 2017-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
6 * \brief Header file for Tor tracing instrumentation definition.
9 #ifndef TOR_LIB_TRACE_EVENTS_H
10 #define TOR_LIB_TRACE_EVENTS_H
15 * A tracepoint signature is defined as follow:
17 * tor_trace(<subsystem>, <event_name>, <args>...)
19 * If tracing is enabled, the tor_trace() macro is mapped to all possible
20 * instrumentations (defined below). Each instrumentation type MUST define a
21 * top level macro (TOR_TRACE_<type>) so it can be inserted into each
24 * In case no tracing is enabled (HAVE_TRACING), tracepoints are NOP and thus
25 * have no execution cost.
27 * Currently, three types of instrumentation are supported:
29 * log-debug: Every tracepoints is mapped to a log_debug() statement.
31 * User Statically-Defined Tracing (USDT): Probes that can be used with perf,
32 * dtrace, SystemTap, DTrace and BPF Compiler Collection (BCC).
34 * LTTng-UST: Probes for the LTTng Userspace Tracer. If USDT interface
35 * (sdt.h) is available, the USDT probes are also generated by LTTng thus
36 * enabling this instrumentation provides both probes.
39 /** Helper to disambiguate these identifiers in the code base. They should
40 * only be used with tor_trace() like so:
42 * tor_trace(TR_SUBSYS(circuit), TR_EV(opened), ...);
45 #define TR_SUBSYS(name) tor_ ## name
46 #define TR_EV(name) name
50 #define tor_trace(subsystem, event_name, ...) \
52 TOR_TRACE_LOG_DEBUG(subsystem, event_name); \
53 TOR_TRACE_USDT(subsystem, event_name, ## __VA_ARGS__); \
54 TOR_TRACE_LTTNG(subsystem, event_name, ## __VA_ARGS__); \
57 /* This corresponds to the --enable-tracing-instrumentation-log-debug
58 * configure option which maps all tracepoints to a log_debug() statement. */
59 #include "lib/trace/debug.h"
61 /* This corresponds to the --enable-tracing-instrumentation-usdt configure
62 * option which will generate USDT probes for each tracepoints. */
63 #include "lib/trace/usdt/usdt.h"
65 /* This corresponds to the --enable-tracing-instrumentation-lttng configure
66 * option which will generate LTTng probes for each tracepoints. */
67 #include "lib/trace/lttng/lttng.h"
69 #else /* !defined(HAVE_TRACING) */
71 /* Reaching this point, tracing is disabled thus we NOP every tracepoints
72 * declaration so we have no execution cost at runtime. */
73 #define tor_trace(subsystem, name, ...)
75 #endif /* defined(HAVE_TRACING) */
77 #endif /* !defined(TOR_LIB_TRACE_EVENTS_H) */