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 <lttng/ust-events.h>
23 #include <lttng/usterr-signal-safe.h>
24 #include <lttng/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 <lttng/ust-tracepoint-event-reset.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 <lttng/ust-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 /* Reset all macros within TRACEPOINT_EVENT */
214 #include <lttng/ust-tracepoint-event-reset.h>
216 #undef TRACEPOINT_EVENT_INSTANCE_NOARGS
217 #define TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
219 .fields = __event_fields___##_template, \
221 .probe_callback = (void *) &__event_probe__##_template,\
222 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_template), \
225 #undef TRACEPOINT_EVENT_INSTANCE
226 #define TRACEPOINT_EVENT_INSTANCE(_template, _name, _proto, _args) \
227 TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name)
229 #define TP_ID1(_token, _system) _token##_system
230 #define TP_ID(_token, _system) TP_ID1(_token, _system)
232 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACEPOINT_SYSTEM
)[] = {
233 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
241 * Stage 4 of the trace events.
243 * Create a toplevel descriptor for the whole probe.
246 #define TP_ID1(_token, _system) _token##_system
247 #define TP_ID(_token, _system) TP_ID1(_token, _system)
249 /* non-const because list head will be modified when registered. */
250 static struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACEPOINT_SYSTEM
) = {
251 .event_desc
= TP_ID(__event_desc___
, TRACEPOINT_SYSTEM
),
252 .nr_events
= _TP_ARRAY_SIZE(TP_ID(__event_desc___
, TRACEPOINT_SYSTEM
)),
259 * Stage 5 of the trace events.
261 * Create static inline function that calculates event size.
264 /* Reset all macros within TRACEPOINT_EVENT */
265 #include <lttng/ust-tracepoint-event-reset.h>
267 #undef ctf_integer_ext
268 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
269 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
270 __event_len += sizeof(_type);
273 #define ctf_float(_type, _item, _src) \
274 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
275 __event_len += sizeof(_type);
277 #undef ctf_array_encoded
278 #define ctf_array_encoded(_type, _item, _src, _length, _encoding) \
279 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
280 __event_len += sizeof(_type) * (_length);
282 #undef ctf_sequence_encoded
283 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
284 _src_length, _encoding) \
285 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
286 __event_len += sizeof(_length_type); \
287 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
288 __dynamic_len[__dynamic_len_idx] = (_src_length); \
289 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
293 #define ctf_string(_item, _src) \
294 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
297 #define TP_PROTO(args...) args
300 #define TP_FIELDS(args...) args
302 #undef TRACEPOINT_EVENT_CLASS
303 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
304 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
306 size_t __event_len = 0; \
307 unsigned int __dynamic_len_idx = 0; \
310 (void) __dynamic_len_idx; /* don't warn if unused */ \
312 return __event_len; \
315 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
318 * Stage 6 of the trace events.
320 * Create static inline function that calculates event payload alignment.
323 /* Reset all macros within TRACEPOINT_EVENT */
324 #include <lttng/ust-tracepoint-event-reset.h>
326 #undef ctf_integer_ext
327 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
328 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
331 #define ctf_float(_type, _item, _src) \
332 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
334 #undef ctf_array_encoded
335 #define ctf_array_encoded(_type, _item, _src, _length, _encoding) \
336 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
338 #undef ctf_sequence_encoded
339 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
340 _src_length, _encoding) \
341 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
342 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
345 #define ctf_string(_item, _src)
348 #define TP_PROTO(args...) args
351 #define TP_FIELDS(args...) args
353 #undef TRACEPOINT_EVENT_CLASS
354 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
355 static inline size_t __event_get_align__##_name(_proto) \
357 size_t __event_align = 1; \
359 return __event_align; \
362 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
366 * Stage 7 of the trace events.
368 * Create the probe function : call even size calculation and write event data
371 * We use both the field and assignment macros to write the fields in the order
372 * defined in the field declaration. The field declarations control the
373 * execution order, jumping to the appropriate assignment block.
376 /* Reset all macros within TRACEPOINT_EVENT */
377 #include <lttng/ust-tracepoint-event-reset.h>
379 #undef ctf_integer_ext
380 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
382 _type __tmp = (_src); \
383 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
384 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
388 #define ctf_float(_type, _item, _src) \
390 _type __tmp = (_src); \
391 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
392 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
395 #undef ctf_array_encoded
396 #define ctf_array_encoded(_type, _item, _src, _length, _encoding) \
397 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
398 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
400 #undef ctf_sequence_encoded
401 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
402 _src_length, _encoding) \
404 _length_type __tmpl = __dynamic_len[__dynamic_len_idx]; \
405 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
406 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
408 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
409 __chan->ops->event_write(&__ctx, _src, \
410 sizeof(_type) * __get_dynamic_len(dest));
413 #define ctf_string(_item, _src) \
414 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
415 __chan->ops->event_write(&__ctx, _src, __get_dynamic_len(dest));
417 /* Beware: this get len actually consumes the len value */
418 #undef __get_dynamic_len
419 #define __get_dynamic_len(field) __dynamic_len[__dynamic_len_idx++]
422 #define TP_PROTO(args...) args
425 #define TP_ARGS(args...) args
428 #define TP_FIELDS(args...) args
430 #undef TRACEPOINT_EVENT_CLASS
431 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
432 static void __event_probe__##_name(void *__data, _proto) \
434 struct ltt_event *__event = __data; \
435 struct ltt_channel *__chan = __event->chan; \
436 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
437 size_t __event_len, __event_align; \
438 size_t __dynamic_len_idx = 0; \
439 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_name)]; \
443 (void) __dynamic_len_idx; /* don't warn if unused */ \
444 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
446 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
448 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
450 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
451 __event_align = __event_get_align__##_name(_args); \
452 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
453 __event_align, -1, __chan->handle); \
454 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
458 __chan->ops->event_commit(&__ctx); \
461 #undef TRACEPOINT_EVENT_CLASS_NOARGS
462 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
463 static void __event_probe__##_name(void *__data) \
465 struct ltt_event *__event = __data; \
466 struct ltt_channel *__chan = __event->chan; \
467 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
468 size_t __event_len, __event_align; \
471 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
473 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
475 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
479 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
480 __event_align, -1, __chan->handle); \
481 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
485 __chan->ops->event_commit(&__ctx); \
488 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
490 #undef __get_dynamic_len
493 * Stage 8 of the trace events.
495 * Register/unregister probes at module load/unload.
498 /* Reset all macros within TRACEPOINT_EVENT */
499 #include <lttng/ust-tracepoint-event-reset.h>
501 #define TP_ID1(_token, _system) _token##_system
502 #define TP_ID(_token, _system) TP_ID1(_token, _system)
504 static void __attribute__((constructor
))
505 TP_ID(__lttng_events_init__
, TRACEPOINT_SYSTEM
)(void)
509 ret
= ltt_probe_register(&TP_ID(__probe_desc___
, TRACEPOINT_SYSTEM
));
513 static void __attribute__((destructor
))
514 TP_ID(__lttng_events_exit__
, TRACEPOINT_SYSTEM
)(void)
516 ltt_probe_unregister(&TP_ID(__probe_desc___
, TRACEPOINT_SYSTEM
));
This page took 0.05867 seconds and 5 git commands to generate.