3a5a3b9cd61c5aeba731e7232b19d398ad5c0584
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 0.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 1 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) \
79 { .name = #_item, .type = { .atype = atype_integer, .name = #_type} },
82 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
85 #define __array(_type, _item, _length) \
89 .atype = atype_array, \
91 .u.array.elem_type = #_type, \
92 .u.array.length = _length, \
96 #undef __dynamic_array
97 #define __dynamic_array(_type, _item, _length) \
101 .atype = atype_sequence, \
103 .u.sequence.elem_type = #_type, \
104 .u.sequence.length_type = "u32", \
109 #define __string(_item, _src) \
113 .atype = atype_string, \
115 .u.string.encoding = lttng_encode_UTF8, \
119 #undef TP_STRUCT__entry
120 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
122 #undef DECLARE_EVENT_CLASS
123 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
124 static const struct lttng_event_field __event_fields___##_name[] = { \
128 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
131 * Stage 1.1 of the trace events.
133 * Create probe callback prototypes.
136 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
139 #define TP_PROTO(args...) args
141 #undef DECLARE_EVENT_CLASS
142 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
143 static void __event_probe__##_name(void *__data, _proto);
145 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
148 * Stage 2 of the trace events.
150 * Create an array of events.
153 /* Named field types must be defined in lttng-types.h */
155 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
158 #define DEFINE_EVENT(_template, _name, _proto, _args) \
160 .fields = __event_fields___##_template, \
162 .probe_callback = (void *) &__event_probe__##_template,\
163 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
166 #define TP_ID1(_token, _system) _token##_system
167 #define TP_ID(_token, _system) TP_ID1(_token, _system)
169 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
170 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
177 * Stage 3 of the trace events.
179 * Create seq file metadata output.
182 #define TP_ID1(_token, _system) _token##_system
183 #define TP_ID(_token, _system) TP_ID1(_token, _system)
185 static void *TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
)(struct seq_file
*m
,
188 const struct lttng_event_desc
*desc
=
189 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[*pos
];
191 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
192 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
194 return (void *) desc
;
197 static void *TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
)(struct seq_file
*m
,
198 void *p
, loff_t
*ppos
)
200 const struct lttng_event_desc
*desc
=
201 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[++(*ppos
)];
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_stop__
, TRACE_SYSTEM
)(struct seq_file
*m
,
214 static int TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
)(struct seq_file
*m
,
217 const struct lttng_event_desc
*desc
= p
;
220 seq_printf(m
, "event {\n"
223 "\tstream = UNKNOWN;\n"
226 for (i
= 0; i
< desc
->nr_fields
; i
++) {
227 if (desc
->fields
[i
].type
.name
) /* Named type */
228 seq_printf(m
, "\t\t%s",
229 desc
->fields
[i
].type
.name
);
230 else /* Nameless type */
231 lttng_print_event_type(m
, 2, &desc
->fields
[i
].type
);
232 seq_printf(m
, " %s;\n", desc
->fields
[i
].name
);
234 seq_printf(m
, "\t};\n");
235 seq_printf(m
, "};\n");
240 struct seq_operations
TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
) = {
241 .start
= TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
),
242 .next
= TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
),
243 .stop
= TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
),
244 .show
= TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
),
248 TP_ID(__lttng_types_open__
, TRACE_SYSTEM
)(struct inode
*inode
, struct file
*file
)
250 return seq_open(file
, &TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
));
254 struct file_operations
TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
) = {
255 .open
= TP_ID(__lttng_types_open__
, TRACE_SYSTEM
),
258 .release
= seq_release_private
,
261 static struct dentry
*TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
);
263 static int TP_ID(__lttng_types_init__
, TRACE_SYSTEM
)(void)
267 TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
) =
268 debugfs_create_file("lttng-events-" __stringify(TRACE_SYSTEM
),
270 &TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
));
271 if (IS_ERR(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
))
272 || !TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
)) {
273 printk(KERN_ERR
"Error creating LTTng type export file\n");
281 static void TP_ID(__lttng_types_exit__
, TRACE_SYSTEM
)(void)
283 debugfs_remove(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
));
290 * Stage 4 of the trace events.
292 * Create static inline function that calculates event size.
295 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
297 /* Named field types must be defined in lttng-types.h */
300 #define __field(_type, _item) \
301 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
302 __event_len += sizeof(_type);
305 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
308 #define __array(_type, _item, _length) \
309 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
310 __event_len += sizeof(_type) * (_length);
312 #undef __dynamic_array
313 #define __dynamic_array(_type, _item, _length) \
314 __event_len += lib_ring_buffer_align(__event_len, __alignof__(u32)); \
315 __event_len += sizeof(u32); \
316 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
317 __event_len += sizeof(_type) * (_length);
320 #define __string(_item, _src) \
321 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
324 #define TP_PROTO(args...) args
326 #undef TP_STRUCT__entry
327 #define TP_STRUCT__entry(args...) args
329 #undef DECLARE_EVENT_CLASS
330 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
331 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
333 size_t __event_len = 0; \
334 unsigned int __dynamic_len_idx = 0; \
337 (void) __dynamic_len_idx; /* don't warn if unused */ \
339 return __event_len; \
342 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
347 * Stage 5 of the trace events.
349 * Create static inline function that calculates event payload alignment.
352 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
354 /* Named field types must be defined in lttng-types.h */
357 #define __field(_type, _item) \
358 __event_align = max_t(size_t, __event_align, __alignof__(_type));
361 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
364 #define __array(_type, _item, _length) \
365 __event_align = max_t(size_t, __event_align, __alignof__(_type));
367 #undef __dynamic_array
368 #define __dynamic_array(_type, _item, _length) \
369 __event_align = max_t(size_t, __event_align, __alignof__(u32)); \
370 __event_align = max_t(size_t, __event_align, __alignof__(_type));
373 #define __string(_item, _src)
376 #define TP_PROTO(args...) args
378 #undef TP_STRUCT__entry
379 #define TP_STRUCT__entry(args...) args
381 #undef DECLARE_EVENT_CLASS
382 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
383 static inline size_t __event_get_align__##_name(_proto) \
385 size_t __event_align = 1; \
387 return __event_align; \
390 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
394 * Stage 6 of the trace events.
396 * Create structure declaration that allows the "assign" macros to access the
400 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
402 /* Named field types must be defined in lttng-types.h */
405 #define __field(_type, _item) _type _item;
408 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
411 #define __array(_type, _item, _length) _type _item;
413 #undef __dynamic_array
414 #define __dynamic_array(_type, _item, _length) _type _item;
417 #define __string(_item, _src) char _item;
419 #undef TP_STRUCT__entry
420 #define TP_STRUCT__entry(args...) args
422 #undef DECLARE_EVENT_CLASS
423 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
424 struct __event_typemap__##_name { \
428 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
432 * Stage 7 of the trace events.
434 * Create the probe function : call even size calculation and write event data
437 * We use both the field and assignment macros to write the fields in the order
438 * defined in the field declaration. The field declarations control the
439 * execution order, jumping to the appropriate assignment block.
442 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
445 #define __field(_type, _item) \
446 goto __assign_##_item; \
450 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
453 #define __array(_type, _item, _length) \
454 goto __assign_##_item; \
457 #undef __dynamic_array
458 #define __dynamic_array(_type, _item, _length) \
459 goto __assign_##_item##_1; \
460 __end_field_##_item##_1: \
461 goto __assign_##_item##_2; \
462 __end_field_##_item##_2:
465 #define __string(_item, _src) \
466 goto __assign_##_item; \
470 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
474 #define tp_assign(dest, src) \
477 __typeof__(__typemap.dest) __tmp = (src); \
478 lib_ring_buffer_align_ctx(&ctx, __alignof__(__tmp)); \
479 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
481 goto __end_field_##dest;
484 #define tp_memcpy(dest, src, len) \
486 lib_ring_buffer_align_ctx(&ctx, __alignof__(__typemap.dest)); \
487 __chan->ops->event_write(&ctx, src, len); \
488 goto __end_field_##dest;
491 #define tp_memcpy_dyn(dest, src, len) \
492 __assign_##dest##_1: \
494 u32 __tmpl = (len); \
495 lib_ring_buffer_align_ctx(&ctx, __alignof__(u32)); \
496 __chan->ops->event_write(&ctx, &__tmpl, sizeof(u32)); \
498 goto __end_field_##dest##_1; \
499 __assign_##dest##_2: \
500 lib_ring_buffer_align_ctx(&ctx, __alignof__(__typemap.dest)); \
501 __chan->ops->event_write(&ctx, src, len); \
502 goto __end_field_##dest##_2;
505 #define tp_strcpy(dest, src) \
506 tp_memcpy(dest, src, __get_dynamic_array_len(dest))
508 /* Named field types must be defined in lttng-types.h */
511 #define __get_str(field) field
513 #undef __get_dynamic_array
514 #define __get_dynamic_array(field) field
516 /* Beware: this get len actually consumes the len value */
517 #undef __get_dynamic_array_len
518 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
521 #define TP_PROTO(args...) args
524 #define TP_ARGS(args...) args
526 #undef TP_STRUCT__entry
527 #define TP_STRUCT__entry(args...) args
529 #undef TP_fast_assign
530 #define TP_fast_assign(args...) args
532 #undef DECLARE_EVENT_CLASS
533 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
534 static void __event_probe__##_name(void *__data, _proto) \
536 struct ltt_event *__event = __data; \
537 struct ltt_channel *__chan = __event->chan; \
538 struct lib_ring_buffer_ctx ctx; \
539 size_t __event_len, __event_align; \
540 size_t __dynamic_len_idx = 0; \
541 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
542 struct __event_typemap__##_name __typemap; \
546 (void) __dynamic_len_idx; /* don't warn if unused */ \
547 if (!ACCESS_ONCE(__chan->session->active)) \
549 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
550 __event_align = __event_get_align__##_name(_args); \
551 lib_ring_buffer_ctx_init(&ctx, __chan->chan, NULL, __event_len, \
552 __event_align, -1); \
553 __ret = __chan->ops->event_reserve(&ctx); \
556 /* Control code (field ordering) */ \
558 __chan->ops->event_commit(&ctx); \
560 /* Copy code, steered by control code */ \
564 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
567 * Stage 8 of the trace events.
569 * Register/unregister probes at module load/unload.
572 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
574 #define TP_ID1(_token, _system) _token##_system
575 #define TP_ID(_token, _system) TP_ID1(_token, _system)
576 #define module_init_eval1(_token, _system) module_init(_token##_system)
577 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
578 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
579 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
581 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
586 wrapper_vmalloc_sync_all();
587 ret
= TP_ID(__lttng_types_init__
, TRACE_SYSTEM
)();
590 for (i
= 0; i
< ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)); i
++) {
591 const struct lttng_event_desc
*event_desc
;
593 event_desc
= &TP_ID(__event_desc___
, TRACE_SYSTEM
)[i
];
594 ret
= ltt_probe_register(event_desc
->name
,
595 event_desc
->probe_callback
);
602 for (i
--; i
>= 0; i
--) {
603 const struct lttng_event_desc
*event_desc
;
605 event_desc
= &TP_ID(__event_desc___
, TRACE_SYSTEM
)[i
];
606 ltt_probe_unregister(event_desc
->name
);
611 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
613 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
617 for (i
= 0; i
< ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)); i
++) {
618 const struct lttng_event_desc
*event_desc
;
620 event_desc
= &TP_ID(__event_desc___
, TRACE_SYSTEM
)[i
];
621 ltt_probe_unregister(event_desc
->name
);
623 TP_ID(__lttng_types_exit__
, TRACE_SYSTEM
)();
626 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
628 #undef module_init_eval
629 #undef module_exit_eval
This page took 0.041857 seconds and 4 git commands to generate.