de145ebe5b2d2a270a60f24371a7e31fb2813652
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)
46 /* ctf_float is redefined at each step */
49 #define ctf_array(_type, _item, _src, _length) \
50 ctf_array_encoded(_type, _item, _src, _length, none)
53 #define ctf_array_text(_type, _item, _src, _length) \
54 ctf_array_encoded(_type, _item, _src, _length, UTF8)
57 #define ctf_sequence(_type, _item, _src, _length_type, _src_length) \
58 ctf_sequence_encoded(_type, _item, _src, \
59 _length_type, _src_length, none)
61 #undef ctf_sequence_text
62 #define ctf_sequence_text(_type, _item, _src, _length_type, _src_length) \
63 ctf_sequence_encoded(_type, _item, _src, \
64 _length_type, _src_length, UTF8)
66 /* ctf_string is redefined at each step */
69 * TRACEPOINT_EVENT_CLASS can be used to add a generic function handlers
70 * for events. That is, if all events have the same parameters and just
71 * have distinct trace points. Each tracepoint can be defined with
72 * TRACEPOINT_EVENT_INSTANCE and that will map the
73 * TRACEPOINT_EVENT_CLASS to the tracepoint.
75 * TRACEPOINT_EVENT is a one to one mapping between tracepoint and
79 #undef TRACEPOINT_EVENT
80 #define TRACEPOINT_EVENT(name, proto, args, fields) \
81 TRACEPOINT_EVENT_CLASS(name, \
85 TRACEPOINT_EVENT_INSTANCE(name, name, TP_PARAMS(proto), TP_PARAMS(args))
87 #undef TRACEPOINT_EVENT_NOARGS
88 #define TRACEPOINT_EVENT_NOARGS(name, fields) \
89 TRACEPOINT_EVENT_CLASS_NOARGS(name, \
91 TRACEPOINT_EVENT_INSTANCE_NOARGS(name, name)
94 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
96 #define _tp_max_t(type, x, y) \
100 __max1 > __max2 ? __max1: __max2; \
105 * Stage 1 of the trace events.
107 * Create event field type metadata section.
108 * Each event produce an array of fields.
111 /* Reset all macros within TRACEPOINT_EVENT */
112 #include <ust/lttng-tracepoint-event-reset.h>
114 /* Named field types must be defined in lttng-types.h */
116 #undef ctf_integer_ext
117 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
120 .type = __type_integer(_type, _byte_order, _base, none),\
124 #define ctf_float(_type, _item, _src) \
127 .type = __type_float(_type), \
130 #undef ctf_array_encoded
131 #define ctf_array_encoded(_type, _item, _src, _length, _encoding) \
136 .atype = atype_array, \
140 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
145 #undef ctf_sequence_encoded
146 #define ctf_sequence_encoded(_type, _item, _src, \
147 _length_type, _src_length, _encoding) \
152 .atype = atype_sequence, \
155 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
156 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
162 #define ctf_string(_item, _src) \
167 .atype = atype_string, \
168 .u.basic.string.encoding = lttng_encode_UTF8, \
173 #define TP_FIELDS(args...) args /* Only one used in this phase */
175 #undef TRACEPOINT_EVENT_CLASS_NOARGS
176 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
177 static const struct lttng_event_field __event_fields___##_name[] = { \
181 #undef TRACEPOINT_EVENT_CLASS
182 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
183 TRACEPOINT_EVENT_CLASS_NOARGS(_name, TP_PARAMS(_fields))
185 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
188 * Stage 2 of the trace events.
190 * Create probe callback prototypes.
193 /* Reset all macros within TRACEPOINT_EVENT */
194 #include <ust/lttng-tracepoint-event-reset.h>
197 #define TP_PROTO(args...) args
199 #undef TRACEPOINT_EVENT_CLASS
200 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
201 static void __event_probe__##_name(void *__data, _proto);
203 #undef TRACEPOINT_EVENT_CLASS_NOARGS
204 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
205 static void __event_probe__##_name(void *__data);
207 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
210 * Stage 3 of the trace events.
212 * Create an array of events.
215 /* Named field types must be defined in lttng-types.h */
217 /* Reset all macros within TRACEPOINT_EVENT */
218 #include <ust/lttng-tracepoint-event-reset.h>
220 #undef TRACEPOINT_EVENT_INSTANCE_NOARGS
221 #define TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
223 .fields = __event_fields___##_template, \
225 .probe_callback = (void *) &__event_probe__##_template,\
226 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_template), \
229 #undef TRACEPOINT_EVENT_INSTANCE
230 #define TRACEPOINT_EVENT_INSTANCE(_template, _name, _proto, _args) \
231 TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name)
233 #define TP_ID1(_token, _system) _token##_system
234 #define TP_ID(_token, _system) TP_ID1(_token, _system)
236 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACEPOINT_SYSTEM
)[] = {
237 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
245 * Stage 4 of the trace events.
247 * Create a toplevel descriptor for the whole probe.
250 #define TP_ID1(_token, _system) _token##_system
251 #define TP_ID(_token, _system) TP_ID1(_token, _system)
253 /* non-const because list head will be modified when registered. */
254 static struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACEPOINT_SYSTEM
) = {
255 .event_desc
= TP_ID(__event_desc___
, TRACEPOINT_SYSTEM
),
256 .nr_events
= _TP_ARRAY_SIZE(TP_ID(__event_desc___
, TRACEPOINT_SYSTEM
)),
263 * Stage 5 of the trace events.
265 * Create static inline function that calculates event size.
268 /* Reset all macros within TRACEPOINT_EVENT */
269 #include <ust/lttng-tracepoint-event-reset.h>
271 /* Named field types must be defined in lttng-types.h */
273 #undef ctf_integer_ext
274 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
275 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
276 __event_len += sizeof(_type);
279 #define ctf_float(_type, _item, _src) \
280 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
281 __event_len += sizeof(_type);
283 #undef ctf_array_encoded
284 #define ctf_array_encoded(_type, _item, _src, _length, _encoding) \
285 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
286 __event_len += sizeof(_type) * (_length);
288 #undef ctf_sequence_encoded
289 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
290 _src_length, _encoding) \
291 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
292 __event_len += sizeof(_length_type); \
293 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
294 __dynamic_len[__dynamic_len_idx] = (_src_length); \
295 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
299 #define ctf_string(_item, _src) \
300 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
303 #define TP_PROTO(args...) args
306 #define TP_FIELDS(args...) args
308 #undef TRACEPOINT_EVENT_CLASS
309 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
310 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
312 size_t __event_len = 0; \
313 unsigned int __dynamic_len_idx = 0; \
316 (void) __dynamic_len_idx; /* don't warn if unused */ \
318 return __event_len; \
321 #undef TRACEPOINT_EVENT_CLASS_NOARGS
322 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
323 static inline size_t __event_get_size__##_name(size_t *__dynamic_len) \
325 size_t __event_len = 0; \
326 unsigned int __dynamic_len_idx = 0; \
329 (void) __dynamic_len_idx; /* don't warn if unused */ \
331 return __event_len; \
334 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
337 * Stage 6 of the trace events.
339 * Create static inline function that calculates event payload alignment.
342 /* Reset all macros within TRACEPOINT_EVENT */
343 #include <ust/lttng-tracepoint-event-reset.h>
345 /* Named field types must be defined in lttng-types.h */
347 #undef ctf_integer_ext
348 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
349 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
352 #define ctf_float(_type, _item, _src) \
353 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
355 #undef ctf_array_encoded
356 #define ctf_array_encoded(_type, _item, _src, _length, _encoding) \
357 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
359 #undef ctf_sequence_encoded
360 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
361 _src_length, _encoding) \
362 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
363 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
366 #define ctf_string(_item, _src)
369 #define TP_PROTO(args...) args
372 #define TP_FIELDS(args...) args
374 #undef TRACEPOINT_EVENT_CLASS
375 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
376 static inline size_t __event_get_align__##_name(_proto) \
378 size_t __event_align = 1; \
380 return __event_align; \
383 #undef TRACEPOINT_EVENT_CLASS_NOARGS
384 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
385 static inline size_t __event_get_align__##_name(void) \
387 size_t __event_align = 1; \
389 return __event_align; \
392 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
396 * Stage 7 of the trace events.
398 * Create the probe function : call even size calculation and write event data
401 * We use both the field and assignment macros to write the fields in the order
402 * defined in the field declaration. The field declarations control the
403 * execution order, jumping to the appropriate assignment block.
406 /* Reset all macros within TRACEPOINT_EVENT */
407 #include <ust/lttng-tracepoint-event-reset.h>
409 #undef ctf_integer_ext
410 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
412 _type __tmp = (_src); \
413 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(__tmp)); \
414 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
418 #define ctf_float(_type, _item, _src) \
420 _type __tmp = (_src); \
421 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(__tmp)); \
422 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
425 #undef ctf_array_encoded
426 #define ctf_array_encoded(_type, _item, _src, _length, _encoding) \
427 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(_type)); \
428 __chan->ops->event_write(&ctx, _src, _length);
430 #undef ctf_sequence_encoded
431 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
432 _src_length, _encoding) \
434 _length_type __tmpl = __dynamic_len[__dynamic_len_idx]; \
435 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(_length_type)); \
436 __chan->ops->event_write(&ctx, &__tmpl, sizeof(_length_type)); \
438 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(_type)); \
439 __chan->ops->event_write(&ctx, _src, \
440 sizeof(_type) * __get_dynamic_len(dest));
443 #define ctf_string(_item, _src) \
444 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(*(_src))); \
445 __chan->ops->event_write(&ctx, _src, __get_dynamic_len(dest));
447 /* Beware: this get len actually consumes the len value */
448 #undef __get_dynamic_len
449 #define __get_dynamic_len(field) __dynamic_len[__dynamic_len_idx++]
452 #define TP_PROTO(args...) args
455 #define TP_ARGS(args...) args
458 #define TP_FIELDS(args...) args
460 #undef TRACEPOINT_EVENT_CLASS
461 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
462 static void __event_probe__##_name(void *__data, _proto) \
464 struct ltt_event *__event = __data; \
465 struct ltt_channel *__chan = __event->chan; \
466 struct lib_ring_buffer_ctx ctx; \
467 size_t __event_len, __event_align; \
468 size_t __dynamic_len_idx = 0; \
469 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_name)]; \
473 (void) __dynamic_len_idx; /* don't warn if unused */ \
474 if (unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
476 if (unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
478 if (unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
480 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
481 __event_align = __event_get_align__##_name(_args); \
482 lib_ring_buffer_ctx_init(&ctx, __chan->chan, __event, __event_len, \
483 __event_align, -1); \
484 __ret = __chan->ops->event_reserve(&ctx, __event->id); \
488 __chan->ops->event_commit(&ctx); \
491 #undef TRACEPOINT_EVENT_CLASS_NOARGS
492 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
493 static void __event_probe__##_name(void *__data) \
495 struct ltt_event *__event = __data; \
496 struct ltt_channel *__chan = __event->chan; \
497 struct lib_ring_buffer_ctx ctx; \
498 size_t __event_len, __event_align; \
499 size_t __dynamic_len_idx = 0; \
500 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_name)]; \
504 (void) __dynamic_len_idx; /* don't warn if unused */ \
505 if (unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
507 if (unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
509 if (unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
511 __event_len = __event_get_size__##_name(__dynamic_len); \
512 __event_align = __event_get_align__##_name(); \
513 lib_ring_buffer_ctx_init(&ctx, __chan->chan, __event, __event_len, \
514 __event_align, -1); \
515 __ret = __chan->ops->event_reserve(&ctx, __event->id); \
519 __chan->ops->event_commit(&ctx); \
522 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
524 #undef __get_dynamic_len
527 * Stage 8 of the trace events.
529 * Register/unregister probes at module load/unload.
532 /* Reset all macros within TRACEPOINT_EVENT */
533 #include <ust/lttng-tracepoint-event-reset.h>
535 #define TP_ID1(_token, _system) _token##_system
536 #define TP_ID(_token, _system) TP_ID1(_token, _system)
538 static void __attribute__((constructor
))
539 TP_ID(__lttng_events_init__
, TRACEPOINT_SYSTEM
)(void)
543 ret
= ltt_probe_register(&TP_ID(__probe_desc___
, TRACEPOINT_SYSTEM
));
547 static void __attribute__((destructor
))
548 TP_ID(__lttng_events_exit__
, TRACEPOINT_SYSTEM
)(void)
550 ltt_probe_unregister(&TP_ID(__probe_desc___
, TRACEPOINT_SYSTEM
));
This page took 0.058299 seconds and 4 git commands to generate.