2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 #ifndef _LTTNG_TRACEPOINT_H
8 #define _LTTNG_TRACEPOINT_H
12 #include <lttng/tracepoint-types.h>
13 #include <lttng/tracepoint-rcu.h>
14 #include <urcu/compiler.h>
15 #include <urcu/system.h>
16 #include <dlfcn.h> /* for dlopen */
17 #include <string.h> /* for memset */
19 #include <lttng/ust-config.h> /* for sdt */
20 #include <lttng/ust-compiler.h>
21 #include <lttng/ust-tracer.h>
23 #define LTTNG_UST_TRACEPOINT_NAME_LEN_MAX 256
25 #ifdef LTTNG_UST_HAVE_SDT_INTEGRATION
27 * Instead of using SDT_USE_VARIADIC from 'sys/sdt.h', use our own namespaced
28 * macros since the instrumented application might already have included
29 * 'sys/sdt.h' without variadic support.
33 #define _LTTNG_UST_SDT_NARG(...) \
34 __LTTNG_UST_SDT_NARG(__VA_ARGS__, 12,11,10,9,8,7,6,5,4,3,2,1,0)
36 #define __LTTNG_UST_SDT_NARG(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12, N, ...) N
38 #define _LTTNG_UST_SDT_PROBE_N(provider, name, N, ...) \
39 _SDT_PROBE(provider, name, N, (__VA_ARGS__))
41 #define LTTNG_UST_STAP_PROBEV(provider, name, ...) \
42 _LTTNG_UST_SDT_PROBE_N(provider, name, _LTTNG_UST_SDT_NARG(0, ##__VA_ARGS__), ##__VA_ARGS__)
45 #define LTTNG_UST_STAP_PROBEV(...)
52 #define tracepoint_enabled(provider, name) \
53 caa_unlikely(CMM_LOAD_SHARED(__tracepoint_##provider##___##name.state))
55 #define do_tracepoint(provider, name, ...) \
56 __tracepoint_cb_##provider##___##name(__VA_ARGS__)
58 #define tracepoint(provider, name, ...) \
60 LTTNG_UST_STAP_PROBEV(provider, name, ## __VA_ARGS__); \
61 if (tracepoint_enabled(provider, name)) \
62 do_tracepoint(provider, name, __VA_ARGS__); \
65 #define TP_ARGS(...) __VA_ARGS__
68 * TP_ARGS takes tuples of type, argument separated by a comma.
69 * It can take up to 10 tuples (which means that less than 10 tuples is
71 * Each tuple is also separated by a comma.
73 #define __TP_COMBINE_TOKENS(_tokena, _tokenb) \
75 #define _TP_COMBINE_TOKENS(_tokena, _tokenb) \
76 __TP_COMBINE_TOKENS(_tokena, _tokenb)
77 #define __TP_COMBINE_TOKENS3(_tokena, _tokenb, _tokenc) \
78 _tokena##_tokenb##_tokenc
79 #define _TP_COMBINE_TOKENS3(_tokena, _tokenb, _tokenc) \
80 __TP_COMBINE_TOKENS3(_tokena, _tokenb, _tokenc)
81 #define __TP_COMBINE_TOKENS4(_tokena, _tokenb, _tokenc, _tokend) \
82 _tokena##_tokenb##_tokenc##_tokend
83 #define _TP_COMBINE_TOKENS4(_tokena, _tokenb, _tokenc, _tokend) \
84 __TP_COMBINE_TOKENS4(_tokena, _tokenb, _tokenc, _tokend)
87 * _TP_EXVAR* extract the var names.
88 * _TP_EXVAR1 and _TP_EXDATA_VAR1 are needed for -std=c99.
92 #define _TP_EXVAR2(a,b) b
93 #define _TP_EXVAR4(a,b,c,d) b,d
94 #define _TP_EXVAR6(a,b,c,d,e,f) b,d,f
95 #define _TP_EXVAR8(a,b,c,d,e,f,g,h) b,d,f,h
96 #define _TP_EXVAR10(a,b,c,d,e,f,g,h,i,j) b,d,f,h,j
97 #define _TP_EXVAR12(a,b,c,d,e,f,g,h,i,j,k,l) b,d,f,h,j,l
98 #define _TP_EXVAR14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) b,d,f,h,j,l,n
99 #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
100 #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
101 #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
103 #define _TP_EXDATA_VAR0() __tp_data
104 #define _TP_EXDATA_VAR1(a) __tp_data
105 #define _TP_EXDATA_VAR2(a,b) __tp_data,b
106 #define _TP_EXDATA_VAR4(a,b,c,d) __tp_data,b,d
107 #define _TP_EXDATA_VAR6(a,b,c,d,e,f) __tp_data,b,d,f
108 #define _TP_EXDATA_VAR8(a,b,c,d,e,f,g,h) __tp_data,b,d,f,h
109 #define _TP_EXDATA_VAR10(a,b,c,d,e,f,g,h,i,j) __tp_data,b,d,f,h,j
110 #define _TP_EXDATA_VAR12(a,b,c,d,e,f,g,h,i,j,k,l) __tp_data,b,d,f,h,j,l
111 #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
112 #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
113 #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
114 #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
117 * _TP_EXPROTO* extract tuples of type, var.
118 * _TP_EXPROTO1 and _TP_EXDATA_PROTO1 are needed for -std=c99.
120 #define _TP_EXPROTO0() void
121 #define _TP_EXPROTO1(a) void
122 #define _TP_EXPROTO2(a,b) a b
123 #define _TP_EXPROTO4(a,b,c,d) a b,c d
124 #define _TP_EXPROTO6(a,b,c,d,e,f) a b,c d,e f
125 #define _TP_EXPROTO8(a,b,c,d,e,f,g,h) a b,c d,e f,g h
126 #define _TP_EXPROTO10(a,b,c,d,e,f,g,h,i,j) a b,c d,e f,g h,i j
127 #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
128 #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
129 #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
130 #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
131 #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
133 #define _TP_EXDATA_PROTO0() void *__tp_data
134 #define _TP_EXDATA_PROTO1(a) void *__tp_data
135 #define _TP_EXDATA_PROTO2(a,b) void *__tp_data,a b
136 #define _TP_EXDATA_PROTO4(a,b,c,d) void *__tp_data,a b,c d
137 #define _TP_EXDATA_PROTO6(a,b,c,d,e,f) void *__tp_data,a b,c d,e f
138 #define _TP_EXDATA_PROTO8(a,b,c,d,e,f,g,h) void *__tp_data,a b,c d,e f,g h
139 #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
140 #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
141 #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
142 #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
143 #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
144 #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
146 /* Preprocessor trick to count arguments. Inspired from sdt.h. */
147 #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)
148 #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
149 #define _TP_PROTO_N(N, ...) _TP_PARAMS(_TP_COMBINE_TOKENS(_TP_EXPROTO, N)(__VA_ARGS__))
150 #define _TP_VAR_N(N, ...) _TP_PARAMS(_TP_COMBINE_TOKENS(_TP_EXVAR, N)(__VA_ARGS__))
151 #define _TP_DATA_PROTO_N(N, ...) _TP_PARAMS(_TP_COMBINE_TOKENS(_TP_EXDATA_PROTO, N)(__VA_ARGS__))
152 #define _TP_DATA_VAR_N(N, ...) _TP_PARAMS(_TP_COMBINE_TOKENS(_TP_EXDATA_VAR, N)(__VA_ARGS__))
153 #define _TP_ARGS_PROTO(...) _TP_PROTO_N(_TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__)
154 #define _TP_ARGS_VAR(...) _TP_VAR_N(_TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__)
155 #define _TP_ARGS_DATA_PROTO(...) _TP_DATA_PROTO_N(_TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__)
156 #define _TP_ARGS_DATA_VAR(...) _TP_DATA_VAR_N(_TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__)
157 #define _TP_PARAMS(...) __VA_ARGS__
160 * sizeof(#_provider) - 1 : length of the provider string (excluding \0).
161 * sizeof(#_name) - 1 : length of the name string (excluding \0).
162 * + 1 : separator between provider and event name.
164 * Upper bound (inclusive) is LTTNG_UST_TRACEPOINT_NAME_LEN_MAX - 1 to
168 * left hand side: sizeof(#_provider) - 1 + sizeof(#_name) - 1 + 1
169 * right hand side: LTTNG_UST_TRACEPOINT_NAME_LEN_MAX - 1
170 * operator: <= (inclusive)
171 * Simplified in the code below.
173 #define lttng_ust_tracepoint_validate_name_len(_provider, _name) \
174 lttng_ust_static_assert(sizeof(#_provider) + sizeof(#_name) <= LTTNG_UST_TRACEPOINT_NAME_LEN_MAX, \
175 "Tracepoint name length is too long", \
176 Tracepoint_name_length_is_too_long)
179 * The tracepoint cb is marked always inline so we can distinguish
180 * between caller's ip addresses within the probe using the return
183 #define _DECLARE_TRACEPOINT(_provider, _name, ...) \
184 extern struct lttng_ust_tracepoint __tracepoint_##_provider##___##_name; \
186 void __tracepoint_cb_##_provider##___##_name(_TP_ARGS_PROTO(__VA_ARGS__)) \
187 __attribute__((always_inline, unused)) lttng_ust_notrace; \
189 void __tracepoint_cb_##_provider##___##_name(_TP_ARGS_PROTO(__VA_ARGS__)) \
191 struct lttng_ust_tracepoint_probe *__tp_probe; \
193 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
195 tp_rcu_read_lock(); \
196 __tp_probe = tp_rcu_dereference(__tracepoint_##_provider##___##_name.probes); \
197 if (caa_unlikely(!__tp_probe)) \
200 void (*__tp_cb)(void) = __tp_probe->func; \
201 void *__tp_data = __tp_probe->data; \
203 URCU_FORCE_CAST(void (*)(_TP_ARGS_DATA_PROTO(__VA_ARGS__)), __tp_cb) \
204 (_TP_ARGS_DATA_VAR(__VA_ARGS__)); \
205 } while ((++__tp_probe)->func); \
207 tp_rcu_read_unlock(); \
210 void __tracepoint_register_##_provider##___##_name(char *name, \
211 void (*func)(void), void *data) \
214 void __tracepoint_register_##_provider##___##_name(char *name, \
215 void (*func)(void), void *data) \
217 __tracepoint_probe_register(name, func, data, \
218 __tracepoint_##_provider##___##_name.signature); \
221 void __tracepoint_unregister_##_provider##___##_name(char *name, \
222 void (*func)(void), void *data) \
225 void __tracepoint_unregister_##_provider##___##_name(char *name, \
226 void (*func)(void), void *data) \
228 __tracepoint_probe_unregister(name, func, data); \
231 extern int __tracepoint_probe_register(const char *name
, void (*func
)(void),
232 void *data
, const char *signature
);
233 extern int __tracepoint_probe_unregister(const char *name
, void (*func
)(void),
237 * tracepoint dynamic linkage handling (callbacks). Hidden visibility:
238 * shared across objects in a module/main executable.
240 * IMPORTANT: this structure is part of the ABI between instrumented
241 * applications and UST. Fields need to be only added at the end, never
242 * reordered, never removed.
244 * The field @struct_size should be used to determine the size of the
245 * structure. It should be queried before using additional fields added
246 * at the end of the structure.
248 struct lttng_ust_tracepoint_dlopen
{
249 uint32_t struct_size
;
251 void *liblttngust_handle
;
253 int (*tracepoint_register_lib
)(struct lttng_ust_tracepoint
* const *tracepoints_start
,
254 int tracepoints_count
);
255 int (*tracepoint_unregister_lib
)(struct lttng_ust_tracepoint
* const *tracepoints_start
);
256 void (*rcu_read_lock_sym
)(void);
257 void (*rcu_read_unlock_sym
)(void);
258 void *(*rcu_dereference_sym
)(void *p
);
260 /* End of base ABI. Fields below should be used after checking struct_size. */
263 extern struct lttng_ust_tracepoint_dlopen tracepoint_dlopen
;
264 extern struct lttng_ust_tracepoint_dlopen
*tracepoint_dlopen_ptr
;
267 * These weak symbols, the constructor, and destructor take care of
268 * registering only _one_ instance of the tracepoints per shared-ojbect
269 * (or for the whole main program).
271 int __tracepoint_registered
272 __attribute__((weak
, visibility("hidden")));
273 int __tracepoint_ptrs_registered
274 __attribute__((weak
, visibility("hidden")));
275 struct lttng_ust_tracepoint_dlopen tracepoint_dlopen
276 __attribute__((weak
, visibility("hidden"))) = {
277 .struct_size
= sizeof(struct lttng_ust_tracepoint_dlopen
),
280 * Deal with gcc O1 optimisation issues with weak hidden symbols. gcc
281 * 4.8 and prior does not have the same behavior for symbol scoping on
282 * 32-bit powerpc depending on the object size: symbols for objects of 8
283 * bytes or less have the same address throughout a module, whereas they
284 * have different addresses between compile units for objects larger
285 * than 8 bytes. Add this pointer indirection to ensure that the symbol
286 * scoping match that of the other weak hidden symbols found in this
289 struct lttng_ust_tracepoint_dlopen
*tracepoint_dlopen_ptr
290 __attribute__((weak
, visibility("hidden")));
293 * Tracepoint dynamic linkage handling (callbacks). Hidden visibility: shared
294 * across objects in a module/main executable. The callbacks are used to
295 * control and check if the destructors should be executed.
297 * IMPORTANT: this structure is part of the ABI between instrumented
298 * applications and UST. Fields need to be only added at the end, never
299 * reordered, never removed.
301 * The field @struct_size should be used to determine the size of the
302 * structure. It should be queried before using additional fields added
303 * at the end of the structure.
305 struct lttng_ust_tracepoint_destructors_syms
{
306 uint32_t struct_size
;
308 void (*tracepoint_disable_destructors
)(void);
309 int (*tracepoint_get_destructors_state
)(void);
311 /* End of base ABI. Fields below should be used after checking struct_size. */
314 extern struct lttng_ust_tracepoint_destructors_syms tracepoint_destructors_syms
;
315 extern struct lttng_ust_tracepoint_destructors_syms
*tracepoint_destructors_syms_ptr
;
317 struct lttng_ust_tracepoint_destructors_syms tracepoint_destructors_syms
318 __attribute__((weak
, visibility("hidden"))) = {
319 .struct_size
= sizeof(struct lttng_ust_tracepoint_destructors_syms
),
321 struct lttng_ust_tracepoint_destructors_syms
*tracepoint_destructors_syms_ptr
322 __attribute__((weak
, visibility("hidden")));
324 static inline void tracepoint_disable_destructors(void)
326 if (!tracepoint_dlopen_ptr
)
327 tracepoint_dlopen_ptr
= &tracepoint_dlopen
;
328 if (!tracepoint_destructors_syms_ptr
)
329 tracepoint_destructors_syms_ptr
= &tracepoint_destructors_syms
;
330 if (tracepoint_dlopen_ptr
->liblttngust_handle
331 && tracepoint_destructors_syms_ptr
->tracepoint_disable_destructors
)
332 tracepoint_destructors_syms_ptr
->tracepoint_disable_destructors();
337 __tracepoint__init_urcu_sym(void)
340 __tracepoint__init_urcu_sym(void)
342 if (!tracepoint_dlopen_ptr
)
343 tracepoint_dlopen_ptr
= &tracepoint_dlopen
;
345 * Symbols below are needed by tracepoint call sites and probe
348 if (!tracepoint_dlopen_ptr
->rcu_read_lock_sym
)
349 tracepoint_dlopen_ptr
->rcu_read_lock_sym
=
350 URCU_FORCE_CAST(void (*)(void),
351 dlsym(tracepoint_dlopen_ptr
->liblttngust_handle
,
352 "tp_rcu_read_lock"));
353 if (!tracepoint_dlopen_ptr
->rcu_read_unlock_sym
)
354 tracepoint_dlopen_ptr
->rcu_read_unlock_sym
=
355 URCU_FORCE_CAST(void (*)(void),
356 dlsym(tracepoint_dlopen_ptr
->liblttngust_handle
,
357 "tp_rcu_read_unlock"));
358 if (!tracepoint_dlopen_ptr
->rcu_dereference_sym
)
359 tracepoint_dlopen_ptr
->rcu_dereference_sym
=
360 URCU_FORCE_CAST(void *(*)(void *p
),
361 dlsym(tracepoint_dlopen_ptr
->liblttngust_handle
,
362 "tp_rcu_dereference_sym"));
366 __tracepoint__init_urcu_sym(void)
369 __tracepoint__init_urcu_sym(void)
375 __tracepoints__init(void)
376 lttng_ust_notrace
__attribute__((constructor
));
378 __tracepoints__init(void)
380 if (__tracepoint_registered
++) {
381 if (!tracepoint_dlopen_ptr
->liblttngust_handle
)
383 __tracepoint__init_urcu_sym();
387 if (!tracepoint_dlopen_ptr
)
388 tracepoint_dlopen_ptr
= &tracepoint_dlopen
;
389 if (!tracepoint_dlopen_ptr
->liblttngust_handle
)
390 tracepoint_dlopen_ptr
->liblttngust_handle
=
391 dlopen(LTTNG_UST_TRACEPOINT_LIB_SONAME
, RTLD_NOW
| RTLD_GLOBAL
);
392 if (!tracepoint_dlopen_ptr
->liblttngust_handle
)
394 __tracepoint__init_urcu_sym();
398 __tracepoints__destroy(void)
399 lttng_ust_notrace
__attribute__((destructor
));
401 __tracepoints__destroy(void)
405 if (--__tracepoint_registered
)
407 if (!tracepoint_dlopen_ptr
)
408 tracepoint_dlopen_ptr
= &tracepoint_dlopen
;
409 if (!tracepoint_destructors_syms_ptr
)
410 tracepoint_destructors_syms_ptr
= &tracepoint_destructors_syms
;
411 if (!tracepoint_dlopen_ptr
->liblttngust_handle
)
413 if (__tracepoint_ptrs_registered
)
416 * Lookup if destructors must be executed using the new method.
418 if (tracepoint_destructors_syms_ptr
->tracepoint_get_destructors_state
419 && !tracepoint_destructors_syms_ptr
->tracepoint_get_destructors_state()) {
421 * The tracepoint_get_destructors_state symbol was found with
422 * dlsym but its returned value is 0 meaning that destructors
423 * must not be executed.
427 ret
= dlclose(tracepoint_dlopen_ptr
->liblttngust_handle
);
429 fprintf(stderr
, "Error (%d) in dlclose\n", ret
);
432 memset(tracepoint_dlopen_ptr
, 0, sizeof(*tracepoint_dlopen_ptr
));
435 #ifdef TRACEPOINT_DEFINE
438 * These weak symbols, the constructor, and destructor take care of
439 * registering only _one_ instance of the tracepoints per shared-ojbect
440 * (or for the whole main program).
442 extern struct lttng_ust_tracepoint
* const __start___tracepoints_ptrs
[]
443 __attribute__((weak
, visibility("hidden")));
444 extern struct lttng_ust_tracepoint
* const __stop___tracepoints_ptrs
[]
445 __attribute__((weak
, visibility("hidden")));
448 * When TRACEPOINT_PROBE_DYNAMIC_LINKAGE is defined, we do not emit a
449 * unresolved symbol that requires the provider to be linked in. When
450 * TRACEPOINT_PROBE_DYNAMIC_LINKAGE is not defined, we emit an
451 * unresolved symbol that depends on having the provider linked in,
452 * otherwise the linker complains. This deals with use of static
453 * libraries, ensuring that the linker does not remove the provider
454 * object from the executable.
456 #ifdef TRACEPOINT_PROBE_DYNAMIC_LINKAGE
457 #define _TRACEPOINT_UNDEFINED_REF(provider) NULL
458 #else /* TRACEPOINT_PROBE_DYNAMIC_LINKAGE */
459 #define _TRACEPOINT_UNDEFINED_REF(provider) &__tracepoint_provider_##provider
460 #endif /* TRACEPOINT_PROBE_DYNAMIC_LINKAGE */
463 * Note: to allow PIC code, we need to allow the linker to update the pointers
464 * in the __tracepoints_ptrs section.
465 * Therefore, this section is _not_ const (read-only).
467 #define _TP_EXTRACT_STRING(...) #__VA_ARGS__
469 #define _DEFINE_TRACEPOINT(_provider, _name, _args) \
470 lttng_ust_tracepoint_validate_name_len(_provider, _name); \
471 extern int __tracepoint_provider_##_provider; \
472 static const char __tp_strtab_##_provider##___##_name[] \
473 __attribute__((section("__tracepoints_strings"))) = \
474 #_provider ":" #_name; \
475 struct lttng_ust_tracepoint __tracepoint_##_provider##___##_name \
476 __attribute__((section("__tracepoints"))) = { \
477 sizeof(struct lttng_ust_tracepoint), \
478 __tp_strtab_##_provider##___##_name, \
481 _TRACEPOINT_UNDEFINED_REF(_provider), \
482 _TP_EXTRACT_STRING(_args), \
484 static struct lttng_ust_tracepoint * \
485 __tracepoint_ptr_##_provider##___##_name \
486 __attribute__((section("__tracepoints_ptrs"), used)) \
487 __lttng_ust_variable_attribute_no_sanitize_address = \
488 &__tracepoint_##_provider##___##_name;
491 __tracepoints__ptrs_init(void)
492 lttng_ust_notrace
__attribute__((constructor
));
494 __tracepoints__ptrs_init(void)
496 if (__tracepoint_ptrs_registered
++)
498 if (!tracepoint_dlopen_ptr
)
499 tracepoint_dlopen_ptr
= &tracepoint_dlopen
;
500 if (!tracepoint_dlopen_ptr
->liblttngust_handle
)
501 tracepoint_dlopen_ptr
->liblttngust_handle
=
502 dlopen(LTTNG_UST_TRACEPOINT_LIB_SONAME
, RTLD_NOW
| RTLD_GLOBAL
);
503 if (!tracepoint_dlopen_ptr
->liblttngust_handle
)
505 if (!tracepoint_destructors_syms_ptr
)
506 tracepoint_destructors_syms_ptr
= &tracepoint_destructors_syms
;
507 tracepoint_dlopen_ptr
->tracepoint_register_lib
=
508 URCU_FORCE_CAST(int (*)(struct lttng_ust_tracepoint
* const *, int),
509 dlsym(tracepoint_dlopen_ptr
->liblttngust_handle
,
510 "tracepoint_register_lib"));
511 tracepoint_dlopen_ptr
->tracepoint_unregister_lib
=
512 URCU_FORCE_CAST(int (*)(struct lttng_ust_tracepoint
* const *),
513 dlsym(tracepoint_dlopen_ptr
->liblttngust_handle
,
514 "tracepoint_unregister_lib"));
515 tracepoint_destructors_syms_ptr
->tracepoint_disable_destructors
=
516 URCU_FORCE_CAST(void (*)(void),
517 dlsym(tracepoint_dlopen_ptr
->liblttngust_handle
,
518 "tp_disable_destructors"));
519 tracepoint_destructors_syms_ptr
->tracepoint_get_destructors_state
=
520 URCU_FORCE_CAST(int (*)(void),
521 dlsym(tracepoint_dlopen_ptr
->liblttngust_handle
,
522 "tp_get_destructors_state"));
523 __tracepoint__init_urcu_sym();
524 if (tracepoint_dlopen_ptr
->tracepoint_register_lib
) {
525 tracepoint_dlopen_ptr
->tracepoint_register_lib(__start___tracepoints_ptrs
,
526 __stop___tracepoints_ptrs
-
527 __start___tracepoints_ptrs
);
532 __tracepoints__ptrs_destroy(void)
533 lttng_ust_notrace
__attribute__((destructor
));
535 __tracepoints__ptrs_destroy(void)
539 if (--__tracepoint_ptrs_registered
)
541 if (!tracepoint_dlopen_ptr
)
542 tracepoint_dlopen_ptr
= &tracepoint_dlopen
;
543 if (!tracepoint_destructors_syms_ptr
)
544 tracepoint_destructors_syms_ptr
= &tracepoint_destructors_syms
;
545 if (tracepoint_dlopen_ptr
->tracepoint_unregister_lib
)
546 tracepoint_dlopen_ptr
->tracepoint_unregister_lib(__start___tracepoints_ptrs
);
547 if (tracepoint_dlopen_ptr
->liblttngust_handle
548 && tracepoint_destructors_syms_ptr
->tracepoint_get_destructors_state
549 && tracepoint_destructors_syms_ptr
->tracepoint_get_destructors_state()
550 && !__tracepoint_ptrs_registered
) {
551 ret
= dlclose(tracepoint_dlopen_ptr
->liblttngust_handle
);
553 fprintf(stderr
, "Error (%d) in dlclose\n", ret
);
556 memset(tracepoint_dlopen_ptr
, 0, sizeof(*tracepoint_dlopen_ptr
));
560 #else /* TRACEPOINT_DEFINE */
562 #define _DEFINE_TRACEPOINT(_provider, _name, _args)
564 #endif /* #else TRACEPOINT_DEFINE */
570 #endif /* _LTTNG_TRACEPOINT_H */
572 /* The following declarations must be outside re-inclusion protection. */
574 #ifndef TRACEPOINT_ENUM
577 * Tracepoint Enumerations
579 * The enumeration is a mapping between an integer, or range of integers, and
580 * a string. It can be used to have a more compact trace in cases where the
581 * possible values for a field are limited:
585 * TRACEPOINT_ENUM(someproject_component, enumname,
587 * ctf_enum_value("even", 0)
588 * ctf_enum_value("uneven", 1)
589 * ctf_enum_range("twoto4", 2, 4)
590 * ctf_enum_value("five", 5)
594 * Where "someproject_component" is the name of the component this enumeration
595 * belongs to and "enumname" identifies this enumeration. Inside the
596 * TP_ENUM_VALUES macro is the actual mapping. Each string value can map
597 * to either a single value with ctf_enum_value or a range of values
598 * with ctf_enum_range.
600 * Enumeration ranges may overlap, but the behavior is implementation-defined,
601 * each trace reader will handle overlapping as it wishes.
603 * That enumeration can then be used in a field inside the TP_FIELD macro using
604 * the following line:
606 * ctf_enum(someproject_component, enumname, enumtype, enumfield, enumval)
608 * Where "someproject_component" and "enumname" match those in the
609 * TRACEPOINT_ENUM, "enumtype" is a signed or unsigned integer type
610 * backing the enumeration, "enumfield" is the name of the field and
611 * "enumval" is the value.
614 #define TRACEPOINT_ENUM(provider, name, values)
616 #endif /* #ifndef TRACEPOINT_ENUM */
618 #ifndef TRACEPOINT_EVENT
621 * How to use the TRACEPOINT_EVENT macro:
625 * TRACEPOINT_EVENT(someproject_component, event_name,
627 * * TP_ARGS takes from 0 to 10 "type, field_name" pairs *
629 * TP_ARGS(int, arg0, void *, arg1, char *, string, size_t, strlen,
630 * long *, arg4, size_t, arg4_len),
632 * * TP_FIELDS describes the event payload layout in the trace *
635 * * Integer, printed in base 10 *
636 * ctf_integer(int, field_a, arg0)
638 * * Integer, printed with 0x base 16 *
639 * ctf_integer_hex(unsigned long, field_d, arg1)
642 * ctf_enum(someproject_component, enum_name, int, field_e, arg0)
644 * * Array Sequence, printed as UTF8-encoded array of bytes *
645 * ctf_array_text(char, field_b, string, FIXED_LEN)
646 * ctf_sequence_text(char, field_c, string, size_t, strlen)
648 * * String, printed as UTF8-encoded string *
649 * ctf_string(field_e, string)
651 * * Array sequence of signed integer values *
652 * ctf_array(long, field_f, arg4, FIXED_LEN4)
653 * ctf_sequence(long, field_g, arg4, size_t, arg4_len)
657 * More detailed explanation:
659 * The name of the tracepoint is expressed as a tuple with the provider
660 * and name arguments.
662 * The provider and name should be a proper C99 identifier.
663 * The "provider" and "name" MUST follow these rules to ensure no
664 * namespace clash occurs:
666 * For projects (applications and libraries) for which an entity
667 * specific to the project controls the source code and thus its
668 * tracepoints (typically with a scope larger than a single company):
671 * project_component, event
675 * Where "project" is the name of the project,
676 * "component" is the name of the project component (which may
677 * include several levels of sub-components, e.g.
678 * ...component_subcomponent_...) where the tracepoint is located
680 * "event" is the name of the tracepoint event.
682 * For projects issued from a single company wishing to advertise that
683 * the company controls the source code and thus the tracepoints, the
684 * "com_" prefix should be used:
687 * com_company_project_component, event
689 * com_company_project, event
691 * Where "company" is the name of the company,
692 * "project" is the name of the project,
693 * "component" is the name of the project component (which may
694 * include several levels of sub-components, e.g.
695 * ...component_subcomponent_...) where the tracepoint is located
697 * "event" is the name of the tracepoint event.
699 * the provider:event identifier is limited to 127 characters.
702 #define TRACEPOINT_EVENT(provider, name, args, fields) \
703 _DECLARE_TRACEPOINT(provider, name, _TP_PARAMS(args)) \
704 _DEFINE_TRACEPOINT(provider, name, _TP_PARAMS(args))
706 #define TRACEPOINT_EVENT_CLASS(provider, name, args, fields)
708 #define TRACEPOINT_EVENT_INSTANCE(provider, _template, name, args) \
709 _DECLARE_TRACEPOINT(provider, name, _TP_PARAMS(args)) \
710 _DEFINE_TRACEPOINT(provider, name, _TP_PARAMS(args))
712 #endif /* #ifndef TRACEPOINT_EVENT */
714 #ifndef TRACEPOINT_LOGLEVEL
717 * Tracepoint Loglevels
719 * Typical use of these loglevels:
721 * The loglevels go from 0 to 14. Higher numbers imply the most
722 * verbosity (higher event throughput expected.
724 * Loglevels 0 through 6, and loglevel 14, match syslog(3) loglevels
725 * semantic. Loglevels 7 through 13 offer more fine-grained selection of
732 * action must be taken immediately
735 * critical conditions
744 * normal, but significant, condition
747 * informational message
749 * TRACE_DEBUG_SYSTEM 7
750 * debug information with system-level scope (set of programs)
752 * TRACE_DEBUG_PROGRAM 8
753 * debug information with program-level scope (set of processes)
755 * TRACE_DEBUG_PROCESS 9
756 * debug information with process-level scope (set of modules)
758 * TRACE_DEBUG_MODULE 10
759 * debug information with module (executable/library) scope (set of units)
761 * TRACE_DEBUG_UNIT 11
762 * debug information with compilation unit scope (set of functions)
764 * TRACE_DEBUG_FUNCTION 12
765 * debug information with function-level scope
767 * TRACE_DEBUG_LINE 13
768 * debug information with line-level scope (TRACEPOINT_EVENT default)
771 * debug-level message
773 * Declare tracepoint loglevels for tracepoints. A TRACEPOINT_EVENT
774 * should be declared prior to the the TRACEPOINT_LOGLEVEL for a given
775 * tracepoint name. The first field is the provider name, the second
776 * field is the name of the tracepoint, the third field is the loglevel
779 * TRACEPOINT_LOGLEVEL(< [com_company_]project[_component] >, < event >,
782 * The TRACEPOINT_PROVIDER must be already declared before declaring a
783 * TRACEPOINT_LOGLEVEL.
794 TRACE_DEBUG_SYSTEM
= 7,
795 TRACE_DEBUG_PROGRAM
= 8,
796 TRACE_DEBUG_PROCESS
= 9,
797 TRACE_DEBUG_MODULE
= 10,
798 TRACE_DEBUG_UNIT
= 11,
799 TRACE_DEBUG_FUNCTION
= 12,
800 TRACE_DEBUG_LINE
= 13,
804 #define TRACEPOINT_LOGLEVEL(provider, name, loglevel)
806 #endif /* #ifndef TRACEPOINT_LOGLEVEL */
808 #ifndef TRACEPOINT_MODEL_EMF_URI
810 #define TRACEPOINT_MODEL_EMF_URI(provider, name, uri)
812 #endif /* #ifndef TRACEPOINT_MODEL_EMF_URI */