New testpoint mechanism to instrument binaries for testing
[lttng-tools.git] / src / common / testpoint / testpoint.h
1 /*
2 * Copyright (C) 2012 - Christian Babeux <christian.babeux@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #ifdef NTESTPOINT
19
20 #define testpoint(name)
21 #define TESTPOINT_DECL(name)
22
23 #else /* NTESTPOINT */
24
25 #include <urcu.h> /* for caa_likely/unlikely */
26
27 extern int lttng_testpoint_activated;
28
29 void *lttng_testpoint_lookup(const char *name);
30
31 /*
32 * Testpoint is only active if the global lttng_testpoint_activated flag is
33 * set.
34 */
35 #define testpoint(name) \
36 do { \
37 if (caa_unlikely(lttng_testpoint_activated)) { \
38 __testpoint_##name##_wrapper(); \
39 } \
40 } while (0)
41
42 /*
43 * One wrapper per testpoint is generated. This is to keep track of the symbol
44 * lookup status and the corresponding function pointer, if any.
45 */
46 #define _TESTPOINT_DECL(_name) \
47 static inline void __testpoint_##_name##_wrapper(void) \
48 { \
49 static void (*tp)(void); \
50 static int found; \
51 const char *tp_name = "__testpoint_" #_name; \
52 \
53 if (tp) { \
54 tp(); \
55 } else { \
56 if (!found) { \
57 tp = lttng_testpoint_lookup(tp_name); \
58 if (tp) { \
59 found = 1; \
60 tp(); \
61 } else { \
62 found = -1; \
63 } \
64 } \
65 } \
66 }
67
68 /* Testpoint declaration */
69 #define TESTPOINT_DECL(name) \
70 _TESTPOINT_DECL(name)
71
72 #endif /* NTESTPOINT */
This page took 0.029908 seconds and 4 git commands to generate.