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