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