#include <lttng.h>
#include <lttng-types.h>
#include <linux/debugfs.h>
-
-/*
- * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
- * strcpy().
- */
-#undef tp_assign
-#define tp_assign(dest, src) \
- lib_ring_buffer_align_ctx(config, &ctx, sizeof(src)); \
- lib_ring_buffer_write(config, &ctx, &src, sizeof(src));
-
-#undef tp_memcpy
-#define tp_memcpy(dest, src, len) \
- lib_ring_buffer_align_ctx(config, &ctx, sizeof(*(src))); \
- lib_ring_buffer_write(config, &ctx, &src, len);
-
-/* TODO */
-#undef tp_strcpy
-#define tp_strcpy(dest, src) __assign_str(dest, src);
+#include <linux/ringbuffer/frontend_types.h>
+#include "../ltt-events.h"
+#include "../ltt-tracer-core.h"
struct lttng_event_field {
const char *name;
};
/*
- * Stage 1 of the trace events.
- *
- * Create event field type metadata section.
- * Each event produce an array of fields.
+ * Macro declarations used for all stages.
*/
/*
*
* TRACE_EVENT is a one to one mapping between tracepoint and template.
*/
+
#undef TRACE_EVENT
#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
DECLARE_EVENT_CLASS(name, \
PARAMS(print)) \
DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args))
+#undef DEFINE_EVENT_PRINT
+#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
+ DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
+
+/* Callbacks are meaningless to LTTng. */
+#undef TRACE_EVENT_FN
+#define TRACE_EVENT_FN(name, proto, args, tstruct, \
+ assign, print, reg, unreg) \
+ TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
+ PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
+
+/*
+ * Stage 1 of the trace events.
+ *
+ * Create event field type metadata section.
+ * Each event produce an array of fields.
+ */
+
+#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
+
/* Named field types must be defined in lttng-types.h */
#undef __field
{ .name = #_item, .type = { .atype = atype_integer, .name = #_type} },
#undef __field_ext
-#define __field_ext(_type, _item, _filter_type) \
- { .name = #_item, .type = { .atype = atype_integer, .name = #_type} },
+#define __field_ext(_type, _item, _filter_type) __field(_type, _item)
#undef __array
#define __array(_type, _item, _length) \
#undef __string
#define __string(_item, _src) \
{ \
- .name = _item, \
+ .name = #_item, \
.type = { \
.atype = atype_string, \
.name = NULL, \
}, \
},
-#undef TP_PROTO
-#define TP_PROTO(args...)
-
-#undef TP_ARGS
-#define TP_ARGS(args...)
-
#undef TP_STRUCT__entry
#define TP_STRUCT__entry(args...) args /* Only one used in this phase */
-#undef TP_fast_assign
-#define TP_fast_assign(args...)
-
-#undef TP_printk
-#define TP_printk(args...)
-
#undef DECLARE_EVENT_CLASS
-#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
- static const struct lttng_event_field __event_fields___##name[] = { \
- tstruct \
+#define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
+ static const struct lttng_event_field __event_fields___##_name[] = { \
+ _tstruct \
};
-#undef DEFINE_EVENT
-#define DEFINE_EVENT(template, name, proto, args)
-
-#undef DEFINE_EVENT_PRINT
-#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
- DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
-
-/* Callbacks are meaningless to LTTng. */
-#undef TRACE_EVENT_FN
-#define TRACE_EVENT_FN(name, proto, args, tstruct, \
- assign, print, reg, unreg) \
- TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
- PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
-
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
/*
* Create an array of events.
*/
-/*
- * DECLARE_EVENT_CLASS can be used to add a generic function
- * handlers for events. That is, if all events have the same
- * parameters and just have distinct trace points.
- * Each tracepoint can be defined with DEFINE_EVENT and that
- * will map the DECLARE_EVENT_CLASS to the tracepoint.
- *
- * TRACE_EVENT is a one to one mapping between tracepoint and template.
- */
-#undef TRACE_EVENT
-#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
- DECLARE_EVENT_CLASS(name, \
- PARAMS(proto), \
- PARAMS(args), \
- PARAMS(tstruct), \
- PARAMS(assign), \
- PARAMS(print)) \
- DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args))
-
/* Named field types must be defined in lttng-types.h */
-#undef __field
-#define __field(_type, _item)
-
-#undef __field_ext
-#define __field_ext(_type, _item, _filter_type)
-
-#undef __array
-#define __array(_type, _item, _length)
-
-#undef __dynamic_array
-#define __dynamic_array(_type, _item, _length)
-
-#undef __string
-#define __string(_item, _src)
-
-#undef TP_PROTO
-#define TP_PROTO(args...)
-
-#undef TP_ARGS
-#define TP_ARGS(args...)
-
-#undef TP_STRUCT__entry
-#define TP_STRUCT__entry(args...)
-
-#undef TP_fast_assign
-#define TP_fast_assign(args...)
-
-#undef TP_printk
-#define TP_printk(args...)
-
-#undef DECLARE_EVENT_CLASS
-#define DECLARE_EVENT_CLASS(_name, proto, args, tstruct, assign, print) \
- { \
- .fields = __event_fields___##_name, \
- .name = #_name, \
- .nr_fields = ARRAY_SIZE(__event_fields___##_name), \
- },
+#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
#undef DEFINE_EVENT
-#define DEFINE_EVENT(template, name, proto, args)
-
-#undef DEFINE_EVENT_PRINT
-#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
- DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
-
-/* Callbacks are meaningless to LTTng. */
-#undef TRACE_EVENT_FN
-#define TRACE_EVENT_FN(name, proto, args, tstruct, \
- assign, print, reg, unreg) \
- TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
- PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
+#define DEFINE_EVENT(_template, _name, _proto, _args) \
+ { \
+ .fields = __event_fields___##_template, \
+ .name = #_name, \
+ .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
+ },
#define TP_ID1(_token, _system) _token##_system
#define TP_ID(_token, _system) TP_ID1(_token, _system)
* Create seq file metadata output.
*/
-/*
- * DECLARE_EVENT_CLASS can be used to add a generic function
- * handlers for events. That is, if all events have the same
- * parameters and just have distinct trace points.
- * Each tracepoint can be defined with DEFINE_EVENT and that
- * will map the DECLARE_EVENT_CLASS to the tracepoint.
- *
- * TRACE_EVENT is a one to one mapping between tracepoint and template.
- */
-#undef TRACE_EVENT
-#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
- DECLARE_EVENT_CLASS(name, \
- PARAMS(proto), \
- PARAMS(args), \
- PARAMS(tstruct), \
- PARAMS(assign), \
- PARAMS(print)) \
- DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args))
-
-/* Named field types must be defined in lttng-types.h */
-
-#undef __field
-#define __field(_type, _item)
-
-#undef __field_ext
-#define __field_ext(_type, _item, _filter_type)
-
-#undef __array
-#define __array(_type, _item, _length)
-
-#undef __dynamic_array
-#define __dynamic_array(_type, _item, _length)
-
-#undef __string
-#define __string(_item, _src)
-
-#undef TP_PROTO
-#define TP_PROTO(args...)
-
-#undef TP_ARGS
-#define TP_ARGS(args...)
-
-#undef TP_STRUCT__entry
-#define TP_STRUCT__entry(args...)
-
-#undef TP_fast_assign
-#define TP_fast_assign(args...)
-
-#undef TP_printk
-#define TP_printk(args...)
-
-#undef DECLARE_EVENT_CLASS
-#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
-static void ()
-
-#undef DEFINE_EVENT
-#define DEFINE_EVENT(template, name, proto, args)
-
-#undef DEFINE_EVENT_PRINT
-#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
- DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
-
-/* Callbacks are meaningless to LTTng. */
-#undef TRACE_EVENT_FN
-#define TRACE_EVENT_FN(name, proto, args, tstruct, \
- assign, print, reg, unreg) \
- TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
- PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
-
#define TP_ID1(_token, _system) _token##_system
#define TP_ID(_token, _system) TP_ID1(_token, _system)
#define module_init_eval1(_token, _system) module_init(_token##_system)
static void *TP_ID(__lttng_seq_start__, TRACE_SYSTEM)(struct seq_file *m,
loff_t *pos)
{
- const struct lttng_event_desc *desc = &TP_ID(__event_desc___, TRACE_SYSTEM)[*pos];
+ const struct lttng_event_desc *desc =
+ &TP_ID(__event_desc___, TRACE_SYSTEM)[*pos];
- if (desc > &TP_ID(__event_desc___, TRACE_SYSTEM)[ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)) - 1])
+ if (desc > &TP_ID(__event_desc___, TRACE_SYSTEM)
+ [ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)) - 1])
return NULL;
return (void *) desc;
}
static void *TP_ID(__lttng_seq_next__, TRACE_SYSTEM)(struct seq_file *m,
void *p, loff_t *ppos)
{
- const struct lttng_event_desc *desc = &TP_ID(__event_desc___, TRACE_SYSTEM)[++(*ppos)];
+ const struct lttng_event_desc *desc =
+ &TP_ID(__event_desc___, TRACE_SYSTEM)[++(*ppos)];
- if (desc > &TP_ID(__event_desc___, TRACE_SYSTEM)[ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)) - 1])
+ if (desc > &TP_ID(__event_desc___, TRACE_SYSTEM)
+ [ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)) - 1])
return NULL;
return (void *) desc;
}
return seq_open(file, &TP_ID(__lttng_types_seq_ops__, TRACE_SYSTEM));
}
-static const struct file_operations TP_ID(__lttng_types_fops__, TRACE_SYSTEM) = {
+static const
+struct file_operations TP_ID(__lttng_types_fops__, TRACE_SYSTEM) = {
.open = TP_ID(__lttng_types_open__, TRACE_SYSTEM),
.read = seq_read,
.llseek = seq_lseek,
int ret = 0;
TP_ID(__lttng_types_dentry__, TRACE_SYSTEM) =
- debugfs_create_file("lttng-events-" __stringify(TRACE_SYSTEM), S_IWUSR,
- NULL, NULL, &TP_ID(__lttng_types_fops__, TRACE_SYSTEM));
+ debugfs_create_file("lttng-events-" __stringify(TRACE_SYSTEM),
+ S_IWUSR, NULL, NULL,
+ &TP_ID(__lttng_types_fops__, TRACE_SYSTEM));
if (IS_ERR(TP_ID(__lttng_types_dentry__, TRACE_SYSTEM))
|| !TP_ID(__lttng_types_dentry__, TRACE_SYSTEM)) {
printk(KERN_ERR "Error creating LTTng type export file\n");
#undef TP_ID1
#undef TP_ID
+/*
+ * Stage 4 of the trace events.
+ *
+ * Create static inline function that calculates event size.
+ */
+
+#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
+
+/* Named field types must be defined in lttng-types.h */
+
+#undef __field
+#define __field(_type, _item) \
+ __event_len += lib_ring_buffer_align(__event_len, sizeof(_type)); \
+ __event_len += sizeof(_type);
+
+#undef __field_ext
+#define __field_ext(_type, _item, _filter_type) __field(_type, _item)
+
+#undef __array
+#define __array(_type, _item, _length) \
+ __event_len += lib_ring_buffer_align(__event_len, sizeof(_type)); \
+ __event_len += sizeof(_type) * (_length);
+
+#undef __dynamic_array
+#define __dynamic_array(_type, _item, _length) \
+ __event_len += lib_ring_buffer_align(__event_len, sizeof(u32)); \
+ __event_len += sizeof(u32); \
+ __event_len += lib_ring_buffer_align(__event_len, sizeof(_type)); \
+ __event_len += sizeof(_type) * (_length);
+
+#undef __string
+#define __string(_item, _src) \
+ __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
+
+#undef TP_PROTO
+#define TP_PROTO(args...) args
+
+#undef TP_STRUCT__entry
+#define TP_STRUCT__entry(args...) args
+
+#undef DECLARE_EVENT_CLASS
+#define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
+static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
+{ \
+ size_t __event_len = 0; \
+ unsigned int __dynamic_len_idx = 0; \
+ \
+ if (0) \
+ (void) __dynamic_len_idx; /* don't warn if unused */ \
+ _tstruct \
+ return __event_len; \
+}
+
+#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
+
-#if 0
/*
- * Stage 3 of the trace events.
+ * Stage 5 of the trace events.
*
- * Create static inline function that calculates event size.
+ * Create static inline function that calculates event payload alignment.
*/
+#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
+/* Named field types must be defined in lttng-types.h */
+
+#undef __field
+#define __field(_type, _item) \
+ __event_align = max_t(size_t, __event_align, sizeof(_type));
+
+#undef __field_ext
+#define __field_ext(_type, _item, _filter_type) __field(_type, _item)
+
+#undef __array
+#define __array(_type, _item, _length) \
+ __event_align = max_t(size_t, __event_align, sizeof(_type));
+
+#undef __dynamic_array
+#define __dynamic_array(_type, _item, _length) \
+ __event_align = max_t(size_t, __event_align, sizeof(u32)); \
+ __event_align = max_t(size_t, __event_align, sizeof(_type));
+
+#undef __string
+#define __string(_item, _src)
+
+#undef TP_PROTO
+#define TP_PROTO(args...) args
+
+#undef TP_STRUCT__entry
+#define TP_STRUCT__entry(args...) args
+
+#undef DECLARE_EVENT_CLASS
+#define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
+static inline size_t __event_get_align__##_name(_proto) \
+{ \
+ size_t __event_align = 1; \
+ _tstruct \
+ return __event_align; \
+}
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
+
+
/*
- * Stage 4 of the trace events.
+ * Stage 6 of the trace events.
*
* Create the probe function : call even size calculation and write event data
* into the buffer.
+ *
+ * Note: the order of fields in TP_fast_assign and TP_STRUCT__entry must be the
+ * same.
*/
+#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
+#undef __field
+#define __field(_type, _item) \
+ lib_ring_buffer_align_ctx(&ctx, sizeof(_type)); \
+ goto __assign_##_item; \
+__end_field_##_item:
-#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
+#undef __field_ext
+#define __field_ext(_type, _item, _filter_type) __field(_type, _item)
+#undef __array
+#define __array(_type, _item, _length) \
+ lib_ring_buffer_align_ctx(&ctx, sizeof(_type)); \
+ goto __assign_##_item; \
+__end_field_##_item:
+
+#undef __dynamic_array
+#define __dynamic_array(_type, _item, _length) \
+ lib_ring_buffer_align_ctx(&ctx, sizeof(u32)); \
+ goto __assign_##_item##_1; \
+__end_field_##_item##_1: \
+ lib_ring_buffer_align_ctx(&ctx, sizeof(_type)); \
+ goto __assign_##_item##_2; \
+__end_field_##_item##_2:
+#undef __string
+#define __string(_item, _src) \
+ goto __assign_##_item; \
+__end_field_##_item:
+/*
+ * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
+ * strcpy().
+ */
+#undef tp_assign
+#define tp_assign(dest, src) \
+__assign_##dest: \
+ { \
+ __typeof__(src) __tmp = (src); \
+ __chan->ops->event_write(&ctx, &__tmp, sizeof(src)); \
+ } \
+ goto __end_field_##dest;
+
+#undef tp_memcpy
+#define tp_memcpy(dest, src, len) \
+__assign_##dest: \
+ __chan->ops->event_write(&ctx, src, len); \
+ goto __end_field_##dest;
+
+#undef tp_memcpy_dyn
+#define tp_memcpy_dyn(dest, src, len) \
+__assign_##dest##_1: \
+ { \
+ __typeof__(len) __tmpl = (len); \
+ __chan->ops->event_write(&ctx, &__tmpl, sizeof(u32)); \
+ } \
+ goto __end_field_##dest##_1; \
+__assign_##dest##_2: \
+ __chan->ops->event_write(&ctx, src, len); \
+ goto __end_field_##dest##_2;
+
+#undef tp_strcpy
+#define tp_strcpy(dest, src) \
+ tp_memcpy(dest, src, __get_dynamic_array_len(dest)); \
+
+/* Named field types must be defined in lttng-types.h */
+
+#undef __get_str
+#define __get_str(field) field
+
+#undef __get_dynamic_array
+#define __get_dynamic_array(field) field
+
+/* Beware: this get len actually consumes the len value */
+#undef __get_dynamic_array_len
+#define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
+
+#undef TP_PROTO
+#define TP_PROTO(args...) args
+
+#undef TP_ARGS
+#define TP_ARGS(args...) args
+
+#undef TP_STRUCT__entry
+#define TP_STRUCT__entry(args...) args
+
+#undef TP_fast_assign
+#define TP_fast_assign(args...) args
+
+#undef DECLARE_EVENT_CLASS
+#define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
+static void __event_probe__##_name(void *__data, _proto) \
+{ \
+ struct ltt_event *__event = __data; \
+ struct ltt_channel *__chan = __event->chan; \
+ struct lib_ring_buffer_ctx ctx; \
+ size_t __event_len, __event_align; \
+ size_t __dynamic_len_idx = 0; \
+ size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
+ int __ret; \
+ \
+ if (0) \
+ (void) __dynamic_len_idx; /* don't warn if unused */ \
+ __event_len = __event_get_size__##_name(__dynamic_len, _args); \
+ __event_align = __event_get_align__##_name(_args); \
+ lib_ring_buffer_ctx_init(&ctx, __chan->chan, NULL, __event_len, \
+ __event_align, -1); \
+ __ret = __chan->ops->event_reserve(&ctx); \
+ if (__ret < 0) \
+ return; \
+ /* Control code (field ordering) */ \
+ _tstruct \
+ __chan->ops->event_commit(&ctx); \
+ return; \
+ /* Copy code, steered by control code */ \
+ _assign \
+}
+
+#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
+
+
+#if 0
#include <linux/ftrace_event.h>