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