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>
22 #include <lttng/ust-api-compat.h>
24 #define LTTNG_UST_TRACEPOINT_NAME_LEN_MAX 256
26 #ifdef LTTNG_UST_HAVE_SDT_INTEGRATION
28 * Instead of using SDT_USE_VARIADIC from 'sys/sdt.h', use our own namespaced
29 * macros since the instrumented application might already have included
30 * 'sys/sdt.h' without variadic support.
34 #define LTTNG_UST__SDT_NARG(...) \
35 LTTNG_UST___SDT_NARG(__VA_ARGS__, 12,11,10,9,8,7,6,5,4,3,2,1,0)
37 #define LTTNG_UST___SDT_NARG(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12, N, ...) N
39 #define LTTNG_UST__SDT_PROBE_N(provider, name, N, ...) \
40 _SDT_PROBE(provider, name, N, (__VA_ARGS__))
42 #define LTTNG_UST_STAP_PROBEV(provider, name, ...) \
43 LTTNG_UST__SDT_PROBE_N(provider, name, LTTNG_UST__SDT_NARG(0, ##__VA_ARGS__), ##__VA_ARGS__)
46 #define LTTNG_UST_STAP_PROBEV(...)
53 #define lttng_ust_tracepoint_enabled(provider, name) \
54 caa_unlikely(CMM_LOAD_SHARED(lttng_ust_tracepoint_##provider##___##name.state))
56 #define lttng_ust_do_tracepoint(provider, name, ...) \
57 lttng_ust_tracepoint_cb_##provider##___##name(__VA_ARGS__)
59 #define lttng_ust_tracepoint(provider, name, ...) \
61 LTTNG_UST_STAP_PROBEV(provider, name, ## __VA_ARGS__); \
62 if (lttng_ust_tracepoint_enabled(provider, name)) \
63 lttng_ust_do_tracepoint(provider, name, __VA_ARGS__); \
66 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
69 * LTTNG_UST_TP_ARGS takes tuples of type, argument separated by a comma.
70 * It can take up to 10 tuples (which means that less than 10 tuples is
72 * Each tuple is also separated by a comma.
74 #define LTTNG_UST___TP_COMBINE_TOKENS(_tokena, _tokenb) \
76 #define LTTNG_UST__TP_COMBINE_TOKENS(_tokena, _tokenb) \
77 LTTNG_UST___TP_COMBINE_TOKENS(_tokena, _tokenb)
78 #define LTTNG_UST___TP_COMBINE_TOKENS3(_tokena, _tokenb, _tokenc) \
79 _tokena##_tokenb##_tokenc
80 #define LTTNG_UST__TP_COMBINE_TOKENS3(_tokena, _tokenb, _tokenc) \
81 LTTNG_UST___TP_COMBINE_TOKENS3(_tokena, _tokenb, _tokenc)
82 #define LTTNG_UST___TP_COMBINE_TOKENS4(_tokena, _tokenb, _tokenc, _tokend) \
83 _tokena##_tokenb##_tokenc##_tokend
84 #define LTTNG_UST__TP_COMBINE_TOKENS4(_tokena, _tokenb, _tokenc, _tokend) \
85 LTTNG_UST___TP_COMBINE_TOKENS4(_tokena, _tokenb, _tokenc, _tokend)
88 * LTTNG_UST__TP_EXVAR* extract the var names.
89 * LTTNG_UST__TP_EXVAR1 and LTTNG_UST__TP_EXDATA_VAR1 are needed for -std=c99.
91 #define LTTNG_UST__TP_EXVAR0()
92 #define LTTNG_UST__TP_EXVAR1(a)
93 #define LTTNG_UST__TP_EXVAR2(a,b) b
94 #define LTTNG_UST__TP_EXVAR4(a,b,c,d) b,d
95 #define LTTNG_UST__TP_EXVAR6(a,b,c,d,e,f) b,d,f
96 #define LTTNG_UST__TP_EXVAR8(a,b,c,d,e,f,g,h) b,d,f,h
97 #define LTTNG_UST__TP_EXVAR10(a,b,c,d,e,f,g,h,i,j) b,d,f,h,j
98 #define LTTNG_UST__TP_EXVAR12(a,b,c,d,e,f,g,h,i,j,k,l) b,d,f,h,j,l
99 #define LTTNG_UST__TP_EXVAR14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) b,d,f,h,j,l,n
100 #define LTTNG_UST__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
101 #define LTTNG_UST__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
102 #define LTTNG_UST__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
104 #define LTTNG_UST__TP_EXDATA_VAR0() __tp_data
105 #define LTTNG_UST__TP_EXDATA_VAR1(a) __tp_data
106 #define LTTNG_UST__TP_EXDATA_VAR2(a,b) __tp_data,b
107 #define LTTNG_UST__TP_EXDATA_VAR4(a,b,c,d) __tp_data,b,d
108 #define LTTNG_UST__TP_EXDATA_VAR6(a,b,c,d,e,f) __tp_data,b,d,f
109 #define LTTNG_UST__TP_EXDATA_VAR8(a,b,c,d,e,f,g,h) __tp_data,b,d,f,h
110 #define LTTNG_UST__TP_EXDATA_VAR10(a,b,c,d,e,f,g,h,i,j) __tp_data,b,d,f,h,j
111 #define LTTNG_UST__TP_EXDATA_VAR12(a,b,c,d,e,f,g,h,i,j,k,l) __tp_data,b,d,f,h,j,l
112 #define LTTNG_UST__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
113 #define LTTNG_UST__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
114 #define LTTNG_UST__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
115 #define LTTNG_UST__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
118 * LTTNG_UST__TP_EXPROTO* extract tuples of type, var.
119 * LTTNG_UST__TP_EXPROTO1 and LTTNG_UST__TP_EXDATA_PROTO1 are needed for -std=c99.
121 #define LTTNG_UST__TP_EXPROTO0() void
122 #define LTTNG_UST__TP_EXPROTO1(a) void
123 #define LTTNG_UST__TP_EXPROTO2(a,b) a b
124 #define LTTNG_UST__TP_EXPROTO4(a,b,c,d) a b,c d
125 #define LTTNG_UST__TP_EXPROTO6(a,b,c,d,e,f) a b,c d,e f
126 #define LTTNG_UST__TP_EXPROTO8(a,b,c,d,e,f,g,h) a b,c d,e f,g h
127 #define LTTNG_UST__TP_EXPROTO10(a,b,c,d,e,f,g,h,i,j) a b,c d,e f,g h,i j
128 #define LTTNG_UST__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
129 #define LTTNG_UST__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
130 #define LTTNG_UST__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
131 #define LTTNG_UST__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
132 #define LTTNG_UST__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
134 #define LTTNG_UST__TP_EXDATA_PROTO0() void *__tp_data
135 #define LTTNG_UST__TP_EXDATA_PROTO1(a) void *__tp_data
136 #define LTTNG_UST__TP_EXDATA_PROTO2(a,b) void *__tp_data,a b
137 #define LTTNG_UST__TP_EXDATA_PROTO4(a,b,c,d) void *__tp_data,a b,c d
138 #define LTTNG_UST__TP_EXDATA_PROTO6(a,b,c,d,e,f) void *__tp_data,a b,c d,e f
139 #define LTTNG_UST__TP_EXDATA_PROTO8(a,b,c,d,e,f,g,h) void *__tp_data,a b,c d,e f,g h
140 #define LTTNG_UST__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
141 #define LTTNG_UST__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
142 #define LTTNG_UST__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
143 #define LTTNG_UST__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
144 #define LTTNG_UST__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
145 #define LTTNG_UST__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
147 /* Preprocessor trick to count arguments. Inspired from sdt.h. */
148 #define LTTNG_UST__TP_NARGS(...) LTTNG_UST___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)
149 #define LTTNG_UST___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
150 #define LTTNG_UST__TP_PROTO_N(N, ...) LTTNG_UST__TP_PARAMS(LTTNG_UST__TP_COMBINE_TOKENS(LTTNG_UST__TP_EXPROTO, N)(__VA_ARGS__))
151 #define LTTNG_UST__TP_VAR_N(N, ...) LTTNG_UST__TP_PARAMS(LTTNG_UST__TP_COMBINE_TOKENS(LTTNG_UST__TP_EXVAR, N)(__VA_ARGS__))
152 #define LTTNG_UST__TP_DATA_PROTO_N(N, ...) LTTNG_UST__TP_PARAMS(LTTNG_UST__TP_COMBINE_TOKENS(LTTNG_UST__TP_EXDATA_PROTO, N)(__VA_ARGS__))
153 #define LTTNG_UST__TP_DATA_VAR_N(N, ...) LTTNG_UST__TP_PARAMS(LTTNG_UST__TP_COMBINE_TOKENS(LTTNG_UST__TP_EXDATA_VAR, N)(__VA_ARGS__))
154 #define LTTNG_UST__TP_ARGS_PROTO(...) LTTNG_UST__TP_PROTO_N(LTTNG_UST__TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__)
155 #define LTTNG_UST__TP_ARGS_VAR(...) LTTNG_UST__TP_VAR_N(LTTNG_UST__TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__)
156 #define LTTNG_UST__TP_ARGS_DATA_PROTO(...) LTTNG_UST__TP_DATA_PROTO_N(LTTNG_UST__TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__)
157 #define LTTNG_UST__TP_ARGS_DATA_VAR(...) LTTNG_UST__TP_DATA_VAR_N(LTTNG_UST__TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__)
158 #define LTTNG_UST__TP_PARAMS(...) __VA_ARGS__
161 * sizeof(#_provider) - 1 : length of the provider string (excluding \0).
162 * sizeof(#_name) - 1 : length of the name string (excluding \0).
163 * + 1 : separator between provider and event name.
165 * Upper bound (inclusive) is LTTNG_UST_TRACEPOINT_NAME_LEN_MAX - 1 to
169 * left hand side: sizeof(#_provider) - 1 + sizeof(#_name) - 1 + 1
170 * right hand side: LTTNG_UST_TRACEPOINT_NAME_LEN_MAX - 1
171 * operator: <= (inclusive)
172 * Simplified in the code below.
174 #define lttng_ust_tracepoint_validate_name_len(_provider, _name) \
175 lttng_ust_static_assert(sizeof(#_provider) + sizeof(#_name) <= LTTNG_UST_TRACEPOINT_NAME_LEN_MAX, \
176 "Tracepoint name length is too long", \
177 Tracepoint_name_length_is_too_long)
180 * The tracepoint cb is marked always inline so we can distinguish
181 * between caller's ip addresses within the probe using the return
184 #define LTTNG_UST__DECLARE_TRACEPOINT(_provider, _name, ...) \
185 extern struct lttng_ust_tracepoint lttng_ust_tracepoint_##_provider##___##_name; \
187 void lttng_ust_tracepoint_cb_##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(__VA_ARGS__)) \
188 __attribute__((always_inline, unused)) lttng_ust_notrace; \
190 void lttng_ust_tracepoint_cb_##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(__VA_ARGS__)) \
192 struct lttng_ust_tracepoint_probe *__tp_probe; \
194 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
196 tp_rcu_read_lock(); \
197 __tp_probe = tp_rcu_dereference(lttng_ust_tracepoint_##_provider##___##_name.probes); \
198 if (caa_unlikely(!__tp_probe)) \
201 void (*__tp_cb)(void) = __tp_probe->func; \
202 void *__tp_data = __tp_probe->data; \
204 URCU_FORCE_CAST(void (*)(LTTNG_UST__TP_ARGS_DATA_PROTO(__VA_ARGS__)), __tp_cb) \
205 (LTTNG_UST__TP_ARGS_DATA_VAR(__VA_ARGS__)); \
206 } while ((++__tp_probe)->func); \
208 tp_rcu_read_unlock(); \
211 void lttng_ust_tracepoint_register_##_provider##___##_name(char *provider_name, char *event_name, \
212 void (*func)(void), void *data) \
215 void lttng_ust_tracepoint_register_##_provider##___##_name(char *provider_name, char *event_name, \
216 void (*func)(void), void *data) \
218 lttng_ust_tracepoint_probe_register(provider_name, event_name, func, data, \
219 lttng_ust_tracepoint_##_provider##___##_name.signature); \
222 void lttng_ust_tracepoint_unregister_##_provider##___##_name(char *provider_name, char *event_name, \
223 void (*func)(void), void *data) \
226 void lttng_ust_tracepoint_unregister_##_provider##___##_name(char *provider_name, char *event_name, \
227 void (*func)(void), void *data) \
229 lttng_ust_tracepoint_probe_unregister(provider_name, event_name, func, data); \
232 extern int lttng_ust_tracepoint_probe_register(const char *provider_name
, const char *event_name
,
233 void (*func
)(void), void *data
, const char *signature
);
234 extern int lttng_ust_tracepoint_probe_unregister(const char *provider_name
, const char *event_name
,
235 void (*func
)(void), void *data
);
238 * tracepoint dynamic linkage handling (callbacks). Hidden visibility:
239 * shared across objects in a module/main executable.
241 * IMPORTANT: this structure is part of the ABI between instrumented
242 * applications and UST. Fields need to be only added at the end, never
243 * reordered, never removed.
245 * The field @struct_size should be used to determine the size of the
246 * structure. It should be queried before using additional fields added
247 * at the end of the structure.
249 struct lttng_ust_tracepoint_dlopen
{
250 uint32_t struct_size
;
252 void *liblttngust_handle
;
254 int (*tracepoint_register_lib
)(struct lttng_ust_tracepoint
* const *tracepoints_start
,
255 int tracepoints_count
);
256 int (*tracepoint_unregister_lib
)(struct lttng_ust_tracepoint
* const *tracepoints_start
);
257 void (*rcu_read_lock_sym
)(void);
258 void (*rcu_read_unlock_sym
)(void);
259 void *(*rcu_dereference_sym
)(void *p
);
261 /* End of base ABI. Fields below should be used after checking struct_size. */
264 extern struct lttng_ust_tracepoint_dlopen lttng_ust_tracepoint_dlopen
;
265 extern struct lttng_ust_tracepoint_dlopen
*lttng_ust_tracepoint_dlopen_ptr
;
268 * These weak symbols, the constructor, and destructor take care of
269 * registering only _one_ instance of the tracepoints per shared-ojbect
270 * (or for the whole main program).
272 int lttng_ust_tracepoint_registered
273 __attribute__((weak
, visibility("hidden")));
274 int lttng_ust_tracepoint_ptrs_registered
275 __attribute__((weak
, visibility("hidden")));
276 struct lttng_ust_tracepoint_dlopen lttng_ust_tracepoint_dlopen
277 __attribute__((weak
, visibility("hidden"))) = {
278 .struct_size
= sizeof(struct lttng_ust_tracepoint_dlopen
),
281 * Deal with gcc O1 optimisation issues with weak hidden symbols. gcc
282 * 4.8 and prior does not have the same behavior for symbol scoping on
283 * 32-bit powerpc depending on the object size: symbols for objects of 8
284 * bytes or less have the same address throughout a module, whereas they
285 * have different addresses between compile units for objects larger
286 * than 8 bytes. Add this pointer indirection to ensure that the symbol
287 * scoping match that of the other weak hidden symbols found in this
290 struct lttng_ust_tracepoint_dlopen
*lttng_ust_tracepoint_dlopen_ptr
291 __attribute__((weak
, visibility("hidden")));
294 * Tracepoint dynamic linkage handling (callbacks). Hidden visibility: shared
295 * across objects in a module/main executable. The callbacks are used to
296 * control and check if the destructors should be executed.
298 * IMPORTANT: this structure is part of the ABI between instrumented
299 * applications and UST. Fields need to be only added at the end, never
300 * reordered, never removed.
302 * The field @struct_size should be used to determine the size of the
303 * structure. It should be queried before using additional fields added
304 * at the end of the structure.
306 struct lttng_ust_tracepoint_destructors_syms
{
307 uint32_t struct_size
;
309 void (*tracepoint_disable_destructors
)(void);
310 int (*tracepoint_get_destructors_state
)(void);
312 /* End of base ABI. Fields below should be used after checking struct_size. */
315 extern struct lttng_ust_tracepoint_destructors_syms lttng_ust_tracepoint_destructors_syms
;
316 extern struct lttng_ust_tracepoint_destructors_syms
*lttng_ust_tracepoint_destructors_syms_ptr
;
318 struct lttng_ust_tracepoint_destructors_syms lttng_ust_tracepoint_destructors_syms
319 __attribute__((weak
, visibility("hidden"))) = {
320 .struct_size
= sizeof(struct lttng_ust_tracepoint_destructors_syms
),
322 struct lttng_ust_tracepoint_destructors_syms
*lttng_ust_tracepoint_destructors_syms_ptr
323 __attribute__((weak
, visibility("hidden")));
325 static inline void tracepoint_disable_destructors(void)
327 if (!lttng_ust_tracepoint_dlopen_ptr
)
328 lttng_ust_tracepoint_dlopen_ptr
= <tng_ust_tracepoint_dlopen
;
329 if (!lttng_ust_tracepoint_destructors_syms_ptr
)
330 lttng_ust_tracepoint_destructors_syms_ptr
= <tng_ust_tracepoint_destructors_syms
;
331 if (lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
332 && lttng_ust_tracepoint_destructors_syms_ptr
->tracepoint_disable_destructors
)
333 lttng_ust_tracepoint_destructors_syms_ptr
->tracepoint_disable_destructors();
338 lttng_ust_tracepoint__init_urcu_sym(void)
341 lttng_ust_tracepoint__init_urcu_sym(void)
343 if (!lttng_ust_tracepoint_dlopen_ptr
)
344 lttng_ust_tracepoint_dlopen_ptr
= <tng_ust_tracepoint_dlopen
;
346 * Symbols below are needed by tracepoint call sites and probe
349 if (!lttng_ust_tracepoint_dlopen_ptr
->rcu_read_lock_sym
)
350 lttng_ust_tracepoint_dlopen_ptr
->rcu_read_lock_sym
=
351 URCU_FORCE_CAST(void (*)(void),
352 dlsym(lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
,
353 "tp_rcu_read_lock"));
354 if (!lttng_ust_tracepoint_dlopen_ptr
->rcu_read_unlock_sym
)
355 lttng_ust_tracepoint_dlopen_ptr
->rcu_read_unlock_sym
=
356 URCU_FORCE_CAST(void (*)(void),
357 dlsym(lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
,
358 "tp_rcu_read_unlock"));
359 if (!lttng_ust_tracepoint_dlopen_ptr
->rcu_dereference_sym
)
360 lttng_ust_tracepoint_dlopen_ptr
->rcu_dereference_sym
=
361 URCU_FORCE_CAST(void *(*)(void *p
),
362 dlsym(lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
,
363 "tp_rcu_dereference_sym"));
367 lttng_ust_tracepoint__init_urcu_sym(void)
370 lttng_ust_tracepoint__init_urcu_sym(void)
376 lttng_ust__tracepoints__init(void)
377 lttng_ust_notrace
__attribute__((constructor
));
379 lttng_ust__tracepoints__init(void)
381 if (lttng_ust_tracepoint_registered
++) {
382 if (!lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
)
384 lttng_ust_tracepoint__init_urcu_sym();
388 if (!lttng_ust_tracepoint_dlopen_ptr
)
389 lttng_ust_tracepoint_dlopen_ptr
= <tng_ust_tracepoint_dlopen
;
390 if (!lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
)
391 lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
=
392 dlopen(LTTNG_UST_TRACEPOINT_LIB_SONAME
, RTLD_NOW
| RTLD_GLOBAL
);
393 if (!lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
)
395 lttng_ust_tracepoint__init_urcu_sym();
399 lttng_ust__tracepoints__destroy(void)
400 lttng_ust_notrace
__attribute__((destructor
));
402 lttng_ust__tracepoints__destroy(void)
406 if (--lttng_ust_tracepoint_registered
)
408 if (!lttng_ust_tracepoint_dlopen_ptr
)
409 lttng_ust_tracepoint_dlopen_ptr
= <tng_ust_tracepoint_dlopen
;
410 if (!lttng_ust_tracepoint_destructors_syms_ptr
)
411 lttng_ust_tracepoint_destructors_syms_ptr
= <tng_ust_tracepoint_destructors_syms
;
412 if (!lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
)
414 if (lttng_ust_tracepoint_ptrs_registered
)
417 * Lookup if destructors must be executed using the new method.
419 if (lttng_ust_tracepoint_destructors_syms_ptr
->tracepoint_get_destructors_state
420 && !lttng_ust_tracepoint_destructors_syms_ptr
->tracepoint_get_destructors_state()) {
422 * The tracepoint_get_destructors_state symbol was found with
423 * dlsym but its returned value is 0 meaning that destructors
424 * must not be executed.
428 ret
= dlclose(lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
);
430 fprintf(stderr
, "Error (%d) in dlclose\n", ret
);
433 memset(lttng_ust_tracepoint_dlopen_ptr
, 0, sizeof(*lttng_ust_tracepoint_dlopen_ptr
));
436 #ifdef TRACEPOINT_DEFINE
439 * These weak symbols, the constructor, and destructor take care of
440 * registering only _one_ instance of the tracepoints per shared-ojbect
441 * (or for the whole main program).
443 extern struct lttng_ust_tracepoint
* const __start_lttng_ust_tracepoints_ptrs
[]
444 __attribute__((weak
, visibility("hidden")));
445 extern struct lttng_ust_tracepoint
* const __stop_lttng_ust_tracepoints_ptrs
[]
446 __attribute__((weak
, visibility("hidden")));
449 * When LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE is defined, we do not emit a
450 * unresolved symbol that requires the provider to be linked in. When
451 * LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE is not defined, we emit an
452 * unresolved symbol that depends on having the provider linked in,
453 * otherwise the linker complains. This deals with use of static
454 * libraries, ensuring that the linker does not remove the provider
455 * object from the executable.
458 #if LTTNG_UST_COMPAT_API(0)
459 # if defined(TRACEPOINT_PROBE_DYNAMIC_LINKAGE) && !defined(LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE)
460 # define LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE
462 #endif /* #if LTTNG_UST_COMPAT_API(0) */
464 #ifdef LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE
465 #define LTTNG_UST__TRACEPOINT_UNDEFINED_REF(provider) NULL
466 #else /* LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE */
467 #define LTTNG_UST__TRACEPOINT_UNDEFINED_REF(provider) <tng_ust_tracepoint_provider_##provider
468 #endif /* LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE */
471 * Note: to allow PIC code, we need to allow the linker to update the pointers
472 * in the lttng_ust_tracepoints_ptrs section.
473 * Therefore, this section is _not_ const (read-only).
475 #define LTTNG_UST__TP_EXTRACT_STRING(...) #__VA_ARGS__
477 #define LTTNG_UST__DEFINE_TRACEPOINT(_provider, _name, _args) \
478 lttng_ust_tracepoint_validate_name_len(_provider, _name); \
479 extern int lttng_ust_tracepoint_provider_##_provider; \
480 static const char __tp_provider_strtab_##_provider##___##_name[] \
481 __attribute__((section("lttng_ust_tracepoints_strings"))) = \
483 static const char __tp_name_strtab_##_provider##___##_name[] \
484 __attribute__((section("lttng_ust_tracepoints_strings"))) = \
486 struct lttng_ust_tracepoint lttng_ust_tracepoint_##_provider##___##_name \
487 __attribute__((section("lttng_ust_tracepoints"))) = { \
488 sizeof(struct lttng_ust_tracepoint), \
489 __tp_provider_strtab_##_provider##___##_name, \
490 __tp_name_strtab_##_provider##___##_name, \
493 LTTNG_UST__TRACEPOINT_UNDEFINED_REF(_provider), \
494 LTTNG_UST__TP_EXTRACT_STRING(_args), \
496 static struct lttng_ust_tracepoint * \
497 lttng_ust_tracepoint_ptr_##_provider##___##_name \
498 __attribute__((section("lttng_ust_tracepoints_ptrs"), used)) \
499 __lttng_ust_variable_attribute_no_sanitize_address = \
500 <tng_ust_tracepoint_##_provider##___##_name;
503 lttng_ust__tracepoints__ptrs_init(void)
504 lttng_ust_notrace
__attribute__((constructor
));
506 lttng_ust__tracepoints__ptrs_init(void)
508 if (lttng_ust_tracepoint_ptrs_registered
++)
510 if (!lttng_ust_tracepoint_dlopen_ptr
)
511 lttng_ust_tracepoint_dlopen_ptr
= <tng_ust_tracepoint_dlopen
;
512 if (!lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
)
513 lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
=
514 dlopen(LTTNG_UST_TRACEPOINT_LIB_SONAME
, RTLD_NOW
| RTLD_GLOBAL
);
515 if (!lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
)
517 if (!lttng_ust_tracepoint_destructors_syms_ptr
)
518 lttng_ust_tracepoint_destructors_syms_ptr
= <tng_ust_tracepoint_destructors_syms
;
519 lttng_ust_tracepoint_dlopen_ptr
->tracepoint_register_lib
=
520 URCU_FORCE_CAST(int (*)(struct lttng_ust_tracepoint
* const *, int),
521 dlsym(lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
,
522 "tracepoint_register_lib"));
523 lttng_ust_tracepoint_dlopen_ptr
->tracepoint_unregister_lib
=
524 URCU_FORCE_CAST(int (*)(struct lttng_ust_tracepoint
* const *),
525 dlsym(lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
,
526 "tracepoint_unregister_lib"));
527 lttng_ust_tracepoint_destructors_syms_ptr
->tracepoint_disable_destructors
=
528 URCU_FORCE_CAST(void (*)(void),
529 dlsym(lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
,
530 "tp_disable_destructors"));
531 lttng_ust_tracepoint_destructors_syms_ptr
->tracepoint_get_destructors_state
=
532 URCU_FORCE_CAST(int (*)(void),
533 dlsym(lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
,
534 "tp_get_destructors_state"));
535 lttng_ust_tracepoint__init_urcu_sym();
536 if (lttng_ust_tracepoint_dlopen_ptr
->tracepoint_register_lib
) {
537 lttng_ust_tracepoint_dlopen_ptr
->tracepoint_register_lib(__start_lttng_ust_tracepoints_ptrs
,
538 __stop_lttng_ust_tracepoints_ptrs
-
539 __start_lttng_ust_tracepoints_ptrs
);
544 lttng_ust__tracepoints__ptrs_destroy(void)
545 lttng_ust_notrace
__attribute__((destructor
));
547 lttng_ust__tracepoints__ptrs_destroy(void)
551 if (--lttng_ust_tracepoint_ptrs_registered
)
553 if (!lttng_ust_tracepoint_dlopen_ptr
)
554 lttng_ust_tracepoint_dlopen_ptr
= <tng_ust_tracepoint_dlopen
;
555 if (!lttng_ust_tracepoint_destructors_syms_ptr
)
556 lttng_ust_tracepoint_destructors_syms_ptr
= <tng_ust_tracepoint_destructors_syms
;
557 if (lttng_ust_tracepoint_dlopen_ptr
->tracepoint_unregister_lib
)
558 lttng_ust_tracepoint_dlopen_ptr
->tracepoint_unregister_lib(__start_lttng_ust_tracepoints_ptrs
);
559 if (lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
560 && lttng_ust_tracepoint_destructors_syms_ptr
->tracepoint_get_destructors_state
561 && lttng_ust_tracepoint_destructors_syms_ptr
->tracepoint_get_destructors_state()
562 && !lttng_ust_tracepoint_ptrs_registered
) {
563 ret
= dlclose(lttng_ust_tracepoint_dlopen_ptr
->liblttngust_handle
);
565 fprintf(stderr
, "Error (%d) in dlclose\n", ret
);
568 memset(lttng_ust_tracepoint_dlopen_ptr
, 0, sizeof(*lttng_ust_tracepoint_dlopen_ptr
));
572 #else /* TRACEPOINT_DEFINE */
574 #define LTTNG_UST__DEFINE_TRACEPOINT(_provider, _name, _args)
576 #endif /* #else TRACEPOINT_DEFINE */
578 #if LTTNG_UST_COMPAT_API(0)
579 #define tracepoint lttng_ust_tracepoint
580 #define do_tracepoint lttng_ust_do_tracepoint
581 #define tracepoint_enabled lttng_ust_tracepoint_enabled
582 #define TP_ARGS LTTNG_UST_TP_ARGS
583 #define TP_FIELDS LTTNG_UST_TP_FIELDS
584 #endif /* #if LTTNG_UST_COMPAT_API(0) */
590 #endif /* _LTTNG_TRACEPOINT_H */
592 /* The following declarations must be outside re-inclusion protection. */
594 #ifndef TRACEPOINT_ENUM
597 * Tracepoint Enumerations
599 * The enumeration is a mapping between an integer, or range of integers, and
600 * a string. It can be used to have a more compact trace in cases where the
601 * possible values for a field are limited:
605 * TRACEPOINT_ENUM(someproject_component, enumname,
607 * ctf_enum_value("even", 0)
608 * ctf_enum_value("uneven", 1)
609 * ctf_enum_range("twoto4", 2, 4)
610 * ctf_enum_value("five", 5)
614 * Where "someproject_component" is the name of the component this enumeration
615 * belongs to and "enumname" identifies this enumeration. Inside the
616 * TP_ENUM_VALUES macro is the actual mapping. Each string value can map
617 * to either a single value with ctf_enum_value or a range of values
618 * with ctf_enum_range.
620 * Enumeration ranges may overlap, but the behavior is implementation-defined,
621 * each trace reader will handle overlapping as it wishes.
623 * That enumeration can then be used in a field inside the TP_FIELD macro using
624 * the following line:
626 * ctf_enum(someproject_component, enumname, enumtype, enumfield, enumval)
628 * Where "someproject_component" and "enumname" match those in the
629 * TRACEPOINT_ENUM, "enumtype" is a signed or unsigned integer type
630 * backing the enumeration, "enumfield" is the name of the field and
631 * "enumval" is the value.
634 #define TRACEPOINT_ENUM(provider, name, values)
636 #endif /* #ifndef TRACEPOINT_ENUM */
638 #ifndef LTTNG_UST_TRACEPOINT_EVENT
641 * How to use the LTTNG_UST_TRACEPOINT_EVENT macro:
645 * LTTNG_UST_TRACEPOINT_EVENT(someproject_component, event_name,
647 * * LTTNG_UST_TP_ARGS takes from 0 to 10 "type, field_name" pairs *
649 * LTTNG_UST_TP_ARGS(int, arg0, void *, arg1, char *, string, size_t, strlen,
650 * long *, arg4, size_t, arg4_len),
652 * * LTTNG_UST_TP_FIELDS describes the event payload layout in the trace *
654 * LTTNG_UST_TP_FIELDS(
655 * * Integer, printed in base 10 *
656 * ctf_integer(int, field_a, arg0)
658 * * Integer, printed with 0x base 16 *
659 * ctf_integer_hex(unsigned long, field_d, arg1)
662 * ctf_enum(someproject_component, enum_name, int, field_e, arg0)
664 * * Array Sequence, printed as UTF8-encoded array of bytes *
665 * ctf_array_text(char, field_b, string, FIXED_LEN)
666 * ctf_sequence_text(char, field_c, string, size_t, strlen)
668 * * String, printed as UTF8-encoded string *
669 * ctf_string(field_e, string)
671 * * Array sequence of signed integer values *
672 * ctf_array(long, field_f, arg4, FIXED_LEN4)
673 * ctf_sequence(long, field_g, arg4, size_t, arg4_len)
677 * More detailed explanation:
679 * The name of the tracepoint is expressed as a tuple with the provider
680 * and name arguments.
682 * The provider and name should be a proper C99 identifier.
683 * The "provider" and "name" MUST follow these rules to ensure no
684 * namespace clash occurs:
686 * For projects (applications and libraries) for which an entity
687 * specific to the project controls the source code and thus its
688 * tracepoints (typically with a scope larger than a single company):
691 * project_component, event
695 * Where "project" is the name of the project,
696 * "component" is the name of the project component (which may
697 * include several levels of sub-components, e.g.
698 * ...component_subcomponent_...) where the tracepoint is located
700 * "event" is the name of the tracepoint event.
702 * For projects issued from a single company wishing to advertise that
703 * the company controls the source code and thus the tracepoints, the
704 * "com_" prefix should be used:
707 * com_company_project_component, event
709 * com_company_project, event
711 * Where "company" is the name of the company,
712 * "project" is the name of the project,
713 * "component" is the name of the project component (which may
714 * include several levels of sub-components, e.g.
715 * ...component_subcomponent_...) where the tracepoint is located
717 * "event" is the name of the tracepoint event.
719 * the provider:event identifier is limited to 127 characters.
722 #define LTTNG_UST_TRACEPOINT_EVENT(provider, name, args, fields) \
723 LTTNG_UST__DECLARE_TRACEPOINT(provider, name, LTTNG_UST__TP_PARAMS(args)) \
724 LTTNG_UST__DEFINE_TRACEPOINT(provider, name, LTTNG_UST__TP_PARAMS(args))
726 #define LTTNG_UST_TRACEPOINT_EVENT_CLASS(provider, name, args, fields)
728 #define LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(provider, _template, name, args) \
729 LTTNG_UST__DECLARE_TRACEPOINT(provider, name, LTTNG_UST__TP_PARAMS(args)) \
730 LTTNG_UST__DEFINE_TRACEPOINT(provider, name, LTTNG_UST__TP_PARAMS(args))
732 #if LTTNG_UST_COMPAT_API(0)
733 #define TRACEPOINT_EVENT LTTNG_UST_TRACEPOINT_EVENT
734 #define TRACEPOINT_EVENT_CLASS LTTNG_UST_TRACEPOINT_EVENT_CLASS
735 #define TRACEPOINT_EVENT_INSTANCE LTTNG_UST_TRACEPOINT_EVENT_INSTANCE
736 #endif /* #if LTTNG_UST_COMPAT_API(0) */
738 #endif /* #ifndef LTTNG_UST_TRACEPOINT_EVENT */
740 #ifndef TRACEPOINT_LOGLEVEL
743 * Tracepoint Loglevels
745 * Typical use of these loglevels:
747 * The loglevels go from 0 to 14. Higher numbers imply the most
748 * verbosity (higher event throughput expected.
750 * Loglevels 0 through 6, and loglevel 14, match syslog(3) loglevels
751 * semantic. Loglevels 7 through 13 offer more fine-grained selection of
758 * action must be taken immediately
761 * critical conditions
770 * normal, but significant, condition
773 * informational message
775 * TRACE_DEBUG_SYSTEM 7
776 * debug information with system-level scope (set of programs)
778 * TRACE_DEBUG_PROGRAM 8
779 * debug information with program-level scope (set of processes)
781 * TRACE_DEBUG_PROCESS 9
782 * debug information with process-level scope (set of modules)
784 * TRACE_DEBUG_MODULE 10
785 * debug information with module (executable/library) scope (set of units)
787 * TRACE_DEBUG_UNIT 11
788 * debug information with compilation unit scope (set of functions)
790 * TRACE_DEBUG_FUNCTION 12
791 * debug information with function-level scope
793 * TRACE_DEBUG_LINE 13
794 * debug information with line-level scope (LTTNG_UST_TRACEPOINT_EVENT default)
797 * debug-level message
799 * Declare tracepoint loglevels for tracepoints. A LTTNG_UST_TRACEPOINT_EVENT
800 * should be declared prior to the the TRACEPOINT_LOGLEVEL for a given
801 * tracepoint name. The first field is the provider name, the second
802 * field is the name of the tracepoint, the third field is the loglevel
805 * TRACEPOINT_LOGLEVEL(< [com_company_]project[_component] >, < event >,
808 * The TRACEPOINT_PROVIDER must be already declared before declaring a
809 * TRACEPOINT_LOGLEVEL.
820 TRACE_DEBUG_SYSTEM
= 7,
821 TRACE_DEBUG_PROGRAM
= 8,
822 TRACE_DEBUG_PROCESS
= 9,
823 TRACE_DEBUG_MODULE
= 10,
824 TRACE_DEBUG_UNIT
= 11,
825 TRACE_DEBUG_FUNCTION
= 12,
826 TRACE_DEBUG_LINE
= 13,
830 #define TRACEPOINT_LOGLEVEL(provider, name, loglevel)
832 #endif /* #ifndef TRACEPOINT_LOGLEVEL */
834 #ifndef TRACEPOINT_MODEL_EMF_URI
836 #define TRACEPOINT_MODEL_EMF_URI(provider, name, uri)
838 #endif /* #ifndef TRACEPOINT_MODEL_EMF_URI */