2 * Copyright (C) 2009 Steven Rostedt <srostedt@redhat.com>
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation;
8 * version 2.1 of the License.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <urcu/compiler.h>
22 #include <ust/lttng-events.h>
23 #include <ust/usterr-signal-safe.h>
24 #include <ust/ringbuffer-config.h>
27 * Macro declarations used for all stages.
31 #define ctf_integer(_type, _item, _src) \
32 ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10)
34 #undef ctf_integer_hex
35 #define ctf_integer_hex(_type, _item, _src) \
36 ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 16)
38 #undef ctf_integer_network
39 #define ctf_integer_network(_type, _item, _src) \
40 ctf_integer_ext(_type, _item, _src, BIG_ENDIAN, 10)
42 #undef ctf_integer_network_hex
43 #define ctf_integer_network_hex(_type, _item, _src) \
44 ctf_integer_ext(_type, _item, _src, BIG_ENDIAN, 16)
47 #define ctf_array(_type, _item, _src, _length) \
48 ctf_array_encoded(_type, _item, _src, _length, none)
51 #define ctf_array_text(_type, _item, _src, _length) \
52 ctf_array_encoded(_type, _item, _src, _length, UTF8)
55 #define ctf_sequence(_type, _item, _src, _length_type, _src_length) \
56 ctf_sequence_encoded(_type, _item, _src, \
57 _length_type, _src_length, none)
59 #undef ctf_sequence_text
60 #define ctf_sequence_text(_type, _item, _src, _length_type, _src_length) \
61 ctf_sequence_encoded(_type, _item, _src, \
62 _length_type, _src_length, UTF8)
64 /* ctf_string is redefined at each step */
67 * TRACEPOINT_EVENT_CLASS can be used to add a generic function handlers
68 * for events. That is, if all events have the same parameters and just
69 * have distinct trace points. Each tracepoint can be defined with
70 * TRACEPOINT_EVENT_INSTANCE and that will map the
71 * TRACEPOINT_EVENT_CLASS to the tracepoint.
73 * TRACEPOINT_EVENT is a one to one mapping between tracepoint and
77 #undef TRACEPOINT_EVENT
78 #define TRACEPOINT_EVENT(name, proto, args, fields) \
79 TRACEPOINT_EVENT_CLASS(name, \
83 TRACEPOINT_EVENT_INSTANCE(name, name, TP_PARAMS(proto), TP_PARAMS(args))
85 #undef TRACEPOINT_EVENT_NOARGS
86 #define TRACEPOINT_EVENT_NOARGS(name, fields) \
87 TRACEPOINT_EVENT_CLASS_NOARGS(name, \
89 TRACEPOINT_EVENT_INSTANCE_NOARGS(name, name)
92 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
94 #define _tp_max_t(type, x, y) \
98 __max1 > __max2 ? __max1: __max2; \
103 * Stage 1 of the trace events.
105 * Create event field type metadata section.
106 * Each event produce an array of fields.
109 /* Reset all macros within TRACEPOINT_EVENT */
110 #include <ust/lttng-tracepoint-event-reset.h>
112 /* Named field types must be defined in lttng-types.h */
114 #undef ctf_integer_ext
115 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
118 .type = __type_integer(_type, _byte_order, _base, none),\
122 #define ctf_float(_type, _item, _src) \
125 .type = __type_float(_type), \
128 #undef ctf_array_encoded
129 #define ctf_array_encoded(_type, _item, _src, _length, _encoding) \
134 .atype = atype_array, \
138 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
143 #undef ctf_sequence_encoded
144 #define ctf_sequence_encoded(_type, _item, _src, \
145 _length_type, _src_length, _encoding) \
150 .atype = atype_sequence, \
153 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
154 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
160 #define ctf_string(_item, _src) \
165 .atype = atype_string, \
166 .u.basic.string.encoding = lttng_encode_UTF8, \
171 #define TP_FIELDS(args...) args /* Only one used in this phase */
173 #undef TRACEPOINT_EVENT_CLASS_NOARGS
174 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
175 static const struct lttng_event_field __event_fields___##_name[] = { \
179 #undef TRACEPOINT_EVENT_CLASS
180 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
181 TRACEPOINT_EVENT_CLASS_NOARGS(_name, TP_PARAMS(_fields))
183 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
186 * Stage 2 of the trace events.
188 * Create probe callback prototypes.
191 /* Reset all macros within TRACEPOINT_EVENT */
192 #include <ust/lttng-tracepoint-event-reset.h>
195 #define TP_PROTO(args...) args
197 #undef TRACEPOINT_EVENT_CLASS
198 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
199 static void __event_probe__##_name(void *__data, _proto);
201 #undef TRACEPOINT_EVENT_CLASS_NOARGS
202 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
203 static void __event_probe__##_name(void *__data);
205 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
208 * Stage 3 of the trace events.
210 * Create an array of events.
213 /* Named field types must be defined in lttng-types.h */
215 /* Reset all macros within TRACEPOINT_EVENT */
216 #include <ust/lttng-tracepoint-event-reset.h>
218 #undef TRACEPOINT_EVENT_INSTANCE_NOARGS
219 #define TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
221 .fields = __event_fields___##_template, \
223 .probe_callback = (void *) &__event_probe__##_template,\
224 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_template), \
227 #undef TRACEPOINT_EVENT_INSTANCE
228 #define TRACEPOINT_EVENT_INSTANCE(_template, _name, _proto, _args) \
229 TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name)
231 #define TP_ID1(_token, _system) _token##_system
232 #define TP_ID(_token, _system) TP_ID1(_token, _system)
234 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACEPOINT_SYSTEM
)[] = {
235 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
243 * Stage 4 of the trace events.
245 * Create a toplevel descriptor for the whole probe.
248 #define TP_ID1(_token, _system) _token##_system
249 #define TP_ID(_token, _system) TP_ID1(_token, _system)
251 /* non-const because list head will be modified when registered. */
252 static struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACEPOINT_SYSTEM
) = {
253 .event_desc
= TP_ID(__event_desc___
, TRACEPOINT_SYSTEM
),
254 .nr_events
= _TP_ARRAY_SIZE(TP_ID(__event_desc___
, TRACEPOINT_SYSTEM
)),
261 * Stage 5 of the trace events.
263 * Create static inline function that calculates event size.
266 /* Reset all macros within TRACEPOINT_EVENT */
267 #include <ust/lttng-tracepoint-event-reset.h>
269 /* Named field types must be defined in lttng-types.h */
271 #undef ctf_integer_ext
272 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
273 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
274 __event_len += sizeof(_type);
277 #define ctf_float(_type, _item, _src) \
278 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
279 __event_len += sizeof(_type);
281 #undef ctf_array_encoded
282 #define ctf_array_encoded(_type, _item, _src, _length, _encoding) \
283 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
284 __event_len += sizeof(_type) * (_length);
286 #undef ctf_sequence_encoded
287 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
288 _src_length, _encoding) \
289 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
290 __event_len += sizeof(_length_type); \
291 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
292 __dynamic_len[__dynamic_len_idx] = (_length); \
293 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
297 #define ctf_string(_item, _src) \
298 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
301 #define TP_PROTO(args...) args
304 #define TP_FIELDS(args...) args
306 #undef TRACEPOINT_EVENT_CLASS
307 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
308 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
310 size_t __event_len = 0; \
311 unsigned int __dynamic_len_idx = 0; \
314 (void) __dynamic_len_idx; /* don't warn if unused */ \
316 return __event_len; \
319 #undef TRACEPOINT_EVENT_CLASS_NOARGS
320 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
321 static inline size_t __event_get_size__##_name(size_t *__dynamic_len) \
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 TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
335 * Stage 6 of the trace events.
337 * Create static inline function that calculates event payload alignment.
340 /* Reset all macros within TRACEPOINT_EVENT */
341 #include <ust/lttng-tracepoint-event-reset.h>
343 /* Named field types must be defined in lttng-types.h */
345 #undef ctf_integer_ext
346 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
347 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
350 #define ctf_float(_type, _item, _src) \
351 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
353 #undef ctf_array_encoded
354 #define ctf_array_encoded(_type, _item, _src, _length, _encoding) \
355 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
357 #undef ctf_sequence_encoded
358 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
359 _src_length, _encoding) \
360 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
361 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
364 #define ctf_string(_item, _src)
367 #define TP_PROTO(args...) args
370 #define TP_FIELDS(args...) args
372 #undef TRACEPOINT_EVENT_CLASS
373 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
374 static inline size_t __event_get_align__##_name(_proto) \
376 size_t __event_align = 1; \
378 return __event_align; \
381 #undef TRACEPOINT_EVENT_CLASS_NOARGS
382 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
383 static inline size_t __event_get_align__##_name(void) \
385 size_t __event_align = 1; \
387 return __event_align; \
390 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
394 * Stage 7 of the trace events.
396 * Create the probe function : call even size calculation and write event data
399 * We use both the field and assignment macros to write the fields in the order
400 * defined in the field declaration. The field declarations control the
401 * execution order, jumping to the appropriate assignment block.
404 /* Reset all macros within TRACEPOINT_EVENT */
405 #include <ust/lttng-tracepoint-event-reset.h>
407 #undef ctf_integer_ext
408 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
410 _type __tmp = (_src); \
411 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(__tmp)); \
412 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
416 #define ctf_float(_type, _item, _src) \
418 _type __tmp = (_src); \
419 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(__tmp)); \
420 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
423 #undef ctf_array_encoded
424 #define ctf_array_encoded(_type, _item, _src, _length, _encoding) \
425 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(_type)); \
426 __chan->ops->event_write(&ctx, _src, _length);
428 #undef ctf_sequence_encoded
429 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
430 _src_length, _encoding) \
432 _length_type __tmpl = __dynamic_len[__dynamic_len_idx]; \
433 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(_length_type)); \
434 __chan->ops->event_write(&ctx, &__tmpl, sizeof(_length_type)); \
436 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(_type)); \
437 __chan->ops->event_write(&ctx, _src, \
438 sizeof(_type) * __get_sequence_len(dest));
441 #define ctf_string(_item, _src) \
442 tp_memcpy(dest, _src, __get_sequence_len(dest))
444 /* Beware: this get len actually consumes the len value */
445 #undef __get_sequence_len
446 #define __get_sequence_len(field) __dynamic_len[__dynamic_len_idx++]
449 #define TP_PROTO(args...) args
452 #define TP_ARGS(args...) args
455 #define TP_FIELDS(args...) args
457 #undef TRACEPOINT_EVENT_CLASS
458 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
459 static void __event_probe__##_name(void *__data, _proto) \
461 struct ltt_event *__event = __data; \
462 struct ltt_channel *__chan = __event->chan; \
463 struct lib_ring_buffer_ctx ctx; \
464 size_t __event_len, __event_align; \
465 size_t __dynamic_len_idx = 0; \
466 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_name)]; \
470 (void) __dynamic_len_idx; /* don't warn if unused */ \
471 if (unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
473 if (unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
475 if (unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
477 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
478 __event_align = __event_get_align__##_name(_args); \
479 lib_ring_buffer_ctx_init(&ctx, __chan->chan, __event, __event_len, \
480 __event_align, -1); \
481 __ret = __chan->ops->event_reserve(&ctx, __event->id); \
485 __chan->ops->event_commit(&ctx); \
488 #undef TRACEPOINT_EVENT_CLASS_NOARGS
489 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
490 static void __event_probe__##_name(void *__data) \
492 struct ltt_event *__event = __data; \
493 struct ltt_channel *__chan = __event->chan; \
494 struct lib_ring_buffer_ctx ctx; \
495 size_t __event_len, __event_align; \
496 size_t __dynamic_len_idx = 0; \
497 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_name)]; \
501 (void) __dynamic_len_idx; /* don't warn if unused */ \
502 if (unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
504 if (unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
506 if (unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
508 __event_len = __event_get_size__##_name(__dynamic_len); \
509 __event_align = __event_get_align__##_name(); \
510 lib_ring_buffer_ctx_init(&ctx, __chan->chan, __event, __event_len, \
511 __event_align, -1); \
512 __ret = __chan->ops->event_reserve(&ctx, __event->id); \
516 __chan->ops->event_commit(&ctx); \
519 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
522 * Stage 8 of the trace events.
524 * Register/unregister probes at module load/unload.
527 /* Reset all macros within TRACEPOINT_EVENT */
528 #include <ust/lttng-tracepoint-event-reset.h>
530 #define TP_ID1(_token, _system) _token##_system
531 #define TP_ID(_token, _system) TP_ID1(_token, _system)
533 static void __attribute__((constructor
))
534 TP_ID(__lttng_events_init__
, TRACEPOINT_SYSTEM
)(void)
538 ret
= ltt_probe_register(&TP_ID(__probe_desc___
, TRACEPOINT_SYSTEM
));
542 static void __attribute__((destructor
))
543 TP_ID(__lttng_events_exit__
, TRACEPOINT_SYSTEM
)(void)
545 ltt_probe_unregister(&TP_ID(__probe_desc___
, TRACEPOINT_SYSTEM
));
This page took 0.04138 seconds and 6 git commands to generate.