Fix: baddr_statedump tracepoint registration
[lttng-ust.git] / include / lttng / ust-tracepoint-event.h
1 /*
2 * Copyright (c) 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <urcu/compiler.h>
26 #include <urcu/rculist.h>
27 #include <lttng/ust-events.h>
28 #include <lttng/ringbuffer-config.h>
29 #include <lttng/ust-compiler.h>
30 #include <lttng/tracepoint.h>
31 #include <string.h>
32
33 #undef tp_list_for_each_entry_rcu
34 #define tp_list_for_each_entry_rcu(pos, head, member) \
35 for (pos = cds_list_entry(tp_rcu_dereference_bp((head)->next), __typeof__(*pos), member); \
36 &pos->member != (head); \
37 pos = cds_list_entry(tp_rcu_dereference_bp(pos->member.next), __typeof__(*pos), member))
38
39 /*
40 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
41 * same arguments and having the same field layout.
42 *
43 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
44 * its own provider and name. It refers to a class (template).
45 *
46 * TRACEPOINT_EVENT declared both a class and an instance and does a
47 * direct mapping from the instance to the class.
48 */
49
50 #undef TRACEPOINT_EVENT
51 #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
52 TRACEPOINT_EVENT_CLASS(_provider, _name, \
53 _TP_PARAMS(_args), \
54 _TP_PARAMS(_fields)) \
55 TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
56 _TP_PARAMS(_args))
57
58 /* Helpers */
59 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
60
61 #define _tp_max_t(type, x, y) \
62 ({ \
63 type __max1 = (x); \
64 type __max2 = (y); \
65 __max1 > __max2 ? __max1: __max2; \
66 })
67
68 /*
69 * Stage 0 of tracepoint event generation.
70 *
71 * Check that each TRACEPOINT_EVENT provider argument match the
72 * TRACEPOINT_PROVIDER by creating dummy callbacks.
73 */
74
75 /* Reset all macros within TRACEPOINT_EVENT */
76 #include <lttng/ust-tracepoint-event-reset.h>
77
78 static inline
79 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void)
80 {
81 }
82
83 #undef TRACEPOINT_EVENT_CLASS
84 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
85 __tracepoint_provider_mismatch_##_provider();
86
87 #undef TRACEPOINT_EVENT_INSTANCE
88 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
89 __tracepoint_provider_mismatch_##_provider();
90
91 static inline
92 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void)
93 {
94 #include TRACEPOINT_INCLUDE
95 }
96
97 /*
98 * Stage 0.1 of tracepoint event generation.
99 *
100 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
101 * tracepoint name length limit.
102 */
103
104 /* Reset all macros within TRACEPOINT_EVENT */
105 #include <lttng/ust-tracepoint-event-reset.h>
106
107 #undef TRACEPOINT_EVENT_INSTANCE
108 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
109 static const char \
110 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
111 __attribute__((unused)) = \
112 #_provider ":" #_name;
113
114 #include TRACEPOINT_INCLUDE
115
116 /*
117 * Stage 1 of tracepoint event generation.
118 *
119 * Create event field type metadata section.
120 * Each event produce an array of fields.
121 */
122
123 /* Reset all macros within TRACEPOINT_EVENT */
124 #include <lttng/ust-tracepoint-event-reset.h>
125 #include <lttng/ust-tracepoint-event-write.h>
126 #include <lttng/ust-tracepoint-event-nowrite.h>
127
128 #undef _ctf_integer_ext
129 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
130 { \
131 .name = #_item, \
132 .type = __type_integer(_type, _byte_order, _base, none),\
133 .nowrite = _nowrite, \
134 },
135
136 #undef _ctf_float
137 #define _ctf_float(_type, _item, _src, _nowrite) \
138 { \
139 .name = #_item, \
140 .type = __type_float(_type), \
141 .nowrite = _nowrite, \
142 },
143
144 #undef _ctf_array_encoded
145 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
146 { \
147 .name = #_item, \
148 .type = \
149 { \
150 .atype = atype_array, \
151 .u = \
152 { \
153 .array = \
154 { \
155 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
156 .length = _length, \
157 } \
158 } \
159 }, \
160 .nowrite = _nowrite, \
161 },
162
163 #undef _ctf_sequence_encoded
164 #define _ctf_sequence_encoded(_type, _item, _src, \
165 _length_type, _src_length, _encoding, _nowrite) \
166 { \
167 .name = #_item, \
168 .type = \
169 { \
170 .atype = atype_sequence, \
171 .u = \
172 { \
173 .sequence = \
174 { \
175 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
176 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
177 }, \
178 }, \
179 }, \
180 .nowrite = _nowrite, \
181 },
182
183 #undef _ctf_string
184 #define _ctf_string(_item, _src, _nowrite) \
185 { \
186 .name = #_item, \
187 .type = \
188 { \
189 .atype = atype_string, \
190 .u = \
191 { \
192 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
193 }, \
194 }, \
195 .nowrite = _nowrite, \
196 },
197
198 #undef TP_FIELDS
199 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
200
201 #undef TRACEPOINT_EVENT_CLASS
202 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
203 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
204 _fields \
205 };
206
207 #include TRACEPOINT_INCLUDE
208
209 /*
210 * Stage 2 of tracepoint event generation.
211 *
212 * Create probe callback prototypes.
213 */
214
215 /* Reset all macros within TRACEPOINT_EVENT */
216 #include <lttng/ust-tracepoint-event-reset.h>
217
218 #undef TP_ARGS
219 #define TP_ARGS(...) __VA_ARGS__
220
221 #undef TRACEPOINT_EVENT_CLASS
222 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
223 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
224
225 #include TRACEPOINT_INCLUDE
226
227 /*
228 * Stage 3 of tracepoint event generation.
229 *
230 * Create static inline function that calculates event size.
231 */
232
233 /* Reset all macros within TRACEPOINT_EVENT */
234 #include <lttng/ust-tracepoint-event-reset.h>
235 #include <lttng/ust-tracepoint-event-write.h>
236
237 #undef _ctf_integer_ext
238 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
239 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
240 __event_len += sizeof(_type);
241
242 #undef _ctf_float
243 #define _ctf_float(_type, _item, _src, _nowrite) \
244 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
245 __event_len += sizeof(_type);
246
247 #undef _ctf_array_encoded
248 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
249 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
250 __event_len += sizeof(_type) * (_length);
251
252 #undef _ctf_sequence_encoded
253 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
254 _src_length, _encoding, _nowrite) \
255 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
256 __event_len += sizeof(_length_type); \
257 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
258 __dynamic_len[__dynamic_len_idx] = (_src_length); \
259 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
260 __dynamic_len_idx++;
261
262 #undef _ctf_string
263 #define _ctf_string(_item, _src, _nowrite) \
264 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
265
266 #undef TP_ARGS
267 #define TP_ARGS(...) __VA_ARGS__
268
269 #undef TP_FIELDS
270 #define TP_FIELDS(...) __VA_ARGS__
271
272 #undef TRACEPOINT_EVENT_CLASS
273 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
274 static inline lttng_ust_notrace \
275 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
276 static inline \
277 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
278 { \
279 size_t __event_len = 0; \
280 unsigned int __dynamic_len_idx = 0; \
281 \
282 if (0) \
283 (void) __dynamic_len_idx; /* don't warn if unused */ \
284 _fields \
285 return __event_len; \
286 }
287
288 #include TRACEPOINT_INCLUDE
289
290 /*
291 * Stage 3.1 of tracepoint event generation.
292 *
293 * Create static inline function that layout the filter stack data.
294 * We make both write and nowrite data available to the filter.
295 */
296
297 /* Reset all macros within TRACEPOINT_EVENT */
298 #include <lttng/ust-tracepoint-event-reset.h>
299 #include <lttng/ust-tracepoint-event-write.h>
300 #include <lttng/ust-tracepoint-event-nowrite.h>
301
302 #undef _ctf_integer_ext
303 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
304 if (lttng_is_signed_type(_type)) { \
305 int64_t __ctf_tmp_int64 = (int64_t) (_type) (_src); \
306 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
307 } else { \
308 uint64_t __ctf_tmp_uint64 = (uint64_t) (_type) (_src); \
309 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
310 } \
311 __stack_data += sizeof(int64_t);
312
313 #undef _ctf_float
314 #define _ctf_float(_type, _item, _src, _nowrite) \
315 { \
316 double __ctf_tmp_double = (double) (_type) (_src); \
317 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
318 __stack_data += sizeof(double); \
319 }
320
321 #undef _ctf_array_encoded
322 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
323 { \
324 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
325 const void *__ctf_tmp_ptr = (_src); \
326 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
327 __stack_data += sizeof(unsigned long); \
328 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \
329 __stack_data += sizeof(void **); \
330 }
331
332 #undef _ctf_sequence_encoded
333 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
334 _src_length, _encoding, _nowrite) \
335 { \
336 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
337 const void *__ctf_tmp_ptr = (_src); \
338 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
339 __stack_data += sizeof(unsigned long); \
340 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \
341 __stack_data += sizeof(void **); \
342 }
343
344 #undef _ctf_string
345 #define _ctf_string(_item, _src, _nowrite) \
346 { \
347 const void *__ctf_tmp_ptr = (_src); \
348 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \
349 __stack_data += sizeof(void **); \
350 }
351
352 #undef TP_ARGS
353 #define TP_ARGS(...) __VA_ARGS__
354
355 #undef TP_FIELDS
356 #define TP_FIELDS(...) __VA_ARGS__
357
358 #undef TRACEPOINT_EVENT_CLASS
359 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
360 static inline \
361 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
362 _TP_ARGS_DATA_PROTO(_args)) \
363 { \
364 _fields \
365 }
366
367 #include TRACEPOINT_INCLUDE
368
369
370
371 /*
372 * Stage 4 of tracepoint event generation.
373 *
374 * Create static inline function that calculates event payload alignment.
375 */
376
377 /* Reset all macros within TRACEPOINT_EVENT */
378 #include <lttng/ust-tracepoint-event-reset.h>
379 #include <lttng/ust-tracepoint-event-write.h>
380
381 #undef _ctf_integer_ext
382 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
383 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
384
385 #undef _ctf_float
386 #define _ctf_float(_type, _item, _src, _nowrite) \
387 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
388
389 #undef _ctf_array_encoded
390 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
391 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
392
393 #undef _ctf_sequence_encoded
394 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
395 _src_length, _encoding, _nowrite) \
396 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
397 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
398
399 #undef _ctf_string
400 #define _ctf_string(_item, _src, _nowrite)
401
402 #undef TP_ARGS
403 #define TP_ARGS(...) __VA_ARGS__
404
405 #undef TP_FIELDS
406 #define TP_FIELDS(...) __VA_ARGS__
407
408 #undef TRACEPOINT_EVENT_CLASS
409 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
410 static inline lttng_ust_notrace \
411 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
412 static inline \
413 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
414 { \
415 size_t __event_align = 1; \
416 _fields \
417 return __event_align; \
418 }
419
420 #include TRACEPOINT_INCLUDE
421
422
423 /*
424 * Stage 5 of tracepoint event generation.
425 *
426 * Create the probe function. This function calls event size calculation
427 * and writes event data into the buffer.
428 */
429
430 /* Reset all macros within TRACEPOINT_EVENT */
431 #include <lttng/ust-tracepoint-event-reset.h>
432 #include <lttng/ust-tracepoint-event-write.h>
433
434 #undef _ctf_integer_ext
435 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
436 { \
437 _type __tmp = (_src); \
438 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
439 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
440 }
441
442 #undef _ctf_float
443 #define _ctf_float(_type, _item, _src, _nowrite) \
444 { \
445 _type __tmp = (_src); \
446 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
447 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
448 }
449
450 #undef _ctf_array_encoded
451 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
452 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
453 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
454
455 #undef _ctf_sequence_encoded
456 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
457 _src_length, _encoding, _nowrite) \
458 { \
459 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
460 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
461 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
462 } \
463 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
464 __chan->ops->event_write(&__ctx, _src, \
465 sizeof(_type) * __get_dynamic_len(dest));
466
467 #undef _ctf_string
468 #define _ctf_string(_item, _src, _nowrite) \
469 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
470 __chan->ops->event_write(&__ctx, _src, __get_dynamic_len(dest));
471
472 /* Beware: this get len actually consumes the len value */
473 #undef __get_dynamic_len
474 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
475
476 #undef TP_ARGS
477 #define TP_ARGS(...) __VA_ARGS__
478
479 #undef TP_FIELDS
480 #define TP_FIELDS(...) __VA_ARGS__
481
482 /*
483 * For state dump, check that "session" argument (mandatory) matches the
484 * session this event belongs to. Ensures that we write state dump data only
485 * into the started session, not into all sessions.
486 */
487 #undef _TP_SESSION_CHECK
488 #ifdef TP_SESSION_CHECK
489 #define _TP_SESSION_CHECK(session, csession) (session == csession)
490 #else /* TP_SESSION_CHECK */
491 #define _TP_SESSION_CHECK(session, csession) 1
492 #endif /* TP_SESSION_CHECK */
493
494 /*
495 * Using twice size for filter stack data to hold size and pointer for
496 * each field (worse case). For integers, max size required is 64-bit.
497 * Same for double-precision floats. Those fit within
498 * 2*sizeof(unsigned long) for all supported architectures.
499 * Perform UNION (||) of filter runtime list.
500 */
501 #undef TRACEPOINT_EVENT_CLASS
502 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
503 static lttng_ust_notrace \
504 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
505 static \
506 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
507 { \
508 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
509 struct lttng_channel *__chan = __event->chan; \
510 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
511 size_t __event_len, __event_align; \
512 size_t __dynamic_len_idx = 0; \
513 union { \
514 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
515 char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
516 } __stackvar; \
517 int __ret; \
518 \
519 if (0) \
520 (void) __dynamic_len_idx; /* don't warn if unused */ \
521 if (!_TP_SESSION_CHECK(session, __chan->session)) \
522 return; \
523 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
524 return; \
525 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
526 return; \
527 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
528 return; \
529 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
530 return; \
531 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
532 struct lttng_bytecode_runtime *bc_runtime; \
533 int __filter_record = __event->has_enablers_without_bytecode; \
534 \
535 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
536 _TP_ARGS_DATA_VAR(_args)); \
537 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
538 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
539 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
540 __filter_record = 1; \
541 } \
542 if (caa_likely(!__filter_record)) \
543 return; \
544 } \
545 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
546 _TP_ARGS_DATA_VAR(_args)); \
547 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
548 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
549 __event_align, -1, __chan->handle); \
550 __ctx.ip = __builtin_return_address(0); \
551 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
552 if (__ret < 0) \
553 return; \
554 _fields \
555 __chan->ops->event_commit(&__ctx); \
556 }
557
558 #include TRACEPOINT_INCLUDE
559
560 #undef __get_dynamic_len
561
562 /*
563 * Stage 5.1 of tracepoint event generation.
564 *
565 * Create probe signature
566 */
567
568 /* Reset all macros within TRACEPOINT_EVENT */
569 #include <lttng/ust-tracepoint-event-reset.h>
570
571 #undef TP_ARGS
572 #define TP_ARGS(...) __VA_ARGS__
573
574 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
575
576 #undef TRACEPOINT_EVENT_CLASS
577 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
578 const char __tp_event_signature___##_provider##___##_name[] = \
579 _TP_EXTRACT_STRING2(_args);
580
581 #include TRACEPOINT_INCLUDE
582
583 #undef _TP_EXTRACT_STRING2
584
585 /*
586 * Stage 6 of tracepoint event generation.
587 *
588 * Tracepoint loglevel mapping definition generation. We generate a
589 * symbol for each mapping for a provider/event to ensure at most a 1 to
590 * 1 mapping between events and loglevels. If the symbol is repeated,
591 * the compiler will complain.
592 */
593
594 /* Reset all macros within TRACEPOINT_EVENT */
595 #include <lttng/ust-tracepoint-event-reset.h>
596
597 #undef TRACEPOINT_LOGLEVEL
598 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
599 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
600 static const int *_loglevel___##__provider##___##__name = \
601 &_loglevel_value___##__provider##___##__name;
602
603 #include TRACEPOINT_INCLUDE
604
605 /*
606 * Stage 6.1 of tracepoint event generation.
607 *
608 * Tracepoint UML URI info.
609 */
610
611 /* Reset all macros within TRACEPOINT_EVENT */
612 #include <lttng/ust-tracepoint-event-reset.h>
613
614 #undef TRACEPOINT_MODEL_EMF_URI
615 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
616 static const char *_model_emf_uri___##__provider##___##__name = __uri;
617
618 #include TRACEPOINT_INCLUDE
619
620 /*
621 * Stage 7.1 of tracepoint event generation.
622 *
623 * Create events description structures. We use a weakref because
624 * loglevels are optional. If not declared, the event will point to the
625 * a loglevel that contains NULL.
626 */
627
628 /* Reset all macros within TRACEPOINT_EVENT */
629 #include <lttng/ust-tracepoint-event-reset.h>
630
631 #undef TRACEPOINT_EVENT_INSTANCE
632 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
633 static const int * \
634 __ref_loglevel___##_provider##___##_name \
635 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
636 static const char * \
637 __ref_model_emf_uri___##_provider##___##_name \
638 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
639 const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
640 .name = #_provider ":" #_name, \
641 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
642 .ctx = NULL, \
643 .fields = __event_fields___##_provider##___##_template, \
644 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template), \
645 .loglevel = &__ref_loglevel___##_provider##___##_name, \
646 .signature = __tp_event_signature___##_provider##___##_template, \
647 .u = { .ext = { .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name } }, \
648 };
649
650 #include TRACEPOINT_INCLUDE
651
652 /*
653 * Stage 7.2 of tracepoint event generation.
654 *
655 * Create array of events.
656 */
657
658 /* Reset all macros within TRACEPOINT_EVENT */
659 #include <lttng/ust-tracepoint-event-reset.h>
660
661 #undef TRACEPOINT_EVENT_INSTANCE
662 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
663 &__event_desc___##_provider##_##_name,
664
665 static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = {
666 #include TRACEPOINT_INCLUDE
667 };
668
669
670 /*
671 * Stage 8 of tracepoint event generation.
672 *
673 * Create a toplevel descriptor for the whole probe.
674 */
675
676 /* non-const because list head will be modified when registered. */
677 static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = {
678 .provider = __tp_stringify(TRACEPOINT_PROVIDER),
679 .event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER),
680 .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)),
681 .head = { NULL, NULL },
682 .lazy_init_head = { NULL, NULL },
683 .lazy = 0,
684 .major = LTTNG_UST_PROVIDER_MAJOR,
685 .minor = LTTNG_UST_PROVIDER_MINOR,
686 };
687
688 static int _TP_COMBINE_TOKENS(__probe_register_refcount___, TRACEPOINT_PROVIDER);
689
690 /*
691 * Stage 9 of tracepoint event generation.
692 *
693 * Register/unregister probes at module load/unload.
694 *
695 * Generate the constructor as an externally visible symbol for use when
696 * linking the probe statically.
697 *
698 * Register refcount is protected by libc dynamic loader mutex.
699 */
700
701 /* Reset all macros within TRACEPOINT_EVENT */
702 #include <lttng/ust-tracepoint-event-reset.h>
703 static void lttng_ust_notrace __attribute__((constructor))
704 _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void);
705 static void
706 _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void)
707 {
708 int ret;
709
710 if (_TP_COMBINE_TOKENS(__probe_register_refcount___,
711 TRACEPOINT_PROVIDER)++) {
712 return;
713 }
714 /*
715 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
716 * static inline function that ensures every probe PROVIDER
717 * argument match the provider within which they appear. It
718 * calls empty static inline functions, and therefore has no
719 * runtime effect. However, if it detects an error, a linker
720 * error will appear.
721 */
722 _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)();
723 ret = lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
724 if (ret) {
725 fprintf(stderr, "LTTng-UST: Error (%d) while registering tracepoint probe. Duplicate registration of tracepoint probes having the same name is not allowed.\n", ret);
726 abort();
727 }
728 }
729
730 static void lttng_ust_notrace __attribute__((destructor))
731 _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void);
732 static void
733 _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void)
734 {
735 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___,
736 TRACEPOINT_PROVIDER)) {
737 return;
738 }
739 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
740 }
741
742 int _TP_COMBINE_TOKENS(__tracepoint_provider_, TRACEPOINT_PROVIDER);
This page took 0.044554 seconds and 4 git commands to generate.