X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Fmarker.c;h=87c053df467af8d23c18ababfd68812a1b166d23;hb=91346f59cc3db03777b8d6f6c8a803a5bd37785f;hp=48b1c9bcb70d0408a2bc7a0dc35197765cedbae0;hpb=bb38a2907d1f182e0fdf443e48da94e3707d7f97;p=lttv.git diff --git a/ltt/branches/poly/ltt/marker.c b/ltt/branches/poly/ltt/marker.c index 48b1c9bc..87c053df 100644 --- a/ltt/branches/poly/ltt/marker.c +++ b/ltt/branches/poly/ltt/marker.c @@ -1,10 +1,27 @@ -/* - * Marker support code. +/* This file is part of the Linux Trace Toolkit viewer + * Copyright (C) 2007 Mathieu Desnoyers + * + * Complete rewrite from the original version made by XangXiu Yang. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License Version 2.1 as published by the Free Software Foundation. * - * Mathieu Desnoyers, August 2007 - * License: LGPL. + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include @@ -63,7 +80,7 @@ static inline const char *parse_trace_type(struct marker_info *info, *trace_type = LTT_TYPE_STRING; goto parse_end; case 'p': - *trace_type = LTT_TYPE_UNSIGNED_INT; + *trace_type = LTT_TYPE_POINTER; *trace_size = info->pointer_size; goto parse_end; case 'd': @@ -167,7 +184,7 @@ static inline const char *parse_c_type(struct marker_info *info, *c_type = LTT_TYPE_STRING; goto parse_end; case 'p': - *c_type = LTT_TYPE_UNSIGNED_INT; + *c_type = LTT_TYPE_POINTER; *c_size = info->pointer_size; goto parse_end; case 'd': @@ -267,11 +284,17 @@ long marker_update_fields_offsets(struct marker_info *info, const char *data) unsigned int i; long offset = 0; - for (i = 0; i < info->fields->len; i++) { + /* Find the last field with a static offset, then update from there. */ + for (i = info->fields->len - 1; i >= 0; i--) { field = &g_array_index(info->fields, struct marker_field, i); + if (field->static_offset) { + offset = field->offset; + break; + } + } - if (field->static_offset) - continue; + for (; i < info->fields->len; i++) { + field = &g_array_index(info->fields, struct marker_field, i); switch (field->type) { case LTT_TYPE_SIGNED_INT: @@ -305,6 +328,7 @@ static void format_parse(const char *fmt, struct marker_info *info) char *name = NULL; unsigned int field_count = 1; + name_begin = fmt; for (; *fmt ; ++fmt) { switch (*fmt) { case '#': @@ -345,7 +369,7 @@ static void format_parse(const char *fmt, struct marker_info *info) } break; case ' ': - if (!name_end) { + if (!name_end && name_begin) { name_end = fmt; if (name) g_free(name); @@ -355,7 +379,7 @@ static void format_parse(const char *fmt, struct marker_info *info) } break; /* Skip white spaces */ default: - if (!name) { + if (!name_begin) { name_begin = fmt; name_end = NULL; } @@ -373,6 +397,7 @@ int marker_parse_format(const char *format, struct marker_info *info) info->fields = g_array_sized_new(FALSE, TRUE, sizeof(struct marker_field), DEFAULT_FIELDS_NUM); format_parse(format, info); + return 0; } int marker_format_event(LttTrace *trace, GQuark name, const char *format) @@ -381,7 +406,7 @@ int marker_format_event(LttTrace *trace, GQuark name, const char *format) 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. " + g_error("Got marker format \"%s\", but marker name \"%s\" has no ID yet. " "Kernel issue.", format, name); for (; info != NULL; info = info->next) { @@ -390,9 +415,10 @@ int marker_format_event(LttTrace *trace, GQuark name, const char *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_error("Error parsing marker format \"%s\" for marker \"%s\"", format, g_quark_to_string(name)); } + return 0; } int marker_id_event(LttTrace *trace, GQuark name, guint16 id, @@ -400,8 +426,9 @@ int marker_id_event(LttTrace *trace, GQuark name, guint16 id, uint8_t size_t_size, uint8_t alignment) { struct marker_info *info, *head; + int found = 0; - if (trace->markers->len < id) + 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; @@ -415,9 +442,16 @@ int marker_id_event(LttTrace *trace, GQuark name, guint16 id, 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; + struct marker_info *iter; + for (iter = head; iter != NULL; iter = iter->next) + if (iter->name == name) + found = 1; + if (!found) { + g_hash_table_replace(trace->markers_hash, (gpointer)name, info); + info->next = head; + } } + return 0; } int allocate_marker_data(LttTrace *trace)