Add ctf_sequence_hex() macro
[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 lttng_ust_notrace
79 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void);
80 static inline
81 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void)
82 {
83 }
84
85 #undef TRACEPOINT_EVENT_CLASS
86 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
87 __tracepoint_provider_mismatch_##_provider();
88
89 #undef TRACEPOINT_EVENT_INSTANCE
90 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
91 __tracepoint_provider_mismatch_##_provider();
92
93 static inline lttng_ust_notrace
94 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void);
95 static inline
96 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void)
97 {
98 #include TRACEPOINT_INCLUDE
99 }
100
101 /*
102 * Stage 0.1 of tracepoint event generation.
103 *
104 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
105 * tracepoint name length limit.
106 */
107
108 /* Reset all macros within TRACEPOINT_EVENT */
109 #include <lttng/ust-tracepoint-event-reset.h>
110
111 #undef TRACEPOINT_EVENT_INSTANCE
112 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
113 static const char \
114 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
115 __attribute__((unused)) = \
116 #_provider ":" #_name;
117
118 #include TRACEPOINT_INCLUDE
119
120 /*
121 * Stage 1 of tracepoint event generation.
122 *
123 * Create event field type metadata section.
124 * Each event produce an array of fields.
125 */
126
127 /* Reset all macros within TRACEPOINT_EVENT */
128 #include <lttng/ust-tracepoint-event-reset.h>
129 #include <lttng/ust-tracepoint-event-write.h>
130 #include <lttng/ust-tracepoint-event-nowrite.h>
131
132 #undef _ctf_integer_ext
133 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
134 { \
135 .name = #_item, \
136 .type = __type_integer(_type, _byte_order, _base, none),\
137 .nowrite = _nowrite, \
138 },
139
140 #undef _ctf_float
141 #define _ctf_float(_type, _item, _src, _nowrite) \
142 { \
143 .name = #_item, \
144 .type = __type_float(_type), \
145 .nowrite = _nowrite, \
146 },
147
148 #undef _ctf_array_encoded
149 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
150 { \
151 .name = #_item, \
152 .type = \
153 { \
154 .atype = atype_array, \
155 .u = \
156 { \
157 .array = \
158 { \
159 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
160 .length = _length, \
161 } \
162 } \
163 }, \
164 .nowrite = _nowrite, \
165 },
166
167 #undef _ctf_sequence_encoded
168 #define _ctf_sequence_encoded(_type, _item, _src, \
169 _length_type, _src_length, _encoding, _nowrite, \
170 _elem_type_base) \
171 { \
172 .name = #_item, \
173 .type = \
174 { \
175 .atype = atype_sequence, \
176 .u = \
177 { \
178 .sequence = \
179 { \
180 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
181 .elem_type = __type_integer(_type, BYTE_ORDER, _elem_type_base, _encoding), \
182 }, \
183 }, \
184 }, \
185 .nowrite = _nowrite, \
186 },
187
188 #undef _ctf_string
189 #define _ctf_string(_item, _src, _nowrite) \
190 { \
191 .name = #_item, \
192 .type = \
193 { \
194 .atype = atype_string, \
195 .u = \
196 { \
197 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
198 }, \
199 }, \
200 .nowrite = _nowrite, \
201 },
202
203 #undef TP_FIELDS
204 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
205
206 #undef TRACEPOINT_EVENT_CLASS
207 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
208 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
209 _fields \
210 };
211
212 #include TRACEPOINT_INCLUDE
213
214 /*
215 * Stage 2 of tracepoint event generation.
216 *
217 * Create probe callback prototypes.
218 */
219
220 /* Reset all macros within TRACEPOINT_EVENT */
221 #include <lttng/ust-tracepoint-event-reset.h>
222
223 #undef TP_ARGS
224 #define TP_ARGS(...) __VA_ARGS__
225
226 #undef TRACEPOINT_EVENT_CLASS
227 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
228 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
229
230 #include TRACEPOINT_INCLUDE
231
232 /*
233 * Stage 3 of tracepoint event generation.
234 *
235 * Create static inline function that calculates event size.
236 */
237
238 /* Reset all macros within TRACEPOINT_EVENT */
239 #include <lttng/ust-tracepoint-event-reset.h>
240 #include <lttng/ust-tracepoint-event-write.h>
241
242 #undef _ctf_integer_ext
243 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
244 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
245 __event_len += sizeof(_type);
246
247 #undef _ctf_float
248 #define _ctf_float(_type, _item, _src, _nowrite) \
249 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
250 __event_len += sizeof(_type);
251
252 #undef _ctf_array_encoded
253 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
254 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
255 __event_len += sizeof(_type) * (_length);
256
257 #undef _ctf_sequence_encoded
258 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
259 _src_length, _encoding, _nowrite, _elem_type_base) \
260 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
261 __event_len += sizeof(_length_type); \
262 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
263 __dynamic_len[__dynamic_len_idx] = (_src_length); \
264 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
265 __dynamic_len_idx++;
266
267 #undef _ctf_string
268 #define _ctf_string(_item, _src, _nowrite) \
269 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
270
271 #undef TP_ARGS
272 #define TP_ARGS(...) __VA_ARGS__
273
274 #undef TP_FIELDS
275 #define TP_FIELDS(...) __VA_ARGS__
276
277 #undef TRACEPOINT_EVENT_CLASS
278 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
279 static inline lttng_ust_notrace \
280 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
281 static inline \
282 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
283 { \
284 size_t __event_len = 0; \
285 unsigned int __dynamic_len_idx = 0; \
286 \
287 if (0) \
288 (void) __dynamic_len_idx; /* don't warn if unused */ \
289 _fields \
290 return __event_len; \
291 }
292
293 #include TRACEPOINT_INCLUDE
294
295 /*
296 * Stage 3.1 of tracepoint event generation.
297 *
298 * Create static inline function that layout the filter stack data.
299 * We make both write and nowrite data available to the filter.
300 */
301
302 /* Reset all macros within TRACEPOINT_EVENT */
303 #include <lttng/ust-tracepoint-event-reset.h>
304 #include <lttng/ust-tracepoint-event-write.h>
305 #include <lttng/ust-tracepoint-event-nowrite.h>
306
307 #undef _ctf_integer_ext
308 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
309 if (lttng_is_signed_type(_type)) { \
310 int64_t __ctf_tmp_int64; \
311 switch (sizeof(_type)) { \
312 case 1: \
313 { \
314 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
315 __ctf_tmp_int64 = (int64_t) __tmp.v; \
316 break; \
317 } \
318 case 2: \
319 { \
320 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
321 __ctf_tmp_int64 = (int64_t) __tmp.v; \
322 break; \
323 } \
324 case 4: \
325 { \
326 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
327 __ctf_tmp_int64 = (int64_t) __tmp.v; \
328 break; \
329 } \
330 case 8: \
331 { \
332 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
333 __ctf_tmp_int64 = (int64_t) __tmp.v; \
334 break; \
335 } \
336 default: \
337 abort(); \
338 }; \
339 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
340 } else { \
341 uint64_t __ctf_tmp_uint64; \
342 switch (sizeof(_type)) { \
343 case 1: \
344 { \
345 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
346 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
347 break; \
348 } \
349 case 2: \
350 { \
351 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
352 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
353 break; \
354 } \
355 case 4: \
356 { \
357 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
358 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
359 break; \
360 } \
361 case 8: \
362 { \
363 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
364 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
365 break; \
366 } \
367 default: \
368 abort(); \
369 }; \
370 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
371 } \
372 __stack_data += sizeof(int64_t);
373
374 #undef _ctf_float
375 #define _ctf_float(_type, _item, _src, _nowrite) \
376 { \
377 double __ctf_tmp_double = (double) (_type) (_src); \
378 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
379 __stack_data += sizeof(double); \
380 }
381
382 #undef _ctf_array_encoded
383 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
384 { \
385 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
386 const void *__ctf_tmp_ptr = (_src); \
387 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
388 __stack_data += sizeof(unsigned long); \
389 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
390 __stack_data += sizeof(void *); \
391 }
392
393 #undef _ctf_sequence_encoded
394 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
395 _src_length, _encoding, _nowrite, _elem_type_base) \
396 { \
397 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
398 const void *__ctf_tmp_ptr = (_src); \
399 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
400 __stack_data += sizeof(unsigned long); \
401 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
402 __stack_data += sizeof(void *); \
403 }
404
405 #undef _ctf_string
406 #define _ctf_string(_item, _src, _nowrite) \
407 { \
408 const void *__ctf_tmp_ptr = (_src); \
409 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
410 __stack_data += sizeof(void *); \
411 }
412
413 #undef TP_ARGS
414 #define TP_ARGS(...) __VA_ARGS__
415
416 #undef TP_FIELDS
417 #define TP_FIELDS(...) __VA_ARGS__
418
419 #undef TRACEPOINT_EVENT_CLASS
420 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
421 static inline \
422 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
423 _TP_ARGS_DATA_PROTO(_args)) \
424 { \
425 _fields \
426 }
427
428 #include TRACEPOINT_INCLUDE
429
430
431
432 /*
433 * Stage 4 of tracepoint event generation.
434 *
435 * Create static inline function that calculates event payload alignment.
436 */
437
438 /* Reset all macros within TRACEPOINT_EVENT */
439 #include <lttng/ust-tracepoint-event-reset.h>
440 #include <lttng/ust-tracepoint-event-write.h>
441
442 #undef _ctf_integer_ext
443 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
444 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
445
446 #undef _ctf_float
447 #define _ctf_float(_type, _item, _src, _nowrite) \
448 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
449
450 #undef _ctf_array_encoded
451 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
452 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
453
454 #undef _ctf_sequence_encoded
455 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
456 _src_length, _encoding, _nowrite, _elem_type_base) \
457 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
458 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
459
460 #undef _ctf_string
461 #define _ctf_string(_item, _src, _nowrite)
462
463 #undef TP_ARGS
464 #define TP_ARGS(...) __VA_ARGS__
465
466 #undef TP_FIELDS
467 #define TP_FIELDS(...) __VA_ARGS__
468
469 #undef TRACEPOINT_EVENT_CLASS
470 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
471 static inline lttng_ust_notrace \
472 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
473 static inline \
474 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
475 { \
476 size_t __event_align = 1; \
477 _fields \
478 return __event_align; \
479 }
480
481 #include TRACEPOINT_INCLUDE
482
483
484 /*
485 * Stage 5 of tracepoint event generation.
486 *
487 * Create the probe function. This function calls event size calculation
488 * and writes event data into the buffer.
489 */
490
491 /* Reset all macros within TRACEPOINT_EVENT */
492 #include <lttng/ust-tracepoint-event-reset.h>
493 #include <lttng/ust-tracepoint-event-write.h>
494
495 #undef _ctf_integer_ext
496 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
497 { \
498 _type __tmp = (_src); \
499 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
500 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
501 }
502
503 #undef _ctf_float
504 #define _ctf_float(_type, _item, _src, _nowrite) \
505 { \
506 _type __tmp = (_src); \
507 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
508 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
509 }
510
511 #undef _ctf_array_encoded
512 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
513 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
514 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
515
516 #undef _ctf_sequence_encoded
517 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
518 _src_length, _encoding, _nowrite, _elem_type_base) \
519 { \
520 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
521 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
522 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
523 } \
524 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
525 __chan->ops->event_write(&__ctx, _src, \
526 sizeof(_type) * __get_dynamic_len(dest));
527
528 /*
529 * __chan->ops->u.has_strcpy is a flag letting us know if the LTTng-UST
530 * tracepoint provider ABI implements event_strcpy. This dynamic check
531 * can be removed when the tracepoint provider ABI moves to 2.
532 */
533 #if (LTTNG_UST_PROVIDER_MAJOR > 1)
534 #error "Tracepoint probe provider major version has changed. Please remove dynamic check for has_strcpy."
535 #endif
536
537 #undef _ctf_string
538 #define _ctf_string(_item, _src, _nowrite) \
539 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
540 if (__chan->ops->u.has_strcpy) \
541 __chan->ops->event_strcpy(&__ctx, _src, \
542 __get_dynamic_len(dest)); \
543 else \
544 __chan->ops->event_write(&__ctx, _src, \
545 __get_dynamic_len(dest));
546
547 /* Beware: this get len actually consumes the len value */
548 #undef __get_dynamic_len
549 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
550
551 #undef TP_ARGS
552 #define TP_ARGS(...) __VA_ARGS__
553
554 #undef TP_FIELDS
555 #define TP_FIELDS(...) __VA_ARGS__
556
557 /*
558 * For state dump, check that "session" argument (mandatory) matches the
559 * session this event belongs to. Ensures that we write state dump data only
560 * into the started session, not into all sessions.
561 */
562 #undef _TP_SESSION_CHECK
563 #ifdef TP_SESSION_CHECK
564 #define _TP_SESSION_CHECK(session, csession) (session == csession)
565 #else /* TP_SESSION_CHECK */
566 #define _TP_SESSION_CHECK(session, csession) 1
567 #endif /* TP_SESSION_CHECK */
568
569 #undef _TP_IP_PARAM
570 #ifdef TP_IP_PARAM
571 #define _TP_IP_PARAM(x) (x)
572 #else /* TP_IP_PARAM */
573 #define _TP_IP_PARAM(x) __builtin_return_address(0)
574 #endif /* TP_IP_PARAM */
575
576 /*
577 * Using twice size for filter stack data to hold size and pointer for
578 * each field (worse case). For integers, max size required is 64-bit.
579 * Same for double-precision floats. Those fit within
580 * 2*sizeof(unsigned long) for all supported architectures.
581 * Perform UNION (||) of filter runtime list.
582 */
583 #undef TRACEPOINT_EVENT_CLASS
584 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
585 static lttng_ust_notrace \
586 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
587 static \
588 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
589 { \
590 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
591 struct lttng_channel *__chan = __event->chan; \
592 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
593 size_t __event_len, __event_align; \
594 size_t __dynamic_len_idx = 0; \
595 union { \
596 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
597 char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
598 } __stackvar; \
599 int __ret; \
600 \
601 if (0) \
602 (void) __dynamic_len_idx; /* don't warn if unused */ \
603 if (!_TP_SESSION_CHECK(session, __chan->session)) \
604 return; \
605 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
606 return; \
607 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
608 return; \
609 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
610 return; \
611 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
612 return; \
613 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
614 struct lttng_bytecode_runtime *bc_runtime; \
615 int __filter_record = __event->has_enablers_without_bytecode; \
616 \
617 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
618 _TP_ARGS_DATA_VAR(_args)); \
619 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
620 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
621 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
622 __filter_record = 1; \
623 } \
624 if (caa_likely(!__filter_record)) \
625 return; \
626 } \
627 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
628 _TP_ARGS_DATA_VAR(_args)); \
629 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
630 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
631 __event_align, -1, __chan->handle); \
632 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
633 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
634 if (__ret < 0) \
635 return; \
636 _fields \
637 __chan->ops->event_commit(&__ctx); \
638 }
639
640 #include TRACEPOINT_INCLUDE
641
642 #undef __get_dynamic_len
643
644 /*
645 * Stage 5.1 of tracepoint event generation.
646 *
647 * Create probe signature
648 */
649
650 /* Reset all macros within TRACEPOINT_EVENT */
651 #include <lttng/ust-tracepoint-event-reset.h>
652
653 #undef TP_ARGS
654 #define TP_ARGS(...) __VA_ARGS__
655
656 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
657
658 #undef TRACEPOINT_EVENT_CLASS
659 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
660 const char __tp_event_signature___##_provider##___##_name[] = \
661 _TP_EXTRACT_STRING2(_args);
662
663 #include TRACEPOINT_INCLUDE
664
665 #undef _TP_EXTRACT_STRING2
666
667 /*
668 * Stage 6 of tracepoint event generation.
669 *
670 * Tracepoint loglevel mapping definition generation. We generate a
671 * symbol for each mapping for a provider/event to ensure at most a 1 to
672 * 1 mapping between events and loglevels. If the symbol is repeated,
673 * the compiler will complain.
674 */
675
676 /* Reset all macros within TRACEPOINT_EVENT */
677 #include <lttng/ust-tracepoint-event-reset.h>
678
679 #undef TRACEPOINT_LOGLEVEL
680 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
681 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
682 static const int *_loglevel___##__provider##___##__name = \
683 &_loglevel_value___##__provider##___##__name;
684
685 #include TRACEPOINT_INCLUDE
686
687 /*
688 * Stage 6.1 of tracepoint event generation.
689 *
690 * Tracepoint UML URI info.
691 */
692
693 /* Reset all macros within TRACEPOINT_EVENT */
694 #include <lttng/ust-tracepoint-event-reset.h>
695
696 #undef TRACEPOINT_MODEL_EMF_URI
697 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
698 static const char *_model_emf_uri___##__provider##___##__name = __uri;
699
700 #include TRACEPOINT_INCLUDE
701
702 /*
703 * Stage 7.1 of tracepoint event generation.
704 *
705 * Create events description structures. We use a weakref because
706 * loglevels are optional. If not declared, the event will point to the
707 * a loglevel that contains NULL.
708 */
709
710 /* Reset all macros within TRACEPOINT_EVENT */
711 #include <lttng/ust-tracepoint-event-reset.h>
712
713 #undef TRACEPOINT_EVENT_INSTANCE
714 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
715 static const int * \
716 __ref_loglevel___##_provider##___##_name \
717 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
718 static const char * \
719 __ref_model_emf_uri___##_provider##___##_name \
720 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
721 const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
722 .name = #_provider ":" #_name, \
723 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
724 .ctx = NULL, \
725 .fields = __event_fields___##_provider##___##_template, \
726 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template), \
727 .loglevel = &__ref_loglevel___##_provider##___##_name, \
728 .signature = __tp_event_signature___##_provider##___##_template, \
729 .u = { .ext = { .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name } }, \
730 };
731
732 #include TRACEPOINT_INCLUDE
733
734 /*
735 * Stage 7.2 of tracepoint event generation.
736 *
737 * Create array of events.
738 */
739
740 /* Reset all macros within TRACEPOINT_EVENT */
741 #include <lttng/ust-tracepoint-event-reset.h>
742
743 #undef TRACEPOINT_EVENT_INSTANCE
744 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
745 &__event_desc___##_provider##_##_name,
746
747 static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = {
748 #include TRACEPOINT_INCLUDE
749 };
750
751
752 /*
753 * Stage 8 of tracepoint event generation.
754 *
755 * Create a toplevel descriptor for the whole probe.
756 */
757
758 /* non-const because list head will be modified when registered. */
759 static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = {
760 .provider = __tp_stringify(TRACEPOINT_PROVIDER),
761 .event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER),
762 .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)),
763 .head = { NULL, NULL },
764 .lazy_init_head = { NULL, NULL },
765 .lazy = 0,
766 .major = LTTNG_UST_PROVIDER_MAJOR,
767 .minor = LTTNG_UST_PROVIDER_MINOR,
768 };
769
770 static int _TP_COMBINE_TOKENS(__probe_register_refcount___, TRACEPOINT_PROVIDER);
771
772 /*
773 * Stage 9 of tracepoint event generation.
774 *
775 * Register/unregister probes at module load/unload.
776 *
777 * Generate the constructor as an externally visible symbol for use when
778 * linking the probe statically.
779 *
780 * Register refcount is protected by libc dynamic loader mutex.
781 */
782
783 /* Reset all macros within TRACEPOINT_EVENT */
784 #include <lttng/ust-tracepoint-event-reset.h>
785 static void lttng_ust_notrace __attribute__((constructor))
786 _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void);
787 static void
788 _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void)
789 {
790 int ret;
791
792 if (_TP_COMBINE_TOKENS(__probe_register_refcount___,
793 TRACEPOINT_PROVIDER)++) {
794 return;
795 }
796 /*
797 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
798 * static inline function that ensures every probe PROVIDER
799 * argument match the provider within which they appear. It
800 * calls empty static inline functions, and therefore has no
801 * runtime effect. However, if it detects an error, a linker
802 * error will appear.
803 */
804 _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)();
805 ret = lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
806 if (ret) {
807 fprintf(stderr, "LTTng-UST: Error (%d) while registering tracepoint probe. Duplicate registration of tracepoint probes having the same name is not allowed.\n", ret);
808 abort();
809 }
810 }
811
812 static void lttng_ust_notrace __attribute__((destructor))
813 _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void);
814 static void
815 _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void)
816 {
817 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___,
818 TRACEPOINT_PROVIDER)) {
819 return;
820 }
821 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
822 }
823
824 int _TP_COMBINE_TOKENS(__tracepoint_provider_, TRACEPOINT_PROVIDER);
This page took 0.056108 seconds and 5 git commands to generate.