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 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
324 * Stage 6 of the trace events.
326 * Create static inline function that calculates event payload alignment.
329 /* Reset all macros within TRACEPOINT_EVENT */
330 #include <ust/lttng-tracepoint-event-reset.h>
332 /* Named field types must be defined in lttng-types.h */
334 #undef ctf_integer_ext
335 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
336 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
339 #define ctf_float(_type, _item, _src) \
340 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
342 #undef ctf_array_encoded
343 #define ctf_array_encoded(_type, _item, _src, _length, _encoding) \
344 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
346 #undef ctf_sequence_encoded
347 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
348 _src_length, _encoding) \
349 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
350 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
353 #define ctf_string(_item, _src)
356 #define TP_PROTO(args...) args
359 #define TP_FIELDS(args...) args
361 #undef TRACEPOINT_EVENT_CLASS
362 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
363 static inline size_t __event_get_align__##_name(_proto) \
365 size_t __event_align = 1; \
367 return __event_align; \
370 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
374 * Stage 7 of the trace events.
376 * Create the probe function : call even size calculation and write event data
379 * We use both the field and assignment macros to write the fields in the order
380 * defined in the field declaration. The field declarations control the
381 * execution order, jumping to the appropriate assignment block.
384 /* Reset all macros within TRACEPOINT_EVENT */
385 #include <ust/lttng-tracepoint-event-reset.h>
387 #undef ctf_integer_ext
388 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
390 _type __tmp = (_src); \
391 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(__tmp)); \
392 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
396 #define ctf_float(_type, _item, _src) \
398 _type __tmp = (_src); \
399 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(__tmp)); \
400 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
403 #undef ctf_array_encoded
404 #define ctf_array_encoded(_type, _item, _src, _length, _encoding) \
405 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(_type)); \
406 __chan->ops->event_write(&ctx, _src, _length);
408 #undef ctf_sequence_encoded
409 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
410 _src_length, _encoding) \
412 _length_type __tmpl = __dynamic_len[__dynamic_len_idx]; \
413 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(_length_type)); \
414 __chan->ops->event_write(&ctx, &__tmpl, sizeof(_length_type)); \
416 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(_type)); \
417 __chan->ops->event_write(&ctx, _src, \
418 sizeof(_type) * __get_dynamic_len(dest));
421 #define ctf_string(_item, _src) \
422 lib_ring_buffer_align_ctx(&ctx, lttng_alignof(*(_src))); \
423 __chan->ops->event_write(&ctx, _src, __get_dynamic_len(dest));
425 /* Beware: this get len actually consumes the len value */
426 #undef __get_dynamic_len
427 #define __get_dynamic_len(field) __dynamic_len[__dynamic_len_idx++]
430 #define TP_PROTO(args...) args
433 #define TP_ARGS(args...) args
436 #define TP_FIELDS(args...) args
438 #undef TRACEPOINT_EVENT_CLASS
439 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
440 static void __event_probe__##_name(void *__data, _proto) \
442 struct ltt_event *__event = __data; \
443 struct ltt_channel *__chan = __event->chan; \
444 struct lib_ring_buffer_ctx ctx; \
445 size_t __event_len, __event_align; \
446 size_t __dynamic_len_idx = 0; \
447 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_name)]; \
451 (void) __dynamic_len_idx; /* don't warn if unused */ \
452 if (unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
454 if (unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
456 if (unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
458 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
459 __event_align = __event_get_align__##_name(_args); \
460 lib_ring_buffer_ctx_init(&ctx, __chan->chan, __event, __event_len, \
461 __event_align, -1, __chan->handle); \
462 __ret = __chan->ops->event_reserve(&ctx, __event->id); \
466 __chan->ops->event_commit(&ctx); \
469 #undef TRACEPOINT_EVENT_CLASS_NOARGS
470 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
471 static void __event_probe__##_name(void *__data) \
473 struct ltt_event *__event = __data; \
474 struct ltt_channel *__chan = __event->chan; \
475 struct lib_ring_buffer_ctx ctx; \
476 size_t __event_len, __event_align; \
479 if (unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
481 if (unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
483 if (unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
487 lib_ring_buffer_ctx_init(&ctx, __chan->chan, __event, __event_len, \
488 __event_align, -1, __chan->handle); \
489 __ret = __chan->ops->event_reserve(&ctx, __event->id); \
493 __chan->ops->event_commit(&ctx); \
496 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
498 #undef __get_dynamic_len
501 * Stage 8 of the trace events.
503 * Register/unregister probes at module load/unload.
506 /* Reset all macros within TRACEPOINT_EVENT */
507 #include <ust/lttng-tracepoint-event-reset.h>
509 #define TP_ID1(_token, _system) _token##_system
510 #define TP_ID(_token, _system) TP_ID1(_token, _system)
512 static void __attribute__((constructor
))
513 TP_ID(__lttng_events_init__
, TRACEPOINT_SYSTEM
)(void)
517 ret
= ltt_probe_register(&TP_ID(__probe_desc___
, TRACEPOINT_SYSTEM
));
521 static void __attribute__((destructor
))
522 TP_ID(__lttng_events_exit__
, TRACEPOINT_SYSTEM
)(void)
524 ltt_probe_unregister(&TP_ID(__probe_desc___
, TRACEPOINT_SYSTEM
));
This page took 0.042657 seconds and 6 git commands to generate.