38c61cd85dfb8ffd2057c756f8d9597be7658ac2
2 #include <lttng-types.h>
3 #include <linux/debugfs.h>
4 #include <linux/vmalloc.h> /* for 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 1 of the trace events.
59 * Create event field type metadata section.
60 * Each event produce an array of fields.
63 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
65 /* Named field types must be defined in lttng-types.h */
68 #define __field(_type, _item) \
69 { .name = #_item, .type = { .atype = atype_integer, .name = #_type} },
72 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
75 #define __array(_type, _item, _length) \
79 .atype = atype_array, \
81 .u.array.elem_type = #_type, \
82 .u.array.length = _length, \
86 #undef __dynamic_array
87 #define __dynamic_array(_type, _item, _length) \
91 .atype = atype_sequence, \
93 .u.sequence.elem_type = #_type, \
94 .u.sequence.length_type = "u32", \
99 #define __string(_item, _src) \
103 .atype = atype_string, \
105 .u.string.encoding = lttng_encode_UTF8, \
109 #undef TP_STRUCT__entry
110 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
112 #undef DECLARE_EVENT_CLASS
113 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
114 static const struct lttng_event_field __event_fields___##_name[] = { \
118 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
121 * Stage 1.1 of the trace events.
123 * Create probe callback prototypes.
126 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
129 #define TP_PROTO(args...) args
131 #undef DECLARE_EVENT_CLASS
132 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
133 static void __event_probe__##_name(void *__data, _proto);
135 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
138 * Stage 2 of the trace events.
140 * Create an array of events.
143 /* Named field types must be defined in lttng-types.h */
145 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
148 #define DEFINE_EVENT(_template, _name, _proto, _args) \
150 .fields = __event_fields___##_template, \
152 .probe_callback = (void *) &__event_probe__##_template,\
153 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
156 #define TP_ID1(_token, _system) _token##_system
157 #define TP_ID(_token, _system) TP_ID1(_token, _system)
159 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
160 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
167 * Stage 3 of the trace events.
169 * Create seq file metadata output.
172 #define TP_ID1(_token, _system) _token##_system
173 #define TP_ID(_token, _system) TP_ID1(_token, _system)
175 static void *TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
)(struct seq_file
*m
,
178 const struct lttng_event_desc
*desc
=
179 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[*pos
];
181 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
182 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
184 return (void *) desc
;
187 static void *TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
)(struct seq_file
*m
,
188 void *p
, loff_t
*ppos
)
190 const struct lttng_event_desc
*desc
=
191 &TP_ID(__event_desc___
, TRACE_SYSTEM
)[++(*ppos
)];
193 if (desc
> &TP_ID(__event_desc___
, TRACE_SYSTEM
)
194 [ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)) - 1])
196 return (void *) desc
;
199 static void TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
)(struct seq_file
*m
,
204 static int TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
)(struct seq_file
*m
,
207 const struct lttng_event_desc
*desc
= p
;
210 seq_printf(m
, "event {\n"
213 "\tstream = UNKNOWN;\n"
216 for (i
= 0; i
< desc
->nr_fields
; i
++) {
217 if (desc
->fields
[i
].type
.name
) /* Named type */
218 seq_printf(m
, "\t\t%s",
219 desc
->fields
[i
].type
.name
);
220 else /* Nameless type */
221 lttng_print_event_type(m
, 2, &desc
->fields
[i
].type
);
222 seq_printf(m
, " %s;\n", desc
->fields
[i
].name
);
224 seq_printf(m
, "\t};\n");
225 seq_printf(m
, "};\n");
230 struct seq_operations
TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
) = {
231 .start
= TP_ID(__lttng_seq_start__
, TRACE_SYSTEM
),
232 .next
= TP_ID(__lttng_seq_next__
, TRACE_SYSTEM
),
233 .stop
= TP_ID(__lttng_seq_stop__
, TRACE_SYSTEM
),
234 .show
= TP_ID(__lttng_seq_show__
, TRACE_SYSTEM
),
238 TP_ID(__lttng_types_open__
, TRACE_SYSTEM
)(struct inode
*inode
, struct file
*file
)
240 return seq_open(file
, &TP_ID(__lttng_types_seq_ops__
, TRACE_SYSTEM
));
244 struct file_operations
TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
) = {
245 .open
= TP_ID(__lttng_types_open__
, TRACE_SYSTEM
),
248 .release
= seq_release_private
,
251 static struct dentry
*TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
);
253 static int TP_ID(__lttng_types_init__
, TRACE_SYSTEM
)(void)
257 TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
) =
258 debugfs_create_file("lttng-events-" __stringify(TRACE_SYSTEM
),
260 &TP_ID(__lttng_types_fops__
, TRACE_SYSTEM
));
261 if (IS_ERR(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
))
262 || !TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
)) {
263 printk(KERN_ERR
"Error creating LTTng type export file\n");
271 static void TP_ID(__lttng_types_exit__
, TRACE_SYSTEM
)(void)
273 debugfs_remove(TP_ID(__lttng_types_dentry__
, TRACE_SYSTEM
));
280 * Stage 4 of the trace events.
282 * Create static inline function that calculates event size.
285 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
287 /* Named field types must be defined in lttng-types.h */
290 #define __field(_type, _item) \
291 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
292 __event_len += sizeof(_type);
295 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
298 #define __array(_type, _item, _length) \
299 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
300 __event_len += sizeof(_type) * (_length);
302 #undef __dynamic_array
303 #define __dynamic_array(_type, _item, _length) \
304 __event_len += lib_ring_buffer_align(__event_len, __alignof__(u32)); \
305 __event_len += sizeof(u32); \
306 __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \
307 __event_len += sizeof(_type) * (_length);
310 #define __string(_item, _src) \
311 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
314 #define TP_PROTO(args...) args
316 #undef TP_STRUCT__entry
317 #define TP_STRUCT__entry(args...) args
319 #undef DECLARE_EVENT_CLASS
320 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
321 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
323 size_t __event_len = 0; \
324 unsigned int __dynamic_len_idx = 0; \
327 (void) __dynamic_len_idx; /* don't warn if unused */ \
329 return __event_len; \
332 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
337 * Stage 5 of the trace events.
339 * Create static inline function that calculates event payload alignment.
342 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
344 /* Named field types must be defined in lttng-types.h */
347 #define __field(_type, _item) \
348 __event_align = max_t(size_t, __event_align, __alignof__(_type));
351 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
354 #define __array(_type, _item, _length) \
355 __event_align = max_t(size_t, __event_align, __alignof__(_type));
357 #undef __dynamic_array
358 #define __dynamic_array(_type, _item, _length) \
359 __event_align = max_t(size_t, __event_align, __alignof__(u32)); \
360 __event_align = max_t(size_t, __event_align, __alignof__(_type));
363 #define __string(_item, _src)
366 #define TP_PROTO(args...) args
368 #undef TP_STRUCT__entry
369 #define TP_STRUCT__entry(args...) args
371 #undef DECLARE_EVENT_CLASS
372 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
373 static inline size_t __event_get_align__##_name(_proto) \
375 size_t __event_align = 1; \
377 return __event_align; \
380 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
384 * Stage 6 of the trace events.
386 * Create structure declaration that allows the "assign" macros to access the
390 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
392 /* Named field types must be defined in lttng-types.h */
395 #define __field(_type, _item) _type _item;
398 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
401 #define __array(_type, _item, _length) _type _item;
403 #undef __dynamic_array
404 #define __dynamic_array(_type, _item, _length) _type _item;
407 #define __string(_item, _src) char _item;
409 #undef TP_STRUCT__entry
410 #define TP_STRUCT__entry(args...) args
412 #undef DECLARE_EVENT_CLASS
413 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
414 struct __event_typemap__##_name { \
418 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
422 * Stage 7 of the trace events.
424 * Create the probe function : call even size calculation and write event data
427 * We use both the field and assignment macros to write the fields in the order
428 * defined in the field declaration. The field declarations control the
429 * execution order, jumping to the appropriate assignment block.
432 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
435 #define __field(_type, _item) \
436 goto __assign_##_item; \
440 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
443 #define __array(_type, _item, _length) \
444 goto __assign_##_item; \
447 #undef __dynamic_array
448 #define __dynamic_array(_type, _item, _length) \
449 goto __assign_##_item##_1; \
450 __end_field_##_item##_1: \
451 goto __assign_##_item##_2; \
452 __end_field_##_item##_2:
455 #define __string(_item, _src) \
456 goto __assign_##_item; \
460 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
464 #define tp_assign(dest, src) \
467 __typeof__(__typemap.dest) __tmp = (src); \
468 lib_ring_buffer_align_ctx(&ctx, __alignof__(__tmp)); \
469 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
471 goto __end_field_##dest;
474 #define tp_memcpy(dest, src, len) \
476 lib_ring_buffer_align_ctx(&ctx, __alignof__(__typemap.dest)); \
477 __chan->ops->event_write(&ctx, src, len); \
478 goto __end_field_##dest;
481 #define tp_memcpy_dyn(dest, src, len) \
482 __assign_##dest##_1: \
484 u32 __tmpl = (len); \
485 lib_ring_buffer_align_ctx(&ctx, __alignof__(u32)); \
486 __chan->ops->event_write(&ctx, &__tmpl, sizeof(u32)); \
488 goto __end_field_##dest##_1; \
489 __assign_##dest##_2: \
490 lib_ring_buffer_align_ctx(&ctx, __alignof__(__typemap.dest)); \
491 __chan->ops->event_write(&ctx, src, len); \
492 goto __end_field_##dest##_2;
495 #define tp_strcpy(dest, src) \
496 tp_memcpy(dest, src, __get_dynamic_array_len(dest))
498 /* Named field types must be defined in lttng-types.h */
501 #define __get_str(field) field
503 #undef __get_dynamic_array
504 #define __get_dynamic_array(field) field
506 /* Beware: this get len actually consumes the len value */
507 #undef __get_dynamic_array_len
508 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
511 #define TP_PROTO(args...) args
514 #define TP_ARGS(args...) args
516 #undef TP_STRUCT__entry
517 #define TP_STRUCT__entry(args...) args
519 #undef TP_fast_assign
520 #define TP_fast_assign(args...) args
522 #undef DECLARE_EVENT_CLASS
523 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
524 static void __event_probe__##_name(void *__data, _proto) \
526 struct ltt_event *__event = __data; \
527 struct ltt_channel *__chan = __event->chan; \
528 struct lib_ring_buffer_ctx ctx; \
529 size_t __event_len, __event_align; \
530 size_t __dynamic_len_idx = 0; \
531 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
532 struct __event_typemap__##_name __typemap; \
536 (void) __dynamic_len_idx; /* don't warn if unused */ \
537 if (!ACCESS_ONCE(__chan->session->active)) \
539 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
540 __event_align = __event_get_align__##_name(_args); \
541 lib_ring_buffer_ctx_init(&ctx, __chan->chan, NULL, __event_len, \
542 __event_align, -1); \
543 __ret = __chan->ops->event_reserve(&ctx); \
546 /* Control code (field ordering) */ \
548 __chan->ops->event_commit(&ctx); \
550 /* Copy code, steered by control code */ \
554 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
557 * Stage 8 of the trace events.
559 * Register/unregister probes at module load/unload.
562 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
564 #define TP_ID1(_token, _system) _token##_system
565 #define TP_ID(_token, _system) TP_ID1(_token, _system)
566 #define module_init_eval1(_token, _system) module_init(_token##_system)
567 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
568 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
569 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
571 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
577 ret
= TP_ID(__lttng_types_init__
, TRACE_SYSTEM
)();
580 for (i
= 0; i
< ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)); i
++) {
581 const struct lttng_event_desc
*event_desc
;
583 event_desc
= &TP_ID(__event_desc___
, TRACE_SYSTEM
)[i
];
584 ret
= ltt_probe_register(event_desc
->name
,
585 event_desc
->probe_callback
);
592 for (i
--; i
>= 0; i
--) {
593 const struct lttng_event_desc
*event_desc
;
595 event_desc
= &TP_ID(__event_desc___
, TRACE_SYSTEM
)[i
];
596 ltt_probe_unregister(event_desc
->name
);
601 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
603 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
607 for (i
= 0; i
< ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)); i
++) {
608 const struct lttng_event_desc
*event_desc
;
610 event_desc
= &TP_ID(__event_desc___
, TRACE_SYSTEM
)[i
];
611 ltt_probe_unregister(event_desc
->name
);
613 TP_ID(__lttng_types_exit__
, TRACE_SYSTEM
)();
616 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
618 #undef module_init_eval
619 #undef module_exit_eval
This page took 0.063631 seconds and 4 git commands to generate.