Add sequence and string support
authorMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Tue, 14 Dec 2010 14:06:24 +0000 (09:06 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Tue, 14 Dec 2010 14:06:24 +0000 (09:06 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
probes/lttng-events.h
probes/lttng-type-list.h
probes/lttng-types.c
probes/lttng-types.h

index b0152829966f8d290264acb94b0ee8706513c225..b4bac43c7dde81eb814cc43d63fe4ccf7ef1aaa7 100644 (file)
@@ -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)
 
 /*
                             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
index 38041b12262645f6c19dd6e9e7b5a7032870dec8..4782caf2483e65f60b9280ecea47455ecf038562 100644 (file)
@@ -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)
index e1a41374b6cc0af8609fbb2ed88c4a2f135e4ff7..5077920662d598cf237d8f625b05ff180c0a179e 100644 (file)
 
 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],
index 5f55ef6a8f57ab6db02f6cd1d5c07ce1aa6fef85..b588265cb966fa73509db72a46fddf651c04b39a 100644 (file)
@@ -7,13 +7,42 @@
 
 #include <lttng.h>
 
+#ifdef __KERNEL__
+# include <asm/byteorder.h>
+# 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 <endian.h>
+#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...)       \
This page took 0.031084 seconds and 4 git commands to generate.