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(_type, _item) \
90 .type = __type_integer(_type, __BYTE_ORDER, 10, none),\
94 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
96 #undef __field_network
97 #define __field_network(_type, _item) \
100 .type = __type_integer(_type, __BIG_ENDIAN, 10, none),\
104 #define __array_enc(_type, _item, _length, _encoding) \
109 .atype = atype_array, \
113 .elem_type = __type_integer(_type, __BYTE_ORDER, 10, _encoding), \
119 #define __array(_type, _item, _length) \
120 __array_enc(_type, _item, _length, none)
123 #define __array_text(_type, _item, _length) \
124 __array_enc(_type, _item, _length, UTF8)
126 #undef __dynamic_array_enc
127 #define __dynamic_array_enc(_type, _item, _length, _encoding) \
132 .atype = atype_sequence, \
135 .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \
136 .elem_type = __type_integer(_type, __BYTE_ORDER, 10, _encoding), \
141 #undef __dynamic_array
142 #define __dynamic_array(_type, _item, _length) \
143 __dynamic_array_enc(_type, _item, _length, none)
145 #undef __dynamic_array_text
146 #define __dynamic_array_text(_type, _item, _length) \
147 __dynamic_array_enc(_type, _item, _length, UTF8)
150 #define __string(_item, _src) \
155 .atype = atype_string, \
156 .u.basic.string.encoding = lttng_encode_UTF8, \
160 #undef TP_STRUCT__entry
161 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
163 #undef DECLARE_EVENT_CLASS
164 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
165 static const struct lttng_event_field __event_fields___##_name[] = { \
169 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
171 #undef __type_integer
174 * Stage 3 of the trace events.
176 * Create probe callback prototypes.
179 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
182 #define TP_PROTO(args...) args
184 #undef DECLARE_EVENT_CLASS
185 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
186 static void __event_probe__##_name(void *__data, _proto);
188 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
191 * Stage 4 of the trace events.
193 * Create an array of events.
196 /* Named field types must be defined in lttng-types.h */
198 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
201 #define DEFINE_EVENT(_template, _name, _proto, _args) \
203 .fields = __event_fields___##_template, \
205 .probe_callback = (void *) &__event_probe__##_template,\
206 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
207 .owner = THIS_MODULE, \
210 #define TP_ID1(_token, _system) _token##_system
211 #define TP_ID(_token, _system) TP_ID1(_token, _system)
213 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
214 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
222 * Stage 5 of the trace events.
224 * Create a toplevel descriptor for the whole probe.
227 #define TP_ID1(_token, _system) _token##_system
228 #define TP_ID(_token, _system) TP_ID1(_token, _system)
230 /* non-const because list head will be modified when registered. */
231 static struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
232 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
233 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
240 * Stage 6 of the trace events.
242 * Create static inline function that calculates event size.
245 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
247 /* Named field types must be defined in lttng-types.h */
250 #define __field(_type, _item) \
251 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
252 __event_len += sizeof(_type);
255 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
258 #define __array(_type, _item, _length) \
259 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
260 __event_len += sizeof(_type) * (_length);
263 #define __array_text(_type, _item, _length) \
264 __array(_type, _item, _length)
266 #undef __dynamic_array
267 #define __dynamic_array(_type, _item, _length) \
268 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(u32)); \
269 __event_len += sizeof(u32); \
270 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
271 __dynamic_len[__dynamic_len_idx] = (_length); \
272 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
275 #undef __dynamic_array_text
276 #define __dynamic_array_text(_type, _item, _length) \
277 __dynamic_array(_type, _item, _length)
280 #define __string(_item, _src) \
281 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
284 #define TP_PROTO(args...) args
286 #undef TP_STRUCT__entry
287 #define TP_STRUCT__entry(args...) args
289 #undef DECLARE_EVENT_CLASS
290 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
291 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
293 size_t __event_len = 0; \
294 unsigned int __dynamic_len_idx = 0; \
297 (void) __dynamic_len_idx; /* don't warn if unused */ \
299 return __event_len; \
302 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
305 * Stage 7 of the trace events.
307 * Create static inline function that calculates event payload alignment.
310 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
312 /* Named field types must be defined in lttng-types.h */
315 #define __field(_type, _item) \
316 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
319 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
322 #define __array(_type, _item, _length) \
323 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
326 #define __array_text(_type, _item, _length) \
327 __array(_type, _item, _length)
329 #undef __dynamic_array
330 #define __dynamic_array(_type, _item, _length) \
331 __event_align = max_t(size_t, __event_align, ltt_alignof(u32)); \
332 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
334 #undef __dynamic_array_text
335 #define __dynamic_array_text(_type, _item, _length) \
336 __dynamic_array(_type, _item, _length)
339 #define __string(_item, _src)
342 #define TP_PROTO(args...) args
344 #undef TP_STRUCT__entry
345 #define TP_STRUCT__entry(args...) args
347 #undef DECLARE_EVENT_CLASS
348 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
349 static inline size_t __event_get_align__##_name(_proto) \
351 size_t __event_align = 1; \
353 return __event_align; \
356 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
360 * Stage 8 of the trace events.
362 * Create structure declaration that allows the "assign" macros to access the
366 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
368 /* Named field types must be defined in lttng-types.h */
371 #define __field(_type, _item) _type _item;
374 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
377 #define __array(_type, _item, _length) _type _item;
380 #define __array_text(_type, _item, _length) \
381 __array(_type, _item, _length)
383 #undef __dynamic_array
384 #define __dynamic_array(_type, _item, _length) _type _item;
386 #undef __dynamic_array_text
387 #define __dynamic_array_text(_type, _item, _length) \
388 __dynamic_array(_type, _item, _length)
391 #define __string(_item, _src) char _item;
393 #undef TP_STRUCT__entry
394 #define TP_STRUCT__entry(args...) args
396 #undef DECLARE_EVENT_CLASS
397 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
398 struct __event_typemap__##_name { \
402 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
406 * Stage 9 of the trace events.
408 * Create the probe function : call even size calculation and write event data
411 * We use both the field and assignment macros to write the fields in the order
412 * defined in the field declaration. The field declarations control the
413 * execution order, jumping to the appropriate assignment block.
416 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
419 #define __field(_type, _item) \
420 goto __assign_##_item; \
424 #define __field_ext(_type, _item, _filter_type) __field(_type, _item)
427 #define __array(_type, _item, _length) \
428 goto __assign_##_item; \
432 #define __array_text(_type, _item, _length) \
433 __array(_type, _item, _length)
435 #undef __dynamic_array
436 #define __dynamic_array(_type, _item, _length) \
437 goto __assign_##_item##_1; \
438 __end_field_##_item##_1: \
439 goto __assign_##_item##_2; \
440 __end_field_##_item##_2:
442 #undef __dynamic_array_text
443 #define __dynamic_array_text(_type, _item, _length) \
444 __dynamic_array(_type, _item, _length)
447 #define __string(_item, _src) \
448 goto __assign_##_item; \
452 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
456 #define tp_assign(dest, src) \
459 __typeof__(__typemap.dest) __tmp = (src); \
460 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(__tmp)); \
461 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
463 goto __end_field_##dest;
466 #define tp_memcpy(dest, src, len) \
469 (void) __typemap.dest; \
470 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(__typemap.dest)); \
471 __chan->ops->event_write(&ctx, src, len); \
472 goto __end_field_##dest;
475 #define tp_memcpy_dyn(dest, src) \
476 __assign_##dest##_1: \
478 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
479 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(u32)); \
480 __chan->ops->event_write(&ctx, &__tmpl, sizeof(u32)); \
482 goto __end_field_##dest##_1; \
483 __assign_##dest##_2: \
484 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(__typemap.dest)); \
485 __chan->ops->event_write(&ctx, src, \
486 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
487 goto __end_field_##dest##_2;
490 #define tp_strcpy(dest, src) \
491 tp_memcpy(dest, src, __get_dynamic_array_len(dest))
493 /* Named field types must be defined in lttng-types.h */
496 #define __get_str(field) field
498 #undef __get_dynamic_array
499 #define __get_dynamic_array(field) field
501 /* Beware: this get len actually consumes the len value */
502 #undef __get_dynamic_array_len
503 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
506 #define TP_PROTO(args...) args
509 #define TP_ARGS(args...) args
511 #undef TP_STRUCT__entry
512 #define TP_STRUCT__entry(args...) args
514 #undef TP_fast_assign
515 #define TP_fast_assign(args...) args
517 #undef DECLARE_EVENT_CLASS
518 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
519 static void __event_probe__##_name(void *__data, _proto) \
521 struct ltt_event *__event = __data; \
522 struct ltt_channel *__chan = __event->chan; \
523 struct lib_ring_buffer_ctx ctx; \
524 size_t __event_len, __event_align; \
525 size_t __dynamic_len_idx = 0; \
526 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
527 struct __event_typemap__##_name __typemap; \
531 (void) __dynamic_len_idx; /* don't warn if unused */ \
532 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
534 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
536 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
538 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
539 __event_align = __event_get_align__##_name(_args); \
540 lib_ring_buffer_ctx_init(&ctx, __chan->chan, __event, __event_len, \
541 __event_align, -1); \
542 __ret = __chan->ops->event_reserve(&ctx, __event->id); \
545 /* Control code (field ordering) */ \
547 __chan->ops->event_commit(&ctx); \
549 /* Copy code, steered by control code */ \
553 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
556 * Stage 10 of the trace events.
558 * Register/unregister probes at module load/unload.
561 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
563 #define TP_ID1(_token, _system) _token##_system
564 #define TP_ID(_token, _system) TP_ID1(_token, _system)
565 #define module_init_eval1(_token, _system) module_init(_token##_system)
566 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
567 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
568 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
570 static int TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
572 wrapper_vmalloc_sync_all();
573 return ltt_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
576 module_init_eval(__lttng_events_init__
, TRACE_SYSTEM
);
578 static void TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
580 ltt_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
583 module_exit_eval(__lttng_events_exit__
, TRACE_SYSTEM
);
585 #undef module_init_eval
586 #undef module_exit_eval
This page took 0.046507 seconds and 4 git commands to generate.