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