[lttng-dev] [RFC-patch 5/5] Add macros to copy struct metadata field by field
Geneviève Bastien
gbastien+lttng at versatic.net
Wed Apr 24 16:14:20 EDT 2013
Just like DECLARE_EVENT_CLASS and TRACE_EVENT, the TRACEPOINT_STRUCT macro
takes a TP_fast_assign parameter to allow to copy a struct data field by
field.
Signed-off-by: Geneviève Bastien <gbastien+lttng at versatic.net>
---
probes/lttng-events-reset.h | 5 ++-
probes/lttng-events.h | 95 +++++++++++++++++++++++++++++++++++++++++----
2 files changed, 91 insertions(+), 9 deletions(-)
diff --git a/probes/lttng-events-reset.h b/probes/lttng-events-reset.h
index f115d5e..0ed685a 100644
--- a/probes/lttng-events-reset.h
+++ b/probes/lttng-events-reset.h
@@ -47,7 +47,7 @@
#define __string(_item, _src)
#undef __struct
-#define __struct(_provider, _type, _item, _params)
+#define __struct(_provider, _type, _item, _params...)
#undef __variant
#define __variant(_provider, _type, _item, _enum_field, _enum, _src...)
@@ -136,6 +136,9 @@
#undef TRACEPOINT_STRUCT_RAW
#define TRACEPOINT_STRUCT_RAW(_provider, _name, _proto, _args, _fields)
+#undef TRACEPOINT_STRUCT
+#define TRACEPOINT_STRUCT(_provider, _name, _proto, _args, _fields, _assign)
+
#undef TRACEPOINT_ENUM
#define TRACEPOINT_ENUM(_provider, _name, _type, _enum)
diff --git a/probes/lttng-events.h b/probes/lttng-events.h
index 7e3a5b0..a49d7a0 100644
--- a/probes/lttng-events.h
+++ b/probes/lttng-events.h
@@ -350,7 +350,7 @@ end: \
__string(_item, _src)
#undef __struct
-#define __struct(_provider, _type, _item, _params) \
+#define __struct(_provider, _type, _item, _params...) \
{ \
.name = #_item, \
.type = \
@@ -405,6 +405,11 @@ end: \
_fields \
};
+#undef TRACEPOINT_STRUCT
+#define TRACEPOINT_STRUCT(_provider, _name, _proto, _args, _fields, _assign)\
+ TRACEPOINT_STRUCT_RAW(_provider, _name, PARAMS(_proto), \
+ PARAMS(_args), PARAMS(_fields))
+
#undef TRACEPOINT_VARIANT
#define TRACEPOINT_VARIANT(_provider, _name, _proto, _args, _enum_provider, _enum_name, _earg, _variants, _assign)\
static const struct lttng_event_field \
@@ -464,6 +469,11 @@ static struct lttng_struct_desc __struct_desc___##_provider##_##_name = {\
.owner = THIS_MODULE, \
};
+#undef TRACEPOINT_STRUCT
+#define TRACEPOINT_STRUCT(_provider, _name, _proto, _args, _fields, _assign)\
+ TRACEPOINT_STRUCT_RAW(_provider, _name, PARAMS(_proto), \
+ PARAMS(_args), PARAMS(_fields))
+
#undef TP_TYPE
#define TP_TYPE(_type) _type
@@ -500,7 +510,7 @@ static struct lttng_struct_desc __variant_desc__##_provider##_##_name = {\
#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
#undef __struct
-#define __struct(_provider, _type, _item, _params) \
+#define __struct(_provider, _type, _item, _params...) \
{ \
.mtype = mtype_struct, \
.m.ctf_st.struct_desc = &__struct_desc___##_provider##_##_type,\
@@ -542,6 +552,11 @@ static const struct lttng_metadata __type_metadata_for__##_provider##_##_name[]
_fields \
};
+#undef TRACEPOINT_STRUCT
+#define TRACEPOINT_STRUCT(_provider, _name, _proto, _args, _fields, _assign)\
+ TRACEPOINT_STRUCT_RAW(_provider, _name, PARAMS(_proto), \
+ PARAMS(_args), PARAMS(_fields))
+
#undef TRACEPOINT_VARIANT
#define TRACEPOINT_VARIANT(_provider, _name, _proto, _args, _enum_provider, _enum_name, _earg, _variants, _assign)\
static const struct lttng_metadata __type_metadata_for_var__##_provider##_##_name[] = {\
@@ -685,7 +700,7 @@ static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = {
__event_len += max_t(size_t, lttng_strlen_user_inatomic(_src), 1);
#undef __struct
-#define __struct(_provider, _type, _item, _params) \
+#define __struct(_provider, _type, _item, _params...) \
__event_len += __struct_get_size__##_provider##_##_type(_params);\
#undef __field_enum
@@ -718,6 +733,11 @@ static inline size_t __struct_get_size__##_provider##_##_name(_proto) \
return __event_len; \
}
+#undef TRACEPOINT_STRUCT
+#define TRACEPOINT_STRUCT(_provider, _name, _proto, _args, _fields, _assign)\
+ TRACEPOINT_STRUCT_RAW(_provider, _name, PARAMS(_proto), \
+ PARAMS(_args), PARAMS(_fields))
+
#undef TRACEPOINT_ENUM
#define TRACEPOINT_ENUM(_provider, _name, _type, _enum) \
static inline size_t __enum_get_size__##_provider##_##_name(void) \
@@ -778,7 +798,7 @@ static inline size_t __variant_get_size__##_provider##_##_name(_proto) \
max_t(size_t, lttng_strlen_user_inatomic(_src), 1);
#undef __struct
-#define __struct(_provider, _type, _item, _params) \
+#define __struct(_provider, _type, _item, _params...) \
__event_len += __dynamic_len[__dynamic_len_idx++] = \
__struct_get_size__##_provider##_##_type(_params);
@@ -790,6 +810,19 @@ static inline size_t __variant_get_size__##_provider##_##_name(_proto) \
#undef TRACEPOINT_STRUCT_RAW
#define TRACEPOINT_STRUCT_RAW(_provider, _name, _proto, _args, _fields)
+#undef TRACEPOINT_STRUCT
+#define TRACEPOINT_STRUCT(_provider, _name, _proto, _args, _fields, _assign)\
+static inline size_t __struct_get_size_full__##_provider##_##_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 */\
+ _fields \
+ return __event_len; \
+}
+
#undef TRACEPOINT_ENUM
#define TRACEPOINT_ENUM(_provider, _name, _type, _enum)
@@ -863,7 +896,7 @@ static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
#define __string_from_user(_item, _src)
#undef __struct
-#define __struct(_provider, _type, _item, _params) \
+#define __struct(_provider, _type, _item, _params...) \
__event_align = max_t(size_t, __event_align, \
__instruct_get_align__##_provider##_##_type(_params));
@@ -911,6 +944,11 @@ static inline size_t __instruct_get_align__##_provider##_##_name(_proto)\
return __struct_get_align__##_provider##_##_name(_args); \
}
+#undef TRACEPOINT_STRUCT
+#define TRACEPOINT_STRUCT(_provider, _name, _proto, _args, _fields, _assign)\
+ TRACEPOINT_STRUCT_RAW(_provider, _name, PARAMS(_proto), \
+ PARAMS(_args), PARAMS(_fields))
+
#undef TRACEPOINT_ENUM
#define TRACEPOINT_ENUM(_provider, _name, _type, _enum) \
static inline size_t __enum_get_align__##_provider##_##_name(void) \
@@ -972,7 +1010,7 @@ static inline size_t __event_get_align__##_name(_proto) \
__string(_item, _src)
#undef __struct
-#define __struct(_provider, _type, _item, _params) char _item;
+#define __struct(_provider, _type, _item, _params...) char _item;
#undef __field_enum
#define __field_enum(_provider, _type, _data_type, _item) \
@@ -985,6 +1023,9 @@ static inline size_t __event_get_align__##_name(_proto) \
#undef TP_STRUCT__entry
#define TP_STRUCT__entry(args...) args
+#undef TP_FIELDS
+#define TP_FIELDS(args...) args
+
#undef TP_VARIANTS
#define TP_VARIANTS(args...) args
@@ -997,6 +1038,12 @@ struct __variant_typemap__##_provider##_##_name { \
_variants \
};
+#undef TRACEPOINT_STRUCT
+#define TRACEPOINT_STRUCT(_provider, _name, _proto, _args, _fields, _assign)\
+struct __struct_typemap__##_provider##_##_name { \
+ _fields \
+};
+
#undef DECLARE_EVENT_CLASS
#define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
struct __event_typemap__##_name { \
@@ -1054,7 +1101,7 @@ __end_field_##_item:
__string(_item, _src)
#undef __struct
-#define __struct(_provider, _type, _item, _params) \
+#define __struct(_provider, _type, _item, _params...) \
goto __assign_##_item; \
__end_field_##_item:
@@ -1136,6 +1183,14 @@ __assign_##dest: \
#define tp_memcpy_struct(provider, name, dest, src) \
tp_memcpy_struct_gen(event_write, provider, name, dest, src)
+/* Still have to consume the array len of this field */
+#undef tp_assign_struct
+#define tp_assign_struct(provider, name, dest, src...) \
+__assign_##dest: \
+ __dynamic_len_idx++; \
+ __struct_assign__##provider##_##name(__ctxptr, __chan, src); \
+ goto __end_field_##dest;
+
/*
* This supposes that the variant field is at the same place (same src) for
* each variant, which is not the case most of the time.
@@ -1160,7 +1215,6 @@ __assign_##dest: \
__variant_assign__##provider##_##name(__ctxptr, __chan, enum_value, src);\
goto __end_field_##dest;
-
/*
* The string length including the final \0.
*/
@@ -1206,6 +1260,9 @@ __assign_##dest: \
#undef TP_STRUCT__entry
#define TP_STRUCT__entry(args...) args
+#undef TP_FIELDS
+#define TP_FIELDS(args...) args
+
#undef TP_fast_assign
#define TP_fast_assign(args...) args
@@ -1224,6 +1281,28 @@ case enum_##_value: \
__end_field_##_value: \
break;
+#undef TRACEPOINT_STRUCT
+#define TRACEPOINT_STRUCT(_provider, _name, _proto, _args, _fields, _assign)\
+static void __struct_assign__##_provider##_##_name(struct lib_ring_buffer_ctx *__ctxptr,\
+ struct lttng_channel *__chan, _proto) \
+{ \
+ struct __struct_typemap__##_provider##_##_name __typemap; \
+ size_t __struct_len, __struct_align; \
+ size_t __dynamic_len_idx = 0; \
+ size_t __dynamic_len[ARRAY_SIZE(__struct_fields___##_provider##_##_name)];\
+ \
+ if (0) { \
+ (void) __dynamic_len_idx; /* don't warn if unused */ \
+ (void) __struct_len; /* don't warn if unused */ \
+ (void) __struct_align; \
+ } \
+ __struct_len = __struct_get_size_full__##_provider##_##_name(__dynamic_len, _args);\
+ __struct_align = __struct_get_align__##_provider##_##_name(_args);\
+ _fields \
+ return; \
+ _assign \
+}
+
#undef TRACEPOINT_VARIANT
#define TRACEPOINT_VARIANT(_provider, _name, _proto, _args, _enum_provider, _enum_name, _earg, _variants, _assign)\
static void __variant_assign__##_provider##_##_name(struct lib_ring_buffer_ctx *__ctxptr,\
--
1.8.2.1
More information about the lttng-dev
mailing list