2 #include <lttng-types.h>
3 #include <linux/debugfs.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"
9 struct lttng_event_field
{
11 const struct lttng_type type
;
14 struct lttng_event_desc
{
15 const struct lttng_event_field
*fields
;
18 unsigned int nr_fields
;
22 * Macro declarations used for all stages.
26 * DECLARE_EVENT_CLASS can be used to add a generic function
27 * handlers for events. That is, if all events have the same
28 * parameters and just have distinct trace points.
29 * Each tracepoint can be defined with DEFINE_EVENT and that
30 * will map the DECLARE_EVENT_CLASS to the tracepoint.
32 * TRACE_EVENT is a one to one mapping between tracepoint and template.
36 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
37 DECLARE_EVENT_CLASS(name, \
43 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args))
45 #undef DEFINE_EVENT_PRINT
46 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
47 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
49 /* Callbacks are meaningless to LTTng. */
51 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
52 assign, print, reg, unreg) \
53 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
54 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
57 * Stage 0.1 of the trace events.
59 * Create dummy trace calls for each events, verifying that the LTTng module
60 * TRACE_EVENT headers match the kernel arguments. Will be optimized out by the
64 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
67 #define TP_PROTO(args...) args
70 #define TP_ARGS(args...) args
73 #define DEFINE_EVENT(_template, _name, _proto, _args) \
74 void trace_##_name(_proto);
76 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
79 * Stage 1 of the trace events.
81 * Create event field type metadata section.
82 * Each event produce an array of fields.
85 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
87 /* Named field types must be defined in lttng-types.h */
90 #define __field(_type, _item) \
91 { .name = #_item, .type = { .atype = atype_integer, .name = #_type} },
94 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
97 #define __array(_type, _item, _length) \
101 .atype = atype_array, \
103 .u.array.elem_type = #_type, \
104 .u.array.length = _length, \
108 #undef __dynamic_array
109 #define __dynamic_array(_type, _item, _length) \
113 .atype = atype_sequence, \
115 .u.sequence.elem_type = #_type, \
116 .u.sequence.length_type = "u32", \
121 #define __string(_item, _src) \
125 .atype = atype_string, \
127 .u.string.encoding = lttng_encode_UTF8, \
131 #undef TP_STRUCT__entry
132 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
134 #undef DECLARE_EVENT_CLASS
135 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
136 static const struct lttng_event_field __event_fields___##_name[] = { \
140 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
143 * Stage 1.1 of the trace events.
145 * Create probe callback prototypes.
148 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
151 #define TP_PROTO(args...) args
153 #undef DECLARE_EVENT_CLASS
154 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
155 static void __event_probe__##_name(void *__data, _proto);
157 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
160 * Stage 2 of the trace events.
162 * Create an array of events.
165 /* Named field types must be defined in lttng-types.h */
167 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
170 #define DEFINE_EVENT(_template, _name, _proto, _args) \
172 .fields = __event_fields___##_template, \
174 .probe_callback = (void *) &__event_probe__##_template,\
175 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
178 #define TP_ID1(_token, _system) _token##_system
179 #define TP_ID(_token, _system) TP_ID1(_token, _system)
181 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
182 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
189 * Stage 3 of the trace events.
191 * Create seq file metadata output.
194 #define TP_ID1(_token, _system) _token##_system
195 #define TP_ID(_token, _system) TP_ID1(_token, _system)
197 static void *TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
)(struct seq_file
*m
,
200 const struct lttng_event_desc
*desc
=
201 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[*pos
];
203 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
204 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
206 return (void *) desc
;
209 static void *TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
)(struct seq_file
*m
,
210 void *p
, loff_t
*ppos
)
212 const struct lttng_event_desc
*desc
=
213 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[++(*ppos
)];
215 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
216 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
218 return (void *) desc
;
221 static void TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
)(struct seq_file
*m
,
226 static int TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
)(struct seq_file
*m
,
229 const struct lttng_event_desc
*desc
= p
;
232 seq_printf(m
, "event {\n"
235 "\tstream = UNKNOWN;\n"
238 for (i
= 0; i
< desc
->nr_fields
; i
++) {
239 if (desc
->fields
[i
].type
.name
) /* Named type */
240 seq_printf(m
, "\t\t%s",
241 desc
->fields
[i
].type
.name
);
242 else /* Nameless type */
243 lttng_print_event_type(m
, 2, &desc
->fields
[i
].type
);
244 seq_printf(m
, " %s;\n", desc
->fields
[i
].name
);
246 seq_printf(m
, "\t};\n");
247 seq_printf(m
, "};\n");
252 struct seq_operations
TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
) = {
253 .start
= TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
),
254 .next
= TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
),
255 .stop
= TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
),
256 .show
= TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
),
260 TP_ID(__lttng_types_open__
, TRACE_SYSTEM
)(struct inode
*inode
, struct file
*file
)
262 return seq_open(file
, &TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
));
266 struct file_operations
TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
) = {
267 .open
= TP_ID(__lttng_types_open__
, TRACE_SYSTEM
),
270 .release
= seq_release_private
,
273 static struct dentry
*TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
);
275 static int TP_ID(__lttng_types_init__
, TRACE_SYSTEM
)(void)
279 TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
) =
280 debugfs_create_file("lttng-events-" __stringify(TRACE_SYSTEM
),
282 &TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
));
283 if (IS_ERR(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
))
284 || !TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
)) {
285 printk(KERN_ERR
"Error creating LTTng type export file\n");
293 static void TP_ID(__lttng_types_exit__
, TRACE_SYSTEM
)(void)
295 debugfs_remove(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
));
302 * Stage 4 of the trace events.
304 * Create static inline function that calculates event size.
307 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
309 /* Named field types must be defined in lttng-types.h */
312 #define __field(_type, _item) \
313 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
314 __event_len += sizeof(_type);
317 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
320 #define __array(_type, _item, _length) \
321 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
322 __event_len += sizeof(_type) * (_length);
324 #undef __dynamic_array
325 #define __dynamic_array(_type, _item, _length) \
326 __event_len += lib_ring_buffer_align(__event_len, __alignof__(u32)); \
327 __event_len += sizeof(u32); \
328 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
329 __event_len += sizeof(_type) * (_length);
332 #define __string(_item, _src) \
333 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
336 #define TP_PROTO(args...) args
338 #undef TP_STRUCT__entry
339 #define TP_STRUCT__entry(args...) args
341 #undef DECLARE_EVENT_CLASS
342 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
343 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
345 size_t __event_len = 0; \
346 unsigned int __dynamic_len_idx = 0; \
349 (void) __dynamic_len_idx; /* don't warn if unused */ \
351 return __event_len; \
354 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
359 * Stage 5 of the trace events.
361 * Create static inline function that calculates event payload alignment.
364 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
366 /* Named field types must be defined in lttng-types.h */
369 #define __field(_type, _item) \
370 __event_align = max_t(size_t, __event_align, __alignof__(_type));
373 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
376 #define __array(_type, _item, _length) \
377 __event_align = max_t(size_t, __event_align, __alignof__(_type));
379 #undef __dynamic_array
380 #define __dynamic_array(_type, _item, _length) \
381 __event_align = max_t(size_t, __event_align, __alignof__(u32)); \
382 __event_align = max_t(size_t, __event_align, __alignof__(_type));
385 #define __string(_item, _src)
388 #define TP_PROTO(args...) args
390 #undef TP_STRUCT__entry
391 #define TP_STRUCT__entry(args...) args
393 #undef DECLARE_EVENT_CLASS
394 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
395 static inline size_t __event_get_align__##_name(_proto) \
397 size_t __event_align = 1; \
399 return __event_align; \
402 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
406 * Stage 6 of the trace events.
408 * Create structure declaration that allows the "assign" macros to access the
412 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
414 /* Named field types must be defined in lttng-types.h */
417 #define __field(_type, _item) _type _item;
420 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
423 #define __array(_type, _item, _length) _type _item;
425 #undef __dynamic_array
426 #define __dynamic_array(_type, _item, _length) _type _item;
429 #define __string(_item, _src) char _item;
431 #undef TP_STRUCT__entry
432 #define TP_STRUCT__entry(args...) args
434 #undef DECLARE_EVENT_CLASS
435 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
436 struct __event_typemap__##_name { \
440 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
444 * Stage 7 of the trace events.
446 * Create the probe function : call even size calculation and write event data
449 * We use both the field and assignment macros to write the fields in the order
450 * defined in the field declaration. The field declarations control the
451 * execution order, jumping to the appropriate assignment block.
454 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
457 #define __field(_type, _item) \
458 goto __assign_##_item; \
462 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
465 #define __array(_type, _item, _length) \
466 goto __assign_##_item; \
469 #undef __dynamic_array
470 #define __dynamic_array(_type, _item, _length) \
471 goto __assign_##_item##_1; \
472 __end_field_##_item##_1: \
473 goto __assign_##_item##_2; \
474 __end_field_##_item##_2:
477 #define __string(_item, _src) \
478 goto __assign_##_item; \
482 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
486 #define tp_assign(dest, src) \
489 __typeof__(__typemap.dest) __tmp = (src); \
490 lib_ring_buffer_align_ctx(&ctx, __alignof__(__tmp)); \
491 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
493 goto __end_field_##dest;
496 #define tp_memcpy(dest, src, len) \
498 lib_ring_buffer_align_ctx(&ctx, __alignof__(__typemap.dest)); \
499 __chan->ops->event_write(&ctx, src, len); \
500 goto __end_field_##dest;
503 #define tp_memcpy_dyn(dest, src, len) \
504 __assign_##dest##_1: \
506 u32 __tmpl = (len); \
507 lib_ring_buffer_align_ctx(&ctx, __alignof__(u32)); \
508 __chan->ops->event_write(&ctx, &__tmpl, sizeof(u32)); \
510 goto __end_field_##dest##_1; \
511 __assign_##dest##_2: \
512 lib_ring_buffer_align_ctx(&ctx, __alignof__(__typemap.dest)); \
513 __chan->ops->event_write(&ctx, src, len); \
514 goto __end_field_##dest##_2;
517 #define tp_strcpy(dest, src) \
518 tp_memcpy(dest, src, __get_dynamic_array_len(dest))
520 /* Named field types must be defined in lttng-types.h */
523 #define __get_str(field) field
525 #undef __get_dynamic_array
526 #define __get_dynamic_array(field) field
528 /* Beware: this get len actually consumes the len value */
529 #undef __get_dynamic_array_len
530 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
533 #define TP_PROTO(args...) args
536 #define TP_ARGS(args...) args
538 #undef TP_STRUCT__entry
539 #define TP_STRUCT__entry(args...) args
541 #undef TP_fast_assign
542 #define TP_fast_assign(args...) args
544 #undef DECLARE_EVENT_CLASS
545 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
546 static void __event_probe__##_name(void *__data, _proto) \
548 struct ltt_event *__event = __data; \
549 struct ltt_channel *__chan = __event->chan; \
550 struct lib_ring_buffer_ctx ctx; \
551 size_t __event_len, __event_align; \
552 size_t __dynamic_len_idx = 0; \
553 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
554 struct __event_typemap__##_name __typemap; \
558 (void) __dynamic_len_idx; /* don't warn if unused */ \
559 if (!ACCESS_ONCE(__chan->session->active)) \
561 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
562 __event_align = __event_get_align__##_name(_args); \
563 lib_ring_buffer_ctx_init(&ctx, __chan->chan, NULL, __event_len, \
564 __event_align, -1); \
565 __ret = __chan->ops->event_reserve(&ctx); \
568 /* Control code (field ordering) */ \
570 __chan->ops->event_commit(&ctx); \
572 /* Copy code, steered by control code */ \
576 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
579 * Stage 8 of the trace events.
581 * Register/unregister probes at module load/unload.
584 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
586 #define TP_ID1(_token, _system) _token##_system
587 #define TP_ID(_token, _system) TP_ID1(_token, _system)
588 #define module_init_eval1(_token, _system) module_init(_token##_system)
589 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
590 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
591 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
593 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
598 wrapper_vmalloc_sync_all();
599 ret
= TP_ID(__lttng_types_init__
, TRACE_SYSTEM
)();
602 for (i
= 0; i
< ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)); i
++) {
603 const struct lttng_event_desc
*event_desc
;
605 event_desc
= &TP_ID(__event_desc___
, TRACE_SYSTEM
)[i
];
606 ret
= ltt_probe_register(event_desc
->name
,
607 event_desc
->probe_callback
);
614 for (i
--; i
>= 0; i
--) {
615 const struct lttng_event_desc
*event_desc
;
617 event_desc
= &TP_ID(__event_desc___
, TRACE_SYSTEM
)[i
];
618 ltt_probe_unregister(event_desc
->name
);
623 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
625 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
629 for (i
= 0; i
< ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)); i
++) {
630 const struct lttng_event_desc
*event_desc
;
632 event_desc
= &TP_ID(__event_desc___
, TRACE_SYSTEM
)[i
];
633 ltt_probe_unregister(event_desc
->name
);
635 TP_ID(__lttng_types_exit__
, TRACE_SYSTEM
)();
638 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
640 #undef module_init_eval
641 #undef module_exit_eval
This page took 0.043358 seconds and 5 git commands to generate.