Fix: perform volatile load of tracepoint state
[lttng-ust.git] / include / lttng / tracepoint.h
CommitLineData
b728d87e
MD
1#ifndef _LTTNG_TRACEPOINT_H
2#define _LTTNG_TRACEPOINT_H
3
4/*
e92f3e28 5 * Copyright 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
b728d87e 6 *
e92f3e28
MD
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
b728d87e 13 *
e92f3e28
MD
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
d2428e87
MD
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
b728d87e
MD
24 */
25
76aca78d
MD
26#include <stdio.h>
27#include <stdlib.h>
8fce9e2b 28#include <lttng/tracepoint-types.h>
40b2b5a4 29#include <lttng/tracepoint-rcu.h>
b728d87e 30#include <urcu/compiler.h>
05523fbf 31#include <urcu/system.h>
deb6e540 32#include <dlfcn.h> /* for dlopen */
51920067 33#include <string.h> /* for memset */
b2f60c79 34#include <lttng/ust-config.h> /* for sdt */
a8909ba5 35#include <lttng/ust-compiler.h>
b2f60c79
MD
36
37#ifdef LTTNG_UST_HAVE_SDT_INTEGRATION
38#define SDT_USE_VARIADIC
39#include <sys/sdt.h>
40#else
41#define STAP_PROBEV(...)
42#endif
b728d87e
MD
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
23c8854a
MD
48#define tracepoint(provider, name, ...) \
49 do { \
7cb85a18 50 STAP_PROBEV(provider, name, ## __VA_ARGS__); \
05523fbf 51 if (caa_unlikely(CMM_LOAD_SHARED(__tracepoint_##provider##___##name.state))) \
23c8854a 52 __tracepoint_cb_##provider##___##name(__VA_ARGS__); \
b728d87e
MD
53 } while (0)
54
55#define TP_ARGS(...) __VA_ARGS__
56
57/*
58 * TP_ARGS takes tuples of type, argument separated by a comma.
59 * It can take up to 10 tuples (which means that less than 10 tuples is
60 * fine too).
61 * Each tuple is also separated by a comma.
62 */
df854e41
MD
63#define __TP_COMBINE_TOKENS(_tokena, _tokenb) \
64 _tokena##_tokenb
65#define _TP_COMBINE_TOKENS(_tokena, _tokenb) \
66 __TP_COMBINE_TOKENS(_tokena, _tokenb)
67#define __TP_COMBINE_TOKENS3(_tokena, _tokenb, _tokenc) \
68 _tokena##_tokenb##_tokenc
69#define _TP_COMBINE_TOKENS3(_tokena, _tokenb, _tokenc) \
70 __TP_COMBINE_TOKENS3(_tokena, _tokenb, _tokenc)
71#define __TP_COMBINE_TOKENS4(_tokena, _tokenb, _tokenc, _tokend) \
72 _tokena##_tokenb##_tokenc##_tokend
73#define _TP_COMBINE_TOKENS4(_tokena, _tokenb, _tokenc, _tokend) \
74 __TP_COMBINE_TOKENS4(_tokena, _tokenb, _tokenc, _tokend)
b728d87e 75
4495dd39
MD
76/*
77 * _TP_EXVAR* extract the var names.
78 * _TP_EXVAR1 and _TP_EXDATA_VAR1 are needed for -std=c99.
79 */
b728d87e 80#define _TP_EXVAR0()
4495dd39 81#define _TP_EXVAR1(a)
b728d87e
MD
82#define _TP_EXVAR2(a,b) b
83#define _TP_EXVAR4(a,b,c,d) b,d
84#define _TP_EXVAR6(a,b,c,d,e,f) b,d,f
85#define _TP_EXVAR8(a,b,c,d,e,f,g,h) b,d,f,h
86#define _TP_EXVAR10(a,b,c,d,e,f,g,h,i,j) b,d,f,h,j
87#define _TP_EXVAR12(a,b,c,d,e,f,g,h,i,j,k,l) b,d,f,h,j,l
88#define _TP_EXVAR14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) b,d,f,h,j,l,n
89#define _TP_EXVAR16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) b,d,f,h,j,l,n,p
90#define _TP_EXVAR18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) b,d,f,h,j,l,n,p,r
91#define _TP_EXVAR20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) b,d,f,h,j,l,n,p,r,t
92
93#define _TP_EXDATA_VAR0() __tp_data
4495dd39 94#define _TP_EXDATA_VAR1(a) __tp_data
b728d87e
MD
95#define _TP_EXDATA_VAR2(a,b) __tp_data,b
96#define _TP_EXDATA_VAR4(a,b,c,d) __tp_data,b,d
97#define _TP_EXDATA_VAR6(a,b,c,d,e,f) __tp_data,b,d,f
98#define _TP_EXDATA_VAR8(a,b,c,d,e,f,g,h) __tp_data,b,d,f,h
99#define _TP_EXDATA_VAR10(a,b,c,d,e,f,g,h,i,j) __tp_data,b,d,f,h,j
100#define _TP_EXDATA_VAR12(a,b,c,d,e,f,g,h,i,j,k,l) __tp_data,b,d,f,h,j,l
101#define _TP_EXDATA_VAR14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) __tp_data,b,d,f,h,j,l,n
102#define _TP_EXDATA_VAR16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) __tp_data,b,d,f,h,j,l,n,p
103#define _TP_EXDATA_VAR18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) __tp_data,b,d,f,h,j,l,n,p,r
104#define _TP_EXDATA_VAR20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) __tp_data,b,d,f,h,j,l,n,p,r,t
105
4495dd39
MD
106/*
107 * _TP_EXPROTO* extract tuples of type, var.
108 * _TP_EXPROTO1 and _TP_EXDATA_PROTO1 are needed for -std=c99.
109 */
86637aa6 110#define _TP_EXPROTO0() void
4495dd39 111#define _TP_EXPROTO1(a) void
b728d87e
MD
112#define _TP_EXPROTO2(a,b) a b
113#define _TP_EXPROTO4(a,b,c,d) a b,c d
114#define _TP_EXPROTO6(a,b,c,d,e,f) a b,c d,e f
115#define _TP_EXPROTO8(a,b,c,d,e,f,g,h) a b,c d,e f,g h
116#define _TP_EXPROTO10(a,b,c,d,e,f,g,h,i,j) a b,c d,e f,g h,i j
117#define _TP_EXPROTO12(a,b,c,d,e,f,g,h,i,j,k,l) a b,c d,e f,g h,i j,k l
118#define _TP_EXPROTO14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) a b,c d,e f,g h,i j,k l,m n
119#define _TP_EXPROTO16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) a b,c d,e f,g h,i j,k l,m n,o p
120#define _TP_EXPROTO18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) a b,c d,e f,g h,i j,k l,m n,o p,q r
121#define _TP_EXPROTO20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) a b,c d,e f,g h,i j,k l,m n,o p,q r,s t
122
123#define _TP_EXDATA_PROTO0() void *__tp_data
4495dd39 124#define _TP_EXDATA_PROTO1(a) void *__tp_data
b728d87e
MD
125#define _TP_EXDATA_PROTO2(a,b) void *__tp_data,a b
126#define _TP_EXDATA_PROTO4(a,b,c,d) void *__tp_data,a b,c d
127#define _TP_EXDATA_PROTO6(a,b,c,d,e,f) void *__tp_data,a b,c d,e f
128#define _TP_EXDATA_PROTO8(a,b,c,d,e,f,g,h) void *__tp_data,a b,c d,e f,g h
129#define _TP_EXDATA_PROTO10(a,b,c,d,e,f,g,h,i,j) void *__tp_data,a b,c d,e f,g h,i j
130#define _TP_EXDATA_PROTO12(a,b,c,d,e,f,g,h,i,j,k,l) void *__tp_data,a b,c d,e f,g h,i j,k l
131#define _TP_EXDATA_PROTO14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) void *__tp_data,a b,c d,e f,g h,i j,k l,m n
132#define _TP_EXDATA_PROTO16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) void *__tp_data,a b,c d,e f,g h,i j,k l,m n,o p
133#define _TP_EXDATA_PROTO18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) void *__tp_data,a b,c d,e f,g h,i j,k l,m n,o p,q r
134#define _TP_EXDATA_PROTO20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) void *__tp_data,a b,c d,e f,g h,i j,k l,m n,o p,q r,s t
135
136/* Preprocessor trick to count arguments. Inspired from sdt.h. */
137#define _TP_NARGS(...) __TP_NARGS(__VA_ARGS__, 20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
138#define __TP_NARGS(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, N, ...) N
23c8854a
MD
139#define _TP_PROTO_N(N, ...) _TP_PARAMS(_TP_COMBINE_TOKENS(_TP_EXPROTO, N)(__VA_ARGS__))
140#define _TP_VAR_N(N, ...) _TP_PARAMS(_TP_COMBINE_TOKENS(_TP_EXVAR, N)(__VA_ARGS__))
141#define _TP_DATA_PROTO_N(N, ...) _TP_PARAMS(_TP_COMBINE_TOKENS(_TP_EXDATA_PROTO, N)(__VA_ARGS__))
142#define _TP_DATA_VAR_N(N, ...) _TP_PARAMS(_TP_COMBINE_TOKENS(_TP_EXDATA_VAR, N)(__VA_ARGS__))
b728d87e 143#define _TP_ARGS_PROTO(...) _TP_PROTO_N(_TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__)
23c8854a 144#define _TP_ARGS_VAR(...) _TP_VAR_N(_TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__)
b728d87e 145#define _TP_ARGS_DATA_PROTO(...) _TP_DATA_PROTO_N(_TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__)
23c8854a 146#define _TP_ARGS_DATA_VAR(...) _TP_DATA_VAR_N(_TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__)
b728d87e
MD
147#define _TP_PARAMS(...) __VA_ARGS__
148
96f85541
MD
149/*
150 * The tracepoint cb is marked always inline so we can distinguish
151 * between caller's ip addresses within the probe using the return
152 * address.
153 */
0f2f7e21 154#define _DECLARE_TRACEPOINT(_provider, _name, ...) \
1a206094 155extern struct lttng_ust_tracepoint __tracepoint_##_provider##___##_name; \
17ca0600 156static inline __attribute__((always_inline, unused)) lttng_ust_notrace \
a8909ba5 157void __tracepoint_cb_##_provider##___##_name(_TP_ARGS_PROTO(__VA_ARGS__)); \
96f85541 158static \
a8909ba5 159void __tracepoint_cb_##_provider##___##_name(_TP_ARGS_PROTO(__VA_ARGS__)) \
b728d87e 160{ \
1a206094 161 struct lttng_ust_tracepoint_probe *__tp_probe; \
b728d87e 162 \
d3db6a40 163 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
deb6e540 164 return; \
40b2b5a4 165 tp_rcu_read_lock_bp(); \
0f2f7e21 166 __tp_probe = tp_rcu_dereference_bp(__tracepoint_##_provider##___##_name.probes); \
23c8854a 167 if (caa_unlikely(!__tp_probe)) \
b728d87e
MD
168 goto end; \
169 do { \
1a206094 170 void (*__tp_cb)(void) = __tp_probe->func; \
23c8854a 171 void *__tp_data = __tp_probe->data; \
b728d87e 172 \
23c8854a
MD
173 URCU_FORCE_CAST(void (*)(_TP_ARGS_DATA_PROTO(__VA_ARGS__)), __tp_cb) \
174 (_TP_ARGS_DATA_VAR(__VA_ARGS__)); \
175 } while ((++__tp_probe)->func); \
b728d87e 176end: \
40b2b5a4 177 tp_rcu_read_unlock_bp(); \
b728d87e 178} \
a8909ba5
PW
179static inline lttng_ust_notrace \
180void __tracepoint_register_##_provider##___##_name(char *name, \
181 void (*func)(void), void *data); \
182static inline \
183void __tracepoint_register_##_provider##___##_name(char *name, \
184 void (*func)(void), void *data) \
b728d87e 185{ \
67e5f391
MD
186 __tracepoint_probe_register(name, func, data, \
187 __tracepoint_##_provider##___##_name.signature); \
b728d87e 188} \
a8909ba5
PW
189static inline lttng_ust_notrace \
190void __tracepoint_unregister_##_provider##___##_name(char *name, \
191 void (*func)(void), void *data); \
192static inline \
193void __tracepoint_unregister_##_provider##___##_name(char *name, \
194 void (*func)(void), void *data) \
b728d87e 195{ \
23c8854a 196 __tracepoint_probe_unregister(name, func, data); \
b728d87e
MD
197}
198
fbdeb5ec
MD
199extern int __tracepoint_probe_register(const char *name, void (*func)(void),
200 void *data, const char *signature);
201extern int __tracepoint_probe_unregister(const char *name, void (*func)(void),
202 void *data);
deb6e540 203
51920067
MD
204/*
205 * tracepoint dynamic linkage handling (callbacks). Hidden visibility:
206 * shared across objects in a module/main executable.
207 */
1a206094 208struct lttng_ust_tracepoint_dlopen {
51920067
MD
209 void *liblttngust_handle;
210
1a206094 211 int (*tracepoint_register_lib)(struct lttng_ust_tracepoint * const *tracepoints_start,
51920067 212 int tracepoints_count);
1a206094 213 int (*tracepoint_unregister_lib)(struct lttng_ust_tracepoint * const *tracepoints_start);
51920067
MD
214#ifndef _LGPL_SOURCE
215 void (*rcu_read_lock_sym_bp)(void);
216 void (*rcu_read_unlock_sym_bp)(void);
217 void *(*rcu_dereference_sym_bp)(void *p);
218#endif
219};
220
1a206094 221extern struct lttng_ust_tracepoint_dlopen tracepoint_dlopen;
51920067 222
46c881a7
MD
223#if defined(TRACEPOINT_DEFINE) || defined(TRACEPOINT_CREATE_PROBES)
224
225/*
226 * These weak symbols, the constructor, and destructor take care of
227 * registering only _one_ instance of the tracepoints per shared-ojbect
228 * (or for the whole main program).
229 */
230int __tracepoint_registered
231 __attribute__((weak, visibility("hidden")));
232int __tracepoint_ptrs_registered
233 __attribute__((weak, visibility("hidden")));
1a206094 234struct lttng_ust_tracepoint_dlopen tracepoint_dlopen
46c881a7
MD
235 __attribute__((weak, visibility("hidden")));
236
99234da6
MD
237#ifndef _LGPL_SOURCE
238static inline void lttng_ust_notrace
239__tracepoint__init_urcu_sym(void);
240static inline void
241__tracepoint__init_urcu_sym(void)
242{
243 /*
244 * Symbols below are needed by tracepoint call sites and probe
245 * providers.
246 */
247 if (!tracepoint_dlopen.rcu_read_lock_sym_bp)
248 tracepoint_dlopen.rcu_read_lock_sym_bp =
249 URCU_FORCE_CAST(void (*)(void),
250 dlsym(tracepoint_dlopen.liblttngust_handle,
251 "tp_rcu_read_lock_bp"));
252 if (!tracepoint_dlopen.rcu_read_unlock_sym_bp)
253 tracepoint_dlopen.rcu_read_unlock_sym_bp =
254 URCU_FORCE_CAST(void (*)(void),
255 dlsym(tracepoint_dlopen.liblttngust_handle,
256 "tp_rcu_read_unlock_bp"));
257 if (!tracepoint_dlopen.rcu_dereference_sym_bp)
258 tracepoint_dlopen.rcu_dereference_sym_bp =
259 URCU_FORCE_CAST(void *(*)(void *p),
260 dlsym(tracepoint_dlopen.liblttngust_handle,
261 "tp_rcu_dereference_sym_bp"));
262}
263#else
264static inline void lttng_ust_notrace
265__tracepoint__init_urcu_sym(void);
266static inline void
267__tracepoint__init_urcu_sym(void)
268{
269}
270#endif
271
46c881a7
MD
272static void lttng_ust_notrace __attribute__((constructor))
273__tracepoints__init(void);
274static void
275__tracepoints__init(void)
276{
277 if (__tracepoint_registered++)
278 return;
279
280 if (!tracepoint_dlopen.liblttngust_handle)
281 tracepoint_dlopen.liblttngust_handle =
282 dlopen("liblttng-ust-tracepoint.so.0", RTLD_NOW | RTLD_GLOBAL);
283 if (!tracepoint_dlopen.liblttngust_handle)
284 return;
99234da6 285 __tracepoint__init_urcu_sym();
46c881a7
MD
286}
287
288static void lttng_ust_notrace __attribute__((destructor))
289__tracepoints__destroy(void);
290static void
291__tracepoints__destroy(void)
292{
293 int ret;
294
295 if (--__tracepoint_registered)
296 return;
297 if (tracepoint_dlopen.liblttngust_handle && !__tracepoint_ptrs_registered) {
298 ret = dlclose(tracepoint_dlopen.liblttngust_handle);
76aca78d
MD
299 if (ret) {
300 fprintf(stderr, "Error (%d) in dlclose\n", ret);
301 abort();
302 }
46c881a7
MD
303 memset(&tracepoint_dlopen, 0, sizeof(tracepoint_dlopen));
304 }
305}
306
307#endif
308
deb6e540
MD
309#ifdef TRACEPOINT_DEFINE
310
558b9d86
MD
311/*
312 * These weak symbols, the constructor, and destructor take care of
313 * registering only _one_ instance of the tracepoints per shared-ojbect
314 * (or for the whole main program).
315 */
1a206094 316extern struct lttng_ust_tracepoint * const __start___tracepoints_ptrs[]
558b9d86 317 __attribute__((weak, visibility("hidden")));
1a206094 318extern struct lttng_ust_tracepoint * const __stop___tracepoints_ptrs[]
558b9d86
MD
319 __attribute__((weak, visibility("hidden")));
320
628e1d81
MD
321/*
322 * When TRACEPOINT_PROBE_DYNAMIC_LINKAGE is defined, we do not emit a
323 * unresolved symbol that requires the provider to be linked in. When
324 * TRACEPOINT_PROBE_DYNAMIC_LINKAGE is not defined, we emit an
325 * unresolved symbol that depends on having the provider linked in,
326 * otherwise the linker complains. This deals with use of static
327 * libraries, ensuring that the linker does not remove the provider
328 * object from the executable.
329 */
330#ifdef TRACEPOINT_PROBE_DYNAMIC_LINKAGE
b4f3bc52 331#define _TRACEPOINT_UNDEFINED_REF(provider) NULL
628e1d81 332#else /* TRACEPOINT_PROBE_DYNAMIC_LINKAGE */
b4f3bc52 333#define _TRACEPOINT_UNDEFINED_REF(provider) &__tracepoint_provider_##provider
628e1d81
MD
334#endif /* TRACEPOINT_PROBE_DYNAMIC_LINKAGE */
335
b728d87e
MD
336/*
337 * Note: to allow PIC code, we need to allow the linker to update the pointers
338 * in the __tracepoints_ptrs section.
339 * Therefore, this section is _not_ const (read-only).
340 */
b4f3bc52
MD
341#define _TP_EXTRACT_STRING(...) #__VA_ARGS__
342
343#define _DEFINE_TRACEPOINT(_provider, _name, _args) \
344 extern int __tracepoint_provider_##_provider; \
345 static const char __tp_strtab_##_provider##___##_name[] \
b728d87e 346 __attribute__((section("__tracepoints_strings"))) = \
b4f3bc52 347 #_provider ":" #_name; \
1a206094 348 struct lttng_ust_tracepoint __tracepoint_##_provider##___##_name \
b728d87e 349 __attribute__((section("__tracepoints"))) = \
b4f3bc52
MD
350 { \
351 __tp_strtab_##_provider##___##_name, \
352 0, \
353 NULL, \
354 _TRACEPOINT_UNDEFINED_REF(_provider), \
355 _TP_EXTRACT_STRING(_args), \
10e594aa 356 { }, \
b4f3bc52 357 }; \
1a206094
SM
358 static struct lttng_ust_tracepoint * \
359 __tracepoint_ptr_##_provider##___##_name \
b728d87e 360 __attribute__((used, section("__tracepoints_ptrs"))) = \
b4f3bc52 361 &__tracepoint_##_provider##___##_name;
b728d87e 362
a8909ba5 363static void lttng_ust_notrace __attribute__((constructor))
46c881a7 364__tracepoints__ptrs_init(void);
a8909ba5 365static void
46c881a7 366__tracepoints__ptrs_init(void)
b728d87e 367{
46c881a7 368 if (__tracepoint_ptrs_registered++)
b728d87e 369 return;
46c881a7
MD
370 if (!tracepoint_dlopen.liblttngust_handle)
371 tracepoint_dlopen.liblttngust_handle =
372 dlopen("liblttng-ust-tracepoint.so.0", RTLD_NOW | RTLD_GLOBAL);
51920067 373 if (!tracepoint_dlopen.liblttngust_handle)
deb6e540 374 return;
99234da6 375 tracepoint_dlopen.tracepoint_register_lib =
1a206094 376 URCU_FORCE_CAST(int (*)(struct lttng_ust_tracepoint * const *, int),
99234da6
MD
377 dlsym(tracepoint_dlopen.liblttngust_handle,
378 "tracepoint_register_lib"));
379 tracepoint_dlopen.tracepoint_unregister_lib =
1a206094 380 URCU_FORCE_CAST(int (*)(struct lttng_ust_tracepoint * const *),
99234da6
MD
381 dlsym(tracepoint_dlopen.liblttngust_handle,
382 "tracepoint_unregister_lib"));
383 __tracepoint__init_urcu_sym();
384 if (tracepoint_dlopen.tracepoint_register_lib) {
385 tracepoint_dlopen.tracepoint_register_lib(__start___tracepoints_ptrs,
46c881a7
MD
386 __stop___tracepoints_ptrs -
387 __start___tracepoints_ptrs);
99234da6 388 }
b728d87e
MD
389}
390
a8909ba5 391static void lttng_ust_notrace __attribute__((destructor))
46c881a7 392__tracepoints__ptrs_destroy(void);
a8909ba5 393static void
46c881a7 394__tracepoints__ptrs_destroy(void)
b728d87e 395{
deb6e540 396 int ret;
51920067 397
46c881a7 398 if (--__tracepoint_ptrs_registered)
b728d87e 399 return;
46c881a7
MD
400 if (tracepoint_dlopen.tracepoint_unregister_lib)
401 tracepoint_dlopen.tracepoint_unregister_lib(__start___tracepoints_ptrs);
402 if (tracepoint_dlopen.liblttngust_handle && !__tracepoint_registered) {
51920067 403 ret = dlclose(tracepoint_dlopen.liblttngust_handle);
76aca78d
MD
404 if (ret) {
405 fprintf(stderr, "Error (%d) in dlclose\n", ret);
406 abort();
407 }
51920067 408 memset(&tracepoint_dlopen, 0, sizeof(tracepoint_dlopen));
deb6e540 409 }
b728d87e
MD
410}
411
46c881a7
MD
412#else /* TRACEPOINT_DEFINE */
413
414#define _DEFINE_TRACEPOINT(_provider, _name, _args)
415
416#endif /* #else TRACEPOINT_DEFINE */
deb6e540 417
b728d87e
MD
418#ifdef __cplusplus
419}
420#endif
421
422#endif /* _LTTNG_TRACEPOINT_H */
423
424/* The following declarations must be outside re-inclusion protection. */
425
426#ifndef TRACEPOINT_EVENT
427
428/*
429 * How to use the TRACEPOINT_EVENT macro:
430 *
431 * An example:
432 *
433 * TRACEPOINT_EVENT(someproject_component, event_name,
434 *
435 * * TP_ARGS takes from 0 to 10 "type, field_name" pairs *
436 *
437 * TP_ARGS(int, arg0, void *, arg1, char *, string, size_t, strlen,
438 * long *, arg4, size_t, arg4_len),
439 *
440 * * TP_FIELDS describes the event payload layout in the trace *
441 *
442 * TP_FIELDS(
443 * * Integer, printed in base 10 *
444 * ctf_integer(int, field_a, arg0)
445 *
446 * * Integer, printed with 0x base 16 *
447 * ctf_integer_hex(unsigned long, field_d, arg1)
448 *
449 * * Array Sequence, printed as UTF8-encoded array of bytes *
450 * ctf_array_text(char, field_b, string, FIXED_LEN)
451 * ctf_sequence_text(char, field_c, string, size_t, strlen)
452 *
453 * * String, printed as UTF8-encoded string *
454 * ctf_string(field_e, string)
455 *
456 * * Array sequence of signed integer values *
457 * ctf_array(long, field_f, arg4, FIXED_LEN4)
458 * ctf_sequence(long, field_g, arg4, size_t, arg4_len)
459 * )
460 * )
461 *
462 * More detailed explanation:
463 *
464 * The name of the tracepoint is expressed as a tuple with the provider
465 * and name arguments.
466 *
467 * The provider and name should be a proper C99 identifier.
468 * The "provider" and "name" MUST follow these rules to ensure no
469 * namespace clash occurs:
470 *
471 * For projects (applications and libraries) for which an entity
472 * specific to the project controls the source code and thus its
473 * tracepoints (typically with a scope larger than a single company):
474 *
475 * either:
476 * project_component, event
477 * or:
478 * project, event
479 *
480 * Where "project" is the name of the project,
481 * "component" is the name of the project component (which may
482 * include several levels of sub-components, e.g.
483 * ...component_subcomponent_...) where the tracepoint is located
484 * (optional),
485 * "event" is the name of the tracepoint event.
486 *
487 * For projects issued from a single company wishing to advertise that
488 * the company controls the source code and thus the tracepoints, the
489 * "com_" prefix should be used:
490 *
491 * either:
492 * com_company_project_component, event
493 * or:
494 * com_company_project, event
495 *
496 * Where "company" is the name of the company,
497 * "project" is the name of the project,
498 * "component" is the name of the project component (which may
499 * include several levels of sub-components, e.g.
500 * ...component_subcomponent_...) where the tracepoint is located
501 * (optional),
502 * "event" is the name of the tracepoint event.
503 *
504 * the provider:event identifier is limited to 127 characters.
505 */
506
b728d87e 507#define TRACEPOINT_EVENT(provider, name, args, fields) \
deb6e540 508 _DECLARE_TRACEPOINT(provider, name, _TP_PARAMS(args)) \
b4f3bc52 509 _DEFINE_TRACEPOINT(provider, name, _TP_PARAMS(args))
b728d87e
MD
510
511#define TRACEPOINT_EVENT_CLASS(provider, name, args, fields)
512
513#define TRACEPOINT_EVENT_INSTANCE(provider, _template, name, args) \
deb6e540 514 _DECLARE_TRACEPOINT(provider, name, _TP_PARAMS(args)) \
b4f3bc52 515 _DEFINE_TRACEPOINT(provider, name, _TP_PARAMS(args))
b728d87e
MD
516
517#endif /* #ifndef TRACEPOINT_EVENT */
518
519#ifndef TRACEPOINT_LOGLEVEL
520
521/*
75c5ad79 522 * Tracepoint Loglevels
b728d87e
MD
523 *
524 * Typical use of these loglevels:
525 *
d8de1354 526 * The loglevels go from 0 to 14. Higher numbers imply the most
75c5ad79
MD
527 * verbosity (higher event throughput expected.
528 *
d8de1354
MD
529 * Loglevels 0 through 6, and loglevel 14, match syslog(3) loglevels
530 * semantic. Loglevels 7 through 13 offer more fine-grained selection of
531 * debug information.
75c5ad79 532 *
d8de1354 533 * TRACE_EMERG 0
75c5ad79
MD
534 * system is unusable
535 *
d8de1354 536 * TRACE_ALERT 1
75c5ad79
MD
537 * action must be taken immediately
538 *
d8de1354 539 * TRACE_CRIT 2
75c5ad79
MD
540 * critical conditions
541 *
d8de1354 542 * TRACE_ERR 3
75c5ad79
MD
543 * error conditions
544 *
d8de1354 545 * TRACE_WARNING 4
75c5ad79
MD
546 * warning conditions
547 *
d8de1354 548 * TRACE_NOTICE 5
75c5ad79
MD
549 * normal, but significant, condition
550 *
d8de1354 551 * TRACE_INFO 6
75c5ad79
MD
552 * informational message
553 *
d8de1354
MD
554 * TRACE_DEBUG_SYSTEM 7
555 * debug information with system-level scope (set of programs)
75c5ad79 556 *
d8de1354
MD
557 * TRACE_DEBUG_PROGRAM 8
558 * debug information with program-level scope (set of processes)
75c5ad79 559 *
d8de1354
MD
560 * TRACE_DEBUG_PROCESS 9
561 * debug information with process-level scope (set of modules)
75c5ad79 562 *
d8de1354
MD
563 * TRACE_DEBUG_MODULE 10
564 * debug information with module (executable/library) scope (set of units)
75c5ad79 565 *
d8de1354
MD
566 * TRACE_DEBUG_UNIT 11
567 * debug information with compilation unit scope (set of functions)
75c5ad79 568 *
d8de1354
MD
569 * TRACE_DEBUG_FUNCTION 12
570 * debug information with function-level scope
75c5ad79 571 *
d8de1354
MD
572 * TRACE_DEBUG_LINE 13
573 * debug information with line-level scope (TRACEPOINT_EVENT default)
902e1379 574 *
d8de1354 575 * TRACE_DEBUG 14
1e3b0059 576 * debug-level message
75c5ad79
MD
577 *
578 * Declare tracepoint loglevels for tracepoints. A TRACEPOINT_EVENT
579 * should be declared prior to the the TRACEPOINT_LOGLEVEL for a given
853cda88
MD
580 * tracepoint name. The first field is the provider name, the second
581 * field is the name of the tracepoint, the third field is the loglevel
582 * name.
b728d87e
MD
583 *
584 * TRACEPOINT_LOGLEVEL(< [com_company_]project[_component] >, < event >,
585 * < loglevel_name >)
586 *
75c5ad79
MD
587 * The TRACEPOINT_PROVIDER must be already declared before declaring a
588 * TRACEPOINT_LOGLEVEL.
b728d87e
MD
589 */
590
882a56d7 591enum {
d8de1354
MD
592 TRACE_EMERG = 0,
593 TRACE_ALERT = 1,
594 TRACE_CRIT = 2,
595 TRACE_ERR = 3,
596 TRACE_WARNING = 4,
597 TRACE_NOTICE = 5,
598 TRACE_INFO = 6,
599 TRACE_DEBUG_SYSTEM = 7,
600 TRACE_DEBUG_PROGRAM = 8,
601 TRACE_DEBUG_PROCESS = 9,
602 TRACE_DEBUG_MODULE = 10,
603 TRACE_DEBUG_UNIT = 11,
604 TRACE_DEBUG_FUNCTION = 12,
605 TRACE_DEBUG_LINE = 13,
606 TRACE_DEBUG = 14,
882a56d7
MD
607};
608
05ceaafd 609#define TRACEPOINT_LOGLEVEL(provider, name, loglevel)
b728d87e
MD
610
611#endif /* #ifndef TRACEPOINT_LOGLEVEL */
6ddc916d
MD
612
613#ifndef TRACEPOINT_MODEL_EMF_URI
614
615#define TRACEPOINT_MODEL_EMF_URI(provider, name, uri)
616
617#endif /* #ifndef TRACEPOINT_MODEL_EMF_URI */
This page took 0.054595 seconds and 4 git commands to generate.