From: Mathieu Desnoyers Date: Tue, 14 Dec 2010 14:06:24 +0000 (-0500) Subject: Add sequence and string support X-Git-Tag: v2.0-pre1~194 X-Git-Url: http://git.liburcu.org/?a=commitdiff_plain;h=1d12cebd26ab7c1ee4a23714ec71660c5352fbd4;p=lttng-modules.git Add sequence and string support Signed-off-by: Mathieu Desnoyers --- diff --git a/probes/lttng-events.h b/probes/lttng-events.h index b0152829..b4bac43c 100644 --- a/probes/lttng-events.h +++ b/probes/lttng-events.h @@ -4,15 +4,18 @@ * 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) /* @@ -40,59 +43,71 @@ PARAMS(print)); \ DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)); -/* Field types must be defined in lttng-types.h */ +/* Named field types must be defined in lttng-types.h */ + +/* TODO turn into a structure definition ? */ #undef __field -#define __field(type, item) type item; +#define __field(_type, _item) #_type " " #_item ";\n" #undef __field_ext -#define __field_ext(type, item, filter_type) type item; +#define __field_ext(_type, _item, _filter_type) #_type " " #_item ";\n" #undef __array -#define __array(type, item, len) \ - type { parent = array; length = len; elem_type = type; } item; - -/* TODO */ +#define __array(_type, _item, _len) \ + "type { parent = array; length = " #_len "; elem_type = " #_type "; } " #_item";\n" #undef __dynamic_array -#define __dynamic_array(type, item, len) u32 __data_loc_##item; +#define __dynamic_array(_type, _item, _len) \ + "type { parent = sequence; length_type = u32; elem_type = " #_type "; } " #_item ";\n" #undef __string -#define __string(item, src) __dynamic_array(char, item, -1) +#define __string(_item, _src) \ + "type { parent = string; encoding = UTF8; } " #_item ";\n" + +#undef TP_PROTO +#define TP_PROTO(args...) + +#undef TP_ARGS +#define TP_ARGS(args...) #undef TP_STRUCT__entry -#define TP_STRUCT__entry(args...) args +#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) \ - struct ftrace_raw_##name { \ - struct trace_entry ent; \ - tstruct \ - char __data[0]; \ - }; \ - \ - static struct ftrace_event_class event_class_##name; + tstruct #undef DEFINE_EVENT -#define DEFINE_EVENT(template, name, proto, args) \ - static struct ftrace_event_call __used \ - __attribute__((__aligned__(4))) event_##name +#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 ftrace. */ +/* 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)) \ +#undef DEFINE_TRACE_EVENT_METADATA +#define DEFINE_TRACE_EVENT_METADATA \ + const char trace_event_metadata_##TRACE_SYSTEM[] - - +//static DEFINE_TRACE_EVENT_METADATA = +static const char blah[] = #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) +; + +#if 0 /* * Stage 2 of the trace events. @@ -805,4 +820,4 @@ static inline void perf_test_probe_##call(void) \ #endif /* CONFIG_PERF_EVENTS */ #undef _TRACE_PROFILE_INIT - +#endif //0 diff --git a/probes/lttng-type-list.h b/probes/lttng-type-list.h index 38041b12..4782caf2 100644 --- a/probes/lttng-type-list.h +++ b/probes/lttng-type-list.h @@ -55,7 +55,13 @@ TRACE_EVENT_ENUM(hrtimer_mode, V(HRTIMER_MODE_PINNED), V(HRTIMER_MODE_ABS_PINNED), V(HRTIMER_MODE_REL_PINNED), - R(HRTIMER_MODE_UNDEFINED, 0x04, 0x100), /* Example (to remove) */ + R(HRTIMER_MODE_UNDEFINED, 0x04, 0x20), /* Example (to remove) */ ) TRACE_EVENT_TYPE(hrtimer_mode, enum, unsigned char) + +/* Tests */ + +TRACE_EVENT_TYPE(__be32, integer_ext, __BIG_ENDIAN) +TRACE_EVENT_TYPE(testseq, sequence, unsigned int, size_t) +TRACE_EVENT_TYPE(teststring, string, UTF8) diff --git a/probes/lttng-types.c b/probes/lttng-types.c index e1a41374..50779206 100644 --- a/probes/lttng-types.c +++ b/probes/lttng-types.c @@ -15,12 +15,23 @@ struct dentry *lttng_types_dentry; -#define ATYPE_ENTRY(name) [atype_##name] = #name +#undef ENTRY +#define ENTRY(name) [atype_##name] = #name const char * const astract_types[NR_ABSTRACT_TYPES] = { - ATYPE_ENTRY(integer), - ATYPE_ENTRY(enum), - ATYPE_ENTRY(array), + ENTRY(integer), + ENTRY(enum), + ENTRY(array), + ENTRY(sequence), + ENTRY(string), +}; + +#undef ENTRY +#define ENTRY(name) [lttng_encode_##name] = #name + +const char * const string_encodings[NR_STRING_ENCODINGS] = { + ENTRY(UTF8), + ENTRY(ASCII), }; #define STAGE_EXPORT_ENUMS @@ -60,12 +71,17 @@ static void print_event_type(struct seq_file *m, const struct lttng_type *type) "\tparent = %s;\n" "\tsize = %u;\n" "\tsigned = %u;\n" - "\talign = %u;\n" - "};\n", type->name, + "\talign = %u;\n", + type->name, astract_types[type->atype], type->u.integer.size, type->u.integer.signedness, type->u.integer.alignment); + if (type->u.integer.reverse_byte_order) + seq_printf(m, "\tbyte_order = %s;\n", + (__BYTE_ORDER == __LITTLE_ENDIAN) ? + "be" : "le"); + seq_printf(m, "};\n"); break; case atype_enum: seq_printf(m, "type %s {\n" @@ -89,6 +105,24 @@ static void print_event_type(struct seq_file *m, const struct lttng_type *type) type->u.array.elem_type, type->u.array.length); break; + case atype_sequence: + seq_printf(m, "type %s {\n" + "\tparent = %s;\n" + "\telem_type = %s;\n" + "\tlength_type = %s;\n" + "};\n", type->name, + astract_types[type->atype], + type->u.sequence.elem_type, + type->u.sequence.length_type); + break; + case atype_string: + seq_printf(m, "type %s {\n" + "\tparent = %s;\n" + "\tencoding = %s;\n" + "};\n", type->name, + astract_types[type->atype], + string_encodings[type->u.string.encoding]); + break; default: seq_printf(m, "<<< unknown abstract type %s for type %s >>>\n", astract_types[type->atype], diff --git a/probes/lttng-types.h b/probes/lttng-types.h index 5f55ef6a..b588265c 100644 --- a/probes/lttng-types.h +++ b/probes/lttng-types.h @@ -7,13 +7,42 @@ #include +#ifdef __KERNEL__ +# include +# ifdef __BIG_ENDIAN +# define __BYTE_ORDER __BIG_ENDIAN +# elif defined(__LITTLE_ENDIAN) +# define __BYTE_ORDER __LITTLE_ENDIAN +# else +# error "unknown endianness" +# endif +#ifndef __BIG_ENDIAN +# define __BIG_ENDIAN 4321 +#endif +#ifndef __LITTLE_ENDIAN +# define __LITTLE_ENDIAN 1234 +#endif +#else +# include +#endif + +/* Update the astract_types name table in lttng-types.c along with this enum */ enum abstract_types { atype_integer, atype_enum, atype_array, + atype_sequence, + atype_string, NR_ABSTRACT_TYPES, }; +/* Update the string_encodings name table in lttng-types.c along with this enum */ +enum lttng_string_encodings { + lttng_encode_UTF8 = 0, + lttng_encode_ASCII = 1, + NR_STRING_ENCODINGS, +}; + struct lttng_enum_entry { unsigned long long start, end; /* start and end are inclusive */ const char *string; @@ -32,6 +61,7 @@ struct lttng_type { unsigned int size; /* in bits */ unsigned short alignment; /* in bits */ unsigned int signedness:1; + unsigned int reverse_byte_order:1; } integer; struct { const char *parent_type; @@ -41,6 +71,13 @@ struct lttng_type { const char *elem_type; unsigned int length; /* num. elems. */ } array; + struct { + const char *elem_type; + const char *length_type; + } sequence; + struct { + enum lttng_string_encodings encoding; + } string; } u; } __attribute__((packed)); @@ -76,16 +113,21 @@ struct lttng_type { #ifdef STAGE_EXPORT_TYPES -#undef TRACE_EVENT_TYPE___integer -#define TRACE_EVENT_TYPE___integer(_name, _unused) \ +#undef TRACE_EVENT_TYPE___integer_ext +#define TRACE_EVENT_TYPE___integer_ext(_name, _byte_order) \ { \ .atype = atype_integer, \ .name = #_name, \ .u.integer.size = sizeof(_name) * 8, \ .u.integer.alignment = __alignof__(_name) * 8,\ .u.integer.signedness = is_signed_type(_name),\ + .u.integer.reverse_byte_order = ((_byte_order) != __BYTE_ORDER),\ }, +#undef TRACE_EVENT_TYPE___integer +#define TRACE_EVENT_TYPE___integer(_name, _unused) \ + TRACE_EVENT_TYPE___integer_ext(_name, __BYTE_ORDER) + #undef TRACE_EVENT_TYPE___enum #define TRACE_EVENT_TYPE___enum(_name, _parent_type) \ { \ @@ -105,6 +147,24 @@ struct lttng_type { .u.array.length = _length, \ }, +#undef TRACE_EVENT_TYPE___sequence +#define TRACE_EVENT_TYPE___sequence(_name, _elem_type, _length_type) \ + { \ + .atype = atype_sequence, \ + .name = #_name, \ + .u.sequence.elem_type = #_elem_type, \ + .u.sequence.length_type = #_length_type, \ + }, + +#undef TRACE_EVENT_TYPE___string +#define TRACE_EVENT_TYPE___string(_name, _encoding) \ + { \ + .atype = atype_string, \ + .name = #_name, \ + .u.string.encoding = lttng_encode_##_encoding,\ + }, + + /* Local declaration */ #undef TRACE_EVENT_TYPE #define TRACE_EVENT_TYPE(_name, _abstract_type, args...) \