1 #include <linux/debugfs.h>
3 #include "lttng-types.h"
4 #include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
5 #include "../wrapper/ringbuffer/frontend_types.h"
6 #include "../ltt-events.h"
7 #include "../ltt-tracer-core.h"
10 * Macro declarations used for all stages.
14 * DECLARE_EVENT_CLASS can be used to add a generic function
15 * handlers for events. That is, if all events have the same
16 * parameters and just have distinct trace points.
17 * Each tracepoint can be defined with DEFINE_EVENT and that
18 * will map the DECLARE_EVENT_CLASS to the tracepoint.
20 * TRACE_EVENT is a one to one mapping between tracepoint and template.
24 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
25 DECLARE_EVENT_CLASS(name, \
31 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args))
33 #undef DEFINE_EVENT_PRINT
34 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
35 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
37 /* Callbacks are meaningless to LTTng. */
39 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
40 assign, print, reg, unreg) \
41 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
42 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
45 * Stage 1 of the trace events.
47 * Create dummy trace calls for each events, verifying that the LTTng module
48 * TRACE_EVENT headers match the kernel arguments. Will be optimized out by the
52 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
55 #define TP_PROTO(args...) args
58 #define TP_ARGS(args...) args
61 #define DEFINE_EVENT(_template, _name, _proto, _args) \
62 void trace_##_name(_proto);
64 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
67 * Stage 2 of the trace events.
69 * Create event field type metadata section.
70 * Each event produce an array of fields.
73 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
75 /* Named field types must be defined in lttng-types.h */
78 #define __field(_type, _item) \
81 .type = __type_integer(_type, __BYTE_ORDER, 10, none),\
85 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
87 #undef __field_network
88 #define __field_network(_type, _item) \
91 .type = __type_integer(_type, __BIG_ENDIAN, 10, none),\
95 #define __array_enc(_type, _item, _length, _encoding) \
100 .atype = atype_array, \
104 .elem_type = __type_integer(_type, __BYTE_ORDER, 10, _encoding), \
110 #define __array(_type, _item, _length) \
111 __array_enc(_type, _item, _length, none)
114 #define __array_text(_type, _item, _length) \
115 __array_enc(_type, _item, _length, UTF8)
117 #undef __dynamic_array_enc
118 #define __dynamic_array_enc(_type, _item, _length, _encoding) \
123 .atype = atype_sequence, \
126 .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \
127 .elem_type = __type_integer(_type, __BYTE_ORDER, 10, _encoding), \
132 #undef __dynamic_array
133 #define __dynamic_array(_type, _item, _length) \
134 __dynamic_array_enc(_type, _item, _length, none)
136 #undef __dynamic_array_text
137 #define __dynamic_array_text(_type, _item, _length) \
138 __dynamic_array_enc(_type, _item, _length, UTF8)
141 #define __string(_item, _src) \
146 .atype = atype_string, \
147 .u.basic.string.encoding = lttng_encode_UTF8, \
151 #undef TP_STRUCT__entry
152 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
154 #undef DECLARE_EVENT_CLASS
155 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
156 static const struct lttng_event_field __event_fields___##_name[] = { \
160 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
162 #undef __type_integer
165 * Stage 3 of the trace events.
167 * Create probe callback prototypes.
170 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
173 #define TP_PROTO(args...) args
175 #undef DECLARE_EVENT_CLASS
176 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
177 static void __event_probe__##_name(void *__data, _proto);
179 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
182 * Stage 4 of the trace events.
184 * Create an array of events.
187 /* Named field types must be defined in lttng-types.h */
189 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
192 #define DEFINE_EVENT(_template, _name, _proto, _args) \
194 .fields = __event_fields___##_template, \
196 .probe_callback = (void *) &__event_probe__##_template,\
197 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
198 .owner = THIS_MODULE, \
201 #define TP_ID1(_token, _system) _token##_system
202 #define TP_ID(_token, _system) TP_ID1(_token, _system)
204 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
205 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
213 * Stage 5 of the trace events.
215 * Create a toplevel descriptor for the whole probe.
218 #define TP_ID1(_token, _system) _token##_system
219 #define TP_ID(_token, _system) TP_ID1(_token, _system)
221 /* non-const because list head will be modified when registered. */
222 static struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
223 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
224 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
231 * Stage 6 of the trace events.
233 * Create static inline function that calculates event size.
236 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
238 /* Named field types must be defined in lttng-types.h */
241 #define __field(_type, _item) \
242 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
243 __event_len += sizeof(_type);
246 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
249 #define __array(_type, _item, _length) \
250 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
251 __event_len += sizeof(_type) * (_length);
254 #define __array_text(_type, _item, _length) \
255 __array(_type, _item, _length)
257 #undef __dynamic_array
258 #define __dynamic_array(_type, _item, _length) \
259 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(u32)); \
260 __event_len += sizeof(u32); \
261 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
262 __event_len += sizeof(_type) * (_length);
264 #undef __dynamic_array_text
265 #define __dynamic_array_text(_type, _item, _length) \
266 __dynamic_array(_type, _item, _length)
269 #define __string(_item, _src) \
270 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
273 #define TP_PROTO(args...) args
275 #undef TP_STRUCT__entry
276 #define TP_STRUCT__entry(args...) args
278 #undef DECLARE_EVENT_CLASS
279 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
280 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
282 size_t __event_len = 0; \
283 unsigned int __dynamic_len_idx = 0; \
286 (void) __dynamic_len_idx; /* don't warn if unused */ \
288 return __event_len; \
291 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
294 * Stage 7 of the trace events.
296 * Create static inline function that calculates event payload alignment.
299 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
301 /* Named field types must be defined in lttng-types.h */
304 #define __field(_type, _item) \
305 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
308 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
311 #define __array(_type, _item, _length) \
312 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
315 #define __array_text(_type, _item, _length) \
316 __array(_type, _item, _length)
318 #undef __dynamic_array
319 #define __dynamic_array(_type, _item, _length) \
320 __event_align = max_t(size_t, __event_align, ltt_alignof(u32)); \
321 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
323 #undef __dynamic_array_text
324 #define __dynamic_array_text(_type, _item, _length) \
325 __dynamic_array(_type, _item, _length)
328 #define __string(_item, _src)
331 #define TP_PROTO(args...) args
333 #undef TP_STRUCT__entry
334 #define TP_STRUCT__entry(args...) args
336 #undef DECLARE_EVENT_CLASS
337 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
338 static inline size_t __event_get_align__##_name(_proto) \
340 size_t __event_align = 1; \
342 return __event_align; \
345 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
349 * Stage 8 of the trace events.
351 * Create structure declaration that allows the "assign" macros to access the
355 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
357 /* Named field types must be defined in lttng-types.h */
360 #define __field(_type, _item) _type _item;
363 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
366 #define __array(_type, _item, _length) _type _item;
369 #define __array_text(_type, _item, _length) \
370 __array(_type, _item, _length)
372 #undef __dynamic_array
373 #define __dynamic_array(_type, _item, _length) _type _item;
375 #undef __dynamic_array_text
376 #define __dynamic_array_text(_type, _item, _length) \
377 __dynamic_array(_type, _item, _length)
380 #define __string(_item, _src) char _item;
382 #undef TP_STRUCT__entry
383 #define TP_STRUCT__entry(args...) args
385 #undef DECLARE_EVENT_CLASS
386 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
387 struct __event_typemap__##_name { \
391 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
395 * Stage 9 of the trace events.
397 * Create the probe function : call even size calculation and write event data
400 * We use both the field and assignment macros to write the fields in the order
401 * defined in the field declaration. The field declarations control the
402 * execution order, jumping to the appropriate assignment block.
405 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
408 #define __field(_type, _item) \
409 goto __assign_##_item; \
413 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
416 #define __array(_type, _item, _length) \
417 goto __assign_##_item; \
421 #define __array_text(_type, _item, _length) \
422 __array(_type, _item, _length)
424 #undef __dynamic_array
425 #define __dynamic_array(_type, _item, _length) \
426 goto __assign_##_item##_1; \
427 __end_field_##_item##_1: \
428 goto __assign_##_item##_2; \
429 __end_field_##_item##_2:
431 #undef __dynamic_array_text
432 #define __dynamic_array_text(_type, _item, _length) \
433 __dynamic_array(_type, _item, _length)
436 #define __string(_item, _src) \
437 goto __assign_##_item; \
441 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
445 #define tp_assign(dest, src) \
448 __typeof__(__typemap.dest) __tmp = (src); \
449 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(__tmp)); \
450 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
452 goto __end_field_##dest;
455 #define tp_memcpy(dest, src, len) \
458 (void) __typemap.dest; \
459 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(__typemap.dest)); \
460 __chan->ops->event_write(&ctx, src, len); \
461 goto __end_field_##dest;
464 #define tp_memcpy_dyn(dest, src, len) \
465 __assign_##dest##_1: \
467 u32 __tmpl = (len); \
468 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(u32)); \
469 __chan->ops->event_write(&ctx, &__tmpl, sizeof(u32)); \
471 goto __end_field_##dest##_1; \
472 __assign_##dest##_2: \
473 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(__typemap.dest)); \
474 __chan->ops->event_write(&ctx, src, len); \
475 goto __end_field_##dest##_2;
478 #define tp_strcpy(dest, src) \
479 tp_memcpy(dest, src, __get_dynamic_array_len(dest))
481 /* Named field types must be defined in lttng-types.h */
484 #define __get_str(field) field
486 #undef __get_dynamic_array
487 #define __get_dynamic_array(field) field
489 /* Beware: this get len actually consumes the len value */
490 #undef __get_dynamic_array_len
491 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
494 #define TP_PROTO(args...) args
497 #define TP_ARGS(args...) args
499 #undef TP_STRUCT__entry
500 #define TP_STRUCT__entry(args...) args
502 #undef TP_fast_assign
503 #define TP_fast_assign(args...) args
505 #undef DECLARE_EVENT_CLASS
506 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
507 static void __event_probe__##_name(void *__data, _proto) \
509 struct ltt_event *__event = __data; \
510 struct ltt_channel *__chan = __event->chan; \
511 struct lib_ring_buffer_ctx ctx; \
512 size_t __event_len, __event_align; \
513 size_t __dynamic_len_idx = 0; \
514 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
515 struct __event_typemap__##_name __typemap; \
519 (void) __dynamic_len_idx; /* don't warn if unused */ \
520 if (!ACCESS_ONCE(__chan->session->active)) \
522 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
523 __event_align = __event_get_align__##_name(_args); \
524 lib_ring_buffer_ctx_init(&ctx, __chan->chan, NULL, __event_len, \
525 __event_align, -1); \
526 __ret = __chan->ops->event_reserve(&ctx, __event->id); \
529 /* Control code (field ordering) */ \
531 __chan->ops->event_commit(&ctx); \
533 /* Copy code, steered by control code */ \
537 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
540 * Stage 10 of the trace events.
542 * Register/unregister probes at module load/unload.
545 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
547 #define TP_ID1(_token, _system) _token##_system
548 #define TP_ID(_token, _system) TP_ID1(_token, _system)
549 #define module_init_eval1(_token, _system) module_init(_token##_system)
550 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
551 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
552 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
554 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
556 wrapper_vmalloc_sync_all();
557 return ltt_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
560 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
562 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
564 ltt_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
567 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
569 #undef module_init_eval
570 #undef module_exit_eval
This page took 0.08462 seconds and 5 git commands to generate.