925e12daaec0eb249a029abab1c57a577c221b6e
4 * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org>
5 * Copyright (C) 2010-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 * Dual LGPL v2.1/GPL v2 license.
10 #include <linux/debugfs.h>
12 #include "lttng-types.h"
13 #include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
14 #include "../wrapper/ringbuffer/frontend_types.h"
15 #include "../ltt-events.h"
16 #include "../ltt-tracer-core.h"
19 * Macro declarations used for all stages.
23 * DECLARE_EVENT_CLASS can be used to add a generic function
24 * handlers for events. That is, if all events have the same
25 * parameters and just have distinct trace points.
26 * Each tracepoint can be defined with DEFINE_EVENT and that
27 * will map the DECLARE_EVENT_CLASS to the tracepoint.
29 * TRACE_EVENT is a one to one mapping between tracepoint and template.
33 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
34 DECLARE_EVENT_CLASS(name, \
40 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args))
42 #undef DEFINE_EVENT_PRINT
43 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
44 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
46 /* Callbacks are meaningless to LTTng. */
48 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
49 assign, print, reg, unreg) \
50 TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
51 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
54 * Stage 1 of the trace events.
56 * Create dummy trace calls for each events, verifying that the LTTng module
57 * TRACE_EVENT headers match the kernel arguments. Will be optimized out by the
61 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
64 #define TP_PROTO(args...) args
67 #define TP_ARGS(args...) args
70 #define DEFINE_EVENT(_template, _name, _proto, _args) \
71 void trace_##_name(_proto);
73 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
76 * Stage 2 of the trace events.
78 * Create event field type metadata section.
79 * Each event produce an array of fields.
82 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
84 /* Named field types must be defined in lttng-types.h */
87 #define __field_full(_type, _item, _order, _base) \
90 .type = __type_integer(_type, _order, _base, none), \
94 #define __field(_type, _item) \
95 __field_full(_type, _item, __BYTE_ORDER, 10)
98 #define __field_ext(_type, _item, _filter_type) \
101 #undef __field_network
102 #define __field_network(_type, _item) \
103 __field_full(_type, _item, __BIG_ENDIAN, 10)
105 #undef __field_network_hex
106 #define __field_network_hex(_type, _item) \
107 __field_full(_type, _item, __BIG_ENDIAN, 16)
109 #undef __array_enc_ext
110 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
115 .atype = atype_array, \
119 .elem_type = __type_integer(_type, _order, _base, _encoding), \
125 #define __array(_type, _item, _length) \
126 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
129 #define __array_text(_type, _item, _length) \
130 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
133 #define __array_hex(_type, _item, _length) \
134 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
136 #undef __dynamic_array_enc_ext
137 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
142 .atype = atype_sequence, \
145 .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \
146 .elem_type = __type_integer(_type, _order, _base, _encoding), \
151 #undef __dynamic_array
152 #define __dynamic_array(_type, _item, _length) \
153 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
155 #undef __dynamic_array_text
156 #define __dynamic_array_text(_type, _item, _length) \
157 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
159 #undef __dynamic_array_hex
160 #define __dynamic_array_hex(_type, _item, _length) \
161 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
164 #define __string(_item, _src) \
169 .atype = atype_string, \
170 .u.basic.string.encoding = lttng_encode_UTF8, \
174 #undef TP_STRUCT__entry
175 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
177 #undef DECLARE_EVENT_CLASS
178 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
179 static const struct lttng_event_field __event_fields___##_name[] = { \
183 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
185 #undef __type_integer
188 * Stage 3 of the trace events.
190 * Create probe callback prototypes.
193 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
196 #define TP_PROTO(args...) args
198 #undef DECLARE_EVENT_CLASS
199 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
200 static void __event_probe__##_name(void *__data, _proto);
202 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
205 * Stage 4 of the trace events.
207 * Create an array of events.
210 /* Named field types must be defined in lttng-types.h */
212 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
215 #define TP_PROBE_CB(_template) &__event_probe__##_template
219 #define DEFINE_EVENT(_template, _name, _proto, _args) \
221 .fields = __event_fields___##_template, \
223 .probe_callback = (void *) TP_PROBE_CB(_template), \
224 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
225 .owner = THIS_MODULE, \
228 #define TP_ID1(_token, _system) _token##_system
229 #define TP_ID(_token, _system) TP_ID1(_token, _system)
231 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
232 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
240 * Stage 5 of the trace events.
242 * Create a toplevel descriptor for the whole probe.
245 #define TP_ID1(_token, _system) _token##_system
246 #define TP_ID(_token, _system) TP_ID1(_token, _system)
248 /* non-const because list head will be modified when registered. */
249 static struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
250 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
251 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
258 * Stage 6 of the trace events.
260 * Create static inline function that calculates event size.
263 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
265 /* Named field types must be defined in lttng-types.h */
268 #define __field_full(_type, _item, _order, _base) \
269 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
270 __event_len += sizeof(_type);
272 #undef __array_enc_ext
273 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
274 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
275 __event_len += sizeof(_type) * (_length);
277 #undef __dynamic_array_enc_ext
278 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
279 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(u32)); \
280 __event_len += sizeof(u32); \
281 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
282 __dynamic_len[__dynamic_len_idx] = (_length); \
283 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
287 #define __string(_item, _src) \
288 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
291 #define TP_PROTO(args...) args
293 #undef TP_STRUCT__entry
294 #define TP_STRUCT__entry(args...) args
296 #undef DECLARE_EVENT_CLASS
297 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
298 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
300 size_t __event_len = 0; \
301 unsigned int __dynamic_len_idx = 0; \
304 (void) __dynamic_len_idx; /* don't warn if unused */ \
306 return __event_len; \
309 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
312 * Stage 7 of the trace events.
314 * Create static inline function that calculates event payload alignment.
317 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
319 /* Named field types must be defined in lttng-types.h */
322 #define __field_full(_type, _item, _order, _base) \
323 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
325 #undef __array_enc_ext
326 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
327 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
329 #undef __dynamic_array_enc_ext
330 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
331 __event_align = max_t(size_t, __event_align, ltt_alignof(u32)); \
332 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
335 #define __string(_item, _src)
338 #define TP_PROTO(args...) args
340 #undef TP_STRUCT__entry
341 #define TP_STRUCT__entry(args...) args
343 #undef DECLARE_EVENT_CLASS
344 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
345 static inline size_t __event_get_align__##_name(_proto) \
347 size_t __event_align = 1; \
349 return __event_align; \
352 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
356 * Stage 8 of the trace events.
358 * Create structure declaration that allows the "assign" macros to access the
362 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
364 /* Named field types must be defined in lttng-types.h */
367 #define __field_full(_type, _item, _order, _base) _type _item;
369 #undef __array_enc_ext
370 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
373 #undef __dynamic_array_enc_ext
374 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
378 #define __string(_item, _src) char _item;
380 #undef TP_STRUCT__entry
381 #define TP_STRUCT__entry(args...) args
383 #undef DECLARE_EVENT_CLASS
384 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
385 struct __event_typemap__##_name { \
389 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
393 * Stage 9 of the trace events.
395 * Create the probe function : call even size calculation and write event data
398 * We use both the field and assignment macros to write the fields in the order
399 * defined in the field declaration. The field declarations control the
400 * execution order, jumping to the appropriate assignment block.
403 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
406 #define __field_full(_type, _item, _order, _base) \
407 goto __assign_##_item; \
410 #undef __array_enc_ext
411 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
412 goto __assign_##_item; \
415 #undef __dynamic_array_enc_ext
416 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
417 goto __assign_##_item##_1; \
418 __end_field_##_item##_1: \
419 goto __assign_##_item##_2; \
420 __end_field_##_item##_2:
423 #define __string(_item, _src) \
424 goto __assign_##_item; \
428 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
432 #define tp_assign(dest, src) \
435 __typeof__(__typemap.dest) __tmp = (src); \
436 lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__tmp)); \
437 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
439 goto __end_field_##dest;
442 #define tp_memcpy(dest, src, len) \
445 (void) __typemap.dest; \
446 lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \
447 __chan->ops->event_write(&__ctx, src, len); \
448 goto __end_field_##dest;
451 #define tp_memcpy_dyn(dest, src) \
452 __assign_##dest##_1: \
454 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
455 lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(u32)); \
456 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
458 goto __end_field_##dest##_1; \
459 __assign_##dest##_2: \
460 lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \
461 __chan->ops->event_write(&__ctx, src, \
462 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
463 goto __end_field_##dest##_2;
466 #define tp_strcpy(dest, src) \
467 tp_memcpy(dest, src, __get_dynamic_array_len(dest))
469 /* Named field types must be defined in lttng-types.h */
472 #define __get_str(field) field
474 #undef __get_dynamic_array
475 #define __get_dynamic_array(field) field
477 /* Beware: this get len actually consumes the len value */
478 #undef __get_dynamic_array_len
479 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
482 #define TP_PROTO(args...) args
485 #define TP_ARGS(args...) args
487 #undef TP_STRUCT__entry
488 #define TP_STRUCT__entry(args...) args
490 #undef TP_fast_assign
491 #define TP_fast_assign(args...) args
493 #undef DECLARE_EVENT_CLASS
494 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
495 static void __event_probe__##_name(void *__data, _proto) \
497 struct ltt_event *__event = __data; \
498 struct ltt_channel *__chan = __event->chan; \
499 struct lib_ring_buffer_ctx __ctx; \
500 size_t __event_len, __event_align; \
501 size_t __dynamic_len_idx = 0; \
502 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
503 struct __event_typemap__##_name __typemap; \
507 (void) __dynamic_len_idx; /* don't warn if unused */ \
508 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
510 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
512 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
514 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
515 __event_align = __event_get_align__##_name(_args); \
516 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
517 __event_align, -1); \
518 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
521 /* Control code (field ordering) */ \
523 __chan->ops->event_commit(&__ctx); \
525 /* Copy code, steered by control code */ \
529 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
532 * Stage 10 of the trace events.
534 * Register/unregister probes at module load/unload.
537 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
539 #define TP_ID1(_token, _system) _token##_system
540 #define TP_ID(_token, _system) TP_ID1(_token, _system)
541 #define module_init_eval1(_token, _system) module_init(_token##_system)
542 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
543 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
544 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
546 #ifndef TP_MODULE_OVERRIDE
547 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
549 wrapper_vmalloc_sync_all();
550 return ltt_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
553 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
555 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
557 ltt_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
560 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
563 #undef module_init_eval
564 #undef module_exit_eval
This page took 0.040313 seconds and 4 git commands to generate.