c006ffd365346e9e50133bf1bcc93178afd17b73
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/ringbuffer-config.h>
26 * Macro declarations used for all stages.
30 #define ctf_integer(_type, _item, _src) \
31 ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10)
33 #undef ctf_integer_hex
34 #define ctf_integer_hex(_type, _item, _src) \
35 ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 16)
37 #undef ctf_integer_network
38 #define ctf_integer_network(_type, _item, _src) \
39 ctf_integer_ext(_type, _item, _src, BIG_ENDIAN, 10)
41 #undef ctf_integer_network_hex
42 #define ctf_integer_network_hex(_type, _item, _src) \
43 ctf_integer_ext(_type, _item, _src, BIG_ENDIAN, 16)
46 #define ctf_array(_type, _item, _src, _length) \
47 ctf_array_encoded(_type, _item, _src, _length, none)
50 #define ctf_array_text(_type, _item, _src, _length) \
51 ctf_array_encoded(_type, _item, _src, _length, UTF8)
54 #define ctf_sequence(_type, _item, _src, _length_type, _src_length) \
55 ctf_sequence_encoded(_type, _item, _src, \
56 _length_type, _src_length, none)
58 #undef ctf_sequence_text
59 #define ctf_sequence_text(_type, _item, _src, _length_type, _src_length) \
60 ctf_sequence_encoded(_type, _item, _src, \
61 _length_type, _src_length, UTF8)
63 /* ctf_string is redefined at each step */
66 * TRACEPOINT_EVENT_CLASS can be used to add a generic function handlers
67 * for events. That is, if all events have the same parameters and just
68 * have distinct trace points. Each tracepoint can be defined with
69 * TRACEPOINT_EVENT_INSTANCE and that will map the
70 * TRACEPOINT_EVENT_CLASS to the tracepoint.
72 * TRACEPOINT_EVENT is a one to one mapping between tracepoint and
76 #undef TRACEPOINT_EVENT
77 #define TRACEPOINT_EVENT(name, proto, args, fields) \
78 TRACEPOINT_EVENT_CLASS(name, \
82 TRACEPOINT_EVENT_INSTANCE(name, name, TP_PARAMS(proto), TP_PARAMS(args))
84 #undef TRACEPOINT_EVENT_NOARGS
85 #define TRACEPOINT_EVENT_NOARGS(name, fields) \
86 TRACEPOINT_EVENT_CLASS_NOARGS(name, \
88 TRACEPOINT_EVENT_INSTANCE_NOARGS(name, name)
91 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
94 * Stage 1 of the trace events.
96 * Create event field type metadata section.
97 * Each event produce an array of fields.
100 /* Reset all macros within TRACEPOINT_EVENT */
101 #include <ust/lttng-tracepoint-event-reset.h>
103 /* Named field types must be defined in lttng-types.h */
105 #undef ctf_integer_ext
106 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
109 .type = __type_integer(_type, _byte_order, _base, none),\
113 #define ctf_float(_type, _item, _src) \
116 .type = __type_float(_type), \
119 #undef ctf_array_encoded
120 #define ctf_array_encoded(_type, _item, _src, _length, _encoding) \
125 .atype = atype_array, \
129 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
134 #undef ctf_sequence_encoded
135 #define ctf_sequence_encoded(_type, _item, _src, \
136 _length_type, _src_length, _encoding) \
141 .atype = atype_sequence, \
144 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
145 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
151 #define ctf_string(_item, _src) \
156 .atype = atype_string, \
157 .u.basic.string.encoding = lttng_encode_UTF8, \
162 #define TP_FIELDS(args...) args /* Only one used in this phase */
164 #undef TRACEPOINT_EVENT_CLASS_NOARGS
165 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
166 static const struct lttng_event_field __event_fields___##_name[] = { \
170 #undef TRACEPOINT_EVENT_CLASS
171 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
172 TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields)
174 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
177 * Stage 2 of the trace events.
179 * Create probe callback prototypes.
182 /* Reset all macros within TRACEPOINT_EVENT */
183 #include <ust/lttng-tracepoint-event-reset.h>
186 #define TP_PROTO(args...) args
188 #undef TRACEPOINT_EVENT_CLASS
189 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
190 static void __event_probe__##_name(void *__data, _proto);
192 #undef TRACEPOINT_EVENT_CLASS_NOARGS
193 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
194 static void __event_probe__##_name(void *__data);
196 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
199 * Stage 3 of the trace events.
201 * Create an array of events.
204 /* Named field types must be defined in lttng-types.h */
206 /* Reset all macros within TRACEPOINT_EVENT */
207 #include <ust/lttng-tracepoint-event-reset.h>
209 #undef TRACEPOINT_EVENT_INSTANCE_NOARGS
210 #define TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
212 .fields = __event_fields___##_template, \
214 .probe_callback = (void *) &__event_probe__##_template,\
215 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_template), \
218 #undef TRACEPOINT_EVENT_INSTANCE
219 #define TRACEPOINT_EVENT_INSTANCE(_template, _name, _proto, _args) \
220 TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name)
222 #define TP_ID1(_token, _system) _token##_system
223 #define TP_ID(_token, _system) TP_ID1(_token, _system)
225 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACEPOINT_SYSTEM
)[] = {
226 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
234 * Stage 4 of the trace events.
236 * Create a toplevel descriptor for the whole probe.
239 #define TP_ID1(_token, _system) _token##_system
240 #define TP_ID(_token, _system) TP_ID1(_token, _system)
242 /* non-const because list head will be modified when registered. */
243 static struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACEPOINT_SYSTEM
) = {
244 .event_desc
= TP_ID(__event_desc___
, TRACEPOINT_SYSTEM
),
245 .nr_events
= _TP_ARRAY_SIZE(TP_ID(__event_desc___
, TRACEPOINT_SYSTEM
)),
252 * Stage 5 of the trace events.
254 * Create static inline function that calculates event size.
257 /* Reset all macros within TRACEPOINT_EVENT */
258 #include <ust/lttng-tracepoint-event-reset.h>
260 /* Named field types must be defined in lttng-types.h */
262 #undef ctf_integer_ext
263 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
264 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
265 __event_len += sizeof(_type);
268 #define ctf_float(_type, _item, _src) \
269 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
270 __event_len += sizeof(_type);
272 #undef ctf_array_encoded
273 #define ctf_array_encoded(_type, _item, _src, _length) \
274 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
275 __event_len += sizeof(_type) * (_length);
277 #undef ctf_sequence_encoded
278 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
279 _src_length, _encoding) \
280 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_length_type)); \
281 __event_len += sizeof(_length_type); \
282 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
283 __dynamic_len[__dynamic_len_idx] = (_length); \
284 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
288 #define ctf_string(_item, _src) \
289 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
292 #define TP_PROTO(args...) args
295 #define TP_FIELDS(args...) args
297 #undef TRACEPOINT_EVENT_CLASS
298 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
299 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
301 size_t __event_len = 0; \
302 unsigned int __dynamic_len_idx = 0; \
305 (void) __dynamic_len_idx; /* don't warn if unused */ \
307 return __event_len; \
310 #undef TRACEPOINT_EVENT_CLASS_NOARGS
311 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
312 static inline size_t __event_get_size__##_name(size_t *__dynamic_len) \
314 size_t __event_len = 0; \
315 unsigned int __dynamic_len_idx = 0; \
318 (void) __dynamic_len_idx; /* don't warn if unused */ \
320 return __event_len; \
323 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
326 * Stage 6 of the trace events.
328 * Create static inline function that calculates event payload alignment.
331 /* Reset all macros within TRACEPOINT_EVENT */
332 #include <ust/lttng-tracepoint-event-reset.h>
334 /* Named field types must be defined in lttng-types.h */
336 #undef ctf_integer_ext
337 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
338 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
341 #define ctf_float(_type, _item, _src) \
342 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
344 #undef ctf_array_encoded
345 #define ctf_array_encoded(_type, _item, _src, _length) \
346 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
348 #undef ctf_sequence_encoded
349 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
350 _src_length, _encoding) \
351 __event_align = max_t(size_t, __event_align, ltt_alignof(_length_type)); \
352 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
355 #define ctf_string(_item, _src)
358 #define TP_PROTO(args...) args
361 #define TP_FIELDS(args...) args
363 #undef TRACEPOINT_EVENT_CLASS
364 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
365 static inline size_t __event_get_align__##_name(_proto) \
367 size_t __event_align = 1; \
369 return __event_align; \
372 #undef TRACEPOINT_EVENT_CLASS_NOARGS
373 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
374 static inline size_t __event_get_align__##_name(void) \
376 size_t __event_align = 1; \
378 return __event_align; \
381 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
385 * Stage 7 of the trace events.
387 * Create the probe function : call even size calculation and write event data
390 * We use both the field and assignment macros to write the fields in the order
391 * defined in the field declaration. The field declarations control the
392 * execution order, jumping to the appropriate assignment block.
395 /* Reset all macros within TRACEPOINT_EVENT */
396 #include <ust/lttng-tracepoint-event-reset.h>
398 #undef ctf_integer_ext
399 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
401 _type __tmp = (_src); \
402 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(__tmp)); \
403 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
407 #define ctf_float(_type, _item, _src) \
409 _type __tmp = (_src); \
410 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(__tmp)); \
411 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
414 #undef ctf_array_encoded
415 #define ctf_array_encoded(_type, _item, _src, _length) \
416 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(_type)); \
417 __chan->ops->event_write(&ctx, _src, _length);
419 #undef ctf_sequence_encoded
420 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
421 _src_length, _encoding) \
423 _length_type __tmpl = __dynamic_len[__dynamic_len_idx]; \
424 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(_length_type)); \
425 __chan->ops->event_write(&ctx, &__tmpl, sizeof(_length_type)); \
427 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(_type)); \
428 __chan->ops->event_write(&ctx, _src, \
429 sizeof(_type) * __get_sequence_len(dest));
432 #define ctf_string(_item, _src) \
433 tp_memcpy(dest, _src, __get_sequence_len(dest))
435 /* Beware: this get len actually consumes the len value */
436 #undef __get_sequence_len
437 #define __get_sequence_len(field) __dynamic_len[__dynamic_len_idx++]
440 #define TP_PROTO(args...) args
443 #define TP_ARGS(args...) args
446 #define TP_FIELDS(args...) args
448 #undef TRACEPOINT_EVENT_CLASS
449 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
450 static void __event_probe__##_name(void *__data, _proto) \
452 struct ltt_event *__event = __data; \
453 struct ltt_channel *__chan = __event->chan; \
454 struct lib_ring_buffer_ctx ctx; \
455 size_t __event_len, __event_align; \
456 size_t __dynamic_len_idx = 0; \
457 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_name)]; \
461 (void) __dynamic_len_idx; /* don't warn if unused */ \
462 if (unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
464 if (unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
466 if (unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
468 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
469 __event_align = __event_get_align__##_name(_args); \
470 lib_ring_buffer_ctx_init(&ctx, __chan->chan, __event, __event_len, \
471 __event_align, -1); \
472 __ret = __chan->ops->event_reserve(&ctx, __event->id); \
476 __chan->ops->event_commit(&ctx); \
479 #undef TRACEPOINT_EVENT_CLASS_NOARGS
480 #define TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
481 static void __event_probe__##_name(void *__data) \
483 struct ltt_event *__event = __data; \
484 struct ltt_channel *__chan = __event->chan; \
485 struct lib_ring_buffer_ctx ctx; \
486 size_t __event_len, __event_align; \
487 size_t __dynamic_len_idx = 0; \
488 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_name)]; \
492 (void) __dynamic_len_idx; /* don't warn if unused */ \
493 if (unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
495 if (unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
497 if (unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
499 __event_len = __event_get_size__##_name(__dynamic_len); \
500 __event_align = __event_get_align__##_name(); \
501 lib_ring_buffer_ctx_init(&ctx, __chan->chan, __event, __event_len, \
502 __event_align, -1); \
503 __ret = __chan->ops->event_reserve(&ctx, __event->id); \
507 __chan->ops->event_commit(&ctx); \
510 #include TRACEPOINT_INCLUDE(TRACEPOINT_INCLUDE_FILE)
513 * Stage 8 of the trace events.
515 * Register/unregister probes at module load/unload.
518 /* Reset all macros within TRACEPOINT_EVENT */
519 #include <ust/lttng-tracepoint-event-reset.h>
521 #define TP_ID1(_token, _system) _token##_system
522 #define TP_ID(_token, _system) TP_ID1(_token, _system)
524 static void __attribute__((constructor
))
525 TP_ID(__lttng_events_init__
, TRACEPOINT_SYSTEM
)(void)
529 ret
= ltt_probe_register(&TP_ID(__probe_desc___
, TRACEPOINT_SYSTEM
));
533 static void __attribute__((destructor
))
534 TP_ID(__lttng_events_exit__
, TRACEPOINT_SYSTEM
)(void)
536 ltt_probe_unregister(&TP_ID(__probe_desc___
, TRACEPOINT_SYSTEM
));
This page took 0.057138 seconds and 4 git commands to generate.