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 <ust/lttng-events.h>
24 * Macro declarations used for all stages.
28 #define ctf_integer(_type, _item, _src) \
29 ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10)
31 #undef ctf_integer_hex
32 #define ctf_integer_hex(_type, _item, _src) \
33 ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 16)
35 #undef ctf_integer_network
36 #define ctf_integer_network(_type, _item, _src) \
37 ctf_integer_ext(_type, _item, _src, BIG_ENDIAN, 10)
39 #undef ctf_integer_network_hex
40 #define ctf_integer_network_hex(_type, _item, _src) \
41 ctf_integer_ext(_type, _item, _src, BIG_ENDIAN, 16)
44 #define ctf_array(_type, _item, _src, _length) \
45 ctf_array_encoded(_type, _item, _src, _length, none)
48 #define ctf_array_text(_type, _item, _src, _length) \
49 ctf_array_encoded(_type, _item, _src, _length, UTF8)
52 #define ctf_sequence(_type, _item, _src, _length_type, _src_length) \
53 ctf_sequence_encoded(_type, _item, _src, \
54 _length_type, _src_length, none)
56 #undef ctf_sequence_text
57 #define ctf_sequence_text(_type, _item, _src, _length_type, _src_length) \
58 ctf_sequence_encoded(_type, _item, _src, \
59 _length_type, _src_length, UTF8)
61 /* ctf_string is redefined at each step */
64 * TRACEPOINT_EVENT_CLASS can be used to add a generic function handlers
65 * for events. That is, if all events have the same parameters and just
66 * have distinct trace points. Each tracepoint can be defined with
67 * TRACEPOINT_EVENT_INSTANCE and that will map the
68 * TRACEPOINT_EVENT_CLASS to the tracepoint.
70 * TRACEPOINT_EVENT is a one to one mapping between tracepoint and
74 #undef TRACEPOINT_EVENT
75 #define TRACEPOINT_EVENT(name, proto, args, fields) \
76 TRACEPOINT_EVENT_CLASS(name, \
80 TRACEPOINT_EVENT_INSTANCE(name, name, TP_PARAMS(proto), TP_PARAMS(args))
83 * Stage 1 of the trace events.
85 * Create event field type metadata section.
86 * Each event produce an array of fields.
89 /* Reset all macros within TRACE_EVENT */
90 #include "lttng-tracepoint-events-reset.h"
92 /* Named field types must be defined in lttng-types.h */
94 #undef ctf_integer_ext
95 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
98 .type = __type_integer(_type, _byte_order, _base, none),\
102 #define ctf_float(_type, _item, _src) \
105 .type = __type_float(_type), \
108 #undef ctf_array_encoded
109 #define ctf_array_encoded(_type, _item, _src, _length, _encoding) \
114 .atype = atype_array, \
118 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
123 #undef ctf_sequence_encoded
124 #define ctf_sequence_encoded(_type, _item, _src, \
125 _length_type, _src_length, _encoding) \
130 .atype = atype_sequence, \
133 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
134 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
140 #define ctf_string(_item, _src) \
145 .atype = atype_string, \
146 .u.basic.string.encoding = lttng_encode_UTF8, \
151 #define TP_FIELDS(args...) args /* Only one used in this phase */
153 #undef TRACEPOINT_EVENT_CLASS
154 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
155 static const struct lttng_event_field __event_fields___##_name[] = { \
159 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
162 * Stage 2 of the trace events.
164 * Create probe callback prototypes.
167 /* Reset all macros within TRACE_EVENT */
168 #include "lttng-tracepoint-events-reset.h"
171 #define TP_PROTO(args...) args
173 #undef TRACEPOINT_EVENT_CLASS
174 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
175 static void __event_probe__##_name(void *__data, _proto);
177 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
180 * Stage 3 of the trace events.
182 * Create an array of events.
185 /* Named field types must be defined in lttng-types.h */
187 /* Reset all macros within TRACE_EVENT */
188 #include "lttng-tracepoint-events-reset.h"
190 #undef TRACEPOINT_EVENT_INSTANCE
191 #define TRACEPOINT_EVENT_INSTANCE(_template, _name, _proto, _args) \
193 .fields = __event_fields___##_template, \
195 .probe_callback = (void *) &__event_probe__##_template,\
196 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
199 #define TP_ID1(_token, _system) _token##_system
200 #define TP_ID(_token, _system) TP_ID1(_token, _system)
202 static const struct lttng_event_desc
TP_ID(__event_desc___
, TRACE_SYSTEM
)[] = {
203 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
211 * Stage 4 of the trace events.
213 * Create a toplevel descriptor for the whole probe.
216 #define TP_ID1(_token, _system) _token##_system
217 #define TP_ID(_token, _system) TP_ID1(_token, _system)
219 /* non-const because list head will be modified when registered. */
220 static struct lttng_probe_desc
TP_ID(__probe_desc___
, TRACE_SYSTEM
) = {
221 .event_desc
= TP_ID(__event_desc___
, TRACE_SYSTEM
),
222 .nr_events
= ARRAY_SIZE(TP_ID(__event_desc___
, TRACE_SYSTEM
)),
229 * Stage 5 of the trace events.
231 * Create static inline function that calculates event size.
234 /* Reset all macros within TRACE_EVENT */
235 #include "lttng-tracepoint-events-reset.h"
237 /* Named field types must be defined in lttng-types.h */
239 #undef ctf_integer_ext
240 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
241 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
242 __event_len += sizeof(_type);
245 #define ctf_float(_type, _item, _src) \
246 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
247 __event_len += sizeof(_type);
249 #undef ctf_array_encoded
250 #define ctf_array_encoded(_type, _item, _src, _length) \
251 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
252 __event_len += sizeof(_type) * (_length);
254 #undef ctf_sequence_encoded
255 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
256 _src_length, _encoding) \
257 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_length_type)); \
258 __event_len += sizeof(_length_type); \
259 __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \
260 __dynamic_len[__dynamic_len_idx] = (_length); \
261 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
265 #define ctf_string(_item, _src) \
266 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
269 #define TP_PROTO(args...) args
272 #define TP_FIELDS(args...) args
274 #undef TRACEPOINT_EVENT_CLASS
275 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
276 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
278 size_t __event_len = 0; \
279 unsigned int __dynamic_len_idx = 0; \
282 (void) __dynamic_len_idx; /* don't warn if unused */ \
284 return __event_len; \
287 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
290 * Stage 6 of the trace events.
292 * Create static inline function that calculates event payload alignment.
295 /* Reset all macros within TRACE_EVENT */
296 #include "lttng-tracepoint-events-reset.h"
298 /* Named field types must be defined in lttng-types.h */
300 #undef ctf_integer_ext
301 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
302 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
305 #define ctf_float(_type, _item, _src) \
306 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
308 #undef ctf_array_encoded
309 #define ctf_array_encoded(_type, _item, _src, _length) \
310 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
312 #undef ctf_sequence_encoded
313 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
314 _src_length, _encoding) \
315 __event_align = max_t(size_t, __event_align, ltt_alignof(_length_type)); \
316 __event_align = max_t(size_t, __event_align, ltt_alignof(_type));
319 #define ctf_string(_item, _src)
322 #define TP_PROTO(args...) args
325 #define TP_FIELDS(args...) args
327 #undef TRACEPOINT_EVENT_CLASS
328 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
329 static inline size_t __event_get_align__##_name(_proto) \
331 size_t __event_align = 1; \
333 return __event_align; \
336 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
340 * Stage 7 of the trace events.
342 * Create the probe function : call even size calculation and write event data
345 * We use both the field and assignment macros to write the fields in the order
346 * defined in the field declaration. The field declarations control the
347 * execution order, jumping to the appropriate assignment block.
350 /* Reset all macros within TRACE_EVENT */
351 #include "lttng-tracepoint-events-reset.h"
353 #undef ctf_integer_ext
354 #define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \
356 _type __tmp = (_src); \
357 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(__tmp)); \
358 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
362 #define ctf_float(_type, _item, _src) \
364 _type __tmp = (_src); \
365 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(__tmp)); \
366 __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \
369 #undef ctf_array_encoded
370 #define ctf_array_encoded(_type, _item, _src, _length) \
371 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(_type)); \
372 __chan->ops->event_write(&ctx, _src, _length);
374 #undef ctf_sequence_encoded
375 #define ctf_sequence_encoded(_type, _item, _src, _length_type, \
376 _src_length, _encoding) \
378 _length_type __tmpl = __dynamic_len[__dynamic_len_idx]; \
379 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(_length_type)); \
380 __chan->ops->event_write(&ctx, &__tmpl, sizeof(_length_type)); \
382 lib_ring_buffer_align_ctx(&ctx, ltt_alignof(_type)); \
383 __chan->ops->event_write(&ctx, _src, \
384 sizeof(_type) * __get_sequence_len(dest));
387 #define ctf_string(_item, _src) \
388 tp_memcpy(dest, _src, __get_sequence_len(dest))
390 /* Beware: this get len actually consumes the len value */
391 #undef __get_sequence_len
392 #define __get_sequence_len(field) __dynamic_len[__dynamic_len_idx++]
395 #define TP_PROTO(args...) args
398 #define TP_ARGS(args...) args
401 #define TP_FIELDS(args...) args
403 #undef TRACEPOINT_EVENT_CLASS
404 #define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
405 static void __event_probe__##_name(void *__data, _proto) \
407 struct ltt_event *__event = __data; \
408 struct ltt_channel *__chan = __event->chan; \
409 struct lib_ring_buffer_ctx ctx; \
410 size_t __event_len, __event_align; \
411 size_t __dynamic_len_idx = 0; \
412 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
416 (void) __dynamic_len_idx; /* don't warn if unused */ \
417 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
419 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
421 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
423 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
424 __event_align = __event_get_align__##_name(_args); \
425 lib_ring_buffer_ctx_init(&ctx, __chan->chan, __event, __event_len, \
426 __event_align, -1); \
427 __ret = __chan->ops->event_reserve(&ctx, __event->id); \
431 __chan->ops->event_commit(&ctx); \
434 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
437 * Stage 8 of the trace events.
439 * Register/unregister probes at module load/unload.
442 /* Reset all macros within TRACE_EVENT */
443 #include "lttng-tracepoint-events-reset.h"
445 #define TP_ID1(_token, _system) _token##_system
446 #define TP_ID(_token, _system) TP_ID1(_token, _system)
448 static void __attribute__((constructor
))
449 TP_ID(__lttng_events_init__
, TRACE_SYSTEM
)(void)
453 ret
= ltt_probe_register(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
457 static void __attribute__((destructor
))
458 TP_ID(__lttng_events_exit__
, TRACE_SYSTEM
)(void)
460 ltt_probe_unregister(&TP_ID(__probe_desc___
, TRACE_SYSTEM
));
This page took 0.040739 seconds and 4 git commands to generate.