From: pmf Date: Wed, 10 Oct 2007 22:13:21 +0000 (+0000) Subject: rename markers*.{c,h} -> marker*.{c,h} X-Git-Tag: v0.12.20~850 X-Git-Url: http://git.liburcu.org/?a=commitdiff_plain;h=bb38a2907d1f182e0fdf443e48da94e3707d7f97;p=lttv.git rename markers*.{c,h} -> marker*.{c,h} git-svn-id: http://ltt.polymtl.ca/svn@2639 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/ltt/branches/poly/ltt/Makefile.am b/ltt/branches/poly/ltt/Makefile.am index df6f1bec..c040f227 100644 --- a/ltt/branches/poly/ltt/Makefile.am +++ b/ltt/branches/poly/ltt/Makefile.am @@ -10,14 +10,15 @@ AM_CFLAGS = $(GLIB_CFLAGS) LIBS += $(GLIB_LIBS) lib_LTLIBRARIES = liblttvtraceread.la -liblttvtraceread_la_SOURCES = tracefile.c markers.c event.c +liblttvtraceread_la_SOURCES = tracefile.c marker.c event.c noinst_HEADERS = ltt-private.h #event.c parser.c type.c #parser.h lttinclude_HEADERS = \ compiler.h\ - markers.h\ + marker.h\ + marker-field.h\ ltt.h\ time.h\ trace.h\ diff --git a/ltt/branches/poly/ltt/event.h b/ltt/branches/poly/ltt/event.h index 75b2e299..bc9452cf 100644 --- a/ltt/branches/poly/ltt/event.h +++ b/ltt/branches/poly/ltt/event.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include /* * Structure LttEvent and LttEventPosition must begin with the _exact_ same diff --git a/ltt/branches/poly/ltt/ltt-private.h b/ltt/branches/poly/ltt/ltt-private.h index c37fd0b0..73700c36 100644 --- a/ltt/branches/poly/ltt/ltt-private.h +++ b/ltt/branches/poly/ltt/ltt-private.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #ifndef max diff --git a/ltt/branches/poly/ltt/marker-field.h b/ltt/branches/poly/ltt/marker-field.h new file mode 100644 index 00000000..5cc87794 --- /dev/null +++ b/ltt/branches/poly/ltt/marker-field.h @@ -0,0 +1,47 @@ +#ifndef _LTT_MARKERS_FIELD_H +#define _LTT_MARKERS_FIELD_H + +/* + * Marker field support header. + * + * Mathieu Desnoyers, August 2007 + * License: LGPL. + */ + +#include + +enum ltt_type { + LTT_TYPE_SIGNED_INT, + LTT_TYPE_UNSIGNED_INT, + LTT_TYPE_STRING, + LTT_TYPE_COMPACT, + LTT_TYPE_NONE, +}; + +struct marker_field { + GQuark name; + enum ltt_type type; + unsigned long offset; /* offset in the event data */ + unsigned long size; + unsigned long alignment; + unsigned long attributes; + int static_offset; /* boolean - private - is the field offset statically + * known with the preceding types ? */ +}; + +static inline GQuark marker_field_get_name(struct marker_field *field) +{ + return field->name; +} + +static inline enum ltt_type marker_field_get_type(struct marker_field *field) +{ + return field->type; +} + +static inline unsigned long marker_field_get_size(struct marker_field *field) +{ + return field->size; +} + +#endif //_LTT_MARKERS_FIELD_H diff --git a/ltt/branches/poly/ltt/marker.c b/ltt/branches/poly/ltt/marker.c new file mode 100644 index 00000000..48b1c9bc --- /dev/null +++ b/ltt/branches/poly/ltt/marker.c @@ -0,0 +1,450 @@ +/* + * Marker support code. + * + * Mathieu Desnoyers, August 2007 + * License: LGPL. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define DEFAULT_MARKERS_NUM 100 +#define DEFAULT_FIELDS_NUM 1 +#define MAX_NAME_LEN 1024 + +static inline const char *parse_trace_type(struct marker_info *info, + const char *fmt, + char *trace_size, enum ltt_type *trace_type, + unsigned long *attributes) +{ + int qualifier; /* 'h', 'l', or 'L' for integer fields */ + /* 'z' support added 23/7/1999 S.H. */ + /* 'z' changed to 'Z' --davidm 1/25/99 */ + /* 't' added for ptrdiff_t */ + + /* parse attributes. */ + repeat: + switch (*fmt) { + case 'b': + *attributes |= LTT_ATTRIBUTE_COMPACT; + ++fmt; + goto repeat; + case 'n': + *attributes |= LTT_ATTRIBUTE_NETWORK_BYTE_ORDER; + ++fmt; + goto repeat; + } + + /* get the conversion qualifier */ + qualifier = -1; + if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || + *fmt =='Z' || *fmt == 'z' || *fmt == 't' || + *fmt == 'S' || *fmt == '1' || *fmt == '2' || + *fmt == '4' || *fmt == 8) { + qualifier = *fmt; + ++fmt; + if (qualifier == 'l' && *fmt == 'l') { + qualifier = 'L'; + ++fmt; + } + } + + switch (*fmt) { + case 'c': + *trace_type = LTT_TYPE_UNSIGNED_INT; + *trace_size = sizeof(char); + goto parse_end; + case 's': + *trace_type = LTT_TYPE_STRING; + goto parse_end; + case 'p': + *trace_type = LTT_TYPE_UNSIGNED_INT; + *trace_size = info->pointer_size; + goto parse_end; + case 'd': + case 'i': + *trace_type = LTT_TYPE_SIGNED_INT; + break; + case 'o': + case 'u': + case 'x': + case 'X': + *trace_type = LTT_TYPE_UNSIGNED_INT; + break; + default: + if (!*fmt) + --fmt; + goto parse_end; + } + switch (qualifier) { + case 'L': + *trace_size = sizeof(long long); + break; + case 'l': + *trace_size = info->long_size; + break; + case 'Z': + case 'z': + *trace_size = info->size_t_size; + break; + case 't': + *trace_size = info->pointer_size; + break; + case 'h': + *trace_size = sizeof(short); + break; + case '1': + *trace_size = sizeof(uint8_t); + break; + case '2': + *trace_size = sizeof(guint16); + break; + case '4': + *trace_size = sizeof(uint32_t); + break; + case '8': + *trace_size = sizeof(uint64_t); + break; + default: + *trace_size = info->int_size; + } + +parse_end: + return fmt; +} + +/* + * Restrictions: + * Field width and precision are *not* supported. + * %n not supported. + */ +__attribute__((no_instrument_function)) +static inline const char *parse_c_type(struct marker_info *info, + const char *fmt, + char *c_size, enum ltt_type *c_type) +{ + int qualifier; /* 'h', 'l', or 'L' for integer fields */ + /* 'z' support added 23/7/1999 S.H. */ + /* 'z' changed to 'Z' --davidm 1/25/99 */ + /* 't' added for ptrdiff_t */ + + /* process flags : ignore standard print formats for now. */ + repeat: + switch (*fmt) { + case '-': + case '+': + case ' ': + case '#': + case '0': + ++fmt; + goto repeat; + } + + /* get the conversion qualifier */ + qualifier = -1; + if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || + *fmt =='Z' || *fmt == 'z' || *fmt == 't' || + *fmt == 'S') { + qualifier = *fmt; + ++fmt; + if (qualifier == 'l' && *fmt == 'l') { + qualifier = 'L'; + ++fmt; + } + } + + switch (*fmt) { + case 'c': + *c_type = LTT_TYPE_UNSIGNED_INT; + *c_size = sizeof(unsigned char); + goto parse_end; + case 's': + *c_type = LTT_TYPE_STRING; + goto parse_end; + case 'p': + *c_type = LTT_TYPE_UNSIGNED_INT; + *c_size = info->pointer_size; + goto parse_end; + case 'd': + case 'i': + *c_type = LTT_TYPE_SIGNED_INT; + break; + case 'o': + case 'u': + case 'x': + case 'X': + *c_type = LTT_TYPE_UNSIGNED_INT; + break; + default: + if (!*fmt) + --fmt; + goto parse_end; + } + switch (qualifier) { + case 'L': + *c_size = sizeof(long long); + break; + case 'l': + *c_size = info->long_size; + break; + case 'Z': + case 'z': + *c_size = info->size_t_size; + break; + case 't': + *c_size = info->pointer_size; + break; + case 'h': + *c_size = sizeof(short); + break; + default: + *c_size = info->int_size; + } + +parse_end: + return fmt; +} + +static inline long add_type(struct marker_info *info, + long offset, const char *name, + char trace_size, enum ltt_type trace_type, + char c_size, enum ltt_type c_type, unsigned long attributes, + unsigned int field_count) +{ + struct marker_field *field; + char tmpname[MAX_NAME_LEN]; + + info->fields = g_array_set_size(info->fields, info->fields->len+1); + field = &g_array_index(info->fields, struct marker_field, + info->fields->len-1); + if (name) + field->name = g_quark_from_string(name); + else { + snprintf(tmpname, MAX_NAME_LEN-1, "field %u", field_count); + field->name = g_quark_from_string(tmpname); + } + field->type = trace_type; + + switch (trace_type) { + case LTT_TYPE_SIGNED_INT: + case LTT_TYPE_UNSIGNED_INT: + field->size = trace_size; + field->alignment = trace_size; + field->attributes = attributes; + if (offset == -1) { + field->offset = -1; + field->static_offset = 0; + return -1; + } else { + field->offset = offset + ltt_align(offset, field->alignment, + info->alignment); + field->static_offset = 1; + return field->offset + trace_size; + } + case LTT_TYPE_STRING: + field->offset = offset; + field->size = 0; /* Variable length, size is 0 */ + field->alignment = 1; + if (offset == -1) + field->static_offset = 0; + else + field->static_offset = 1; + return -1; + default: + g_error("Unexpected type"); //FIXME: compact type + return 0; + } +} + +long marker_update_fields_offsets(struct marker_info *info, const char *data) +{ + struct marker_field *field; + unsigned int i; + long offset = 0; + + for (i = 0; i < info->fields->len; i++) { + field = &g_array_index(info->fields, struct marker_field, i); + + if (field->static_offset) + continue; + + switch (field->type) { + case LTT_TYPE_SIGNED_INT: + case LTT_TYPE_UNSIGNED_INT: + field->offset = offset + ltt_align(offset, field->alignment, + info->alignment); + offset = field->offset + field->size; + break; + case LTT_TYPE_STRING: + field->offset = offset; + offset = offset + strlen(&data[offset]) + 1; + // not aligning on pointer size, breaking genevent backward compatibility. + break; + default: + g_error("Unexpected type"); //FIXME: compact type + return -1; + } + } + return offset; +} + +static void format_parse(const char *fmt, struct marker_info *info) +{ + char trace_size = 0, c_size = 0; /* + * 0 (unset), 1, 2, 4, 8 bytes. + */ + enum ltt_type trace_type = LTT_TYPE_NONE, c_type = LTT_TYPE_NONE; + unsigned long attributes = 0; + long offset = 0; + const char *name_begin = NULL, *name_end = NULL; + char *name = NULL; + unsigned int field_count = 1; + + for (; *fmt ; ++fmt) { + switch (*fmt) { + case '#': + /* tracetypes (#) */ + ++fmt; /* skip first '#' */ + if (*fmt == '#') /* Escaped ## */ + break; + attributes = 0; + fmt = parse_trace_type(info, fmt, &trace_size, &trace_type, + &attributes); + break; + case '%': + /* c types (%) */ + ++fmt; /* skip first '%' */ + if (*fmt == '%') /* Escaped %% */ + break; + fmt = parse_c_type(info, fmt, &c_size, &c_type); + /* + * Output c types if no trace types has been + * specified. + */ + if (!trace_size) + trace_size = c_size; + if (trace_type == LTT_TYPE_NONE) + trace_type = c_type; + if (c_type == LTT_TYPE_STRING) + trace_type = LTT_TYPE_STRING; + /* perform trace write */ + offset = add_type(info, offset, name, trace_size, + trace_type, c_size, c_type, attributes, field_count++); + trace_size = c_size = 0; + trace_type = c_size = LTT_TYPE_NONE; + attributes = 0; + name_begin = NULL; + if (name) { + g_free(name); + name = NULL; + } + break; + case ' ': + if (!name_end) { + name_end = fmt; + if (name) + g_free(name); + name = g_new(char, name_end - name_begin + 1); + memcpy(name, name_begin, name_end - name_begin); + name[name_end - name_begin] = '\0'; + } + break; /* Skip white spaces */ + default: + if (!name) { + name_begin = fmt; + name_end = NULL; + } + } + } + info->size = offset; + if (name) + g_free(name); +} + +int marker_parse_format(const char *format, struct marker_info *info) +{ + if (info->fields) + g_array_free(info->fields, TRUE); + info->fields = g_array_sized_new(FALSE, TRUE, + sizeof(struct marker_field), DEFAULT_FIELDS_NUM); + format_parse(format, info); +} + +int marker_format_event(LttTrace *trace, GQuark name, const char *format) +{ + struct marker_info *info; + + info = g_hash_table_lookup(trace->markers_hash, (gconstpointer)name); + if (!info) + g_error("Got marker format %s, but marker name %s has no ID yet. " + "Kernel issue.", + format, name); + for (; info != NULL; info = info->next) { + if (info->format) + g_free(info->format); + info->format = g_new(char, strlen(format)+1); + strcpy(info->format, format); + if (marker_parse_format(format, info)) + g_error("Error parsing marker format %s for marker %s", format, + g_quark_to_string(name)); + } +} + +int marker_id_event(LttTrace *trace, GQuark name, guint16 id, + uint8_t int_size, uint8_t long_size, uint8_t pointer_size, + uint8_t size_t_size, uint8_t alignment) +{ + struct marker_info *info, *head; + + if (trace->markers->len < id) + trace->markers = g_array_set_size(trace->markers, id+1); + info = &g_array_index(trace->markers, struct marker_info, id); + info->name = name; + info->int_size = int_size; + info->long_size = long_size; + info->pointer_size = pointer_size; + info->size_t_size = size_t_size; + info->alignment = alignment; + info->next = NULL; + head = g_hash_table_lookup(trace->markers_hash, (gconstpointer)name); + if (!head) + g_hash_table_insert(trace->markers_hash, (gpointer)name, info); + else { + g_hash_table_replace(trace->markers_hash, (gpointer)name, info); + info->next = head; + } +} + +int allocate_marker_data(LttTrace *trace) +{ + /* Init array to 0 */ + trace->markers = g_array_sized_new(FALSE, TRUE, + sizeof(struct marker_info), DEFAULT_MARKERS_NUM); + if (!trace->markers) + return -ENOMEM; + trace->markers_hash = g_hash_table_new(g_direct_hash, g_direct_equal); + if (!trace->markers_hash) + return -ENOMEM; + return 0; +} + +void destroy_marker_data(LttTrace *trace) +{ + unsigned int i; + struct marker_info *info; + + for (i=0; imarkers->len; i++) { + info = &g_array_index(trace->markers, struct marker_info, i); + if (info->format) + g_free(info->format); + if (info->fields) + g_array_free(info->fields, TRUE); + } + g_array_free(trace->markers, TRUE); + g_hash_table_destroy(trace->markers_hash); +} diff --git a/ltt/branches/poly/ltt/marker.h b/ltt/branches/poly/ltt/marker.h new file mode 100644 index 00000000..fc134356 --- /dev/null +++ b/ltt/branches/poly/ltt/marker.h @@ -0,0 +1,97 @@ +#ifndef _LTT_MARKERS_H +#define _LTT_MARKERS_H + +/* + * Marker support header. + * + * Mathieu Desnoyers, August 2007 + * License: LGPL. + */ + +#include +#include +#include +#include +#include + +#define LTT_ATTRIBUTE_COMPACT (1<<0) +#define LTT_ATTRIBUTE_NETWORK_BYTE_ORDER (1<<1) + +/* static ids 0-7 reserved for internal use. */ +#define MARKER_CORE_IDS 8 +/* dynamic ids 8-127 reserved for compact events. */ +#define MARKER_COMPACT_IDS 128 + +struct marker_info; + +struct marker_info { + GQuark name; + char *format; + long size; /* size if known statically, else -1 */ + GArray *fields; /* Array of struct marker_field */ + guint8 int_size, long_size, pointer_size, size_t_size, alignment; + struct marker_info *next; /* Linked list of markers with the same name */ +}; + +enum marker_id { + MARKER_ID_SET_MARKER_ID = 0, /* Static IDs available (range 0-7) */ + MARKER_ID_SET_MARKER_FORMAT, + MARKER_ID_HEARTBEAT_32, + MARKER_ID_HEARTBEAT_64, + MARKER_ID_COMPACT, /* Compact IDs (range: 8-127) */ + MARKER_ID_DYNAMIC, /* Dynamic IDs (range: 128-65535) */ +}; + +static inline guint16 marker_get_id_from_info(LttTrace *trace, + struct marker_info *info) +{ + return ((unsigned long)info - (unsigned long)trace->markers->data) + / sizeof(struct marker_info); +} + +static inline struct marker_info *marker_get_info_from_id(LttTrace *trace, + guint16 id) +{ + if (unlikely(trace->markers->len < id)) + return NULL; + return &g_array_index(trace->markers, struct marker_info, id); +} + +/* + * Returns the head of the marker info list for that name. + */ +static inline struct marker_info *marker_get_info_from_name(LttTrace *trace, + GQuark name) +{ + return g_hash_table_lookup(trace->markers_hash, (gconstpointer)name); +} + +static inline struct marker_field *marker_get_field(struct marker_info *info, + guint i) +{ + return &g_array_index(info->fields, struct marker_field, i); +} + +static inline unsigned int marker_get_num_fields(struct marker_info *info) +{ + return info->fields->len; +} + +/* + * for_each_marker_field - iterate over fields of a marker + * @field: struct marker_field * to use as iterator + * @info: marker info pointer + */ +#define for_each_marker_field(field, info) \ + for (field = marker_get_field(info, 0); \ + field != marker_get_field(info, marker_get_num_fields(info)); \ + field++) + +int marker_format_event(LttTrace *trace, GQuark name, const char *format); +int marker_id_event(LttTrace *trace, GQuark name, guint16 id, + uint8_t int_size, uint8_t long_size, uint8_t pointer_size, + uint8_t size_t_size, uint8_t alignment); +int allocate_marker_data(LttTrace *trace); +void destroy_marker_data(LttTrace *trace); + +#endif //_LTT_MARKERS_H diff --git a/ltt/branches/poly/ltt/markers-field.h b/ltt/branches/poly/ltt/markers-field.h deleted file mode 100644 index 5cc87794..00000000 --- a/ltt/branches/poly/ltt/markers-field.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef _LTT_MARKERS_FIELD_H -#define _LTT_MARKERS_FIELD_H - -/* - * Marker field support header. - * - * Mathieu Desnoyers, August 2007 - * License: LGPL. - */ - -#include - -enum ltt_type { - LTT_TYPE_SIGNED_INT, - LTT_TYPE_UNSIGNED_INT, - LTT_TYPE_STRING, - LTT_TYPE_COMPACT, - LTT_TYPE_NONE, -}; - -struct marker_field { - GQuark name; - enum ltt_type type; - unsigned long offset; /* offset in the event data */ - unsigned long size; - unsigned long alignment; - unsigned long attributes; - int static_offset; /* boolean - private - is the field offset statically - * known with the preceding types ? */ -}; - -static inline GQuark marker_field_get_name(struct marker_field *field) -{ - return field->name; -} - -static inline enum ltt_type marker_field_get_type(struct marker_field *field) -{ - return field->type; -} - -static inline unsigned long marker_field_get_size(struct marker_field *field) -{ - return field->size; -} - -#endif //_LTT_MARKERS_FIELD_H diff --git a/ltt/branches/poly/ltt/markers.c b/ltt/branches/poly/ltt/markers.c deleted file mode 100644 index 6be38228..00000000 --- a/ltt/branches/poly/ltt/markers.c +++ /dev/null @@ -1,450 +0,0 @@ -/* - * Marker support code. - * - * Mathieu Desnoyers, August 2007 - * License: LGPL. - */ - -#include -#include -#include -#include -#include -#include -#include - -#define DEFAULT_MARKERS_NUM 100 -#define DEFAULT_FIELDS_NUM 1 -#define MAX_NAME_LEN 1024 - -static inline const char *parse_trace_type(struct marker_info *info, - const char *fmt, - char *trace_size, enum ltt_type *trace_type, - unsigned long *attributes) -{ - int qualifier; /* 'h', 'l', or 'L' for integer fields */ - /* 'z' support added 23/7/1999 S.H. */ - /* 'z' changed to 'Z' --davidm 1/25/99 */ - /* 't' added for ptrdiff_t */ - - /* parse attributes. */ - repeat: - switch (*fmt) { - case 'b': - *attributes |= LTT_ATTRIBUTE_COMPACT; - ++fmt; - goto repeat; - case 'n': - *attributes |= LTT_ATTRIBUTE_NETWORK_BYTE_ORDER; - ++fmt; - goto repeat; - } - - /* get the conversion qualifier */ - qualifier = -1; - if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || - *fmt =='Z' || *fmt == 'z' || *fmt == 't' || - *fmt == 'S' || *fmt == '1' || *fmt == '2' || - *fmt == '4' || *fmt == 8) { - qualifier = *fmt; - ++fmt; - if (qualifier == 'l' && *fmt == 'l') { - qualifier = 'L'; - ++fmt; - } - } - - switch (*fmt) { - case 'c': - *trace_type = LTT_TYPE_UNSIGNED_INT; - *trace_size = sizeof(char); - goto parse_end; - case 's': - *trace_type = LTT_TYPE_STRING; - goto parse_end; - case 'p': - *trace_type = LTT_TYPE_UNSIGNED_INT; - *trace_size = info->pointer_size; - goto parse_end; - case 'd': - case 'i': - *trace_type = LTT_TYPE_SIGNED_INT; - break; - case 'o': - case 'u': - case 'x': - case 'X': - *trace_type = LTT_TYPE_UNSIGNED_INT; - break; - default: - if (!*fmt) - --fmt; - goto parse_end; - } - switch (qualifier) { - case 'L': - *trace_size = sizeof(long long); - break; - case 'l': - *trace_size = info->long_size; - break; - case 'Z': - case 'z': - *trace_size = info->size_t_size; - break; - case 't': - *trace_size = info->pointer_size; - break; - case 'h': - *trace_size = sizeof(short); - break; - case '1': - *trace_size = sizeof(uint8_t); - break; - case '2': - *trace_size = sizeof(guint16); - break; - case '4': - *trace_size = sizeof(uint32_t); - break; - case '8': - *trace_size = sizeof(uint64_t); - break; - default: - *trace_size = info->int_size; - } - -parse_end: - return fmt; -} - -/* - * Restrictions: - * Field width and precision are *not* supported. - * %n not supported. - */ -__attribute__((no_instrument_function)) -static inline const char *parse_c_type(struct marker_info *info, - const char *fmt, - char *c_size, enum ltt_type *c_type) -{ - int qualifier; /* 'h', 'l', or 'L' for integer fields */ - /* 'z' support added 23/7/1999 S.H. */ - /* 'z' changed to 'Z' --davidm 1/25/99 */ - /* 't' added for ptrdiff_t */ - - /* process flags : ignore standard print formats for now. */ - repeat: - switch (*fmt) { - case '-': - case '+': - case ' ': - case '#': - case '0': - ++fmt; - goto repeat; - } - - /* get the conversion qualifier */ - qualifier = -1; - if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || - *fmt =='Z' || *fmt == 'z' || *fmt == 't' || - *fmt == 'S') { - qualifier = *fmt; - ++fmt; - if (qualifier == 'l' && *fmt == 'l') { - qualifier = 'L'; - ++fmt; - } - } - - switch (*fmt) { - case 'c': - *c_type = LTT_TYPE_UNSIGNED_INT; - *c_size = sizeof(unsigned char); - goto parse_end; - case 's': - *c_type = LTT_TYPE_STRING; - goto parse_end; - case 'p': - *c_type = LTT_TYPE_UNSIGNED_INT; - *c_size = info->pointer_size; - goto parse_end; - case 'd': - case 'i': - *c_type = LTT_TYPE_SIGNED_INT; - break; - case 'o': - case 'u': - case 'x': - case 'X': - *c_type = LTT_TYPE_UNSIGNED_INT; - break; - default: - if (!*fmt) - --fmt; - goto parse_end; - } - switch (qualifier) { - case 'L': - *c_size = sizeof(long long); - break; - case 'l': - *c_size = info->long_size; - break; - case 'Z': - case 'z': - *c_size = info->size_t_size; - break; - case 't': - *c_size = info->pointer_size; - break; - case 'h': - *c_size = sizeof(short); - break; - default: - *c_size = info->int_size; - } - -parse_end: - return fmt; -} - -static inline long add_type(struct marker_info *info, - long offset, const char *name, - char trace_size, enum ltt_type trace_type, - char c_size, enum ltt_type c_type, unsigned long attributes, - unsigned int field_count) -{ - struct marker_field *field; - char tmpname[MAX_NAME_LEN]; - - info->fields = g_array_set_size(info->fields, info->fields->len+1); - field = &g_array_index(info->fields, struct marker_field, - info->fields->len-1); - if (name) - field->name = g_quark_from_string(name); - else { - snprintf(tmpname, MAX_NAME_LEN-1, "field %u", field_count); - field->name = g_quark_from_string(tmpname); - } - field->type = trace_type; - - switch (trace_type) { - case LTT_TYPE_SIGNED_INT: - case LTT_TYPE_UNSIGNED_INT: - field->size = trace_size; - field->alignment = trace_size; - field->attributes = attributes; - if (offset == -1) { - field->offset = -1; - field->static_offset = 0; - return -1; - } else { - field->offset = offset + ltt_align(offset, field->alignment, - info->alignment); - field->static_offset = 1; - return field->offset + trace_size; - } - case LTT_TYPE_STRING: - field->offset = offset; - field->size = 0; /* Variable length, size is 0 */ - field->alignment = 1; - if (offset == -1) - field->static_offset = 0; - else - field->static_offset = 1; - return -1; - default: - g_error("Unexpected type"); //FIXME: compact type - return 0; - } -} - -long marker_update_fields_offsets(struct marker_info *info, const char *data) -{ - struct marker_field *field; - unsigned int i; - long offset = 0; - - for (i = 0; i < info->fields->len; i++) { - field = &g_array_index(info->fields, struct marker_field, i); - - if (field->static_offset) - continue; - - switch (field->type) { - case LTT_TYPE_SIGNED_INT: - case LTT_TYPE_UNSIGNED_INT: - field->offset = offset + ltt_align(offset, field->alignment, - info->alignment); - offset = field->offset + field->size; - break; - case LTT_TYPE_STRING: - field->offset = offset; - offset = offset + strlen(&data[offset]) + 1; - // not aligning on pointer size, breaking genevent backward compatibility. - break; - default: - g_error("Unexpected type"); //FIXME: compact type - return -1; - } - } - return offset; -} - -static void format_parse(const char *fmt, struct marker_info *info) -{ - char trace_size = 0, c_size = 0; /* - * 0 (unset), 1, 2, 4, 8 bytes. - */ - enum ltt_type trace_type = LTT_TYPE_NONE, c_type = LTT_TYPE_NONE; - unsigned long attributes = 0; - long offset = 0; - const char *name_begin = NULL, *name_end = NULL; - char *name = NULL; - unsigned int field_count = 1; - - for (; *fmt ; ++fmt) { - switch (*fmt) { - case '#': - /* tracetypes (#) */ - ++fmt; /* skip first '#' */ - if (*fmt == '#') /* Escaped ## */ - break; - attributes = 0; - fmt = parse_trace_type(info, fmt, &trace_size, &trace_type, - &attributes); - break; - case '%': - /* c types (%) */ - ++fmt; /* skip first '%' */ - if (*fmt == '%') /* Escaped %% */ - break; - fmt = parse_c_type(info, fmt, &c_size, &c_type); - /* - * Output c types if no trace types has been - * specified. - */ - if (!trace_size) - trace_size = c_size; - if (trace_type == LTT_TYPE_NONE) - trace_type = c_type; - if (c_type == LTT_TYPE_STRING) - trace_type = LTT_TYPE_STRING; - /* perform trace write */ - offset = add_type(info, offset, name, trace_size, - trace_type, c_size, c_type, attributes, field_count++); - trace_size = c_size = 0; - trace_type = c_size = LTT_TYPE_NONE; - attributes = 0; - name_begin = NULL; - if (name) { - g_free(name); - name = NULL; - } - break; - case ' ': - if (!name_end) { - name_end = fmt; - if (name) - g_free(name); - name = g_new(char, name_end - name_begin + 1); - memcpy(name, name_begin, name_end - name_begin); - name[name_end - name_begin] = '\0'; - } - break; /* Skip white spaces */ - default: - if (!name) { - name_begin = fmt; - name_end = NULL; - } - } - } - info->size = offset; - if (name) - g_free(name); -} - -int marker_parse_format(const char *format, struct marker_info *info) -{ - if (info->fields) - g_array_free(info->fields, TRUE); - info->fields = g_array_sized_new(FALSE, TRUE, - sizeof(struct marker_field), DEFAULT_FIELDS_NUM); - format_parse(format, info); -} - -int marker_format_event(LttTrace *trace, GQuark name, const char *format) -{ - struct marker_info *info; - - info = g_hash_table_lookup(trace->markers_hash, (gconstpointer)name); - if (!info) - g_error("Got marker format %s, but marker name %s has no ID yet. " - "Kernel issue.", - format, name); - for (; info != NULL; info = info->next) { - if (info->format) - g_free(info->format); - info->format = g_new(char, strlen(format)+1); - strcpy(info->format, format); - if (marker_parse_format(format, info)) - g_error("Error parsing marker format %s for marker %s", format, - g_quark_to_string(name)); - } -} - -int marker_id_event(LttTrace *trace, GQuark name, guint16 id, - uint8_t int_size, uint8_t long_size, uint8_t pointer_size, - uint8_t size_t_size, uint8_t alignment) -{ - struct marker_info *info, *head; - - if (trace->markers->len < id) - trace->markers = g_array_set_size(trace->markers, id+1); - info = &g_array_index(trace->markers, struct marker_info, id); - info->name = name; - info->int_size = int_size; - info->long_size = long_size; - info->pointer_size = pointer_size; - info->size_t_size = size_t_size; - info->alignment = alignment; - info->next = NULL; - head = g_hash_table_lookup(trace->markers_hash, (gconstpointer)name); - if (!head) - g_hash_table_insert(trace->markers_hash, (gpointer)name, info); - else { - g_hash_table_replace(trace->markers_hash, (gpointer)name, info); - info->next = head; - } -} - -int allocate_marker_data(LttTrace *trace) -{ - /* Init array to 0 */ - trace->markers = g_array_sized_new(FALSE, TRUE, - sizeof(struct marker_info), DEFAULT_MARKERS_NUM); - if (!trace->markers) - return -ENOMEM; - trace->markers_hash = g_hash_table_new(g_direct_hash, g_direct_equal); - if (!trace->markers_hash) - return -ENOMEM; - return 0; -} - -void destroy_marker_data(LttTrace *trace) -{ - unsigned int i; - struct marker_info *info; - - for (i=0; imarkers->len; i++) { - info = &g_array_index(trace->markers, struct marker_info, i); - if (info->format) - g_free(info->format); - if (info->fields) - g_array_free(info->fields, TRUE); - } - g_array_free(trace->markers, TRUE); - g_hash_table_destroy(trace->markers_hash); -} diff --git a/ltt/branches/poly/ltt/markers.h b/ltt/branches/poly/ltt/markers.h deleted file mode 100644 index 48bbd5bd..00000000 --- a/ltt/branches/poly/ltt/markers.h +++ /dev/null @@ -1,97 +0,0 @@ -#ifndef _LTT_MARKERS_H -#define _LTT_MARKERS_H - -/* - * Marker support header. - * - * Mathieu Desnoyers, August 2007 - * License: LGPL. - */ - -#include -#include -#include -#include -#include - -#define LTT_ATTRIBUTE_COMPACT (1<<0) -#define LTT_ATTRIBUTE_NETWORK_BYTE_ORDER (1<<1) - -/* static ids 0-7 reserved for internal use. */ -#define MARKER_CORE_IDS 8 -/* dynamic ids 8-127 reserved for compact events. */ -#define MARKER_COMPACT_IDS 128 - -struct marker_info; - -struct marker_info { - GQuark name; - char *format; - long size; /* size if known statically, else -1 */ - GArray *fields; /* Array of struct marker_field */ - guint8 int_size, long_size, pointer_size, size_t_size, alignment; - struct marker_info *next; /* Linked list of markers with the same name */ -}; - -enum marker_id { - MARKER_ID_SET_MARKER_ID = 0, /* Static IDs available (range 0-7) */ - MARKER_ID_SET_MARKER_FORMAT, - MARKER_ID_HEARTBEAT_32, - MARKER_ID_HEARTBEAT_64, - MARKER_ID_COMPACT, /* Compact IDs (range: 8-127) */ - MARKER_ID_DYNAMIC, /* Dynamic IDs (range: 128-65535) */ -}; - -static inline guint16 marker_get_id_from_info(LttTrace *trace, - struct marker_info *info) -{ - return ((unsigned long)info - (unsigned long)trace->markers->data) - / sizeof(struct marker_info); -} - -static inline struct marker_info *marker_get_info_from_id(LttTrace *trace, - guint16 id) -{ - if (unlikely(trace->markers->len < id)) - return NULL; - return &g_array_index(trace->markers, struct marker_info, id); -} - -/* - * Returns the head of the marker info list for that name. - */ -static inline struct marker_info *marker_get_info_from_name(LttTrace *trace, - GQuark name) -{ - return g_hash_table_lookup(trace->markers_hash, (gconstpointer)name); -} - -static inline struct marker_field *marker_get_field(struct marker_info *info, - guint i) -{ - return &g_array_index(info->fields, struct marker_field, i); -} - -static inline unsigned int marker_get_num_fields(struct marker_info *info) -{ - return info->fields->len; -} - -/* - * for_each_marker_field - iterate over fields of a marker - * @field: struct marker_field * to use as iterator - * @info: marker info pointer - */ -#define for_each_marker_field(field, info) \ - for (field = marker_get_field(info, 0); \ - field != marker_get_field(info, marker_get_num_fields(info)); \ - field++) - -int marker_format_event(LttTrace *trace, GQuark name, const char *format); -int marker_id_event(LttTrace *trace, GQuark name, guint16 id, - uint8_t int_size, uint8_t long_size, uint8_t pointer_size, - uint8_t size_t_size, uint8_t alignment); -int allocate_marker_data(LttTrace *trace); -void destroy_marker_data(LttTrace *trace); - -#endif //_LTT_MARKERS_H diff --git a/ltt/branches/poly/ltt/tracefile.c b/ltt/branches/poly/ltt/tracefile.c index df02f4be..c3e61845 100644 --- a/ltt/branches/poly/ltt/tracefile.c +++ b/ltt/branches/poly/ltt/tracefile.c @@ -48,7 +48,7 @@ #include //#include #include -#include +#include /* Facility names used in this file */ diff --git a/ltt/branches/poly/lttv/lttv/tracecontext.h b/ltt/branches/poly/lttv/lttv/tracecontext.h index a99d3eb6..2ec68be0 100644 --- a/ltt/branches/poly/lttv/lttv/tracecontext.h +++ b/ltt/branches/poly/lttv/lttv/tracecontext.h @@ -23,7 +23,7 @@ #include #include #include -#include +#include /* This is the generic part of trace processing. All events within a certain time interval are accessed and processing hooks are called for