]> git.proxmox.com Git - mirror_frr.git/blob - lib/trace.h
Merge pull request #6145 from patrasar/pim_nb_code_upstream
[mirror_frr.git] / lib / trace.h
1 /* Tracing macros
2 *
3 * Wraps tracepoint macros for different tracing systems to allow switching
4 * between them at compile time.
5 *
6 * This should not be included directly by source files wishing to provide
7 * tracepoints. Instead, write a header that defines LTTng tracepoints and
8 * which includes this header, and include your new header in your source. USDT
9 * probes do not need tracepoint definitions, but are less capable than LTTng
10 * tracepoints.
11 *
12 * Copyright (C) 2020 NVIDIA Corporation
13 * Quentin Young
14 *
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the Free
17 * Software Foundation; either version 2 of the License, or (at your option)
18 * any later version.
19 *
20 * This program is distributed in the hope that it will be useful, but WITHOUT
21 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
23 * more details.
24 *
25 * You should have received a copy of the GNU General Public License along
26 * with this program; see the file COPYING; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
30 #ifndef _TRACE_H_
31 #define _TRACE_H_
32
33 #ifdef HAVE_CONFIG_H
34 #include "config.h"
35 #endif /* HAVE_CONFIG_H */
36
37 /*
38 * Provided here:
39 * - frrtrace(n, provider, name, ...args...)
40 * - frrtrace_enabled(provider, name)
41 * - frrtracelog(level, msg, ...)
42 *
43 * Use frrtrace() to define tracepoints. n is the number of arguments; this is
44 * needed because USDT probe definitions use DTRACE_PROBEn macros, so the
45 * number of args must be passed in order to expand the correct macro.
46 *
47 * frrtrace_enabled() maps to tracepoint_enabled() under LTTng and is always
48 * true when using USDT. In the future it could be mapped to USDT semaphores
49 * but this is not implemented at present.
50 *
51 * frrtracelog() maps to tracelog() under LTTng and should only be used in zlog
52 * core code, to propagate zlog messages to LTTng. It expands to nothing
53 * otherwise.
54 */
55
56 #if defined(HAVE_LTTNG)
57
58 #define frrtrace(nargs, provider, name, ...) \
59 tracepoint(provider, name, ## __VA_ARGS__)
60 #define frrtrace_enabled(...) tracepoint_enabled(__VA_ARGS__)
61 #define frrtracelog(...) tracelog(__VA_ARGS__)
62
63 #elif defined(HAVE_USDT)
64
65 #include "sys/sdt.h"
66
67 #define frrtrace(nargs, provider, name, ...) \
68 DTRACE_PROBE##nargs(provider, name, ## __VA_ARGS__)
69 #define frrtrace_enabled(...) true
70 #define frrtracelog(...)
71
72 #else
73
74 #define frrtrace(nargs, provider, name, ...) (void)0
75 #define frrtrace_enabled(...) false
76 #define frrtracelog(...) (void)0
77
78 #endif
79
80 #endif /* _TRACE_H_ */