From 90e19f82bca635a1ba52b8a50b64e484bd19c14f Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Tue, 25 May 2010 17:19:09 -0400 Subject: [PATCH] Indentation updates Switch the indentation from spaces to tabs for all files in ./lttv/lttv as per the kernel coding style. Signed-off-by: Alexandre Montplaisir --- lttv/lttv/attribute.c | 896 ++--- lttv/lttv/attribute.h | 65 +- lttv/lttv/batchtest.c | 1731 +++++----- lttv/lttv/contextmacros.h | 72 +- lttv/lttv/filter.c | 2994 ++++++++-------- lttv/lttv/filter.h | 178 +- lttv/lttv/hook.c | 696 ++-- lttv/lttv/hook.h | 26 +- lttv/lttv/iattribute.c | 332 +- lttv/lttv/iattribute.h | 88 +- lttv/lttv/main.c | 275 +- lttv/lttv/module.c | 658 ++-- lttv/lttv/module.h | 74 +- lttv/lttv/option.c | 363 +- lttv/lttv/print.c | 450 +-- lttv/lttv/print.h | 6 +- lttv/lttv/state.c | 6888 ++++++++++++++++++------------------- lttv/lttv/state.h | 421 ++- lttv/lttv/stats.c | 1949 ++++++----- lttv/lttv/stats.h | 56 +- lttv/lttv/tracecontext.c | 2410 +++++++------ lttv/lttv/tracecontext.h | 258 +- lttv/lttv/traceset.c | 163 +- 23 files changed, 10527 insertions(+), 10522 deletions(-) diff --git a/lttv/lttv/attribute.c b/lttv/lttv/attribute.c index 7ba8f2c5..80126a5e 100644 --- a/lttv/lttv/attribute.c +++ b/lttv/lttv/attribute.c @@ -26,162 +26,163 @@ #include typedef union _AttributeValue { - int dv_int; - unsigned dv_uint; - long dv_long; - unsigned long dv_ulong; - float dv_float; - double dv_double; - LttTime dv_time; - gpointer dv_pointer; - char *dv_string; - GObject *dv_gobject; + int dv_int; + unsigned dv_uint; + long dv_long; + unsigned long dv_ulong; + float dv_float; + double dv_double; + LttTime dv_time; + gpointer dv_pointer; + char *dv_string; + GObject *dv_gobject; } AttributeValue; typedef struct _Attribute { - LttvAttributeName name; - LttvAttributeType type; - AttributeValue value; + LttvAttributeName name; + LttvAttributeType type; + AttributeValue value; gboolean is_named; } Attribute; -static __inline__ LttvAttributeValue address_of_value(LttvAttributeType t, - AttributeValue *v) +static __inline__ LttvAttributeValue +address_of_value(LttvAttributeType t, AttributeValue *v) { - LttvAttributeValue va; - - switch(t) { - case LTTV_INT: va.v_int = &v->dv_int; break; - case LTTV_UINT: va.v_uint = &v->dv_uint; break; - case LTTV_LONG: va.v_long = &v->dv_long; break; - case LTTV_ULONG: va.v_ulong = &v->dv_ulong; break; - case LTTV_FLOAT: va.v_float = &v->dv_float; break; - case LTTV_DOUBLE: va.v_double = &v->dv_double; break; - case LTTV_TIME: va.v_time = &v->dv_time; break; - case LTTV_POINTER: va.v_pointer = &v->dv_pointer; break; - case LTTV_STRING: va.v_string = &v->dv_string; break; - case LTTV_GOBJECT: va.v_gobject = &v->dv_gobject; break; - case LTTV_NONE: break; - } - return va; + LttvAttributeValue va; + + switch(t) { + case LTTV_INT: va.v_int = &v->dv_int; break; + case LTTV_UINT: va.v_uint = &v->dv_uint; break; + case LTTV_LONG: va.v_long = &v->dv_long; break; + case LTTV_ULONG: va.v_ulong = &v->dv_ulong; break; + case LTTV_FLOAT: va.v_float = &v->dv_float; break; + case LTTV_DOUBLE: va.v_double = &v->dv_double; break; + case LTTV_TIME: va.v_time = &v->dv_time; break; + case LTTV_POINTER: va.v_pointer = &v->dv_pointer; break; + case LTTV_STRING: va.v_string = &v->dv_string; break; + case LTTV_GOBJECT: va.v_gobject = &v->dv_gobject; break; + case LTTV_NONE: break; + } + return va; } -AttributeValue init_value(LttvAttributeType t) +AttributeValue +init_value(LttvAttributeType t) { - AttributeValue v; - - switch(t) { - case LTTV_INT: v.dv_int = 0; break; - case LTTV_UINT: v.dv_uint = 0; break; - case LTTV_LONG: v.dv_long = 0; break; - case LTTV_ULONG: v.dv_ulong = 0; break; - case LTTV_FLOAT: v.dv_float = 0; break; - case LTTV_DOUBLE: v.dv_double = 0; break; - case LTTV_TIME: v.dv_time.tv_sec = 0; v.dv_time.tv_nsec = 0; break; - case LTTV_POINTER: v.dv_pointer = NULL; break; - case LTTV_STRING: v.dv_string = NULL; break; - case LTTV_GOBJECT: v.dv_gobject = NULL; break; - case LTTV_NONE: break; - } - return v; + AttributeValue v; + + switch(t) { + case LTTV_INT: v.dv_int = 0; break; + case LTTV_UINT: v.dv_uint = 0; break; + case LTTV_LONG: v.dv_long = 0; break; + case LTTV_ULONG: v.dv_ulong = 0; break; + case LTTV_FLOAT: v.dv_float = 0; break; + case LTTV_DOUBLE: v.dv_double = 0; break; + case LTTV_TIME: v.dv_time.tv_sec = 0; v.dv_time.tv_nsec = 0; break; + case LTTV_POINTER: v.dv_pointer = NULL; break; + case LTTV_STRING: v.dv_string = NULL; break; + case LTTV_GOBJECT: v.dv_gobject = NULL; break; + case LTTV_NONE: break; + } + return v; } unsigned int lttv_attribute_get_number(LttvAttribute *self) { - return self->attributes->len; + return self->attributes->len; } gboolean lttv_attribute_named(LttvAttribute *self, gboolean *homogeneous) { - *homogeneous = FALSE; - return TRUE; + *homogeneous = FALSE; + return TRUE; } LttvAttributeType lttv_attribute_get(LttvAttribute *self, unsigned i, LttvAttributeName *name, - LttvAttributeValue *v, gboolean *is_named) + LttvAttributeValue *v, gboolean *is_named) { - Attribute *a; + Attribute *a; - a = &g_array_index(self->attributes, Attribute, i); - *name = a->name; - *v = address_of_value(a->type, &(a->value)); + a = &g_array_index(self->attributes, Attribute, i); + *name = a->name; + *v = address_of_value(a->type, &(a->value)); *is_named = a->is_named; - return a->type; + return a->type; } LttvAttributeType lttv_attribute_get_by_name(LttvAttribute *self, LttvAttributeName name, - LttvAttributeValue *v) + LttvAttributeValue *v) { - Attribute *a; + Attribute *a; - unsigned i; + unsigned i; - gpointer p; + gpointer p; - p = g_hash_table_lookup(self->names, GUINT_TO_POINTER(name)); - if(p == NULL) return LTTV_NONE; + p = g_hash_table_lookup(self->names, GUINT_TO_POINTER(name)); + if(p == NULL) return LTTV_NONE; - i = GPOINTER_TO_UINT(p); - i--; - a = &g_array_index(self->attributes, Attribute, i); - *v = address_of_value(a->type, &(a->value)); - return a->type; + i = GPOINTER_TO_UINT(p); + i--; + a = &g_array_index(self->attributes, Attribute, i); + *v = address_of_value(a->type, &(a->value)); + return a->type; } LttvAttributeValue lttv_attribute_add(LttvAttribute *self, LttvAttributeName name, - LttvAttributeType t) + LttvAttributeType t) { - unsigned int i; + unsigned int i; - Attribute a, *pa; + Attribute a, *pa; - i = GPOINTER_TO_UINT(g_hash_table_lookup(self->names, GUINT_TO_POINTER(name))); - if(i != 0) g_error("duplicate entry in attribute table"); + i = GPOINTER_TO_UINT(g_hash_table_lookup(self->names, GUINT_TO_POINTER(name))); + if(i != 0) g_error("duplicate entry in attribute table"); - a.name = name; + a.name = name; a.is_named = 1; - a.type = t; - a.value = init_value(t); - g_array_append_val(self->attributes, a); - i = self->attributes->len - 1; - pa = &g_array_index(self->attributes, Attribute, i); - g_hash_table_insert(self->names, GUINT_TO_POINTER(name), - GUINT_TO_POINTER(i + 1)); - return address_of_value(t, &(pa->value)); + a.type = t; + a.value = init_value(t); + g_array_append_val(self->attributes, a); + i = self->attributes->len - 1; + pa = &g_array_index(self->attributes, Attribute, i); + g_hash_table_insert(self->names, GUINT_TO_POINTER(name), + GUINT_TO_POINTER(i + 1)); + return address_of_value(t, &(pa->value)); } LttvAttributeValue lttv_attribute_add_unnamed(LttvAttribute *self, LttvAttributeName name, - LttvAttributeType t) + LttvAttributeType t) { - unsigned int i; + unsigned int i; - Attribute a, *pa; + Attribute a, *pa; - i = GPOINTER_TO_UINT(g_hash_table_lookup(self->names, GUINT_TO_POINTER(name))); - if(i != 0) g_error("duplicate entry in attribute table"); + i = GPOINTER_TO_UINT(g_hash_table_lookup(self->names, GUINT_TO_POINTER(name))); + if(i != 0) g_error("duplicate entry in attribute table"); - a.name = name; + a.name = name; a.is_named = 0; - a.type = t; - a.value = init_value(t); - g_array_append_val(self->attributes, a); - i = self->attributes->len - 1; - pa = &g_array_index(self->attributes, Attribute, i); - g_hash_table_insert(self->names, GUINT_TO_POINTER(name), - GUINT_TO_POINTER(i + 1)); - return address_of_value(t, &(pa->value)); + a.type = t; + a.value = init_value(t); + g_array_append_val(self->attributes, a); + i = self->attributes->len - 1; + pa = &g_array_index(self->attributes, Attribute, i); + g_hash_table_insert(self->names, GUINT_TO_POINTER(name), + GUINT_TO_POINTER(i + 1)); + return address_of_value(t, &(pa->value)); } @@ -190,37 +191,37 @@ lttv_attribute_add_unnamed(LttvAttribute *self, LttvAttributeName name, void lttv_attribute_remove(LttvAttribute *self, unsigned i) { - Attribute *a; + Attribute *a; - a = &g_array_index(self->attributes, Attribute, i); + a = &g_array_index(self->attributes, Attribute, i); - /* If the element is a gobject, unreference it. */ - if(a->type == LTTV_GOBJECT && a->value.dv_gobject != NULL) - g_object_unref(a->value.dv_gobject); - - /* Remove the array element and its entry in the name index */ + /* If the element is a gobject, unreference it. */ + if(a->type == LTTV_GOBJECT && a->value.dv_gobject != NULL) + g_object_unref(a->value.dv_gobject); - g_hash_table_remove(self->names, GUINT_TO_POINTER(a->name)); - g_array_remove_index_fast(self->attributes, i); + /* Remove the array element and its entry in the name index */ - /* The element used to replace the removed element has its index entry - all wrong now. Reinsert it with its new position. */ + g_hash_table_remove(self->names, GUINT_TO_POINTER(a->name)); + g_array_remove_index_fast(self->attributes, i); - if(likely(self->attributes->len != i)){ - g_hash_table_remove(self->names, GUINT_TO_POINTER(a->name)); - g_hash_table_insert(self->names, GUINT_TO_POINTER(a->name), GUINT_TO_POINTER(i + 1)); - } + /* The element used to replace the removed element has its index entry + all wrong now. Reinsert it with its new position. */ + + if(likely(self->attributes->len != i)){ + g_hash_table_remove(self->names, GUINT_TO_POINTER(a->name)); + g_hash_table_insert(self->names, GUINT_TO_POINTER(a->name), GUINT_TO_POINTER(i + 1)); + } } void lttv_attribute_remove_by_name(LttvAttribute *self, LttvAttributeName name) { - unsigned int i; + unsigned int i; - i = GPOINTER_TO_UINT(g_hash_table_lookup(self->names, GUINT_TO_POINTER(name))); - if(unlikely(i == 0)) g_error("remove by name non existent attribute"); + i = GPOINTER_TO_UINT(g_hash_table_lookup(self->names, GUINT_TO_POINTER(name))); + if(unlikely(i == 0)) g_error("remove by name non existent attribute"); - lttv_attribute_remove(self, i - 1); + lttv_attribute_remove(self, i - 1); } /* Create an empty iattribute object and add it as an attribute under the @@ -231,443 +232,444 @@ lttv_attribute_remove_by_name(LttvAttribute *self, LttvAttributeName name) /*CHECK*/LttvAttribute* lttv_attribute_find_subdir(LttvAttribute *self, LttvAttributeName name) { - unsigned int i; - - Attribute a; - - LttvAttribute *new; - - i = GPOINTER_TO_UINT(g_hash_table_lookup(self->names, GUINT_TO_POINTER(name))); - if(likely(i != 0)) { - a = g_array_index(self->attributes, Attribute, i - 1); - if(likely(a.type == LTTV_GOBJECT && LTTV_IS_IATTRIBUTE(a.value.dv_gobject))) { - return LTTV_ATTRIBUTE(a.value.dv_gobject); - } - else return NULL; - } - new = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); - *(lttv_attribute_add(self, name, LTTV_GOBJECT).v_gobject) = G_OBJECT(new); - return (LttvAttribute *)new; + unsigned int i; + + Attribute a; + + LttvAttribute *new; + + i = GPOINTER_TO_UINT(g_hash_table_lookup(self->names, GUINT_TO_POINTER(name))); + if(likely(i != 0)) { + a = g_array_index(self->attributes, Attribute, i - 1); + if(likely(a.type == LTTV_GOBJECT && LTTV_IS_IATTRIBUTE(a.value.dv_gobject))) { + return LTTV_ATTRIBUTE(a.value.dv_gobject); + } + else return NULL; + } + new = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); + *(lttv_attribute_add(self, name, LTTV_GOBJECT).v_gobject) = G_OBJECT(new); + return (LttvAttribute *)new; } /*CHECK*/LttvAttribute* lttv_attribute_find_subdir_unnamed(LttvAttribute *self, LttvAttributeName name) { - unsigned int i; - - Attribute a; - - LttvAttribute *new; - - i = GPOINTER_TO_UINT(g_hash_table_lookup(self->names, GUINT_TO_POINTER(name))); - if(likely(i != 0)) { - a = g_array_index(self->attributes, Attribute, i - 1); - if(likely(a.type == LTTV_GOBJECT && LTTV_IS_IATTRIBUTE(a.value.dv_gobject))) { - return LTTV_ATTRIBUTE(a.value.dv_gobject); - } - else return NULL; - } - new = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); - *(lttv_attribute_add_unnamed(self, name, LTTV_GOBJECT).v_gobject) + unsigned int i; + + Attribute a; + + LttvAttribute *new; + + i = GPOINTER_TO_UINT(g_hash_table_lookup(self->names, GUINT_TO_POINTER(name))); + if(likely(i != 0)) { + a = g_array_index(self->attributes, Attribute, i - 1); + if(likely(a.type == LTTV_GOBJECT && LTTV_IS_IATTRIBUTE(a.value.dv_gobject))) { + return LTTV_ATTRIBUTE(a.value.dv_gobject); + } + else return NULL; + } + new = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); + *(lttv_attribute_add_unnamed(self, name, LTTV_GOBJECT).v_gobject) = G_OBJECT(new); - return (LttvAttribute *)new; + return (LttvAttribute *)new; } gboolean lttv_attribute_find(LttvAttribute *self, LttvAttributeName name, - LttvAttributeType t, LttvAttributeValue *v) + LttvAttributeType t, LttvAttributeValue *v) { - unsigned int i; + unsigned int i; - Attribute *a; + Attribute *a; - i = GPOINTER_TO_UINT(g_hash_table_lookup(self->names, GUINT_TO_POINTER(name))); - if(likely(i != 0)) { - a = &g_array_index(self->attributes, Attribute, i - 1); - if(unlikely(a->type != t)) return FALSE; - *v = address_of_value(t, &(a->value)); - return TRUE; - } + i = GPOINTER_TO_UINT(g_hash_table_lookup(self->names, GUINT_TO_POINTER(name))); + if(likely(i != 0)) { + a = &g_array_index(self->attributes, Attribute, i - 1); + if(unlikely(a->type != t)) return FALSE; + *v = address_of_value(t, &(a->value)); + return TRUE; + } - *v = lttv_attribute_add(self, name, t); - return TRUE; + *v = lttv_attribute_add(self, name, t); + return TRUE; } gboolean lttv_attribute_find_unnamed(LttvAttribute *self, LttvAttributeName name, - LttvAttributeType t, LttvAttributeValue *v) + LttvAttributeType t, LttvAttributeValue *v) { - unsigned i; + unsigned i; - Attribute *a; + Attribute *a; - i = GPOINTER_TO_UINT(g_hash_table_lookup(self->names, GUINT_TO_POINTER(name))); - if(likely(i != 0)) { - a = &g_array_index(self->attributes, Attribute, i - 1); - if(unlikely(a->type != t)) return FALSE; - *v = address_of_value(t, &(a->value)); - return TRUE; - } + i = GPOINTER_TO_UINT(g_hash_table_lookup(self->names, GUINT_TO_POINTER(name))); + if(likely(i != 0)) { + a = &g_array_index(self->attributes, Attribute, i - 1); + if(unlikely(a->type != t)) return FALSE; + *v = address_of_value(t, &(a->value)); + return TRUE; + } - *v = lttv_attribute_add_unnamed(self, name, t); - return TRUE; + *v = lttv_attribute_add_unnamed(self, name, t); + return TRUE; } /*void lttv_attribute_recursive_free(LttvAttribute *self) { - int i, nb; + int i, nb; - Attribute *a; + Attribute *a; - nb = self->attributes->len; + nb = self->attributes->len; - for(i = 0 ; i < nb ; i++) { - a = &g_array_index(self->attributes, Attribute, i); - if(a->type == LTTV_GOBJECT && LTTV_IS_ATTRIBUTE(a->value.dv_gobject)) { - lttv_attribute_recursive_free((LttvAttribute *)(a->value.dv_gobject)); - } - } - g_object_unref(self); + for(i = 0 ; i < nb ; i++) { + a = &g_array_index(self->attributes, Attribute, i); + if(a->type == LTTV_GOBJECT && LTTV_IS_ATTRIBUTE(a->value.dv_gobject)) { + lttv_attribute_recursive_free((LttvAttribute *)(a->value.dv_gobject)); + } + } + g_object_unref(self); }*/ -void lttv_attribute_recursive_add(LttvAttribute *dest, LttvAttribute *src) +void +lttv_attribute_recursive_add(LttvAttribute *dest, LttvAttribute *src) { - int i, nb; + int i, nb; - Attribute *a; + Attribute *a; - LttvAttributeValue value; - gboolean retval; + LttvAttributeValue value; + gboolean retval; - nb = src->attributes->len; + nb = src->attributes->len; - for(i = 0 ; i < nb ; i++) { - a = &g_array_index(src->attributes, Attribute, i); - if(a->type == LTTV_GOBJECT && LTTV_IS_ATTRIBUTE(a->value.dv_gobject)) { + for(i = 0 ; i < nb ; i++) { + a = &g_array_index(src->attributes, Attribute, i); + if(a->type == LTTV_GOBJECT && LTTV_IS_ATTRIBUTE(a->value.dv_gobject)) { if(a->is_named) - lttv_attribute_recursive_add( - /*CHECK*/(LttvAttribute *)lttv_attribute_find_subdir(dest, a->name), - (LttvAttribute *)(a->value.dv_gobject)); + lttv_attribute_recursive_add( + /*CHECK*/(LttvAttribute *)lttv_attribute_find_subdir(dest, a->name), + (LttvAttribute *)(a->value.dv_gobject)); else - lttv_attribute_recursive_add( - /*CHECK*/(LttvAttribute *)lttv_attribute_find_subdir_unnamed( + lttv_attribute_recursive_add( + /*CHECK*/(LttvAttribute *)lttv_attribute_find_subdir_unnamed( dest, a->name), (LttvAttribute *)(a->value.dv_gobject)); - } - else { - if(a->is_named) { - retval= lttv_attribute_find(dest, a->name, a->type, &value); - g_assert(retval); - } - else { - retval= lttv_attribute_find_unnamed(dest, a->name, a->type, &value); - g_assert(retval); - } - switch(a->type) { - case LTTV_INT: - *value.v_int += a->value.dv_int; - break; - case LTTV_UINT: - *value.v_uint += a->value.dv_uint; - break; - case LTTV_LONG: - *value.v_long += a->value.dv_long; - break; - case LTTV_ULONG: - *value.v_ulong += a->value.dv_ulong; - break; - case LTTV_FLOAT: - *value.v_float += a->value.dv_float; - break; - case LTTV_DOUBLE: - *value.v_double += a->value.dv_double; - break; - case LTTV_TIME: - *value.v_time = ltt_time_add(*value.v_time, a->value.dv_time); - break; - case LTTV_POINTER: - break; - case LTTV_STRING: - break; - case LTTV_GOBJECT: - break; - case LTTV_NONE: - break; - } - } - } + } + else { + if(a->is_named) { + retval= lttv_attribute_find(dest, a->name, a->type, &value); + g_assert(retval); + } + else { + retval= lttv_attribute_find_unnamed(dest, a->name, a->type, &value); + g_assert(retval); + } + switch(a->type) { + case LTTV_INT: + *value.v_int += a->value.dv_int; + break; + case LTTV_UINT: + *value.v_uint += a->value.dv_uint; + break; + case LTTV_LONG: + *value.v_long += a->value.dv_long; + break; + case LTTV_ULONG: + *value.v_ulong += a->value.dv_ulong; + break; + case LTTV_FLOAT: + *value.v_float += a->value.dv_float; + break; + case LTTV_DOUBLE: + *value.v_double += a->value.dv_double; + break; + case LTTV_TIME: + *value.v_time = ltt_time_add(*value.v_time, a->value.dv_time); + break; + case LTTV_POINTER: + break; + case LTTV_STRING: + break; + case LTTV_GOBJECT: + break; + case LTTV_NONE: + break; + } + } + } } static void print_indent(FILE *fp, int pos) { - int i; + int i; - for(i = 0 ; i < pos ; i++) putc(' ', fp); + for(i = 0 ; i < pos ; i++) putc(' ', fp); } void lttv_attribute_write_xml(LttvAttribute *self, FILE *fp, int pos, int indent) { - int i, nb; - - Attribute *a; - - nb = self->attributes->len; - - fprintf(fp,"\n"); - for(i = 0 ; i < nb ; i++) { - a = &g_array_index(self->attributes, Attribute, i); - print_indent(fp, pos); - fprintf(fp, "name)); - if(a->type == LTTV_GOBJECT && LTTV_IS_ATTRIBUTE(a->value.dv_gobject)) { - fprintf(fp, "TYPE=ATTRS>"); - lttv_attribute_write_xml((LttvAttribute *)(a->value.dv_gobject), fp, - pos + indent, indent); - } - else { - switch(a->type) { - case LTTV_INT: - fprintf(fp, "TYPE=INT VALUE=%d/>\n", a->value.dv_int); - break; - case LTTV_UINT: - fprintf(fp, "TYPE=UINT VALUE=%u/>\n", a->value.dv_uint); - break; - case LTTV_LONG: - fprintf(fp, "TYPE=LONG VALUE=%ld/>\n", a->value.dv_long); - break; - case LTTV_ULONG: - fprintf(fp, "TYPE=ULONG VALUE=%lu/>\n", a->value.dv_ulong); - break; - case LTTV_FLOAT: - fprintf(fp, "TYPE=FLOAT VALUE=%f/>\n", a->value.dv_float); - break; - case LTTV_DOUBLE: - fprintf(fp, "TYPE=DOUBLE VALUE=%f/>\n", a->value.dv_double); - break; - case LTTV_TIME: - fprintf(fp, "TYPE=TIME SEC=%lu NSEC=%lu/>\n", a->value.dv_time.tv_sec, - a->value.dv_time.tv_nsec); - break; - case LTTV_POINTER: - fprintf(fp, "TYPE=POINTER VALUE=%p/>\n", a->value.dv_pointer); - break; - case LTTV_STRING: - fprintf(fp, "TYPE=STRING VALUE=\"%s\"/>\n", a->value.dv_string); - break; - case LTTV_GOBJECT: - fprintf(fp, "TYPE=GOBJECT VALUE=%p/>\n", a->value.dv_gobject); - break; - case LTTV_NONE: - fprintf(fp, "TYPE=NONE/>\n"); - break; - } - } - } - print_indent(fp, pos); - fprintf(fp,"\n"); + int i, nb; + + Attribute *a; + + nb = self->attributes->len; + + fprintf(fp,"\n"); + for(i = 0 ; i < nb ; i++) { + a = &g_array_index(self->attributes, Attribute, i); + print_indent(fp, pos); + fprintf(fp, "name)); + if(a->type == LTTV_GOBJECT && LTTV_IS_ATTRIBUTE(a->value.dv_gobject)) { + fprintf(fp, "TYPE=ATTRS>"); + lttv_attribute_write_xml((LttvAttribute *)(a->value.dv_gobject), fp, + pos + indent, indent); + } + else { + switch(a->type) { + case LTTV_INT: + fprintf(fp, "TYPE=INT VALUE=%d/>\n", a->value.dv_int); + break; + case LTTV_UINT: + fprintf(fp, "TYPE=UINT VALUE=%u/>\n", a->value.dv_uint); + break; + case LTTV_LONG: + fprintf(fp, "TYPE=LONG VALUE=%ld/>\n", a->value.dv_long); + break; + case LTTV_ULONG: + fprintf(fp, "TYPE=ULONG VALUE=%lu/>\n", a->value.dv_ulong); + break; + case LTTV_FLOAT: + fprintf(fp, "TYPE=FLOAT VALUE=%f/>\n", a->value.dv_float); + break; + case LTTV_DOUBLE: + fprintf(fp, "TYPE=DOUBLE VALUE=%f/>\n", a->value.dv_double); + break; + case LTTV_TIME: + fprintf(fp, "TYPE=TIME SEC=%lu NSEC=%lu/>\n", + a->value.dv_time.tv_sec, a->value.dv_time.tv_nsec); + break; + case LTTV_POINTER: + fprintf(fp, "TYPE=POINTER VALUE=%p/>\n", a->value.dv_pointer); + break; + case LTTV_STRING: + fprintf(fp, "TYPE=STRING VALUE=\"%s\"/>\n", a->value.dv_string); + break; + case LTTV_GOBJECT: + fprintf(fp, "TYPE=GOBJECT VALUE=%p/>\n", a->value.dv_gobject); + break; + case LTTV_NONE: + fprintf(fp, "TYPE=NONE/>\n"); + break; + } + } + } + print_indent(fp, pos); + fprintf(fp,"\n"); } void lttv_attribute_read_xml(LttvAttribute *self, FILE *fp) { - int res; - - char buffer[256], type[10]; - - LttvAttributeName name; - - LttvAttributeValue value; - - LttvAttribute *subtree; - - fscanf(fp,""); - while(1) { - res = fscanf(fp, "]", buffer, type); - g_assert(res == 2); - name = g_quark_from_string(buffer); - if(strcmp(type, "ATTRS") == 0) { - fscanf(fp, ">"); - subtree = lttv_attribute_find_subdir(self, name); - lttv_attribute_read_xml(subtree, fp); - } - else if(strcmp(type, "INT") == 0) { - value = lttv_attribute_add(self, name, LTTV_INT); - res = fscanf(fp, " VALUE=%d/>", value.v_int); - g_assert(res == 1); - } - else if(strcmp(type, "UINT") == 0) { - value = lttv_attribute_add(self, name, LTTV_UINT); - res = fscanf(fp, " VALUE=%u/>", value.v_uint); - g_assert(res == 1); - } - else if(strcmp(type, "LONG") == 0) { - value = lttv_attribute_add(self, name, LTTV_LONG); - res = fscanf(fp, " VALUE=%ld/>", value.v_long); - g_assert(res == 1); - } - else if(strcmp(type, "ULONG") == 0) { - value = lttv_attribute_add(self, name, LTTV_ULONG); - res = fscanf(fp, " VALUE=%lu/>", value.v_ulong); - g_assert(res == 1); - } - else if(strcmp(type, "FLOAT") == 0) { - float d; - value = lttv_attribute_add(self, name, LTTV_FLOAT); - res = fscanf(fp, " VALUE=%f/>", &d); - *(value.v_float) = d; - g_assert(res == 1); - } - else if(strcmp(type, "DOUBLE") == 0) { - value = lttv_attribute_add(self, name, LTTV_DOUBLE); - res = fscanf(fp, " VALUE=%lf/>", value.v_double); - g_assert(res == 1); - } - else if(strcmp(type, "TIME") == 0) { - value = lttv_attribute_add(self, name, LTTV_TIME); - res = fscanf(fp, " SEC=%lu NSEC=%lu/>", &(value.v_time->tv_sec), - &(value.v_time->tv_nsec)); - g_assert(res == 2); - } - else if(strcmp(type, "POINTER") == 0) { - value = lttv_attribute_add(self, name, LTTV_POINTER); - res = fscanf(fp, " VALUE=%p/>", value.v_pointer); - g_error("Cannot read a pointer"); - } - else if(strcmp(type, "STRING") == 0) { - value = lttv_attribute_add(self, name, LTTV_STRING); - res = fscanf(fp, " VALUE=\"%256[^\"]\"/>", buffer); - *(value.v_string) = g_strdup(buffer); - g_assert(res == 1); - } - else if(strcmp(type, "GOBJECT") == 0) { - value = lttv_attribute_add(self, name, LTTV_GOBJECT); - res = fscanf(fp, " VALUE=%p/>", value.v_gobject); - g_error("Cannot read a pointer"); - } - else if(strcmp(type, "NONE") == 0) { - value = lttv_attribute_add(self, name, LTTV_NONE); - fscanf(fp, "/>"); - } - else g_error("Unknown type to read"); - } - fscanf(fp,""); + int res; + + char buffer[256], type[10]; + + LttvAttributeName name; + + LttvAttributeValue value; + + LttvAttribute *subtree; + + fscanf(fp,""); + while(1) { + res = fscanf(fp, "]", buffer, type); + g_assert(res == 2); + name = g_quark_from_string(buffer); + if(strcmp(type, "ATTRS") == 0) { + fscanf(fp, ">"); + subtree = lttv_attribute_find_subdir(self, name); + lttv_attribute_read_xml(subtree, fp); + } + else if(strcmp(type, "INT") == 0) { + value = lttv_attribute_add(self, name, LTTV_INT); + res = fscanf(fp, " VALUE=%d/>", value.v_int); + g_assert(res == 1); + } + else if(strcmp(type, "UINT") == 0) { + value = lttv_attribute_add(self, name, LTTV_UINT); + res = fscanf(fp, " VALUE=%u/>", value.v_uint); + g_assert(res == 1); + } + else if(strcmp(type, "LONG") == 0) { + value = lttv_attribute_add(self, name, LTTV_LONG); + res = fscanf(fp, " VALUE=%ld/>", value.v_long); + g_assert(res == 1); + } + else if(strcmp(type, "ULONG") == 0) { + value = lttv_attribute_add(self, name, LTTV_ULONG); + res = fscanf(fp, " VALUE=%lu/>", value.v_ulong); + g_assert(res == 1); + } + else if(strcmp(type, "FLOAT") == 0) { + float d; + value = lttv_attribute_add(self, name, LTTV_FLOAT); + res = fscanf(fp, " VALUE=%f/>", &d); + *(value.v_float) = d; + g_assert(res == 1); + } + else if(strcmp(type, "DOUBLE") == 0) { + value = lttv_attribute_add(self, name, LTTV_DOUBLE); + res = fscanf(fp, " VALUE=%lf/>", value.v_double); + g_assert(res == 1); + } + else if(strcmp(type, "TIME") == 0) { + value = lttv_attribute_add(self, name, LTTV_TIME); + res = fscanf(fp, " SEC=%lu NSEC=%lu/>", &(value.v_time->tv_sec), + &(value.v_time->tv_nsec)); + g_assert(res == 2); + } + else if(strcmp(type, "POINTER") == 0) { + value = lttv_attribute_add(self, name, LTTV_POINTER); + res = fscanf(fp, " VALUE=%p/>", value.v_pointer); + g_error("Cannot read a pointer"); + } + else if(strcmp(type, "STRING") == 0) { + value = lttv_attribute_add(self, name, LTTV_STRING); + res = fscanf(fp, " VALUE=\"%256[^\"]\"/>", buffer); + *(value.v_string) = g_strdup(buffer); + g_assert(res == 1); + } + else if(strcmp(type, "GOBJECT") == 0) { + value = lttv_attribute_add(self, name, LTTV_GOBJECT); + res = fscanf(fp, " VALUE=%p/>", value.v_gobject); + g_error("Cannot read a pointer"); + } + else if(strcmp(type, "NONE") == 0) { + value = lttv_attribute_add(self, name, LTTV_NONE); + fscanf(fp, "/>"); + } + else g_error("Unknown type to read"); + } + fscanf(fp,""); } static LttvAttribute * new_attribute (LttvAttribute *self) { - return g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); + return g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); } static void attribute_interface_init (gpointer g_iface, gpointer iface_data) { - LttvIAttributeClass *klass = (LttvIAttributeClass *)g_iface; + LttvIAttributeClass *klass = (LttvIAttributeClass *)g_iface; - klass->new_attribute = (LttvIAttribute* (*) (LttvIAttribute *self)) - new_attribute; + klass->new_attribute = (LttvIAttribute* (*) (LttvIAttribute *self)) + new_attribute; - klass->get_number = (unsigned int (*) (LttvIAttribute *self)) - lttv_attribute_get_number; + klass->get_number = (unsigned int (*) (LttvIAttribute *self)) + lttv_attribute_get_number; - klass->named = (gboolean (*) (LttvIAttribute *self, gboolean *homogeneous)) - lttv_attribute_named; + klass->named = (gboolean (*) (LttvIAttribute *self, gboolean *homogeneous)) + lttv_attribute_named; - klass->get = (LttvAttributeType (*) (LttvIAttribute *self, unsigned i, - LttvAttributeName *name, LttvAttributeValue *v, gboolean *is_named)) + klass->get = (LttvAttributeType (*) (LttvIAttribute *self, unsigned i, + LttvAttributeName *name, LttvAttributeValue *v, gboolean *is_named)) lttv_attribute_get; - klass->get_by_name = (LttvAttributeType (*) (LttvIAttribute *self, - LttvAttributeName name, LttvAttributeValue *v)) - lttv_attribute_get_by_name; + klass->get_by_name = (LttvAttributeType (*) (LttvIAttribute *self, + LttvAttributeName name, LttvAttributeValue *v)) + lttv_attribute_get_by_name; - klass->add = (LttvAttributeValue (*) (LttvIAttribute *self, - LttvAttributeName name, LttvAttributeType t)) lttv_attribute_add; + klass->add = (LttvAttributeValue (*) (LttvIAttribute *self, + LttvAttributeName name, LttvAttributeType t)) lttv_attribute_add; - klass->add_unnamed = (LttvAttributeValue (*) (LttvIAttribute *self, - LttvAttributeName name, LttvAttributeType t)) lttv_attribute_add_unnamed; + klass->add_unnamed = (LttvAttributeValue (*) (LttvIAttribute *self, + LttvAttributeName name, LttvAttributeType t)) lttv_attribute_add_unnamed; - klass->remove = (void (*) (LttvIAttribute *self, unsigned i)) - lttv_attribute_remove; + klass->remove = (void (*) (LttvIAttribute *self, unsigned i)) + lttv_attribute_remove; - klass->remove_by_name = (void (*) (LttvIAttribute *self, - LttvAttributeName name)) lttv_attribute_remove_by_name; + klass->remove_by_name = (void (*) (LttvIAttribute *self, + LttvAttributeName name)) lttv_attribute_remove_by_name; - klass->find_subdir = (LttvIAttribute* (*) (LttvIAttribute *self, - LttvAttributeName name)) lttv_attribute_find_subdir; + klass->find_subdir = (LttvIAttribute* (*) (LttvIAttribute *self, + LttvAttributeName name)) lttv_attribute_find_subdir; - klass->find_subdir = (LttvIAttribute* (*) (LttvIAttribute *self, - LttvAttributeName name)) lttv_attribute_find_subdir_unnamed; + klass->find_subdir = (LttvIAttribute* (*) (LttvIAttribute *self, + LttvAttributeName name)) lttv_attribute_find_subdir_unnamed; } static void attribute_instance_init (GTypeInstance *instance, gpointer g_class) { - LttvAttribute *self = (LttvAttribute *)instance; - self->names = g_hash_table_new(g_direct_hash, - g_direct_equal); - self->attributes = g_array_new(FALSE, FALSE, sizeof(Attribute)); + LttvAttribute *self = (LttvAttribute *)instance; + self->names = g_hash_table_new(g_direct_hash, + g_direct_equal); + self->attributes = g_array_new(FALSE, FALSE, sizeof(Attribute)); } static void attribute_finalize (LttvAttribute *self) { - guint i; - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "attribute_finalize()"); - - for(i=0;iattributes->len;i++) { - lttv_attribute_remove(self, i); - } - - g_hash_table_destroy(self->names); - g_array_free(self->attributes, TRUE); + guint i; + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "attribute_finalize()"); + + for(i=0;iattributes->len;i++) { + lttv_attribute_remove(self, i); + } + + g_hash_table_destroy(self->names); + g_array_free(self->attributes, TRUE); } static void attribute_class_init (LttvAttributeClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->finalize = (void (*)(GObject *self))attribute_finalize; + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->finalize = (void (*)(GObject *self))attribute_finalize; } GType lttv_attribute_get_type (void) { - static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof (LttvAttributeClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) attribute_class_init, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (LttvAttribute), - 0, /* n_preallocs */ - (GInstanceInitFunc) attribute_instance_init, /* instance_init */ - NULL /* value handling */ - }; - - static const GInterfaceInfo iattribute_info = { - (GInterfaceInitFunc) attribute_interface_init, /* interface_init */ - NULL, /* interface_finalize */ - NULL /* interface_data */ - }; - - type = g_type_register_static (G_TYPE_OBJECT, "LttvAttributeType", &info, - 0); - g_type_add_interface_static (type, LTTV_IATTRIBUTE_TYPE, &iattribute_info); - } - return type; + static GType type = 0; + if (type == 0) { + static const GTypeInfo info = { + sizeof (LttvAttributeClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) attribute_class_init, /* class_init */ + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (LttvAttribute), + 0, /* n_preallocs */ + (GInstanceInitFunc) attribute_instance_init, /* instance_init */ + NULL /* value handling */ + }; + + static const GInterfaceInfo iattribute_info = { + (GInterfaceInitFunc) attribute_interface_init, /* interface_init */ + NULL, /* interface_finalize */ + NULL /* interface_data */ + }; + + type = g_type_register_static (G_TYPE_OBJECT, "LttvAttributeType", &info, + 0); + g_type_add_interface_static (type, LTTV_IATTRIBUTE_TYPE, &iattribute_info); + } + return type; } diff --git a/lttv/lttv/attribute.h b/lttv/lttv/attribute.h index 498d567c..77d4dc73 100644 --- a/lttv/lttv/attribute.h +++ b/lttv/lttv/attribute.h @@ -37,19 +37,20 @@ typedef struct _LttvAttribute LttvAttribute; typedef struct _LttvAttributeClass LttvAttributeClass; struct _LttvAttribute { - GObject parent; + GObject parent; - /* private members */ - GHashTable *names; - GArray *attributes; + /* private members */ + GHashTable *names; + GArray *attributes; }; struct _LttvAttributeClass { - GObjectClass parent; + GObjectClass parent; }; -GType lttv_attribute_get_type (void); +GType +lttv_attribute_get_type (void); /* The functions exported in the IAttribute interface are also available @@ -58,43 +59,50 @@ GType lttv_attribute_get_type (void); /* Total number of attributes */ -unsigned int lttv_attribute_get_number(LttvAttribute *self); +unsigned int +lttv_attribute_get_number(LttvAttribute *self); /* Container type. Named (fields in struct or elements in a hash table) or unnamed (elements in an array) attributes, homogeneous type or not. */ -gboolean lttv_attribute_named(LttvAttribute *self, gboolean *homogeneous); +gboolean +lttv_attribute_named(LttvAttribute *self, gboolean *homogeneous); /* Get the i th attribute along with its type and a pointer to its value. */ -LttvAttributeType lttv_attribute_get(LttvAttribute *self, unsigned i, - LttvAttributeName *name, LttvAttributeValue *v, gboolean *is_named); +LttvAttributeType +lttv_attribute_get(LttvAttribute *self, unsigned i, LttvAttributeName *name, + LttvAttributeValue *v, gboolean *is_named); /* Get the named attribute in the table along with its type and a pointer to its value. If the named attribute does not exist, the type is LTTV_NONE. */ -LttvAttributeType lttv_attribute_get_by_name(LttvAttribute *self, - LttvAttributeName name, LttvAttributeValue *v); +LttvAttributeType +lttv_attribute_get_by_name(LttvAttribute *self, LttvAttributeName name, + LttvAttributeValue *v); /* Add an attribute, which must not exist. The name is an empty string for containers with unnamed attributes. */ -LttvAttributeValue lttv_attribute_add(LttvAttribute *self, - LttvAttributeName name, LttvAttributeType t); +LttvAttributeValue +lttv_attribute_add(LttvAttribute *self, LttvAttributeName name, + LttvAttributeType t); -LttvAttributeValue lttv_attribute_add_unnamed(LttvAttribute *self, - LttvAttributeName name, LttvAttributeType t); +LttvAttributeValue +lttv_attribute_add_unnamed(LttvAttribute *self, LttvAttributeName name, + LttvAttributeType t); /* Remove an attribute */ -void lttv_attribute_remove(LttvAttribute *self, unsigned i); +void +lttv_attribute_remove(LttvAttribute *self, unsigned i); -void lttv_attribute_remove_by_name(LttvAttribute *self, - LttvAttributeName name); +void +lttv_attribute_remove_by_name(LttvAttribute *self, LttvAttributeName name); /* Create an empty iattribute object and add it as an attribute under the @@ -102,15 +110,16 @@ void lttv_attribute_remove_by_name(LttvAttribute *self, attribute of that name already exists but is not a GObject supporting the iattribute interface, return NULL. */ -LttvAttribute* lttv_attribute_find_subdir(LttvAttribute *self, - LttvAttributeName name); +LttvAttribute* +lttv_attribute_find_subdir(LttvAttribute *self, LttvAttributeName name); -LttvAttribute* lttv_attribute_find_subdir_unnamed(LttvAttribute *self, - LttvAttributeName name); +LttvAttribute* +lttv_attribute_find_subdir_unnamed(LttvAttribute *self, LttvAttributeName name); -gboolean lttv_attribute_find(LttvAttribute *self, LttvAttributeName name, - LttvAttributeType t, LttvAttributeValue *v); +gboolean +lttv_attribute_find(LttvAttribute *self, LttvAttributeName name, + LttvAttributeType t, LttvAttributeValue *v); /* Free recursively a tree of attributes. All contained gobject of type @@ -121,11 +130,13 @@ gboolean lttv_attribute_find(LttvAttribute *self, LttvAttributeName name, /* Add items from a tree of attributes to another tree. */ -void lttv_attribute_recursive_add(LttvAttribute *dest, LttvAttribute *src); +void +lttv_attribute_recursive_add(LttvAttribute *dest, LttvAttribute *src); void lttv_attribute_write_xml(LttvAttribute *self, FILE *fp, int pos, int indent); -void lttv_attribute_read_xml(LttvAttribute *self, FILE *fp); +void +lttv_attribute_read_xml(LttvAttribute *self, FILE *fp); #endif // ATTRIBUTE_H diff --git a/lttv/lttv/batchtest.c b/lttv/lttv/batchtest.c index 3dd7725e..08b892be 100644 --- a/lttv/lttv/batchtest.c +++ b/lttv/lttv/batchtest.c @@ -42,16 +42,16 @@ static LttvTraceset *traceset; static LttvHooks - *before_traceset, - *after_traceset, - *before_trace, - *after_trace, - *before_tracefile, - *after_tracefile, - //*before_event, - //*after_event, - *event_hook, - *main_hooks; + *before_traceset, + *after_traceset, + *before_trace, + *after_trace, + *before_tracefile, + *after_tracefile, + //*before_event, + //*after_event, + *event_hook, + *main_hooks; static char *a_trace; @@ -60,955 +60,952 @@ static char *a_dump_tracefiles; static char *a_save_sample; static int - a_sample_interval, - a_sample_number, - a_seek_number, - a_save_interval; + a_sample_interval, + a_sample_number, + a_seek_number, + a_save_interval; static gboolean - a_trace_event, - a_save_state_copy, - a_test1, - a_test2, - a_test3, - a_test4, - a_test5, - a_test6, - a_test7, - a_test8, - a_test9, - a_test10, - a_test_all; + a_trace_event, + a_save_state_copy, + a_test1, + a_test2, + a_test3, + a_test4, + a_test5, + a_test6, + a_test7, + a_test8, + a_test9, + a_test10, + a_test_all; static GQuark QUARK_BLOCK_START, - QUARK_BLOCK_END; + QUARK_BLOCK_END; LttEventPosition *a_event_position; typedef struct _save_state { - guint count; - FILE *fp; - guint interval; - guint position; - guint size; - LttTime *write_time; - guint version; + guint count; + FILE *fp; + guint interval; + guint position; + guint size; + LttTime *write_time; + guint version; } SaveState; static void lttv_trace_option(void __UNUSED__ *hook_data) { - LttTrace *trace; - - trace = ltt_trace_open(a_trace); - if(trace == NULL) { - g_critical("cannot open trace %s", a_trace); - } else { - lttv_traceset_add(traceset, lttv_trace_new(trace)); - } + LttTrace *trace; + + trace = ltt_trace_open(a_trace); + if(trace == NULL) { + g_critical("cannot open trace %s", a_trace); + } else { + lttv_traceset_add(traceset, lttv_trace_new(trace)); + } } static double get_time() { - GTimeVal gt; + GTimeVal gt; - g_get_current_time(>); - return gt.tv_sec + (double)gt.tv_usec / (double)1000000.0; + g_get_current_time(>); + return gt.tv_sec + (double)gt.tv_usec / (double)1000000.0; } static double run_one_test(LttvTracesetState *ts, LttTime start, LttTime end) { - double t0, t1; - - unsigned int i; - - //lttv_traceset_context_add_hooks(&ts->parent, - //before_traceset, after_traceset, NULL, before_trace, after_trace, - //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event); - lttv_process_traceset_begin(&ts->parent, - before_traceset, - before_trace, - before_tracefile, - event_hook, - NULL); - - for(i = 0 ; i < lttv_traceset_number(traceset) ; i++) { - ((LttvTraceState *)(ts->parent.traces[i]))->save_interval =a_save_interval; - } - - t0 = get_time(); - lttv_state_traceset_seek_time_closest(ts, start); - //lttv_process_traceset(&ts->parent, end, G_MAXULONG); - lttv_process_traceset_middle(&ts->parent, - end, - G_MAXULONG, - NULL); - t1 = get_time(); - - //lttv_traceset_context_remove_hooks(&ts->parent, - //before_traceset, after_traceset, NULL, before_trace, after_trace, - //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event); - lttv_process_traceset_end(&ts->parent, - after_traceset, - after_trace, - after_tracefile, - event_hook, - NULL); - - return t1 - t0; + double t0, t1; + + unsigned int i; + + //lttv_traceset_context_add_hooks(&ts->parent, + //before_traceset, after_traceset, NULL, before_trace, after_trace, + //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event); + lttv_process_traceset_begin(&ts->parent, + before_traceset, + before_trace, + before_tracefile, + event_hook, + NULL); + + for(i = 0 ; i < lttv_traceset_number(traceset) ; i++) { + ((LttvTraceState *)(ts->parent.traces[i]))->save_interval =a_save_interval; + } + + t0 = get_time(); + lttv_state_traceset_seek_time_closest(ts, start); + //lttv_process_traceset(&ts->parent, end, G_MAXULONG); + lttv_process_traceset_middle(&ts->parent, + end, + G_MAXULONG, + NULL); + t1 = get_time(); + + //lttv_traceset_context_remove_hooks(&ts->parent, + //before_traceset, after_traceset, NULL, before_trace, after_trace, + //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event); + lttv_process_traceset_end(&ts->parent, + after_traceset, + after_trace, + after_tracefile, + event_hook, + NULL); + + return t1 - t0; } gboolean trace_event(void __UNUSED__ *hook_data, void *call_data) { - LttvTracefileState *tfs = (LttvTracefileState *)call_data; - - guint nb_block, offset; - - guint64 tsc; - - LttTracefile *tf; - LttEvent *e = ltt_tracefile_get_event(tfs->parent.tf); - ltt_event_position(e, a_event_position); - ltt_event_position_get(a_event_position, &tf, &nb_block, &offset, &tsc); - fprintf(stderr, "Event %s %lu.%09lu [%u 0x%x tsc %" PRIu64 "]\n", - g_quark_to_string(marker_get_info_from_id(tf->mdata, - ltt_event_id(e))->name), - tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec, - nb_block, offset, tsc); - return FALSE; + LttvTracefileState *tfs = (LttvTracefileState *)call_data; + + guint nb_block, offset; + + guint64 tsc; + + LttTracefile *tf; + LttEvent *e = ltt_tracefile_get_event(tfs->parent.tf); + ltt_event_position(e, a_event_position); + ltt_event_position_get(a_event_position, &tf, &nb_block, &offset, &tsc); + fprintf(stderr, "Event %s %lu.%09lu [%u 0x%x tsc %" PRIu64 "]\n", + g_quark_to_string(marker_get_info_from_id(tf->mdata, + ltt_event_id(e))->name), + tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec, + nb_block, offset, tsc); + return FALSE; } static LttTime count_previous_time = { 0, 0 }; gboolean count_event(void *hook_data, void __UNUSED__ *call_data) { - LttvTracefileState *tfs = (LttvTracefileState *)call_data; - LttTracefile *tracefile = tfs->parent.tf; - guint nb_block, offset; - LttTracefile *tf_pos; - guint64 tsc; - LttEvent * event = ltt_tracefile_get_event(tracefile); - LttTime time; - guint *pcount = (guint *)hook_data; - - (*pcount)++; - - time = ltt_event_time(event); - ltt_event_position(event, a_event_position); - ltt_event_position_get(a_event_position, &tf_pos, &nb_block, &offset, &tsc); - - if(ltt_time_compare(time, count_previous_time) < 0) { - g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x", - g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile))), - g_quark_to_string(ltt_tracefile_name(tracefile)), - tfs->cpu, nb_block, offset); - g_warning("last time %lu.%lu vs current %lu.%lu", - count_previous_time.tv_sec, count_previous_time.tv_nsec, - time.tv_sec, time.tv_nsec); - } - count_previous_time = time; - - - - return FALSE; + LttvTracefileState *tfs = (LttvTracefileState *)call_data; + LttTracefile *tracefile = tfs->parent.tf; + guint nb_block, offset; + LttTracefile *tf_pos; + guint64 tsc; + LttEvent * event = ltt_tracefile_get_event(tracefile); + LttTime time; + guint *pcount = (guint *)hook_data; + + (*pcount)++; + + time = ltt_event_time(event); + ltt_event_position(event, a_event_position); + ltt_event_position_get(a_event_position, &tf_pos, &nb_block, &offset, &tsc); + + if(ltt_time_compare(time, count_previous_time) < 0) { + g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x", + g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile))), + g_quark_to_string(ltt_tracefile_name(tracefile)), + tfs->cpu, nb_block, offset); + g_warning("last time %lu.%lu vs current %lu.%lu", + count_previous_time.tv_sec, count_previous_time.tv_nsec, + time.tv_sec, time.tv_nsec); + } + count_previous_time = time; + + + + return FALSE; } gboolean save_state_copy_event(void *hook_data, void *call_data) { - SaveState __UNUSED__ *save_state = (SaveState *)hook_data; + SaveState __UNUSED__ *save_state = (SaveState *)hook_data; - LttvTracefileState *tfs = (LttvTracefileState *)call_data; + LttvTracefileState *tfs = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState *)tfs->parent.t_context; + LttvTraceState *ts = (LttvTraceState *)tfs->parent.t_context; - LttEvent *e = ltt_tracefile_get_event(tfs->parent.tf); + LttEvent *e = ltt_tracefile_get_event(tfs->parent.tf); - GString *filename; + GString *filename; - FILE *fp; + FILE *fp; - if(ts->nb_event == 0 && - marker_get_info_from_id(tfs->parent.tf->mdata, e->event_id)->name - == QUARK_BLOCK_START) { - if(a_save_sample != NULL) { - filename = g_string_new(""); - g_string_printf(filename, "%s.copy.%lu.%09lu.xml", a_save_sample, - tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); - fp = fopen(filename->str, "w"); - if(fp == NULL) g_error("Cannot open %s", filename->str); - g_string_free(filename, TRUE); - lttv_state_write(ts, tfs->parent.timestamp, fp); - fclose(fp); - } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp); - } - return FALSE; + if(ts->nb_event == 0 && + marker_get_info_from_id(tfs->parent.tf->mdata, e->event_id)->name + == QUARK_BLOCK_START) { + if(a_save_sample != NULL) { + filename = g_string_new(""); + g_string_printf(filename, "%s.copy.%lu.%09lu.xml", a_save_sample, + tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); + fp = fopen(filename->str, "w"); + if(fp == NULL) g_error("Cannot open %s", filename->str); + g_string_free(filename, TRUE); + lttv_state_write(ts, tfs->parent.timestamp, fp); + fclose(fp); + } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp); + } + return FALSE; } gboolean save_state_event(void *hook_data, void *call_data) { - SaveState *save_state = (SaveState *)hook_data; - - LttvTracefileState *tfs = (LttvTracefileState *)call_data; - - LttvTraceState *ts = (LttvTraceState *)tfs->parent.t_context; - - GString *filename; - - FILE *fp; - - (save_state->count)++; - if(save_state->count % save_state->interval == 0 && - save_state->position < save_state->size) { - if(a_save_sample != NULL) { - filename = g_string_new(""); - g_string_printf(filename, "%s.%u.xml.%u", a_save_sample, - save_state->position, save_state->version); - fp = fopen(filename->str, "w"); - if(fp == NULL) g_error("Cannot open %s", filename->str); - g_string_free(filename, TRUE); - lttv_state_write(ts, tfs->parent.timestamp, fp); - fclose(fp); - } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp); - - save_state->write_time[save_state->position] = tfs->parent.timestamp; - save_state->position++; - } - return FALSE; + SaveState *save_state = (SaveState *)hook_data; + + LttvTracefileState *tfs = (LttvTracefileState *)call_data; + + LttvTraceState *ts = (LttvTraceState *)tfs->parent.t_context; + + GString *filename; + + FILE *fp; + + (save_state->count)++; + if(save_state->count % save_state->interval == 0 && + save_state->position < save_state->size) { + if(a_save_sample != NULL) { + filename = g_string_new(""); + g_string_printf(filename, "%s.%u.xml.%u", a_save_sample, + save_state->position, save_state->version); + fp = fopen(filename->str, "w"); + if(fp == NULL) g_error("Cannot open %s", filename->str); + g_string_free(filename, TRUE); + lttv_state_write(ts, tfs->parent.timestamp, fp); + fclose(fp); + } //else lttv_state_write(ts, tfs->parent.timestamp, save_state->fp); + + save_state->write_time[save_state->position] = tfs->parent.timestamp; + save_state->position++; + } + return FALSE; } static void sanitize_name(gchar *name) { - while(*name != '\0') { - if(*name == '/') *name = '_'; - name++; - } - + while(*name != '\0') { + if(*name == '/') *name = '_'; + name++; + } + } static void compute_tracefile(LttTracefile *tracefile, void *hook_data) { - GString *filename; - guint nb_equal, nb_block, offset; - guint64 tsc; - FILE *fp; - LttTime time, previous_time; - LttEvent *event = ltt_tracefile_get_event(tracefile); - //LttEventType *event_type; - struct marker_info *minfo; - int err; - gchar mod_name[PATH_MAX]; - - /* start_count is always initialized in this function _if_ there is always - * a block_start before a block_end. - */ - //long long unsigned cycle_count, start_count=0, delta_cycle; - - - filename = g_string_new(""); - strcpy(mod_name, g_quark_to_string(ltt_tracefile_name(tracefile))); - - sanitize_name(mod_name); - - g_warning("test %s test", g_quark_to_string(ltt_tracefile_name(tracefile))); - g_string_printf(filename, "%s.%s.%u.trace", a_dump_tracefiles, - mod_name, ltt_tracefile_cpu(tracefile)); - fp = fopen(filename->str, "w"); - if(fp == NULL) g_error("Cannot open %s", filename->str); - g_string_free(filename, TRUE); - err = ltt_tracefile_seek_time(tracefile, ltt_time_zero); - if(err) goto close; - - previous_time = ltt_time_zero; - nb_equal = 0; - - do { - LttTracefile *tf_pos; - //event_type = ltt_event_eventtype(event); - minfo = marker_get_info_from_id(tracefile->mdata, - ltt_event_id(event)); - time = ltt_event_time(event); - ltt_event_position(event, a_event_position); - ltt_event_position_get(a_event_position, &tf_pos, &nb_block, &offset, &tsc); - //fprintf(fp,"%s.%s: %llu %lu.%09lu position %u/%u\n", - fprintf(fp, "%s: %" PRIu64 " %lu.%09lu position %u/%u, tracefile %s\n", - g_quark_to_string(minfo->name), - tsc, (unsigned long)time.tv_sec, - (unsigned long)time.tv_nsec, - nb_block, offset, - g_quark_to_string(ltt_tracefile_name(tracefile))); - - if(ltt_time_compare(time, previous_time) < 0) { - g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x", - g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile))), - g_quark_to_string(ltt_tracefile_name(tracefile)), - ltt_tracefile_cpu(tracefile), nb_block, offset); - g_warning("last time %lu.%lu vs current %lu.%lu", - previous_time.tv_sec, previous_time.tv_nsec, - time.tv_sec, time.tv_nsec); - } + GString *filename; + guint nb_equal, nb_block, offset; + guint64 tsc; + FILE *fp; + LttTime time, previous_time; + LttEvent *event = ltt_tracefile_get_event(tracefile); + //LttEventType *event_type; + struct marker_info *minfo; + int err; + gchar mod_name[PATH_MAX]; + + /* start_count is always initialized in this function _if_ there is always + * a block_start before a block_end. + */ + //long long unsigned cycle_count, start_count=0, delta_cycle; + + + filename = g_string_new(""); + strcpy(mod_name, g_quark_to_string(ltt_tracefile_name(tracefile))); + + sanitize_name(mod_name); + + g_warning("test %s test", g_quark_to_string(ltt_tracefile_name(tracefile))); + g_string_printf(filename, "%s.%s.%u.trace", a_dump_tracefiles, + mod_name, ltt_tracefile_cpu(tracefile)); + fp = fopen(filename->str, "w"); + if(fp == NULL) g_error("Cannot open %s", filename->str); + g_string_free(filename, TRUE); + err = ltt_tracefile_seek_time(tracefile, ltt_time_zero); + if(err) goto close; + + previous_time = ltt_time_zero; + nb_equal = 0; + + do { + LttTracefile *tf_pos; + //event_type = ltt_event_eventtype(event); + minfo = marker_get_info_from_id(tracefile->mdata, + ltt_event_id(event)); + time = ltt_event_time(event); + ltt_event_position(event, a_event_position); + ltt_event_position_get(a_event_position, &tf_pos, &nb_block, &offset, &tsc); + //fprintf(fp,"%s.%s: %llu %lu.%09lu position %u/%u\n", + fprintf(fp, "%s: %" PRIu64 " %lu.%09lu position %u/%u, tracefile %s\n", + g_quark_to_string(minfo->name), + tsc, (unsigned long)time.tv_sec, + (unsigned long)time.tv_nsec, + nb_block, offset, + g_quark_to_string(ltt_tracefile_name(tracefile))); + + if(ltt_time_compare(time, previous_time) < 0) { + g_warning("Time decreasing trace %s tracefile %s cpu %u position %u/0x%x", + g_quark_to_string(ltt_trace_name(ltt_tracefile_get_trace(tracefile))), + g_quark_to_string(ltt_tracefile_name(tracefile)), + ltt_tracefile_cpu(tracefile), nb_block, offset); + g_warning("last time %lu.%lu vs current %lu.%lu", + previous_time.tv_sec, previous_time.tv_nsec, + time.tv_sec, time.tv_nsec); + } #if 0 //FIXME - if(ltt_eventtype_name(event_type) == QUARK_BLOCK_START) { - start_count = cycle_count; - start_time = time; - } - else if(ltt_eventtype_name(event_type) == QUARK_BLOCK_END) { - delta_cycle = cycle_count - start_count; - end_nsec_sec = (long long unsigned)time.tv_sec * (long long unsigned)1000000000; - end_nsec_nsec = time.tv_nsec; - end_nsec = end_nsec_sec + end_nsec_nsec; - start_nsec = (long long unsigned)start_time.tv_sec * (long long unsigned)1000000000 + (long long unsigned)start_time.tv_nsec; - delta_nsec = end_nsec - start_nsec; - cycle_per_nsec = (double)delta_cycle / (double)delta_nsec; - nsec_per_cycle = (double)delta_nsec / (double)delta_cycle; - added_nsec = (double)delta_cycle * nsec_per_cycle; - interpolated_nsec = start_nsec + added_nsec; - added_nsec2 = (double)delta_cycle / cycle_per_nsec; - interpolated_nsec2 = start_nsec + added_nsec2; - - fprintf(fp,"Time: start_count %llu, end_count %llu, delta_cycle %llu, start_nsec %llu, end_nsec_sec %llu, end_nsec_nsec %llu, end_nsec %llu, delta_nsec %llu, cycle_per_nsec %.25f, nsec_per_cycle %.25f, added_nsec %llu, added_nsec2 %llu, interpolated_nsec %llu, interpolated_nsec2 %llu\n", start_count, cycle_count, delta_cycle, start_nsec, end_nsec_sec, end_nsec_nsec, end_nsec, delta_nsec, cycle_per_nsec, nsec_per_cycle, added_nsec, added_nsec2, interpolated_nsec, interpolated_nsec2); - } - else { + if(ltt_eventtype_name(event_type) == QUARK_BLOCK_START) { + start_count = cycle_count; + start_time = time; + } + else if(ltt_eventtype_name(event_type) == QUARK_BLOCK_END) { + delta_cycle = cycle_count - start_count; + end_nsec_sec = (long long unsigned)time.tv_sec * (long long unsigned)1000000000; + end_nsec_nsec = time.tv_nsec; + end_nsec = end_nsec_sec + end_nsec_nsec; + start_nsec = (long long unsigned)start_time.tv_sec * (long long unsigned)1000000000 + (long long unsigned)start_time.tv_nsec; + delta_nsec = end_nsec - start_nsec; + cycle_per_nsec = (double)delta_cycle / (double)delta_nsec; + nsec_per_cycle = (double)delta_nsec / (double)delta_cycle; + added_nsec = (double)delta_cycle * nsec_per_cycle; + interpolated_nsec = start_nsec + added_nsec; + added_nsec2 = (double)delta_cycle / cycle_per_nsec; + interpolated_nsec2 = start_nsec + added_nsec2; + + fprintf(fp,"Time: start_count %llu, end_count %llu, delta_cycle %llu, start_nsec %llu, end_nsec_sec %llu, end_nsec_nsec %llu, end_nsec %llu, delta_nsec %llu, cycle_per_nsec %.25f, nsec_per_cycle %.25f, added_nsec %llu, added_nsec2 %llu, interpolated_nsec %llu, interpolated_nsec2 %llu\n", start_count, cycle_count, delta_cycle, start_nsec, end_nsec_sec, end_nsec_nsec, end_nsec, delta_nsec, cycle_per_nsec, nsec_per_cycle, added_nsec, added_nsec2, interpolated_nsec, interpolated_nsec2); + } + else { #endif //0 - if(ltt_time_compare(time, previous_time) == 0) - nb_equal++; - else if(nb_equal > 0) { - g_warning("Consecutive %d events with time %lu.%09lu", - nb_equal + 1, previous_time.tv_sec, previous_time.tv_nsec); - nb_equal = 0; - } - previous_time = time; - //} - } while((!ltt_tracefile_read(tracefile))); + if(ltt_time_compare(time, previous_time) == 0) + nb_equal++; + else if(nb_equal > 0) { + g_warning("Consecutive %d events with time %lu.%09lu", + nb_equal + 1, previous_time.tv_sec, previous_time.tv_nsec); + nb_equal = 0; + } + previous_time = time; + //} + } while((!ltt_tracefile_read(tracefile))); close: - fclose(fp); + fclose(fp); } static gboolean process_traceset(void __UNUSED__ *hook_data, - void __UNUSED__ *call_data) + void __UNUSED__ *call_data) { - GString *filename; - LttvTracesetStats *tscs; + GString *filename; + LttvTracesetStats *tscs; + + LttvTracesetState *ts; + + LttvTracesetContext *tc; + + FILE *fp; + + double t; + + //guint count, nb_control, nb_tracefile, nb_block, nb_event; + //guint i, j, count, nb_control, nb_tracefile, nb_block, nb_event, nb_equal; + guint i, j, count; + + LttTrace *trace; + + LttTime max_time = { G_MAXULONG, G_MAXULONG }; + + a_event_position = ltt_event_position_new(); + + GData **tracefiles_groups; - LttvTracesetState *ts; + struct compute_tracefile_group_args args; - LttvTracesetContext *tc; + args.func = compute_tracefile; + args.func_args = NULL; - FILE *fp; + if(a_dump_tracefiles != NULL) { + for(i = 0 ; i < lttv_traceset_number(traceset) ; i++) { + trace = lttv_trace(lttv_traceset_get(traceset, i)); + tracefiles_groups = ltt_trace_get_tracefiles_groups(trace); - double t; + g_datalist_foreach(tracefiles_groups, + (GDataForeachFunc)compute_tracefile_group, &args); - //guint count, nb_control, nb_tracefile, nb_block, nb_event; - //guint i, j, count, nb_control, nb_tracefile, nb_block, nb_event, nb_equal; - guint i, j, count; + } + } - LttTrace *trace; + tscs = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL); + ts = &tscs->parent; + tc = &tscs->parent.parent; - LttTime max_time = { G_MAXULONG, G_MAXULONG }; + lttv_context_init(tc, traceset); - a_event_position = ltt_event_position_new(); + /* For each case compute and print the elapsed time. + The first case is simply to run through all events with a + simple counter. */ - GData **tracefiles_groups; + if(a_test1 || a_test_all) { + count = 0; + lttv_hooks_add(event_hook, count_event, &count, LTTV_PRIO_DEFAULT); + t = run_one_test(ts, ltt_time_zero, max_time); + lttv_hooks_remove_data(event_hook, count_event, &count); + g_message("Processing trace while counting events (%u events in %g seconds)", + count, t); + } - struct compute_tracefile_group_args args; + /* Run through all events computing the state. */ - args.func = compute_tracefile; - args.func_args = NULL; - - if(a_dump_tracefiles != NULL) { - for(i = 0 ; i < lttv_traceset_number(traceset) ; i++) { - trace = lttv_trace(lttv_traceset_get(traceset, i)); - tracefiles_groups = ltt_trace_get_tracefiles_groups(trace); + if(a_test2 || a_test_all) { + lttv_state_add_event_hooks(ts); + t = run_one_test(ts, ltt_time_zero, max_time); + lttv_state_remove_event_hooks(ts); + g_message("Processing trace while updating state (%g seconds)", t); + } - g_datalist_foreach(tracefiles_groups, - (GDataForeachFunc)compute_tracefile_group, - &args); - - } - } - - tscs = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL); - ts = &tscs->parent; - tc = &tscs->parent.parent; - - lttv_context_init(tc, traceset); - - /* For each case compute and print the elapsed time. - The first case is simply to run through all events with a - simple counter. */ - - if(a_test1 || a_test_all) { - count = 0; - lttv_hooks_add(event_hook, count_event, &count, LTTV_PRIO_DEFAULT); - t = run_one_test(ts, ltt_time_zero, max_time); - lttv_hooks_remove_data(event_hook, count_event, &count); - g_message( - "Processing trace while counting events (%u events in %g seconds)", - count, t); - } - - /* Run through all events computing the state. */ - - if(a_test2 || a_test_all) { - lttv_state_add_event_hooks(ts); - t = run_one_test(ts, ltt_time_zero, max_time); - lttv_state_remove_event_hooks(ts); - g_message("Processing trace while updating state (%g seconds)", t); - } - - /* Run through all events computing the state and writing it out - periodically. */ - - SaveState save_state; - - save_state.interval = a_sample_interval; - save_state.size = a_sample_number; - save_state.fp = stderr; - save_state.write_time = g_new(LttTime, a_sample_number); - - - if(a_test3 || a_test_all) { - for(i = 0 ; i < 2 ; i++) { - save_state.count = 0; - save_state.position = 0; - save_state.version = i; - lttv_state_add_event_hooks(ts); - lttv_hooks_add(event_hook, save_state_event, &save_state, - LTTV_PRIO_DEFAULT); - t = run_one_test(ts, ltt_time_zero, max_time); - lttv_state_remove_event_hooks(ts); - lttv_hooks_remove_data(event_hook, save_state_event, &save_state); - g_warning("Processing while updating/writing state (%g seconds)", t); - } - } - - /* Run through all events computing the stats. */ - - if(a_test4 || a_test_all) { - if(lttv_profile_memory) { - g_message("Memory summary before computing stats"); - g_mem_profile(); - } - - lttv_stats_add_event_hooks(tscs); - t = run_one_test(ts, ltt_time_zero, max_time); - lttv_stats_remove_event_hooks(tscs); - g_message("Processing trace while counting stats (%g seconds)", t); - - if(lttv_profile_memory) { - g_message("Memory summary after computing stats"); - g_mem_profile(); - } - - lttv_stats_sum_traceset(tscs, ltt_time_infinite); - - if(lttv_profile_memory) { - g_message("Memory summary after summing stats"); - g_mem_profile(); - } - - lttv_context_fini(tc); - lttv_context_init(tc, traceset); - - if(lttv_profile_memory) { - g_message("Memory summary after cleaning up the stats"); - g_mem_profile(); - } - } - - /* Run through all events computing the state and stats. */ - - if(a_test5 || a_test_all) { - if(lttv_profile_memory) { - g_message("Memory summary before computing state and stats"); - g_mem_profile(); - } - - lttv_state_add_event_hooks(ts); - lttv_stats_add_event_hooks(tscs); - t = run_one_test(ts, ltt_time_zero, max_time); - lttv_state_remove_event_hooks(ts); - lttv_stats_remove_event_hooks(tscs); - g_message( - "Processing trace while counting state and stats (%g seconds)", t); - - if(lttv_profile_memory) { - g_message("Memory summary after computing and state and stats"); - g_mem_profile(); - } - - lttv_context_fini(tc); - lttv_context_init(tc, traceset); - - if(lttv_profile_memory) { - g_message("Memory summary after cleaning up the stats"); - g_mem_profile(); - } - } - - /* Run through all events computing and saving the state. */ - - if(a_trace_event) lttv_hooks_add(event_hook, trace_event, NULL, - LTTV_PRIO_DEFAULT); - - if(a_test6 || a_test_all) { - if(lttv_profile_memory) { - g_message("Memory summary before computing and saving state"); - g_mem_profile(); - } - - lttv_state_add_event_hooks(ts); - lttv_state_save_add_event_hooks(ts); - if(a_save_state_copy) - lttv_hooks_add(event_hook, save_state_copy_event, &save_state, - LTTV_PRIO_DEFAULT); - t = run_one_test(ts, ltt_time_zero, max_time); - lttv_state_remove_event_hooks(ts); - lttv_state_save_remove_event_hooks(ts); - if(a_save_state_copy) - lttv_hooks_remove_data(event_hook,save_state_copy_event, &save_state); - - g_message("Processing trace while updating/saving state (%g seconds)", t); - - if(lttv_profile_memory) { - g_message("Memory summary after computing/saving state"); - g_mem_profile(); - } - } - - /* Seek a few times to each saved position */ - - if((a_test7 && a_test3) || a_test_all) { - g_assert(a_seek_number >= 0); - for(i = 0 ; i < (guint)a_seek_number ; i++) { - gint reverse_j; /* just to make sure j is unsigned */ - for(reverse_j = save_state.position - 1 ; reverse_j >= 0 ; reverse_j--) { - j = (guint)reverse_j; - lttv_state_add_event_hooks(ts); - t = run_one_test(ts, save_state.write_time[j], - save_state.write_time[j]); - lttv_state_remove_event_hooks(ts); - g_message("Seeking to %lu.%lu (%g seconds)", - save_state.write_time[j].tv_sec, save_state.write_time[j].tv_nsec, - t); - - if(a_save_sample != NULL) { - filename = g_string_new(""); - g_string_printf(filename, "%s.%d.xml.bak%d", a_save_sample, j, i); - fp = fopen(filename->str, "w"); - if(fp == NULL) g_error("Cannot open %s", filename->str); - g_string_free(filename, TRUE); - lttv_state_write((LttvTraceState *)tc->traces[0], - save_state.write_time[j], fp); - fclose(fp); - } - //else lttv_state_write((LttvTraceState *)tc->traces[0], - // save_state.write_time[j], save_state.fp); - } - } - } - - /* Seek at specified interval, using states computed in 6, making - * sure that there is no more than the number of events between - * state save interval to read before getting there. - */ - - if((a_test8 && a_test6) || a_test_all) { - g_message("Running test 8 : check save interval"); - LttTime time = tc->time_span.start_time; - LttTime interval; - interval.tv_sec = 0; - interval.tv_nsec = 175674987; - guint count; - - while(ltt_time_compare(time, tc->time_span.end_time) < 0) { - //g_message("Seeking at time %u.%u", time.tv_sec, time.tv_nsec); - lttv_process_traceset_seek_time(&ts->parent, ltt_time_zero); - lttv_state_traceset_seek_time_closest(ts, time); - /* We add no hook to the traceset, not necessary */ - count = lttv_process_traceset_middle(&ts->parent, - time, G_MAXUINT, NULL); - g_info("Number of events to jump over : %u", count); - - if(count > LTTV_STATE_SAVE_INTERVAL) - g_warning("Oops! Save interval is %u and it took %u events to seek to a time %lu.%lu supposed to be closer from the last saved state.", - LTTV_STATE_SAVE_INTERVAL, count, time.tv_sec, time.tv_nsec); - time = ltt_time_add(time, interval); - } - - } - - if(a_test9 || a_test_all) { - double t0, t1; - /* Run seek_forward and seek_backward test */ - guint count; - LttvTracesetContext *tsc = &ts->parent; - LttvTracesetContextPosition *saved_pos = - lttv_traceset_context_position_new(tsc); - g_message("Running test 9 : seek_forward and seek_backward"); - lttv_process_traceset_seek_time(tsc, ltt_time_zero); - - count = lttv_process_traceset_seek_n_forward(tsc, 500, NULL, NULL, NULL, NULL, NULL, NULL); - g_assert(count == 500); - lttv_traceset_context_position_save(tsc, saved_pos); - t0 = get_time(); - count = lttv_process_traceset_seek_n_forward(tsc, 150000, NULL, NULL, NULL, NULL, NULL, NULL); - t1 = get_time(); - g_message("Seek forward 150000 events in %g seconds", t1 - t0); - g_assert(count == 150000); - t0 = get_time(); - count = lttv_process_traceset_seek_n_backward(tsc, 150000, - seek_back_default_offset, lttv_process_traceset_seek_time, NULL, - NULL, NULL, NULL, NULL, NULL); - t1 = get_time(); - g_message("Seek backward 150000 events in %g seconds", t1 - t0); - g_assert(count == 150000); - if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) { - g_warning("Problem with seek_n ! Positions differ. (1)"); - } - - lttv_process_traceset_seek_n_forward(tsc, 500, NULL, NULL, NULL, NULL, NULL, NULL); - lttv_traceset_context_position_save(tsc, saved_pos); - lttv_process_traceset_seek_n_forward(tsc, 15000, NULL, NULL, NULL, NULL, NULL, NULL); - lttv_process_traceset_seek_n_backward(tsc, 15005, - seek_back_default_offset, lttv_process_traceset_seek_time, NULL, - NULL, NULL, NULL, NULL, NULL); - lttv_process_traceset_seek_n_forward(tsc, 5, NULL, NULL, NULL, NULL, NULL, NULL); - if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) { - g_warning("Problem with seek_n ! Positions differ. (2)"); - } - - lttv_process_traceset_seek_time(tsc, ltt_time_infinite); - - count = lttv_process_traceset_seek_n_forward(tsc, 15000, NULL, NULL, NULL, NULL, NULL, NULL); - if(count > 0) - g_warning("Problem with seek_n ! Forward at end of traceset."); - - lttv_process_traceset_seek_time(tsc, ltt_time_infinite); - - lttv_traceset_context_position_save(tsc, saved_pos); - t0 = get_time(); - lttv_process_traceset_seek_n_backward(tsc, 300, - seek_back_default_offset, lttv_process_traceset_seek_time, NULL, - NULL, NULL, NULL, NULL, NULL); - t1 = get_time(); - g_message("Seek backward 300 events in %g seconds", t1 - t0); - count = lttv_process_traceset_seek_n_forward(tsc, 299, NULL, NULL, NULL, NULL, NULL, NULL); - count = lttv_process_traceset_seek_n_forward(tsc, 1, NULL, NULL, NULL, NULL, NULL, NULL); - - if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) { - g_warning("Problem with seek_n ! Positions differ. (4)"); - } - - lttv_traceset_context_position_save(tsc, saved_pos); - t0 = get_time(); - lttv_process_traceset_seek_n_backward(tsc, 10, - seek_back_default_offset, lttv_process_traceset_seek_time, NULL, - NULL, NULL, NULL, NULL, NULL); - t1 = get_time(); - g_message("Seek backward 10 events in %g seconds", t1 - t0); - t0 = get_time(); - count = lttv_process_traceset_seek_n_forward(tsc, 10, NULL, NULL, NULL, NULL, NULL, NULL); - t1 = get_time(); - g_message("Seek forward 10 events in %g seconds", t1 - t0); - - - /* try a volountary error */ - lttv_process_traceset_seek_time(tsc, ltt_time_infinite); - - lttv_traceset_context_position_save(tsc, saved_pos); - lttv_process_traceset_seek_n_backward(tsc, 301, - seek_back_default_offset, lttv_process_traceset_seek_time, NULL, - NULL, NULL, NULL, NULL, NULL); - count = lttv_process_traceset_seek_n_forward(tsc, 299, NULL, NULL, NULL, NULL, NULL, NULL); - count = lttv_process_traceset_seek_n_forward(tsc, 1, NULL, NULL, NULL, NULL, NULL, NULL); - - if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) == 0) { - g_warning("Problem with seek_n ! Positions _should_ differ. (5)"); - } - - /* Try a seek by closest time : Hint : try this one with and without states - * computed. */ - lttv_process_traceset_seek_time(tsc, ltt_time_zero); - count = lttv_process_traceset_seek_n_forward(tsc, 200000, NULL, NULL, NULL, NULL, NULL, NULL); - lttv_traceset_context_position_save(tsc, saved_pos); - t0 = get_time(); - lttv_process_traceset_seek_n_backward(tsc, 100301, - seek_back_default_offset, - (seek_time_fct)lttv_state_traceset_seek_time_closest, NULL, - NULL, NULL, NULL, NULL, NULL); - t1 = get_time(); - g_message("Seek backward 100301 events (with seek closest) in %g seconds", - t1 - t0); - count = lttv_process_traceset_seek_n_forward(tsc, 100301, NULL, NULL, NULL, NULL, NULL, NULL); - - if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) { - g_warning("Problem with seek_n with state seek time! Positions differ. (6)"); - } - - lttv_traceset_context_position_destroy(saved_pos); - } - - if(a_test10 || a_test_all) { - g_message("Running test 10 : check seek traceset context position"); - LttvTracesetContext *tsc = &ts->parent; - LttvTracesetContextPosition *saved_pos = - lttv_traceset_context_position_new(tsc); - - lttv_process_traceset_seek_time(tsc, ltt_time_zero); - lttv_process_traceset_seek_n_forward(tsc, 200000, NULL, NULL, NULL, NULL, NULL, NULL); - lttv_traceset_context_position_save(tsc, saved_pos); - if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) != 0) - g_critical("Error in seek position. (1)"); - - lttv_process_traceset_seek_time(tsc, ltt_time_infinite); - lttv_process_traceset_seek_n_backward(tsc, 500, - seek_back_default_offset, lttv_process_traceset_seek_time, NULL, - NULL, NULL, NULL, NULL, NULL); - lttv_traceset_context_position_save(tsc, saved_pos); - - if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) != 0) - g_critical("Error in seek position. (2)"); - - lttv_traceset_context_position_destroy(saved_pos); - } - - if(a_trace_event) lttv_hooks_remove_data(event_hook, trace_event, NULL); - - g_free(save_state.write_time); - g_free(a_event_position); - lttv_context_fini(tc); - g_object_unref(tscs); - - if(lttv_profile_memory) { - g_message("Memory summary at the end of batchtest"); - g_mem_profile(); - } - - g_info("BatchTest end process traceset"); - return 0; + /* Run through all events computing the state and writing it out + periodically. */ + + SaveState save_state; + + save_state.interval = a_sample_interval; + save_state.size = a_sample_number; + save_state.fp = stderr; + save_state.write_time = g_new(LttTime, a_sample_number); + + + if(a_test3 || a_test_all) { + for(i = 0 ; i < 2 ; i++) { + save_state.count = 0; + save_state.position = 0; + save_state.version = i; + lttv_state_add_event_hooks(ts); + lttv_hooks_add(event_hook, save_state_event, &save_state, + LTTV_PRIO_DEFAULT); + t = run_one_test(ts, ltt_time_zero, max_time); + lttv_state_remove_event_hooks(ts); + lttv_hooks_remove_data(event_hook, save_state_event, &save_state); + g_warning("Processing while updating/writing state (%g seconds)", t); + } + } + + /* Run through all events computing the stats. */ + + if(a_test4 || a_test_all) { + if(lttv_profile_memory) { + g_message("Memory summary before computing stats"); + g_mem_profile(); + } + + lttv_stats_add_event_hooks(tscs); + t = run_one_test(ts, ltt_time_zero, max_time); + lttv_stats_remove_event_hooks(tscs); + g_message("Processing trace while counting stats (%g seconds)", t); + + if(lttv_profile_memory) { + g_message("Memory summary after computing stats"); + g_mem_profile(); + } + + lttv_stats_sum_traceset(tscs, ltt_time_infinite); + + if(lttv_profile_memory) { + g_message("Memory summary after summing stats"); + g_mem_profile(); + } + + lttv_context_fini(tc); + lttv_context_init(tc, traceset); + + if(lttv_profile_memory) { + g_message("Memory summary after cleaning up the stats"); + g_mem_profile(); + } + } + + /* Run through all events computing the state and stats. */ + + if(a_test5 || a_test_all) { + if(lttv_profile_memory) { + g_message("Memory summary before computing state and stats"); + g_mem_profile(); + } + + lttv_state_add_event_hooks(ts); + lttv_stats_add_event_hooks(tscs); + t = run_one_test(ts, ltt_time_zero, max_time); + lttv_state_remove_event_hooks(ts); + lttv_stats_remove_event_hooks(tscs); + g_message("Processing trace while counting state and stats (%g seconds)", t); + + if(lttv_profile_memory) { + g_message("Memory summary after computing and state and stats"); + g_mem_profile(); + } + + lttv_context_fini(tc); + lttv_context_init(tc, traceset); + + if(lttv_profile_memory) { + g_message("Memory summary after cleaning up the stats"); + g_mem_profile(); + } + } + + /* Run through all events computing and saving the state. */ + + if(a_trace_event) lttv_hooks_add(event_hook, trace_event, NULL, + LTTV_PRIO_DEFAULT); + + if(a_test6 || a_test_all) { + if(lttv_profile_memory) { + g_message("Memory summary before computing and saving state"); + g_mem_profile(); + } + + lttv_state_add_event_hooks(ts); + lttv_state_save_add_event_hooks(ts); + if(a_save_state_copy) + lttv_hooks_add(event_hook, save_state_copy_event, &save_state, + LTTV_PRIO_DEFAULT); + t = run_one_test(ts, ltt_time_zero, max_time); + lttv_state_remove_event_hooks(ts); + lttv_state_save_remove_event_hooks(ts); + if(a_save_state_copy) + lttv_hooks_remove_data(event_hook,save_state_copy_event, &save_state); + + g_message("Processing trace while updating/saving state (%g seconds)", t); + + if(lttv_profile_memory) { + g_message("Memory summary after computing/saving state"); + g_mem_profile(); + } + } + + /* Seek a few times to each saved position */ + + if((a_test7 && a_test3) || a_test_all) { + g_assert(a_seek_number >= 0); + for(i = 0 ; i < (guint)a_seek_number ; i++) { + gint reverse_j; /* just to make sure j is unsigned */ + for(reverse_j = save_state.position - 1 ; reverse_j >= 0 ; reverse_j--) { + j = (guint)reverse_j; + lttv_state_add_event_hooks(ts); + t = run_one_test(ts, save_state.write_time[j], + save_state.write_time[j]); + lttv_state_remove_event_hooks(ts); + g_message("Seeking to %lu.%lu (%g seconds)", + save_state.write_time[j].tv_sec, + save_state.write_time[j].tv_nsec, t); + + if(a_save_sample != NULL) { + filename = g_string_new(""); + g_string_printf(filename, "%s.%d.xml.bak%d", a_save_sample, j, i); + fp = fopen(filename->str, "w"); + if(fp == NULL) g_error("Cannot open %s", filename->str); + g_string_free(filename, TRUE); + lttv_state_write((LttvTraceState *)tc->traces[0], + save_state.write_time[j], fp); + fclose(fp); + } + //else lttv_state_write((LttvTraceState *)tc->traces[0], + // save_state.write_time[j], save_state.fp); + } + } + } + + /* Seek at specified interval, using states computed in 6, making + * sure that there is no more than the number of events between + * state save interval to read before getting there. + */ + + if((a_test8 && a_test6) || a_test_all) { + g_message("Running test 8 : check save interval"); + LttTime time = tc->time_span.start_time; + LttTime interval; + interval.tv_sec = 0; + interval.tv_nsec = 175674987; + guint count; + + while(ltt_time_compare(time, tc->time_span.end_time) < 0) { + //g_message("Seeking at time %u.%u", time.tv_sec, time.tv_nsec); + lttv_process_traceset_seek_time(&ts->parent, ltt_time_zero); + lttv_state_traceset_seek_time_closest(ts, time); + /* We add no hook to the traceset, not necessary */ + count = lttv_process_traceset_middle(&ts->parent, + time, G_MAXUINT, NULL); + g_info("Number of events to jump over : %u", count); + + if(count > LTTV_STATE_SAVE_INTERVAL) + g_warning("Oops! Save interval is %u and it took %u events to seek to a time %lu.%lu supposed to be closer from the last saved state.", + LTTV_STATE_SAVE_INTERVAL, count, time.tv_sec, time.tv_nsec); + time = ltt_time_add(time, interval); + } + + } + + if(a_test9 || a_test_all) { + double t0, t1; + /* Run seek_forward and seek_backward test */ + guint count; + LttvTracesetContext *tsc = &ts->parent; + LttvTracesetContextPosition *saved_pos = + lttv_traceset_context_position_new(tsc); + g_message("Running test 9 : seek_forward and seek_backward"); + lttv_process_traceset_seek_time(tsc, ltt_time_zero); + + count = lttv_process_traceset_seek_n_forward(tsc, 500, NULL, NULL, NULL, NULL, NULL, NULL); + g_assert(count == 500); + lttv_traceset_context_position_save(tsc, saved_pos); + t0 = get_time(); + count = lttv_process_traceset_seek_n_forward(tsc, 150000, NULL, NULL, NULL, NULL, NULL, NULL); + t1 = get_time(); + g_message("Seek forward 150000 events in %g seconds", t1 - t0); + g_assert(count == 150000); + t0 = get_time(); + count = lttv_process_traceset_seek_n_backward(tsc, 150000, + seek_back_default_offset, lttv_process_traceset_seek_time, NULL, + NULL, NULL, NULL, NULL, NULL); + t1 = get_time(); + g_message("Seek backward 150000 events in %g seconds", t1 - t0); + g_assert(count == 150000); + if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) { + g_warning("Problem with seek_n ! Positions differ. (1)"); + } + + lttv_process_traceset_seek_n_forward(tsc, 500, NULL, NULL, NULL, NULL, NULL, NULL); + lttv_traceset_context_position_save(tsc, saved_pos); + lttv_process_traceset_seek_n_forward(tsc, 15000, NULL, NULL, NULL, NULL, NULL, NULL); + lttv_process_traceset_seek_n_backward(tsc, 15005, + seek_back_default_offset, lttv_process_traceset_seek_time, NULL, + NULL, NULL, NULL, NULL, NULL); + lttv_process_traceset_seek_n_forward(tsc, 5, NULL, NULL, NULL, NULL, NULL, NULL); + if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) { + g_warning("Problem with seek_n ! Positions differ. (2)"); + } + + lttv_process_traceset_seek_time(tsc, ltt_time_infinite); + + count = lttv_process_traceset_seek_n_forward(tsc, 15000, NULL, NULL, NULL, NULL, NULL, NULL); + if(count > 0) + g_warning("Problem with seek_n ! Forward at end of traceset."); + + lttv_process_traceset_seek_time(tsc, ltt_time_infinite); + + lttv_traceset_context_position_save(tsc, saved_pos); + t0 = get_time(); + lttv_process_traceset_seek_n_backward(tsc, 300, + seek_back_default_offset, lttv_process_traceset_seek_time, NULL, + NULL, NULL, NULL, NULL, NULL); + t1 = get_time(); + g_message("Seek backward 300 events in %g seconds", t1 - t0); + count = lttv_process_traceset_seek_n_forward(tsc, 299, NULL, NULL, NULL, NULL, NULL, NULL); + count = lttv_process_traceset_seek_n_forward(tsc, 1, NULL, NULL, NULL, NULL, NULL, NULL); + + if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) { + g_warning("Problem with seek_n ! Positions differ. (4)"); + } + + lttv_traceset_context_position_save(tsc, saved_pos); + t0 = get_time(); + lttv_process_traceset_seek_n_backward(tsc, 10, + seek_back_default_offset, lttv_process_traceset_seek_time, NULL, + NULL, NULL, NULL, NULL, NULL); + t1 = get_time(); + g_message("Seek backward 10 events in %g seconds", t1 - t0); + t0 = get_time(); + count = lttv_process_traceset_seek_n_forward(tsc, 10, NULL, NULL, NULL, NULL, NULL, NULL); + t1 = get_time(); + g_message("Seek forward 10 events in %g seconds", t1 - t0); + + + /* try a volountary error */ + lttv_process_traceset_seek_time(tsc, ltt_time_infinite); + + lttv_traceset_context_position_save(tsc, saved_pos); + lttv_process_traceset_seek_n_backward(tsc, 301, + seek_back_default_offset, lttv_process_traceset_seek_time, NULL, + NULL, NULL, NULL, NULL, NULL); + count = lttv_process_traceset_seek_n_forward(tsc, 299, NULL, NULL, NULL, NULL, NULL, NULL); + count = lttv_process_traceset_seek_n_forward(tsc, 1, NULL, NULL, NULL, NULL, NULL, NULL); + + if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) == 0) { + g_warning("Problem with seek_n ! Positions _should_ differ. (5)"); + } + + /* Try a seek by closest time : Hint : try this one with and without states + * computed. */ + lttv_process_traceset_seek_time(tsc, ltt_time_zero); + count = lttv_process_traceset_seek_n_forward(tsc, 200000, NULL, NULL, NULL, NULL, NULL, NULL); + lttv_traceset_context_position_save(tsc, saved_pos); + t0 = get_time(); + lttv_process_traceset_seek_n_backward(tsc, 100301, + seek_back_default_offset, + (seek_time_fct)lttv_state_traceset_seek_time_closest, NULL, + NULL, NULL, NULL, NULL, NULL); + t1 = get_time(); + g_message("Seek backward 100301 events (with seek closest) in %g seconds", + t1 - t0); + count = lttv_process_traceset_seek_n_forward(tsc, 100301, NULL, NULL, NULL, NULL, NULL, NULL); + + if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos)) { + g_warning("Problem with seek_n with state seek time! Positions differ. (6)"); + } + + lttv_traceset_context_position_destroy(saved_pos); + } + + if(a_test10 || a_test_all) { + g_message("Running test 10 : check seek traceset context position"); + LttvTracesetContext *tsc = &ts->parent; + LttvTracesetContextPosition *saved_pos = + lttv_traceset_context_position_new(tsc); + + lttv_process_traceset_seek_time(tsc, ltt_time_zero); + lttv_process_traceset_seek_n_forward(tsc, 200000, NULL, NULL, NULL, NULL, NULL, NULL); + lttv_traceset_context_position_save(tsc, saved_pos); + if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) != 0) + g_critical("Error in seek position. (1)"); + + lttv_process_traceset_seek_time(tsc, ltt_time_infinite); + lttv_process_traceset_seek_n_backward(tsc, 500, + seek_back_default_offset, lttv_process_traceset_seek_time, NULL, + NULL, NULL, NULL, NULL, NULL); + lttv_traceset_context_position_save(tsc, saved_pos); + + if(lttv_traceset_context_ctx_pos_compare(tsc, saved_pos) != 0) + g_critical("Error in seek position. (2)"); + + lttv_traceset_context_position_destroy(saved_pos); + } + + if(a_trace_event) lttv_hooks_remove_data(event_hook, trace_event, NULL); + + g_free(save_state.write_time); + g_free(a_event_position); + lttv_context_fini(tc); + g_object_unref(tscs); + + if(lttv_profile_memory) { + g_message("Memory summary at the end of batchtest"); + g_mem_profile(); + } + + g_info("BatchTest end process traceset"); + return 0; } static void init() { - LttvAttributeValue value; - - LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); - gboolean retval; - - g_info("Init batchtest.c"); + LttvAttributeValue value; + + LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); + gboolean retval; + + g_info("Init batchtest.c"); + + /* Init GQuarks */ + QUARK_BLOCK_START = g_quark_from_string("block_start"); + QUARK_BLOCK_END = g_quark_from_string("block_end"); + + + lttv_option_add("trace", 't', + "add a trace to the trace set to analyse", + "pathname of the directory containing the trace", + LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL); + + a_trace_event = FALSE; - /* Init GQuarks */ - QUARK_BLOCK_START = g_quark_from_string("block_start"); - QUARK_BLOCK_END = g_quark_from_string("block_end"); - - - lttv_option_add("trace", 't', - "add a trace to the trace set to analyse", - "pathname of the directory containing the trace", - LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL); - - a_trace_event = FALSE; - - a_dump_tracefiles = NULL; - lttv_option_add("dump-tracefiles", 'D', - "Write event by event the content of tracefiles", - "basename for the files where to dump events", - LTTV_OPT_STRING, &a_dump_tracefiles, NULL, NULL); - - a_save_sample = NULL; - lttv_option_add("save-sample", 's', - "Save state samples to multiple files", - "basename for the files containing the state samples", - LTTV_OPT_STRING, &a_save_sample, NULL, NULL); - - a_save_state_copy = FALSE; - lttv_option_add("save-state-copy", 'S', "Write the state saved for seeking", - "", LTTV_OPT_NONE, &a_save_state_copy, NULL, NULL); - - a_save_interval = 100000; - lttv_option_add("save-interval", 'i', - "Interval between saving state", - "number of events before a block start triggers saving state", - LTTV_OPT_INT, &a_save_interval, NULL, NULL); - - a_sample_interval = 100000; - lttv_option_add("sample-interval", 'S', - "Interval between sampling state", - "number of events before sampling and writing state", - LTTV_OPT_INT, &a_sample_interval, NULL, NULL); - - a_sample_number = 20; - lttv_option_add("sample-number", 'N', - "Number of state samples", - "maximum number", - LTTV_OPT_INT, &a_sample_number, NULL, NULL); - - a_seek_number = 200; - lttv_option_add("seek-number", 'K', - "Number of seek", - "number", - LTTV_OPT_INT, &a_seek_number, NULL, NULL); - - a_test1 = FALSE; - lttv_option_add("test1", '1', "Test just counting events", "", - LTTV_OPT_NONE, &a_test1, NULL, NULL); - - a_test2 = FALSE; - lttv_option_add("test2", '2', "Test computing the state", "", - LTTV_OPT_NONE, &a_test2, NULL, NULL); - - a_test3 = FALSE; - lttv_option_add("test3", '3', "Test computing the state, writing out a few", - "", LTTV_OPT_NONE, &a_test3, NULL, NULL); - - a_test4 = FALSE; - lttv_option_add("test4", '4', "Test computing the stats", "", - LTTV_OPT_NONE, &a_test4, NULL, NULL); - - a_test5 = FALSE; - lttv_option_add("test5", '5', "Test computing the state and stats", "", - LTTV_OPT_NONE, &a_test5, NULL, NULL); - - a_test6 = FALSE; - lttv_option_add("test6", '6', "Test computing and saving the state", "", - LTTV_OPT_NONE, &a_test6, NULL, NULL); - - a_test7 = FALSE; - lttv_option_add("test7", '7', "Test seeking to positions written out in 3", - "", LTTV_OPT_NONE, &a_test7, NULL, NULL); - - a_test8 = FALSE; - lttv_option_add("test8", '8', "Test seeking to positions using saved states computed at 6 : check if number of events fits", - "", LTTV_OPT_NONE, &a_test8, NULL, NULL); - - a_test9 = FALSE; - lttv_option_add("test9", '9', "Test seeking backward/forward positions", - "", LTTV_OPT_NONE, &a_test9, NULL, NULL); - - a_test10 = FALSE; - lttv_option_add("test10", ' ', "Test seeking traceset by position", - "", LTTV_OPT_NONE, &a_test10, NULL, NULL); - - - - a_test_all = FALSE; - lttv_option_add("testall", 'a', "Run all tests ", "", - LTTV_OPT_NONE, &a_test_all, NULL, NULL); - - traceset = lttv_traceset_new(); - - before_traceset = lttv_hooks_new(); - after_traceset = lttv_hooks_new(); - before_trace = lttv_hooks_new(); - after_trace = lttv_hooks_new(); - before_tracefile = lttv_hooks_new(); - after_tracefile = lttv_hooks_new(); - //before_event = lttv_hooks_new(); - //after_event = lttv_hooks_new(); - event_hook = lttv_hooks_new(); - - - retval= lttv_iattribute_find_by_path(attributes, "hooks/traceset/before", - LTTV_POINTER, &value); - g_assert(retval); - *(value.v_pointer) = before_traceset; - retval= lttv_iattribute_find_by_path(attributes, "hooks/traceset/after", - LTTV_POINTER, &value); - g_assert(retval); - *(value.v_pointer) = after_traceset; - retval= lttv_iattribute_find_by_path(attributes, "hooks/trace/before", - LTTV_POINTER, &value); - g_assert(retval); - *(value.v_pointer) = before_trace; - retval= lttv_iattribute_find_by_path(attributes, "hooks/trace/after", - LTTV_POINTER, &value); - g_assert(retval); - *(value.v_pointer) = after_trace; - retval= lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before", - LTTV_POINTER, &value); - g_assert(retval); - *(value.v_pointer) = before_tracefile; - retval= lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after", - LTTV_POINTER, &value); - g_assert(retval); - *(value.v_pointer) = after_tracefile; - //retval= lttv_iattribute_find_by_path(attributes, "hooks/event/before", - // LTTV_POINTER, &value); - //*(value.v_pointer) = before_event; - //retval= lttv_iattribute_find_by_path(attributes, "hooks/event/after", - // LTTV_POINTER, &value); - //*(value.v_pointer) = after_event; - retval= lttv_iattribute_find_by_path(attributes, "hooks/event", - LTTV_POINTER, &value); - g_assert(retval); - *(value.v_pointer) = event_hook; - retval= lttv_iattribute_find_by_path(attributes, "hooks/main/before", - LTTV_POINTER, &value); - g_assert(retval); - g_assert((main_hooks = *(value.v_pointer)) != NULL); - lttv_hooks_add(main_hooks, process_traceset, NULL, LTTV_PRIO_DEFAULT); + a_dump_tracefiles = NULL; + lttv_option_add("dump-tracefiles", 'D', + "Write event by event the content of tracefiles", + "basename for the files where to dump events", + LTTV_OPT_STRING, &a_dump_tracefiles, NULL, NULL); + + a_save_sample = NULL; + lttv_option_add("save-sample", 's', + "Save state samples to multiple files", + "basename for the files containing the state samples", + LTTV_OPT_STRING, &a_save_sample, NULL, NULL); + + a_save_state_copy = FALSE; + lttv_option_add("save-state-copy", 'S', "Write the state saved for seeking", + "", LTTV_OPT_NONE, &a_save_state_copy, NULL, NULL); + + a_save_interval = 100000; + lttv_option_add("save-interval", 'i', + "Interval between saving state", + "number of events before a block start triggers saving state", + LTTV_OPT_INT, &a_save_interval, NULL, NULL); + + a_sample_interval = 100000; + lttv_option_add("sample-interval", 'S', + "Interval between sampling state", + "number of events before sampling and writing state", + LTTV_OPT_INT, &a_sample_interval, NULL, NULL); + + a_sample_number = 20; + lttv_option_add("sample-number", 'N', + "Number of state samples", + "maximum number", + LTTV_OPT_INT, &a_sample_number, NULL, NULL); + + a_seek_number = 200; + lttv_option_add("seek-number", 'K', + "Number of seek", + "number", + LTTV_OPT_INT, &a_seek_number, NULL, NULL); + + a_test1 = FALSE; + lttv_option_add("test1", '1', "Test just counting events", "", + LTTV_OPT_NONE, &a_test1, NULL, NULL); + + a_test2 = FALSE; + lttv_option_add("test2", '2', "Test computing the state", "", + LTTV_OPT_NONE, &a_test2, NULL, NULL); + + a_test3 = FALSE; + lttv_option_add("test3", '3', "Test computing the state, writing out a few", + "", LTTV_OPT_NONE, &a_test3, NULL, NULL); + + a_test4 = FALSE; + lttv_option_add("test4", '4', "Test computing the stats", "", + LTTV_OPT_NONE, &a_test4, NULL, NULL); + + a_test5 = FALSE; + lttv_option_add("test5", '5', "Test computing the state and stats", "", + LTTV_OPT_NONE, &a_test5, NULL, NULL); + + a_test6 = FALSE; + lttv_option_add("test6", '6', "Test computing and saving the state", "", + LTTV_OPT_NONE, &a_test6, NULL, NULL); + + a_test7 = FALSE; + lttv_option_add("test7", '7', "Test seeking to positions written out in 3", + "", LTTV_OPT_NONE, &a_test7, NULL, NULL); + + a_test8 = FALSE; + lttv_option_add("test8", '8', "Test seeking to positions using saved states computed at 6 : check if number of events fits", + "", LTTV_OPT_NONE, &a_test8, NULL, NULL); + + a_test9 = FALSE; + lttv_option_add("test9", '9', "Test seeking backward/forward positions", + "", LTTV_OPT_NONE, &a_test9, NULL, NULL); + + a_test10 = FALSE; + lttv_option_add("test10", ' ', "Test seeking traceset by position", + "", LTTV_OPT_NONE, &a_test10, NULL, NULL); + + + + a_test_all = FALSE; + lttv_option_add("testall", 'a', "Run all tests ", "", + LTTV_OPT_NONE, &a_test_all, NULL, NULL); + + traceset = lttv_traceset_new(); + + before_traceset = lttv_hooks_new(); + after_traceset = lttv_hooks_new(); + before_trace = lttv_hooks_new(); + after_trace = lttv_hooks_new(); + before_tracefile = lttv_hooks_new(); + after_tracefile = lttv_hooks_new(); + //before_event = lttv_hooks_new(); + //after_event = lttv_hooks_new(); + event_hook = lttv_hooks_new(); + + + retval= lttv_iattribute_find_by_path(attributes, "hooks/traceset/before", + LTTV_POINTER, &value); + g_assert(retval); + *(value.v_pointer) = before_traceset; + retval= lttv_iattribute_find_by_path(attributes, "hooks/traceset/after", + LTTV_POINTER, &value); + g_assert(retval); + *(value.v_pointer) = after_traceset; + retval= lttv_iattribute_find_by_path(attributes, "hooks/trace/before", + LTTV_POINTER, &value); + g_assert(retval); + *(value.v_pointer) = before_trace; + retval= lttv_iattribute_find_by_path(attributes, "hooks/trace/after", + LTTV_POINTER, &value); + g_assert(retval); + *(value.v_pointer) = after_trace; + retval= lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before", + LTTV_POINTER, &value); + g_assert(retval); + *(value.v_pointer) = before_tracefile; + retval= lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after", + LTTV_POINTER, &value); + g_assert(retval); + *(value.v_pointer) = after_tracefile; + //retval= lttv_iattribute_find_by_path(attributes, "hooks/event/before", + // LTTV_POINTER, &value); + //*(value.v_pointer) = before_event; + //retval= lttv_iattribute_find_by_path(attributes, "hooks/event/after", + // LTTV_POINTER, &value); + //*(value.v_pointer) = after_event; + retval= lttv_iattribute_find_by_path(attributes, "hooks/event", + LTTV_POINTER, &value); + g_assert(retval); + *(value.v_pointer) = event_hook; + retval= lttv_iattribute_find_by_path(attributes, "hooks/main/before", + LTTV_POINTER, &value); + g_assert(retval); + g_assert((main_hooks = *(value.v_pointer)) != NULL); + lttv_hooks_add(main_hooks, process_traceset, NULL, LTTV_PRIO_DEFAULT); } static void destroy() { - guint i, nb; - - LttvTrace *trace; - - g_info("Destroy batchAnalysis.c"); - - lttv_option_remove("trace"); - lttv_option_remove("dump-tracefiles"); - lttv_option_remove("save-sample"); - lttv_option_remove("save-state-copy"); - lttv_option_remove("sample-interval"); - lttv_option_remove("sample-number"); - lttv_option_remove("seek-number"); - lttv_option_remove("save-interval"); - lttv_option_remove("test1"); - lttv_option_remove("test2"); - lttv_option_remove("test3"); - lttv_option_remove("test4"); - lttv_option_remove("test5"); - lttv_option_remove("test6"); - lttv_option_remove("test7"); - lttv_option_remove("test8"); - lttv_option_remove("test9"); - lttv_option_remove("test10"); - lttv_option_remove("testall"); - - lttv_hooks_destroy(before_traceset); - lttv_hooks_destroy(after_traceset); - lttv_hooks_destroy(before_trace); - lttv_hooks_destroy(after_trace); - lttv_hooks_destroy(before_tracefile); - lttv_hooks_destroy(after_tracefile); - //lttv_hooks_destroy(before_event); - //lttv_hooks_destroy(after_event); - lttv_hooks_destroy(event_hook); - lttv_hooks_remove_data(main_hooks, process_traceset, NULL); - - nb = lttv_traceset_number(traceset); - for(i = 0 ; i < nb ; i++) { - trace = lttv_traceset_get(traceset, i); - lttv_traceset_remove(traceset,i); - ltt_trace_close(lttv_trace(trace)); - lttv_trace_destroy(trace); - } - - lttv_traceset_destroy(traceset); + guint i, nb; + + LttvTrace *trace; + + g_info("Destroy batchAnalysis.c"); + + lttv_option_remove("trace"); + lttv_option_remove("dump-tracefiles"); + lttv_option_remove("save-sample"); + lttv_option_remove("save-state-copy"); + lttv_option_remove("sample-interval"); + lttv_option_remove("sample-number"); + lttv_option_remove("seek-number"); + lttv_option_remove("save-interval"); + lttv_option_remove("test1"); + lttv_option_remove("test2"); + lttv_option_remove("test3"); + lttv_option_remove("test4"); + lttv_option_remove("test5"); + lttv_option_remove("test6"); + lttv_option_remove("test7"); + lttv_option_remove("test8"); + lttv_option_remove("test9"); + lttv_option_remove("test10"); + lttv_option_remove("testall"); + + lttv_hooks_destroy(before_traceset); + lttv_hooks_destroy(after_traceset); + lttv_hooks_destroy(before_trace); + lttv_hooks_destroy(after_trace); + lttv_hooks_destroy(before_tracefile); + lttv_hooks_destroy(after_tracefile); + //lttv_hooks_destroy(before_event); + //lttv_hooks_destroy(after_event); + lttv_hooks_destroy(event_hook); + lttv_hooks_remove_data(main_hooks, process_traceset, NULL); + + nb = lttv_traceset_number(traceset); + for(i = 0 ; i < nb ; i++) { + trace = lttv_traceset_get(traceset, i); + lttv_traceset_remove(traceset,i); + ltt_trace_close(lttv_trace(trace)); + lttv_trace_destroy(trace); + } + + lttv_traceset_destroy(traceset); } LTTV_MODULE("batchtest", "Batch processing of a trace for tests", \ - "Run through a trace calling all the registered hooks for tests", \ - init, destroy, "state", "stats", "option" ) + "Run through a trace calling all the registered hooks for tests", \ + init, destroy, "state", "stats", "option" ) diff --git a/lttv/lttv/contextmacros.h b/lttv/lttv/contextmacros.h index b6276e98..1877ea31 100644 --- a/lttv/lttv/contextmacros.h +++ b/lttv/lttv/contextmacros.h @@ -35,7 +35,7 @@ * returns : (LttvTraceContext *) */ #define LTTV_TRACESET_CONTEXT_GET_TRACE_CONTEXT(tsc, trace_num)\ - (tsc->traces[trace_num]) + (tsc->traces[trace_num]) /* LTTV_TRACESET_CONTEXT_GET_NUM_TRACES * @@ -43,7 +43,7 @@ * returns : (guint) the number of traces */ #define LTTV_TRACESET_CONTEXT_GET_NUM_TRACES(tsc)\ - (lttv_traceset_number(tsc->ts)) + (lttv_traceset_number(tsc->ts)) /* LTTV_TRACESET_CONTEXT_GET_TRACESET_STATS * @@ -51,7 +51,7 @@ * returns : (LttvTracesetStats*) */ #define LTTV_TRACESET_CONTEXT_GET_TRACESET_STATS(tsc)\ - ((LttvTracesetStats*)tsc) + ((LttvTracesetStats*)tsc) /************ TraceContext get methods ***************/ @@ -62,7 +62,7 @@ * returns : (LttvTracesetContext *) */ #define LTTV_TRACE_CONTEXT_GET_TRACESET_CONTEXT(tc)\ - (tc->ts_context) + (tc->ts_context) /* LTTV_TRACE_CONTEXT_GET_TRACE_INDEX * @@ -70,7 +70,7 @@ * returns : (guint) trace context index in its traceset context. */ #define LTTV_TRACE_CONTEXT_GET_TRACE_INDEX(tc)\ - (tc->index) + (tc->index) @@ -80,7 +80,7 @@ * returns : (LttvTraceState *) */ #define LTTV_TRACE_CONTEXT_GET_TRACE_STATE(tc)\ - ((LttvTraceState*)tc) + ((LttvTraceState*)tc) /* LTTV_TRACE_CONTEXT_GET_TRACE_STATS * @@ -88,7 +88,7 @@ * returns : (LttvTraceStats *) */ #define LTTV_TRACE_CONTEXT_GET_TRACE_STATS(tc)\ - ((LttvTraceStats*)tc) + ((LttvTraceStats*)tc) /* LTTV_TRACE_CONTEXT_GET_CPU_TRACEFILE_CONTEXT * @@ -97,7 +97,7 @@ * returns : (LttvTracefileContext*) */ #define LTTV_TRACE_CONTEXT_GET_CPU_TRACEFILE_CONTEXT(tc, cpu_index)\ - ( tc->tracefiles[cpu_index + ltt_trace_control_tracefile_number(tc->t)] ) + ( tc->tracefiles[cpu_index + ltt_trace_control_tracefile_number(tc->t)] ) /* LTTV_TRACE_CONTEXT_GET_NUMBER_CPU * @@ -105,7 +105,7 @@ * returns : (guint) number_cpu */ #define LTTV_TRACE_CONTEXT_GET_NUMBER_CPU(tc)\ - ( ltt_trace_per_cpu_tracefile_number(tc->t) ) + ( ltt_trace_per_cpu_tracefile_number(tc->t) ) /* LTTV_TRACE_CONTEXT_GET_CONTROL_TRACEFILE_CONTEXT @@ -115,7 +115,7 @@ * returns : (LttvTracefileContext*) */ #define LTTV_TRACE_CONTEXT_GET_CONTROL_TRACEFILE_CONTEXT(tc, control_index)\ - (tc->tracefiles[control_index]) + (tc->tracefiles[control_index]) /* LTTV_TRACE_CONTEXT_GET_NUMBER_CONTROL * @@ -123,7 +123,7 @@ * returns : (guint) number_control */ #define LTTV_TRACE_CONTEXT_GET_NUMBER_CONTROL(tc)\ - ( ltt_trace_control_tracefile_number(tc->t) ) + ( ltt_trace_control_tracefile_number(tc->t) ) /* LTTV_TRACE_CONTEXT_GET_TRACE * @@ -133,7 +133,7 @@ * NOTE : see traceset.h for LttvTrace methods */ #define LTTV_TRACE_CONTEXT_GET_TRACE(tc)\ - (tc->vt) + (tc->vt) @@ -147,7 +147,7 @@ * returns : (LttvTraceContext*) */ #define LTTV_TRACEFILE_CONTEXT_GET_TRACE_CONTEXT(tfc)\ - (tfc->t_context) + (tfc->t_context) /* LTTV_TRACEFILE_CONTEXT_GET_EVENT * @@ -155,7 +155,7 @@ * returns : (LttEvent *) */ #define LTTV_TRACEFILE_CONTEXT_GET_EVENT(tfc)\ - (tfc->e) + (tfc->e) /* LTTV_TRACEFILE_CONTEXT_GET_TRACEFILE_STATE * @@ -163,7 +163,7 @@ * returns : (LttvTracefileState *) */ #define LTTV_TRACEFILE_CONTEXT_GET_TRACEFILE_STATE(tfc)\ - ((LttvTracefileState*)tfc) + ((LttvTracefileState*)tfc) /* LTTV_TRACEFILE_CONTEXT_GET_TRACEFILE_STATS * @@ -171,7 +171,7 @@ * returns : (LttvTracefileStats *) */ #define LTTV_TRACEFILE_CONTEXT_GET_TRACEFILE_STATS(tfc)\ - ((LttvTracefileStats*)tfc) + ((LttvTracefileStats*)tfc) /* LTTV_TRACEFILE_CONTEXT_GET_TRACEFILE_INDEX * @@ -184,9 +184,9 @@ * returns : (guint) cpu_index or control_index. */ #define LTTV_TRACEFILE_CONTEXT_GET_TRACEFILE_INDEX(tfc)\ - (tfc->control?\ - tfc->index:\ - tfc->index-ltt_trace_control_tracefile_number(tfc->t_context->t)) + (tfc->control?\ + tfc->index:\ + tfc->index-ltt_trace_control_tracefile_number(tfc->t_context->t)) @@ -199,7 +199,7 @@ * */ #define LTTV_TRACE_STATE_GET_TRACE_CONTEXT(tse)\ - ((LttvTraceContext*)tse) + ((LttvTraceContext*)tse) /* LTTV_TRACE_STATE_GET_EVENTTYPE_NAME * @@ -210,7 +210,7 @@ * NOTE : use g_quark_to_string to convert a GQuark into a static char * */ #define LTTV_TRACE_STATE_GET_EVENTTYPE_NAME(tse, eventtype_number)\ - (tse->eventtype_names[eventtype_number]) + (tse->eventtype_names[eventtype_number]) /* LTTV_TRACE_STATE_GET_SYSCALL_NAME * @@ -221,7 +221,7 @@ * NOTE : use g_quark_to_string to convert a GQuark into a static char * */ #define LTTV_TRACE_STATE_GET_SYSCALL_NAME(tse, syscall_number)\ - (tse->syscall_names[syscall_number]) + (tse->syscall_names[syscall_number]) /* LTTV_TRACE_STATE_GET_TRAP_NAME * @@ -232,7 +232,7 @@ * NOTE : use g_quark_to_string to convert a GQuark into a static char * */ #define LTTV_TRACE_STATE_GET_TRAP_NAME(tse, trap_number)\ - (tse->trap_names[trap_number]) + (tse->trap_names[trap_number]) /* LTTV_TRACE_STATE_GET_IRQ_NAME * @@ -243,7 +243,7 @@ * NOTE : use g_quark_to_string to convert a GQuark into a static char * */ #define LTTV_TRACE_STATE_GET_IRQ_NAME(tse, irq_number)\ - (tse->irq_names[irq_number]) + (tse->irq_names[irq_number]) /* LTTV_TRACE_STATE_GET_PROCESS_STATE @@ -259,10 +259,10 @@ * on any cpu of the trace. */ #define LTTV_TRACE_STATE_GET_PROCESS_STATE(tse, pid, cpu_index)\ - (lttv_state_find_process( \ - (LttvTraceFileState*)tse->parent->tracefiles[\ - cpu_index+\ - ltt_trace_control_tracefile_number((LttvTraceContext*)tse->t)], pid)) + (lttv_state_find_process( \ + (LttvTraceFileState*)tse->parent->tracefiles[\ + cpu_index+\ + ltt_trace_control_tracefile_number((LttvTraceContext*)tse->t)], pid)) /* LTTV_TRACE_STATE_GET_NUMBER_CPU @@ -271,7 +271,7 @@ * returns : (guint) number_cpu */ #define LTTV_TRACE_STATE_GET_NUMBER_CPU(tse)\ - ( ltt_trace_per_cpu_tracefile_number((LttvTraceState*)tse->t) ) + ( ltt_trace_per_cpu_tracefile_number((LttvTraceState*)tse->t) ) @@ -285,7 +285,7 @@ * */ #define LTTV_TRACEFILE_STATE_GET_TRACEFILE_CONTEXT(tfse)\ - ((LttvTracefileContext*)tfse) + ((LttvTracefileContext*)tfse) /* LTTV_TRACEFILE_STATE_GET_CURRENT_PROCESS_STATE @@ -296,7 +296,7 @@ * returns : (LttvProcessState *) */ #define LTTV_TRACEFILE_STATE_GET_CURRENT_PROCESS_STATE(tfse)\ - (tfse->process) + (tfse->process) /* LTTV_TRACEFILE_STATE_GET_CPU_NAME * @@ -306,7 +306,7 @@ * NOTE : use g_quark_to_string to convert a GQuark into a static char * */ #define LTTV_TRACEFILE_STATE_GET_CPU_NAME(tfse)\ - (tfse->cpu_name) + (tfse->cpu_name) /* LTTV_TRACEFILE_STATE_GET_PROCESS_STATE @@ -321,7 +321,7 @@ * on any cpu of the trace. */ #define LTTV_TRACEFILE_STATE_GET_PROCESS_STATE(tfse, pid)\ - (lttv_state_find_process(tfse, pid)) + (lttv_state_find_process(tfse, pid)) @@ -337,7 +337,7 @@ * returns : (LttvExecutionState*) */ #define LTTV_PROCESS_STATE_GET_EXECUTION_STATE(pse)\ - (pse->state) + (pse->state) /* LTTV_PROCESS_STATE_GET_NESTED_EXECUTION_STATE * @@ -346,7 +346,7 @@ * returns : (LttvExecutionState*) */ #define LTTV_PROCESS_STATE_GET_NESTED_EXECUTION_STATE(pse, num_nest)\ - (&g_array_index(pse->execution_stack,LttvExecutionState,num_nest)) + (&g_array_index(pse->execution_stack,LttvExecutionState,num_nest)) /* LTTV_PROCESS_STATE_GET_NUM_NESTED_EXECUTION_STATES @@ -357,7 +357,7 @@ * returns : (guint) */ #define LTTV_PROCESS_STATE_GET_NUM_NESTED_EXECUTION_STATES(pse)\ - (pse->execution_stack->len) + (pse->execution_stack->len) /************ ExecutionState get methods ***************/ diff --git a/lttv/lttv/filter.c b/lttv/lttv/filter.c index a91cbf21..29721d4d 100644 --- a/lttv/lttv/filter.c +++ b/lttv/lttv/filter.c @@ -89,36 +89,36 @@ * Constructor for LttvSimpleExpression * @return pointer to new LttvSimpleExpression */ -LttvSimpleExpression* -lttv_simple_expression_new() { +LttvSimpleExpression* lttv_simple_expression_new() +{ - LttvSimpleExpression* se = g_new(LttvSimpleExpression,1); + LttvSimpleExpression* se = g_new(LttvSimpleExpression,1); - se->field = LTTV_FILTER_UNDEFINED; - se->op = NULL; - se->offset = 0; + se->field = LTTV_FILTER_UNDEFINED; + se->op = NULL; + se->offset = 0; - return se; + return se; } /* * Keeps the array order. */ static inline gpointer ltt_g_ptr_array_remove_index_slow(GPtrArray *fp, - int index) + int index) { - gpointer ptr; - int i; - - if (fp->len == 0) - return NULL; - - ptr = g_ptr_array_index(fp, index); - for (i = index; i < fp->len - 1; i++) { - g_ptr_array_index(fp, i) = g_ptr_array_index(fp, i + 1); - } - g_ptr_array_remove_index(fp, fp->len - 1); - return ptr; + gpointer ptr; + int i; + + if (fp->len == 0) + return NULL; + + ptr = g_ptr_array_index(fp, index); + for (i = index; i < fp->len - 1; i++) { + g_ptr_array_index(fp, i) = g_ptr_array_index(fp, i + 1); + } + g_ptr_array_remove_index(fp, fp->len - 1); + return ptr; } /** @@ -131,165 +131,166 @@ static inline gpointer ltt_g_ptr_array_remove_index_slow(GPtrArray *fp, * @param se current simple expression * @return success/failure of operation */ -gboolean -lttv_simple_expression_assign_field(GPtrArray* fp, LttvSimpleExpression* se) { - - GString* f = NULL; - - if(fp->len < 2) return FALSE; - f=ltt_g_ptr_array_remove_index_slow(fp,0); - g_assert(f); - - - /* - * Parse through the specified - * hardcoded fields. - * - * Take note however that the - * 'event' subfields might change - * depending on values specified - * in core.xml file. Hence, if - * none of the subfields in the - * array match the hardcoded - * subfields, it will be considered - * as a dynamic field - */ - - if(!g_strcasecmp(f->str,"trace") ) { - /* - * Possible values: - * trace.name - */ - g_string_free(f,TRUE); - f=ltt_g_ptr_array_remove_index_slow(fp,0); - if(!g_strcasecmp(f->str,"name")) { - se->field = LTTV_FILTER_TRACE_NAME; - } - } else if(!g_strcasecmp(f->str,"traceset") ) { - /* - * FIXME: not yet implemented ! - */ - } else if(!g_strcasecmp(f->str,"tracefile") - || !g_strcasecmp(f->str,"channel") ) { - /* - * Possible values: - * tracefile.name - * channel.name - */ - g_string_free(f,TRUE); - f=ltt_g_ptr_array_remove_index_slow(fp,0); - if(!g_strcasecmp(f->str,"name")) { - se->field = LTTV_FILTER_TRACEFILE_NAME; - } - } else if(!g_strcasecmp(f->str,"state") ) { - /* - * Possible values: - * state.pid - * state.ppid - * state.creation_time - * state.insertion_time - * state.process_name - * state.thread_brand - * state.execution_mode - * state.execution_submode - * state.process_status - * state.cpu - */ - g_string_free(f,TRUE); - f=ltt_g_ptr_array_remove_index_slow(fp,0); - if(!g_strcasecmp(f->str,"pid") ) { - se->field = LTTV_FILTER_STATE_PID; - } - else if(!g_strcasecmp(f->str,"ppid") ) { - se->field = LTTV_FILTER_STATE_PPID; - } - else if(!g_strcasecmp(f->str,"creation_time") ) { - se->field = LTTV_FILTER_STATE_CT; - } - else if(!g_strcasecmp(f->str,"insertion_time") ) { - se->field = LTTV_FILTER_STATE_IT; - } - else if(!g_strcasecmp(f->str,"process_name") ) { - se->field = LTTV_FILTER_STATE_P_NAME; - } - else if(!g_strcasecmp(f->str,"thread_brand") ) { - se->field = LTTV_FILTER_STATE_T_BRAND; - } - else if(!g_strcasecmp(f->str,"execution_mode") ) { - se->field = LTTV_FILTER_STATE_EX_MODE; - } - else if(!g_strcasecmp(f->str,"execution_submode") ) { - se->field = LTTV_FILTER_STATE_EX_SUBMODE; - } - else if(!g_strcasecmp(f->str,"process_status") ) { - se->field = LTTV_FILTER_STATE_P_STATUS; - } - else if(!g_strcasecmp(f->str,"cpu") ) { - se->field = LTTV_FILTER_STATE_CPU; - } - } else if(!g_strcasecmp(f->str,"event") ) { - /* - * Possible values: - * event.name - * event.channel - * event.category - * event.time - * event.tsc - * event.target_pid - * event.field - */ - g_string_free(f,TRUE); - f=ltt_g_ptr_array_remove_index_slow(fp,0); - - if(!g_strcasecmp(f->str,"name") ) { - se->field = LTTV_FILTER_EVENT_NAME; - } - else if(!g_strcasecmp(f->str,"subname") ) { - se->field = LTTV_FILTER_EVENT_SUBNAME; - } - else if(!g_strcasecmp(f->str,"category") ) { - /* - * FIXME: Category not yet functional in lttv - */ - se->field = LTTV_FILTER_EVENT_CATEGORY; - } - else if(!g_strcasecmp(f->str,"time") ) { - se->field = LTTV_FILTER_EVENT_TIME; - } - else if(!g_strcasecmp(f->str,"tsc") ) { - se->field = LTTV_FILTER_EVENT_TSC; - } - else if(!g_strcasecmp(f->str,"target_pid") ) { - se->field = LTTV_FILTER_EVENT_TARGET_PID; - } - else if(!g_strcasecmp(f->str,"field") ) { - se->field = LTTV_FILTER_EVENT_FIELD; - g_string_free(f,TRUE); - f=ltt_g_ptr_array_remove_index_slow(fp,0); - - } else { - //g_string_free(f,TRUE); - //f=ltt_g_ptr_array_remove_index_slow(fp,0); - g_warning("Unknown event filter subtype %s", f->str); - } - } else { - g_string_free(f,TRUE); - f=ltt_g_ptr_array_remove_index_slow(fp,0); - - g_warning("Unrecognized field in filter string"); - } - - /* free memory for last string */ - g_string_free(f,TRUE); - - /* array should be empty */ - g_assert(fp->len == 0); +gboolean lttv_simple_expression_assign_field(GPtrArray* fp, + LttvSimpleExpression* se) +{ + + GString* f = NULL; + + if(fp->len < 2) return FALSE; + f=ltt_g_ptr_array_remove_index_slow(fp,0); + g_assert(f); + + + /* + * Parse through the specified + * hardcoded fields. + * + * Take note however that the + * 'event' subfields might change + * depending on values specified + * in core.xml file. Hence, if + * none of the subfields in the + * array match the hardcoded + * subfields, it will be considered + * as a dynamic field + */ + + if(!g_strcasecmp(f->str,"trace") ) { + /* + * Possible values: + * trace.name + */ + g_string_free(f,TRUE); + f=ltt_g_ptr_array_remove_index_slow(fp,0); + if(!g_strcasecmp(f->str,"name")) { + se->field = LTTV_FILTER_TRACE_NAME; + } + } else if(!g_strcasecmp(f->str,"traceset") ) { + /* + * FIXME: not yet implemented ! + */ + } else if(!g_strcasecmp(f->str,"tracefile") + || !g_strcasecmp(f->str,"channel") ) { + /* + * Possible values: + * tracefile.name + * channel.name + */ + g_string_free(f,TRUE); + f=ltt_g_ptr_array_remove_index_slow(fp,0); + if(!g_strcasecmp(f->str,"name")) { + se->field = LTTV_FILTER_TRACEFILE_NAME; + } + } else if(!g_strcasecmp(f->str,"state") ) { + /* + * Possible values: + * state.pid + * state.ppid + * state.creation_time + * state.insertion_time + * state.process_name + * state.thread_brand + * state.execution_mode + * state.execution_submode + * state.process_status + * state.cpu + */ + g_string_free(f,TRUE); + f=ltt_g_ptr_array_remove_index_slow(fp,0); + if(!g_strcasecmp(f->str,"pid") ) { + se->field = LTTV_FILTER_STATE_PID; + } + else if(!g_strcasecmp(f->str,"ppid") ) { + se->field = LTTV_FILTER_STATE_PPID; + } + else if(!g_strcasecmp(f->str,"creation_time") ) { + se->field = LTTV_FILTER_STATE_CT; + } + else if(!g_strcasecmp(f->str,"insertion_time") ) { + se->field = LTTV_FILTER_STATE_IT; + } + else if(!g_strcasecmp(f->str,"process_name") ) { + se->field = LTTV_FILTER_STATE_P_NAME; + } + else if(!g_strcasecmp(f->str,"thread_brand") ) { + se->field = LTTV_FILTER_STATE_T_BRAND; + } + else if(!g_strcasecmp(f->str,"execution_mode") ) { + se->field = LTTV_FILTER_STATE_EX_MODE; + } + else if(!g_strcasecmp(f->str,"execution_submode") ) { + se->field = LTTV_FILTER_STATE_EX_SUBMODE; + } + else if(!g_strcasecmp(f->str,"process_status") ) { + se->field = LTTV_FILTER_STATE_P_STATUS; + } + else if(!g_strcasecmp(f->str,"cpu") ) { + se->field = LTTV_FILTER_STATE_CPU; + } + } else if(!g_strcasecmp(f->str,"event") ) { + /* + * Possible values: + * event.name + * event.channel + * event.category + * event.time + * event.tsc + * event.target_pid + * event.field + */ + g_string_free(f,TRUE); + f=ltt_g_ptr_array_remove_index_slow(fp,0); + + if(!g_strcasecmp(f->str,"name") ) { + se->field = LTTV_FILTER_EVENT_NAME; + } + else if(!g_strcasecmp(f->str,"subname") ) { + se->field = LTTV_FILTER_EVENT_SUBNAME; + } + else if(!g_strcasecmp(f->str,"category") ) { + /* + * FIXME: Category not yet functional in lttv + */ + se->field = LTTV_FILTER_EVENT_CATEGORY; + } + else if(!g_strcasecmp(f->str,"time") ) { + se->field = LTTV_FILTER_EVENT_TIME; + } + else if(!g_strcasecmp(f->str,"tsc") ) { + se->field = LTTV_FILTER_EVENT_TSC; + } + else if(!g_strcasecmp(f->str,"target_pid") ) { + se->field = LTTV_FILTER_EVENT_TARGET_PID; + } + else if(!g_strcasecmp(f->str,"field") ) { + se->field = LTTV_FILTER_EVENT_FIELD; + g_string_free(f,TRUE); + f=ltt_g_ptr_array_remove_index_slow(fp,0); + + } else { + //g_string_free(f,TRUE); + //f=ltt_g_ptr_array_remove_index_slow(fp,0); + g_warning("Unknown event filter subtype %s", f->str); + } + } else { + g_string_free(f,TRUE); + f=ltt_g_ptr_array_remove_index_slow(fp,0); + + g_warning("Unrecognized field in filter string"); + } + + /* free memory for last string */ + g_string_free(f,TRUE); + + /* array should be empty */ + g_assert(fp->len == 0); - if(se->field == LTTV_FILTER_UNDEFINED) { - g_warning("The specified field was not recognized !"); - return FALSE; - } - return TRUE; + if(se->field == LTTV_FILTER_UNDEFINED) { + g_warning("The specified field was not recognized !"); + return FALSE; + } + return TRUE; } /** @@ -301,167 +302,168 @@ lttv_simple_expression_assign_field(GPtrArray* fp, LttvSimpleExpression* se) { * @param op current operator * @return success/failure of operation */ -gboolean -lttv_simple_expression_assign_operator(LttvSimpleExpression* se, LttvExpressionOp op) { - - switch(se->field) { - /* - * string - */ - case LTTV_FILTER_TRACE_NAME: - case LTTV_FILTER_TRACEFILE_NAME: - case LTTV_FILTER_STATE_P_NAME: - case LTTV_FILTER_STATE_T_BRAND: - case LTTV_FILTER_EVENT_SUBNAME: - case LTTV_FILTER_STATE_EX_MODE: - case LTTV_FILTER_STATE_EX_SUBMODE: - case LTTV_FILTER_STATE_P_STATUS: - switch(op) { - case LTTV_FIELD_EQ: - se->op = lttv_apply_op_eq_quark; - break; - case LTTV_FIELD_NE: - se->op = lttv_apply_op_ne_quark; - break; - default: - g_warning("Error encountered in operator assignment = or != expected"); - return FALSE; - } - break; - /* - * two strings. - */ - case LTTV_FILTER_EVENT_NAME: - switch(op) { - case LTTV_FIELD_EQ: - se->op = lttv_apply_op_eq_quarks; - break; - case LTTV_FIELD_NE: - se->op = lttv_apply_op_ne_quarks; - break; - default: - g_warning("Error encountered in operator assignment = or != expected"); - return FALSE; - } - break; - /* - * integer - */ - case LTTV_FILTER_EVENT_TSC: - switch(op) { - case LTTV_FIELD_EQ: - se->op = lttv_apply_op_eq_uint64; - break; - case LTTV_FIELD_NE: - se->op = lttv_apply_op_ne_uint64; - break; - case LTTV_FIELD_LT: - se->op = lttv_apply_op_lt_uint64; - break; - case LTTV_FIELD_LE: - se->op = lttv_apply_op_le_uint64; - break; - case LTTV_FIELD_GT: - se->op = lttv_apply_op_gt_uint64; - break; - case LTTV_FIELD_GE: - se->op = lttv_apply_op_ge_uint64; - break; - default: - g_warning("Error encountered in operator assignment"); - return FALSE; - } - break; - /* - * unsigned integers - */ - case LTTV_FILTER_STATE_CPU: - case LTTV_FILTER_STATE_PID: - case LTTV_FILTER_STATE_PPID: - case LTTV_FILTER_EVENT_TARGET_PID: - switch(op) { - case LTTV_FIELD_EQ: - se->op = lttv_apply_op_eq_uint; - break; - case LTTV_FIELD_NE: - se->op = lttv_apply_op_ne_uint; - break; - case LTTV_FIELD_LT: - se->op = lttv_apply_op_lt_uint; - break; - case LTTV_FIELD_LE: - se->op = lttv_apply_op_le_uint; - break; - case LTTV_FIELD_GT: - se->op = lttv_apply_op_gt_uint; - break; - case LTTV_FIELD_GE: - se->op = lttv_apply_op_ge_uint; - break; - default: - g_warning("Error encountered in operator assignment"); - return FALSE; - } - break; - - /* - * Enums - * Entered as string, converted to enum - * - * can only be compared with 'equal' or 'not equal' operators - * - * unsigned int of 16 bits are used here since enums - * should not go over 2^16-1 values - */ -// case /*NOTHING*/: -// switch(op) { -// case LTTV_FIELD_EQ: -// se->op = lttv_apply_op_eq_uint16; -// break; -// case LTTV_FIELD_NE: -// se->op = lttv_apply_op_ne_uint16; -// break; -// default: -// g_warning("Error encountered in operator assignment = or != expected"); -// return FALSE; -// } -// break; - /* - * Ltttime - */ - case LTTV_FILTER_STATE_CT: - case LTTV_FILTER_STATE_IT: - case LTTV_FILTER_EVENT_TIME: - switch(op) { - case LTTV_FIELD_EQ: - se->op = lttv_apply_op_eq_ltttime; - break; - case LTTV_FIELD_NE: - se->op = lttv_apply_op_ne_ltttime; - break; - case LTTV_FIELD_LT: - se->op = lttv_apply_op_lt_ltttime; - break; - case LTTV_FIELD_LE: - se->op = lttv_apply_op_le_ltttime; - break; - case LTTV_FIELD_GT: - se->op = lttv_apply_op_gt_ltttime; - break; - case LTTV_FIELD_GE: - se->op = lttv_apply_op_ge_ltttime; - break; - default: - g_warning("Error encountered in operator assignment"); - return FALSE; - } - break; - default: - g_warning("Error encountered in operator assignation ! Field type:%i",se->field); - return FALSE; - } - - return TRUE; +gboolean lttv_simple_expression_assign_operator(LttvSimpleExpression* se, + LttvExpressionOp op) +{ + + switch(se->field) { + /* + * string + */ + case LTTV_FILTER_TRACE_NAME: + case LTTV_FILTER_TRACEFILE_NAME: + case LTTV_FILTER_STATE_P_NAME: + case LTTV_FILTER_STATE_T_BRAND: + case LTTV_FILTER_EVENT_SUBNAME: + case LTTV_FILTER_STATE_EX_MODE: + case LTTV_FILTER_STATE_EX_SUBMODE: + case LTTV_FILTER_STATE_P_STATUS: + switch(op) { + case LTTV_FIELD_EQ: + se->op = lttv_apply_op_eq_quark; + break; + case LTTV_FIELD_NE: + se->op = lttv_apply_op_ne_quark; + break; + default: + g_warning("Error encountered in operator assignment = or != expected"); + return FALSE; + } + break; + /* + * two strings. + */ + case LTTV_FILTER_EVENT_NAME: + switch(op) { + case LTTV_FIELD_EQ: + se->op = lttv_apply_op_eq_quarks; + break; + case LTTV_FIELD_NE: + se->op = lttv_apply_op_ne_quarks; + break; + default: + g_warning("Error encountered in operator assignment = or != expected"); + return FALSE; + } + break; + /* + * integer + */ + case LTTV_FILTER_EVENT_TSC: + switch(op) { + case LTTV_FIELD_EQ: + se->op = lttv_apply_op_eq_uint64; + break; + case LTTV_FIELD_NE: + se->op = lttv_apply_op_ne_uint64; + break; + case LTTV_FIELD_LT: + se->op = lttv_apply_op_lt_uint64; + break; + case LTTV_FIELD_LE: + se->op = lttv_apply_op_le_uint64; + break; + case LTTV_FIELD_GT: + se->op = lttv_apply_op_gt_uint64; + break; + case LTTV_FIELD_GE: + se->op = lttv_apply_op_ge_uint64; + break; + default: + g_warning("Error encountered in operator assignment"); + return FALSE; + } + break; + /* + * unsigned integers + */ + case LTTV_FILTER_STATE_CPU: + case LTTV_FILTER_STATE_PID: + case LTTV_FILTER_STATE_PPID: + case LTTV_FILTER_EVENT_TARGET_PID: + switch(op) { + case LTTV_FIELD_EQ: + se->op = lttv_apply_op_eq_uint; + break; + case LTTV_FIELD_NE: + se->op = lttv_apply_op_ne_uint; + break; + case LTTV_FIELD_LT: + se->op = lttv_apply_op_lt_uint; + break; + case LTTV_FIELD_LE: + se->op = lttv_apply_op_le_uint; + break; + case LTTV_FIELD_GT: + se->op = lttv_apply_op_gt_uint; + break; + case LTTV_FIELD_GE: + se->op = lttv_apply_op_ge_uint; + break; + default: + g_warning("Error encountered in operator assignment"); + return FALSE; + } + break; + + /* + * Enums + * Entered as string, converted to enum + * + * can only be compared with 'equal' or 'not equal' operators + * + * unsigned int of 16 bits are used here since enums + * should not go over 2^16-1 values + */ +// case /*NOTHING*/: +// switch(op) { +// case LTTV_FIELD_EQ: +// se->op = lttv_apply_op_eq_uint16; +// break; +// case LTTV_FIELD_NE: +// se->op = lttv_apply_op_ne_uint16; +// break; +// default: +// g_warning("Error encountered in operator assignment = or != expected"); +// return FALSE; +// } +// break; + /* + * Ltttime + */ + case LTTV_FILTER_STATE_CT: + case LTTV_FILTER_STATE_IT: + case LTTV_FILTER_EVENT_TIME: + switch(op) { + case LTTV_FIELD_EQ: + se->op = lttv_apply_op_eq_ltttime; + break; + case LTTV_FIELD_NE: + se->op = lttv_apply_op_ne_ltttime; + break; + case LTTV_FIELD_LT: + se->op = lttv_apply_op_lt_ltttime; + break; + case LTTV_FIELD_LE: + se->op = lttv_apply_op_le_ltttime; + break; + case LTTV_FIELD_GT: + se->op = lttv_apply_op_gt_ltttime; + break; + case LTTV_FIELD_GE: + se->op = lttv_apply_op_ge_ltttime; + break; + default: + g_warning("Error encountered in operator assignment"); + return FALSE; + } + break; + default: + g_warning("Error encountered in operator assignation ! Field type:%i",se->field); + return FALSE; + } + + return TRUE; } @@ -472,111 +474,112 @@ lttv_simple_expression_assign_operator(LttvSimpleExpression* se, LttvExpressionO * @param se pointer to the current LttvSimpleExpression * @param value string value for simple expression */ -gboolean -lttv_simple_expression_assign_value(LttvSimpleExpression* se, char* value) { - - unsigned i; - gboolean is_double = FALSE; - LttTime t = ltt_time_zero; - GString* v; - guint string_len; - - switch(se->field) { - /* - * Strings - * entered as strings, converted to Quarks - */ - case LTTV_FILTER_TRACE_NAME: - case LTTV_FILTER_TRACEFILE_NAME: - case LTTV_FILTER_STATE_P_NAME: - case LTTV_FILTER_STATE_T_BRAND: - case LTTV_FILTER_EVENT_SUBNAME: - case LTTV_FILTER_STATE_EX_MODE: - case LTTV_FILTER_STATE_EX_SUBMODE: - case LTTV_FILTER_STATE_P_STATUS: - // se->value.v_string = value; - se->value.v_quark = g_quark_from_string(value); - g_free(value); - break; - /* - * Two strings. - */ - case LTTV_FILTER_EVENT_NAME: - { - /* channel.event */ - char *end = strchr(value, '.'); - if (end) { - *end = '\0'; - end++; - se->value.v_quarks.q[0] = g_quark_from_string(value); - se->value.v_quarks.q[1] = g_quark_from_string(end); - } else { - se->value.v_quarks.q[0] = (GQuark)0; - se->value.v_quarks.q[1] = g_quark_from_string(value); - } - g_free(value); - } - break; - /* - * integer -- supposed to be uint64 - */ - case LTTV_FILTER_EVENT_TSC: - se->value.v_uint64 = atoi(value); - g_free(value); - break; - /* - * unsigned integers - */ - case LTTV_FILTER_STATE_PID: - case LTTV_FILTER_STATE_PPID: - case LTTV_FILTER_STATE_CPU: - case LTTV_FILTER_EVENT_TARGET_PID: - se->value.v_uint = atoi(value); - g_free(value); - break; - /* - * LttTime - */ - case LTTV_FILTER_STATE_CT: - case LTTV_FILTER_STATE_IT: - case LTTV_FILTER_EVENT_TIME: - //se->value.v_double = atof(value); - /* - * parsing logic could be optimised, - * but as for now, simpler this way - */ - v = g_string_new(""); - string_len = strlen(value); - for(i=0;istr); - g_string_free(v,TRUE); - v = g_string_new(""); - } else v = g_string_append_c(v,value[i]); - } - /* number can be integer or double */ - if(is_double) t.tv_nsec = atoi(v->str); - else { - t.tv_sec = atoi(v->str); - t.tv_nsec = 0; - } - - g_string_free(v,TRUE); - - se->value.v_ltttime = t; - g_free(value); - break; - default: - g_warning("Error encountered in value assignation ! Field type = %i",se->field); - g_free(value); - return FALSE; - } - - return TRUE; - +gboolean lttv_simple_expression_assign_value(LttvSimpleExpression* se, + char* value) +{ + + unsigned i; + gboolean is_double = FALSE; + LttTime t = ltt_time_zero; + GString* v; + guint string_len; + + switch(se->field) { + /* + * Strings + * entered as strings, converted to Quarks + */ + case LTTV_FILTER_TRACE_NAME: + case LTTV_FILTER_TRACEFILE_NAME: + case LTTV_FILTER_STATE_P_NAME: + case LTTV_FILTER_STATE_T_BRAND: + case LTTV_FILTER_EVENT_SUBNAME: + case LTTV_FILTER_STATE_EX_MODE: + case LTTV_FILTER_STATE_EX_SUBMODE: + case LTTV_FILTER_STATE_P_STATUS: + // se->value.v_string = value; + se->value.v_quark = g_quark_from_string(value); + g_free(value); + break; + /* + * Two strings. + */ + case LTTV_FILTER_EVENT_NAME: + { + /* channel.event */ + char *end = strchr(value, '.'); + if (end) { + *end = '\0'; + end++; + se->value.v_quarks.q[0] = g_quark_from_string(value); + se->value.v_quarks.q[1] = g_quark_from_string(end); + } else { + se->value.v_quarks.q[0] = (GQuark)0; + se->value.v_quarks.q[1] = g_quark_from_string(value); + } + g_free(value); + } + break; + /* + * integer -- supposed to be uint64 + */ + case LTTV_FILTER_EVENT_TSC: + se->value.v_uint64 = atoi(value); + g_free(value); + break; + /* + * unsigned integers + */ + case LTTV_FILTER_STATE_PID: + case LTTV_FILTER_STATE_PPID: + case LTTV_FILTER_STATE_CPU: + case LTTV_FILTER_EVENT_TARGET_PID: + se->value.v_uint = atoi(value); + g_free(value); + break; + /* + * LttTime + */ + case LTTV_FILTER_STATE_CT: + case LTTV_FILTER_STATE_IT: + case LTTV_FILTER_EVENT_TIME: + //se->value.v_double = atof(value); + /* + * parsing logic could be optimised, + * but as for now, simpler this way + */ + v = g_string_new(""); + string_len = strlen(value); + for(i=0;istr); + g_string_free(v,TRUE); + v = g_string_new(""); + } else v = g_string_append_c(v,value[i]); + } + /* number can be integer or double */ + if(is_double) t.tv_nsec = atoi(v->str); + else { + t.tv_sec = atoi(v->str); + t.tv_nsec = 0; + } + + g_string_free(v,TRUE); + + se->value.v_ltttime = t; + g_free(value); + break; + default: + g_warning("Error encountered in value assignation ! Field type = %i",se->field); + g_free(value); + return FALSE; + } + + return TRUE; + } /** @@ -586,19 +589,19 @@ lttv_simple_expression_assign_value(LttvSimpleExpression* se, char* value) { * simple expression * @param se pointer to the current LttvSimpleExpression */ -void -lttv_simple_expression_destroy(LttvSimpleExpression* se) { - - // g_free(se->value); -// switch(se->field) { -// case LTTV_FILTER_TRACE_NAME: -// case LTTV_FILTER_TRACEFILE_NAME: -// case LTTV_FILTER_STATE_P_NAME: -// case LTTV_FILTER_EVENT_NAME: -// g_free(se->value.v_string); -// break; -// } - g_free(se); +void lttv_simple_expression_destroy(LttvSimpleExpression* se) +{ + +// g_free(se->value); +// switch(se->field) { +// case LTTV_FILTER_TRACE_NAME: +// case LTTV_FILTER_TRACEFILE_NAME: +// case LTTV_FILTER_STATE_P_NAME: +// case LTTV_FILTER_EVENT_NAME: +// g_free(se->value.v_string); +// break; +// } + g_free(se); } @@ -610,40 +613,40 @@ lttv_simple_expression_destroy(LttvSimpleExpression* se) { * @params ft Field of the current structure * @return LttvStructType enum or -1 for error */ -gint -lttv_struct_type(gint ft) { - - switch(ft) { - case LTTV_FILTER_TRACE_NAME: - return LTTV_FILTER_TRACE; - break; - case LTTV_FILTER_TRACEFILE_NAME: - return LTTV_FILTER_TRACEFILE; - break; - case LTTV_FILTER_STATE_PID: - case LTTV_FILTER_STATE_PPID: - case LTTV_FILTER_STATE_CT: - case LTTV_FILTER_STATE_IT: - case LTTV_FILTER_STATE_P_NAME: - case LTTV_FILTER_STATE_T_BRAND: - case LTTV_FILTER_STATE_EX_MODE: - case LTTV_FILTER_STATE_EX_SUBMODE: - case LTTV_FILTER_STATE_P_STATUS: - case LTTV_FILTER_STATE_CPU: - return LTTV_FILTER_STATE; - break; - case LTTV_FILTER_EVENT_NAME: - case LTTV_FILTER_EVENT_SUBNAME: - case LTTV_FILTER_EVENT_CATEGORY: - case LTTV_FILTER_EVENT_TIME: - case LTTV_FILTER_EVENT_TSC: - case LTTV_FILTER_EVENT_TARGET_PID: - case LTTV_FILTER_EVENT_FIELD: - return LTTV_FILTER_EVENT; - break; - default: - return -1; - } +gint lttv_struct_type(gint ft) +{ + + switch(ft) { + case LTTV_FILTER_TRACE_NAME: + return LTTV_FILTER_TRACE; + break; + case LTTV_FILTER_TRACEFILE_NAME: + return LTTV_FILTER_TRACEFILE; + break; + case LTTV_FILTER_STATE_PID: + case LTTV_FILTER_STATE_PPID: + case LTTV_FILTER_STATE_CT: + case LTTV_FILTER_STATE_IT: + case LTTV_FILTER_STATE_P_NAME: + case LTTV_FILTER_STATE_T_BRAND: + case LTTV_FILTER_STATE_EX_MODE: + case LTTV_FILTER_STATE_EX_SUBMODE: + case LTTV_FILTER_STATE_P_STATUS: + case LTTV_FILTER_STATE_CPU: + return LTTV_FILTER_STATE; + break; + case LTTV_FILTER_EVENT_NAME: + case LTTV_FILTER_EVENT_SUBNAME: + case LTTV_FILTER_EVENT_CATEGORY: + case LTTV_FILTER_EVENT_TIME: + case LTTV_FILTER_EVENT_TSC: + case LTTV_FILTER_EVENT_TARGET_PID: + case LTTV_FILTER_EVENT_FIELD: + return LTTV_FILTER_EVENT; + break; + default: + return -1; + } } /** @@ -655,11 +658,10 @@ lttv_struct_type(gint ft) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_eq_uint(const gpointer v1, LttvFieldValue v2) { - - guint* r = (guint*) v1; - return (*r == v2.v_uint); - +gboolean lttv_apply_op_eq_uint(const gpointer v1, LttvFieldValue v2) +{ + guint* r = (guint*) v1; + return (*r == v2.v_uint); } /** @@ -671,11 +673,10 @@ gboolean lttv_apply_op_eq_uint(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_eq_uint64(const gpointer v1, LttvFieldValue v2) { - - guint64* r = (guint64*) v1; - return (*r == v2.v_uint64); - +gboolean lttv_apply_op_eq_uint64(const gpointer v1, LttvFieldValue v2) +{ + guint64* r = (guint64*) v1; + return (*r == v2.v_uint64); } /** @@ -687,9 +688,10 @@ gboolean lttv_apply_op_eq_uint64(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_eq_uint32(const gpointer v1, LttvFieldValue v2) { - guint32* r = (guint32*) v1; - return (*r == v2.v_uint32); +gboolean lttv_apply_op_eq_uint32(const gpointer v1, LttvFieldValue v2) +{ + guint32* r = (guint32*) v1; + return (*r == v2.v_uint32); } /** @@ -701,9 +703,10 @@ gboolean lttv_apply_op_eq_uint32(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_eq_uint16(const gpointer v1, LttvFieldValue v2) { - guint16* r = (guint16*) v1; - return (*r == v2.v_uint16); +gboolean lttv_apply_op_eq_uint16(const gpointer v1, LttvFieldValue v2) +{ + guint16* r = (guint16*) v1; + return (*r == v2.v_uint16); } /** @@ -715,9 +718,10 @@ gboolean lttv_apply_op_eq_uint16(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_eq_double(const gpointer v1, LttvFieldValue v2) { - double* r = (double*) v1; - return (*r == v2.v_double); +gboolean lttv_apply_op_eq_double(const gpointer v1, LttvFieldValue v2) +{ + double* r = (double*) v1; + return (*r == v2.v_double); } /** @@ -729,9 +733,10 @@ gboolean lttv_apply_op_eq_double(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_eq_string(const gpointer v1, LttvFieldValue v2) { - char* r = (char*) v1; - return (!g_strcasecmp(r,v2.v_string)); +gboolean lttv_apply_op_eq_string(const gpointer v1, LttvFieldValue v2) +{ + char* r = (char*) v1; + return (!g_strcasecmp(r,v2.v_string)); } /** @@ -743,9 +748,10 @@ gboolean lttv_apply_op_eq_string(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_eq_quark(const gpointer v1, LttvFieldValue v2) { - GQuark* r = (GQuark*) v1; - return (*r == v2.v_quark); +gboolean lttv_apply_op_eq_quark(const gpointer v1, LttvFieldValue v2) +{ + GQuark* r = (GQuark*) v1; + return (*r == v2.v_quark); } /** @@ -757,14 +763,15 @@ gboolean lttv_apply_op_eq_quark(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_eq_quarks(const gpointer v1, LttvFieldValue v2) { - GQuark *r1 = (GQuark *) v1; - GQuark *r2 = r1 + 1; - if (likely(*r1 != (GQuark)0) && *r1 != v2.v_quarks.q[0]) - return 0; - if (*r2 != v2.v_quarks.q[1]) - return 0; - return 1; +gboolean lttv_apply_op_eq_quarks(const gpointer v1, LttvFieldValue v2) +{ + GQuark *r1 = (GQuark *) v1; + GQuark *r2 = r1 + 1; + if (likely(*r1 != (GQuark)0) && *r1 != v2.v_quarks.q[0]) + return 0; + if (*r2 != v2.v_quarks.q[1]) + return 0; + return 1; } /** @@ -776,9 +783,10 @@ gboolean lttv_apply_op_eq_quarks(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_eq_ltttime(const gpointer v1, LttvFieldValue v2) { - LttTime* r = (LttTime*) v1; - return ltt_time_compare(*r, v2.v_ltttime)==0?1:0; +gboolean lttv_apply_op_eq_ltttime(const gpointer v1, LttvFieldValue v2) +{ + LttTime* r = (LttTime*) v1; + return ltt_time_compare(*r, v2.v_ltttime)==0?1:0; } /** @@ -790,9 +798,10 @@ gboolean lttv_apply_op_eq_ltttime(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_ne_uint(const gpointer v1, LttvFieldValue v2) { - guint* r = (guint*) v1; - return (*r != v2.v_uint); +gboolean lttv_apply_op_ne_uint(const gpointer v1, LttvFieldValue v2) +{ + guint* r = (guint*) v1; + return (*r != v2.v_uint); } /** @@ -804,9 +813,10 @@ gboolean lttv_apply_op_ne_uint(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_ne_uint64(const gpointer v1, LttvFieldValue v2) { - guint64* r = (guint64*) v1; - return (*r != v2.v_uint64); +gboolean lttv_apply_op_ne_uint64(const gpointer v1, LttvFieldValue v2) +{ + guint64* r = (guint64*) v1; + return (*r != v2.v_uint64); } /** @@ -818,9 +828,10 @@ gboolean lttv_apply_op_ne_uint64(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_ne_uint32(const gpointer v1, LttvFieldValue v2) { - guint32* r = (guint32*) v1; - return (*r != v2.v_uint32); +gboolean lttv_apply_op_ne_uint32(const gpointer v1, LttvFieldValue v2) +{ + guint32* r = (guint32*) v1; + return (*r != v2.v_uint32); } /** @@ -832,9 +843,10 @@ gboolean lttv_apply_op_ne_uint32(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_ne_uint16(const gpointer v1, LttvFieldValue v2) { - guint16* r = (guint16*) v1; - return (*r != v2.v_uint16); +gboolean lttv_apply_op_ne_uint16(const gpointer v1, LttvFieldValue v2) +{ + guint16* r = (guint16*) v1; + return (*r != v2.v_uint16); } /** @@ -846,9 +858,10 @@ gboolean lttv_apply_op_ne_uint16(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_ne_double(const gpointer v1, LttvFieldValue v2) { - double* r = (double*) v1; - return (*r != v2.v_double); +gboolean lttv_apply_op_ne_double(const gpointer v1, LttvFieldValue v2) +{ + double* r = (double*) v1; + return (*r != v2.v_double); } /** @@ -860,9 +873,10 @@ gboolean lttv_apply_op_ne_double(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_ne_string(const gpointer v1, LttvFieldValue v2) { - char* r = (char*) v1; - return (g_strcasecmp(r,v2.v_string)); +gboolean lttv_apply_op_ne_string(const gpointer v1, LttvFieldValue v2) +{ + char* r = (char*) v1; + return (g_strcasecmp(r,v2.v_string)); } /** @@ -874,9 +888,10 @@ gboolean lttv_apply_op_ne_string(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_ne_quark(const gpointer v1, LttvFieldValue v2) { - GQuark* r = (GQuark*) v1; - return (*r != v2.v_quark); +gboolean lttv_apply_op_ne_quark(const gpointer v1, LttvFieldValue v2) +{ + GQuark* r = (GQuark*) v1; + return (*r != v2.v_quark); } /** @@ -888,13 +903,14 @@ gboolean lttv_apply_op_ne_quark(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_ne_quarks(const gpointer v1, LttvFieldValue v2) { - GQuark *r1 = (GQuark *) v1; - GQuark *r2 = r1 + 1; - if ((*r1 == (GQuark)0 || *r1 == v2.v_quarks.q[0]) && *r2 == v2.v_quarks.q[1]) - return 0; - else - return 1; +gboolean lttv_apply_op_ne_quarks(const gpointer v1, LttvFieldValue v2) +{ + GQuark *r1 = (GQuark *) v1; + GQuark *r2 = r1 + 1; + if ((*r1 == (GQuark)0 || *r1 == v2.v_quarks.q[0]) && *r2 == v2.v_quarks.q[1]) + return 0; + else + return 1; } /** @@ -906,9 +922,10 @@ gboolean lttv_apply_op_ne_quarks(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_ne_ltttime(const gpointer v1, LttvFieldValue v2) { - LttTime* r = (LttTime*) v1; - return ltt_time_compare(*r, v2.v_ltttime)!=0?1:0; +gboolean lttv_apply_op_ne_ltttime(const gpointer v1, LttvFieldValue v2) +{ + LttTime* r = (LttTime*) v1; + return ltt_time_compare(*r, v2.v_ltttime)!=0?1:0; } /** @@ -920,9 +937,10 @@ gboolean lttv_apply_op_ne_ltttime(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_lt_uint(const gpointer v1, LttvFieldValue v2) { - guint* r = (guint*) v1; - return (*r < v2.v_uint); +gboolean lttv_apply_op_lt_uint(const gpointer v1, LttvFieldValue v2) +{ + guint* r = (guint*) v1; + return (*r < v2.v_uint); } /** @@ -934,9 +952,10 @@ gboolean lttv_apply_op_lt_uint(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_lt_uint64(const gpointer v1, LttvFieldValue v2) { - guint64* r = (guint64*) v1; - return (*r < v2.v_uint64); +gboolean lttv_apply_op_lt_uint64(const gpointer v1, LttvFieldValue v2) +{ + guint64* r = (guint64*) v1; + return (*r < v2.v_uint64); } /** @@ -948,9 +967,10 @@ gboolean lttv_apply_op_lt_uint64(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_lt_uint32(const gpointer v1, LttvFieldValue v2) { - guint32* r = (guint32*) v1; - return (*r < v2.v_uint32); +gboolean lttv_apply_op_lt_uint32(const gpointer v1, LttvFieldValue v2) +{ + guint32* r = (guint32*) v1; + return (*r < v2.v_uint32); } /** @@ -962,9 +982,10 @@ gboolean lttv_apply_op_lt_uint32(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_lt_uint16(const gpointer v1, LttvFieldValue v2) { - guint16* r = (guint16*) v1; - return (*r < v2.v_uint16); +gboolean lttv_apply_op_lt_uint16(const gpointer v1, LttvFieldValue v2) +{ + guint16* r = (guint16*) v1; + return (*r < v2.v_uint16); } /** @@ -976,9 +997,10 @@ gboolean lttv_apply_op_lt_uint16(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_lt_double(const gpointer v1, LttvFieldValue v2) { - double* r = (double*) v1; - return (*r < v2.v_double); +gboolean lttv_apply_op_lt_double(const gpointer v1, LttvFieldValue v2) +{ + double* r = (double*) v1; + return (*r < v2.v_double); } /** @@ -990,10 +1012,11 @@ gboolean lttv_apply_op_lt_double(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_lt_ltttime(const gpointer v1, LttvFieldValue v2) { - LttTime* r = (LttTime*) v1; -// return ((r->tv_sec < v2.v_ltttime.tv_sec) || ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec < v2.v_ltttime.tv_nsec))); - return ltt_time_compare(*r, v2.v_ltttime)==-1?1:0; +gboolean lttv_apply_op_lt_ltttime(const gpointer v1, LttvFieldValue v2) +{ + LttTime* r = (LttTime*) v1; +// return ((r->tv_sec < v2.v_ltttime.tv_sec) || ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec < v2.v_ltttime.tv_nsec))); + return ltt_time_compare(*r, v2.v_ltttime)==-1?1:0; } /** @@ -1005,9 +1028,10 @@ gboolean lttv_apply_op_lt_ltttime(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_le_uint(const gpointer v1, LttvFieldValue v2) { - guint* r = (guint*) v1; - return (*r <= v2.v_uint); +gboolean lttv_apply_op_le_uint(const gpointer v1, LttvFieldValue v2) +{ + guint* r = (guint*) v1; + return (*r <= v2.v_uint); } /** @@ -1019,9 +1043,10 @@ gboolean lttv_apply_op_le_uint(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_le_uint64(const gpointer v1, LttvFieldValue v2) { - guint64* r = (guint64*) v1; - return (*r <= v2.v_uint64); +gboolean lttv_apply_op_le_uint64(const gpointer v1, LttvFieldValue v2) +{ + guint64* r = (guint64*) v1; + return (*r <= v2.v_uint64); } /** @@ -1033,9 +1058,10 @@ gboolean lttv_apply_op_le_uint64(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_le_uint32(const gpointer v1, LttvFieldValue v2) { - guint32* r = (guint32*) v1; - return (*r <= v2.v_uint32); +gboolean lttv_apply_op_le_uint32(const gpointer v1, LttvFieldValue v2) +{ + guint32* r = (guint32*) v1; + return (*r <= v2.v_uint32); } /** @@ -1047,9 +1073,10 @@ gboolean lttv_apply_op_le_uint32(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_le_uint16(const gpointer v1, LttvFieldValue v2) { - guint16* r = (guint16*) v1; - return (*r <= v2.v_uint16); +gboolean lttv_apply_op_le_uint16(const gpointer v1, LttvFieldValue v2) +{ + guint16* r = (guint16*) v1; + return (*r <= v2.v_uint16); } /** @@ -1061,9 +1088,10 @@ gboolean lttv_apply_op_le_uint16(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_le_double(const gpointer v1, LttvFieldValue v2) { - double* r = (double*) v1; - return (*r <= v2.v_double); +gboolean lttv_apply_op_le_double(const gpointer v1, LttvFieldValue v2) +{ + double* r = (double*) v1; + return (*r <= v2.v_double); } /** @@ -1075,10 +1103,11 @@ gboolean lttv_apply_op_le_double(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_le_ltttime(const gpointer v1, LttvFieldValue v2) { - LttTime* r = (LttTime*) v1; -// return ((r->tv_sec < v2.v_ltttime.tv_sec) || ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec <= v2.v_ltttime.tv_nsec))); - return ltt_time_compare(*r, v2.v_ltttime)<1?1:0; +gboolean lttv_apply_op_le_ltttime(const gpointer v1, LttvFieldValue v2) +{ + LttTime* r = (LttTime*) v1; +// return ((r->tv_sec < v2.v_ltttime.tv_sec) || ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec <= v2.v_ltttime.tv_nsec))); + return ltt_time_compare(*r, v2.v_ltttime)<1?1:0; } @@ -1091,9 +1120,10 @@ gboolean lttv_apply_op_le_ltttime(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_gt_uint(const gpointer v1, LttvFieldValue v2) { - guint* r = (guint*) v1; - return (*r > v2.v_uint); +gboolean lttv_apply_op_gt_uint(const gpointer v1, LttvFieldValue v2) +{ + guint* r = (guint*) v1; + return (*r > v2.v_uint); } /** @@ -1105,9 +1135,10 @@ gboolean lttv_apply_op_gt_uint(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_gt_uint64(const gpointer v1, LttvFieldValue v2) { - guint64* r = (guint64*) v1; - return (*r > v2.v_uint64); +gboolean lttv_apply_op_gt_uint64(const gpointer v1, LttvFieldValue v2) +{ + guint64* r = (guint64*) v1; + return (*r > v2.v_uint64); } /** @@ -1119,9 +1150,10 @@ gboolean lttv_apply_op_gt_uint64(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_gt_uint32(const gpointer v1, LttvFieldValue v2) { - guint32* r = (guint32*) v1; - return (*r > v2.v_uint32); +gboolean lttv_apply_op_gt_uint32(const gpointer v1, LttvFieldValue v2) +{ + guint32* r = (guint32*) v1; + return (*r > v2.v_uint32); } /** @@ -1133,9 +1165,10 @@ gboolean lttv_apply_op_gt_uint32(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_gt_uint16(const gpointer v1, LttvFieldValue v2) { - guint16* r = (guint16*) v1; - return (*r > v2.v_uint16); +gboolean lttv_apply_op_gt_uint16(const gpointer v1, LttvFieldValue v2) +{ + guint16* r = (guint16*) v1; + return (*r > v2.v_uint16); } /** @@ -1147,9 +1180,10 @@ gboolean lttv_apply_op_gt_uint16(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_gt_double(const gpointer v1, LttvFieldValue v2) { - double* r = (double*) v1; - return (*r > v2.v_double); +gboolean lttv_apply_op_gt_double(const gpointer v1, LttvFieldValue v2) +{ + double* r = (double*) v1; + return (*r > v2.v_double); } /** @@ -1161,10 +1195,11 @@ gboolean lttv_apply_op_gt_double(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_gt_ltttime(const gpointer v1, LttvFieldValue v2) { - LttTime* r = (LttTime*) v1; -// return ((r->tv_sec > v2.v_ltttime.tv_sec) || ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec > v2.v_ltttime.tv_nsec))); - return ltt_time_compare(*r, v2.v_ltttime)==1?1:0; +gboolean lttv_apply_op_gt_ltttime(const gpointer v1, LttvFieldValue v2) +{ + LttTime* r = (LttTime*) v1; +// return ((r->tv_sec > v2.v_ltttime.tv_sec) || ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec > v2.v_ltttime.tv_nsec))); + return ltt_time_compare(*r, v2.v_ltttime)==1?1:0; } /** @@ -1176,9 +1211,10 @@ gboolean lttv_apply_op_gt_ltttime(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_ge_uint(const gpointer v1, LttvFieldValue v2) { - guint* r = (guint*) v1; - return (*r >= v2.v_uint); +gboolean lttv_apply_op_ge_uint(const gpointer v1, LttvFieldValue v2) +{ + guint* r = (guint*) v1; + return (*r >= v2.v_uint); } /** @@ -1190,9 +1226,10 @@ gboolean lttv_apply_op_ge_uint(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_ge_uint64(const gpointer v1, LttvFieldValue v2) { - guint64* r = (guint64*) v1; - return (*r >= v2.v_uint64); +gboolean lttv_apply_op_ge_uint64(const gpointer v1, LttvFieldValue v2) +{ + guint64* r = (guint64*) v1; + return (*r >= v2.v_uint64); } /** @@ -1204,9 +1241,10 @@ gboolean lttv_apply_op_ge_uint64(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_ge_uint32(const gpointer v1, LttvFieldValue v2) { - guint32* r = (guint32*) v1; - return (*r >= v2.v_uint32); +gboolean lttv_apply_op_ge_uint32(const gpointer v1, LttvFieldValue v2) +{ + guint32* r = (guint32*) v1; + return (*r >= v2.v_uint32); } /** @@ -1218,9 +1256,10 @@ gboolean lttv_apply_op_ge_uint32(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_ge_uint16(const gpointer v1, LttvFieldValue v2) { - guint16* r = (guint16*) v1; - return (*r >= v2.v_uint16); +gboolean lttv_apply_op_ge_uint16(const gpointer v1, LttvFieldValue v2) +{ + guint16* r = (guint16*) v1; + return (*r >= v2.v_uint16); } /** @@ -1232,9 +1271,10 @@ gboolean lttv_apply_op_ge_uint16(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_ge_double(const gpointer v1, LttvFieldValue v2) { - double* r = (double*) v1; - return (*r >= v2.v_double); +gboolean lttv_apply_op_ge_double(const gpointer v1, LttvFieldValue v2) +{ + double* r = (double*) v1; + return (*r >= v2.v_double); } /** @@ -1246,10 +1286,11 @@ gboolean lttv_apply_op_ge_double(const gpointer v1, LttvFieldValue v2) { * @param v2 right member of comparison * @return success/failure of operation */ -gboolean lttv_apply_op_ge_ltttime(const gpointer v1, LttvFieldValue v2) { - LttTime* r = (LttTime*) v1; -// return ((r->tv_sec > v2.v_ltttime.tv_sec) || ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec >= v2.v_ltttime.tv_nsec))); - return ltt_time_compare(*r, v2.v_ltttime)>-1?1:0; +gboolean lttv_apply_op_ge_ltttime(const gpointer v1, LttvFieldValue v2) +{ + LttTime* r = (LttTime*) v1; +// return ((r->tv_sec > v2.v_ltttime.tv_sec) || ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec >= v2.v_ltttime.tv_nsec))); + return ltt_time_compare(*r, v2.v_ltttime)>-1?1:0; } @@ -1259,38 +1300,38 @@ gboolean lttv_apply_op_ge_ltttime(const gpointer v1, LttvFieldValue v2) { * @param tree pointer to the current tree * @return new copy of the filter tree */ -LttvFilterTree* -lttv_filter_tree_clone(const LttvFilterTree* tree) { +LttvFilterTree* lttv_filter_tree_clone(const LttvFilterTree* tree) +{ - LttvFilterTree* newtree = lttv_filter_tree_new(); + LttvFilterTree* newtree = lttv_filter_tree_new(); - newtree->node = tree->node; + newtree->node = tree->node; - newtree->left = tree->left; - if(newtree->left == LTTV_TREE_NODE) { - newtree->l_child.t = lttv_filter_tree_clone(tree->l_child.t); - } else if(newtree->left == LTTV_TREE_LEAF) { - newtree->l_child.leaf = lttv_simple_expression_new(); - newtree->l_child.leaf->field = tree->l_child.leaf->field; - newtree->l_child.leaf->offset = tree->l_child.leaf->offset; - newtree->l_child.leaf->op = tree->l_child.leaf->op; - /* FIXME: special case for string copy ! */ - newtree->l_child.leaf->value = tree->l_child.leaf->value; - } + newtree->left = tree->left; + if(newtree->left == LTTV_TREE_NODE) { + newtree->l_child.t = lttv_filter_tree_clone(tree->l_child.t); + } else if(newtree->left == LTTV_TREE_LEAF) { + newtree->l_child.leaf = lttv_simple_expression_new(); + newtree->l_child.leaf->field = tree->l_child.leaf->field; + newtree->l_child.leaf->offset = tree->l_child.leaf->offset; + newtree->l_child.leaf->op = tree->l_child.leaf->op; + /* FIXME: special case for string copy ! */ + newtree->l_child.leaf->value = tree->l_child.leaf->value; + } - newtree->right = tree->right; - if(newtree->right == LTTV_TREE_NODE) { - newtree->r_child.t = lttv_filter_tree_clone(tree->r_child.t); - } else if(newtree->right == LTTV_TREE_LEAF) { - newtree->r_child.leaf = lttv_simple_expression_new(); - newtree->r_child.leaf->field = tree->r_child.leaf->field; - newtree->r_child.leaf->offset = tree->r_child.leaf->offset; - newtree->r_child.leaf->op = tree->r_child.leaf->op; - newtree->r_child.leaf->value = tree->r_child.leaf->value; - } - - return newtree; - + newtree->right = tree->right; + if(newtree->right == LTTV_TREE_NODE) { + newtree->r_child.t = lttv_filter_tree_clone(tree->r_child.t); + } else if(newtree->right == LTTV_TREE_LEAF) { + newtree->r_child.leaf = lttv_simple_expression_new(); + newtree->r_child.leaf->field = tree->r_child.leaf->field; + newtree->r_child.leaf->offset = tree->r_child.leaf->offset; + newtree->r_child.leaf->op = tree->r_child.leaf->op; + newtree->r_child.leaf->value = tree->r_child.leaf->value; + } + + return newtree; + } /** @@ -1298,19 +1339,19 @@ lttv_filter_tree_clone(const LttvFilterTree* tree) { * @param filter pointer to the current filter * @return new copy of the filter */ -LttvFilter* -lttv_filter_clone(const LttvFilter* filter) { +LttvFilter* lttv_filter_clone(const LttvFilter* filter) +{ - if(!filter) return NULL; + if(!filter) return NULL; - LttvFilter* newfilter = g_new(LttvFilter,1); + LttvFilter* newfilter = g_new(LttvFilter,1); - strcpy(newfilter->expression,filter->expression); + strcpy(newfilter->expression,filter->expression); + + newfilter->head = lttv_filter_tree_clone(filter->head); + + return newfilter; - newfilter->head = lttv_filter_tree_clone(filter->head); - - return newfilter; - } @@ -1320,15 +1361,15 @@ lttv_filter_clone(const LttvFilter* filter) { * Creates a new LttvFilter * @return the current LttvFilter or NULL if error */ -LttvFilter* -lttv_filter_new() { +LttvFilter* lttv_filter_new() +{ - LttvFilter* filter = g_new(LttvFilter,1); - filter->expression = NULL; - filter->head = NULL; + LttvFilter* filter = g_new(LttvFilter,1); + filter->expression = NULL; + filter->head = NULL; + + return filter; - return filter; - } /** @@ -1339,465 +1380,473 @@ lttv_filter_new() { * @param filter pointer to the current LttvFilter * @return Failure/Success of operation */ -gboolean -lttv_filter_update(LttvFilter* filter) { - -// g_print("filter::lttv_filter_new()\n"); /* debug */ - - if(filter->expression == NULL) return FALSE; - - int - i, - p_nesting=0, /* parenthesis nesting value */ - not=0; - guint expression_len; - - /* trees */ - LttvFilterTree - *tree = lttv_filter_tree_new(), /* main tree */ - *subtree = NULL, /* buffer for subtrees */ - *t1, /* buffer #1 */ - *t2, /* buffer #2 */ - *t3; /* buffer #3 */ - - /* - * the filter - * If the tree already exists, - * destroy it and build a new one - */ - if(filter->head != NULL) lttv_filter_tree_destroy(filter->head); - filter->head = NULL; /* will be assigned at the end */ - - /* - * Tree Stack - * each element of the list - * is a sub tree created - * by the use of parenthesis in the - * global expression. The final tree - * will be the one left at the root of - * the list - */ - GPtrArray *tree_stack = g_ptr_array_new(); - g_ptr_array_add( tree_stack,(gpointer) tree ); - - /* temporary values */ - GString *a_field_component = g_string_new(""); - GString *a_string_spaces = g_string_new(""); - GPtrArray *a_field_path = g_ptr_array_new(); - - /* simple expression buffer */ - LttvSimpleExpression* a_simple_expression = lttv_simple_expression_new(); - - gint nest_quotes = 0; - - /* - * Parse entire expression and construct - * the binary tree. There are two steps - * in browsing that string - * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} " - * 2. finding simple expressions - * - field path ( separated by dots ) - * - op ( >, <, =, >=, <=, !=) - * - value ( integer, string ... ) - * To spare computing time, the whole - * string is parsed in this loop for a - * O(n) complexity order. - * - * When encountering logical op &,|,^ - * 1. parse the last value if any - * 2. create a new tree - * 3. add the expression (simple exp, or exp (subtree)) to the tree - * 4. concatenate this tree with the current tree on top of the stack - * When encountering math ops >,>=,<,<=,=,!= - * 1. add to op to the simple expression - * 2. concatenate last field component to field path - * When encountering concatening ops . - * 1. concatenate last field component to field path - * When encountering opening parenthesis (,{,[ - * 1. create a new subtree on top of tree stack - * When encountering closing parenthesis ),},] - * 1. add the expression on right child of the current tree - * 2. the subtree is completed, allocate a new subtree - * 3. pop the tree value from the tree stack - */ - +gboolean lttv_filter_update(LttvFilter* filter) +{ + +// g_print("filter::lttv_filter_new()\n"); /* debug */ + + if(filter->expression == NULL) return FALSE; + + int + i, + p_nesting=0, /* parenthesis nesting value */ + not=0; + guint expression_len; + + /* trees */ + LttvFilterTree + *tree = lttv_filter_tree_new(), /* main tree */ + *subtree = NULL, /* buffer for subtrees */ + *t1, /* buffer #1 */ + *t2, /* buffer #2 */ + *t3; /* buffer #3 */ + + /* + * the filter + * If the tree already exists, + * destroy it and build a new one + */ + if(filter->head != NULL) lttv_filter_tree_destroy(filter->head); + filter->head = NULL; /* will be assigned at the end */ + + /* + * Tree Stack + * each element of the list + * is a sub tree created + * by the use of parenthesis in the + * global expression. The final tree + * will be the one left at the root of + * the list + */ + GPtrArray *tree_stack = g_ptr_array_new(); + g_ptr_array_add( tree_stack,(gpointer) tree ); + + /* temporary values */ + GString *a_field_component = g_string_new(""); + GString *a_string_spaces = g_string_new(""); + GPtrArray *a_field_path = g_ptr_array_new(); + + /* simple expression buffer */ + LttvSimpleExpression* a_simple_expression = lttv_simple_expression_new(); + + gint nest_quotes = 0; + + /* + * Parse entire expression and construct + * the binary tree. There are two steps + * in browsing that string + * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} " + * 2. finding simple expressions + * - field path ( separated by dots ) + * - op ( >, <, =, >=, <=, !=) + * - value ( integer, string ... ) + * To spare computing time, the whole + * string is parsed in this loop for a + * O(n) complexity order. + * + * When encountering logical op &,|,^ + * 1. parse the last value if any + * 2. create a new tree + * 3. add the expression (simple exp, or exp (subtree)) to the tree + * 4. concatenate this tree with the current tree on top of the stack + * When encountering math ops >,>=,<,<=,=,!= + * 1. add to op to the simple expression + * 2. concatenate last field component to field path + * When encountering concatening ops . + * 1. concatenate last field component to field path + * When encountering opening parenthesis (,{,[ + * 1. create a new subtree on top of tree stack + * When encountering closing parenthesis ),},] + * 1. add the expression on right child of the current tree + * 2. the subtree is completed, allocate a new subtree + * 3. pop the tree value from the tree stack + */ + #ifdef TEST - struct timeval starttime; - struct timeval endtime; - gettimeofday(&starttime, NULL); + struct timeval starttime; + struct timeval endtime; + gettimeofday(&starttime, NULL); #endif - - expression_len = strlen(filter->expression); - for(i=0;iexpression[i]); - if(nest_quotes) { - switch(filter->expression[i]) { - case '\\' : - if(filter->expression[i+1] == '\"') { - i++; - } - break; - case '\"': - nest_quotes = 0; - i++; - break; - } - if(a_string_spaces->len != 0) { - a_field_component = g_string_append( - a_field_component, a_string_spaces->str); - a_string_spaces = g_string_set_size(a_string_spaces, 0); - } - a_field_component = g_string_append_c(a_field_component, - filter->expression[i]); - continue; - } - - switch(filter->expression[i]) { - /* - * logical operators - */ - case '&': /* and */ - - /* get current tree in tree stack */ - t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1); - - /* get current node at absolute right */ - while(t1->right != LTTV_TREE_IDLE) { - g_assert(t1->right == LTTV_TREE_NODE); - t1 = t1->r_child.t; - } - t2 = lttv_filter_tree_new(); - t2->node = LTTV_LOGICAL_AND; - t1->right = LTTV_TREE_NODE; - t1->r_child.t = t2; - if(not) { /* add not operator to tree */ - t3 = lttv_filter_tree_new(); - t3->node = LTTV_LOGICAL_NOT; - t2->left = LTTV_TREE_NODE; - t2->l_child.t = t3; - t2 = t3; - not = 0; - } - if(subtree != NULL) { /* append subtree to current tree */ - t2->left = LTTV_TREE_NODE; - t2->l_child.t = subtree; - subtree = NULL; - } else { /* append a simple expression */ - lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); - a_field_component = g_string_new(""); - g_string_free(a_string_spaces, TRUE); - a_string_spaces = g_string_new(""); - t2->left = LTTV_TREE_LEAF; - t2->l_child.leaf = a_simple_expression; - a_simple_expression = lttv_simple_expression_new(); - } - break; - - case '|': /* or */ - - t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1); - while(t1->right != LTTV_TREE_IDLE) { - g_assert(t1->right == LTTV_TREE_NODE); - t1 = t1->r_child.t; - } - t2 = lttv_filter_tree_new(); - t2->node = LTTV_LOGICAL_OR; - t1->right = LTTV_TREE_NODE; - t1->r_child.t = t2; - if(not) { // add not operator to tree - t3 = lttv_filter_tree_new(); - t3->node = LTTV_LOGICAL_NOT; - t2->left = LTTV_TREE_NODE; - t2->l_child.t = t3; - t2 = t3; - not = 0; - } - if(subtree != NULL) { /* append subtree to current tree */ - t2->left = LTTV_TREE_NODE; - t2->l_child.t = subtree; - subtree = NULL; - } else { /* append a simple expression */ - lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); - a_field_component = g_string_new(""); - g_string_free(a_string_spaces, TRUE); - a_string_spaces = g_string_new(""); - t2->left = LTTV_TREE_LEAF; - t2->l_child.leaf = a_simple_expression; - a_simple_expression = lttv_simple_expression_new(); - } - break; - - case '^': /* xor */ - - t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1); - while(t1->right != LTTV_TREE_IDLE) { - g_assert(t1->right == LTTV_TREE_NODE); - t1 = t1->r_child.t; - } - t2 = lttv_filter_tree_new(); - t2->node = LTTV_LOGICAL_XOR; - t1->right = LTTV_TREE_NODE; - t1->r_child.t = t2; - if(not) { // add not operator to tree - t3 = lttv_filter_tree_new(); - t3->node = LTTV_LOGICAL_NOT; - t2->left = LTTV_TREE_NODE; - t2->l_child.t = t3; - t2 = t3; - not = 0; - } - if(subtree != NULL) { /* append subtree to current tree */ - t2->left = LTTV_TREE_NODE; - t2->l_child.t = subtree; - subtree = NULL; - } else { /* append a simple expression */ - lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); - a_field_component = g_string_new(""); - g_string_free(a_string_spaces, TRUE); - a_string_spaces = g_string_new(""); - t2->left = LTTV_TREE_LEAF; - t2->l_child.leaf = a_simple_expression; - a_simple_expression = lttv_simple_expression_new(); - } - break; - - case '!': /* not, or not equal (math op) */ - - if(filter->expression[i+1] == '=') { /* != */ - g_ptr_array_add( a_field_path,(gpointer) a_field_component ); - lttv_simple_expression_assign_field(a_field_path,a_simple_expression); - a_field_component = g_string_new(""); - g_string_free(a_string_spaces, TRUE); - a_string_spaces = g_string_new(""); - lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_NE); - i++; - } else { /* ! */ - not=1; - } - break; - - case '(': /* start of parenthesis */ - case '[': - case '{': - - p_nesting++; /* incrementing parenthesis nesting value */ - t1 = lttv_filter_tree_new(); - if(not) { /* add not operator to tree */ - t3 = lttv_filter_tree_new(); - t3->node = LTTV_LOGICAL_NOT; - t1->right = LTTV_TREE_NODE; - t1->r_child.t = t3; - not = 0; - } - g_ptr_array_add( tree_stack,(gpointer) t1 ); - break; - - case ')': /* end of parenthesis */ - case ']': - case '}': - - p_nesting--; /* decrementing parenthesis nesting value */ - if(p_nesting<0 || tree_stack->len<2) { - g_warning("Wrong filtering options, the string\n\"%s\"\n\ - is not valid due to parenthesis incorrect use",filter->expression); - return FALSE; - } - - /* there must at least be the root tree left in the array */ - g_assert(tree_stack->len>0); - - t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); - while(t1->right != LTTV_TREE_IDLE) { - t1 = t1->r_child.t; - } - if(not) { // add not operator to tree - g_print("ici"); - t3 = lttv_filter_tree_new(); - t3->node = LTTV_LOGICAL_NOT; - t1->right = LTTV_TREE_NODE; - t1->r_child.t = t3; - t1 = t3; - not = 0; - } - if(subtree != NULL) { /* append subtree to current tree */ - t1->right = LTTV_TREE_NODE; - t1->r_child.t = subtree; - subtree = g_ptr_array_index(tree_stack,tree_stack->len-1); - g_ptr_array_remove_index(tree_stack,tree_stack->len-1); - } else { /* assign subtree as current tree */ - lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); - a_field_component = g_string_new(""); - g_string_free(a_string_spaces, TRUE); - a_string_spaces = g_string_new(""); - t1->right = LTTV_TREE_LEAF; - t1->r_child.leaf = a_simple_expression; - a_simple_expression = lttv_simple_expression_new(); - subtree = g_ptr_array_remove_index(tree_stack,tree_stack->len-1); - } - break; - - /* - * mathematic operators - */ - case '<': /* lower, lower or equal */ - - g_ptr_array_add( a_field_path,(gpointer) a_field_component ); - lttv_simple_expression_assign_field(a_field_path,a_simple_expression); - a_field_component = g_string_new(""); - g_string_free(a_string_spaces, TRUE); - a_string_spaces = g_string_new(""); - if(filter->expression[i+1] == '=') { /* <= */ - i++; - lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_LE); - } else lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_LT); - break; - - case '>': /* higher, higher or equal */ - - g_ptr_array_add( a_field_path,(gpointer) a_field_component ); - lttv_simple_expression_assign_field(a_field_path,a_simple_expression); - a_field_component = g_string_new(""); - g_string_free(a_string_spaces, TRUE); - a_string_spaces = g_string_new(""); - if(filter->expression[i+1] == '=') { /* >= */ - i++; - lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_GE); - } else lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_GT); - break; - - case '=': /* equal */ - - g_ptr_array_add( a_field_path,(gpointer) a_field_component ); - lttv_simple_expression_assign_field(a_field_path,a_simple_expression); - a_field_component = g_string_new(""); - g_string_free(a_string_spaces, TRUE); - a_string_spaces = g_string_new(""); - lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_EQ); - break; - - /* - * Field concatening caracter - */ - case '.': /* dot */ - - /* - * divide field expression into elements - * in a_field_path array. - * - * A dot can also be present in double values - */ - if(a_simple_expression->field == LTTV_FILTER_UNDEFINED) { - g_ptr_array_add( a_field_path,(gpointer) a_field_component ); - a_field_component = g_string_new(""); - g_string_free(a_string_spaces, TRUE); - a_string_spaces = g_string_new(""); - } else { - /* Operator found, we are in the value field */ - g_string_append_c(a_field_component, filter->expression[i]); - } - break; - case ' ': /* keep spaces that are within a field component */ - if(a_field_component->len == 0) break; /* ignore */ - else - a_string_spaces = g_string_append_c(a_string_spaces, - filter->expression[i]); - - case '\n': /* ignore */ - break; - case '\"': - nest_quotes?(nest_quotes=0):(nest_quotes=1); - break; - default: /* concatening current string */ - if(a_string_spaces->len != 0) { - a_field_component = g_string_append( - a_field_component, a_string_spaces->str); - a_string_spaces = g_string_set_size(a_string_spaces, 0); - } - a_field_component = g_string_append_c(a_field_component, - filter->expression[i]); - } - } - - /* - * Preliminary check to see - * if tree was constructed correctly - */ - if( p_nesting>0 ) { - g_warning("Wrong filtering options, the string\n\"%s\"\n\ - is not valid due to parenthesis incorrect use",filter->expression); - return FALSE; - } - - if(tree_stack->len != 1) /* only root tree should remain */ - return FALSE; - - /* - * processing last element of expression - */ - t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); - while(t1->right != LTTV_TREE_IDLE) { - g_assert(t1->right == LTTV_TREE_NODE); - t1 = t1->r_child.t; - } - if(not) { // add not operator to tree - t3 = lttv_filter_tree_new(); - t3->node = LTTV_LOGICAL_NOT; - t1->right = LTTV_TREE_NODE; - t1->r_child.t = t3; - t1 = t3; - not = 0; - } - if(subtree != NULL) { /* add the subtree */ - t1->right = LTTV_TREE_NODE; - t1->r_child.t = subtree; - subtree = NULL; - } else { /* add a leaf */ - lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); - a_field_component = NULL; - g_string_free(a_string_spaces, TRUE); - a_string_spaces = NULL; - t1->right = LTTV_TREE_LEAF; - t1->r_child.leaf = a_simple_expression; - a_simple_expression = NULL; - } - - - /* free the pointer array */ - g_assert(a_field_path->len == 0); - g_ptr_array_free(a_field_path,TRUE); - - /* free the tree stack -- but keep the root tree */ - filter->head = ltt_g_ptr_array_remove_index_slow(tree_stack,0); - g_ptr_array_free(tree_stack,TRUE); - - /* free the field buffer if allocated */ - if(a_field_component != NULL) g_string_free(a_field_component,TRUE); - if(a_string_spaces != NULL) g_string_free(a_string_spaces, TRUE); - - /* free the simple expression buffer if allocated */ - if(a_simple_expression != NULL) lttv_simple_expression_destroy(a_simple_expression); - - g_assert(filter->head != NULL); /* tree should exist */ - g_assert(subtree == NULL); /* remaining subtree should be included in main tree */ - + + expression_len = strlen(filter->expression); + for(i=0;iexpression[i]); + if(nest_quotes) { + switch(filter->expression[i]) { + case '\\' : + if(filter->expression[i+1] == '\"') { + i++; + } + break; + case '\"': + nest_quotes = 0; + i++; + break; + } + if(a_string_spaces->len != 0) { + a_field_component = g_string_append( + a_field_component, a_string_spaces->str); + a_string_spaces = g_string_set_size(a_string_spaces, 0); + } + a_field_component = g_string_append_c(a_field_component, + filter->expression[i]); + continue; + } + + switch(filter->expression[i]) { + /* + * logical operators + */ + case '&': /* and */ + + /* get current tree in tree stack */ + t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1); + + /* get current node at absolute right */ + while(t1->right != LTTV_TREE_IDLE) { + g_assert(t1->right == LTTV_TREE_NODE); + t1 = t1->r_child.t; + } + t2 = lttv_filter_tree_new(); + t2->node = LTTV_LOGICAL_AND; + t1->right = LTTV_TREE_NODE; + t1->r_child.t = t2; + if(not) { /* add not operator to tree */ + t3 = lttv_filter_tree_new(); + t3->node = LTTV_LOGICAL_NOT; + t2->left = LTTV_TREE_NODE; + t2->l_child.t = t3; + t2 = t3; + not = 0; + } + if(subtree != NULL) { /* append subtree to current tree */ + t2->left = LTTV_TREE_NODE; + t2->l_child.t = subtree; + subtree = NULL; + } else { /* append a simple expression */ + lttv_simple_expression_assign_value(a_simple_expression, + g_string_free(a_field_component,FALSE)); + a_field_component = g_string_new(""); + g_string_free(a_string_spaces, TRUE); + a_string_spaces = g_string_new(""); + t2->left = LTTV_TREE_LEAF; + t2->l_child.leaf = a_simple_expression; + a_simple_expression = lttv_simple_expression_new(); + } + break; + + case '|': /* or */ + + t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1); + while(t1->right != LTTV_TREE_IDLE) { + g_assert(t1->right == LTTV_TREE_NODE); + t1 = t1->r_child.t; + } + t2 = lttv_filter_tree_new(); + t2->node = LTTV_LOGICAL_OR; + t1->right = LTTV_TREE_NODE; + t1->r_child.t = t2; + if(not) { // add not operator to tree + t3 = lttv_filter_tree_new(); + t3->node = LTTV_LOGICAL_NOT; + t2->left = LTTV_TREE_NODE; + t2->l_child.t = t3; + t2 = t3; + not = 0; + } + if(subtree != NULL) { /* append subtree to current tree */ + t2->left = LTTV_TREE_NODE; + t2->l_child.t = subtree; + subtree = NULL; + } else { /* append a simple expression */ + lttv_simple_expression_assign_value(a_simple_expression, + g_string_free(a_field_component,FALSE)); + a_field_component = g_string_new(""); + g_string_free(a_string_spaces, TRUE); + a_string_spaces = g_string_new(""); + t2->left = LTTV_TREE_LEAF; + t2->l_child.leaf = a_simple_expression; + a_simple_expression = lttv_simple_expression_new(); + } + break; + + case '^': /* xor */ + + t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1); + while(t1->right != LTTV_TREE_IDLE) { + g_assert(t1->right == LTTV_TREE_NODE); + t1 = t1->r_child.t; + } + t2 = lttv_filter_tree_new(); + t2->node = LTTV_LOGICAL_XOR; + t1->right = LTTV_TREE_NODE; + t1->r_child.t = t2; + if(not) { // add not operator to tree + t3 = lttv_filter_tree_new(); + t3->node = LTTV_LOGICAL_NOT; + t2->left = LTTV_TREE_NODE; + t2->l_child.t = t3; + t2 = t3; + not = 0; + } + if(subtree != NULL) { /* append subtree to current tree */ + t2->left = LTTV_TREE_NODE; + t2->l_child.t = subtree; + subtree = NULL; + } else { /* append a simple expression */ + lttv_simple_expression_assign_value(a_simple_expression, + g_string_free(a_field_component,FALSE)); + a_field_component = g_string_new(""); + g_string_free(a_string_spaces, TRUE); + a_string_spaces = g_string_new(""); + t2->left = LTTV_TREE_LEAF; + t2->l_child.leaf = a_simple_expression; + a_simple_expression = lttv_simple_expression_new(); + } + break; + + case '!': /* not, or not equal (math op) */ + + if(filter->expression[i+1] == '=') { /* != */ + g_ptr_array_add( a_field_path,(gpointer) a_field_component ); + lttv_simple_expression_assign_field(a_field_path,a_simple_expression); + a_field_component = g_string_new(""); + g_string_free(a_string_spaces, TRUE); + a_string_spaces = g_string_new(""); + lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_NE); + i++; + } else { /* ! */ + not=1; + } + break; + + case '(': /* start of parenthesis */ + case '[': + case '{': + + p_nesting++; /* incrementing parenthesis nesting value */ + t1 = lttv_filter_tree_new(); + if(not) { /* add not operator to tree */ + t3 = lttv_filter_tree_new(); + t3->node = LTTV_LOGICAL_NOT; + t1->right = LTTV_TREE_NODE; + t1->r_child.t = t3; + not = 0; + } + g_ptr_array_add( tree_stack,(gpointer) t1 ); + break; + + case ')': /* end of parenthesis */ + case ']': + case '}': + + p_nesting--; /* decrementing parenthesis nesting value */ + if(p_nesting<0 || tree_stack->len<2) { + g_warning("Wrong filtering options, the string\n\"%s\"\n\ + is not valid due to parenthesis incorrect use",filter->expression); + return FALSE; + } + + /* there must at least be the root tree left in the array */ + g_assert(tree_stack->len>0); + + t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); + while(t1->right != LTTV_TREE_IDLE) { + t1 = t1->r_child.t; + } + if(not) { // add not operator to tree + g_print("ici"); + t3 = lttv_filter_tree_new(); + t3->node = LTTV_LOGICAL_NOT; + t1->right = LTTV_TREE_NODE; + t1->r_child.t = t3; + t1 = t3; + not = 0; + } + if(subtree != NULL) { /* append subtree to current tree */ + t1->right = LTTV_TREE_NODE; + t1->r_child.t = subtree; + subtree = g_ptr_array_index(tree_stack,tree_stack->len-1); + g_ptr_array_remove_index(tree_stack,tree_stack->len-1); + } else { /* assign subtree as current tree */ + lttv_simple_expression_assign_value(a_simple_expression, + g_string_free(a_field_component,FALSE)); + a_field_component = g_string_new(""); + g_string_free(a_string_spaces, TRUE); + a_string_spaces = g_string_new(""); + t1->right = LTTV_TREE_LEAF; + t1->r_child.leaf = a_simple_expression; + a_simple_expression = lttv_simple_expression_new(); + subtree = g_ptr_array_remove_index(tree_stack,tree_stack->len-1); + } + break; + + /* + * mathematic operators + */ + case '<': /* lower, lower or equal */ + + g_ptr_array_add( a_field_path,(gpointer) a_field_component ); + lttv_simple_expression_assign_field(a_field_path,a_simple_expression); + a_field_component = g_string_new(""); + g_string_free(a_string_spaces, TRUE); + a_string_spaces = g_string_new(""); + if(filter->expression[i+1] == '=') { /* <= */ + i++; + lttv_simple_expression_assign_operator(a_simple_expression, + LTTV_FIELD_LE); + } else lttv_simple_expression_assign_operator(a_simple_expression, + LTTV_FIELD_LT); + break; + + case '>': /* higher, higher or equal */ + + g_ptr_array_add( a_field_path,(gpointer) a_field_component ); + lttv_simple_expression_assign_field(a_field_path,a_simple_expression); + a_field_component = g_string_new(""); + g_string_free(a_string_spaces, TRUE); + a_string_spaces = g_string_new(""); + if(filter->expression[i+1] == '=') { /* >= */ + i++; + lttv_simple_expression_assign_operator(a_simple_expression, + LTTV_FIELD_GE); + } else lttv_simple_expression_assign_operator(a_simple_expression, + LTTV_FIELD_GT); + break; + + case '=': /* equal */ + + g_ptr_array_add( a_field_path,(gpointer) a_field_component ); + lttv_simple_expression_assign_field(a_field_path,a_simple_expression); + a_field_component = g_string_new(""); + g_string_free(a_string_spaces, TRUE); + a_string_spaces = g_string_new(""); + lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_EQ); + break; + + /* + * Field concatening caracter + */ + case '.': /* dot */ + + /* + * divide field expression into elements + * in a_field_path array. + * + * A dot can also be present in double values + */ + if(a_simple_expression->field == LTTV_FILTER_UNDEFINED) { + g_ptr_array_add( a_field_path,(gpointer) a_field_component ); + a_field_component = g_string_new(""); + g_string_free(a_string_spaces, TRUE); + a_string_spaces = g_string_new(""); + } else { + /* Operator found, we are in the value field */ + g_string_append_c(a_field_component, filter->expression[i]); + } + break; + case ' ': /* keep spaces that are within a field component */ + if(a_field_component->len == 0) break; /* ignore */ + else + a_string_spaces = g_string_append_c(a_string_spaces, + filter->expression[i]); + + case '\n': /* ignore */ + break; + case '\"': + nest_quotes?(nest_quotes=0):(nest_quotes=1); + break; + default: /* concatening current string */ + if(a_string_spaces->len != 0) { + a_field_component = g_string_append( + a_field_component, a_string_spaces->str); + a_string_spaces = g_string_set_size(a_string_spaces, 0); + } + a_field_component = g_string_append_c(a_field_component, + filter->expression[i]); + } + } + + /* + * Preliminary check to see + * if tree was constructed correctly + */ + if( p_nesting>0 ) { + g_warning("Wrong filtering options, the string\n\"%s\"\n\ + is not valid due to parenthesis incorrect use",filter->expression); + return FALSE; + } + + if(tree_stack->len != 1) /* only root tree should remain */ + return FALSE; + + /* + * processing last element of expression + */ + t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); + while(t1->right != LTTV_TREE_IDLE) { + g_assert(t1->right == LTTV_TREE_NODE); + t1 = t1->r_child.t; + } + if(not) { // add not operator to tree + t3 = lttv_filter_tree_new(); + t3->node = LTTV_LOGICAL_NOT; + t1->right = LTTV_TREE_NODE; + t1->r_child.t = t3; + t1 = t3; + not = 0; + } + if(subtree != NULL) { /* add the subtree */ + t1->right = LTTV_TREE_NODE; + t1->r_child.t = subtree; + subtree = NULL; + } else { /* add a leaf */ + lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); + a_field_component = NULL; + g_string_free(a_string_spaces, TRUE); + a_string_spaces = NULL; + t1->right = LTTV_TREE_LEAF; + t1->r_child.leaf = a_simple_expression; + a_simple_expression = NULL; + } + + + /* free the pointer array */ + g_assert(a_field_path->len == 0); + g_ptr_array_free(a_field_path,TRUE); + + /* free the tree stack -- but keep the root tree */ + filter->head = ltt_g_ptr_array_remove_index_slow(tree_stack,0); + g_ptr_array_free(tree_stack,TRUE); + + /* free the field buffer if allocated */ + if(a_field_component != NULL) g_string_free(a_field_component,TRUE); + if(a_string_spaces != NULL) g_string_free(a_string_spaces, TRUE); + + /* free the simple expression buffer if allocated */ + if(a_simple_expression != NULL) lttv_simple_expression_destroy(a_simple_expression); + + g_assert(filter->head != NULL); /* tree should exist */ + g_assert(subtree == NULL); /* remaining subtree should be included in main tree */ + #ifdef TEST - gettimeofday(&endtime, NULL); + gettimeofday(&endtime, NULL); - /* Calcul du temps de l'algorithme */ - double time1 = starttime.tv_sec + (starttime.tv_usec/1000000.0); - double time2 = endtime.tv_sec + (endtime.tv_usec/1000000.0); + /* Calcul du temps de l'algorithme */ + double time1 = starttime.tv_sec + (starttime.tv_usec/1000000.0); + double time2 = endtime.tv_sec + (endtime.tv_usec/1000000.0); // g_print("Tree build took %.10f ms for strlen of %i\n",(time2-time1)*1000,strlen(filter->expression)); - g_print("%.10f %i\n",(time2-time1)*1000,strlen(filter->expression)); + g_print("%.10f %i\n",(time2-time1)*1000,strlen(filter->expression)); #endif - - /* debug */ - g_debug("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n"); - lttv_print_tree(filter->head,0) ; - g_debug("+++++++++++++++ END PRINT ++++++++++++++++++\n"); - - /* success */ - return TRUE; + + /* debug */ + g_debug("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n"); + lttv_print_tree(filter->head,0) ; + g_debug("+++++++++++++++ END PRINT ++++++++++++++++++\n"); + + /* success */ + return TRUE; } @@ -1807,17 +1856,17 @@ lttv_filter_update(LttvFilter* filter) { * Destroy the current LttvFilter * @param filter pointer to the current LttvFilter */ -void -lttv_filter_destroy(LttvFilter* filter) { - - if(!filter) return; - - if(filter->expression) - g_free(filter->expression); - if(filter->head) - lttv_filter_tree_destroy(filter->head); - g_free(filter); - +void lttv_filter_destroy(LttvFilter* filter) +{ + + if(!filter) return; + + if(filter->expression) + g_free(filter->expression); + if(filter->head) + lttv_filter_tree_destroy(filter->head); + g_free(filter); + } /** @@ -1827,18 +1876,18 @@ lttv_filter_destroy(LttvFilter* filter) { * or sub expression * @return pointer of LttvFilterTree */ -LttvFilterTree* -lttv_filter_tree_new() { - LttvFilterTree* tree; - - tree = g_new(LttvFilterTree,1); - tree->node = 0; //g_new(lttv_expression,1); - tree->left = LTTV_TREE_IDLE; - tree->right = LTTV_TREE_IDLE; - tree->r_child.t = NULL; - tree->l_child.t = NULL; - - return tree; +LttvFilterTree* lttv_filter_tree_new() +{ + LttvFilterTree* tree; + + tree = g_new(LttvFilterTree,1); + tree->node = 0; //g_new(lttv_expression,1); + tree->left = LTTV_TREE_IDLE; + tree->right = LTTV_TREE_IDLE; + tree->r_child.t = NULL; + tree->l_child.t = NULL; + + return tree; } /** @@ -1850,26 +1899,26 @@ lttv_filter_tree_new() { * @param expression string that must be appended * @return Success/Failure of operation */ -gboolean -lttv_filter_append_expression(LttvFilter* filter, const char *expression) { +gboolean lttv_filter_append_expression(LttvFilter* filter, + const char *expression) +{ + if(expression == NULL) return FALSE; + if(filter == NULL) return FALSE; + if(expression[0] == '\0') return FALSE; /* Empty expression */ - if(expression == NULL) return FALSE; - if(filter == NULL) return FALSE; - if(expression[0] == '\0') return FALSE; /* Empty expression */ + GString* s = g_string_new(""); + if(filter->expression != NULL) { + s = g_string_append(s,filter->expression); + s = g_string_append_c(s,'&'); + } + s = g_string_append(s,expression); + + g_free(filter->expression); + filter->expression = g_string_free(s,FALSE); + + /* TRUE if construction of tree proceeded without errors */ + return lttv_filter_update(filter); - GString* s = g_string_new(""); - if(filter->expression != NULL) { - s = g_string_append(s,filter->expression); - s = g_string_append_c(s,'&'); - } - s = g_string_append(s,expression); - - g_free(filter->expression); - filter->expression = g_string_free(s,FALSE); - - /* TRUE if construction of tree proceeded without errors */ - return lttv_filter_update(filter); - } /** @@ -1879,14 +1928,13 @@ lttv_filter_append_expression(LttvFilter* filter, const char *expression) { * current filter and sets its pointer to NULL * @param filter pointer to the current LttvFilter */ -void -lttv_filter_clear_expression(LttvFilter* filter) { - - if(filter->expression != NULL) { - g_free(filter->expression); - filter->expression = NULL; - } - +void lttv_filter_clear_expression(LttvFilter* filter) +{ + if(filter->expression != NULL) { + g_free(filter->expression); + filter->expression = NULL; + } + } /** @@ -1895,19 +1943,18 @@ lttv_filter_clear_expression(LttvFilter* filter) { * Destroys the tree and his sub-trees * @param tree Tree which must be destroyed */ -void -lttv_filter_tree_destroy(LttvFilterTree* tree) { - - if(tree == NULL) return; +void lttv_filter_tree_destroy(LttvFilterTree* tree) +{ + if(tree == NULL) return; - if(tree->left == LTTV_TREE_LEAF) lttv_simple_expression_destroy(tree->l_child.leaf); - else if(tree->left == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->l_child.t); + if(tree->left == LTTV_TREE_LEAF) lttv_simple_expression_destroy(tree->l_child.leaf); + else if(tree->left == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->l_child.t); - if(tree->right == LTTV_TREE_LEAF) lttv_simple_expression_destroy(tree->r_child.leaf); - else if(tree->right == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->r_child.t); + if(tree->right == LTTV_TREE_LEAF) lttv_simple_expression_destroy(tree->r_child.leaf); + else if(tree->right == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->r_child.t); -// g_free(tree->node); - g_free(tree); +// g_free(tree->node); + g_free(tree); } /** @@ -1921,117 +1968,118 @@ lttv_filter_tree_destroy(LttvFilterTree* tree) { * @param context current LttvTracefileContext, NULL if not used * @return response of filter */ -gboolean -lttv_filter_tree_parse( - const LttvFilterTree* t, - const LttEvent* event, - const LttTracefile* tracefile, - const LttTrace* trace, - const LttvTracefileContext* context, - const LttvProcessState* state, - const LttvTraceContext* tc - /*,...*/) +gboolean lttv_filter_tree_parse( + const LttvFilterTree* t, + const LttEvent* event, + const LttTracefile* tracefile, + const LttTrace* trace, + const LttvTracefileContext* context, + const LttvProcessState* state, + const LttvTraceContext* tc + /*,...*/) { - /* - * Each tree is parsed in inorder. - * This way, it's possible to apply the left filter of the - * tree, then decide whether or not the right branch should - * be parsed depending on the linking logical operator - * - * Each node consists in a - * 1. logical operator - * 2. left child ( node or simple expression ) - * 3. right child ( node or simple expression ) - * - * When the child is a simple expression, we must - * before all determine if the expression refers to - * a structure which is whithin observation ( not NULL ). - * -If so, the expression is evaluated. - * -If not, the result is set to TRUE since this particular - * operation does not interfere with the lttv structure - * - * The result of each simple expression will directly - * affect the next branch. This way, depending on - * the linking logical operator, the parser will decide - * to explore or not the next branch. - * 1. AND OPERATOR - * -If result of left branch is 0 / FALSE - * then don't explore right branch and return 0; - * -If result of left branch is 1 / TRUE then explore - * 2. OR OPERATOR - * -If result of left branch is 1 / TRUE - * then don't explore right branch and return 1; - * -If result of left branch is 0 / FALSE then explore - * 3. XOR OPERATOR - * -Result of left branch will not affect exploration of - * right branch - */ - - gboolean lresult = FALSE, rresult = FALSE; - - LttvTraceState *ts = NULL; - LttvTracefileState *tfs = (LttvTracefileState*)context; - if(tc) - ts = (LttvTraceState*)tc; - else if(context) - ts = (LttvTraceState*)context->t_context; - - if(tfs) { - guint cpu = tfs->cpu; - if(ts) - state = ts->running_process[cpu]; - } - - /* - * Parse left branch - */ - if(t->left == LTTV_TREE_NODE) { - lresult = lttv_filter_tree_parse(t->l_child.t,event,tracefile,trace,context,NULL,NULL); - } - else if(t->left == LTTV_TREE_LEAF) { - lresult = lttv_filter_tree_parse_branch(t->l_child.leaf,event,tracefile,trace,state,context); - } - - /* - * Parse linking operator - * make a cutoff if possible - */ - if((t->node & LTTV_LOGICAL_OR) && lresult == TRUE) return TRUE; - if((t->node & LTTV_LOGICAL_AND) && lresult == FALSE) return FALSE; - - /* - * Parse right branch - */ - if(t->right == LTTV_TREE_NODE) { - rresult = lttv_filter_tree_parse(t->r_child.t,event,tracefile,trace,context,NULL,NULL); - } - else if(t->right == LTTV_TREE_LEAF) { - rresult = lttv_filter_tree_parse_branch(t->r_child.leaf,event,tracefile,trace,state,context); - } - - - /* - * Apply and return the - * logical link between the - * two operation - */ - switch(t->node) { - case LTTV_LOGICAL_OR: return (lresult | rresult); - case LTTV_LOGICAL_AND: return (lresult & rresult); - case LTTV_LOGICAL_NOT: - return (t->left==LTTV_TREE_LEAF)?!lresult:((t->right==LTTV_TREE_LEAF)?!rresult:TRUE); - case LTTV_LOGICAL_XOR: return (lresult ^ rresult); - case 0: return (rresult); - default: - /* - * This case should never be - * parsed, if so, this subtree - * is cancelled ! - */ - return TRUE; - } - + /* + * Each tree is parsed in inorder. + * This way, it's possible to apply the left filter of the + * tree, then decide whether or not the right branch should + * be parsed depending on the linking logical operator + * + * Each node consists in a + * 1. logical operator + * 2. left child ( node or simple expression ) + * 3. right child ( node or simple expression ) + * + * When the child is a simple expression, we must + * before all determine if the expression refers to + * a structure which is whithin observation ( not NULL ). + * -If so, the expression is evaluated. + * -If not, the result is set to TRUE since this particular + * operation does not interfere with the lttv structure + * + * The result of each simple expression will directly + * affect the next branch. This way, depending on + * the linking logical operator, the parser will decide + * to explore or not the next branch. + * 1. AND OPERATOR + * -If result of left branch is 0 / FALSE + * then don't explore right branch and return 0; + * -If result of left branch is 1 / TRUE then explore + * 2. OR OPERATOR + * -If result of left branch is 1 / TRUE + * then don't explore right branch and return 1; + * -If result of left branch is 0 / FALSE then explore + * 3. XOR OPERATOR + * -Result of left branch will not affect exploration of + * right branch + */ + + gboolean lresult = FALSE, rresult = FALSE; + + LttvTraceState *ts = NULL; + LttvTracefileState *tfs = (LttvTracefileState*)context; + if(tc) + ts = (LttvTraceState*)tc; + else if(context) + ts = (LttvTraceState*)context->t_context; + + if(tfs) { + guint cpu = tfs->cpu; + if(ts) + state = ts->running_process[cpu]; + } + + /* + * Parse left branch + */ + if(t->left == LTTV_TREE_NODE) { + lresult = lttv_filter_tree_parse(t->l_child.t,event, + tracefile,trace,context,NULL,NULL); + } + else if(t->left == LTTV_TREE_LEAF) { + lresult = lttv_filter_tree_parse_branch(t->l_child.leaf,event, + tracefile,trace,state,context); + } + + /* + * Parse linking operator + * make a cutoff if possible + */ + if((t->node & LTTV_LOGICAL_OR) && lresult == TRUE) return TRUE; + if((t->node & LTTV_LOGICAL_AND) && lresult == FALSE) return FALSE; + + /* + * Parse right branch + */ + if(t->right == LTTV_TREE_NODE) { + rresult = lttv_filter_tree_parse(t->r_child.t,event,tracefile,trace,context,NULL,NULL); + } + else if(t->right == LTTV_TREE_LEAF) { + rresult = lttv_filter_tree_parse_branch(t->r_child.leaf,event,tracefile,trace,state,context); + } + + + /* + * Apply and return the + * logical link between the + * two operation + */ + switch(t->node) { + case LTTV_LOGICAL_OR: return (lresult | rresult); + case LTTV_LOGICAL_AND: return (lresult & rresult); + case LTTV_LOGICAL_NOT: + return (t->left==LTTV_TREE_LEAF)?!lresult:((t->right==LTTV_TREE_LEAF)?!rresult:TRUE); + case LTTV_LOGICAL_XOR: return (lresult ^ rresult); + case 0: return (rresult); + default: + /* + * This case should never be + * parsed, if so, this subtree + * is cancelled ! + */ + return TRUE; + } + } /** @@ -2044,156 +2092,155 @@ lttv_filter_tree_parse( * @param context current LttvTracefileContext, NULL if not used * @return response of filter */ -gboolean -lttv_filter_tree_parse_branch( - const LttvSimpleExpression* se, - const LttEvent* event, - const LttTracefile* tracefile, - const LttTrace* trace, - const LttvProcessState* state, - const LttvTracefileContext* context) { - - LttvFieldValue v; - v = se->value; - switch(se->field) { - case LTTV_FILTER_TRACE_NAME: - if(trace == NULL) return TRUE; - else { - GQuark quark = ltt_trace_name(trace); - return se->op((gpointer)&quark,v); - } - break; - case LTTV_FILTER_TRACEFILE_NAME: - if(tracefile == NULL) return TRUE; - else { - GQuark quark = ltt_tracefile_name(tracefile); - return se->op((gpointer)&quark,v); - } - break; - case LTTV_FILTER_STATE_PID: - if(state == NULL) return TRUE; - else return se->op((gpointer)&state->pid,v); - break; - case LTTV_FILTER_STATE_PPID: - if(state == NULL) return TRUE; - else return se->op((gpointer)&state->ppid,v); - break; - case LTTV_FILTER_STATE_CT: - if(state == NULL) return TRUE; - else { - return se->op((gpointer)&state->creation_time,v); - } - break; - case LTTV_FILTER_STATE_IT: - if(state == NULL) return TRUE; - else { - return se->op((gpointer)&state->insertion_time,v); - } - break; - case LTTV_FILTER_STATE_P_NAME: - if(state == NULL) return TRUE; - else { - GQuark quark = state->name; - return se->op((gpointer)&quark,v); - } - break; - case LTTV_FILTER_STATE_T_BRAND: - if(state == NULL) return TRUE; - else { - GQuark quark = state->brand; - return se->op((gpointer)&quark,v); - } - break; - case LTTV_FILTER_STATE_EX_MODE: - if(state == NULL) return TRUE; - else return se->op((gpointer)&state->state->t,v); - break; - case LTTV_FILTER_STATE_EX_SUBMODE: - if(state == NULL) return TRUE; - else return se->op((gpointer)&state->state->n,v); - break; - case LTTV_FILTER_STATE_P_STATUS: - if(state == NULL) return TRUE; - else return se->op((gpointer)&state->state->s,v); - break; - case LTTV_FILTER_STATE_CPU: - if(state == NULL) return TRUE; - else { - return se->op((gpointer)&state->cpu,v); - } - break; - case LTTV_FILTER_EVENT_NAME: - if(event == NULL) return TRUE; - else { - struct marker_info *info; - GQuark qtuple[2]; - LttTracefile *tf = context->tf; - qtuple[0] = ltt_tracefile_name(tracefile); - info = marker_get_info_from_id(tf->mdata, event->event_id); - g_assert(info != NULL); - qtuple[1] = info->name; - return se->op((gpointer)qtuple,v); - } - break; - case LTTV_FILTER_EVENT_SUBNAME: - if(event == NULL) return TRUE; - else { - struct marker_info *info; - LttTracefile *tf = context->tf; - info = marker_get_info_from_id(tf->mdata, event->event_id); - g_assert(info != NULL); - GQuark quark = info->name; - return se->op((gpointer)&quark,v); - } - break; - case LTTV_FILTER_EVENT_CATEGORY: - /* - * TODO: Not yet implemented - */ - return TRUE; - break; - case LTTV_FILTER_EVENT_TIME: - if(event == NULL) return TRUE; - else { - LttTime time = ltt_event_time(event); - return se->op((gpointer)&time,v); - } - break; - case LTTV_FILTER_EVENT_TSC: - if(event == NULL) return TRUE; - else { - LttCycleCount count = ltt_event_cycle_count(event); - return se->op((gpointer)&count,v); - } - break; - case LTTV_FILTER_EVENT_TARGET_PID: - if(context == NULL) return TRUE; - else { - guint target_pid = - lttv_state_get_target_pid((LttvTracefileState*)context); - return se->op((gpointer)&target_pid,v); - } - break; - case LTTV_FILTER_EVENT_FIELD: - /* - * TODO: Use the offset to - * find the dynamic field - * in the event struct - */ - return TRUE; - default: - /* - * This case should never be - * parsed, if so, the whole - * filtering is cancelled - */ - g_warning("Error while parsing the filter tree"); - return TRUE; - } - - /* should never get here */ - return TRUE; - +gboolean lttv_filter_tree_parse_branch( + const LttvSimpleExpression* se, + const LttEvent* event, + const LttTracefile* tracefile, + const LttTrace* trace, + const LttvProcessState* state, + const LttvTracefileContext* context) { + + LttvFieldValue v; + v = se->value; + switch(se->field) { + case LTTV_FILTER_TRACE_NAME: + if(trace == NULL) return TRUE; + else { + GQuark quark = ltt_trace_name(trace); + return se->op((gpointer)&quark,v); + } + break; + case LTTV_FILTER_TRACEFILE_NAME: + if(tracefile == NULL) return TRUE; + else { + GQuark quark = ltt_tracefile_name(tracefile); + return se->op((gpointer)&quark,v); + } + break; + case LTTV_FILTER_STATE_PID: + if(state == NULL) return TRUE; + else return se->op((gpointer)&state->pid,v); + break; + case LTTV_FILTER_STATE_PPID: + if(state == NULL) return TRUE; + else return se->op((gpointer)&state->ppid,v); + break; + case LTTV_FILTER_STATE_CT: + if(state == NULL) return TRUE; + else { + return se->op((gpointer)&state->creation_time,v); + } + break; + case LTTV_FILTER_STATE_IT: + if(state == NULL) return TRUE; + else { + return se->op((gpointer)&state->insertion_time,v); + } + break; + case LTTV_FILTER_STATE_P_NAME: + if(state == NULL) return TRUE; + else { + GQuark quark = state->name; + return se->op((gpointer)&quark,v); + } + break; + case LTTV_FILTER_STATE_T_BRAND: + if(state == NULL) return TRUE; + else { + GQuark quark = state->brand; + return se->op((gpointer)&quark,v); + } + break; + case LTTV_FILTER_STATE_EX_MODE: + if(state == NULL) return TRUE; + else return se->op((gpointer)&state->state->t,v); + break; + case LTTV_FILTER_STATE_EX_SUBMODE: + if(state == NULL) return TRUE; + else return se->op((gpointer)&state->state->n,v); + break; + case LTTV_FILTER_STATE_P_STATUS: + if(state == NULL) return TRUE; + else return se->op((gpointer)&state->state->s,v); + break; + case LTTV_FILTER_STATE_CPU: + if(state == NULL) return TRUE; + else { + return se->op((gpointer)&state->cpu,v); + } + break; + case LTTV_FILTER_EVENT_NAME: + if(event == NULL) return TRUE; + else { + struct marker_info *info; + GQuark qtuple[2]; + LttTracefile *tf = context->tf; + qtuple[0] = ltt_tracefile_name(tracefile); + info = marker_get_info_from_id(tf->mdata, event->event_id); + g_assert(info != NULL); + qtuple[1] = info->name; + return se->op((gpointer)qtuple,v); + } + break; + case LTTV_FILTER_EVENT_SUBNAME: + if(event == NULL) return TRUE; + else { + struct marker_info *info; + LttTracefile *tf = context->tf; + info = marker_get_info_from_id(tf->mdata, event->event_id); + g_assert(info != NULL); + GQuark quark = info->name; + return se->op((gpointer)&quark,v); + } + break; + case LTTV_FILTER_EVENT_CATEGORY: + /* + * TODO: Not yet implemented + */ + return TRUE; + break; + case LTTV_FILTER_EVENT_TIME: + if(event == NULL) return TRUE; + else { + LttTime time = ltt_event_time(event); + return se->op((gpointer)&time,v); + } + break; + case LTTV_FILTER_EVENT_TSC: + if(event == NULL) return TRUE; + else { + LttCycleCount count = ltt_event_cycle_count(event); + return se->op((gpointer)&count,v); + } + break; + case LTTV_FILTER_EVENT_TARGET_PID: + if(context == NULL) return TRUE; + else { + guint target_pid = + lttv_state_get_target_pid((LttvTracefileState*)context); + return se->op((gpointer)&target_pid,v); + } + break; + case LTTV_FILTER_EVENT_FIELD: + /* + * TODO: Use the offset to + * find the dynamic field + * in the event struct + */ + return TRUE; + default: + /* + * This case should never be + * parsed, if so, the whole + * filtering is cancelled + */ + g_warning("Error while parsing the filter tree"); + return TRUE; + } + + /* should never get here */ + return TRUE; + } @@ -2202,29 +2249,28 @@ lttv_filter_tree_parse_branch( * Debug function. Prints tree memory allocation. * @param t the pointer to the current LttvFilterTree */ -void -lttv_print_tree(const LttvFilterTree* t, const int count) { - - g_debug("node:%p lchild:%p rchild:%p depth:%i\n",t, //t->l_child.t,t->r_child.t); - (t->left==LTTV_TREE_NODE)?t->l_child.t:NULL, - (t->right==LTTV_TREE_NODE)?t->r_child.t:NULL, - count); - g_debug("logic operator: %s\n",(t->node&1)?"OR":((t->node&2)?"AND":((t->node&4)?"NOT":((t->node&8)?"XOR":"IDLE")))); - g_debug("|-> left branch %p is a %s\n",t->l_child.t,(t->left==LTTV_TREE_NODE)?"NODE":((t->left==LTTV_TREE_LEAF)?"LEAF":"IDLE")); - if(t->left == LTTV_TREE_LEAF) { - g_debug("| |-> field type number: %i\n",t->l_child.leaf->field); - g_debug("| |-> offset is: %i\n",t->l_child.leaf->offset); - g_debug("| |-> operator function is: %p\n",t->l_child.leaf->op); - } - g_debug("|-> right branch %p is a %s\n",t->r_child.t,(t->right==LTTV_TREE_NODE)?"NODE":((t->right==LTTV_TREE_LEAF)?"LEAF":"IDLE")); - if(t->right == LTTV_TREE_LEAF) { - g_debug("| |-> field type number: %i\n",t->r_child.leaf->field); - g_debug("| |-> offset is: %i\n",t->r_child.leaf->offset); - g_debug("| |-> operator function is: %p\n",t->r_child.leaf->op); - } - - if(t->left == LTTV_TREE_NODE) lttv_print_tree(t->l_child.t,count+1); - if(t->right == LTTV_TREE_NODE) lttv_print_tree(t->r_child.t,count+1); +void lttv_print_tree(const LttvFilterTree* t, const int count) +{ + g_debug("node:%p lchild:%p rchild:%p depth:%i\n",t, //t->l_child.t,t->r_child.t); + (t->left==LTTV_TREE_NODE)?t->l_child.t:NULL, + (t->right==LTTV_TREE_NODE)?t->r_child.t:NULL, + count); + g_debug("logic operator: %s\n",(t->node&1)?"OR":((t->node&2)?"AND":((t->node&4)?"NOT":((t->node&8)?"XOR":"IDLE")))); + g_debug("|-> left branch %p is a %s\n",t->l_child.t,(t->left==LTTV_TREE_NODE)?"NODE":((t->left==LTTV_TREE_LEAF)?"LEAF":"IDLE")); + if(t->left == LTTV_TREE_LEAF) { + g_debug("| |-> field type number: %i\n",t->l_child.leaf->field); + g_debug("| |-> offset is: %i\n",t->l_child.leaf->offset); + g_debug("| |-> operator function is: %p\n",t->l_child.leaf->op); + } + g_debug("|-> right branch %p is a %s\n",t->r_child.t,(t->right==LTTV_TREE_NODE)?"NODE":((t->right==LTTV_TREE_LEAF)?"LEAF":"IDLE")); + if(t->right == LTTV_TREE_LEAF) { + g_debug("| |-> field type number: %i\n",t->r_child.leaf->field); + g_debug("| |-> offset is: %i\n",t->r_child.leaf->offset); + g_debug("| |-> operator function is: %p\n",t->r_child.leaf->op); + } + + if(t->left == LTTV_TREE_NODE) lttv_print_tree(t->l_child.t,count+1); + if(t->right == LTTV_TREE_NODE) lttv_print_tree(t->r_child.t,count+1); } /** @@ -2247,8 +2293,8 @@ static void module_destroy() LTTV_MODULE("filter", "Filters traceset and events", \ - "Filters traceset and events specifically to user input", \ - module_init, module_destroy) + "Filters traceset and events specifically to user input", \ + module_init, module_destroy) diff --git a/lttv/lttv/filter.h b/lttv/lttv/filter.h index d942752d..1bbd5f51 100644 --- a/lttv/lttv/filter.h +++ b/lttv/lttv/filter.h @@ -80,11 +80,11 @@ typedef struct _LttvFilter LttvFilter; * lttv core filter */ enum _LttvStructType { - LTTV_FILTER_TRACE, /**< trace (LttTrace) */ - LTTV_FILTER_TRACESET, /**< traceset */ - LTTV_FILTER_TRACEFILE, /**< tracefile (LttTracefile) */ - LTTV_FILTER_EVENT, /**< event (LttEvent) */ - LTTV_FILTER_STATE /**< state (LttvProcessState) */ + LTTV_FILTER_TRACE, /**< trace (LttTrace) */ + LTTV_FILTER_TRACESET, /**< traceset */ + LTTV_FILTER_TRACEFILE, /**< tracefile (LttTracefile) */ + LTTV_FILTER_EVENT, /**< event (LttEvent) */ + LTTV_FILTER_STATE /**< state (LttvProcessState) */ }; /** @@ -97,28 +97,28 @@ enum _LttvStructType { * filters can be applied. */ enum _LttvFieldType { - LTTV_FILTER_TRACE_NAME, /**< trace.name (char*) */ - LTTV_FILTER_TRACEFILE_NAME, /**< tracefile.name (char*) */ - LTTV_FILTER_STATE_PID, /**< state.pid (guint) */ - LTTV_FILTER_STATE_PPID, /**< state.ppid (guint) */ - LTTV_FILTER_STATE_CT, /**< state.creation_time (double) */ - LTTV_FILTER_STATE_IT, /**< state.insertion_time (double) */ - LTTV_FILTER_STATE_P_NAME, /**< state.process_name (char*) */ - LTTV_FILTER_STATE_T_BRAND, /**< state.thread_brand (char*) */ - LTTV_FILTER_STATE_EX_MODE, /**< state.execution_mode (LttvExecutionMode) */ - LTTV_FILTER_STATE_EX_SUBMODE, /**< state.execution_submode (LttvExecutionSubmode) */ - LTTV_FILTER_STATE_P_STATUS, /**< state.process_status (LttvProcessStatus) */ - LTTV_FILTER_STATE_CPU, /**< state.cpu (?last_cpu?) */ - LTTV_FILTER_EVENT_NAME, /**< event.name (char*) */ - LTTV_FILTER_EVENT_SUBNAME, /**< event.subname (char*) */ - LTTV_FILTER_EVENT_CATEGORY, /**< FIXME: not implemented */ - LTTV_FILTER_EVENT_TIME, /**< event.time (double) */ - LTTV_FILTER_EVENT_TSC, /**< event.tsc (double) */ - LTTV_FILTER_EVENT_TARGET_PID, /**< event.target_pid (guint) */ - LTTV_FILTER_EVENT_FIELD, /**< dynamic field, specified in facility */ - LTTV_FILTER_UNDEFINED /**< undefined field */ + LTTV_FILTER_TRACE_NAME, /**< trace.name (char*) */ + LTTV_FILTER_TRACEFILE_NAME, /**< tracefile.name (char*) */ + LTTV_FILTER_STATE_PID, /**< state.pid (guint) */ + LTTV_FILTER_STATE_PPID, /**< state.ppid (guint) */ + LTTV_FILTER_STATE_CT, /**< state.creation_time (double) */ + LTTV_FILTER_STATE_IT, /**< state.insertion_time (double) */ + LTTV_FILTER_STATE_P_NAME, /**< state.process_name (char*) */ + LTTV_FILTER_STATE_T_BRAND, /**< state.thread_brand (char*) */ + LTTV_FILTER_STATE_EX_MODE, /**< state.execution_mode (LttvExecutionMode) */ + LTTV_FILTER_STATE_EX_SUBMODE, /**< state.execution_submode (LttvExecutionSubmode) */ + LTTV_FILTER_STATE_P_STATUS, /**< state.process_status (LttvProcessStatus) */ + LTTV_FILTER_STATE_CPU, /**< state.cpu (?last_cpu?) */ + LTTV_FILTER_EVENT_NAME, /**< event.name (char*) */ + LTTV_FILTER_EVENT_SUBNAME, /**< event.subname (char*) */ + LTTV_FILTER_EVENT_CATEGORY, /**< FIXME: not implemented */ + LTTV_FILTER_EVENT_TIME, /**< event.time (double) */ + LTTV_FILTER_EVENT_TSC, /**< event.tsc (double) */ + LTTV_FILTER_EVENT_TARGET_PID, /**< event.target_pid (guint) */ + LTTV_FILTER_EVENT_FIELD, /**< dynamic field, specified in facility */ + LTTV_FILTER_UNDEFINED /**< undefined field */ }; - + /** * @enum _LttvExpressionOp * @brief Contains possible operators @@ -130,12 +130,12 @@ enum _LttvFieldType { */ enum _LttvExpressionOp { - LTTV_FIELD_EQ, /**< equal */ - LTTV_FIELD_NE, /**< not equal */ - LTTV_FIELD_LT, /**< lower than */ - LTTV_FIELD_LE, /**< lower or equal */ - LTTV_FIELD_GT, /**< greater than */ - LTTV_FIELD_GE /**< greater or equal */ + LTTV_FIELD_EQ, /**< equal */ + LTTV_FIELD_NE, /**< not equal */ + LTTV_FIELD_LT, /**< lower than */ + LTTV_FIELD_LE, /**< lower or equal */ + LTTV_FIELD_GT, /**< greater than */ + LTTV_FIELD_GE /**< greater or equal */ }; /** @@ -144,22 +144,22 @@ enum _LttvExpressionOp * * This particular union defines the * possible set of values taken by the - * right member of a simple expression. + * right member of a simple expression. * It is used for comparison whithin the * 'operators' functions */ union _LttvFieldValue { - GQuark v_quark; /**< GQuark */ - guint64 v_uint64; /**< unsigned int of 64 bytes */ - guint32 v_uint32; /**< unsigned int of 32 bytes */ - guint16 v_uint16; /**< unsigned int of 16 bytes */ - guint16 v_uint; /**< unsigned int */ - double v_double; /**< double */ - char* v_string; /**< string */ - LttTime v_ltttime; /**< LttTime */ - struct { - GQuark q[2]; - } v_quarks; + GQuark v_quark; /**< GQuark */ + guint64 v_uint64; /**< unsigned int of 64 bytes */ + guint32 v_uint32; /**< unsigned int of 32 bytes */ + guint16 v_uint16; /**< unsigned int of 16 bytes */ + guint16 v_uint; /**< unsigned int */ + double v_double; /**< double */ + char* v_string; /**< string */ + LttTime v_ltttime; /**< LttTime */ + struct { + GQuark q[2]; + } v_quarks; }; /** @@ -167,12 +167,12 @@ union _LttvFieldValue { * @brief element types for the tree nodes * * LttvTreeElement defines the possible - * types of nodes which build the LttvFilterTree. + * types of nodes which build the LttvFilterTree. */ enum _LttvTreeElement { - LTTV_TREE_IDLE, /**< this node does nothing */ - LTTV_TREE_NODE, /**< this node contains a logical operator */ - LTTV_TREE_LEAF /**< this node is a leaf and contains a simple expression */ + LTTV_TREE_IDLE, /**< this node does nothing */ + LTTV_TREE_NODE, /**< this node contains a logical operator */ + LTTV_TREE_LEAF /**< this node is a leaf and contains a simple expression */ }; @@ -190,10 +190,10 @@ enum _LttvTreeElement { */ struct _LttvSimpleExpression { - gint field; /**< left member of simple expression */ - gint offset; /**< offset used for dynamic fields */ - gboolean (*op)(gpointer,LttvFieldValue); /**< operator of simple expression */ - LttvFieldValue value; /**< right member of simple expression */ + gint field; /**< left member of simple expression */ + gint offset; /**< offset used for dynamic fields */ + gboolean (*op)(gpointer,LttvFieldValue); /**< operator of simple expression */ + LttvFieldValue value; /**< right member of simple expression */ }; /** @@ -206,10 +206,10 @@ struct _LttvSimpleExpression * AND, OR, XOR or NOT */ enum _LttvLogicalOp { - LTTV_LOGICAL_OR = 1, /**< OR (1) */ - LTTV_LOGICAL_AND = 1<<1, /**< AND (2) */ - LTTV_LOGICAL_NOT = 1<<2, /**< NOT (4) */ - LTTV_LOGICAL_XOR = 1<<3 /**< XOR (8) */ + LTTV_LOGICAL_OR = 1, /**< OR (1) */ + LTTV_LOGICAL_AND = 1<<1, /**< AND (2) */ + LTTV_LOGICAL_NOT = 1<<2, /**< NOT (4) */ + LTTV_LOGICAL_XOR = 1<<3 /**< XOR (8) */ }; /** @@ -222,17 +222,17 @@ enum _LttvLogicalOp { * operators */ struct _LttvFilterTree { - int node; /**< value of LttvLogicalOp */ - LttvTreeElement left; /**< nature of left branch (node/leaf) */ - LttvTreeElement right; /**< nature of right branch (node/leaf) */ - union { - LttvFilterTree* t; - LttvSimpleExpression* leaf; - } l_child; /**< left branch of tree */ - union { - LttvFilterTree* t; - LttvSimpleExpression* leaf; - } r_child; /**< right branch of tree */ + int node; /**< value of LttvLogicalOp */ + LttvTreeElement left; /**< nature of left branch (node/leaf) */ + LttvTreeElement right; /**< nature of right branch (node/leaf) */ + union { + LttvFilterTree* t; + LttvSimpleExpression* leaf; + } l_child; /**< left branch of tree */ + union { + LttvFilterTree* t; + LttvSimpleExpression* leaf; + } r_child; /**< right branch of tree */ }; /** @@ -243,8 +243,8 @@ struct _LttvFilterTree { * with the expression itself. */ struct _LttvFilter { - char *expression; /**< filtering expression string */ - LttvFilterTree *head; /**< tree associated to expression */ + char *expression; /**< filtering expression string */ + LttvFilterTree *head; /**< tree associated to expression */ }; /* @@ -252,11 +252,14 @@ struct _LttvFilter { */ LttvSimpleExpression* lttv_simple_expression_new(); -gboolean lttv_simple_expression_assign_field(GPtrArray* fp, LttvSimpleExpression* se); +gboolean lttv_simple_expression_assign_field(GPtrArray* fp, + LttvSimpleExpression* se); -gboolean lttv_simple_expression_assign_operator(LttvSimpleExpression* se, LttvExpressionOp op); +gboolean lttv_simple_expression_assign_operator(LttvSimpleExpression* se, + LttvExpressionOp op); -gboolean lttv_simple_expression_assign_value(LttvSimpleExpression* se, char* value); +gboolean lttv_simple_expression_assign_value(LttvSimpleExpression* se, + char* value); void lttv_simple_expression_destroy(LttvSimpleExpression* se); @@ -324,13 +327,14 @@ LttvFilter* lttv_filter_clone(const LttvFilter* filter); /* * LttvFilter */ -LttvFilter *lttv_filter_new(); +LttvFilter* lttv_filter_new(); gboolean lttv_filter_update(LttvFilter* filter); void lttv_filter_destroy(LttvFilter* filter); -gboolean lttv_filter_append_expression(LttvFilter* filter, const char *expression); +gboolean lttv_filter_append_expression(LttvFilter* filter, + const char *expression); void lttv_filter_clear_expression(LttvFilter* filter); @@ -342,21 +346,21 @@ LttvFilterTree* lttv_filter_tree_new(); void lttv_filter_tree_destroy(LttvFilterTree* tree); gboolean lttv_filter_tree_parse( - const LttvFilterTree* t, - const LttEvent* event, - const LttTracefile* tracefile, - const LttTrace* trace, - const LttvTracefileContext* context, - const LttvProcessState* pstate, - const LttvTraceContext* tc); + const LttvFilterTree* t, + const LttEvent* event, + const LttTracefile* tracefile, + const LttTrace* trace, + const LttvTracefileContext* context, + const LttvProcessState* pstate, + const LttvTraceContext* tc); gboolean lttv_filter_tree_parse_branch( - const LttvSimpleExpression* se, - const LttEvent* event, - const LttTracefile* tracefile, - const LttTrace* trace, - const LttvProcessState* state, - const LttvTracefileContext* context); + const LttvSimpleExpression* se, + const LttEvent* event, + const LttTracefile* tracefile, + const LttTrace* trace, + const LttvProcessState* state, + const LttvTracefileContext* context); /* * Debug functions diff --git a/lttv/lttv/hook.c b/lttv/lttv/hook.c index ae88fdeb..57dcb049 100644 --- a/lttv/lttv/hook.c +++ b/lttv/lttv/hook.c @@ -25,67 +25,67 @@ #include typedef struct _LttvHookClosure { - LttvHook hook; - void *hook_data; - LttvHookPrio prio; - guint ref_count; + LttvHook hook; + void *hook_data; + LttvHookPrio prio; + guint ref_count; } LttvHookClosure; gint lttv_hooks_prio_compare(LttvHookClosure *a, LttvHookClosure *b) { - gint ret=0; - if(a->prio < b->prio) ret = -1; - else if(a->prio > b->prio) ret = 1; - return ret; + gint ret=0; + if(a->prio < b->prio) ret = -1; + else if(a->prio > b->prio) ret = 1; + return ret; } LttvHooks *lttv_hooks_new() { - return g_array_new(FALSE, FALSE, sizeof(LttvHookClosure)); + return g_array_new(FALSE, FALSE, sizeof(LttvHookClosure)); } void lttv_hooks_destroy(LttvHooks *h) { - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "lttv_hooks_destroy()"); - g_array_free(h, TRUE); + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "lttv_hooks_destroy()"); + g_array_free(h, TRUE); } void lttv_hooks_add(LttvHooks *h, LttvHook f, void *hook_data, LttvHookPrio p) { - LttvHookClosure *c, new_c; - guint i; - - if(unlikely(h == NULL))g_error("Null hook added"); - - new_c.hook = f; - new_c.hook_data = hook_data; - new_c.prio = p; - new_c.ref_count = 1; - - /* Preliminary check for duplication */ - /* only hook and hook data is checked */ - for(i = 0; i < h->len; i++) { - c = &g_array_index(h, LttvHookClosure, i); - if(new_c.hook == c->hook && new_c.hook_data == c->hook_data) { - g_assert(new_c.prio == c->prio); - c->ref_count++; - return; - } - } - - - for(i = 0; i < h->len; i++) { - c = &g_array_index(h, LttvHookClosure, i); - if(new_c.prio < c->prio) { - g_array_insert_val(h,i,new_c); - return; - } - } - if(i == h->len) - g_array_append_val(h,new_c); + LttvHookClosure *c, new_c; + guint i; + + if(unlikely(h == NULL))g_error("Null hook added"); + + new_c.hook = f; + new_c.hook_data = hook_data; + new_c.prio = p; + new_c.ref_count = 1; + + /* Preliminary check for duplication */ + /* only hook and hook data is checked */ + for(i = 0; i < h->len; i++) { + c = &g_array_index(h, LttvHookClosure, i); + if(new_c.hook == c->hook && new_c.hook_data == c->hook_data) { + g_assert(new_c.prio == c->prio); + c->ref_count++; + return; + } + } + + + for(i = 0; i < h->len; i++) { + c = &g_array_index(h, LttvHookClosure, i); + if(new_c.prio < c->prio) { + g_array_insert_val(h,i,new_c); + return; + } + } + if(i == h->len) + g_array_append_val(h,new_c); } /* lttv_hooks_add_list @@ -100,194 +100,194 @@ void lttv_hooks_add(LttvHooks *h, LttvHook f, void *hook_data, LttvHookPrio p) */ void lttv_hooks_add_list(LttvHooks *h, const LttvHooks *list) { - guint i,j,k; - LttvHookClosure *c; - const LttvHookClosure *new_c; - - if(unlikely(list == NULL)) return; - - for(i = 0, j = 0 ; i < list->len; i++) { - new_c = &g_array_index(list, LttvHookClosure, i); - gboolean found=FALSE; - - /* Preliminary check for duplication */ - /* only hook and hook data is checked, not priority */ - for(k = 0; k < h->len; k++) { - c = &g_array_index(h, LttvHookClosure, k); - if(new_c->hook == c->hook && new_c->hook_data == c->hook_data) { - /* Found another identical entry : increment its ref_count and - * jump over the source index */ - g_assert(new_c->prio == c->prio); - found=TRUE; - c->ref_count++; - break; - } - } - - if(!found) { - /* If not found, add it to the destination array */ - while(j < h->len) { - c = &g_array_index(h, LttvHookClosure, j); - if(new_c->prio < c->prio) { - g_array_insert_val(h,j,*new_c); - j++; - break; - } - else j++; - } - if(j == h->len) { - g_array_append_val(h,*new_c); - j++; - } - } - } + guint i,j,k; + LttvHookClosure *c; + const LttvHookClosure *new_c; + + if(unlikely(list == NULL)) return; + + for(i = 0, j = 0 ; i < list->len; i++) { + new_c = &g_array_index(list, LttvHookClosure, i); + gboolean found=FALSE; + + /* Preliminary check for duplication */ + /* only hook and hook data is checked, not priority */ + for(k = 0; k < h->len; k++) { + c = &g_array_index(h, LttvHookClosure, k); + if(new_c->hook == c->hook && new_c->hook_data == c->hook_data) { + /* Found another identical entry : increment its ref_count and + * jump over the source index */ + g_assert(new_c->prio == c->prio); + found=TRUE; + c->ref_count++; + break; + } + } + + if(!found) { + /* If not found, add it to the destination array */ + while(j < h->len) { + c = &g_array_index(h, LttvHookClosure, j); + if(new_c->prio < c->prio) { + g_array_insert_val(h,j,*new_c); + j++; + break; + } + else j++; + } + if(j == h->len) { + g_array_append_val(h,*new_c); + j++; + } + } + } } void *lttv_hooks_remove(LttvHooks *h, LttvHook f) { - unsigned i; - - void *hook_data; - - LttvHookClosure *c; - - for(i = 0 ; i < h->len ; i++) { - c = &g_array_index(h, LttvHookClosure, i); - if(c->hook == f) { - if(c->ref_count == 1) { - hook_data = c->hook_data; - lttv_hooks_remove_by_position(h, i); - return hook_data; - } else { - g_assert(c->ref_count != 0); - c->ref_count--; - return NULL; /* We do not want anyone to free a hook_data - still referenced */ - } - } - } - return NULL; + unsigned i; + + void *hook_data; + + LttvHookClosure *c; + + for(i = 0 ; i < h->len ; i++) { + c = &g_array_index(h, LttvHookClosure, i); + if(c->hook == f) { + if(c->ref_count == 1) { + hook_data = c->hook_data; + lttv_hooks_remove_by_position(h, i); + return hook_data; + } else { + g_assert(c->ref_count != 0); + c->ref_count--; + return NULL; /* We do not want anyone to free a hook_data + still referenced */ + } + } + } + return NULL; } void lttv_hooks_remove_data(LttvHooks *h, LttvHook f, void *hook_data) { - unsigned i; - - LttvHookClosure *c; - - for(i = 0 ; i < h->len ; i++) { - c = &g_array_index(h, LttvHookClosure, i); - if(c->hook == f && c->hook_data == hook_data) { - if(c->ref_count == 1) { - lttv_hooks_remove_by_position(h, i); - return; - } else { - g_assert(c->ref_count != 0); - c->ref_count--; - return; - } - } - } + unsigned i; + + LttvHookClosure *c; + + for(i = 0 ; i < h->len ; i++) { + c = &g_array_index(h, LttvHookClosure, i); + if(c->hook == f && c->hook_data == hook_data) { + if(c->ref_count == 1) { + lttv_hooks_remove_by_position(h, i); + return; + } else { + g_assert(c->ref_count != 0); + c->ref_count--; + return; + } + } + } } void lttv_hooks_remove_list(LttvHooks *h, LttvHooks *list) { - guint i, j; - - LttvHookClosure *c, *c_list; - - if(list == NULL) return; - for(i = 0, j = 0 ; i < h->len && j < list->len ;) { - c = &g_array_index(h, LttvHookClosure, i); - c_list = &g_array_index(list, LttvHookClosure, j); - if(c->hook == c_list->hook && c->hook_data == c_list->hook_data) { - if(c->ref_count == 1) { - lttv_hooks_remove_by_position(h, i); - } else { - g_assert(c->ref_count != 0); - c->ref_count--; - } - j++; - } - else i++; - } - - /* Normally the hooks in h are ordered as in list. If this is not the case, - try harder here. */ - - if(unlikely(j < list->len)) { - for(; j < list->len ; j++) { - c_list = &g_array_index(list, LttvHookClosure, j); - lttv_hooks_remove_data(h, c_list->hook, c_list->hook_data); - } - } + guint i, j; + + LttvHookClosure *c, *c_list; + + if(list == NULL) return; + for(i = 0, j = 0 ; i < h->len && j < list->len ;) { + c = &g_array_index(h, LttvHookClosure, i); + c_list = &g_array_index(list, LttvHookClosure, j); + if(c->hook == c_list->hook && c->hook_data == c_list->hook_data) { + if(c->ref_count == 1) { + lttv_hooks_remove_by_position(h, i); + } else { + g_assert(c->ref_count != 0); + c->ref_count--; + } + j++; + } + else i++; + } + + /* Normally the hooks in h are ordered as in list. If this is not the case, + try harder here. */ + + if(unlikely(j < list->len)) { + for(; j < list->len ; j++) { + c_list = &g_array_index(list, LttvHookClosure, j); + lttv_hooks_remove_data(h, c_list->hook, c_list->hook_data); + } + } } unsigned lttv_hooks_number(LttvHooks *h) { - return h->len; + return h->len; } void lttv_hooks_get(LttvHooks *h, unsigned i, LttvHook *f, void **hook_data, - LttvHookPrio *p) + LttvHookPrio *p) { - LttvHookClosure *c; - - if(unlikely(i >= h->len)) - { - *f = NULL; - *hook_data = NULL; - *p = 0; - return; - } - - c = &g_array_index(h, LttvHookClosure, i); - *f = c->hook; - *hook_data = c->hook_data; - *p = c->prio; + LttvHookClosure *c; + + if(unlikely(i >= h->len)) + { + *f = NULL; + *hook_data = NULL; + *p = 0; + return; + } + + c = &g_array_index(h, LttvHookClosure, i); + *f = c->hook; + *hook_data = c->hook_data; + *p = c->prio; } void lttv_hooks_remove_by_position(LttvHooks *h, unsigned i) { - g_array_remove_index(h, i); + g_array_remove_index(h, i); } gboolean lttv_hooks_call(LttvHooks *h, void *call_data) { - gboolean ret, sum_ret = FALSE; + gboolean ret, sum_ret = FALSE; - LttvHookClosure *c; + LttvHookClosure *c; - guint i; + guint i; - if(likely(h != NULL)) { - for(i = 0 ; i < h->len ; i++) { - c = &g_array_index(h, LttvHookClosure, i); - ret = c->hook(c->hook_data,call_data); - sum_ret = sum_ret || ret; - } - } - return sum_ret; + if(likely(h != NULL)) { + for(i = 0 ; i < h->len ; i++) { + c = &g_array_index(h, LttvHookClosure, i); + ret = c->hook(c->hook_data,call_data); + sum_ret = sum_ret || ret; + } + } + return sum_ret; } gboolean lttv_hooks_call_check(LttvHooks *h, void *call_data) { - LttvHookClosure *c; + LttvHookClosure *c; - guint i; + guint i; - for(i = 0 ; i < h->len ; i++) { - c = &g_array_index(h, LttvHookClosure, i); - if(unlikely(c->hook(c->hook_data,call_data))) return TRUE; - } - return FALSE; + for(i = 0 ; i < h->len ; i++) { + c = &g_array_index(h, LttvHookClosure, i); + if(unlikely(c->hook(c->hook_data,call_data))) return TRUE; + } + return FALSE; } /* Optimised for h1 == NULL, h2 != NULL. This is the case @@ -298,103 +298,101 @@ gboolean lttv_hooks_call_check(LttvHooks *h, void *call_data) * h1 != NULL , h2 == NULL. */ gint lttv_hooks_call_merge(LttvHooks *h1, void *call_data1, - LttvHooks *h2, void *call_data2) + LttvHooks *h2, void *call_data2) { - gint ret, sum_ret = 0; - - LttvHookClosure *c1, *c2; - - guint i, j; - - if(unlikely(h1 != NULL)) { - if(unlikely(h2 != NULL)) { - for(i = 0, j = 0 ; i < h1->len && j < h2->len ;) { - c1 = &g_array_index(h1, LttvHookClosure, i); - c2 = &g_array_index(h2, LttvHookClosure, j); - if(c1->prio <= c2->prio) { - ret = c1->hook(c1->hook_data,call_data1); - sum_ret = sum_ret | ret; - i++; - } - else { - ret = c2->hook(c2->hook_data,call_data2); - sum_ret = sum_ret | ret; - j++; - } - } - /* Finish the last list with hooks left */ - for(;i < h1->len; i++) { - c1 = &g_array_index(h1, LttvHookClosure, i); - ret = c1->hook(c1->hook_data,call_data1); - sum_ret = sum_ret | ret; - } - for(;j < h2->len; j++) { - c2 = &g_array_index(h2, LttvHookClosure, j); - ret = c2->hook(c2->hook_data,call_data2); - sum_ret = sum_ret | ret; - } - } else { /* h1 != NULL && h2 == NULL */ - for(i = 0 ; i < h1->len ; i++) { - c1 = &g_array_index(h1, LttvHookClosure, i); - ret = c1->hook(c1->hook_data,call_data1); - sum_ret = sum_ret | ret; - } - } - } else if(likely(h2 != NULL)) { /* h1 == NULL && h2 != NULL */ - for(j = 0 ; j < h2->len ; j++) { - c2 = &g_array_index(h2, LttvHookClosure, j); - ret = c2->hook(c2->hook_data,call_data2); - sum_ret = sum_ret | ret; - } - } - - return sum_ret; + gint ret, sum_ret = 0; + + LttvHookClosure *c1, *c2; + + guint i, j; + + if(unlikely(h1 != NULL)) { + if(unlikely(h2 != NULL)) { + for(i = 0, j = 0 ; i < h1->len && j < h2->len ;) { + c1 = &g_array_index(h1, LttvHookClosure, i); + c2 = &g_array_index(h2, LttvHookClosure, j); + if(c1->prio <= c2->prio) { + ret = c1->hook(c1->hook_data,call_data1); + sum_ret = sum_ret | ret; + i++; + } else { + ret = c2->hook(c2->hook_data,call_data2); + sum_ret = sum_ret | ret; + j++; + } + } + /* Finish the last list with hooks left */ + for(;i < h1->len; i++) { + c1 = &g_array_index(h1, LttvHookClosure, i); + ret = c1->hook(c1->hook_data,call_data1); + sum_ret = sum_ret | ret; + } + for(;j < h2->len; j++) { + c2 = &g_array_index(h2, LttvHookClosure, j); + ret = c2->hook(c2->hook_data,call_data2); + sum_ret = sum_ret | ret; + } + } else { /* h1 != NULL && h2 == NULL */ + for(i = 0 ; i < h1->len ; i++) { + c1 = &g_array_index(h1, LttvHookClosure, i); + ret = c1->hook(c1->hook_data,call_data1); + sum_ret = sum_ret | ret; + } + } + } else if(likely(h2 != NULL)) { /* h1 == NULL && h2 != NULL */ + for(j = 0 ; j < h2->len ; j++) { + c2 = &g_array_index(h2, LttvHookClosure, j); + ret = c2->hook(c2->hook_data,call_data2); + sum_ret = sum_ret | ret; + } + } + + return sum_ret; } gboolean lttv_hooks_call_check_merge(LttvHooks *h1, void *call_data1, - LttvHooks *h2, void *call_data2) + LttvHooks *h2, void *call_data2) { - LttvHookClosure *c1, *c2; - - guint i, j; - - if(unlikely(h1 != NULL)) { - if(unlikely(h2 != NULL)) { - for(i = 0, j = 0 ; i < h1->len && j < h2->len ;) { - c1 = &g_array_index(h1, LttvHookClosure, i); - c2 = &g_array_index(h2, LttvHookClosure, j); - if(c1->prio <= c2->prio) { - if(c1->hook(c1->hook_data,call_data1)) return TRUE; - i++; - } - else { - if(c2->hook(c2->hook_data,call_data2)) return TRUE; - j++; - } - } - /* Finish the last list with hooks left */ - for(;i < h1->len; i++) { - c1 = &g_array_index(h1, LttvHookClosure, i); - if(c1->hook(c1->hook_data,call_data1)) return TRUE; - } - for(;j < h2->len; j++) { - c2 = &g_array_index(h2, LttvHookClosure, j); - if(c2->hook(c2->hook_data,call_data2)) return TRUE; - } - } else { /* h2 == NULL && h1 != NULL */ - for(i = 0 ; i < h1->len ; i++) { - c1 = &g_array_index(h1, LttvHookClosure, i); - if(c1->hook(c1->hook_data,call_data1)) return TRUE; - } - } - } else if(likely(h2 != NULL)) { /* h1 == NULL && h2 != NULL */ - for(j = 0 ; j < h2->len ; j++) { - c2 = &g_array_index(h2, LttvHookClosure, j); - if(c2->hook(c2->hook_data,call_data2)) return TRUE; - } - } - - return FALSE; + LttvHookClosure *c1, *c2; + + guint i, j; + + if(unlikely(h1 != NULL)) { + if(unlikely(h2 != NULL)) { + for(i = 0, j = 0 ; i < h1->len && j < h2->len ;) { + c1 = &g_array_index(h1, LttvHookClosure, i); + c2 = &g_array_index(h2, LttvHookClosure, j); + if(c1->prio <= c2->prio) { + if(c1->hook(c1->hook_data,call_data1)) return TRUE; + i++; + } else { + if(c2->hook(c2->hook_data,call_data2)) return TRUE; + j++; + } + } + /* Finish the last list with hooks left */ + for(;i < h1->len; i++) { + c1 = &g_array_index(h1, LttvHookClosure, i); + if(c1->hook(c1->hook_data,call_data1)) return TRUE; + } + for(;j < h2->len; j++) { + c2 = &g_array_index(h2, LttvHookClosure, j); + if(c2->hook(c2->hook_data,call_data2)) return TRUE; + } + } else { /* h2 == NULL && h1 != NULL */ + for(i = 0 ; i < h1->len ; i++) { + c1 = &g_array_index(h1, LttvHookClosure, i); + if(c1->hook(c1->hook_data,call_data1)) return TRUE; + } + } + } else if(likely(h2 != NULL)) { /* h1 == NULL && h2 != NULL */ + for(j = 0 ; j < h2->len ; j++) { + c2 = &g_array_index(h2, LttvHookClosure, j); + if(c2->hook(c2->hook_data,call_data2)) return TRUE; + } + } + + return FALSE; } @@ -408,117 +406,117 @@ gboolean lttv_hooks_call_check_merge(LttvHooks *h1, void *call_data1, LttvHooksById *lttv_hooks_by_id_new() { - LttvHooksById *h = g_new(LttvHooksById, 1); - h->index = g_ptr_array_sized_new(PREALLOC_EVENTS); - h->array = g_array_sized_new(FALSE, FALSE, sizeof(guint), PREALLOC_EVENTS); - return h; + LttvHooksById *h = g_new(LttvHooksById, 1); + h->index = g_ptr_array_sized_new(PREALLOC_EVENTS); + h->array = g_array_sized_new(FALSE, FALSE, sizeof(guint), PREALLOC_EVENTS); + return h; } void lttv_hooks_by_id_destroy(LttvHooksById *h) { - guint i; - - for(i = 0 ; i < h->array->len ; i++) { - guint index = g_array_index(h->array, guint, i); - if(h->index->pdata[index] != NULL) { /* hook may have been removed */ - lttv_hooks_destroy(h->index->pdata[index]); - h->index->pdata[index] = NULL; /* Must be there in case of - multiple addition of the same index */ - } - } - g_ptr_array_free(h->index, TRUE); - g_array_free(h->array, TRUE); + guint i; + + for(i = 0 ; i < h->array->len ; i++) { + guint index = g_array_index(h->array, guint, i); + if(h->index->pdata[index] != NULL) { /* hook may have been removed */ + lttv_hooks_destroy(h->index->pdata[index]); + h->index->pdata[index] = NULL; /* Must be there in case of + multiple addition of the same index */ + } + } + g_ptr_array_free(h->index, TRUE); + g_array_free(h->array, TRUE); } /* Optimised for searching an existing hook */ LttvHooks *lttv_hooks_by_id_find(LttvHooksById *h, unsigned id) { - if(unlikely(h->index->len <= id)) g_ptr_array_set_size(h->index, id + 1); - if(unlikely(h->index->pdata[id] == NULL)) { - h->index->pdata[id] = lttv_hooks_new(); - g_array_append_val(h->array, id); - } - return h->index->pdata[id]; + if(unlikely(h->index->len <= id)) g_ptr_array_set_size(h->index, id + 1); + if(unlikely(h->index->pdata[id] == NULL)) { + h->index->pdata[id] = lttv_hooks_new(); + g_array_append_val(h->array, id); + } + return h->index->pdata[id]; } unsigned lttv_hooks_by_id_max_id(LttvHooksById *h) { - return h->index->len; + return h->index->len; } /* We don't bother removing the used slot array id : lttv_hooks_by_id_destroy is * almost never called and is able to deal with used slot repetition. */ void lttv_hooks_by_id_remove(LttvHooksById *h, unsigned id) { - if(likely(id < h->index->len && h->index->pdata[id] != NULL)) { - lttv_hooks_destroy((LttvHooks *)h->index->pdata[id]); - h->index->pdata[id] = NULL; - } + if(likely(id < h->index->len && h->index->pdata[id] != NULL)) { + lttv_hooks_destroy((LttvHooks *)h->index->pdata[id]); + h->index->pdata[id] = NULL; + } } void lttv_hooks_by_id_copy(LttvHooksById *dest, LttvHooksById *src) { - guint i; - - for(i = 0 ; i < src->array->len ; i++) { - guint index = g_array_index(src->array, guint, i); - LttvHooks *srch = lttv_hooks_by_id_find(src, index); - LttvHooks *desth = lttv_hooks_by_id_find(dest, index); - lttv_hooks_add_list(desth, srch); - } + guint i; + + for(i = 0 ; i < src->array->len ; i++) { + guint index = g_array_index(src->array, guint, i); + LttvHooks *srch = lttv_hooks_by_id_find(src, index); + LttvHooks *desth = lttv_hooks_by_id_find(dest, index); + lttv_hooks_add_list(desth, srch); + } } LttvHooksByIdChannelArray *lttv_hooks_by_id_channel_new(void) { - LttvHooksByIdChannelArray *h = g_new(LttvHooksByIdChannelArray, 1); + LttvHooksByIdChannelArray *h = g_new(LttvHooksByIdChannelArray, 1); - h->array = g_array_new(FALSE, FALSE, sizeof(LttvHooksByIdChannel)); - return h; + h->array = g_array_new(FALSE, FALSE, sizeof(LttvHooksByIdChannel)); + return h; } void lttv_hooks_by_id_channel_destroy(LttvHooksByIdChannelArray *h) { - LttvHooksByIdChannel *hid; - int i; - - for (i = 0; i < h->array->len; i++) { - hid = &g_array_index(h->array, LttvHooksByIdChannel, i); - lttv_hooks_by_id_destroy(hid->hooks_by_id); - } - g_array_free(h->array, TRUE); - g_free(h); + LttvHooksByIdChannel *hid; + int i; + + for (i = 0; i < h->array->len; i++) { + hid = &g_array_index(h->array, LttvHooksByIdChannel, i); + lttv_hooks_by_id_destroy(hid->hooks_by_id); + } + g_array_free(h->array, TRUE); + g_free(h); } -static LttvHooksByIdChannel *lttv_hooks_by_id_channel_find_channel( - LttvHooksByIdChannelArray *h, - GQuark channel) +static LttvHooksByIdChannel * +lttv_hooks_by_id_channel_find_channel(LttvHooksByIdChannelArray *h, + GQuark channel) { - LttvHooksByIdChannel *hid; - int i, found = 0; - - for (i = 0; i < h->array->len; i++) { - hid = &g_array_index(h->array, LttvHooksByIdChannel, i); - if (hid->channel == channel) { - found = 1; - break; - } - } - if (!found) { - g_array_set_size(h->array, h->array->len + 1); - hid = &g_array_index(h->array, LttvHooksByIdChannel, h->array->len - 1); - hid->channel = channel; - hid->hooks_by_id = lttv_hooks_by_id_new(); - } - return hid; + LttvHooksByIdChannel *hid; + int i, found = 0; + + for (i = 0; i < h->array->len; i++) { + hid = &g_array_index(h->array, LttvHooksByIdChannel, i); + if (hid->channel == channel) { + found = 1; + break; + } + } + if (!found) { + g_array_set_size(h->array, h->array->len + 1); + hid = &g_array_index(h->array, LttvHooksByIdChannel, h->array->len - 1); + hid->channel = channel; + hid->hooks_by_id = lttv_hooks_by_id_new(); + } + return hid; } /* get, or create if not found */ LttvHooks *lttv_hooks_by_id_channel_find(LttvHooksByIdChannelArray *h, - GQuark channel, guint16 id) + GQuark channel, guint16 id) { - LttvHooksByIdChannel *hid; - hid = lttv_hooks_by_id_channel_find_channel(h, channel); - return lttv_hooks_by_id_find(hid->hooks_by_id, id); + LttvHooksByIdChannel *hid; + hid = lttv_hooks_by_id_channel_find_channel(h, channel); + return lttv_hooks_by_id_find(hid->hooks_by_id, id); } diff --git a/lttv/lttv/hook.h b/lttv/lttv/hook.h index 91f0c13f..c5a71b75 100644 --- a/lttv/lttv/hook.h +++ b/lttv/lttv/hook.h @@ -89,7 +89,7 @@ unsigned lttv_hooks_number(LttvHooks *h); * *f and *hook_data are NULL if no hook exists at that position. */ void lttv_hooks_get(LttvHooks *h, unsigned i, LttvHook *f, void **hook_data, - LttvHookPrio *p); + LttvHookPrio *p); /* Remove the specified hook. The position of the following hooks may change */ @@ -115,17 +115,17 @@ gboolean lttv_hooks_call_check(LttvHooks *h, void *call_data); * hooks from h1 are called first. */ gboolean lttv_hooks_call_merge(LttvHooks *h1, void *call_data1, - LttvHooks *h2, void *call_data2); + LttvHooks *h2, void *call_data2); gboolean lttv_hooks_call_check_merge(LttvHooks *h1, void *call_data1, - LttvHooks *h2, void *call_data2); + LttvHooks *h2, void *call_data2); /* Sometimes different hooks need to be called based on the case. The case is represented by an unsigned integer id */ typedef struct _LttvHooksById { - GPtrArray *index; - GArray *array; + GPtrArray *index; + GArray *array; } LttvHooksById; /* Create and destroy a hooks by id list */ @@ -149,11 +149,11 @@ unsigned lttv_hooks_by_id_max_id(LttvHooksById *h); static inline LttvHooks *lttv_hooks_by_id_get(LttvHooksById *h, unsigned id) { - LttvHooks *ret; - if(likely(id < h->index->len)) ret = h->index->pdata[id]; - else ret = NULL; + LttvHooks *ret; + if(likely(id < h->index->len)) ret = h->index->pdata[id]; + else ret = NULL; - return ret; + return ret; } /* Remove the list of hooks associated with an id */ @@ -169,12 +169,12 @@ void lttv_hooks_by_id_copy(LttvHooksById *dest, LttvHooksById *src); /* Internal structure, contained in by the LttvHooksByIdChannelArray */ typedef struct _LttvHooksByIdChannel { - LttvHooksById *hooks_by_id; - GQuark channel; + LttvHooksById *hooks_by_id; + GQuark channel; } LttvHooksByIdChannel; typedef struct _LttvHooksByIdChannelArray { - GArray *array; /* Array of LttvHooksByIdChannel */ + GArray *array; /* Array of LttvHooksByIdChannel */ } LttvHooksByIdChannelArray; LttvHooksByIdChannelArray *lttv_hooks_by_id_channel_new(void); @@ -182,6 +182,6 @@ LttvHooksByIdChannelArray *lttv_hooks_by_id_channel_new(void); void lttv_hooks_by_id_channel_destroy(LttvHooksByIdChannelArray *h); LttvHooks *lttv_hooks_by_id_channel_find(LttvHooksByIdChannelArray *h, - GQuark channel, guint16 id); + GQuark channel, guint16 id); #endif // HOOK_H diff --git a/lttv/lttv/iattribute.c b/lttv/lttv/iattribute.c index fe50fb63..0ee1b092 100644 --- a/lttv/lttv/iattribute.c +++ b/lttv/lttv/iattribute.c @@ -22,100 +22,98 @@ #include -static void -lttv_iattribute_base_init (gpointer klass) +static void lttv_iattribute_base_init (gpointer klass) { - static gboolean initialized = FALSE; + static gboolean initialized = FALSE; - if (!initialized) { - initialized = TRUE; - } + if (!initialized) { + initialized = TRUE; + } } -GType -lttv_iattribute_get_type (void) +GType lttv_iattribute_get_type (void) { - static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof (LttvIAttributeClass), - lttv_iattribute_base_init, /* base_init */ - NULL, /* base_finalize */ - NULL, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - 0, - 0, /* n_preallocs */ - NULL /* instance_init */ - }; - type = g_type_register_static (G_TYPE_INTERFACE, "LttvIAttribute", - &info, 0); - } - return type; + static GType type = 0; + if (type == 0) { + static const GTypeInfo info = { + sizeof (LttvIAttributeClass), + lttv_iattribute_base_init, /* base_init */ + NULL, /* base_finalize */ + NULL, /* class_init */ + NULL, /* class_finalize */ + NULL, /* class_data */ + 0, + 0, /* n_preallocs */ + NULL /* instance_init */ + }; + type = g_type_register_static (G_TYPE_INTERFACE, "LttvIAttribute", + &info, 0); + } + return type; } unsigned int lttv_iattribute_get_number(LttvIAttribute *self) { - return LTTV_IATTRIBUTE_GET_CLASS (self)->get_number (self); + return LTTV_IATTRIBUTE_GET_CLASS (self)->get_number (self); } gboolean lttv_iattribute_named(LttvIAttribute *self, gboolean *homogeneous) { - return LTTV_IATTRIBUTE_GET_CLASS (self)->named (self, homogeneous); + return LTTV_IATTRIBUTE_GET_CLASS (self)->named (self, homogeneous); } LttvAttributeType lttv_iattribute_get(LttvIAttribute *self, unsigned i, - LttvAttributeName *name, LttvAttributeValue *v, gboolean *is_named) + LttvAttributeName *name, LttvAttributeValue *v, gboolean *is_named) { - return LTTV_IATTRIBUTE_GET_CLASS (self)->get (self, i, name, v, is_named); + return LTTV_IATTRIBUTE_GET_CLASS (self)->get (self, i, name, v, is_named); } LttvAttributeType lttv_iattribute_get_by_name(LttvIAttribute *self, - LttvAttributeName name, LttvAttributeValue *v) + LttvAttributeName name, LttvAttributeValue *v) { - return LTTV_IATTRIBUTE_GET_CLASS (self)->get_by_name (self, name, v); + return LTTV_IATTRIBUTE_GET_CLASS (self)->get_by_name (self, name, v); } LttvAttributeValue lttv_iattribute_add(LttvIAttribute *self, - LttvAttributeName name, LttvAttributeType t) + LttvAttributeName name, LttvAttributeType t) { - return LTTV_IATTRIBUTE_GET_CLASS (self)->add (self, name, t); + return LTTV_IATTRIBUTE_GET_CLASS (self)->add (self, name, t); } LttvAttributeValue lttv_iattribute_add_unnamed(LttvIAttribute *self, - LttvAttributeName name, LttvAttributeType t) + LttvAttributeName name, LttvAttributeType t) { - return LTTV_IATTRIBUTE_GET_CLASS (self)->add_unnamed (self, name, t); + return LTTV_IATTRIBUTE_GET_CLASS (self)->add_unnamed (self, name, t); } void lttv_iattribute_remove(LttvIAttribute *self, unsigned i) { - return LTTV_IATTRIBUTE_GET_CLASS (self)->remove (self, i); + return LTTV_IATTRIBUTE_GET_CLASS (self)->remove (self, i); } void lttv_iattribute_remove_by_name(LttvIAttribute *self, - LttvAttributeName name) + LttvAttributeName name) { - return LTTV_IATTRIBUTE_GET_CLASS (self)->remove_by_name (self, name); + return LTTV_IATTRIBUTE_GET_CLASS (self)->remove_by_name (self, name); } LttvIAttribute* lttv_iattribute_find_subdir(LttvIAttribute *self, - LttvAttributeName name) + LttvAttributeName name) { - return LTTV_IATTRIBUTE_GET_CLASS (self)->find_subdir (self, name); + return LTTV_IATTRIBUTE_GET_CLASS (self)->find_subdir (self, name); } LttvIAttribute* lttv_iattribute_find_subdir_unnamed(LttvIAttribute *self, - LttvAttributeName name) + LttvAttributeName name) { - return LTTV_IATTRIBUTE_GET_CLASS (self)->find_subdir_unnamed (self, name); + return LTTV_IATTRIBUTE_GET_CLASS (self)->find_subdir_unnamed (self, name); } @@ -127,19 +125,19 @@ LttvIAttribute* lttv_iattribute_find_subdir_unnamed(LttvIAttribute *self, exists but is of incorrect type. */ gboolean lttv_iattribute_find(LttvIAttribute *self, LttvAttributeName name, - LttvAttributeType t, LttvAttributeValue *v) + LttvAttributeType t, LttvAttributeValue *v) { - LttvAttributeType found_type; + LttvAttributeType found_type; - found_type = lttv_iattribute_get_by_name(self, name, v); - if(found_type == t) return TRUE; + found_type = lttv_iattribute_get_by_name(self, name, v); + if(found_type == t) return TRUE; - if(found_type == LTTV_NONE) { - *v = lttv_iattribute_add(self, name, t); - return TRUE; - } + if(found_type == LTTV_NONE) { + *v = lttv_iattribute_add(self, name, t); + return TRUE; + } - return FALSE; + return FALSE; } @@ -147,46 +145,44 @@ gboolean lttv_iattribute_find(LttvIAttribute *self, LttvAttributeName name, components separated by /, like in filesystems */ gboolean lttv_iattribute_find_by_path(LttvIAttribute *self, const char *path, - LttvAttributeType t, LttvAttributeValue *v) + LttvAttributeType t, LttvAttributeValue *v) { - LttvIAttribute *node = self; - - LttvAttributeType found_type; - - LttvAttributeName name; - - gchar **components, **cursor; - - components = g_strsplit(path, "\"", G_MAXINT); - - if(components == NULL || *components == NULL) { - g_strfreev(components); - return FALSE; - } - - for(cursor = components;;) { - name = g_quark_from_string(*cursor); - cursor++; - - if(*cursor == NULL) { - g_strfreev(components); - return lttv_iattribute_find(node, name, t, v); - } - else { - found_type = lttv_iattribute_get_by_name(node, name, v); - if(found_type == LTTV_NONE) { - node = lttv_iattribute_find_subdir(node, name); - } - else if(found_type == LTTV_GOBJECT && - LTTV_IS_IATTRIBUTE(*(v->v_gobject))) { - node = LTTV_IATTRIBUTE(*(v->v_gobject)); - } - else { - g_strfreev(components); - return FALSE; - } - } - } + LttvIAttribute *node = self; + + LttvAttributeType found_type; + + LttvAttributeName name; + + gchar **components, **cursor; + + components = g_strsplit(path, "\"", G_MAXINT); + + if(components == NULL || *components == NULL) { + g_strfreev(components); + return FALSE; + } + + for(cursor = components;;) { + name = g_quark_from_string(*cursor); + cursor++; + + if(*cursor == NULL) { + g_strfreev(components); + return lttv_iattribute_find(node, name, t, v); + } else { + found_type = lttv_iattribute_get_by_name(node, name, v); + if(found_type == LTTV_NONE) { + node = lttv_iattribute_find_subdir(node, name); + } + else if(found_type == LTTV_GOBJECT && + LTTV_IS_IATTRIBUTE(*(v->v_gobject))) { + node = LTTV_IATTRIBUTE(*(v->v_gobject)); + } else { + g_strfreev(components); + return FALSE; + } + } + } } @@ -194,114 +190,114 @@ gboolean lttv_iattribute_find_by_path(LttvIAttribute *self, const char *path, LttvIAttribute *lttv_iattribute_shallow_copy(LttvIAttribute *self) { - LttvIAttribute *copy; + LttvIAttribute *copy; - LttvAttributeType t; + LttvAttributeType t; - LttvAttributeValue v, v_copy; + LttvAttributeValue v, v_copy; - LttvAttributeName name; + LttvAttributeName name; gboolean is_named; - int i; + int i; - int nb_attributes = lttv_iattribute_get_number(self); + int nb_attributes = lttv_iattribute_get_number(self); - copy = LTTV_IATTRIBUTE_GET_CLASS(self)->new_attribute(NULL); + copy = LTTV_IATTRIBUTE_GET_CLASS(self)->new_attribute(NULL); - for(i = 0 ; i < nb_attributes ; i++) { - t = lttv_iattribute_get(self, i, &name, &v, &is_named); + for(i = 0 ; i < nb_attributes ; i++) { + t = lttv_iattribute_get(self, i, &name, &v, &is_named); if(is_named) - v_copy = lttv_iattribute_add(copy, name, t); + v_copy = lttv_iattribute_add(copy, name, t); else - v_copy = lttv_iattribute_add_unnamed(copy, name, t); - lttv_iattribute_copy_value(t, v_copy, v); - } - return copy; + v_copy = lttv_iattribute_add_unnamed(copy, name, t); + lttv_iattribute_copy_value(t, v_copy, v); + } + return copy; } LttvIAttribute *lttv_iattribute_deep_copy(LttvIAttribute *self) { - LttvIAttribute *copy, *child; + LttvIAttribute *copy, *child; - LttvAttributeType t; + LttvAttributeType t; - LttvAttributeValue v, v_copy; + LttvAttributeValue v, v_copy; - LttvAttributeName name; + LttvAttributeName name; gboolean is_named; - int i; + int i; - int nb_attributes = lttv_iattribute_get_number(self); + int nb_attributes = lttv_iattribute_get_number(self); - copy = LTTV_IATTRIBUTE_GET_CLASS(self)->new_attribute(NULL); + copy = LTTV_IATTRIBUTE_GET_CLASS(self)->new_attribute(NULL); - for(i = 0 ; i < nb_attributes ; i++) { - t = lttv_iattribute_get(self, i, &name, &v, &is_named); + for(i = 0 ; i < nb_attributes ; i++) { + t = lttv_iattribute_get(self, i, &name, &v, &is_named); if(is_named) - v_copy = lttv_iattribute_add(copy, name, t); + v_copy = lttv_iattribute_add(copy, name, t); else - v_copy = lttv_iattribute_add_unnamed(copy, name, t); - if(t == LTTV_GOBJECT && LTTV_IS_IATTRIBUTE(*(v.v_gobject))) { - child = LTTV_IATTRIBUTE(*(v.v_gobject)); - *(v_copy.v_gobject) = G_OBJECT(lttv_iattribute_deep_copy(child)); - } - else lttv_iattribute_copy_value(t, v_copy, v); - } - return copy; + v_copy = lttv_iattribute_add_unnamed(copy, name, t); + if(t == LTTV_GOBJECT && LTTV_IS_IATTRIBUTE(*(v.v_gobject))) { + child = LTTV_IATTRIBUTE(*(v.v_gobject)); + *(v_copy.v_gobject) = G_OBJECT(lttv_iattribute_deep_copy(child)); + } + else lttv_iattribute_copy_value(t, v_copy, v); + } + return copy; } void lttv_iattribute_copy_value(LttvAttributeType t, LttvAttributeValue dest, - LttvAttributeValue src) + LttvAttributeValue src) { - switch(t) { - case LTTV_INT: - *(dest.v_int) = *(src.v_int); - break; - - case LTTV_UINT: - *(dest.v_uint) = *(src.v_uint); - break; - - case LTTV_LONG: - *(dest.v_long) = *(src.v_long); - break; - - case LTTV_ULONG: - *(dest.v_ulong) = *(src.v_ulong); - break; - - case LTTV_FLOAT: - *(dest.v_float) = *(src.v_float); - break; - - case LTTV_DOUBLE: - *(dest.v_double) = *(src.v_double); - break; - - case LTTV_TIME: - *(dest.v_time) = *(src.v_time); - break; - - case LTTV_POINTER: - *(dest.v_pointer) = *(src.v_pointer); - break; - - case LTTV_STRING: - *(dest.v_string) = *(src.v_string); - break; - - case LTTV_GOBJECT: - *(dest.v_gobject) = *(src.v_gobject); - if(*(dest.v_gobject) != NULL) g_object_ref(*(dest.v_gobject)); - break; - - case LTTV_NONE: - break; - } + switch(t) { + case LTTV_INT: + *(dest.v_int) = *(src.v_int); + break; + + case LTTV_UINT: + *(dest.v_uint) = *(src.v_uint); + break; + + case LTTV_LONG: + *(dest.v_long) = *(src.v_long); + break; + + case LTTV_ULONG: + *(dest.v_ulong) = *(src.v_ulong); + break; + + case LTTV_FLOAT: + *(dest.v_float) = *(src.v_float); + break; + + case LTTV_DOUBLE: + *(dest.v_double) = *(src.v_double); + break; + + case LTTV_TIME: + *(dest.v_time) = *(src.v_time); + break; + + case LTTV_POINTER: + *(dest.v_pointer) = *(src.v_pointer); + break; + + case LTTV_STRING: + *(dest.v_string) = *(src.v_string); + break; + + case LTTV_GOBJECT: + *(dest.v_gobject) = *(src.v_gobject); + if(*(dest.v_gobject) != NULL) g_object_ref(*(dest.v_gobject)); + break; + + case LTTV_NONE: + break; + } } diff --git a/lttv/lttv/iattribute.h b/lttv/lttv/iattribute.h index 29227090..d56f320b 100644 --- a/lttv/lttv/iattribute.h +++ b/lttv/lttv/iattribute.h @@ -26,9 +26,9 @@ #include /* The content of a data structure may be seen as an array of pairs of - attribute name and value. This simple model allows generic navigation - and access functions over a wide range of structures. The names are - represented by unique integer identifiers, GQuarks. */ + * attribute name and value. This simple model allows generic navigation + * and access functions over a wide range of structures. The names are + * represented by unique integer identifiers, GQuarks. */ /* Please note that adding a value of type gobject that is non null does not * increment the reference count of this object : the actual reference to @@ -40,21 +40,21 @@ typedef GQuark LttvAttributeName; typedef enum _LttvAttributeType { - LTTV_INT, LTTV_UINT, LTTV_LONG, LTTV_ULONG, LTTV_FLOAT, LTTV_DOUBLE, - LTTV_TIME, LTTV_POINTER, LTTV_STRING, LTTV_GOBJECT, LTTV_NONE + LTTV_INT, LTTV_UINT, LTTV_LONG, LTTV_ULONG, LTTV_FLOAT, LTTV_DOUBLE, + LTTV_TIME, LTTV_POINTER, LTTV_STRING, LTTV_GOBJECT, LTTV_NONE } LttvAttributeType; typedef union LttvAttributeValue { - int *v_int; - unsigned *v_uint; - long *v_long; - unsigned long *v_ulong; - float *v_float; - double *v_double; - LttTime *v_time; - gpointer *v_pointer; - char **v_string; - GObject **v_gobject; + int *v_int; + unsigned *v_uint; + long *v_long; + unsigned long *v_ulong; + float *v_float; + double *v_double; + LttTime *v_time; + gpointer *v_pointer; + char **v_string; + GObject **v_gobject; } LttvAttributeValue; @@ -73,37 +73,37 @@ typedef struct _LttvIAttributeClass LttvIAttributeClass; struct _LttvIAttributeClass { - GTypeInterface parent; + GTypeInterface parent; - LttvIAttribute* (*new_attribute) (LttvIAttribute *self); + LttvIAttribute* (*new_attribute) (LttvIAttribute *self); - unsigned int (*get_number) (LttvIAttribute *self); + unsigned int (*get_number) (LttvIAttribute *self); - gboolean (*named) (LttvIAttribute *self, gboolean *homogeneous); + gboolean (*named) (LttvIAttribute *self, gboolean *homogeneous); - LttvAttributeType (*get) (LttvIAttribute *self, unsigned i, - LttvAttributeName *name, LttvAttributeValue *v, gboolean *is_named); + LttvAttributeType (*get) (LttvIAttribute *self, unsigned i, + LttvAttributeName *name, LttvAttributeValue *v, gboolean *is_named); - LttvAttributeType (*get_by_name) (LttvIAttribute *self, - LttvAttributeName name, LttvAttributeValue *v); + LttvAttributeType (*get_by_name) (LttvIAttribute *self, + LttvAttributeName name, LttvAttributeValue *v); - LttvAttributeValue (*add) (LttvIAttribute *self, LttvAttributeName name, - LttvAttributeType t); + LttvAttributeValue (*add) (LttvIAttribute *self, LttvAttributeName name, + LttvAttributeType t); - LttvAttributeValue (*add_unnamed) (LttvIAttribute *self, + LttvAttributeValue (*add_unnamed) (LttvIAttribute *self, LttvAttributeName name, - LttvAttributeType t); + LttvAttributeType t); - void (*remove) (LttvIAttribute *self, unsigned i); + void (*remove) (LttvIAttribute *self, unsigned i); - void (*remove_by_name) (LttvIAttribute *self, - LttvAttributeName name); + void (*remove_by_name) (LttvIAttribute *self, + LttvAttributeName name); - LttvIAttribute* (*find_subdir) (LttvIAttribute *self, - LttvAttributeName name); + LttvIAttribute* (*find_subdir) (LttvIAttribute *self, + LttvAttributeName name); - LttvIAttribute* (*find_subdir_unnamed) (LttvIAttribute *self, - LttvAttributeName name); + LttvIAttribute* (*find_subdir_unnamed) (LttvIAttribute *self, + LttvAttributeName name); }; @@ -125,14 +125,14 @@ gboolean lttv_iattribute_named(LttvIAttribute *self, gboolean *homogeneous); /* Get the i th attribute along with its type and a pointer to its value. */ LttvAttributeType lttv_iattribute_get(LttvIAttribute *self, unsigned i, - LttvAttributeName *name, LttvAttributeValue *v, gboolean *is_named); + LttvAttributeName *name, LttvAttributeValue *v, gboolean *is_named); /* Get the named attribute in the table along with its type and a pointer to its value. If the named attribute does not exist, the type is LTTV_NONE. */ LttvAttributeType lttv_iattribute_get_by_name(LttvIAttribute *self, - LttvAttributeName name, LttvAttributeValue *v); + LttvAttributeName name, LttvAttributeValue *v); /* Add an attribute, which must not exist. The name is an empty string for @@ -140,16 +140,16 @@ LttvAttributeType lttv_iattribute_get_by_name(LttvIAttribute *self, and its pointer returned. */ LttvAttributeValue lttv_iattribute_add(LttvIAttribute *self, - LttvAttributeName name, LttvAttributeType t); + LttvAttributeName name, LttvAttributeType t); LttvAttributeValue lttv_iattribute_add_unnamed(LttvIAttribute *self, - LttvAttributeName name, LttvAttributeType t); + LttvAttributeName name, LttvAttributeType t); /* Remove an attribute */ void lttv_iattribute_remove(LttvIAttribute *self, unsigned i); void lttv_iattribute_remove_by_name(LttvIAttribute *self, - LttvAttributeName name); + LttvAttributeName name); /* Create an empty iattribute object and add it as an attribute under the @@ -158,10 +158,10 @@ void lttv_iattribute_remove_by_name(LttvIAttribute *self, iattribute interface, return NULL. */ LttvIAttribute* lttv_iattribute_find_subdir(LttvIAttribute *self, - LttvAttributeName name); + LttvAttributeName name); LttvIAttribute* lttv_iattribute_find_subdir_unnamed(LttvIAttribute *self, - LttvAttributeName name); + LttvAttributeName name); /* The remaining utility functions are not part of the LttvIAttribute interface but operate on objects implementing it. */ @@ -173,20 +173,20 @@ LttvIAttribute* lttv_iattribute_find_subdir_unnamed(LttvIAttribute *self, exists but is of incorrect type. */ gboolean lttv_iattribute_find(LttvIAttribute *self, LttvAttributeName name, - LttvAttributeType t, LttvAttributeValue *v); + LttvAttributeType t, LttvAttributeValue *v); /* Trees of attribute tables may be accessed using a hierarchical path with components separated by /, like in filesystems */ gboolean lttv_iattribute_find_by_path(LttvIAttribute *self, const char *path, - LttvAttributeType t, LttvAttributeValue *v); + LttvAttributeType t, LttvAttributeValue *v); /* Shallow and deep copies */ void lttv_iattribute_copy_value(LttvAttributeType t, LttvAttributeValue dest, - LttvAttributeValue src); + LttvAttributeValue src); LttvIAttribute *lttv_iattribute_shallow_copy(LttvIAttribute *self); diff --git a/lttv/lttv/main.c b/lttv/lttv/main.c index e894ac18..d3b69fb6 100644 --- a/lttv/lttv/main.c +++ b/lttv/lttv/main.c @@ -39,19 +39,19 @@ static LttvIAttribute *attributes; static LttvHooks - *before_options, - *after_options, - *before_main, - *after_main; + *before_options, + *after_options, + *before_main, + *after_main; static char - *a_module, - *a_module_path; + *a_module, + *a_module_path; static gboolean - a_verbose, - a_debug, - a_fatal; + a_verbose, + a_debug, + a_fatal; gboolean lttv_profile_memory; @@ -77,7 +77,7 @@ static void lttv_help(void *hook_data); messages. It receives the message and does nothing. */ void ignore_and_drop_message(const gchar *log_domain, GLogLevelFlags log_level, - const gchar *message, gpointer user_data) + const gchar *message, gpointer user_data) { } @@ -88,220 +88,219 @@ void ignore_and_drop_message(const gchar *log_domain, GLogLevelFlags log_level, int main(int argc, char **argv) { - int i; + int i; - char - *profile_memory_short_option = "-M", - *profile_memory_long_option = "--memory"; + char + *profile_memory_short_option = "-M", + *profile_memory_long_option = "--memory"; - gboolean profile_memory = FALSE; - gboolean retval; + gboolean profile_memory = FALSE; + gboolean retval; - LttvAttributeValue value; + LttvAttributeValue value; - lttv_argc = argc; - lttv_argv = argv; + lttv_argc = argc; + lttv_argv = argv; - /* Before anything else, check if memory profiling is requested */ + /* Before anything else, check if memory profiling is requested */ - for(i = 1 ; i < argc ; i++) { - if(*(argv[i]) != '-') break; - if(strcmp(argv[i], profile_memory_short_option) == 0 || - strcmp(argv[i], profile_memory_long_option) == 0) { - g_mem_set_vtable(glib_mem_profiler_table); - g_message("Memory summary before main"); - g_mem_profile(); - profile_memory = TRUE; - break; - } - } + for(i = 1 ; i < argc ; i++) { + if(*(argv[i]) != '-') break; + if(strcmp(argv[i], profile_memory_short_option) == 0 || + strcmp(argv[i], profile_memory_long_option) == 0) { + g_mem_set_vtable(glib_mem_profiler_table); + g_message("Memory summary before main"); + g_mem_profile(); + profile_memory = TRUE; + break; + } + } - /* Initialize glib and by default ignore info and debug messages */ + /* Initialize glib and by default ignore info and debug messages */ - g_type_init(); - //g_type_init_with_debug_flags (G_TYPE_DEBUG_OBJECTS | G_TYPE_DEBUG_SIGNALS); - g_log_set_handler(NULL, G_LOG_LEVEL_INFO, ignore_and_drop_message, NULL); - g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, ignore_and_drop_message, NULL); + g_type_init(); + //g_type_init_with_debug_flags (G_TYPE_DEBUG_OBJECTS | G_TYPE_DEBUG_SIGNALS); + g_log_set_handler(NULL, G_LOG_LEVEL_INFO, ignore_and_drop_message, NULL); + g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, ignore_and_drop_message, NULL); - /* Have an attributes subtree to store hooks to be registered by modules. */ + /* Have an attributes subtree to store hooks to be registered by modules. */ - attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL)); + attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL)); - before_options = lttv_hooks_new(); - after_options = lttv_hooks_new(); - before_main = lttv_hooks_new(); - after_main = lttv_hooks_new(); + before_options = lttv_hooks_new(); + after_options = lttv_hooks_new(); + before_main = lttv_hooks_new(); + after_main = lttv_hooks_new(); - /* Create a number of hooks lists */ + /* Create a number of hooks lists */ - retval= lttv_iattribute_find_by_path(attributes, "hooks/options/before", - LTTV_POINTER, &value); - g_assert(retval); - *(value.v_pointer) = before_options; - retval= lttv_iattribute_find_by_path(attributes, "hooks/options/after", - LTTV_POINTER, &value); - g_assert(retval); - *(value.v_pointer) = after_options; - retval= lttv_iattribute_find_by_path(attributes, "hooks/main/before", - LTTV_POINTER, &value); - g_assert(retval); - *(value.v_pointer) = before_main; - retval= lttv_iattribute_find_by_path(attributes, "hooks/main/after", - LTTV_POINTER, &value); - g_assert(retval); - *(value.v_pointer) = after_main; + retval= lttv_iattribute_find_by_path(attributes, "hooks/options/before", + LTTV_POINTER, &value); + g_assert(retval); + *(value.v_pointer) = before_options; + retval= lttv_iattribute_find_by_path(attributes, "hooks/options/after", + LTTV_POINTER, &value); + g_assert(retval); + *(value.v_pointer) = after_options; + retval= lttv_iattribute_find_by_path(attributes, "hooks/main/before", + LTTV_POINTER, &value); + g_assert(retval); + *(value.v_pointer) = before_main; + retval= lttv_iattribute_find_by_path(attributes, "hooks/main/after", + LTTV_POINTER, &value); + g_assert(retval); + *(value.v_pointer) = after_main; - /* Initialize the command line options processing */ + /* Initialize the command line options processing */ - GError *error = NULL; + GError *error = NULL; - LttvModule *module_module = lttv_module_require("module", &error); - if(error != NULL) g_error("%s", error->message); - LttvModule *module_option = lttv_module_require("option", &error); - if(error != NULL) g_error("%s", error->message); + LttvModule *module_module = lttv_module_require("module", &error); + if(error != NULL) g_error("%s", error->message); + LttvModule *module_option = lttv_module_require("option", &error); + if(error != NULL) g_error("%s", error->message); - /* Initialize the module loading */ + /* Initialize the module loading */ - lttv_library_path_add(PACKAGE_PLUGIN_DIR); + lttv_library_path_add(PACKAGE_PLUGIN_DIR); - /* Add some built-in options */ + /* Add some built-in options */ - lttv_option_add("module",'m', "load a module", "name of module to load", - LTTV_OPT_STRING, &a_module, lttv_module_option, NULL); + lttv_option_add("module",'m', "load a module", "name of module to load", + LTTV_OPT_STRING, &a_module, lttv_module_option, NULL); - lttv_option_add("modules-path", 'L', - "add a directory to the module search path", - "directory to add to the path", LTTV_OPT_STRING, &a_module_path, - lttv_module_path_option, NULL); + lttv_option_add("modules-path", 'L', + "add a directory to the module search path", + "directory to add to the path", LTTV_OPT_STRING, &a_module_path, + lttv_module_path_option, NULL); - lttv_option_add("help",'h', "basic help", "none", - LTTV_OPT_NONE, NULL, lttv_help, NULL); + lttv_option_add("help",'h', "basic help", "none", + LTTV_OPT_NONE, NULL, lttv_help, NULL); - a_verbose = FALSE; - lttv_option_add("verbose",'v', "print information messages", "none", - LTTV_OPT_NONE, NULL, lttv_verbose, NULL); + a_verbose = FALSE; + lttv_option_add("verbose",'v', "print information messages", "none", + LTTV_OPT_NONE, NULL, lttv_verbose, NULL); - a_debug = FALSE; - lttv_option_add("debug",'d', "print debugging messages", "none", - LTTV_OPT_NONE, NULL, lttv_debug, NULL); - - /* use --edebug, -e conflicts with filter. Problem with option parsing when we - * reparse the options with different number of arguments. */ - lttv_option_add("edebug",'e', "print event debugging", "none", - LTTV_OPT_NONE, NULL, lttv_event_debug, NULL); - - a_fatal = FALSE; - lttv_option_add("fatal",'f', "make critical messages fatal", - "none", - LTTV_OPT_NONE, NULL, lttv_fatal, NULL); + a_debug = FALSE; + lttv_option_add("debug",'d', "print debugging messages", "none", + LTTV_OPT_NONE, NULL, lttv_debug, NULL); + + /* use --edebug, -e conflicts with filter. Problem with option parsing when we + * reparse the options with different number of arguments. */ + lttv_option_add("edebug",'e', "print event debugging", "none", + LTTV_OPT_NONE, NULL, lttv_event_debug, NULL); + + a_fatal = FALSE; + lttv_option_add("fatal",'f', "make critical messages fatal", "none", + LTTV_OPT_NONE, NULL, lttv_fatal, NULL); - lttv_profile_memory = FALSE; - lttv_option_add(profile_memory_long_option + 2, - profile_memory_short_option[1], "print memory information", "none", - LTTV_OPT_NONE, <tv_profile_memory, NULL, NULL); + lttv_profile_memory = FALSE; + lttv_option_add(profile_memory_long_option + 2, + profile_memory_short_option[1], "print memory information", "none", + LTTV_OPT_NONE, <tv_profile_memory, NULL, NULL); - /* Process the options */ + /* Process the options */ - lttv_hooks_call(before_options, NULL); - lttv_option_parse(argc, argv); - lttv_hooks_call(after_options, NULL); + lttv_hooks_call(before_options, NULL); + lttv_option_parse(argc, argv); + lttv_hooks_call(after_options, NULL); - /* Memory profiling to be useful must be activated as early as possible */ + /* Memory profiling to be useful must be activated as early as possible */ - if(profile_memory != lttv_profile_memory) - g_error("Memory profiling options must appear before other options"); + if(profile_memory != lttv_profile_memory) + g_error("Memory profiling options must appear before other options"); - /* Do the main work */ + /* Do the main work */ - lttv_hooks_call(before_main, NULL); - lttv_hooks_call(after_main, NULL); + lttv_hooks_call(before_main, NULL); + lttv_hooks_call(after_main, NULL); - /* Clean up everything */ + /* Clean up everything */ - lttv_module_release(module_option); - lttv_module_release(module_module); + lttv_module_release(module_option); + lttv_module_release(module_module); - lttv_hooks_destroy(before_options); - lttv_hooks_destroy(after_options); - lttv_hooks_destroy(before_main); - lttv_hooks_destroy(after_main); - g_object_unref(attributes); + lttv_hooks_destroy(before_options); + lttv_hooks_destroy(after_options); + lttv_hooks_destroy(before_main); + lttv_hooks_destroy(after_main); + g_object_unref(attributes); - if(profile_memory) { - g_message("Memory summary after main"); - g_mem_profile(); - } - return 0; + if(profile_memory) { + g_message("Memory summary after main"); + g_mem_profile(); + } + return 0; } LttvAttribute *lttv_global_attributes() { - return (LttvAttribute*)attributes; + return (LttvAttribute*)attributes; } void lttv_module_option(void *hook_data) { - GError *error = NULL; + GError *error = NULL; - lttv_module_require(a_module, &error); - if(error != NULL) g_error("%s", error->message); + lttv_module_require(a_module, &error); + if(error != NULL) g_error("%s", error->message); } void lttv_module_path_option(void *hook_data) { - lttv_library_path_add(a_module_path); + lttv_library_path_add(a_module_path); } void lttv_verbose(void *hook_data) { - g_log_set_handler(NULL, G_LOG_LEVEL_INFO, g_log_default_handler, NULL); - g_info("Logging set to include INFO level messages"); + g_log_set_handler(NULL, G_LOG_LEVEL_INFO, g_log_default_handler, NULL); + g_info("Logging set to include INFO level messages"); } void lttv_debug(void *hook_data) { - g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, g_log_default_handler, NULL); - g_info("Logging set to include DEBUG level messages"); + g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, g_log_default_handler, NULL); + g_info("Logging set to include DEBUG level messages"); } void lttv_event_debug(void *hook_data) { - ltt_event_debug(1); - g_info("Output event detailed debug"); + ltt_event_debug(1); + g_info("Output event detailed debug"); } void lttv_fatal(void *hook_data) { - g_log_set_always_fatal(G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL); - //g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); - g_info("Critical log from glib will abort execution"); + g_log_set_always_fatal(G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL); + //g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); + g_info("Critical log from glib will abort execution"); } void lttv_help(void *hook_data) { - printf("Linux Trace Toolkit Visualizer " VERSION "\n"); - printf("\n"); - lttv_option_show_help(); - printf("\n"); + printf("Linux Trace Toolkit Visualizer " VERSION "\n"); + printf("\n"); + lttv_option_show_help(); + printf("\n"); } /* - Define formally traceset/trace in the GUI for the user and decide how - trace/traceset sharing goes in the application. + trace/traceset sharing goes in the application. - Use appropriately the new functions in time.h diff --git a/lttv/lttv/module.c b/lttv/lttv/module.c index 198e1385..28c3ca70 100644 --- a/lttv/lttv/module.c +++ b/lttv/lttv/module.c @@ -30,18 +30,18 @@ struct _LttvLibrary { - LttvLibraryInfo info; - GPtrArray *modules; - GModule *gm; - guint locked_loaded; + LttvLibraryInfo info; + GPtrArray *modules; + GModule *gm; + guint locked_loaded; }; struct _LttvModule { - LttvModuleInfo info; - char **prerequisites_names; - GPtrArray *prerequisites; + LttvModuleInfo info; + char **prerequisites_names; + GPtrArray *prerequisites; }; @@ -81,309 +81,309 @@ static void module_release(LttvModule *m); static LttvLibrary *library_add(char *name, char *path, GModule *gm) { - LttvLibrary *l; - - LttvModule *m; - - struct _LttvModuleDescription *link; - - GPtrArray *modules; - - l = g_new(LttvLibrary, 1); - l->modules = g_ptr_array_new(); - l->gm = gm; - l->locked_loaded = 0; - l->info.name = g_strdup(name); - l->info.path = g_strdup(path); - l->info.load_count = 0; - - g_ptr_array_add(libraries, l); - g_hash_table_insert(libraries_by_g_module, gm, l); - - *module_next = NULL; - for(link = module_chain; link != NULL; link = link->next) { - m = g_new(LttvModule, 1); - g_ptr_array_add(l->modules, m); - - modules = g_hash_table_lookup(modules_by_name, link->name); - if(modules == NULL) { - modules = g_ptr_array_new(); - g_hash_table_insert(modules_by_name, g_strdup(link->name), modules); - } - g_ptr_array_add(modules, m); - - m->prerequisites_names = link->prerequisites; - m->prerequisites = g_ptr_array_new(); - m->info.name = link->name; - m->info.short_description = link->short_description; - m->info.description = link->description; - m->info.init = link->init; - m->info.destroy = link->destroy; - m->info.library = l; - m->info.require_count = 0; - m->info.use_count = 0; - m->info.prerequisites_number = link->prerequisites_number; - } - return l; + LttvLibrary *l; + + LttvModule *m; + + struct _LttvModuleDescription *link; + + GPtrArray *modules; + + l = g_new(LttvLibrary, 1); + l->modules = g_ptr_array_new(); + l->gm = gm; + l->locked_loaded = 0; + l->info.name = g_strdup(name); + l->info.path = g_strdup(path); + l->info.load_count = 0; + + g_ptr_array_add(libraries, l); + g_hash_table_insert(libraries_by_g_module, gm, l); + + *module_next = NULL; + for(link = module_chain; link != NULL; link = link->next) { + m = g_new(LttvModule, 1); + g_ptr_array_add(l->modules, m); + + modules = g_hash_table_lookup(modules_by_name, link->name); + if(modules == NULL) { + modules = g_ptr_array_new(); + g_hash_table_insert(modules_by_name, g_strdup(link->name), modules); + } + g_ptr_array_add(modules, m); + + m->prerequisites_names = link->prerequisites; + m->prerequisites = g_ptr_array_new(); + m->info.name = link->name; + m->info.short_description = link->short_description; + m->info.description = link->description; + m->info.init = link->init; + m->info.destroy = link->destroy; + m->info.library = l; + m->info.require_count = 0; + m->info.use_count = 0; + m->info.prerequisites_number = link->prerequisites_number; + } + return l; } static void library_remove(LttvLibrary *l) { - LttvModule *m; + LttvModule *m; - GPtrArray *modules; - GPtrArray **modules_ptr = &modules; /* for strict aliasing */ - guint i; + GPtrArray *modules; + GPtrArray **modules_ptr = &modules; /* for strict aliasing */ + guint i; - char *key; - char **key_ptr = &key; /* for strict aliasing */ + char *key; + char **key_ptr = &key; /* for strict aliasing */ - for(i = 0 ; i < l->modules->len ; i++) { - m = (LttvModule *)(l->modules->pdata[i]); + for(i = 0 ; i < l->modules->len ; i++) { + m = (LttvModule *)(l->modules->pdata[i]); - g_hash_table_lookup_extended(modules_by_name, m->info.name, + g_hash_table_lookup_extended(modules_by_name, m->info.name, (gpointer *)key_ptr, (gpointer *)modules_ptr); - g_assert(modules != NULL); - g_ptr_array_remove(modules, m); - if(modules->len == 0) { - g_hash_table_remove(modules_by_name, m->info.name); - g_ptr_array_free(modules, TRUE); - g_free(key); - } - - g_ptr_array_free(m->prerequisites, TRUE); - g_free(m); - } - - g_ptr_array_remove(libraries, l); - g_hash_table_remove(libraries_by_g_module, l->gm); - g_ptr_array_free(l->modules, TRUE); - g_free(l->info.name); - g_free(l->info.path); - g_free(l); + g_assert(modules != NULL); + g_ptr_array_remove(modules, m); + if(modules->len == 0) { + g_hash_table_remove(modules_by_name, m->info.name); + g_ptr_array_free(modules, TRUE); + g_free(key); + } + + g_ptr_array_free(m->prerequisites, TRUE); + g_free(m); + } + + g_ptr_array_remove(libraries, l); + g_hash_table_remove(libraries_by_g_module, l->gm); + g_ptr_array_free(l->modules, TRUE); + g_free(l->info.name); + g_free(l->info.path); + g_free(l); } static LttvLibrary *library_load(char *name, GError **error) { - GModule *gm = NULL; + GModule *gm = NULL; - int i, nb; + int i, nb; - /* path is always initialized, checked */ - char *path = NULL, *pathname; + /* path is always initialized, checked */ + char *path = NULL, *pathname; - LttvLibrary *l; + LttvLibrary *l; - GString *messages = g_string_new(""); + GString *messages = g_string_new(""); - /* insure that module.c is initialized */ + /* insure that module.c is initialized */ - init(); + init(); - /* Try to find the library along all the user specified paths */ + /* Try to find the library along all the user specified paths */ - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Load library %s", name); - nb = lttv_library_path_number(); - for(i = 0 ; i <= nb ; i++) { - if(i < nb) path = lttv_library_path_get(i); - else path = NULL; + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Load library %s", name); + nb = lttv_library_path_number(); + for(i = 0 ; i <= nb ; i++) { + if(i < nb) path = lttv_library_path_get(i); + else path = NULL; - pathname = g_module_build_path(path ,name); - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Try path %s", pathname); - module_chain = NULL; - module_next = &module_chain; - gm = g_module_open(pathname,0); - g_free(pathname); - - if(gm != NULL) break; + pathname = g_module_build_path(path ,name); + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Try path %s", pathname); + module_chain = NULL; + module_next = &module_chain; + gm = g_module_open(pathname,0); + g_free(pathname); - messages = g_string_append(messages, g_module_error()); - messages = g_string_append(messages, "\n"); - g_log(G_LOG_DOMAIN,G_LOG_LEVEL_INFO,"Trial failed, %s", g_module_error()); - } + if(gm != NULL) break; - /* Module cannot be found */ + messages = g_string_append(messages, g_module_error()); + messages = g_string_append(messages, "\n"); + g_log(G_LOG_DOMAIN,G_LOG_LEVEL_INFO,"Trial failed, %s", g_module_error()); + } - if(gm == NULL) { - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Failed to load %s", name); - g_set_error(error, lttv_module_error, LTTV_MODULE_NOT_FOUND, - "Cannot load library %s: %s", name, messages->str); - g_string_free(messages, TRUE); - return NULL; - } - g_string_free(messages, TRUE); + /* Module cannot be found */ - /* Check if the library was already loaded */ + if(gm == NULL) { + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Failed to load %s", name); + g_set_error(error, lttv_module_error, LTTV_MODULE_NOT_FOUND, + "Cannot load library %s: %s", name, messages->str); + g_string_free(messages, TRUE); + return NULL; + } + g_string_free(messages, TRUE); - l = g_hash_table_lookup(libraries_by_g_module, gm); + /* Check if the library was already loaded */ - /* This library was not already loaded */ + l = g_hash_table_lookup(libraries_by_g_module, gm); - if(l == NULL) { - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Library %s (%s) loaded", name, - g_module_name(gm)); - l = library_add(name, path, gm); - } - return l; + /* This library was not already loaded */ + + if(l == NULL) { + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Library %s (%s) loaded", name, + g_module_name(gm)); + l = library_add(name, path, gm); + } + return l; } LttvLibrary *lttv_library_load(char *name, GError **error) { - LttvLibrary *l = library_load(name, error); - if(l != NULL) l->info.load_count++; - return l; + LttvLibrary *l = library_load(name, error); + if(l != NULL) l->info.load_count++; + return l; } /* Returns < 0 if still in use, 0 if freed */ static gint library_unload(LttvLibrary *l) { - guint i; + guint i; - GModule *gm; + GModule *gm; - LttvModule *m; + LttvModule *m; - if(l->locked_loaded > 0) { - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Unload library %s: locked loaded", - l->info.name); - return 1; - } + if(l->locked_loaded > 0) { + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Unload library %s: locked loaded", + l->info.name); + return 1; + } - if(l->info.load_count > 0) { - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Unload library %s: load count %d", - l->info.name, l->info.load_count); - return l->info.load_count; - } + if(l->info.load_count > 0) { + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Unload library %s: load count %d", + l->info.name, l->info.load_count); + return l->info.load_count; + } - /* Check if all its modules have been released */ + /* Check if all its modules have been released */ - for(i = 0 ; i < l->modules->len ; i++) { - m = (LttvModule *)(l->modules->pdata[i]); - if(m->info.use_count > 0) { - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO,"Unload library %s: module %s used", - l->info.name, m->info.name); - return 1; - } - } + for(i = 0 ; i < l->modules->len ; i++) { + m = (LttvModule *)(l->modules->pdata[i]); + if(m->info.use_count > 0) { + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO,"Unload library %s: module %s used", + l->info.name, m->info.name); + return 1; + } + } - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Unload library %s: close the GModule", - l->info.name); - gm = l->gm; - library_remove(l); - if(gm != NULL) g_module_close(gm); + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Unload library %s: close the GModule", + l->info.name); + gm = l->gm; + library_remove(l); + if(gm != NULL) g_module_close(gm); - /* insure that module.c will be finalized */ + /* insure that module.c will be finalized */ - finish_destroy(); - return 0; + finish_destroy(); + return 0; } gint lttv_library_unload(LttvLibrary *l) { - /* In the case where we wait for a module to release, the load count is 0 - * and should not be decremented. */ - if(l->info.load_count != 0) { - l->info.load_count--; - return l->info.load_count; - } else { - library_unload(l); - return 0; - } + /* In the case where we wait for a module to release, the load count is 0 + * and should not be decremented. */ + if(l->info.load_count != 0) { + l->info.load_count--; + return l->info.load_count; + } else { + library_unload(l); + return 0; + } } static void library_lock_loaded(LttvLibrary *l) { - l->locked_loaded++; + l->locked_loaded++; } static gint library_unlock_loaded(LttvLibrary *l) { - l->locked_loaded--; - return library_unload(l); + l->locked_loaded--; + return library_unload(l); } static LttvModule *module_require(char *name, GError **error) { - GError *tmp_error = NULL; + GError *tmp_error = NULL; - guint i, j; + guint i, j; - LttvModule *m, *required; + LttvModule *m, *required; - LttvLibrary *l = NULL; + LttvLibrary *l = NULL; - GPtrArray *modules; + GPtrArray *modules; - /* Insure that module.c is initialized */ + /* Insure that module.c is initialized */ - init(); + init(); - /* Check if the module is already loaded */ + /* Check if the module is already loaded */ - modules = g_hash_table_lookup(modules_by_name, name); + modules = g_hash_table_lookup(modules_by_name, name); - /* Try to load a library having the module name */ + /* Try to load a library having the module name */ - if(modules == NULL) { - l = library_load(name, error); - if(l == NULL) return NULL; - else library_lock_loaded(l); + if(modules == NULL) { + l = library_load(name, error); + if(l == NULL) return NULL; + else library_lock_loaded(l); - /* A library was found, does it contain the named module */ + /* A library was found, does it contain the named module */ - modules = g_hash_table_lookup(modules_by_name, name); - if(modules == NULL) { - g_set_error(error, lttv_module_error, LTTV_MODULE_NOT_FOUND, - "Module %s not found in library %s", name, l->info.name); - library_unlock_loaded(l); - return NULL; - } - } - m = (LttvModule *)(modules->pdata[modules->len - 1]); + modules = g_hash_table_lookup(modules_by_name, name); + if(modules == NULL) { + g_set_error(error, lttv_module_error, LTTV_MODULE_NOT_FOUND, + "Module %s not found in library %s", name, l->info.name); + library_unlock_loaded(l); + return NULL; + } + } + m = (LttvModule *)(modules->pdata[modules->len - 1]); - /* We have the module */ + /* We have the module */ - m->info.use_count++; + m->info.use_count++; - /* First use of the module. Initialize after getting the prerequisites */ + /* First use of the module. Initialize after getting the prerequisites */ - if(m->info.use_count == 1) { - for(i = 0 ; i < m->info.prerequisites_number ; i++) { - required = module_require(m->prerequisites_names[i], &tmp_error); + if(m->info.use_count == 1) { + for(i = 0 ; i < m->info.prerequisites_number ; i++) { + required = module_require(m->prerequisites_names[i], &tmp_error); - /* A prerequisite could not be found, undo everything and fail */ + /* A prerequisite could not be found, undo everything and fail */ - if(required == NULL) { - for(j = 0 ; j < m->prerequisites->len ; j++) { - module_release((LttvModule *)(m->prerequisites->pdata[j])); - } - g_ptr_array_set_size(m->prerequisites, 0); - if(l != NULL) library_unlock_loaded(l); - g_set_error(error, lttv_module_error, LTTV_MODULE_NOT_FOUND, - "Cannot find prerequisite for module %s: %s", name, - tmp_error->message); - g_clear_error(&tmp_error); - return NULL; - } - g_ptr_array_add(m->prerequisites, required); - } - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Module %s: init()", m->info.name); - m->info.init(); - } + if(required == NULL) { + for(j = 0 ; j < m->prerequisites->len ; j++) { + module_release((LttvModule *)(m->prerequisites->pdata[j])); + } + g_ptr_array_set_size(m->prerequisites, 0); + if(l != NULL) library_unlock_loaded(l); + g_set_error(error, lttv_module_error, LTTV_MODULE_NOT_FOUND, + "Cannot find prerequisite for module %s: %s", name, + tmp_error->message); + g_clear_error(&tmp_error); + return NULL; + } + g_ptr_array_add(m->prerequisites, required); + } + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Module %s: init()", m->info.name); + m->info.init(); + } - /* Decrement the load count of the library. It will not really be - unloaded since it contains a currently used module. */ + /* Decrement the load count of the library. It will not really be + unloaded since it contains a currently used module. */ - if(l != NULL) library_unlock_loaded(l); + if(l != NULL) library_unlock_loaded(l); - return(m); + return(m); } @@ -393,218 +393,218 @@ static LttvModule *module_require(char *name, GError **error) LttvModule *lttv_module_require(char *name, GError **error) { - LttvModule *m = module_require(name, error); - if(m != NULL) m->info.require_count++; - return(m); + LttvModule *m = module_require(name, error); + if(m != NULL) m->info.require_count++; + return(m); } static void module_release(LttvModule *m) { - guint i; - - library_lock_loaded(m->info.library); - - m->info.use_count--; - if(m->info.use_count == 0) { - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Module %s: destroy()",m->info.name); - m->info.destroy(); - for(i = 0 ; i < m->prerequisites->len ; i++) { - module_release((LttvModule *)(m->prerequisites->pdata[i])); - } - g_ptr_array_set_size(m->prerequisites, 0); - } - library_unlock_loaded(m->info.library); + guint i; + + library_lock_loaded(m->info.library); + + m->info.use_count--; + if(m->info.use_count == 0) { + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Module %s: destroy()",m->info.name); + m->info.destroy(); + for(i = 0 ; i < m->prerequisites->len ; i++) { + module_release((LttvModule *)(m->prerequisites->pdata[i])); + } + g_ptr_array_set_size(m->prerequisites, 0); + } + library_unlock_loaded(m->info.library); } void lttv_module_release(LttvModule *m) { - m->info.require_count--; - module_release(m); + m->info.require_count--; + module_release(m); } void lttv_module_info(LttvModule *m, LttvModuleInfo *info) { - *info = m->info; + *info = m->info; } unsigned lttv_module_prerequisite_number(LttvModule *m) { - return m->prerequisites->len; + return m->prerequisites->len; } LttvModule *lttv_module_prerequisite_get(LttvModule *m, unsigned i) { - return (LttvModule *)(m->prerequisites->pdata[i]); + return (LttvModule *)(m->prerequisites->pdata[i]); } void lttv_library_info(LttvLibrary *l, LttvLibraryInfo *info) { - *info = l->info; + *info = l->info; } unsigned lttv_library_module_number(LttvLibrary *l) { - return l->modules->len; + return l->modules->len; } LttvModule *lttv_library_module_get(LttvLibrary *l, unsigned i) { - return (LttvModule *)(l->modules->pdata[i]); + return (LttvModule *)(l->modules->pdata[i]); } unsigned lttv_library_number() { - return libraries->len; + return libraries->len; } LttvLibrary *lttv_library_get(unsigned i) { - return (LttvLibrary *)(libraries->pdata[i]); + return (LttvLibrary *)(libraries->pdata[i]); } void lttv_library_path_add(const char *name) { - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Add library path %s", name); - g_ptr_array_add(library_paths,(char*)g_strdup(name)); + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Add library path %s", name); + g_ptr_array_add(library_paths,(char*)g_strdup(name)); } void lttv_library_path_remove(const char *name) { - guint i; - - for(i = 0 ; i < library_paths->len ; i++) { - if(g_str_equal(name, library_paths->pdata[i])) { - g_free(library_paths->pdata[i]); - g_ptr_array_remove_index(library_paths,i); - return; - } - } + guint i; + + for(i = 0 ; i < library_paths->len ; i++) { + if(g_str_equal(name, library_paths->pdata[i])) { + g_free(library_paths->pdata[i]); + g_ptr_array_remove_index(library_paths,i); + return; + } + } } unsigned lttv_library_path_number() { - return library_paths->len; + return library_paths->len; } char *lttv_library_path_get(unsigned i) { - return (char *)(library_paths->pdata[library_paths->len - i - 1]); + return (char *)(library_paths->pdata[library_paths->len - i - 1]); } void lttv_module_register(struct _LttvModuleDescription *d) { - *module_next = d; - module_next = &(d->next); + *module_next = d; + module_next = &(d->next); } static void init() { - if(initialized) return; - g_assert(destroyed); - - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Init module.c"); - - initialized = TRUE; - destroyed = FALSE; - lttv_module_error = g_quark_from_string("LTTV_MODULE_ERROR"); - modules_by_name = g_hash_table_new(g_str_hash, g_str_equal); - libraries = g_ptr_array_new(); - libraries_by_g_module = g_hash_table_new(g_direct_hash, g_direct_equal); - library_paths = g_ptr_array_new(); - - if(builtin_chain == NULL) builtin_chain = module_chain; - module_chain = builtin_chain; - library_add("builtin", NULL, NULL); + if(initialized) return; + g_assert(destroyed); + + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Init module.c"); + + initialized = TRUE; + destroyed = FALSE; + lttv_module_error = g_quark_from_string("LTTV_MODULE_ERROR"); + modules_by_name = g_hash_table_new(g_str_hash, g_str_equal); + libraries = g_ptr_array_new(); + libraries_by_g_module = g_hash_table_new(g_direct_hash, g_direct_equal); + library_paths = g_ptr_array_new(); + + if(builtin_chain == NULL) builtin_chain = module_chain; + module_chain = builtin_chain; + library_add("builtin", NULL, NULL); } static void finish_destroy() { - guint i; - - if(initialized) return; - g_assert(!destroyed); - - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Finish destroy module.c"); - g_hash_table_destroy(modules_by_name); - g_ptr_array_free(libraries, TRUE); - g_hash_table_destroy(libraries_by_g_module); - for(i = 0 ; i < library_paths->len ; i++) { - g_free(library_paths->pdata[i]); - } - g_ptr_array_free(library_paths, TRUE); - destroyed = TRUE; + guint i; + + if(initialized) return; + g_assert(!destroyed); + + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Finish destroy module.c"); + g_hash_table_destroy(modules_by_name); + g_ptr_array_free(libraries, TRUE); + g_hash_table_destroy(libraries_by_g_module); + for(i = 0 ; i < library_paths->len ; i++) { + g_free(library_paths->pdata[i]); + } + g_ptr_array_free(library_paths, TRUE); + destroyed = TRUE; } static void destroy() -{ - guint i, j, nb; +{ + guint i, j, nb; - LttvLibrary *l, **locked_libraries; + LttvLibrary *l, **locked_libraries; - LttvModule *m; + LttvModule *m; - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Destroy module.c"); + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Destroy module.c"); - /* Unload all libraries */ + /* Unload all libraries */ - nb = libraries->len; - locked_libraries = g_new(LttvLibrary *, nb); + nb = libraries->len; + locked_libraries = g_new(LttvLibrary *, nb); - for(i = 0 ; i < nb ; i++) { - //g_assert(nb == libraries->len); - l = (LttvLibrary *)(libraries->pdata[i]); - locked_libraries[i] = l; - library_lock_loaded(l); - for(j = 0 ; j < l->modules->len ; j++) { - m = (LttvModule *)(l->modules->pdata[j]); - while(m->info.require_count > 0) lttv_module_release(m); - } - if(library_unlock_loaded(l) > 0) - while(lttv_library_unload(l) > 0); + for(i = 0 ; i < nb ; i++) { + //g_assert(nb == libraries->len); + l = (LttvLibrary *)(libraries->pdata[i]); + locked_libraries[i] = l; + library_lock_loaded(l); + for(j = 0 ; j < l->modules->len ; j++) { + m = (LttvModule *)(l->modules->pdata[j]); + while(m->info.require_count > 0) lttv_module_release(m); + } + if(library_unlock_loaded(l) > 0) + while(lttv_library_unload(l) > 0); - /* If the number of librairies loaded have changed, restart from the - * beginning */ - if(nb != libraries->len) { - i = 0; - nb = libraries->len; - } + /* If the number of librairies loaded have changed, restart from the + * beginning */ + if(nb != libraries->len) { + i = 0; + nb = libraries->len; + } - } + } - for(i = 0 ; i < nb ; i++) { - l = locked_libraries[i]; - library_unlock_loaded(l); - } - g_free(locked_libraries); + for(i = 0 ; i < nb ; i++) { + l = locked_libraries[i]; + library_unlock_loaded(l); + } + g_free(locked_libraries); - /* The library containing module.c may be locked by our caller */ + /* The library containing module.c may be locked by our caller */ - g_assert(libraries->len <= 1); + g_assert(libraries->len <= 1); - initialized = FALSE; + initialized = FALSE; - exit(0); + exit(0); } -LTTV_MODULE("module", "Modules in libraries", \ - "Load libraries, list, require and initialize contained modules", \ - init, destroy) +LTTV_MODULE("module", "Modules in libraries", \ + "Load libraries, list, require and initialize contained modules", \ + init, destroy) diff --git a/lttv/lttv/module.h b/lttv/lttv/module.h index 67931405..ff992aec 100644 --- a/lttv/lttv/module.h +++ b/lttv/lttv/module.h @@ -47,30 +47,30 @@ typedef void (*LttvModuleDestroy)(); typedef struct _LttvModuleInfo { - char *name; - char *short_description; - char *description; - LttvModuleInit init; - LttvModuleDestroy destroy; - LttvLibrary *library; - unsigned require_count; - unsigned use_count; - unsigned prerequisites_number; + char *name; + char *short_description; + char *description; + LttvModuleInit init; + LttvModuleDestroy destroy; + LttvLibrary *library; + unsigned require_count; + unsigned use_count; + unsigned prerequisites_number; } LttvModuleInfo; typedef struct _LttvLibraryInfo { - char *name; - char *path; - unsigned load_count; + char *name; + char *path; + unsigned load_count; } LttvLibraryInfo; typedef enum _LttvModuleError { - LTTV_MODULE_NOT_FOUND, - LTTV_MODULE_NO_INIT + LTTV_MODULE_NOT_FOUND, + LTTV_MODULE_NO_INIT } LttvModuleError; @@ -162,21 +162,21 @@ char *lttv_library_path_get(unsigned i); */ #define LTTV_MODULE(name, short_desc, desc, init, destroy, ...) \ - \ - static void _LTTV_MODULE_REGISTER(__LINE__)() \ - __attribute__((constructor)); \ - \ - static void _LTTV_MODULE_REGISTER(__LINE__)() \ - { \ - static char *module_prerequisites[] = { __VA_ARGS__ }; \ - \ - static struct _LttvModuleDescription module = { \ - name, short_desc, desc, init, destroy, \ - sizeof(module_prerequisites) / sizeof(char *), \ - module_prerequisites, NULL}; \ - \ - lttv_module_register(&module); \ - } + \ + static void _LTTV_MODULE_REGISTER(__LINE__)() \ + __attribute__((constructor)); \ + \ + static void _LTTV_MODULE_REGISTER(__LINE__)() \ + { \ + static char *module_prerequisites[] = { __VA_ARGS__ }; \ + \ + static struct _LttvModuleDescription module = { \ + name, short_desc, desc, init, destroy, \ + sizeof(module_prerequisites) / sizeof(char *), \ + module_prerequisites, NULL}; \ + \ + lttv_module_register(&module); \ + } /* Internal structure and function used to register modules, called by @@ -187,14 +187,14 @@ char *lttv_library_path_get(unsigned i); struct _LttvModuleDescription { - char *name; - char *short_description; - char *description; - LttvModuleInit init; - LttvModuleDestroy destroy; - unsigned prerequisites_number; - char **prerequisites; - struct _LttvModuleDescription *next; + char *name; + char *short_description; + char *description; + LttvModuleInit init; + LttvModuleDestroy destroy; + unsigned prerequisites_number; + char **prerequisites; + struct _LttvModuleDescription *next; }; void lttv_module_register(struct _LttvModuleDescription *d); diff --git a/lttv/lttv/option.c b/lttv/lttv/option.c index f0d44254..148b4c88 100644 --- a/lttv/lttv/option.c +++ b/lttv/lttv/option.c @@ -26,292 +26,287 @@ #include typedef struct _LttvOption { - char *long_name; - char char_name; - char *description; - char *arg_description; - LttvOptionType t; - gpointer p; - LttvOptionHook hook; - gpointer hook_data; - - /* Keep the order of addition */ - guint val; + char *long_name; + char char_name; + char *description; + char *arg_description; + LttvOptionType t; + gpointer p; + LttvOptionHook hook; + gpointer hook_data; + + /* Keep the order of addition */ + guint val; } LttvOption; GHashTable *options; -static void -list_options(gpointer key, gpointer value, gpointer user_data) +static void list_options(gpointer key, gpointer value, gpointer user_data) { - GPtrArray *list = (GPtrArray *)user_data; - LttvOption *option = (LttvOption *)value; + GPtrArray *list = (GPtrArray *)user_data; + LttvOption *option = (LttvOption *)value; - if(list->len < option->val) - g_ptr_array_set_size(list, option->val); - list->pdata[option->val-1] = option; + if(list->len < option->val) + g_ptr_array_set_size(list, option->val); + list->pdata[option->val-1] = option; } -static void -free_option(LttvOption *option) +static void free_option(LttvOption *option) { - g_free(option->long_name); - g_free(option->description); - g_free(option->arg_description); - g_free(option); + g_free(option->long_name); + g_free(option->description); + g_free(option->arg_description); + g_free(option); } void lttv_option_add(const char *long_name, const char char_name, - const char *description, const char *arg_description, - const LttvOptionType t, void *p, - const LttvOptionHook h, void *hook_data) + const char *description, const char *arg_description, + const LttvOptionType t, void *p, + const LttvOptionHook h, void *hook_data) { - LttvOption *option; - - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Add option %s", long_name); - if(g_hash_table_lookup(options, long_name) != NULL) { - g_warning("duplicate option"); - return; - } - - option = g_new(LttvOption, 1); - option->long_name = g_strdup(long_name); - option->char_name = char_name; - option->description = g_strdup(description); - option->arg_description = g_strdup(arg_description); - option->t = t; - option->p = p; - option->hook = h; - option->hook_data = hook_data; - option->val = g_hash_table_size(options) + 1; - g_hash_table_insert(options, option->long_name, option); + LttvOption *option; + + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Add option %s", long_name); + if(g_hash_table_lookup(options, long_name) != NULL) { + g_warning("duplicate option"); + return; + } + + option = g_new(LttvOption, 1); + option->long_name = g_strdup(long_name); + option->char_name = char_name; + option->description = g_strdup(description); + option->arg_description = g_strdup(arg_description); + option->t = t; + option->p = p; + option->hook = h; + option->hook_data = hook_data; + option->val = g_hash_table_size(options) + 1; + g_hash_table_insert(options, option->long_name, option); } -void -lttv_option_remove(const char *long_name) +void lttv_option_remove(const char *long_name) { - LttvOption *option = g_hash_table_lookup(options, long_name); - - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Remove option %s", long_name); - if(option == NULL) { - g_warning("trying to remove unknown option %s", long_name); - return; - } - g_hash_table_remove(options, long_name); - free_option(option); + LttvOption *option = g_hash_table_lookup(options, long_name); + + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Remove option %s", long_name); + if(option == NULL) { + g_warning("trying to remove unknown option %s", long_name); + return; + } + g_hash_table_remove(options, long_name); + free_option(option); } static int poptToLTT[] = { - POPT_ARG_NONE, POPT_ARG_STRING, POPT_ARG_INT, POPT_ARG_LONG + POPT_ARG_NONE, POPT_ARG_STRING, POPT_ARG_INT, POPT_ARG_LONG }; static struct poptOption endOption = { NULL, '\0', 0, NULL, 0, NULL, NULL }; -static void -build_popts(GPtrArray **plist, struct poptOption **ppopts, poptContext *pc, - int argc, char **argv) +static void build_popts(GPtrArray **plist, struct poptOption **ppopts, + poptContext *pc, int argc, char **argv) { - LttvOption *option; + LttvOption *option; - GPtrArray *list; + GPtrArray *list; - struct poptOption *popts; + struct poptOption *popts; - poptContext c; + poptContext c; - guint i; + guint i; - list = g_ptr_array_sized_new(g_hash_table_size(options)); + list = g_ptr_array_sized_new(g_hash_table_size(options)); - g_hash_table_foreach(options, list_options, list); + g_hash_table_foreach(options, list_options, list); - /* Build a popt options array from our list */ + /* Build a popt options array from our list */ - popts = g_new(struct poptOption, list->len + 1); + popts = g_new(struct poptOption, list->len + 1); - /* add the options in the reverse order, so last additions are parsed first */ - for(i = 0 ; i < list->len ; i++) { - guint reverse_i = list->len-1-i; - option = (LttvOption *)list->pdata[i]; - popts[reverse_i].longName = option->long_name; - popts[reverse_i].shortName = option->char_name; - popts[reverse_i].descrip = option->description; - popts[reverse_i].argDescrip = option->arg_description; - popts[reverse_i].argInfo = poptToLTT[option->t]; - popts[reverse_i].arg = option->p; - popts[reverse_i].val = option->val; - } + /* add the options in the reverse order, so last additions are parsed first */ + for(i = 0 ; i < list->len ; i++) { + guint reverse_i = list->len-1-i; + option = (LttvOption *)list->pdata[i]; + popts[reverse_i].longName = option->long_name; + popts[reverse_i].shortName = option->char_name; + popts[reverse_i].descrip = option->description; + popts[reverse_i].argDescrip = option->arg_description; + popts[reverse_i].argInfo = poptToLTT[option->t]; + popts[reverse_i].arg = option->p; + popts[reverse_i].val = option->val; + } - /* Terminate the array for popt and create the context */ + /* Terminate the array for popt and create the context */ - popts[list->len] = endOption; - c = poptGetContext(argv[0], argc, (const char**)argv, popts, 0); + popts[list->len] = endOption; + c = poptGetContext(argv[0], argc, (const char**)argv, popts, 0); - *plist = list; - *ppopts = popts; - *pc = c; + *plist = list; + *ppopts = popts; + *pc = c; } -static void -destroy_popts(GPtrArray **plist, struct poptOption **ppopts, poptContext *pc) +static void destroy_popts(GPtrArray **plist, struct poptOption **ppopts, + poptContext *pc) { - g_ptr_array_free(*plist, TRUE); *plist = NULL; - g_free(*ppopts); *ppopts = NULL; - poptFreeContext(*pc); + g_ptr_array_free(*plist, TRUE); *plist = NULL; + g_free(*ppopts); *ppopts = NULL; + poptFreeContext(*pc); } void lttv_option_parse(int argc, char **argv) { - GPtrArray *list; + GPtrArray *list; - LttvOption *option; + LttvOption *option; - int i, rc, first_arg; + int i, rc, first_arg; - struct poptOption *popts; + struct poptOption *popts; - poptContext c; + poptContext c; - i = 0; + i = 0; - first_arg = 0; + first_arg = 0; - guint hash_size = 0; + guint hash_size = 0; - build_popts(&list, &popts, &c, argc, argv); + build_popts(&list, &popts, &c, argc, argv); - /* Parse options while not end of options event */ + /* Parse options while not end of options event */ - while((rc = poptGetNextOpt(c)) != -1) { + while((rc = poptGetNextOpt(c)) != -1) { - /* The option was recognized and the rc value returned is the argument - position in the array. Call the associated hook if present. */ - - if(rc > 0) { - option = (LttvOption *)(list->pdata[rc - 1]); - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Option %s encountered", - option->long_name); - hash_size = g_hash_table_size(options); - if(option->hook != NULL) { - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Option %s hook called", - option->long_name); - option->hook(option->hook_data); - } - i++; + /* The option was recognized and the rc value returned is the argument + position in the array. Call the associated hook if present. */ - /* If the size of the option hash changed, add new options - * right now. It resolves the conflict of multiple same short - * option use. - */ - if(hash_size != g_hash_table_size(options)) { - destroy_popts(&list, &popts, &c); - build_popts(&list, &popts, &c, argc, argv); + if(rc > 0) { + option = (LttvOption *)(list->pdata[rc - 1]); + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Option %s encountered", + option->long_name); + hash_size = g_hash_table_size(options); + if(option->hook != NULL) { + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Option %s hook called", + option->long_name); + option->hook(option->hook_data); + } + i++; - /* Get back to the same argument */ + /* If the size of the option hash changed, add new options + * right now. It resolves the conflict of multiple same short + * option use. + */ + if(hash_size != g_hash_table_size(options)) { + destroy_popts(&list, &popts, &c); + build_popts(&list, &popts, &c, argc, argv); - first_arg = i; - for(i = 0; i < first_arg; i++) { - rc = poptGetNextOpt(c); - option = (LttvOption *)(list->pdata[rc - 1]); - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Option %s rescanned, skipped", - option->long_name); - } - } - } + /* Get back to the same argument */ - else if(rc == POPT_ERROR_BADOPT && i != first_arg) { - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, - "Option %s not recognized, rescan options with new additions", - poptBadOption(c,0)); + first_arg = i; + for(i = 0; i < first_arg; i++) { + rc = poptGetNextOpt(c); + option = (LttvOption *)(list->pdata[rc - 1]); + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Option %s rescanned, skipped", + option->long_name); + } + } + } - /* Perhaps this option is newly added, restart parsing */ + else if(rc == POPT_ERROR_BADOPT && i != first_arg) { + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, + "Option %s not recognized, rescan options with new additions", + poptBadOption(c,0)); - destroy_popts(&list, &popts, &c); - build_popts(&list, &popts, &c, argc, argv); + /* Perhaps this option is newly added, restart parsing */ - /* Get back to the same argument */ + destroy_popts(&list, &popts, &c); + build_popts(&list, &popts, &c, argc, argv); - first_arg = i; - for(i = 0; i < first_arg; i++) { - rc = poptGetNextOpt(c); - option = (LttvOption *)(list->pdata[rc - 1]); - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Option %s rescanned, skipped", - option->long_name); - } - } + /* Get back to the same argument */ - else { + first_arg = i; + for(i = 0; i < first_arg; i++) { + rc = poptGetNextOpt(c); + option = (LttvOption *)(list->pdata[rc - 1]); + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Option %s rescanned, skipped", + option->long_name); + } + } - /* The option has some error and it is not because this is a newly - added option not recognized. */ + else { - g_error("option %s: %s", poptBadOption(c,0), poptStrerror(rc)); - break; - } - - } + /* The option has some error and it is not because this is a newly + added option not recognized. */ - destroy_popts(&list, &popts, &c); + g_error("option %s: %s", poptBadOption(c,0), poptStrerror(rc)); + break; + } + + } + + destroy_popts(&list, &popts, &c); } /* CHECK */ static void show_help(LttvOption *option) { - printf("--%s -%c argument: %s\n" , option->long_name, - option->char_name, - option->arg_description); - printf(" %s\n" , option->description); + printf("--%s -%c argument: %s\n" , option->long_name, + option->char_name, option->arg_description); + printf(" %s\n" , option->description); } void lttv_option_show_help(void) { - GPtrArray *list = g_ptr_array_new(); + GPtrArray *list = g_ptr_array_new(); - guint i; + guint i; - g_hash_table_foreach(options, list_options, list); + g_hash_table_foreach(options, list_options, list); printf("Built-in commands available:\n"); printf("\n"); - for(i = 0 ; i < list->len ; i++) { - show_help((LttvOption *)list->pdata[i]); - } - g_ptr_array_free(list, TRUE); + for(i = 0 ; i < list->len ; i++) { + show_help((LttvOption *)list->pdata[i]); + } + g_ptr_array_free(list, TRUE); } static void init() { - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Init option.c"); - options = g_hash_table_new(g_str_hash, g_str_equal); + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Init option.c"); + options = g_hash_table_new(g_str_hash, g_str_equal); } static void destroy() { - GPtrArray *list = g_ptr_array_new(); + GPtrArray *list = g_ptr_array_new(); - guint i; + guint i; - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Destroy option.c"); - g_hash_table_foreach(options, list_options, list); - g_hash_table_destroy(options); + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Destroy option.c"); + g_hash_table_foreach(options, list_options, list); + g_hash_table_destroy(options); - for(i = 0 ; i < list->len ; i++) { - free_option((LttvOption *)list->pdata[i]); - } - g_ptr_array_free(list, TRUE); + for(i = 0 ; i < list->len ; i++) { + free_option((LttvOption *)list->pdata[i]); + } + g_ptr_array_free(list, TRUE); } LTTV_MODULE("option", "Command line options processing", \ - "Functions to add, remove and parse command line options", \ - init, destroy) + "Functions to add, remove and parse command line options", \ + init, destroy) diff --git a/lttv/lttv/print.c b/lttv/lttv/print.c index 4b7ef447..d54f5f0d 100644 --- a/lttv/lttv/print.c +++ b/lttv/lttv/print.c @@ -45,265 +45,265 @@ #include static inline void print_enum_events(LttEvent *e, struct marker_field *f, - guint64 value, GString *s, LttvTracefileState *tfs) + guint64 value, GString *s, LttvTracefileState *tfs) { - LttTracefile *tf = tfs->parent.tf; - struct marker_info *info = marker_get_info_from_id(tf->mdata, e->event_id); - LttvTraceState *ts = (LttvTraceState*)(tfs->parent.t_context); - LttvNameTables *nt = ts->name_tables; - - if (tf->name == LTT_CHANNEL_KERNEL) { - if (info->name == LTT_EVENT_SYSCALL_ENTRY - && f->name == LTT_FIELD_SYSCALL_ID) { - g_string_append_printf(s, " [%s]", - g_quark_to_string(nt->syscall_names[value])); - } else if ((info->name == LTT_EVENT_SOFT_IRQ_ENTRY - || info->name == LTT_EVENT_SOFT_IRQ_EXIT - || info->name == LTT_EVENT_SOFT_IRQ_RAISE) - && f->name == LTT_FIELD_SOFT_IRQ_ID) { - g_string_append_printf(s, " [%s]", - g_quark_to_string(nt->soft_irq_names[value])); - } else if (info->name == LTT_EVENT_KPROBE - && f->name == LTT_FIELD_IP) { + LttTracefile *tf = tfs->parent.tf; + struct marker_info *info = marker_get_info_from_id(tf->mdata, e->event_id); + LttvTraceState *ts = (LttvTraceState*)(tfs->parent.t_context); + LttvNameTables *nt = ts->name_tables; + + if (tf->name == LTT_CHANNEL_KERNEL) { + if (info->name == LTT_EVENT_SYSCALL_ENTRY + && f->name == LTT_FIELD_SYSCALL_ID) { + g_string_append_printf(s, " [%s]", + g_quark_to_string(nt->syscall_names[value])); + } else if ((info->name == LTT_EVENT_SOFT_IRQ_ENTRY + || info->name == LTT_EVENT_SOFT_IRQ_EXIT + || info->name == LTT_EVENT_SOFT_IRQ_RAISE) + && f->name == LTT_FIELD_SOFT_IRQ_ID) { + g_string_append_printf(s, " [%s]", + g_quark_to_string(nt->soft_irq_names[value])); + } else if (info->name == LTT_EVENT_KPROBE + && f->name == LTT_FIELD_IP) { #if (__WORDSIZE == 32) - GQuark symbol = (GQuark)g_hash_table_lookup(nt->kprobe_hash, - (gconstpointer)&value); + GQuark symbol = (GQuark)g_hash_table_lookup(nt->kprobe_hash, + (gconstpointer)&value); #else - GQuark symbol = (GQuark)(unsigned long)g_hash_table_lookup(nt->kprobe_hash, - (gconstpointer)value); + GQuark symbol = (GQuark)(unsigned long)g_hash_table_lookup(nt->kprobe_hash, + (gconstpointer)value); #endif - if (symbol) - g_string_append_printf(s, " [%s]", g_quark_to_string(symbol)); - } - } + if (symbol) + g_string_append_printf(s, " [%s]", g_quark_to_string(symbol)); + } + } } void lttv_print_field(LttEvent *e, struct marker_field *f, GString *s, - gboolean field_names, LttvTracefileState *tfs) + gboolean field_names, LttvTracefileState *tfs) { - GQuark name; - guint64 value; + GQuark name; + guint64 value; + + //int nb, i; - //int nb, i; + switch(f->type) { + case LTT_TYPE_SIGNED_INT: + if(field_names) { + name = f->name; + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + value = ltt_event_get_long_int(e,f); + //g_string_append_printf(s, "%lld", value); + g_string_append_printf(s, f->fmt->str, value); + //g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f)); + print_enum_events(e, f, value, s, tfs); + break; - switch(f->type) { - case LTT_TYPE_SIGNED_INT: - if(field_names) { - name = f->name; - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - value = ltt_event_get_long_int(e,f); - //g_string_append_printf(s, "%lld", value); - g_string_append_printf(s, f->fmt->str, value); - //g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f)); - print_enum_events(e, f, value, s, tfs); - break; + case LTT_TYPE_UNSIGNED_INT: + if(field_names) { + name = f->name; + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + value = ltt_event_get_long_unsigned(e,f); + //g_string_append_printf(s, "%llu", value); + g_string_append_printf(s, f->fmt->str, value); + print_enum_events(e, f, value, s, tfs); + //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f)); + break; - case LTT_TYPE_UNSIGNED_INT: - if(field_names) { - name = f->name; - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - value = ltt_event_get_long_unsigned(e,f); - //g_string_append_printf(s, "%llu", value); - g_string_append_printf(s, f->fmt->str, value); - print_enum_events(e, f, value, s, tfs); - //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f)); - break; - #if 0 - case LTT_CHAR: - case LTT_UCHAR: - { - unsigned car = ltt_event_get_unsigned(e,f); - if(field_names) { - name = ltt_field_name(f); - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - if(isprint(car)) { - if(field_names) { - name = ltt_field_name(f); - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - //g_string_append_printf(s, "%c", car); - g_string_append_printf(s, type->fmt, car); - } else { - g_string_append_printf(s, "\\%x", car); - } - } - break; - case LTT_FLOAT: - if(field_names) { - name = ltt_field_name(f); - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - //g_string_append_printf(s, "%g", ltt_event_get_double(e,f)); - g_string_append_printf(s, type->fmt, ltt_event_get_double(e,f)); - break; + case LTT_CHAR: + case LTT_UCHAR: + { + unsigned car = ltt_event_get_unsigned(e,f); + if(field_names) { + name = ltt_field_name(f); + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + if(isprint(car)) { + if(field_names) { + name = ltt_field_name(f); + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + //g_string_append_printf(s, "%c", car); + g_string_append_printf(s, type->fmt, car); + } else { + g_string_append_printf(s, "\\%x", car); + } + } + break; + case LTT_FLOAT: + if(field_names) { + name = ltt_field_name(f); + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + //g_string_append_printf(s, "%g", ltt_event_get_double(e,f)); + g_string_append_printf(s, type->fmt, ltt_event_get_double(e,f)); + break; #endif - case LTT_TYPE_POINTER: - if(field_names) { - name = f->name; - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - g_string_append_printf(s, "0x%" PRIx64, ltt_event_get_long_unsigned(e,f)); - //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f)); - break; + case LTT_TYPE_POINTER: + if(field_names) { + name = f->name; + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + g_string_append_printf(s, "0x%" PRIx64, ltt_event_get_long_unsigned(e,f)); + //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f)); + break; - case LTT_TYPE_STRING: - if(field_names) { - name = f->name; - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - g_string_append_printf(s, "\"%s\"", ltt_event_get_string(e,f)); - break; + case LTT_TYPE_STRING: + if(field_names) { + name = f->name; + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + g_string_append_printf(s, "\"%s\"", ltt_event_get_string(e,f)); + break; #if 0 - case LTT_ENUM: - { - GQuark value = ltt_enum_string_get(type, ltt_event_get_unsigned(e,f)); - if(field_names) { - name = ltt_field_name(f); - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - if(value) - g_string_append_printf(s, "%s", g_quark_to_string(value)); - else - g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f)); - } - break; + case LTT_ENUM: + { + GQuark value = ltt_enum_string_get(type, ltt_event_get_unsigned(e,f)); + if(field_names) { + name = ltt_field_name(f); + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + if(value) + g_string_append_printf(s, "%s", g_quark_to_string(value)); + else + g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f)); + } + break; - case LTT_ARRAY: - case LTT_SEQUENCE: - if(field_names) { - name = ltt_field_name(f); - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - // g_string_append_printf(s, "{ "); - //Insert header - g_string_append_printf(s, type->header);//tested, works fine. + case LTT_ARRAY: + case LTT_SEQUENCE: + if(field_names) { + name = ltt_field_name(f); + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + // g_string_append_printf(s, "{ "); + //Insert header + g_string_append_printf(s, type->header);//tested, works fine. - nb = ltt_event_field_element_number(e,f); - for(i = 0 ; i < nb ; i++) { - LttField *child = ltt_event_field_element_select(e,f,i); - lttv_print_field(e, child, s, field_names, i); + nb = ltt_event_field_element_number(e,f); + for(i = 0 ; i < nb ; i++) { + LttField *child = ltt_event_field_element_select(e,f,i); + lttv_print_field(e, child, s, field_names, i); if(iseparator); - } - //g_string_append_printf(s, " }"); - //Insert footer - g_string_append_printf(s, type->footer);//tested, works fine. - break; + g_string_append_printf(s,type->separator); + } + //g_string_append_printf(s, " }"); + //Insert footer + g_string_append_printf(s, type->footer);//tested, works fine. + break; - case LTT_STRUCT: - if(field_names) { - name = ltt_field_name(f); - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - // g_string_append_printf(s, "{ "); - //Insert header - g_string_append_printf(s, type->header); + case LTT_STRUCT: + if(field_names) { + name = ltt_field_name(f); + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + // g_string_append_printf(s, "{ "); + //Insert header + g_string_append_printf(s, type->header); - nb = ltt_type_member_number(type); - for(i = 0 ; i < nb ; i++) { - LttField *element; - element = ltt_field_member(f,i); - lttv_print_field(e, element, s, field_names, i); + nb = ltt_type_member_number(type); + for(i = 0 ; i < nb ; i++) { + LttField *element; + element = ltt_field_member(f,i); + lttv_print_field(e, element, s, field_names, i); if(i < nb-1) - g_string_append_printf(s,type->separator); - } - //g_string_append_printf(s, " }"); - //Insert footer - g_string_append_printf(s, type->footer); - break; + g_string_append_printf(s,type->separator); + } + //g_string_append_printf(s, " }"); + //Insert footer + g_string_append_printf(s, type->footer); + break; - case LTT_UNION: - if(field_names) { - name = ltt_field_name(f); - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - // g_string_append_printf(s, "{ "); - g_string_append_printf(s, type->header); + case LTT_UNION: + if(field_names) { + name = ltt_field_name(f); + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + // g_string_append_printf(s, "{ "); + g_string_append_printf(s, type->header); - nb = ltt_type_member_number(type); - for(i = 0 ; i < nb ; i++) { - LttField *element; - element = ltt_field_member(f,i); - lttv_print_field(e, element, s, field_names, i); + nb = ltt_type_member_number(type); + for(i = 0 ; i < nb ; i++) { + LttField *element; + element = ltt_field_member(f,i); + lttv_print_field(e, element, s, field_names, i); if(iseparator); - } - // g_string_append_printf(s, " }"); - g_string_append_printf(s, type->footer); - break; + g_string_append_printf(s, type->separator); + } + // g_string_append_printf(s, " }"); + g_string_append_printf(s, type->footer); + break; #endif - case LTT_TYPE_COMPACT: - g_error("compact type printing not implemented"); - break; - case LTT_TYPE_NONE: - break; - } + case LTT_TYPE_COMPACT: + g_error("compact type printing not implemented"); + break; + case LTT_TYPE_NONE: + break; + } } -void lttv_event_to_string(LttEvent *e, GString *s, - gboolean mandatory_fields, gboolean field_names, LttvTracefileState *tfs) +void lttv_event_to_string(LttEvent *e, GString *s, gboolean mandatory_fields, + gboolean field_names, LttvTracefileState *tfs) { - struct marker_field *field; - struct marker_info *info; + struct marker_field *field; + struct marker_info *info; + + LttTime time; - LttTime time; + guint cpu = tfs->cpu; + LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; + LttvProcessState *process = ts->running_process[cpu]; - guint cpu = tfs->cpu; - LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; - LttvProcessState *process = ts->running_process[cpu]; + s = g_string_set_size(s,0); - s = g_string_set_size(s,0); + info = marker_get_info_from_id(tfs->parent.tf->mdata, e->event_id); - info = marker_get_info_from_id(tfs->parent.tf->mdata, e->event_id); + if(mandatory_fields) { + time = ltt_event_time(e); + g_string_append_printf(s,"%s.%s: %ld.%09ld (%s/%s_%u)", + g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)), + g_quark_to_string(info->name), (long)time.tv_sec, time.tv_nsec, + g_quark_to_string( + ltt_trace_name(ltt_tracefile_get_trace(tfs->parent.tf))), + g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)), cpu); + /* Print the process id and the state/interrupt type of the process */ + g_string_append_printf(s,", %u, %u, %s, %s, %u, 0x%" PRIx64", %s", + process->pid, + process->tgid, + g_quark_to_string(process->name), + g_quark_to_string(process->brand), + process->ppid, + process->current_function, + g_quark_to_string(process->state->t)); + } - if(mandatory_fields) { - time = ltt_event_time(e); - g_string_append_printf(s,"%s.%s: %ld.%09ld (%s/%s_%u)", - g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)), - g_quark_to_string(info->name), (long)time.tv_sec, time.tv_nsec, - g_quark_to_string( - ltt_trace_name(ltt_tracefile_get_trace(tfs->parent.tf))), - g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)), cpu); - /* Print the process id and the state/interrupt type of the process */ - g_string_append_printf(s,", %u, %u, %s, %s, %u, 0x%" PRIx64", %s", - process->pid, - process->tgid, - g_quark_to_string(process->name), - g_quark_to_string(process->brand), - process->ppid, - process->current_function, - g_quark_to_string(process->state->t)); - } - - if(marker_get_num_fields(info) == 0) return; - g_string_append_printf(s, " "); - g_string_append_printf(s, "{ "); - for (field = marker_get_field(info, 0); - field != marker_get_field(info, marker_get_num_fields(info)); - field++) { - if(field != marker_get_field(info, 0)) - g_string_append_printf(s, ", "); - lttv_print_field(e, field, s, field_names, tfs); - } - g_string_append_printf(s, " }"); + if(marker_get_num_fields(info) == 0) return; + g_string_append_printf(s, " "); + g_string_append_printf(s, "{ "); + for (field = marker_get_field(info, 0); + field != marker_get_field(info, marker_get_num_fields(info)); + field++) { + if(field != marker_get_field(info, 0)) + g_string_append_printf(s, ", "); + lttv_print_field(e, field, s, field_names, tfs); + } + g_string_append_printf(s, " }"); } static void init() @@ -315,6 +315,6 @@ static void destroy() } LTTV_MODULE("print", "Print events", \ - "Produce a detailed text printout of events", \ - init, destroy) + "Produce a detailed text printout of events", \ + init, destroy) diff --git a/lttv/lttv/print.h b/lttv/lttv/print.h index 3615abc7..90402810 100644 --- a/lttv/lttv/print.h +++ b/lttv/lttv/print.h @@ -27,8 +27,8 @@ void lttv_print_field(LttEvent *e, struct marker_field *f, GString *s, - gboolean field_names, LttvTracefileState *tfs); + gboolean field_names, LttvTracefileState *tfs); -void lttv_event_to_string(LttEvent *e, GString *s, - gboolean mandatory_fields, gboolean field_names, LttvTracefileState *tfs); +void lttv_event_to_string(LttEvent *e, GString *s, gboolean mandatory_fields, + gboolean field_names, LttvTracefileState *tfs); diff --git a/lttv/lttv/state.c b/lttv/lttv/state.c index 25af4116..871df9bc 100644 --- a/lttv/lttv/state.c +++ b/lttv/lttv/state.c @@ -49,163 +49,163 @@ /* Channel Quarks */ GQuark - LTT_CHANNEL_FD_STATE, - LTT_CHANNEL_GLOBAL_STATE, - LTT_CHANNEL_IRQ_STATE, - LTT_CHANNEL_MODULE_STATE, - LTT_CHANNEL_NETIF_STATE, - LTT_CHANNEL_SOFTIRQ_STATE, - LTT_CHANNEL_SWAP_STATE, - LTT_CHANNEL_SYSCALL_STATE, - LTT_CHANNEL_TASK_STATE, - LTT_CHANNEL_VM_STATE, - LTT_CHANNEL_KPROBE_STATE, - LTT_CHANNEL_FS, - LTT_CHANNEL_KERNEL, - LTT_CHANNEL_MM, - LTT_CHANNEL_USERSPACE, - LTT_CHANNEL_BLOCK; + LTT_CHANNEL_FD_STATE, + LTT_CHANNEL_GLOBAL_STATE, + LTT_CHANNEL_IRQ_STATE, + LTT_CHANNEL_MODULE_STATE, + LTT_CHANNEL_NETIF_STATE, + LTT_CHANNEL_SOFTIRQ_STATE, + LTT_CHANNEL_SWAP_STATE, + LTT_CHANNEL_SYSCALL_STATE, + LTT_CHANNEL_TASK_STATE, + LTT_CHANNEL_VM_STATE, + LTT_CHANNEL_KPROBE_STATE, + LTT_CHANNEL_FS, + LTT_CHANNEL_KERNEL, + LTT_CHANNEL_MM, + LTT_CHANNEL_USERSPACE, + LTT_CHANNEL_BLOCK; /* Events Quarks */ GQuark - LTT_EVENT_SYSCALL_ENTRY, - LTT_EVENT_SYSCALL_EXIT, - LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY, - LTT_EVENT_PAGE_FAULT_NOSEM_EXIT, - LTT_EVENT_PAGE_FAULT_ENTRY, - LTT_EVENT_PAGE_FAULT_EXIT, - LTT_EVENT_TRAP_ENTRY, - LTT_EVENT_TRAP_EXIT, - LTT_EVENT_IRQ_ENTRY, - LTT_EVENT_IRQ_EXIT, - LTT_EVENT_SOFT_IRQ_RAISE, - LTT_EVENT_SOFT_IRQ_ENTRY, - LTT_EVENT_SOFT_IRQ_EXIT, - LTT_EVENT_SCHED_SCHEDULE, - LTT_EVENT_SCHED_TRY_WAKEUP, - LTT_EVENT_PROCESS_FORK, - LTT_EVENT_KTHREAD_CREATE, - LTT_EVENT_PROCESS_EXIT, - LTT_EVENT_PROCESS_FREE, - LTT_EVENT_EXEC, - LTT_EVENT_PROCESS_STATE, - LTT_EVENT_STATEDUMP_END, - LTT_EVENT_FUNCTION_ENTRY, - LTT_EVENT_FUNCTION_EXIT, - LTT_EVENT_THREAD_BRAND, - LTT_EVENT_REQUEST_ISSUE, - LTT_EVENT_REQUEST_COMPLETE, - LTT_EVENT_LIST_INTERRUPT, - LTT_EVENT_SYS_CALL_TABLE, - LTT_EVENT_SOFTIRQ_VEC, - LTT_EVENT_KPROBE_TABLE, - LTT_EVENT_KPROBE, - LTT_EVENT_OPEN, - LTT_EVENT_READ, - LTT_EVENT_POLL_EVENT; + LTT_EVENT_SYSCALL_ENTRY, + LTT_EVENT_SYSCALL_EXIT, + LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY, + LTT_EVENT_PAGE_FAULT_NOSEM_EXIT, + LTT_EVENT_PAGE_FAULT_ENTRY, + LTT_EVENT_PAGE_FAULT_EXIT, + LTT_EVENT_TRAP_ENTRY, + LTT_EVENT_TRAP_EXIT, + LTT_EVENT_IRQ_ENTRY, + LTT_EVENT_IRQ_EXIT, + LTT_EVENT_SOFT_IRQ_RAISE, + LTT_EVENT_SOFT_IRQ_ENTRY, + LTT_EVENT_SOFT_IRQ_EXIT, + LTT_EVENT_SCHED_SCHEDULE, + LTT_EVENT_SCHED_TRY_WAKEUP, + LTT_EVENT_PROCESS_FORK, + LTT_EVENT_KTHREAD_CREATE, + LTT_EVENT_PROCESS_EXIT, + LTT_EVENT_PROCESS_FREE, + LTT_EVENT_EXEC, + LTT_EVENT_PROCESS_STATE, + LTT_EVENT_STATEDUMP_END, + LTT_EVENT_FUNCTION_ENTRY, + LTT_EVENT_FUNCTION_EXIT, + LTT_EVENT_THREAD_BRAND, + LTT_EVENT_REQUEST_ISSUE, + LTT_EVENT_REQUEST_COMPLETE, + LTT_EVENT_LIST_INTERRUPT, + LTT_EVENT_SYS_CALL_TABLE, + LTT_EVENT_SOFTIRQ_VEC, + LTT_EVENT_KPROBE_TABLE, + LTT_EVENT_KPROBE, + LTT_EVENT_OPEN, + LTT_EVENT_READ, + LTT_EVENT_POLL_EVENT; /* Fields Quarks */ GQuark - LTT_FIELD_SYSCALL_ID, - LTT_FIELD_TRAP_ID, - LTT_FIELD_IRQ_ID, - LTT_FIELD_SOFT_IRQ_ID, - LTT_FIELD_PREV_PID, - LTT_FIELD_NEXT_PID, - LTT_FIELD_PREV_STATE, - LTT_FIELD_PARENT_PID, - LTT_FIELD_CHILD_PID, - LTT_FIELD_PID, - LTT_FIELD_TGID, - LTT_FIELD_CHILD_TGID, - LTT_FIELD_FILENAME, - LTT_FIELD_NAME, - LTT_FIELD_TYPE, - LTT_FIELD_MODE, - LTT_FIELD_SUBMODE, - LTT_FIELD_STATUS, - LTT_FIELD_THIS_FN, - LTT_FIELD_CALL_SITE, - LTT_FIELD_MINOR, - LTT_FIELD_MAJOR, - LTT_FIELD_OPERATION, - LTT_FIELD_ACTION, - LTT_FIELD_ID, - LTT_FIELD_ADDRESS, - LTT_FIELD_SYMBOL, - LTT_FIELD_IP, - LTT_FIELD_FD, - LTT_FIELD_STATE, - LTT_FIELD_CPU_ID; + LTT_FIELD_SYSCALL_ID, + LTT_FIELD_TRAP_ID, + LTT_FIELD_IRQ_ID, + LTT_FIELD_SOFT_IRQ_ID, + LTT_FIELD_PREV_PID, + LTT_FIELD_NEXT_PID, + LTT_FIELD_PREV_STATE, + LTT_FIELD_PARENT_PID, + LTT_FIELD_CHILD_PID, + LTT_FIELD_PID, + LTT_FIELD_TGID, + LTT_FIELD_CHILD_TGID, + LTT_FIELD_FILENAME, + LTT_FIELD_NAME, + LTT_FIELD_TYPE, + LTT_FIELD_MODE, + LTT_FIELD_SUBMODE, + LTT_FIELD_STATUS, + LTT_FIELD_THIS_FN, + LTT_FIELD_CALL_SITE, + LTT_FIELD_MINOR, + LTT_FIELD_MAJOR, + LTT_FIELD_OPERATION, + LTT_FIELD_ACTION, + LTT_FIELD_ID, + LTT_FIELD_ADDRESS, + LTT_FIELD_SYMBOL, + LTT_FIELD_IP, + LTT_FIELD_FD, + LTT_FIELD_STATE, + LTT_FIELD_CPU_ID; LttvExecutionMode - LTTV_STATE_MODE_UNKNOWN, - LTTV_STATE_USER_MODE, - LTTV_STATE_SYSCALL, - LTTV_STATE_TRAP, - LTTV_STATE_IRQ, - LTTV_STATE_SOFT_IRQ; + LTTV_STATE_MODE_UNKNOWN, + LTTV_STATE_USER_MODE, + LTTV_STATE_SYSCALL, + LTTV_STATE_TRAP, + LTTV_STATE_IRQ, + LTTV_STATE_SOFT_IRQ; LttvExecutionSubmode - LTTV_STATE_SUBMODE_UNKNOWN, - LTTV_STATE_SUBMODE_NONE; + LTTV_STATE_SUBMODE_UNKNOWN, + LTTV_STATE_SUBMODE_NONE; LttvProcessStatus - LTTV_STATE_UNNAMED, - LTTV_STATE_WAIT_FORK, - LTTV_STATE_WAIT_CPU, - LTTV_STATE_EXIT, - LTTV_STATE_ZOMBIE, - LTTV_STATE_WAIT, - LTTV_STATE_RUN, - LTTV_STATE_DEAD; + LTTV_STATE_UNNAMED, + LTTV_STATE_WAIT_FORK, + LTTV_STATE_WAIT_CPU, + LTTV_STATE_EXIT, + LTTV_STATE_ZOMBIE, + LTTV_STATE_WAIT, + LTTV_STATE_RUN, + LTTV_STATE_DEAD; GQuark - LTTV_STATE_UNBRANDED; + LTTV_STATE_UNBRANDED; LttvProcessType - LTTV_STATE_USER_THREAD, - LTTV_STATE_KERNEL_THREAD; + LTTV_STATE_USER_THREAD, + LTTV_STATE_KERNEL_THREAD; LttvCPUMode - LTTV_CPU_UNKNOWN, - LTTV_CPU_IDLE, - LTTV_CPU_BUSY, - LTTV_CPU_IRQ, - LTTV_CPU_SOFT_IRQ, - LTTV_CPU_TRAP; + LTTV_CPU_UNKNOWN, + LTTV_CPU_IDLE, + LTTV_CPU_BUSY, + LTTV_CPU_IRQ, + LTTV_CPU_SOFT_IRQ, + LTTV_CPU_TRAP; LttvIRQMode - LTTV_IRQ_UNKNOWN, - LTTV_IRQ_IDLE, - LTTV_IRQ_BUSY; + LTTV_IRQ_UNKNOWN, + LTTV_IRQ_IDLE, + LTTV_IRQ_BUSY; LttvBdevMode - LTTV_BDEV_UNKNOWN, - LTTV_BDEV_IDLE, - LTTV_BDEV_BUSY_READING, - LTTV_BDEV_BUSY_WRITING; + LTTV_BDEV_UNKNOWN, + LTTV_BDEV_IDLE, + LTTV_BDEV_BUSY_READING, + LTTV_BDEV_BUSY_WRITING; static GQuark - LTTV_STATE_TRACEFILES, - LTTV_STATE_PROCESSES, - LTTV_STATE_PROCESS, - LTTV_STATE_RUNNING_PROCESS, - LTTV_STATE_EVENT, - LTTV_STATE_SAVED_STATES, - LTTV_STATE_SAVED_STATES_TIME, - LTTV_STATE_TIME, - LTTV_STATE_HOOKS, - LTTV_STATE_NAME_TABLES, - LTTV_STATE_TRACE_STATE_USE_COUNT, - LTTV_STATE_RESOURCE_CPUS, - LTTV_STATE_RESOURCE_CPUS_COUNT, - LTTV_STATE_RESOURCE_IRQS, - LTTV_STATE_RESOURCE_SOFT_IRQS, - LTTV_STATE_RESOURCE_TRAPS, - LTTV_STATE_RESOURCE_BLKDEVS; + LTTV_STATE_TRACEFILES, + LTTV_STATE_PROCESSES, + LTTV_STATE_PROCESS, + LTTV_STATE_RUNNING_PROCESS, + LTTV_STATE_EVENT, + LTTV_STATE_SAVED_STATES, + LTTV_STATE_SAVED_STATES_TIME, + LTTV_STATE_TIME, + LTTV_STATE_HOOKS, + LTTV_STATE_NAME_TABLES, + LTTV_STATE_TRACE_STATE_USE_COUNT, + LTTV_STATE_RESOURCE_CPUS, + LTTV_STATE_RESOURCE_CPUS_COUNT, + LTTV_STATE_RESOURCE_IRQS, + LTTV_STATE_RESOURCE_SOFT_IRQS, + LTTV_STATE_RESOURCE_TRAPS, + LTTV_STATE_RESOURCE_BLKDEVS; static void create_max_time(LttvTraceState *tcs); @@ -224,7 +224,7 @@ static void free_saved_state(LttvTraceState *tcs); static void lttv_state_free_process_table(GHashTable *processes); static void lttv_trace_states_read_raw(LttvTraceState *tcs, FILE *fp, - GPtrArray *quarktable); + GPtrArray *quarktable); /* Resource function prototypes */ static LttvBdevState *get_hashed_bdevstate(LttvTraceState *ts, guint16 devcode); @@ -253,27 +253,27 @@ gboolean guint64_equal(gconstpointer a, gconstpointer b) void lttv_state_save(LttvTraceState *self, LttvAttribute *container) { - LTTV_TRACE_STATE_GET_CLASS(self)->state_save(self, container); + LTTV_TRACE_STATE_GET_CLASS(self)->state_save(self, container); } void lttv_state_restore(LttvTraceState *self, LttvAttribute *container) { - LTTV_TRACE_STATE_GET_CLASS(self)->state_restore(self, container); + LTTV_TRACE_STATE_GET_CLASS(self)->state_restore(self, container); } void lttv_state_state_saved_free(LttvTraceState *self, - LttvAttribute *container) + LttvAttribute *container) { - LTTV_TRACE_STATE_GET_CLASS(self)->state_saved_free(self, container); + LTTV_TRACE_STATE_GET_CLASS(self)->state_saved_free(self, container); } guint process_hash(gconstpointer key) { - guint pid = ((const LttvProcessState *)key)->pid; - return (pid>>8 ^ pid>>4 ^ pid>>2 ^ pid) ; + guint pid = ((const LttvProcessState *)key)->pid; + return (pid>>8 ^ pid>>4 ^ pid>>2 ^ pid) ; } @@ -281,28 +281,28 @@ guint process_hash(gconstpointer key) * the process_equal should compare different pid */ gboolean process_equal(gconstpointer a, gconstpointer b) { - const LttvProcessState *process_a, *process_b; - gboolean ret = TRUE; - - process_a = (const LttvProcessState *)a; - process_b = (const LttvProcessState *)b; - - if(likely(process_a->pid != process_b->pid)) ret = FALSE; - else if(likely(process_a->pid == 0 && - process_a->cpu != process_b->cpu)) ret = FALSE; + const LttvProcessState *process_a, *process_b; + gboolean ret = TRUE; + + process_a = (const LttvProcessState *)a; + process_b = (const LttvProcessState *)b; - return ret; + if(likely(process_a->pid != process_b->pid)) ret = FALSE; + else if(likely(process_a->pid == 0 && + process_a->cpu != process_b->cpu)) ret = FALSE; + + return ret; } static void delete_usertrace(gpointer key, gpointer value, gpointer user_data) { - g_tree_destroy((GTree*)value); + g_tree_destroy((GTree*)value); } static void lttv_state_free_usertraces(GHashTable *usertraces) { - g_hash_table_foreach(usertraces, delete_usertrace, NULL); - g_hash_table_destroy(usertraces); + g_hash_table_foreach(usertraces, delete_usertrace, NULL); + g_hash_table_destroy(usertraces); } gboolean rettrue(gpointer key, gpointer value, gpointer user_data) @@ -312,740 +312,734 @@ gboolean rettrue(gpointer key, gpointer value, gpointer user_data) static guint check_expand(nb, id) { - if(likely(nb > id)) - return nb; - else - return max(id + 1, nb * 2); + if(likely(nb > id)) + return nb; + else + return max(id + 1, nb * 2); } static void expand_name_table(LttvTraceState *ts, GQuark **table, - guint nb, guint new_nb) + guint nb, guint new_nb) { - /* Expand an incomplete table */ - GQuark *old_table = *table; - *table = g_new(GQuark, new_nb); - memcpy(*table, old_table, nb * sizeof(GQuark)); - g_free(old_table); + /* Expand an incomplete table */ + GQuark *old_table = *table; + *table = g_new(GQuark, new_nb); + memcpy(*table, old_table, nb * sizeof(GQuark)); + g_free(old_table); } static void fill_name_table(LttvTraceState *ts, GQuark *table, guint nb, - guint new_nb, const char *def_string) + guint new_nb, const char *def_string) { - guint i; - GString *fe_name = g_string_new(""); - for(i = nb; i < new_nb; i++) { - g_string_printf(fe_name, "%s %d", def_string, i); - table[i] = g_quark_from_string(fe_name->str); - } - g_string_free(fe_name, TRUE); + guint i; + GString *fe_name = g_string_new(""); + for(i = nb; i < new_nb; i++) { + g_string_printf(fe_name, "%s %d", def_string, i); + table[i] = g_quark_from_string(fe_name->str); + } + g_string_free(fe_name, TRUE); } static void expand_syscall_table(LttvTraceState *ts, int id) { - LttvNameTables *nt = ts->name_tables; - guint new_nb; + LttvNameTables *nt = ts->name_tables; + guint new_nb; - new_nb = check_expand(nt->nb_syscalls, id); - if(likely(new_nb == nt->nb_syscalls)) - return; - expand_name_table(ts, &nt->syscall_names, nt->nb_syscalls, new_nb); - fill_name_table(ts, nt->syscall_names, nt->nb_syscalls, new_nb, "syscall"); - /* Update the table size */ - nt->nb_syscalls = new_nb; + new_nb = check_expand(nt->nb_syscalls, id); + if(likely(new_nb == nt->nb_syscalls)) + return; + expand_name_table(ts, &nt->syscall_names, nt->nb_syscalls, new_nb); + fill_name_table(ts, nt->syscall_names, nt->nb_syscalls, new_nb, "syscall"); + /* Update the table size */ + nt->nb_syscalls = new_nb; } static void expand_kprobe_table(LttvTraceState *ts, guint64 ip, char *symbol) { - LttvNameTables *nt = ts->name_tables; + LttvNameTables *nt = ts->name_tables; #if (__WORDSIZE == 32) - guint64 *ip_ptr = g_new(guint64, 1); - g_hash_table_insert(nt->kprobe_hash, ip_ptr, - (gpointer)(glong)g_quark_from_string(symbol)); + guint64 *ip_ptr = g_new(guint64, 1); + g_hash_table_insert(nt->kprobe_hash, ip_ptr, + (gpointer)(glong)g_quark_from_string(symbol)); #else - g_hash_table_insert(nt->kprobe_hash, (gpointer)ip, - (gpointer)(glong)g_quark_from_string(symbol)); + g_hash_table_insert(nt->kprobe_hash, (gpointer)ip, + (gpointer)(glong)g_quark_from_string(symbol)); #endif } static void expand_trap_table(LttvTraceState *ts, int id) { - LttvNameTables *nt = ts->name_tables; - LttvTrapState *old_table; - guint new_nb, i; + LttvNameTables *nt = ts->name_tables; + LttvTrapState *old_table; + guint new_nb, i; - new_nb = check_expand(nt->nb_traps, id); - if(likely(new_nb == nt->nb_traps)) - return; + new_nb = check_expand(nt->nb_traps, id); + if(likely(new_nb == nt->nb_traps)) + return; - expand_name_table(ts, &nt->trap_names, nt->nb_traps, new_nb); - fill_name_table(ts, nt->trap_names, nt->nb_traps, new_nb, "trap"); + expand_name_table(ts, &nt->trap_names, nt->nb_traps, new_nb); + fill_name_table(ts, nt->trap_names, nt->nb_traps, new_nb, "trap"); - old_table = ts->trap_states; - ts->trap_states = g_new(LttvTrapState, new_nb); - memcpy(ts->trap_states, old_table, nt->nb_traps * sizeof(LttvTrapState)); - g_free(old_table); - for(i = nt->nb_traps; i < new_nb; i++) - ts->trap_states[i].running = 0; + old_table = ts->trap_states; + ts->trap_states = g_new(LttvTrapState, new_nb); + memcpy(ts->trap_states, old_table, nt->nb_traps * sizeof(LttvTrapState)); + g_free(old_table); + for(i = nt->nb_traps; i < new_nb; i++) + ts->trap_states[i].running = 0; - /* Update the table size */ - nt->nb_traps = new_nb; + /* Update the table size */ + nt->nb_traps = new_nb; } static void expand_irq_table(LttvTraceState *ts, int id) { - LttvNameTables *nt = ts->name_tables; - LttvIRQState *old_table; - guint new_nb, i; + LttvNameTables *nt = ts->name_tables; + LttvIRQState *old_table; + guint new_nb, i; - new_nb = check_expand(nt->nb_irqs, id); - if(likely(new_nb == nt->nb_irqs)) - return; + new_nb = check_expand(nt->nb_irqs, id); + if(likely(new_nb == nt->nb_irqs)) + return; - expand_name_table(ts, &nt->irq_names, nt->nb_irqs, new_nb); - fill_name_table(ts, nt->irq_names, nt->nb_irqs, new_nb, "irq"); + expand_name_table(ts, &nt->irq_names, nt->nb_irqs, new_nb); + fill_name_table(ts, nt->irq_names, nt->nb_irqs, new_nb, "irq"); - old_table = ts->irq_states; - ts->irq_states = g_new(LttvIRQState, new_nb); - memcpy(ts->irq_states, old_table, nt->nb_irqs * sizeof(LttvIRQState)); - g_free(old_table); - for(i = nt->nb_irqs; i < new_nb; i++) - ts->irq_states[i].mode_stack = - g_array_new(FALSE, FALSE, sizeof(LttvIRQMode)); + old_table = ts->irq_states; + ts->irq_states = g_new(LttvIRQState, new_nb); + memcpy(ts->irq_states, old_table, nt->nb_irqs * sizeof(LttvIRQState)); + g_free(old_table); + for(i = nt->nb_irqs; i < new_nb; i++) + ts->irq_states[i].mode_stack = + g_array_new(FALSE, FALSE, sizeof(LttvIRQMode)); - /* Update the table size */ - nt->nb_irqs = new_nb; + /* Update the table size */ + nt->nb_irqs = new_nb; } static void expand_soft_irq_table(LttvTraceState *ts, int id) { - LttvNameTables *nt = ts->name_tables; - LttvSoftIRQState *old_table; - guint new_nb, i; - - new_nb = check_expand(nt->nb_soft_irqs, id); - if(likely(new_nb == nt->nb_soft_irqs)) - return; - - expand_name_table(ts, &nt->soft_irq_names, nt->nb_soft_irqs, new_nb); - fill_name_table(ts, nt->soft_irq_names, nt->nb_soft_irqs, new_nb, "softirq"); - - old_table = ts->soft_irq_states; - ts->soft_irq_states = g_new(LttvSoftIRQState, new_nb); - memcpy(ts->soft_irq_states, old_table, - nt->nb_soft_irqs * sizeof(LttvSoftIRQState)); - g_free(old_table); - for(i = nt->nb_soft_irqs; i < new_nb; i++) - ts->soft_irq_states[i].running = 0; - - /* Update the table size */ - nt->nb_soft_irqs = new_nb; -} - -static void -restore_init_state(LttvTraceState *self) -{ - guint i, nb_cpus, nb_irqs, nb_soft_irqs, nb_traps; - - //LttvTracefileState *tfcs; - - LttTime start_time, end_time; - - /* Free the process tables */ - if(self->processes != NULL) lttv_state_free_process_table(self->processes); - if(self->usertraces != NULL) lttv_state_free_usertraces(self->usertraces); - self->processes = g_hash_table_new(process_hash, process_equal); - self->usertraces = g_hash_table_new(g_direct_hash, g_direct_equal); - self->nb_event = 0; - - /* Seek time to beginning */ - // Mathieu : fix : don't seek traceset here : causes inconsistency in seek - // closest. It's the tracecontext job to seek the trace to the beginning - // anyway : the init state might be used at the middle of the trace as well... - //g_tree_destroy(self->parent.ts_context->pqueue); - //self->parent.ts_context->pqueue = g_tree_new(compare_tracefile); - - ltt_trace_time_span_get(self->parent.t, &start_time, &end_time); - - //lttv_process_trace_seek_time(&self->parent, ltt_time_zero); - - nb_cpus = ltt_trace_get_num_cpu(self->parent.t); - nb_irqs = self->name_tables->nb_irqs; - nb_soft_irqs = self->name_tables->nb_soft_irqs; - nb_traps = self->name_tables->nb_traps; - - /* Put the per cpu running_process to beginning state : process 0. */ - for(i=0; i< nb_cpus; i++) { - LttvExecutionState *es; - self->running_process[i] = lttv_state_create_process(self, NULL, i, 0, 0, - LTTV_STATE_UNNAMED, &start_time); - /* We are not sure is it's a kernel thread or normal thread, put the - * bottom stack state to unknown */ - self->running_process[i]->execution_stack = - g_array_set_size(self->running_process[i]->execution_stack, 1); - es = self->running_process[i]->state = - &g_array_index(self->running_process[i]->execution_stack, - LttvExecutionState, 0); - es->t = LTTV_STATE_MODE_UNKNOWN; - es->s = LTTV_STATE_UNNAMED; - - //self->running_process[i]->state->s = LTTV_STATE_RUN; - self->running_process[i]->cpu = i; - - /* reset cpu states */ - if(self->cpu_states[i].mode_stack->len > 0) { - g_array_remove_range(self->cpu_states[i].mode_stack, 0, self->cpu_states[i].mode_stack->len); - if(self->cpu_states[i].irq_stack->len) - g_array_remove_range(self->cpu_states[i].irq_stack, 0, self->cpu_states[i].irq_stack->len); - if(self->cpu_states[i].softirq_stack->len) - g_array_remove_range(self->cpu_states[i].softirq_stack, 0, self->cpu_states[i].softirq_stack->len); - if(self->cpu_states[i].trap_stack->len) - g_array_remove_range(self->cpu_states[i].trap_stack, 0, self->cpu_states[i].trap_stack->len); - } - } - - /* reset irq states */ - for(i=0; iirq_states[i].mode_stack->len > 0) - g_array_remove_range(self->irq_states[i].mode_stack, 0, self->irq_states[i].mode_stack->len); - } - - /* reset softirq states */ - for(i=0; isoft_irq_states[i].pending = 0; - self->soft_irq_states[i].running = 0; - } - - /* reset trap states */ - for(i=0; itrap_states[i].running = 0; - } - - /* reset bdev states */ - g_hash_table_foreach(self->bdev_states, bdevstate_free_cb, NULL); - //g_hash_table_steal_all(self->bdev_states); - g_hash_table_foreach_steal(self->bdev_states, rettrue, NULL); - + LttvNameTables *nt = ts->name_tables; + LttvSoftIRQState *old_table; + guint new_nb, i; + + new_nb = check_expand(nt->nb_soft_irqs, id); + if(likely(new_nb == nt->nb_soft_irqs)) + return; + + expand_name_table(ts, &nt->soft_irq_names, nt->nb_soft_irqs, new_nb); + fill_name_table(ts, nt->soft_irq_names, nt->nb_soft_irqs, new_nb, "softirq"); + + old_table = ts->soft_irq_states; + ts->soft_irq_states = g_new(LttvSoftIRQState, new_nb); + memcpy(ts->soft_irq_states, old_table, + nt->nb_soft_irqs * sizeof(LttvSoftIRQState)); + g_free(old_table); + for(i = nt->nb_soft_irqs; i < new_nb; i++) + ts->soft_irq_states[i].running = 0; + + /* Update the table size */ + nt->nb_soft_irqs = new_nb; +} + +static void restore_init_state(LttvTraceState *self) +{ + guint i, nb_cpus, nb_irqs, nb_soft_irqs, nb_traps; + + //LttvTracefileState *tfcs; + + LttTime start_time, end_time; + + /* Free the process tables */ + if(self->processes != NULL) lttv_state_free_process_table(self->processes); + if(self->usertraces != NULL) lttv_state_free_usertraces(self->usertraces); + self->processes = g_hash_table_new(process_hash, process_equal); + self->usertraces = g_hash_table_new(g_direct_hash, g_direct_equal); + self->nb_event = 0; + + /* Seek time to beginning */ + // Mathieu : fix : don't seek traceset here : causes inconsistency in seek + // closest. It's the tracecontext job to seek the trace to the beginning + // anyway : the init state might be used at the middle of the trace as well... + //g_tree_destroy(self->parent.ts_context->pqueue); + //self->parent.ts_context->pqueue = g_tree_new(compare_tracefile); + + ltt_trace_time_span_get(self->parent.t, &start_time, &end_time); + + //lttv_process_trace_seek_time(&self->parent, ltt_time_zero); + + nb_cpus = ltt_trace_get_num_cpu(self->parent.t); + nb_irqs = self->name_tables->nb_irqs; + nb_soft_irqs = self->name_tables->nb_soft_irqs; + nb_traps = self->name_tables->nb_traps; + + /* Put the per cpu running_process to beginning state : process 0. */ + for(i=0; i< nb_cpus; i++) { + LttvExecutionState *es; + self->running_process[i] = lttv_state_create_process(self, NULL, i, 0, 0, + LTTV_STATE_UNNAMED, &start_time); + /* We are not sure is it's a kernel thread or normal thread, put the + * bottom stack state to unknown */ + self->running_process[i]->execution_stack = + g_array_set_size(self->running_process[i]->execution_stack, 1); + es = self->running_process[i]->state = + &g_array_index(self->running_process[i]->execution_stack, + LttvExecutionState, 0); + es->t = LTTV_STATE_MODE_UNKNOWN; + es->s = LTTV_STATE_UNNAMED; + + //self->running_process[i]->state->s = LTTV_STATE_RUN; + self->running_process[i]->cpu = i; + + /* reset cpu states */ + if(self->cpu_states[i].mode_stack->len > 0) { + g_array_remove_range(self->cpu_states[i].mode_stack, 0, + self->cpu_states[i].mode_stack->len); + if(self->cpu_states[i].irq_stack->len) + g_array_remove_range(self->cpu_states[i].irq_stack, 0, + self->cpu_states[i].irq_stack->len); + if(self->cpu_states[i].softirq_stack->len) + g_array_remove_range(self->cpu_states[i].softirq_stack, 0, + self->cpu_states[i].softirq_stack->len); + if(self->cpu_states[i].trap_stack->len) + g_array_remove_range(self->cpu_states[i].trap_stack, 0, + self->cpu_states[i].trap_stack->len); + } + } + + /* reset irq states */ + for(i=0; iirq_states[i].mode_stack->len > 0) + g_array_remove_range(self->irq_states[i].mode_stack, 0, + self->irq_states[i].mode_stack->len); + } + + /* reset softirq states */ + for(i=0; isoft_irq_states[i].pending = 0; + self->soft_irq_states[i].running = 0; + } + + /* reset trap states */ + for(i=0; itrap_states[i].running = 0; + } + + /* reset bdev states */ + g_hash_table_foreach(self->bdev_states, bdevstate_free_cb, NULL); + //g_hash_table_steal_all(self->bdev_states); + g_hash_table_foreach_steal(self->bdev_states, rettrue, NULL); + #if 0 - nb_tracefile = self->parent.tracefiles->len; - - for(i = 0 ; i < nb_tracefile ; i++) { - tfcs = - LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, - LttvTracefileContext*, i)); - ltt_trace_time_span_get(self->parent.t, &tfcs->parent.timestamp, NULL); -// tfcs->saved_position = 0; - tfcs->process = lttv_state_create_process(tfcs, NULL,0); - tfcs->process->state->s = LTTV_STATE_RUN; - tfcs->process->last_cpu = tfcs->cpu_name; - tfcs->process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfcs)->tf); - } + nb_tracefile = self->parent.tracefiles->len; + + for(i = 0 ; i < nb_tracefile ; i++) { + tfcs = + LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, + LttvTracefileContext*, i)); + ltt_trace_time_span_get(self->parent.t, &tfcs->parent.timestamp, NULL); +// tfcs->saved_position = 0; + tfcs->process = lttv_state_create_process(tfcs, NULL,0); + tfcs->process->state->s = LTTV_STATE_RUN; + tfcs->process->last_cpu = tfcs->cpu_name; + tfcs->process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfcs)->tf); + } #endif //0 } //static LttTime time_zero = {0,0}; static gint compare_usertraces(gconstpointer a, gconstpointer b, - gpointer user_data) + gpointer user_data) { - const LttTime *t1 = (const LttTime *)a; - const LttTime *t2 = (const LttTime *)b; + const LttTime *t1 = (const LttTime *)a; + const LttTime *t2 = (const LttTime *)b; - return ltt_time_compare(*t1, *t2); + return ltt_time_compare(*t1, *t2); } static void free_usertrace_key(gpointer data) { - g_free(data); + g_free(data); } #define MAX_STRING_LEN 4096 -static void -state_load_saved_states(LttvTraceState *tcs) -{ - FILE *fp; - GPtrArray *quarktable; - const char *trace_path; - char path[PATH_MAX]; - guint count; - guint i; - tcs->has_precomputed_states = FALSE; - GQuark q; - gchar *string; - gint hdr; - gchar buf[MAX_STRING_LEN]; - guint len; - - trace_path = g_quark_to_string(ltt_trace_name(tcs->parent.t)); - strncpy(path, trace_path, PATH_MAX-1); - count = strnlen(trace_path, PATH_MAX-1); - // quarktable : open, test - strncat(path, "/precomputed/quarktable", PATH_MAX-count-1); - fp = fopen(path, "r"); - if(!fp) return; - quarktable = g_ptr_array_sized_new(4096); - - /* Index 0 is null */ - hdr = fgetc(fp); - if(hdr == EOF) return; - g_assert(hdr == HDR_QUARKS); - q = 1; - do { - hdr = fgetc(fp); - if(hdr == EOF) break; - g_assert(hdr == HDR_QUARK); - g_ptr_array_set_size(quarktable, q+1); - i=0; - while(1) { - fread(&buf[i], sizeof(gchar), 1, fp); - if(buf[i] == '\0' || feof(fp)) break; - i++; - } - len = strnlen(buf, MAX_STRING_LEN-1); - g_ptr_array_index (quarktable, q) = g_new(gchar, len+1); - strncpy(g_ptr_array_index (quarktable, q), buf, len+1); - q++; - } while(1); - - fclose(fp); - - // saved_states : open, test - strncpy(path, trace_path, PATH_MAX-1); - count = strnlen(trace_path, PATH_MAX-1); - strncat(path, "/precomputed/states", PATH_MAX-count-1); - fp = fopen(path, "r"); - if(!fp) return; - - hdr = fgetc(fp); - if(hdr != HDR_TRACE) goto end; - - lttv_trace_states_read_raw(tcs, fp, quarktable); - - tcs->has_precomputed_states = TRUE; +static void state_load_saved_states(LttvTraceState *tcs) +{ + FILE *fp; + GPtrArray *quarktable; + const char *trace_path; + char path[PATH_MAX]; + guint count; + guint i; + tcs->has_precomputed_states = FALSE; + GQuark q; + gchar *string; + gint hdr; + gchar buf[MAX_STRING_LEN]; + guint len; + + trace_path = g_quark_to_string(ltt_trace_name(tcs->parent.t)); + strncpy(path, trace_path, PATH_MAX-1); + count = strnlen(trace_path, PATH_MAX-1); + // quarktable : open, test + strncat(path, "/precomputed/quarktable", PATH_MAX-count-1); + fp = fopen(path, "r"); + if(!fp) return; + quarktable = g_ptr_array_sized_new(4096); + + /* Index 0 is null */ + hdr = fgetc(fp); + if(hdr == EOF) return; + g_assert(hdr == HDR_QUARKS); + q = 1; + do { + hdr = fgetc(fp); + if(hdr == EOF) break; + g_assert(hdr == HDR_QUARK); + g_ptr_array_set_size(quarktable, q+1); + i=0; + while(1) { + fread(&buf[i], sizeof(gchar), 1, fp); + if(buf[i] == '\0' || feof(fp)) break; + i++; + } + len = strnlen(buf, MAX_STRING_LEN-1); + g_ptr_array_index (quarktable, q) = g_new(gchar, len+1); + strncpy(g_ptr_array_index (quarktable, q), buf, len+1); + q++; + } while(1); + + fclose(fp); + + // saved_states : open, test + strncpy(path, trace_path, PATH_MAX-1); + count = strnlen(trace_path, PATH_MAX-1); + strncat(path, "/precomputed/states", PATH_MAX-count-1); + fp = fopen(path, "r"); + if(!fp) return; + + hdr = fgetc(fp); + if(hdr != HDR_TRACE) goto end; + + lttv_trace_states_read_raw(tcs, fp, quarktable); + + tcs->has_precomputed_states = TRUE; end: - fclose(fp); - - /* Free the quarktable */ - for(i=0; ilen; i++) { - string = g_ptr_array_index (quarktable, i); - g_free(string); - } - g_ptr_array_free(quarktable, TRUE); - return; -} - -static void -init(LttvTracesetState *self, LttvTraceset *ts) -{ - guint i, j, nb_trace, nb_tracefile, nb_cpu; - guint64 nb_irq; - - LttvTraceContext *tc; - - LttvTraceState *tcs; - - LttvTracefileState *tfcs; - - LttvAttributeValue v; - - LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE))-> - init((LttvTracesetContext *)self, ts); - - nb_trace = lttv_traceset_number(ts); - for(i = 0 ; i < nb_trace ; i++) { - tc = self->parent.traces[i]; - tcs = LTTV_TRACE_STATE(tc); - tcs->save_interval = LTTV_STATE_SAVE_INTERVAL; - lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_TRACE_STATE_USE_COUNT, - LTTV_UINT, &v); - (*v.v_uint)++; - - if(*(v.v_uint) == 1) { - create_name_tables(tcs); - create_max_time(tcs); - } - get_name_tables(tcs); - get_max_time(tcs); - - nb_tracefile = tc->tracefiles->len; - nb_cpu = ltt_trace_get_num_cpu(tc->t); - nb_irq = tcs->name_tables->nb_irqs; - tcs->processes = NULL; - tcs->usertraces = NULL; - tcs->running_process = g_new(LttvProcessState*, nb_cpu); - - /* init cpu resource stuff */ - tcs->cpu_states = g_new(LttvCPUState, nb_cpu); - for(j = 0; jcpu_states[j].mode_stack = g_array_new(FALSE, FALSE, sizeof(LttvCPUMode)); - tcs->cpu_states[j].irq_stack = g_array_new(FALSE, FALSE, sizeof(gint)); - tcs->cpu_states[j].softirq_stack = g_array_new(FALSE, FALSE, sizeof(gint)); - tcs->cpu_states[j].trap_stack = g_array_new(FALSE, FALSE, sizeof(gint)); - g_assert(tcs->cpu_states[j].mode_stack != NULL); - } - - /* init irq resource stuff */ - tcs->irq_states = g_new(LttvIRQState, nb_irq); - for(j = 0; jirq_states[j].mode_stack = g_array_new(FALSE, FALSE, sizeof(LttvIRQMode)); - g_assert(tcs->irq_states[j].mode_stack != NULL); - } + fclose(fp); - /* init soft irq stuff */ - /* the kernel has a statically fixed max of 32 softirqs */ - tcs->soft_irq_states = g_new(LttvSoftIRQState, tcs->name_tables->nb_soft_irqs); - - /* init trap stuff */ - tcs->trap_states = g_new(LttvTrapState, tcs->name_tables->nb_traps); + /* Free the quarktable */ + for(i=0; ilen; i++) { + string = g_ptr_array_index (quarktable, i); + g_free(string); + } + g_ptr_array_free(quarktable, TRUE); + return; +} + +static void init(LttvTracesetState *self, LttvTraceset *ts) +{ + guint i, j, nb_trace, nb_tracefile, nb_cpu; + guint64 nb_irq; + + LttvTraceContext *tc; + + LttvTraceState *tcs; + + LttvTracefileState *tfcs; + + LttvAttributeValue v; + + LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE))-> + init((LttvTracesetContext *)self, ts); + + nb_trace = lttv_traceset_number(ts); + for(i = 0 ; i < nb_trace ; i++) { + tc = self->parent.traces[i]; + tcs = LTTV_TRACE_STATE(tc); + tcs->save_interval = LTTV_STATE_SAVE_INTERVAL; + lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_TRACE_STATE_USE_COUNT, + LTTV_UINT, &v); + (*v.v_uint)++; + + if(*(v.v_uint) == 1) { + create_name_tables(tcs); + create_max_time(tcs); + } + get_name_tables(tcs); + get_max_time(tcs); + + nb_tracefile = tc->tracefiles->len; + nb_cpu = ltt_trace_get_num_cpu(tc->t); + nb_irq = tcs->name_tables->nb_irqs; + tcs->processes = NULL; + tcs->usertraces = NULL; + tcs->running_process = g_new(LttvProcessState*, nb_cpu); + + /* init cpu resource stuff */ + tcs->cpu_states = g_new(LttvCPUState, nb_cpu); + for(j = 0; jcpu_states[j].mode_stack = g_array_new(FALSE, FALSE, sizeof(LttvCPUMode)); + tcs->cpu_states[j].irq_stack = g_array_new(FALSE, FALSE, sizeof(gint)); + tcs->cpu_states[j].softirq_stack = g_array_new(FALSE, FALSE, sizeof(gint)); + tcs->cpu_states[j].trap_stack = g_array_new(FALSE, FALSE, sizeof(gint)); + g_assert(tcs->cpu_states[j].mode_stack != NULL); + } + + /* init irq resource stuff */ + tcs->irq_states = g_new(LttvIRQState, nb_irq); + for(j = 0; jirq_states[j].mode_stack = g_array_new(FALSE, FALSE, sizeof(LttvIRQMode)); + g_assert(tcs->irq_states[j].mode_stack != NULL); + } + + /* init soft irq stuff */ + /* the kernel has a statically fixed max of 32 softirqs */ + tcs->soft_irq_states = g_new(LttvSoftIRQState, tcs->name_tables->nb_soft_irqs); + + /* init trap stuff */ + tcs->trap_states = g_new(LttvTrapState, tcs->name_tables->nb_traps); + + /* init bdev resource stuff */ + tcs->bdev_states = g_hash_table_new(g_int_hash, g_int_equal); + + restore_init_state(tcs); + for(j = 0 ; j < nb_tracefile ; j++) { + tfcs = + LTTV_TRACEFILE_STATE(g_array_index(tc->tracefiles, + LttvTracefileContext*, j)); + tfcs->tracefile_name = ltt_tracefile_name(tfcs->parent.tf); + tfcs->cpu = ltt_tracefile_cpu(tfcs->parent.tf); + tfcs->cpu_state = &(tcs->cpu_states[tfcs->cpu]); + if(ltt_tracefile_tid(tfcs->parent.tf) != 0) { + /* It's a Usertrace */ + guint tid = ltt_tracefile_tid(tfcs->parent.tf); + GTree *usertrace_tree = (GTree*)g_hash_table_lookup(tcs->usertraces, + GUINT_TO_POINTER(tid)); + if(!usertrace_tree) { + usertrace_tree = g_tree_new_full(compare_usertraces, + NULL, free_usertrace_key, NULL); + g_hash_table_insert(tcs->usertraces, + GUINT_TO_POINTER(tid), usertrace_tree); + } + LttTime *timestamp = g_new(LttTime, 1); + *timestamp = ltt_interpolate_time_from_tsc(tfcs->parent.tf, + ltt_tracefile_creation(tfcs->parent.tf)); + g_tree_insert(usertrace_tree, timestamp, tfcs); + } + } + + /* See if the trace has saved states */ + state_load_saved_states(tcs); + } +} - /* init bdev resource stuff */ - tcs->bdev_states = g_hash_table_new(g_int_hash, g_int_equal); +static void fini(LttvTracesetState *self) +{ + guint i, nb_trace; - restore_init_state(tcs); - for(j = 0 ; j < nb_tracefile ; j++) { - tfcs = - LTTV_TRACEFILE_STATE(g_array_index(tc->tracefiles, - LttvTracefileContext*, j)); - tfcs->tracefile_name = ltt_tracefile_name(tfcs->parent.tf); - tfcs->cpu = ltt_tracefile_cpu(tfcs->parent.tf); - tfcs->cpu_state = &(tcs->cpu_states[tfcs->cpu]); - if(ltt_tracefile_tid(tfcs->parent.tf) != 0) { - /* It's a Usertrace */ - guint tid = ltt_tracefile_tid(tfcs->parent.tf); - GTree *usertrace_tree = (GTree*)g_hash_table_lookup(tcs->usertraces, - GUINT_TO_POINTER(tid)); - if(!usertrace_tree) { - usertrace_tree = g_tree_new_full(compare_usertraces, - NULL, free_usertrace_key, NULL); - g_hash_table_insert(tcs->usertraces, - GUINT_TO_POINTER(tid), usertrace_tree); - } - LttTime *timestamp = g_new(LttTime, 1); - *timestamp = ltt_interpolate_time_from_tsc(tfcs->parent.tf, - ltt_tracefile_creation(tfcs->parent.tf)); - g_tree_insert(usertrace_tree, timestamp, tfcs); - } - } + LttvTraceState *tcs; - /* See if the trace has saved states */ - state_load_saved_states(tcs); - } -} + //LttvTracefileState *tfcs; -static void -fini(LttvTracesetState *self) -{ - guint i, nb_trace; + LttvAttributeValue v; - LttvTraceState *tcs; + nb_trace = lttv_traceset_number(LTTV_TRACESET_CONTEXT(self)->ts); + for(i = 0 ; i < nb_trace ; i++) { + tcs = (LttvTraceState *)(LTTV_TRACESET_CONTEXT(self)->traces[i]); + lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_TRACE_STATE_USE_COUNT, + LTTV_UINT, &v); - //LttvTracefileState *tfcs; + g_assert(*(v.v_uint) != 0); + (*v.v_uint)--; - LttvAttributeValue v; - - nb_trace = lttv_traceset_number(LTTV_TRACESET_CONTEXT(self)->ts); - for(i = 0 ; i < nb_trace ; i++) { - tcs = (LttvTraceState *)(LTTV_TRACESET_CONTEXT(self)->traces[i]); - lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_TRACE_STATE_USE_COUNT, - LTTV_UINT, &v); - - g_assert(*(v.v_uint) != 0); - (*v.v_uint)--; - - if(*(v.v_uint) == 0) { - free_name_tables(tcs); - free_max_time(tcs); - free_saved_state(tcs); - } - g_free(tcs->running_process); - tcs->running_process = NULL; - lttv_state_free_process_table(tcs->processes); - lttv_state_free_usertraces(tcs->usertraces); - tcs->processes = NULL; - tcs->usertraces = NULL; - } - LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE))-> - fini((LttvTracesetContext *)self); + if(*(v.v_uint) == 0) { + free_name_tables(tcs); + free_max_time(tcs); + free_saved_state(tcs); + } + g_free(tcs->running_process); + tcs->running_process = NULL; + lttv_state_free_process_table(tcs->processes); + lttv_state_free_usertraces(tcs->usertraces); + tcs->processes = NULL; + tcs->usertraces = NULL; + } + LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE))-> + fini((LttvTracesetContext *)self); } -static LttvTracesetContext * -new_traceset_context(LttvTracesetContext *self) +static LttvTracesetContext *new_traceset_context(LttvTracesetContext *self) { - return LTTV_TRACESET_CONTEXT(g_object_new(LTTV_TRACESET_STATE_TYPE, NULL)); + return LTTV_TRACESET_CONTEXT(g_object_new(LTTV_TRACESET_STATE_TYPE, NULL)); } -static LttvTraceContext * -new_trace_context(LttvTracesetContext *self) +static LttvTraceContext *new_trace_context(LttvTracesetContext *self) { - return LTTV_TRACE_CONTEXT(g_object_new(LTTV_TRACE_STATE_TYPE, NULL)); + return LTTV_TRACE_CONTEXT(g_object_new(LTTV_TRACE_STATE_TYPE, NULL)); } -static LttvTracefileContext * -new_tracefile_context(LttvTracesetContext *self) +static LttvTracefileContext *new_tracefile_context(LttvTracesetContext *self) { - return LTTV_TRACEFILE_CONTEXT(g_object_new(LTTV_TRACEFILE_STATE_TYPE, NULL)); + return LTTV_TRACEFILE_CONTEXT(g_object_new(LTTV_TRACEFILE_STATE_TYPE, NULL)); } /* Write the process state of the trace */ static void write_process_state(gpointer key, gpointer value, - gpointer user_data) + gpointer user_data) { - LttvProcessState *process; - - LttvExecutionState *es; - - FILE *fp = (FILE *)user_data; - - guint i; - guint64 address; + LttvProcessState *process; - process = (LttvProcessState *)value; - fprintf(fp, -" \n", - process, process->pid, process->tgid, process->ppid, - g_quark_to_string(process->type), - process->creation_time.tv_sec, - process->creation_time.tv_nsec, - process->insertion_time.tv_sec, - process->insertion_time.tv_nsec, - g_quark_to_string(process->name), - g_quark_to_string(process->brand), - process->cpu, process->free_events); + LttvExecutionState *es; - for(i = 0 ; i < process->execution_stack->len; i++) { - es = &g_array_index(process->execution_stack, LttvExecutionState, i); - fprintf(fp, " t), g_quark_to_string(es->n), - es->entry.tv_sec, es->entry.tv_nsec); - fprintf(fp, " CHANGE_S=%lu CHANGE_NS=%lu STATUS=\"%s\"/>\n", - es->change.tv_sec, es->change.tv_nsec, g_quark_to_string(es->s)); - } + FILE *fp = (FILE *)user_data; + + guint i; + guint64 address; + + process = (LttvProcessState *)value; + fprintf(fp," \n", + process, process->pid, process->tgid, process->ppid, + g_quark_to_string(process->type), + process->creation_time.tv_sec, + process->creation_time.tv_nsec, + process->insertion_time.tv_sec, + process->insertion_time.tv_nsec, + g_quark_to_string(process->name), + g_quark_to_string(process->brand), + process->cpu, process->free_events); + + for(i = 0 ; i < process->execution_stack->len; i++) { + es = &g_array_index(process->execution_stack, LttvExecutionState, i); + fprintf(fp, " t), g_quark_to_string(es->n), + es->entry.tv_sec, es->entry.tv_nsec); + fprintf(fp, " CHANGE_S=%lu CHANGE_NS=%lu STATUS=\"%s\"/>\n", + es->change.tv_sec, es->change.tv_nsec, g_quark_to_string(es->s)); + } - for(i = 0 ; i < process->user_stack->len; i++) { - address = g_array_index(process->user_stack, guint64, i); - fprintf(fp, " \n", - address); - } + for(i = 0 ; i < process->user_stack->len; i++) { + address = g_array_index(process->user_stack, guint64, i); + fprintf(fp, " \n", address); + } - if(process->usertrace) { - fprintf(fp, " ", - g_quark_to_string(process->usertrace->tracefile_name), - process->usertrace->cpu); - } + if(process->usertrace) { + fprintf(fp, " ", + g_quark_to_string(process->usertrace->tracefile_name), + process->usertrace->cpu); + } - fprintf(fp, " \n"); + fprintf(fp, " \n"); } void lttv_state_write(LttvTraceState *self, LttTime t, FILE *fp) { - guint i, nb_tracefile, nb_block, offset; - guint64 tsc; + guint i, nb_tracefile, nb_block, offset; + guint64 tsc; - LttvTracefileState *tfcs; + LttvTracefileState *tfcs; - LttTracefile *tf; + LttTracefile *tf; - LttEventPosition *ep; + LttEventPosition *ep; - guint nb_cpus; + guint nb_cpus; - ep = ltt_event_position_new(); + ep = ltt_event_position_new(); - fprintf(fp,"\n", t.tv_sec, t.tv_nsec); + fprintf(fp,"\n", t.tv_sec, t.tv_nsec); - g_hash_table_foreach(self->processes, write_process_state, fp); - - nb_cpus = ltt_trace_get_num_cpu(self->parent.t); - for(i=0;i\n", - i, self->running_process[i]->pid); - } + g_hash_table_foreach(self->processes, write_process_state, fp); - nb_tracefile = self->parent.tracefiles->len; + nb_cpus = ltt_trace_get_num_cpu(self->parent.t); + for(i=0;i\n", + i, self->running_process[i]->pid); + } - for(i = 0 ; i < nb_tracefile ; i++) { - tfcs = - LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, - LttvTracefileContext*, i)); - fprintf(fp, " parent.timestamp.tv_sec, - tfcs->parent.timestamp.tv_nsec); - LttEvent *e = ltt_tracefile_get_event(tfcs->parent.tf); - if(e == NULL) fprintf(fp,"/>\n"); - else { - ltt_event_position(e, ep); - ltt_event_position_get(ep, &tf, &nb_block, &offset, &tsc); - fprintf(fp, " BLOCK=%u OFFSET=%u TSC=%" PRIu64 "/>\n", nb_block, offset, - tsc); - } - } - g_free(ep); - fprintf(fp,"\n"); + nb_tracefile = self->parent.tracefiles->len; + + for(i = 0 ; i < nb_tracefile ; i++) { + tfcs = + LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, + LttvTracefileContext*, i)); + fprintf(fp, " parent.timestamp.tv_sec, + tfcs->parent.timestamp.tv_nsec); + LttEvent *e = ltt_tracefile_get_event(tfcs->parent.tf); + if(e == NULL) fprintf(fp,"/>\n"); + else { + ltt_event_position(e, ep); + ltt_event_position_get(ep, &tf, &nb_block, &offset, &tsc); + fprintf(fp, " BLOCK=%u OFFSET=%u TSC=%" PRIu64 "/>\n", nb_block, offset, + tsc); + } + } + g_free(ep); + fprintf(fp,"\n"); } static void write_process_state_raw(gpointer key, gpointer value, - gpointer user_data) -{ - LttvProcessState *process; - - LttvExecutionState *es; - - FILE *fp = (FILE *)user_data; - - guint i; - guint64 address; - - process = (LttvProcessState *)value; - fputc(HDR_PROCESS, fp); - //fwrite(&header, sizeof(header), 1, fp); - //fprintf(fp, "%s", g_quark_to_string(process->type)); - //fputc('\0', fp); - fwrite(&process->type, sizeof(process->type), 1, fp); - //fprintf(fp, "%s", g_quark_to_string(process->name)); - //fputc('\0', fp); - fwrite(&process->name, sizeof(process->name), 1, fp); - //fprintf(fp, "%s", g_quark_to_string(process->brand)); - //fputc('\0', fp); - fwrite(&process->brand, sizeof(process->brand), 1, fp); - fwrite(&process->pid, sizeof(process->pid), 1, fp); - fwrite(&process->free_events, sizeof(process->free_events), 1, fp); - fwrite(&process->tgid, sizeof(process->tgid), 1, fp); - fwrite(&process->ppid, sizeof(process->ppid), 1, fp); - fwrite(&process->cpu, sizeof(process->cpu), 1, fp); - fwrite(&process->creation_time, sizeof(process->creation_time), 1, fp); - fwrite(&process->insertion_time, sizeof(process->insertion_time), 1, fp); + gpointer user_data) +{ + LttvProcessState *process; + + LttvExecutionState *es; + + FILE *fp = (FILE *)user_data; + + guint i; + guint64 address; + + process = (LttvProcessState *)value; + fputc(HDR_PROCESS, fp); + //fwrite(&header, sizeof(header), 1, fp); + //fprintf(fp, "%s", g_quark_to_string(process->type)); + //fputc('\0', fp); + fwrite(&process->type, sizeof(process->type), 1, fp); + //fprintf(fp, "%s", g_quark_to_string(process->name)); + //fputc('\0', fp); + fwrite(&process->name, sizeof(process->name), 1, fp); + //fprintf(fp, "%s", g_quark_to_string(process->brand)); + //fputc('\0', fp); + fwrite(&process->brand, sizeof(process->brand), 1, fp); + fwrite(&process->pid, sizeof(process->pid), 1, fp); + fwrite(&process->free_events, sizeof(process->free_events), 1, fp); + fwrite(&process->tgid, sizeof(process->tgid), 1, fp); + fwrite(&process->ppid, sizeof(process->ppid), 1, fp); + fwrite(&process->cpu, sizeof(process->cpu), 1, fp); + fwrite(&process->creation_time, sizeof(process->creation_time), 1, fp); + fwrite(&process->insertion_time, sizeof(process->insertion_time), 1, fp); #if 0 - fprintf(fp, -" \n", - process, process->pid, process->tgid, process->ppid, - g_quark_to_string(process->type), - process->creation_time.tv_sec, - process->creation_time.tv_nsec, - process->insertion_time.tv_sec, - process->insertion_time.tv_nsec, - g_quark_to_string(process->name), - g_quark_to_string(process->brand), - process->cpu); + fprintf(fp," \n", + process, process->pid, process->tgid, process->ppid, + g_quark_to_string(process->type), + process->creation_time.tv_sec, + process->creation_time.tv_nsec, + process->insertion_time.tv_sec, + process->insertion_time.tv_nsec, + g_quark_to_string(process->name), + g_quark_to_string(process->brand), + process->cpu); #endif //0 - for(i = 0 ; i < process->execution_stack->len; i++) { - es = &g_array_index(process->execution_stack, LttvExecutionState, i); - - fputc(HDR_ES, fp); - //fprintf(fp, "%s", g_quark_to_string(es->t)); - //fputc('\0', fp); - fwrite(&es->t, sizeof(es->t), 1, fp); - //fprintf(fp, "%s", g_quark_to_string(es->n)); - //fputc('\0', fp); - fwrite(&es->n, sizeof(es->n), 1, fp); - //fprintf(fp, "%s", g_quark_to_string(es->s)); - //fputc('\0', fp); - fwrite(&es->s, sizeof(es->s), 1, fp); - fwrite(&es->entry, sizeof(es->entry), 1, fp); - fwrite(&es->change, sizeof(es->change), 1, fp); - fwrite(&es->cum_cpu_time, sizeof(es->cum_cpu_time), 1, fp); + for(i = 0 ; i < process->execution_stack->len; i++) { + es = &g_array_index(process->execution_stack, LttvExecutionState, i); + + fputc(HDR_ES, fp); + //fprintf(fp, "%s", g_quark_to_string(es->t)); + //fputc('\0', fp); + fwrite(&es->t, sizeof(es->t), 1, fp); + //fprintf(fp, "%s", g_quark_to_string(es->n)); + //fputc('\0', fp); + fwrite(&es->n, sizeof(es->n), 1, fp); + //fprintf(fp, "%s", g_quark_to_string(es->s)); + //fputc('\0', fp); + fwrite(&es->s, sizeof(es->s), 1, fp); + fwrite(&es->entry, sizeof(es->entry), 1, fp); + fwrite(&es->change, sizeof(es->change), 1, fp); + fwrite(&es->cum_cpu_time, sizeof(es->cum_cpu_time), 1, fp); #if 0 - fprintf(fp, " t), g_quark_to_string(es->n), - es->entry.tv_sec, es->entry.tv_nsec); - fprintf(fp, " CHANGE_S=%lu CHANGE_NS=%lu STATUS=\"%s\"/>\n", - es->change.tv_sec, es->change.tv_nsec, g_quark_to_string(es->s)); + fprintf(fp, " t), g_quark_to_string(es->n), + es->entry.tv_sec, es->entry.tv_nsec); + fprintf(fp, " CHANGE_S=%lu CHANGE_NS=%lu STATUS=\"%s\"/>\n", + es->change.tv_sec, es->change.tv_nsec, g_quark_to_string(es->s)); #endif //0 - } + } - for(i = 0 ; i < process->user_stack->len; i++) { - address = g_array_index(process->user_stack, guint64, i); - fputc(HDR_USER_STACK, fp); - fwrite(&address, sizeof(address), 1, fp); + for(i = 0 ; i < process->user_stack->len; i++) { + address = g_array_index(process->user_stack, guint64, i); + fputc(HDR_USER_STACK, fp); + fwrite(&address, sizeof(address), 1, fp); #if 0 - fprintf(fp, " \n", - address); + fprintf(fp, " \n", address); #endif //0 - } - - if(process->usertrace) { - fputc(HDR_USERTRACE, fp); - //fprintf(fp, "%s", g_quark_to_string(process->usertrace->tracefile_name)); - //fputc('\0', fp); - fwrite(&process->usertrace->tracefile_name, - sizeof(process->usertrace->tracefile_name), 1, fp); - fwrite(&process->usertrace->cpu, sizeof(process->usertrace->cpu), 1, fp); + } + + if(process->usertrace) { + fputc(HDR_USERTRACE, fp); + //fprintf(fp, "%s", g_quark_to_string(process->usertrace->tracefile_name)); + //fputc('\0', fp); + fwrite(&process->usertrace->tracefile_name, + sizeof(process->usertrace->tracefile_name), 1, fp); + fwrite(&process->usertrace->cpu, sizeof(process->usertrace->cpu), 1, fp); #if 0 - fprintf(fp, " ", - g_quark_to_string(process->usertrace->tracefile_name), - process->usertrace->cpu); + fprintf(fp, " ", + g_quark_to_string(process->usertrace->tracefile_name), + process->usertrace->cpu); #endif //0 - } + } } void lttv_state_write_raw(LttvTraceState *self, LttTime t, FILE *fp) { - guint i, nb_tracefile, nb_block, offset; - guint64 tsc; - - LttvTracefileState *tfcs; - - LttTracefile *tf; - - LttEventPosition *ep; - - guint nb_cpus; - - ep = ltt_event_position_new(); - - //fprintf(fp,"\n", t.tv_sec, t.tv_nsec); - fputc(HDR_PROCESS_STATE, fp); - fwrite(&t, sizeof(t), 1, fp); - - g_hash_table_foreach(self->processes, write_process_state_raw, fp); - - nb_cpus = ltt_trace_get_num_cpu(self->parent.t); - for(i=0;irunning_process[i]->pid, - sizeof(self->running_process[i]->pid), 1, fp); - //fprintf(fp," \n", - // i, self->running_process[i]->pid); - } - - nb_tracefile = self->parent.tracefiles->len; - - for(i = 0 ; i < nb_tracefile ; i++) { - tfcs = - LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, - LttvTracefileContext*, i)); - // fprintf(fp, " parent.timestamp.tv_sec, - // tfcs->parent.timestamp.tv_nsec); - fputc(HDR_TRACEFILE, fp); - fwrite(&tfcs->parent.timestamp, sizeof(tfcs->parent.timestamp), 1, fp); - /* Note : if timestamp if LTT_TIME_INFINITE, there will be no - * position following : end of trace */ - LttEvent *e = ltt_tracefile_get_event(tfcs->parent.tf); - if(e != NULL) { - ltt_event_position(e, ep); - ltt_event_position_get(ep, &tf, &nb_block, &offset, &tsc); - //fprintf(fp, " BLOCK=%u OFFSET=%u TSC=%llu/>\n", nb_block, offset, - // tsc); - fwrite(&nb_block, sizeof(nb_block), 1, fp); - fwrite(&offset, sizeof(offset), 1, fp); - fwrite(&tsc, sizeof(tsc), 1, fp); - } - } - g_free(ep); + guint i, nb_tracefile, nb_block, offset; + guint64 tsc; + + LttvTracefileState *tfcs; + + LttTracefile *tf; + + LttEventPosition *ep; + + guint nb_cpus; + + ep = ltt_event_position_new(); + + //fprintf(fp,"\n", t.tv_sec, t.tv_nsec); + fputc(HDR_PROCESS_STATE, fp); + fwrite(&t, sizeof(t), 1, fp); + + g_hash_table_foreach(self->processes, write_process_state_raw, fp); + + nb_cpus = ltt_trace_get_num_cpu(self->parent.t); + for(i=0;irunning_process[i]->pid, + sizeof(self->running_process[i]->pid), 1, fp); + //fprintf(fp," \n", + // i, self->running_process[i]->pid); + } + + nb_tracefile = self->parent.tracefiles->len; + + for(i = 0 ; i < nb_tracefile ; i++) { + tfcs = + LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, + LttvTracefileContext*, i)); + // fprintf(fp, " parent.timestamp.tv_sec, + // tfcs->parent.timestamp.tv_nsec); + fputc(HDR_TRACEFILE, fp); + fwrite(&tfcs->parent.timestamp, sizeof(tfcs->parent.timestamp), 1, fp); + /* Note : if timestamp if LTT_TIME_INFINITE, there will be no + * position following : end of trace */ + LttEvent *e = ltt_tracefile_get_event(tfcs->parent.tf); + if(e != NULL) { + ltt_event_position(e, ep); + ltt_event_position_get(ep, &tf, &nb_block, &offset, &tsc); + //fprintf(fp, " BLOCK=%u OFFSET=%u TSC=%llu/>\n", nb_block, offset, + // tsc); + fwrite(&nb_block, sizeof(nb_block), 1, fp); + fwrite(&offset, sizeof(offset), 1, fp); + fwrite(&tsc, sizeof(tsc), 1, fp); + } + } + g_free(ep); } @@ -1053,100 +1047,103 @@ void lttv_state_write_raw(LttvTraceState *self, LttTime t, FILE *fp) /* Called because a HDR_PROCESS was found */ static void read_process_state_raw(LttvTraceState *self, FILE *fp, - GPtrArray *quarktable) -{ - LttvExecutionState *es; - LttvProcessState *process, *parent_process; - LttvProcessState tmp; - GQuark tmpq; - - guint64 *address; - - /* TODO : check return value */ - fread(&tmp.type, sizeof(tmp.type), 1, fp); - fread(&tmp.name, sizeof(tmp.name), 1, fp); - fread(&tmp.brand, sizeof(tmp.brand), 1, fp); - fread(&tmp.pid, sizeof(tmp.pid), 1, fp); - fread(&tmp.free_events, sizeof(tmp.free_events), 1, fp); - fread(&tmp.tgid, sizeof(tmp.tgid), 1, fp); - fread(&tmp.ppid, sizeof(tmp.ppid), 1, fp); - fread(&tmp.cpu, sizeof(tmp.cpu), 1, fp); - fread(&tmp.creation_time, sizeof(tmp.creation_time), 1, fp); - fread(&tmp.insertion_time, sizeof(tmp.insertion_time), 1, fp); - - if(tmp.pid == 0) { - process = lttv_state_find_process(self, tmp.cpu, tmp.pid); - } else { - /* We must link to the parent */ - parent_process = lttv_state_find_process_or_create(self, ANY_CPU, tmp.ppid, - <t_time_zero); - process = lttv_state_find_process(self, ANY_CPU, tmp.pid); - if(process == NULL) { - process = lttv_state_create_process(self, parent_process, tmp.cpu, - tmp.pid, tmp.tgid, - g_quark_from_string((gchar*)g_ptr_array_index(quarktable, tmp.name)), - &tmp.creation_time); - } - } - process->insertion_time = tmp.insertion_time; - process->creation_time = tmp.creation_time; - process->type = g_quark_from_string( - (gchar*)g_ptr_array_index(quarktable, tmp.type)); - process->tgid = tmp.tgid; - process->ppid = tmp.ppid; - process->brand = g_quark_from_string( - (gchar*)g_ptr_array_index(quarktable, tmp.brand)); - process->name = - g_quark_from_string((gchar*)g_ptr_array_index(quarktable, tmp.name)); - process->free_events = tmp.free_events; - - do { - if(feof(fp) || ferror(fp)) goto end_loop; - - gint hdr = fgetc(fp); - if(hdr == EOF) goto end_loop; - - switch(hdr) { - case HDR_ES: - process->execution_stack = - g_array_set_size(process->execution_stack, - process->execution_stack->len + 1); - es = &g_array_index(process->execution_stack, LttvExecutionState, - process->execution_stack->len-1); - process->state = es; - - fread(&es->t, sizeof(es->t), 1, fp); - es->t = g_quark_from_string( - (gchar*)g_ptr_array_index(quarktable, es->t)); - fread(&es->n, sizeof(es->n), 1, fp); - es->n = g_quark_from_string( - (gchar*)g_ptr_array_index(quarktable, es->n)); - fread(&es->s, sizeof(es->s), 1, fp); - es->s = g_quark_from_string( - (gchar*)g_ptr_array_index(quarktable, es->s)); - fread(&es->entry, sizeof(es->entry), 1, fp); - fread(&es->change, sizeof(es->change), 1, fp); - fread(&es->cum_cpu_time, sizeof(es->cum_cpu_time), 1, fp); - break; - case HDR_USER_STACK: - process->user_stack = g_array_set_size(process->user_stack, - process->user_stack->len + 1); - address = &g_array_index(process->user_stack, guint64, - process->user_stack->len-1); - fread(address, sizeof(address), 1, fp); - process->current_function = *address; - break; - case HDR_USERTRACE: - fread(&tmpq, sizeof(tmpq), 1, fp); - fread(&process->usertrace->cpu, sizeof(process->usertrace->cpu), 1, fp); - break; - default: - ungetc(hdr, fp); - goto end_loop; - }; - } while(1); + GPtrArray *quarktable) +{ + LttvExecutionState *es; + LttvProcessState *process, *parent_process; + LttvProcessState tmp; + GQuark tmpq; + + guint64 *address; + + /* TODO : check return value */ + fread(&tmp.type, sizeof(tmp.type), 1, fp); + fread(&tmp.name, sizeof(tmp.name), 1, fp); + fread(&tmp.brand, sizeof(tmp.brand), 1, fp); + fread(&tmp.pid, sizeof(tmp.pid), 1, fp); + fread(&tmp.free_events, sizeof(tmp.free_events), 1, fp); + fread(&tmp.tgid, sizeof(tmp.tgid), 1, fp); + fread(&tmp.ppid, sizeof(tmp.ppid), 1, fp); + fread(&tmp.cpu, sizeof(tmp.cpu), 1, fp); + fread(&tmp.creation_time, sizeof(tmp.creation_time), 1, fp); + fread(&tmp.insertion_time, sizeof(tmp.insertion_time), 1, fp); + + if(tmp.pid == 0) { + process = lttv_state_find_process(self, tmp.cpu, tmp.pid); + } else { + /* We must link to the parent */ + parent_process = lttv_state_find_process_or_create(self, ANY_CPU, tmp.ppid, + <t_time_zero); + process = lttv_state_find_process(self, ANY_CPU, tmp.pid); + if(process == NULL) { + process = lttv_state_create_process(self, parent_process, tmp.cpu, + tmp.pid, tmp.tgid, + g_quark_from_string((gchar*)g_ptr_array_index(quarktable, tmp.name)), + &tmp.creation_time); + } + } + process->insertion_time = tmp.insertion_time; + process->creation_time = tmp.creation_time; + process->type = g_quark_from_string( + (gchar*)g_ptr_array_index(quarktable, tmp.type)); + process->tgid = tmp.tgid; + process->ppid = tmp.ppid; + process->brand = g_quark_from_string( + (gchar*)g_ptr_array_index(quarktable, tmp.brand)); + process->name = + g_quark_from_string((gchar*)g_ptr_array_index(quarktable, tmp.name)); + process->free_events = tmp.free_events; + + do { + if(feof(fp) || ferror(fp)) goto end_loop; + + gint hdr = fgetc(fp); + if(hdr == EOF) goto end_loop; + + switch(hdr) { + case HDR_ES: + process->execution_stack = + g_array_set_size(process->execution_stack, + process->execution_stack->len + 1); + es = &g_array_index(process->execution_stack, LttvExecutionState, + process->execution_stack->len-1); + process->state = es; + + fread(&es->t, sizeof(es->t), 1, fp); + es->t = g_quark_from_string( + (gchar*)g_ptr_array_index(quarktable, es->t)); + fread(&es->n, sizeof(es->n), 1, fp); + es->n = g_quark_from_string( + (gchar*)g_ptr_array_index(quarktable, es->n)); + fread(&es->s, sizeof(es->s), 1, fp); + es->s = g_quark_from_string( + (gchar*)g_ptr_array_index(quarktable, es->s)); + fread(&es->entry, sizeof(es->entry), 1, fp); + fread(&es->change, sizeof(es->change), 1, fp); + fread(&es->cum_cpu_time, sizeof(es->cum_cpu_time), 1, fp); + break; + + case HDR_USER_STACK: + process->user_stack = g_array_set_size(process->user_stack, + process->user_stack->len + 1); + address = &g_array_index(process->user_stack, guint64, + process->user_stack->len-1); + fread(address, sizeof(address), 1, fp); + process->current_function = *address; + break; + + case HDR_USERTRACE: + fread(&tmpq, sizeof(tmpq), 1, fp); + fread(&process->usertrace->cpu, sizeof(process->usertrace->cpu), 1, fp); + break; + + default: + ungetc(hdr, fp); + goto end_loop; + }; + } while(1); end_loop: - return; + return; } @@ -1154,152 +1151,152 @@ end_loop: /* Append a saved state to the trace states */ void lttv_state_read_raw(LttvTraceState *self, FILE *fp, GPtrArray *quarktable) { - guint i, nb_tracefile, nb_block, offset; - guint64 tsc; - LttvTracefileState *tfcs; - - LttEventPosition *ep; - - guint nb_cpus; - - int hdr; - - LttTime t; - - LttvAttribute *saved_states_tree, *saved_state_tree; - - LttvAttributeValue value; - GTree *pqueue = self->parent.ts_context->pqueue; - ep = ltt_event_position_new(); - - restore_init_state(self); - - fread(&t, sizeof(t), 1, fp); - - do { - if(feof(fp) || ferror(fp)) goto end_loop; - hdr = fgetc(fp); - if(hdr == EOF) goto end_loop; - - switch(hdr) { - case HDR_PROCESS: - /* Call read_process_state_raw */ - read_process_state_raw(self, fp, quarktable); - break; - case HDR_TRACEFILE: - case HDR_TRACESET: - case HDR_TRACE: - case HDR_QUARKS: - case HDR_QUARK: - case HDR_ES: - case HDR_USER_STACK: - case HDR_USERTRACE: - case HDR_PROCESS_STATE: - case HDR_CPU: - ungetc(hdr, fp); - goto end_loop; - break; - default: - g_error("Error while parsing saved state file : unknown data header %d", - hdr); - }; - } while(1); + guint i, nb_tracefile, nb_block, offset; + guint64 tsc; + LttvTracefileState *tfcs; + + LttEventPosition *ep; + + guint nb_cpus; + + int hdr; + + LttTime t; + + LttvAttribute *saved_states_tree, *saved_state_tree; + + LttvAttributeValue value; + GTree *pqueue = self->parent.ts_context->pqueue; + ep = ltt_event_position_new(); + + restore_init_state(self); + + fread(&t, sizeof(t), 1, fp); + + do { + if(feof(fp) || ferror(fp)) goto end_loop; + hdr = fgetc(fp); + if(hdr == EOF) goto end_loop; + + switch(hdr) { + case HDR_PROCESS: + /* Call read_process_state_raw */ + read_process_state_raw(self, fp, quarktable); + break; + case HDR_TRACEFILE: + case HDR_TRACESET: + case HDR_TRACE: + case HDR_QUARKS: + case HDR_QUARK: + case HDR_ES: + case HDR_USER_STACK: + case HDR_USERTRACE: + case HDR_PROCESS_STATE: + case HDR_CPU: + ungetc(hdr, fp); + goto end_loop; + break; + default: + g_error("Error while parsing saved state file : unknown data header %d", + hdr); + }; + } while(1); end_loop: - nb_cpus = ltt_trace_get_num_cpu(self->parent.t); - for(i=0;irunning_process[i]->pid, - sizeof(self->running_process[i]->pid), 1, fp); - } - - nb_tracefile = self->parent.tracefiles->len; - - for(i = 0 ; i < nb_tracefile ; i++) { - tfcs = - LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, - LttvTracefileContext*, i)); - // fprintf(fp, " parent.timestamp.tv_sec, - // tfcs->parent.timestamp.tv_nsec); - g_tree_remove(pqueue, &tfcs->parent); - hdr = fgetc(fp); - g_assert(hdr == HDR_TRACEFILE); - fread(&tfcs->parent.timestamp, sizeof(tfcs->parent.timestamp), 1, fp); - /* Note : if timestamp if LTT_TIME_INFINITE, there will be no - * position following : end of trace */ - if(ltt_time_compare(tfcs->parent.timestamp, ltt_time_infinite) != 0) { - fread(&nb_block, sizeof(nb_block), 1, fp); - fread(&offset, sizeof(offset), 1, fp); - fread(&tsc, sizeof(tsc), 1, fp); - ltt_event_position_set(ep, tfcs->parent.tf, nb_block, offset, tsc); - gint ret = ltt_tracefile_seek_position(tfcs->parent.tf, ep); - g_assert(ret == 0); - g_tree_insert(pqueue, &tfcs->parent, &tfcs->parent); - } - } - g_free(ep); - - saved_states_tree = lttv_attribute_find_subdir(self->parent.t_a, - LTTV_STATE_SAVED_STATES); - saved_state_tree = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); - value = lttv_attribute_add(saved_states_tree, - lttv_attribute_get_number(saved_states_tree), LTTV_GOBJECT); - *(value.v_gobject) = (GObject *)saved_state_tree; - value = lttv_attribute_add(saved_state_tree, LTTV_STATE_TIME, LTTV_TIME); - *(value.v_time) = t; - lttv_state_save(self, saved_state_tree); - g_debug("Saving state at time %lu.%lu", t.tv_sec, - t.tv_nsec); - - *(self->max_time_state_recomputed_in_seek) = t; + nb_cpus = ltt_trace_get_num_cpu(self->parent.t); + for(i=0;irunning_process[i]->pid, + sizeof(self->running_process[i]->pid), 1, fp); + } + + nb_tracefile = self->parent.tracefiles->len; + + for(i = 0 ; i < nb_tracefile ; i++) { + tfcs = + LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, + LttvTracefileContext*, i)); + // fprintf(fp, " parent.timestamp.tv_sec, + // tfcs->parent.timestamp.tv_nsec); + g_tree_remove(pqueue, &tfcs->parent); + hdr = fgetc(fp); + g_assert(hdr == HDR_TRACEFILE); + fread(&tfcs->parent.timestamp, sizeof(tfcs->parent.timestamp), 1, fp); + /* Note : if timestamp if LTT_TIME_INFINITE, there will be no + * position following : end of trace */ + if(ltt_time_compare(tfcs->parent.timestamp, ltt_time_infinite) != 0) { + fread(&nb_block, sizeof(nb_block), 1, fp); + fread(&offset, sizeof(offset), 1, fp); + fread(&tsc, sizeof(tsc), 1, fp); + ltt_event_position_set(ep, tfcs->parent.tf, nb_block, offset, tsc); + gint ret = ltt_tracefile_seek_position(tfcs->parent.tf, ep); + g_assert(ret == 0); + g_tree_insert(pqueue, &tfcs->parent, &tfcs->parent); + } + } + g_free(ep); + + saved_states_tree = lttv_attribute_find_subdir(self->parent.t_a, + LTTV_STATE_SAVED_STATES); + saved_state_tree = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); + value = lttv_attribute_add(saved_states_tree, + lttv_attribute_get_number(saved_states_tree), LTTV_GOBJECT); + *(value.v_gobject) = (GObject *)saved_state_tree; + value = lttv_attribute_add(saved_state_tree, LTTV_STATE_TIME, LTTV_TIME); + *(value.v_time) = t; + lttv_state_save(self, saved_state_tree); + g_debug("Saving state at time %lu.%lu", t.tv_sec, + t.tv_nsec); + + *(self->max_time_state_recomputed_in_seek) = t; } /* Called when a HDR_TRACE is found */ void lttv_trace_states_read_raw(LttvTraceState *tcs, FILE *fp, - GPtrArray *quarktable) -{ - int hdr; - - do { - if(feof(fp) || ferror(fp)) goto end_loop; - hdr = fgetc(fp); - if(hdr == EOF) goto end_loop; - - switch(hdr) { - case HDR_PROCESS_STATE: - /* Call read_process_state_raw */ - lttv_state_read_raw(tcs, fp, quarktable); - break; - case HDR_TRACEFILE: - case HDR_TRACESET: - case HDR_TRACE: - case HDR_QUARKS: - case HDR_QUARK: - case HDR_ES: - case HDR_USER_STACK: - case HDR_USERTRACE: - case HDR_PROCESS: - case HDR_CPU: - g_error("Error while parsing saved state file :" - " unexpected data header %d", - hdr); - break; - default: - g_error("Error while parsing saved state file : unknown data header %d", - hdr); - }; - } while(1); + GPtrArray *quarktable) +{ + int hdr; + + do { + if(feof(fp) || ferror(fp)) goto end_loop; + hdr = fgetc(fp); + if(hdr == EOF) goto end_loop; + + switch(hdr) { + case HDR_PROCESS_STATE: + /* Call read_process_state_raw */ + lttv_state_read_raw(tcs, fp, quarktable); + break; + case HDR_TRACEFILE: + case HDR_TRACESET: + case HDR_TRACE: + case HDR_QUARKS: + case HDR_QUARK: + case HDR_ES: + case HDR_USER_STACK: + case HDR_USERTRACE: + case HDR_PROCESS: + case HDR_CPU: + g_error("Error while parsing saved state file :" + " unexpected data header %d", + hdr); + break; + default: + g_error("Error while parsing saved state file : unknown data header %d", + hdr); + }; + } while(1); end_loop: - *(tcs->max_time_state_recomputed_in_seek) = tcs->parent.time_span.end_time; - restore_init_state(tcs); - lttv_process_trace_seek_time(&tcs->parent, ltt_time_zero); - return; + *(tcs->max_time_state_recomputed_in_seek) = tcs->parent.time_span.end_time; + restore_init_state(tcs); + lttv_process_trace_seek_time(&tcs->parent, ltt_time_zero); + return; } @@ -1308,256 +1305,263 @@ end_loop: static void copy_process_state(gpointer key, gpointer value,gpointer user_data) { - LttvProcessState *process, *new_process; - - GHashTable *new_processes = (GHashTable *)user_data; - - guint i; - - process = (LttvProcessState *)value; - new_process = g_new(LttvProcessState, 1); - *new_process = *process; - new_process->execution_stack = g_array_sized_new(FALSE, FALSE, - sizeof(LttvExecutionState), PREALLOCATED_EXECUTION_STACK); - new_process->execution_stack = - g_array_set_size(new_process->execution_stack, - process->execution_stack->len); - for(i = 0 ; i < process->execution_stack->len; i++) { - g_array_index(new_process->execution_stack, LttvExecutionState, i) = - g_array_index(process->execution_stack, LttvExecutionState, i); - } - new_process->state = &g_array_index(new_process->execution_stack, - LttvExecutionState, new_process->execution_stack->len - 1); - new_process->user_stack = g_array_sized_new(FALSE, FALSE, - sizeof(guint64), 0); - new_process->user_stack = - g_array_set_size(new_process->user_stack, - process->user_stack->len); - for(i = 0 ; i < process->user_stack->len; i++) { - g_array_index(new_process->user_stack, guint64, i) = - g_array_index(process->user_stack, guint64, i); - } - new_process->current_function = process->current_function; - - /* fd hash table stuff */ - { - GHashTableIter it; - gpointer key; - gpointer value; - - /* copy every item in the hash table */ - new_process->fds = g_hash_table_new(g_direct_hash, g_direct_equal); - - g_hash_table_iter_init(&it, process->fds); - while (g_hash_table_iter_next (&it, (void *)&key, (void *)&value)) { - g_hash_table_insert(new_process->fds, key, value); - } - } - - /* When done creating the new process state, insert it in the - * hash table */ - g_hash_table_insert(new_processes, new_process, new_process); + LttvProcessState *process, *new_process; + + GHashTable *new_processes = (GHashTable *)user_data; + + guint i; + + process = (LttvProcessState *)value; + new_process = g_new(LttvProcessState, 1); + *new_process = *process; + new_process->execution_stack = g_array_sized_new(FALSE, FALSE, + sizeof(LttvExecutionState), PREALLOCATED_EXECUTION_STACK); + new_process->execution_stack = + g_array_set_size(new_process->execution_stack, + process->execution_stack->len); + for(i = 0 ; i < process->execution_stack->len; i++) { + g_array_index(new_process->execution_stack, LttvExecutionState, i) = + g_array_index(process->execution_stack, LttvExecutionState, i); + } + new_process->state = &g_array_index(new_process->execution_stack, + LttvExecutionState, new_process->execution_stack->len - 1); + new_process->user_stack = g_array_sized_new(FALSE, FALSE, + sizeof(guint64), 0); + new_process->user_stack = g_array_set_size(new_process->user_stack, + process->user_stack->len); + for(i = 0 ; i < process->user_stack->len; i++) { + g_array_index(new_process->user_stack, guint64, i) = + g_array_index(process->user_stack, guint64, i); + } + new_process->current_function = process->current_function; + + /* fd hash table stuff */ + { + GHashTableIter it; + gpointer key; + gpointer value; + + /* copy every item in the hash table */ + new_process->fds = g_hash_table_new(g_direct_hash, g_direct_equal); + + g_hash_table_iter_init(&it, process->fds); + while (g_hash_table_iter_next (&it, (void *)&key, (void *)&value)) { + g_hash_table_insert(new_process->fds, key, value); + } + } + + /* When done creating the new process state, insert it in the + * hash table */ + g_hash_table_insert(new_processes, new_process, new_process); } static GHashTable *lttv_state_copy_process_table(GHashTable *processes) { - GHashTable *new_processes = g_hash_table_new(process_hash, process_equal); + GHashTable *new_processes = g_hash_table_new(process_hash, process_equal); - g_hash_table_foreach(processes, copy_process_state, new_processes); - return new_processes; + g_hash_table_foreach(processes, copy_process_state, new_processes); + return new_processes; } static LttvCPUState *lttv_state_copy_cpu_states(LttvCPUState *states, guint n) { - guint i,j; - LttvCPUState *retval; - - retval = g_new(LttvCPUState, n); - - for(i=0; ilen); - for(j=0; jlen; j++) { - g_array_index(retval[i].irq_stack, gint, j) = g_array_index(states[i].irq_stack, gint, j); - } - - retval[i].softirq_stack = g_array_new(FALSE, FALSE, sizeof(gint)); - g_array_set_size(retval[i].softirq_stack, states[i].softirq_stack->len); - for(j=0; jlen; j++) { - g_array_index(retval[i].softirq_stack, gint, j) = g_array_index(states[i].softirq_stack, gint, j); - } - - retval[i].trap_stack = g_array_new(FALSE, FALSE, sizeof(gint)); - g_array_set_size(retval[i].trap_stack, states[i].trap_stack->len); - for(j=0; jlen; j++) { - g_array_index(retval[i].trap_stack, gint, j) = g_array_index(states[i].trap_stack, gint, j); - } - - retval[i].mode_stack = g_array_new(FALSE, FALSE, sizeof(LttvCPUMode)); - g_array_set_size(retval[i].mode_stack, states[i].mode_stack->len); - for(j=0; jlen; j++) { - g_array_index(retval[i].mode_stack, GQuark, j) = g_array_index(states[i].mode_stack, GQuark, j); - } - } + guint i,j; + LttvCPUState *retval; + + retval = g_new(LttvCPUState, n); + + for(i=0; ilen); + for(j=0; jlen; j++) { + g_array_index(retval[i].irq_stack, gint, j) = + g_array_index(states[i].irq_stack, gint, j); + } + + retval[i].softirq_stack = g_array_new(FALSE, FALSE, sizeof(gint)); + g_array_set_size(retval[i].softirq_stack, states[i].softirq_stack->len); + for(j=0; jlen; j++) { + g_array_index(retval[i].softirq_stack, gint, j) = + g_array_index(states[i].softirq_stack, gint, j); + } + + retval[i].trap_stack = g_array_new(FALSE, FALSE, sizeof(gint)); + g_array_set_size(retval[i].trap_stack, states[i].trap_stack->len); + for(j=0; jlen; j++) { + g_array_index(retval[i].trap_stack, gint, j) = + g_array_index(states[i].trap_stack, gint, j); + } + + retval[i].mode_stack = g_array_new(FALSE, FALSE, sizeof(LttvCPUMode)); + g_array_set_size(retval[i].mode_stack, states[i].mode_stack->len); + for(j=0; jlen; j++) { + g_array_index(retval[i].mode_stack, GQuark, j) = + g_array_index(states[i].mode_stack, GQuark, j); + } + } - return retval; + return retval; } static void lttv_state_free_cpu_states(LttvCPUState *states, guint n) { - guint i; + guint i; - for(i=0; ilen); - for(j=0; jlen; j++) { - g_array_index(retval[i].mode_stack, GQuark, j) = g_array_index(states[i].mode_stack, GQuark, j); - } - } + for(i=0; ilen); + for(j=0; jlen; j++) { + g_array_index(retval[i].mode_stack, GQuark, j) = + g_array_index(states[i].mode_stack, GQuark, j); + } + } - return retval; + return retval; } static void lttv_state_free_irq_states(LttvIRQState *states, guint n) { - guint i; + guint i; - for(i=0; ibdev_states, &devcode_gint); - if(bdev == NULL) { - LttvBdevState *bdevstate = g_new(LttvBdevState, 1); - bdevstate->mode_stack = g_array_new(FALSE, FALSE, sizeof(GQuark)); + gint devcode_gint = devcode; + gpointer bdev = g_hash_table_lookup(ts->bdev_states, &devcode_gint); + if(bdev == NULL) { + LttvBdevState *bdevstate = g_new(LttvBdevState, 1); + bdevstate->mode_stack = g_array_new(FALSE, FALSE, sizeof(GQuark)); - gint * key = g_new(gint, 1); - *key = devcode; - g_hash_table_insert(ts->bdev_states, key, bdevstate); + gint * key = g_new(gint, 1); + *key = devcode; + g_hash_table_insert(ts->bdev_states, key, bdevstate); - bdev = bdevstate; - } + bdev = bdevstate; + } - return bdev; + return bdev; } static LttvBdevState *bdevstate_new(void) { - LttvBdevState *retval; - retval = g_new(LttvBdevState, 1); - retval->mode_stack = g_array_new(FALSE, FALSE, sizeof(GQuark)); + LttvBdevState *retval; + retval = g_new(LttvBdevState, 1); + retval->mode_stack = g_array_new(FALSE, FALSE, sizeof(GQuark)); - return retval; + return retval; } static void bdevstate_free(LttvBdevState *bds) { - g_array_free(bds->mode_stack, TRUE); - g_free(bds); + g_array_free(bds->mode_stack, TRUE); + g_free(bds); } static void bdevstate_free_cb(gpointer key, gpointer value, gpointer user_data) { - LttvBdevState *bds = (LttvBdevState *) value; + LttvBdevState *bds = (LttvBdevState *) value; - bdevstate_free(bds); + bdevstate_free(bds); } static LttvBdevState *bdevstate_copy(LttvBdevState *bds) { - LttvBdevState *retval; + LttvBdevState *retval; - retval = bdevstate_new(); - g_array_insert_vals(retval->mode_stack, 0, bds->mode_stack->data, bds->mode_stack->len); + retval = bdevstate_new(); + g_array_insert_vals(retval->mode_stack, 0, bds->mode_stack->data, + bds->mode_stack->len); - return retval; + return retval; } static void insert_and_copy_bdev_state(gpointer k, gpointer v, gpointer u) { - //GHashTable *ht = (GHashTable *)u; - LttvBdevState *bds = (LttvBdevState *)v; - LttvBdevState *newbds; + //GHashTable *ht = (GHashTable *)u; + LttvBdevState *bds = (LttvBdevState *)v; + LttvBdevState *newbds; - newbds = bdevstate_copy(bds); + newbds = bdevstate_copy(bds); - g_hash_table_insert(u, k, newbds); + g_hash_table_insert(u, k, newbds); } static GHashTable *lttv_state_copy_blkdev_hashtable(GHashTable *ht) { - GHashTable *retval; + GHashTable *retval; - retval = g_hash_table_new(g_int_hash, g_int_equal); + retval = g_hash_table_new(g_int_hash, g_int_equal); - g_hash_table_foreach(ht, insert_and_copy_bdev_state, retval); + g_hash_table_foreach(ht, insert_and_copy_bdev_state, retval); - return retval; + return retval; } /* Free a hashtable and the LttvBdevState structures its values @@ -1565,8 +1569,8 @@ static GHashTable *lttv_state_copy_blkdev_hashtable(GHashTable *ht) static void lttv_state_free_blkdev_hashtable(GHashTable *ht) { - g_hash_table_foreach(ht, bdevstate_free_cb, NULL); - g_hash_table_destroy(ht); + g_hash_table_foreach(ht, bdevstate_free_cb, NULL); + g_hash_table_destroy(ht); } /* The saved state for each trace contains a member "processes", which @@ -1577,573 +1581,569 @@ static void lttv_state_free_blkdev_hashtable(GHashTable *ht) static void state_save(LttvTraceState *self, LttvAttribute *container) { - guint i, nb_tracefile, nb_cpus, nb_irqs, nb_soft_irqs, nb_traps; - - LttvTracefileState *tfcs; - - LttvAttribute *tracefiles_tree, *tracefile_tree; - - guint *running_process; - - LttvAttributeValue value; - - LttEventPosition *ep; - - tracefiles_tree = lttv_attribute_find_subdir(container, - LTTV_STATE_TRACEFILES); - - value = lttv_attribute_add(container, LTTV_STATE_PROCESSES, - LTTV_POINTER); - *(value.v_pointer) = lttv_state_copy_process_table(self->processes); - - /* Add the currently running processes array */ - nb_cpus = ltt_trace_get_num_cpu(self->parent.t); - running_process = g_new(guint, nb_cpus); - for(i=0;irunning_process[i]->pid; - } - value = lttv_attribute_add(container, LTTV_STATE_RUNNING_PROCESS, - LTTV_POINTER); - *(value.v_pointer) = running_process; - - g_info("State save"); - - nb_tracefile = self->parent.tracefiles->len; - - for(i = 0 ; i < nb_tracefile ; i++) { - tfcs = - LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, - LttvTracefileContext*, i)); - tracefile_tree = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); - value = lttv_attribute_add(tracefiles_tree, i, - LTTV_GOBJECT); - *(value.v_gobject) = (GObject *)tracefile_tree; + guint i, nb_tracefile, nb_cpus, nb_irqs, nb_soft_irqs, nb_traps; + + LttvTracefileState *tfcs; + + LttvAttribute *tracefiles_tree, *tracefile_tree; + + guint *running_process; + + LttvAttributeValue value; + + LttEventPosition *ep; + + tracefiles_tree = lttv_attribute_find_subdir(container, + LTTV_STATE_TRACEFILES); + + value = lttv_attribute_add(container, LTTV_STATE_PROCESSES, + LTTV_POINTER); + *(value.v_pointer) = lttv_state_copy_process_table(self->processes); + + /* Add the currently running processes array */ + nb_cpus = ltt_trace_get_num_cpu(self->parent.t); + running_process = g_new(guint, nb_cpus); + for(i=0;irunning_process[i]->pid; + } + value = lttv_attribute_add(container, LTTV_STATE_RUNNING_PROCESS, + LTTV_POINTER); + *(value.v_pointer) = running_process; + + g_info("State save"); + + nb_tracefile = self->parent.tracefiles->len; + + for(i = 0 ; i < nb_tracefile ; i++) { + tfcs = + LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, + LttvTracefileContext*, i)); + tracefile_tree = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); + value = lttv_attribute_add(tracefiles_tree, i, + LTTV_GOBJECT); + *(value.v_gobject) = (GObject *)tracefile_tree; #if 0 - value = lttv_attribute_add(tracefile_tree, LTTV_STATE_PROCESS, - LTTV_UINT); - *(value.v_uint) = tfcs->process->pid; + value = lttv_attribute_add(tracefile_tree, LTTV_STATE_PROCESS, + LTTV_UINT); + *(value.v_uint) = tfcs->process->pid; #endif //0 - value = lttv_attribute_add(tracefile_tree, LTTV_STATE_EVENT, - LTTV_POINTER); - /* Only save the position if the tfs has not infinite time. */ - //if(!g_tree_lookup(self->parent.ts_context->pqueue, &tfcs->parent) - // && current_tfcs != tfcs) { - if(ltt_time_compare(tfcs->parent.timestamp, ltt_time_infinite) == 0) { - *(value.v_pointer) = NULL; - } else { - LttEvent *e = ltt_tracefile_get_event(tfcs->parent.tf); - ep = ltt_event_position_new(); - ltt_event_position(e, ep); - *(value.v_pointer) = ep; - - guint nb_block, offset; - guint64 tsc; - LttTracefile *tf; - ltt_event_position_get(ep, &tf, &nb_block, &offset, &tsc); - g_info("Block %u offset %u tsc %" PRIu64 " time %lu.%lu", nb_block, offset, - tsc, - tfcs->parent.timestamp.tv_sec, tfcs->parent.timestamp.tv_nsec); - } - } - - /* save the cpu state */ - { - value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_CPUS_COUNT, - LTTV_UINT); - *(value.v_uint) = nb_cpus; - - value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_CPUS, - LTTV_POINTER); - *(value.v_pointer) = lttv_state_copy_cpu_states(self->cpu_states, nb_cpus); - } - - /* save the irq state */ - nb_irqs = self->name_tables->nb_irqs; - { - value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_IRQS, - LTTV_POINTER); - *(value.v_pointer) = lttv_state_copy_irq_states(self->irq_states, nb_irqs); - } - - /* save the soft irq state */ - nb_soft_irqs = self->name_tables->nb_soft_irqs; - { - value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_SOFT_IRQS, - LTTV_POINTER); - *(value.v_pointer) = lttv_state_copy_soft_irq_states(self->soft_irq_states, nb_soft_irqs); - } - - /* save the trap state */ - nb_traps = self->name_tables->nb_traps; - { - value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_TRAPS, - LTTV_POINTER); - *(value.v_pointer) = lttv_state_copy_trap_states(self->trap_states, nb_traps); - } - - /* save the blkdev states */ - value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_BLKDEVS, - LTTV_POINTER); - *(value.v_pointer) = lttv_state_copy_blkdev_hashtable(self->bdev_states); + value = lttv_attribute_add(tracefile_tree, LTTV_STATE_EVENT, + LTTV_POINTER); + /* Only save the position if the tfs has not infinite time. */ + //if(!g_tree_lookup(self->parent.ts_context->pqueue, &tfcs->parent) + // && current_tfcs != tfcs) { + if(ltt_time_compare(tfcs->parent.timestamp, ltt_time_infinite) == 0) { + *(value.v_pointer) = NULL; + } else { + LttEvent *e = ltt_tracefile_get_event(tfcs->parent.tf); + ep = ltt_event_position_new(); + ltt_event_position(e, ep); + *(value.v_pointer) = ep; + + guint nb_block, offset; + guint64 tsc; + LttTracefile *tf; + ltt_event_position_get(ep, &tf, &nb_block, &offset, &tsc); + g_info("Block %u offset %u tsc %" PRIu64 " time %lu.%lu", nb_block, + offset, tsc, tfcs->parent.timestamp.tv_sec, + tfcs->parent.timestamp.tv_nsec); + } + } + + /* save the cpu state */ + { + value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_CPUS_COUNT, + LTTV_UINT); + *(value.v_uint) = nb_cpus; + + value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_CPUS, + LTTV_POINTER); + *(value.v_pointer) = lttv_state_copy_cpu_states(self->cpu_states, nb_cpus); + } + + /* save the irq state */ + nb_irqs = self->name_tables->nb_irqs; + { + value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_IRQS, + LTTV_POINTER); + *(value.v_pointer) = lttv_state_copy_irq_states(self->irq_states, nb_irqs); + } + + /* save the soft irq state */ + nb_soft_irqs = self->name_tables->nb_soft_irqs; + { + value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_SOFT_IRQS, + LTTV_POINTER); + *(value.v_pointer) = lttv_state_copy_soft_irq_states(self->soft_irq_states, nb_soft_irqs); + } + + /* save the trap state */ + nb_traps = self->name_tables->nb_traps; + { + value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_TRAPS, + LTTV_POINTER); + *(value.v_pointer) = lttv_state_copy_trap_states(self->trap_states, nb_traps); + } + + /* save the blkdev states */ + value = lttv_attribute_add(container, LTTV_STATE_RESOURCE_BLKDEVS, + LTTV_POINTER); + *(value.v_pointer) = lttv_state_copy_blkdev_hashtable(self->bdev_states); } static void state_restore(LttvTraceState *self, LttvAttribute *container) { - guint i, nb_tracefile, pid, nb_cpus, nb_irqs, nb_soft_irqs, nb_traps; + guint i, nb_tracefile, pid, nb_cpus, nb_irqs, nb_soft_irqs, nb_traps; - LttvTracefileState *tfcs; + LttvTracefileState *tfcs; - LttvAttribute *tracefiles_tree, *tracefile_tree; + LttvAttribute *tracefiles_tree, *tracefile_tree; - guint *running_process; + guint *running_process; - LttvAttributeType type; + LttvAttributeType type; - LttvAttributeValue value; + LttvAttributeValue value; - LttvAttributeName name; + LttvAttributeName name; - gboolean is_named; + gboolean is_named; - LttEventPosition *ep; + LttEventPosition *ep; - LttvTracesetContext *tsc = self->parent.ts_context; - int retval; + LttvTracesetContext *tsc = self->parent.ts_context; + int retval; - tracefiles_tree = lttv_attribute_find_subdir(container, - LTTV_STATE_TRACEFILES); + tracefiles_tree = lttv_attribute_find_subdir(container, + LTTV_STATE_TRACEFILES); - type = lttv_attribute_get_by_name(container, LTTV_STATE_PROCESSES, - &value); - g_assert(type == LTTV_POINTER); - lttv_state_free_process_table(self->processes); - self->processes = lttv_state_copy_process_table(*(value.v_pointer)); + type = lttv_attribute_get_by_name(container, LTTV_STATE_PROCESSES, + &value); + g_assert(type == LTTV_POINTER); + lttv_state_free_process_table(self->processes); + self->processes = lttv_state_copy_process_table(*(value.v_pointer)); - /* Add the currently running processes array */ - nb_cpus = ltt_trace_get_num_cpu(self->parent.t); - type = lttv_attribute_get_by_name(container, LTTV_STATE_RUNNING_PROCESS, - &value); - g_assert(type == LTTV_POINTER); - running_process = *(value.v_pointer); - for(i=0;irunning_process[i] = lttv_state_find_process(self, i, pid); - g_assert(self->running_process[i] != NULL); - } + /* Add the currently running processes array */ + nb_cpus = ltt_trace_get_num_cpu(self->parent.t); + type = lttv_attribute_get_by_name(container, LTTV_STATE_RUNNING_PROCESS, + &value); + g_assert(type == LTTV_POINTER); + running_process = *(value.v_pointer); + for(i=0;irunning_process[i] = lttv_state_find_process(self, i, pid); + g_assert(self->running_process[i] != NULL); + } - nb_tracefile = self->parent.tracefiles->len; + nb_tracefile = self->parent.tracefiles->len; - //g_tree_destroy(tsc->pqueue); - //tsc->pqueue = g_tree_new(compare_tracefile); + //g_tree_destroy(tsc->pqueue); + //tsc->pqueue = g_tree_new(compare_tracefile); - /* restore cpu resource states */ - type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_CPUS, &value); - g_assert(type == LTTV_POINTER); - lttv_state_free_cpu_states(self->cpu_states, nb_cpus); - self->cpu_states = lttv_state_copy_cpu_states(*(value.v_pointer), nb_cpus); + /* restore cpu resource states */ + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_CPUS, &value); + g_assert(type == LTTV_POINTER); + lttv_state_free_cpu_states(self->cpu_states, nb_cpus); + self->cpu_states = lttv_state_copy_cpu_states(*(value.v_pointer), nb_cpus); - /* restore irq resource states */ - nb_irqs = self->name_tables->nb_irqs; - type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_IRQS, &value); - g_assert(type == LTTV_POINTER); - lttv_state_free_irq_states(self->irq_states, nb_irqs); - self->irq_states = lttv_state_copy_irq_states(*(value.v_pointer), nb_irqs); + /* restore irq resource states */ + nb_irqs = self->name_tables->nb_irqs; + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_IRQS, &value); + g_assert(type == LTTV_POINTER); + lttv_state_free_irq_states(self->irq_states, nb_irqs); + self->irq_states = lttv_state_copy_irq_states(*(value.v_pointer), nb_irqs); - /* restore soft irq resource states */ - nb_soft_irqs = self->name_tables->nb_soft_irqs; - type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_SOFT_IRQS, &value); - g_assert(type == LTTV_POINTER); - lttv_state_free_soft_irq_states(self->soft_irq_states, nb_soft_irqs); - self->soft_irq_states = lttv_state_copy_soft_irq_states(*(value.v_pointer), nb_soft_irqs); + /* restore soft irq resource states */ + nb_soft_irqs = self->name_tables->nb_soft_irqs; + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_SOFT_IRQS, &value); + g_assert(type == LTTV_POINTER); + lttv_state_free_soft_irq_states(self->soft_irq_states, nb_soft_irqs); + self->soft_irq_states = lttv_state_copy_soft_irq_states(*(value.v_pointer), nb_soft_irqs); - /* restore trap resource states */ - nb_traps = self->name_tables->nb_traps; - type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_TRAPS, &value); - g_assert(type == LTTV_POINTER); - lttv_state_free_trap_states(self->trap_states, nb_traps); - self->trap_states = lttv_state_copy_trap_states(*(value.v_pointer), nb_traps); + /* restore trap resource states */ + nb_traps = self->name_tables->nb_traps; + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_TRAPS, &value); + g_assert(type == LTTV_POINTER); + lttv_state_free_trap_states(self->trap_states, nb_traps); + self->trap_states = lttv_state_copy_trap_states(*(value.v_pointer), nb_traps); - /* restore the blkdev states */ - type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_BLKDEVS, &value); - g_assert(type == LTTV_POINTER); - lttv_state_free_blkdev_hashtable(self->bdev_states); - self->bdev_states = lttv_state_copy_blkdev_hashtable(*(value.v_pointer)); - - for(i = 0 ; i < nb_tracefile ; i++) { - tfcs = - LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, - LttvTracefileContext*, i)); - type = lttv_attribute_get(tracefiles_tree, i, &name, &value, &is_named); - g_assert(type == LTTV_GOBJECT); - tracefile_tree = *((LttvAttribute **)(value.v_gobject)); + /* restore the blkdev states */ + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_BLKDEVS, &value); + g_assert(type == LTTV_POINTER); + lttv_state_free_blkdev_hashtable(self->bdev_states); + self->bdev_states = lttv_state_copy_blkdev_hashtable(*(value.v_pointer)); + + for(i = 0 ; i < nb_tracefile ; i++) { + tfcs = + LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, + LttvTracefileContext*, i)); + type = lttv_attribute_get(tracefiles_tree, i, &name, &value, &is_named); + g_assert(type == LTTV_GOBJECT); + tracefile_tree = *((LttvAttribute **)(value.v_gobject)); #if 0 - type = lttv_attribute_get_by_name(tracefile_tree, LTTV_STATE_PROCESS, - &value); - g_assert(type == LTTV_UINT); - pid = *(value.v_uint); - tfcs->process = lttv_state_find_process_or_create(tfcs, pid); + type = lttv_attribute_get_by_name(tracefile_tree, LTTV_STATE_PROCESS, + &value); + g_assert(type == LTTV_UINT); + pid = *(value.v_uint); + tfcs->process = lttv_state_find_process_or_create(tfcs, pid); #endif //0 - type = lttv_attribute_get_by_name(tracefile_tree, LTTV_STATE_EVENT, - &value); - g_assert(type == LTTV_POINTER); - //g_assert(*(value.v_pointer) != NULL); - ep = *(value.v_pointer); - g_assert(tfcs->parent.t_context != NULL); - - tfcs->cpu_state = &self->cpu_states[tfcs->cpu]; - - LttvTracefileContext *tfc = LTTV_TRACEFILE_CONTEXT(tfcs); - g_tree_remove(tsc->pqueue, tfc); - - if(ep != NULL) { - retval= ltt_tracefile_seek_position(tfc->tf, ep); - g_assert_cmpint(retval, ==, 0); - tfc->timestamp = ltt_event_time(ltt_tracefile_get_event(tfc->tf)); - g_assert_cmpint(ltt_time_compare(tfc->timestamp, ltt_time_infinite), !=, 0); - g_tree_insert(tsc->pqueue, tfc, tfc); - g_info("Restoring state for a tf at time %lu.%lu", tfc->timestamp.tv_sec, tfc->timestamp.tv_nsec); - } else { - tfc->timestamp = ltt_time_infinite; - } - } + type = lttv_attribute_get_by_name(tracefile_tree, LTTV_STATE_EVENT, + &value); + g_assert(type == LTTV_POINTER); + //g_assert(*(value.v_pointer) != NULL); + ep = *(value.v_pointer); + g_assert(tfcs->parent.t_context != NULL); + + tfcs->cpu_state = &self->cpu_states[tfcs->cpu]; + + LttvTracefileContext *tfc = LTTV_TRACEFILE_CONTEXT(tfcs); + g_tree_remove(tsc->pqueue, tfc); + + if(ep != NULL) { + retval= ltt_tracefile_seek_position(tfc->tf, ep); + g_assert_cmpint(retval, ==, 0); + tfc->timestamp = ltt_event_time(ltt_tracefile_get_event(tfc->tf)); + g_assert_cmpint(ltt_time_compare(tfc->timestamp, ltt_time_infinite), + !=, 0); + g_tree_insert(tsc->pqueue, tfc, tfc); + g_info("Restoring state for a tf at time %lu.%lu", + tfc->timestamp.tv_sec, tfc->timestamp.tv_nsec); + } else { + tfc->timestamp = ltt_time_infinite; + } + } } static void state_saved_free(LttvTraceState *self, LttvAttribute *container) { - guint i, nb_tracefile, nb_cpus, nb_irqs, nb_soft_irqs; + guint i, nb_tracefile, nb_cpus, nb_irqs, nb_soft_irqs; - LttvTracefileState *tfcs; + LttvTracefileState *tfcs; - LttvAttribute *tracefiles_tree, *tracefile_tree; + LttvAttribute *tracefiles_tree, *tracefile_tree; - guint *running_process; + guint *running_process; - LttvAttributeType type; + LttvAttributeType type; - LttvAttributeValue value; + LttvAttributeValue value; - LttvAttributeName name; + LttvAttributeName name; - gboolean is_named; + gboolean is_named; - tracefiles_tree = lttv_attribute_find_subdir(container, - LTTV_STATE_TRACEFILES); - g_object_ref(G_OBJECT(tracefiles_tree)); - lttv_attribute_remove_by_name(container, LTTV_STATE_TRACEFILES); + tracefiles_tree = lttv_attribute_find_subdir(container, + LTTV_STATE_TRACEFILES); + g_object_ref(G_OBJECT(tracefiles_tree)); + lttv_attribute_remove_by_name(container, LTTV_STATE_TRACEFILES); - type = lttv_attribute_get_by_name(container, LTTV_STATE_PROCESSES, - &value); - g_assert(type == LTTV_POINTER); - lttv_state_free_process_table(*(value.v_pointer)); - *(value.v_pointer) = NULL; - lttv_attribute_remove_by_name(container, LTTV_STATE_PROCESSES); + type = lttv_attribute_get_by_name(container, LTTV_STATE_PROCESSES, + &value); + g_assert(type == LTTV_POINTER); + lttv_state_free_process_table(*(value.v_pointer)); + *(value.v_pointer) = NULL; + lttv_attribute_remove_by_name(container, LTTV_STATE_PROCESSES); - /* Free running processes array */ - type = lttv_attribute_get_by_name(container, LTTV_STATE_RUNNING_PROCESS, - &value); - g_assert(type == LTTV_POINTER); - running_process = *(value.v_pointer); - g_free(running_process); + /* Free running processes array */ + type = lttv_attribute_get_by_name(container, LTTV_STATE_RUNNING_PROCESS, + &value); + g_assert(type == LTTV_POINTER); + running_process = *(value.v_pointer); + g_free(running_process); - /* free cpu resource states */ - type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_CPUS_COUNT, &value); - g_assert(type == LTTV_UINT); - nb_cpus = *value.v_uint; - type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_CPUS, &value); - g_assert(type == LTTV_POINTER); - lttv_state_free_cpu_states(*(value.v_pointer), nb_cpus); + /* free cpu resource states */ + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_CPUS_COUNT, &value); + g_assert(type == LTTV_UINT); + nb_cpus = *value.v_uint; + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_CPUS, &value); + g_assert(type == LTTV_POINTER); + lttv_state_free_cpu_states(*(value.v_pointer), nb_cpus); - /* free irq resource states */ - nb_irqs = self->name_tables->nb_irqs; - type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_IRQS, &value); - g_assert(type == LTTV_POINTER); - lttv_state_free_irq_states(*(value.v_pointer), nb_irqs); + /* free irq resource states */ + nb_irqs = self->name_tables->nb_irqs; + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_IRQS, &value); + g_assert(type == LTTV_POINTER); + lttv_state_free_irq_states(*(value.v_pointer), nb_irqs); - /* free softirq resource states */ - nb_soft_irqs = self->name_tables->nb_soft_irqs; - type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_SOFT_IRQS, &value); - g_assert(type == LTTV_POINTER); - lttv_state_free_soft_irq_states(*(value.v_pointer), nb_soft_irqs); + /* free softirq resource states */ + nb_soft_irqs = self->name_tables->nb_soft_irqs; + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_SOFT_IRQS, &value); + g_assert(type == LTTV_POINTER); + lttv_state_free_soft_irq_states(*(value.v_pointer), nb_soft_irqs); - /* free the blkdev states */ - type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_BLKDEVS, &value); - g_assert(type == LTTV_POINTER); - lttv_state_free_blkdev_hashtable(*(value.v_pointer)); + /* free the blkdev states */ + type = lttv_attribute_get_by_name(container, LTTV_STATE_RESOURCE_BLKDEVS, &value); + g_assert(type == LTTV_POINTER); + lttv_state_free_blkdev_hashtable(*(value.v_pointer)); - nb_tracefile = self->parent.tracefiles->len; + nb_tracefile = self->parent.tracefiles->len; - for(i = 0 ; i < nb_tracefile ; i++) { - tfcs = - LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, - LttvTracefileContext*, i)); - type = lttv_attribute_get(tracefiles_tree, i, &name, &value, &is_named); - g_assert(type == LTTV_GOBJECT); - tracefile_tree = *((LttvAttribute **)(value.v_gobject)); + for(i = 0 ; i < nb_tracefile ; i++) { + tfcs = + LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, + LttvTracefileContext*, i)); + type = lttv_attribute_get(tracefiles_tree, i, &name, &value, &is_named); + g_assert(type == LTTV_GOBJECT); + tracefile_tree = *((LttvAttribute **)(value.v_gobject)); - type = lttv_attribute_get_by_name(tracefile_tree, LTTV_STATE_EVENT, - &value); - g_assert(type == LTTV_POINTER); - if(*(value.v_pointer) != NULL) g_free(*(value.v_pointer)); - } - g_object_unref(G_OBJECT(tracefiles_tree)); + type = lttv_attribute_get_by_name(tracefile_tree, LTTV_STATE_EVENT, + &value); + g_assert(type == LTTV_POINTER); + if(*(value.v_pointer) != NULL) g_free(*(value.v_pointer)); + } + g_object_unref(G_OBJECT(tracefiles_tree)); } static void free_saved_state(LttvTraceState *self) { - guint i, nb; + guint i, nb; - LttvAttributeType type; + LttvAttributeType type; - LttvAttributeValue value; + LttvAttributeValue value; - LttvAttributeName name; + LttvAttributeName name; - gboolean is_named; + gboolean is_named; - LttvAttribute *saved_states; + LttvAttribute *saved_states; - saved_states = lttv_attribute_find_subdir(self->parent.t_a, - LTTV_STATE_SAVED_STATES); + saved_states = lttv_attribute_find_subdir(self->parent.t_a, + LTTV_STATE_SAVED_STATES); - nb = lttv_attribute_get_number(saved_states); - for(i = 0 ; i < nb ; i++) { - type = lttv_attribute_get(saved_states, i, &name, &value, &is_named); - g_assert(type == LTTV_GOBJECT); - state_saved_free(self, *((LttvAttribute **)value.v_gobject)); - } + nb = lttv_attribute_get_number(saved_states); + for(i = 0 ; i < nb ; i++) { + type = lttv_attribute_get(saved_states, i, &name, &value, &is_named); + g_assert(type == LTTV_GOBJECT); + state_saved_free(self, *((LttvAttribute **)value.v_gobject)); + } - lttv_attribute_remove_by_name(self->parent.t_a, LTTV_STATE_SAVED_STATES); + lttv_attribute_remove_by_name(self->parent.t_a, LTTV_STATE_SAVED_STATES); } -static void -create_max_time(LttvTraceState *tcs) +static void create_max_time(LttvTraceState *tcs) { - LttvAttributeValue v; + LttvAttributeValue v; - lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_SAVED_STATES_TIME, - LTTV_POINTER, &v); - g_assert(*(v.v_pointer) == NULL); - *(v.v_pointer) = g_new(LttTime,1); - *((LttTime *)*(v.v_pointer)) = ltt_time_zero; + lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_SAVED_STATES_TIME, + LTTV_POINTER, &v); + g_assert(*(v.v_pointer) == NULL); + *(v.v_pointer) = g_new(LttTime,1); + *((LttTime *)*(v.v_pointer)) = ltt_time_zero; } -static void -get_max_time(LttvTraceState *tcs) +static void get_max_time(LttvTraceState *tcs) { - LttvAttributeValue v; + LttvAttributeValue v; - lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_SAVED_STATES_TIME, - LTTV_POINTER, &v); - g_assert(*(v.v_pointer) != NULL); - tcs->max_time_state_recomputed_in_seek = (LttTime *)*(v.v_pointer); + lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_SAVED_STATES_TIME, + LTTV_POINTER, &v); + g_assert(*(v.v_pointer) != NULL); + tcs->max_time_state_recomputed_in_seek = (LttTime *)*(v.v_pointer); } -static void -free_max_time(LttvTraceState *tcs) +static void free_max_time(LttvTraceState *tcs) { - LttvAttributeValue v; + LttvAttributeValue v; - lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_SAVED_STATES_TIME, - LTTV_POINTER, &v); - g_free(*(v.v_pointer)); - *(v.v_pointer) = NULL; + lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_SAVED_STATES_TIME, + LTTV_POINTER, &v); + g_free(*(v.v_pointer)); + *(v.v_pointer) = NULL; } -static void -create_name_tables(LttvTraceState *tcs) +static void create_name_tables(LttvTraceState *tcs) { - int i; + int i; + + GString *fe_name = g_string_new(""); - GString *fe_name = g_string_new(""); + LttvNameTables *name_tables = g_new(LttvNameTables, 1); - LttvNameTables *name_tables = g_new(LttvNameTables, 1); + LttvAttributeValue v; - LttvAttributeValue v; + GArray *hooks; - GArray *hooks; + lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_NAME_TABLES, + LTTV_POINTER, &v); + g_assert(*(v.v_pointer) == NULL); + *(v.v_pointer) = name_tables; - lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_NAME_TABLES, - LTTV_POINTER, &v); - g_assert(*(v.v_pointer) == NULL); - *(v.v_pointer) = name_tables; + hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 1); - hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 1); + if(!lttv_trace_find_hook(tcs->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SYSCALL_ENTRY, + FIELD_ARRAY(LTT_FIELD_SYSCALL_ID), + NULL, NULL, &hooks)) { - if(!lttv_trace_find_hook(tcs->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SYSCALL_ENTRY, - FIELD_ARRAY(LTT_FIELD_SYSCALL_ID), - NULL, NULL, &hooks)) { - -// th = lttv_trace_hook_get_first(&th); -// -// t = ltt_field_type(lttv_trace_get_hook_field(th, 0)); -// nb = ltt_type_element_number(t); -// -// name_tables->syscall_names = g_new(GQuark, nb); -// name_tables->nb_syscalls = nb; +// th = lttv_trace_hook_get_first(&th); // -// for(i = 0 ; i < nb ; i++) { -// name_tables->syscall_names[i] = ltt_enum_string_get(t, i); -// if(!name_tables->syscall_names[i]) { -// GString *string = g_string_new(""); -// g_string_printf(string, "syscall %u", i); -// name_tables->syscall_names[i] = g_quark_from_string(string->str); -// g_string_free(string, TRUE); -// } -// } - - name_tables->nb_syscalls = 256; - name_tables->syscall_names = g_new(GQuark, 256); - for(i = 0 ; i < 256 ; i++) { - g_string_printf(fe_name, "syscall %d", i); - name_tables->syscall_names[i] = g_quark_from_string(fe_name->str); - } - } else { - name_tables->syscall_names = NULL; - name_tables->nb_syscalls = 0; - } - lttv_trace_hook_remove_all(&hooks); - - if(!lttv_trace_find_hook(tcs->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_TRAP_ENTRY, - FIELD_ARRAY(LTT_FIELD_TRAP_ID), - NULL, NULL, &hooks) || - !lttv_trace_find_hook(tcs->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_PAGE_FAULT_ENTRY, - FIELD_ARRAY(LTT_FIELD_TRAP_ID), - NULL, NULL, &hooks)) { - -// th = lttv_trace_hook_get_first(&th); +// t = ltt_field_type(lttv_trace_get_hook_field(th, 0)); +// nb = ltt_type_element_number(t); // -// t = ltt_field_type(lttv_trace_get_hook_field(th, 0)); -// //nb = ltt_type_element_number(t); +// name_tables->syscall_names = g_new(GQuark, nb); +// name_tables->nb_syscalls = nb; // -// name_tables->trap_names = g_new(GQuark, nb); -// for(i = 0 ; i < nb ; i++) { -// name_tables->trap_names[i] = g_quark_from_string( -// ltt_enum_string_get(t, i)); -// } - - name_tables->nb_traps = 256; - name_tables->trap_names = g_new(GQuark, 256); - for(i = 0 ; i < 256 ; i++) { - g_string_printf(fe_name, "trap %d", i); - name_tables->trap_names[i] = g_quark_from_string(fe_name->str); - } - } else { - name_tables->trap_names = NULL; - name_tables->nb_traps = 0; - } - lttv_trace_hook_remove_all(&hooks); - - if(!lttv_trace_find_hook(tcs->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_IRQ_ENTRY, - FIELD_ARRAY(LTT_FIELD_IRQ_ID), - NULL, NULL, &hooks)) { - - /* - name_tables->irq_names = g_new(GQuark, nb); - for(i = 0 ; i < nb ; i++) { - name_tables->irq_names[i] = g_quark_from_string(ltt_enum_string_get(t, i)); - } - */ - /* FIXME: LttvIRQState *irq_states should become a g_array */ - /* temp fix: increase from 256 to 512 default size */ - - name_tables->nb_irqs = 512; - name_tables->irq_names = g_new(GQuark, 512); - for(i = 0 ; i < 512 ; i++) { - g_string_printf(fe_name, "irq %d", i); - name_tables->irq_names[i] = g_quark_from_string(fe_name->str); - } - } else { - name_tables->nb_irqs = 0; - name_tables->irq_names = NULL; - } - lttv_trace_hook_remove_all(&hooks); - /* - name_tables->soft_irq_names = g_new(GQuark, nb); - for(i = 0 ; i < nb ; i++) { - name_tables->soft_irq_names[i] = g_quark_from_string(ltt_enum_string_get(t, i)); - } - */ - - /* the kernel is limited to 32 statically defined softirqs */ - name_tables->nb_soft_irqs = 32; - name_tables->soft_irq_names = g_new(GQuark, name_tables->nb_soft_irqs); - for(i = 0 ; i < name_tables->nb_soft_irqs ; i++) { - g_string_printf(fe_name, "softirq %d", i); - name_tables->soft_irq_names[i] = g_quark_from_string(fe_name->str); - } - g_array_free(hooks, TRUE); - - g_string_free(fe_name, TRUE); +// for(i = 0 ; i < nb ; i++) { +// name_tables->syscall_names[i] = ltt_enum_string_get(t, i); +// if(!name_tables->syscall_names[i]) { +// GString *string = g_string_new(""); +// g_string_printf(string, "syscall %u", i); +// name_tables->syscall_names[i] = g_quark_from_string(string->str); +// g_string_free(string, TRUE); +// } +// } + + name_tables->nb_syscalls = 256; + name_tables->syscall_names = g_new(GQuark, 256); + for(i = 0 ; i < 256 ; i++) { + g_string_printf(fe_name, "syscall %d", i); + name_tables->syscall_names[i] = g_quark_from_string(fe_name->str); + } + } else { + name_tables->syscall_names = NULL; + name_tables->nb_syscalls = 0; + } + lttv_trace_hook_remove_all(&hooks); + + if(!lttv_trace_find_hook(tcs->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_TRAP_ENTRY, + FIELD_ARRAY(LTT_FIELD_TRAP_ID), + NULL, NULL, &hooks) || + !lttv_trace_find_hook(tcs->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_PAGE_FAULT_ENTRY, + FIELD_ARRAY(LTT_FIELD_TRAP_ID), + NULL, NULL, &hooks)) { + +// th = lttv_trace_hook_get_first(&th); +// +// t = ltt_field_type(lttv_trace_get_hook_field(th, 0)); +// //nb = ltt_type_element_number(t); +// +// name_tables->trap_names = g_new(GQuark, nb); +// for(i = 0 ; i < nb ; i++) { +// name_tables->trap_names[i] = g_quark_from_string( +// ltt_enum_string_get(t, i)); +// } + + name_tables->nb_traps = 256; + name_tables->trap_names = g_new(GQuark, 256); + for(i = 0 ; i < 256 ; i++) { + g_string_printf(fe_name, "trap %d", i); + name_tables->trap_names[i] = g_quark_from_string(fe_name->str); + } + } else { + name_tables->trap_names = NULL; + name_tables->nb_traps = 0; + } + lttv_trace_hook_remove_all(&hooks); + + if(!lttv_trace_find_hook(tcs->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_IRQ_ENTRY, + FIELD_ARRAY(LTT_FIELD_IRQ_ID), + NULL, NULL, &hooks)) { + + /* + name_tables->irq_names = g_new(GQuark, nb); + for(i = 0 ; i < nb ; i++) { + name_tables->irq_names[i] = g_quark_from_string(ltt_enum_string_get(t, i)); + } + */ + /* FIXME: LttvIRQState *irq_states should become a g_array */ + /* temp fix: increase from 256 to 512 default size */ + + name_tables->nb_irqs = 512; + name_tables->irq_names = g_new(GQuark, 512); + for(i = 0 ; i < 512 ; i++) { + g_string_printf(fe_name, "irq %d", i); + name_tables->irq_names[i] = g_quark_from_string(fe_name->str); + } + } else { + name_tables->nb_irqs = 0; + name_tables->irq_names = NULL; + } + lttv_trace_hook_remove_all(&hooks); + /* + name_tables->soft_irq_names = g_new(GQuark, nb); + for(i = 0 ; i < nb ; i++) { + name_tables->soft_irq_names[i] = g_quark_from_string(ltt_enum_string_get(t, i)); + } + */ + + /* the kernel is limited to 32 statically defined softirqs */ + name_tables->nb_soft_irqs = 32; + name_tables->soft_irq_names = g_new(GQuark, name_tables->nb_soft_irqs); + for(i = 0 ; i < name_tables->nb_soft_irqs ; i++) { + g_string_printf(fe_name, "softirq %d", i); + name_tables->soft_irq_names[i] = g_quark_from_string(fe_name->str); + } + g_array_free(hooks, TRUE); + + g_string_free(fe_name, TRUE); #if (__WORDSIZE == 32) - name_tables->kprobe_hash = g_hash_table_new_full(guint64_hash, guint64_equal, - g_free, NULL); + name_tables->kprobe_hash = g_hash_table_new_full(guint64_hash, guint64_equal, + g_free, NULL); #else - name_tables->kprobe_hash = g_hash_table_new(g_direct_hash, g_direct_equal); + name_tables->kprobe_hash = g_hash_table_new(g_direct_hash, g_direct_equal); #endif } -static void -get_name_tables(LttvTraceState *tcs) +static void get_name_tables(LttvTraceState *tcs) { - LttvAttributeValue v; + LttvAttributeValue v; - lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_NAME_TABLES, - LTTV_POINTER, &v); - g_assert(*(v.v_pointer) != NULL); - tcs->name_tables = (LttvNameTables *)*(v.v_pointer); + lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_NAME_TABLES, + LTTV_POINTER, &v); + g_assert(*(v.v_pointer) != NULL); + tcs->name_tables = (LttvNameTables *)*(v.v_pointer); } -static void -free_name_tables(LttvTraceState *tcs) +static void free_name_tables(LttvTraceState *tcs) { - LttvNameTables *name_tables; + LttvNameTables *name_tables; - LttvAttributeValue v; + LttvAttributeValue v; - lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_NAME_TABLES, - LTTV_POINTER, &v); - name_tables = (LttvNameTables *)*(v.v_pointer); - *(v.v_pointer) = NULL; + lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_NAME_TABLES, + LTTV_POINTER, &v); + name_tables = (LttvNameTables *)*(v.v_pointer); + *(v.v_pointer) = NULL; // g_free(name_tables->eventtype_names); - if(name_tables->syscall_names) g_free(name_tables->syscall_names); - if(name_tables->trap_names) g_free(name_tables->trap_names); - if(name_tables->irq_names) g_free(name_tables->irq_names); - if(name_tables->soft_irq_names) g_free(name_tables->soft_irq_names); - g_hash_table_destroy(name_tables->kprobe_hash); - g_free(name_tables); + if(name_tables->syscall_names) g_free(name_tables->syscall_names); + if(name_tables->trap_names) g_free(name_tables->trap_names); + if(name_tables->irq_names) g_free(name_tables->irq_names); + if(name_tables->soft_irq_names) g_free(name_tables->soft_irq_names); + g_hash_table_destroy(name_tables->kprobe_hash); + g_free(name_tables); } #ifdef HASH_TABLE_DEBUG static void test_process(gpointer key, gpointer value, gpointer user_data) { - LttvProcessState *process = (LttvProcessState *)value; - - /* Test for process corruption */ - guint stack_len = process->execution_stack->len; + LttvProcessState *process = (LttvProcessState *)value; + + /* Test for process corruption */ + guint stack_len = process->execution_stack->len; } static void hash_table_check(GHashTable *table) { - g_hash_table_foreach(table, test_process, NULL); + g_hash_table_foreach(table, test_process, NULL); } @@ -2152,316 +2152,315 @@ static void hash_table_check(GHashTable *table) /* clears the stack and sets the state passed as argument */ static void cpu_set_base_mode(LttvCPUState *cpust, LttvCPUMode state) { - g_array_set_size(cpust->mode_stack, 1); - ((GQuark *)cpust->mode_stack->data)[0] = state; + g_array_set_size(cpust->mode_stack, 1); + ((GQuark *)cpust->mode_stack->data)[0] = state; } static void cpu_push_mode(LttvCPUState *cpust, LttvCPUMode state) { - g_array_set_size(cpust->mode_stack, cpust->mode_stack->len + 1); - ((GQuark *)cpust->mode_stack->data)[cpust->mode_stack->len - 1] = state; + g_array_set_size(cpust->mode_stack, cpust->mode_stack->len + 1); + ((GQuark *)cpust->mode_stack->data)[cpust->mode_stack->len - 1] = state; } static void cpu_pop_mode(LttvCPUState *cpust) { - if(cpust->mode_stack->len <= 1) - cpu_set_base_mode(cpust, LTTV_CPU_UNKNOWN); - else - g_array_set_size(cpust->mode_stack, cpust->mode_stack->len - 1); + if(cpust->mode_stack->len <= 1) + cpu_set_base_mode(cpust, LTTV_CPU_UNKNOWN); + else + g_array_set_size(cpust->mode_stack, cpust->mode_stack->len - 1); } /* clears the stack and sets the state passed as argument */ static void bdev_set_base_mode(LttvBdevState *bdevst, LttvBdevMode state) { - g_array_set_size(bdevst->mode_stack, 1); - ((GQuark *)bdevst->mode_stack->data)[0] = state; + g_array_set_size(bdevst->mode_stack, 1); + ((GQuark *)bdevst->mode_stack->data)[0] = state; } static void bdev_push_mode(LttvBdevState *bdevst, LttvBdevMode state) { - g_array_set_size(bdevst->mode_stack, bdevst->mode_stack->len + 1); - ((GQuark *)bdevst->mode_stack->data)[bdevst->mode_stack->len - 1] = state; + g_array_set_size(bdevst->mode_stack, bdevst->mode_stack->len + 1); + ((GQuark *)bdevst->mode_stack->data)[bdevst->mode_stack->len - 1] = state; } static void bdev_pop_mode(LttvBdevState *bdevst) { - if(bdevst->mode_stack->len <= 1) - bdev_set_base_mode(bdevst, LTTV_BDEV_UNKNOWN); - else - g_array_set_size(bdevst->mode_stack, bdevst->mode_stack->len - 1); + if(bdevst->mode_stack->len <= 1) + bdev_set_base_mode(bdevst, LTTV_BDEV_UNKNOWN); + else + g_array_set_size(bdevst->mode_stack, bdevst->mode_stack->len - 1); } static void irq_set_base_mode(LttvIRQState *irqst, LttvIRQMode state) { - g_array_set_size(irqst->mode_stack, 1); - ((GQuark *)irqst->mode_stack->data)[0] = state; + g_array_set_size(irqst->mode_stack, 1); + ((GQuark *)irqst->mode_stack->data)[0] = state; } static void irq_push_mode(LttvIRQState *irqst, LttvIRQMode state) { - g_array_set_size(irqst->mode_stack, irqst->mode_stack->len + 1); - ((GQuark *)irqst->mode_stack->data)[irqst->mode_stack->len - 1] = state; + g_array_set_size(irqst->mode_stack, irqst->mode_stack->len + 1); + ((GQuark *)irqst->mode_stack->data)[irqst->mode_stack->len - 1] = state; } static void irq_pop_mode(LttvIRQState *irqst) { - if(irqst->mode_stack->len <= 1) - irq_set_base_mode(irqst, LTTV_IRQ_UNKNOWN); - else - g_array_set_size(irqst->mode_stack, irqst->mode_stack->len - 1); + if(irqst->mode_stack->len <= 1) + irq_set_base_mode(irqst, LTTV_IRQ_UNKNOWN); + else + g_array_set_size(irqst->mode_stack, irqst->mode_stack->len - 1); } static void push_state(LttvTracefileState *tfs, LttvExecutionMode t, - guint state_id) + guint state_id) { - LttvExecutionState *es; - - LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; - guint cpu = tfs->cpu; + LttvExecutionState *es; + + LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; + guint cpu = tfs->cpu; #ifdef HASH_TABLE_DEBUG - hash_table_check(ts->processes); + hash_table_check(ts->processes); #endif - LttvProcessState *process = ts->running_process[cpu]; + LttvProcessState *process = ts->running_process[cpu]; - guint depth = process->execution_stack->len; + guint depth = process->execution_stack->len; - process->execution_stack = - g_array_set_size(process->execution_stack, depth + 1); - /* Keep in sync */ - process->state = - &g_array_index(process->execution_stack, LttvExecutionState, depth - 1); - - es = &g_array_index(process->execution_stack, LttvExecutionState, depth); - es->t = t; - es->n = state_id; - es->entry = es->change = tfs->parent.timestamp; - es->cum_cpu_time = ltt_time_zero; - es->s = process->state->s; - process->state = es; + process->execution_stack = + g_array_set_size(process->execution_stack, depth + 1); + /* Keep in sync */ + process->state = + &g_array_index(process->execution_stack, LttvExecutionState, depth - 1); + + es = &g_array_index(process->execution_stack, LttvExecutionState, depth); + es->t = t; + es->n = state_id; + es->entry = es->change = tfs->parent.timestamp; + es->cum_cpu_time = ltt_time_zero; + es->s = process->state->s; + process->state = es; } /* pop state * return 1 when empty, else 0 */ -int lttv_state_pop_state_cleanup(LttvProcessState *process, - LttvTracefileState *tfs) +int +lttv_state_pop_state_cleanup(LttvProcessState *process, LttvTracefileState *tfs) { - guint depth = process->execution_stack->len; + guint depth = process->execution_stack->len; - if(depth == 1){ - return 1; - } + if(depth == 1){ + return 1; + } - process->execution_stack = - g_array_set_size(process->execution_stack, depth - 1); - process->state = &g_array_index(process->execution_stack, LttvExecutionState, - depth - 2); - process->state->change = tfs->parent.timestamp; - - return 0; + process->execution_stack = + g_array_set_size(process->execution_stack, depth - 1); + process->state = &g_array_index(process->execution_stack, LttvExecutionState, + depth - 2); + process->state->change = tfs->parent.timestamp; + + return 0; } static void pop_state(LttvTracefileState *tfs, LttvExecutionMode t) { - guint cpu = tfs->cpu; - LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; - LttvProcessState *process = ts->running_process[cpu]; - - guint depth = process->execution_stack->len; - - if(process->state->t != t){ - g_info("Different execution mode type (%lu.%09lu): ignore it\n", - tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); - g_info("process state has %s when pop_int is %s\n", - g_quark_to_string(process->state->t), - g_quark_to_string(t)); - g_info("{ %u, %u, %s, %s, %s }\n", - process->pid, - process->ppid, - g_quark_to_string(process->name), - g_quark_to_string(process->brand), - g_quark_to_string(process->state->s)); - return; - } - - if(depth == 1){ - g_info("Trying to pop last state on stack (%lu.%09lu): ignore it\n", - tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); - return; - } - - process->execution_stack = - g_array_set_size(process->execution_stack, depth - 1); - process->state = &g_array_index(process->execution_stack, LttvExecutionState, - depth - 2); - process->state->change = tfs->parent.timestamp; + guint cpu = tfs->cpu; + LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; + LttvProcessState *process = ts->running_process[cpu]; + + guint depth = process->execution_stack->len; + + if(process->state->t != t){ + g_info("Different execution mode type (%lu.%09lu): ignore it\n", + tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); + g_info("process state has %s when pop_int is %s\n", + g_quark_to_string(process->state->t), + g_quark_to_string(t)); + g_info("{ %u, %u, %s, %s, %s }\n", + process->pid, + process->ppid, + g_quark_to_string(process->name), + g_quark_to_string(process->brand), + g_quark_to_string(process->state->s)); + return; + } + + if(depth == 1){ + g_info("Trying to pop last state on stack (%lu.%09lu): ignore it\n", + tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); + return; + } + + process->execution_stack = + g_array_set_size(process->execution_stack, depth - 1); + process->state = &g_array_index(process->execution_stack, LttvExecutionState, + depth - 2); + process->state->change = tfs->parent.timestamp; } struct search_result { - const LttTime *time; /* Requested time */ - LttTime *best; /* Best result */ + const LttTime *time; /* Requested time */ + LttTime *best; /* Best result */ }; static gint search_usertrace(gconstpointer a, gconstpointer b) { - const LttTime *elem_time = (const LttTime*)a; - /* Explicit non const cast */ - struct search_result *res = (struct search_result *)b; - - if(ltt_time_compare(*elem_time, *(res->time)) < 0) { - /* The usertrace was created before the schedchange */ - /* Get larger keys */ - return 1; - } else if(ltt_time_compare(*elem_time, *(res->time)) >= 0) { - /* The usertrace was created after the schedchange time */ - /* Get smaller keys */ - if(res->best) { - if(ltt_time_compare(*elem_time, *res->best) < 0) { - res->best = (LttTime *)elem_time; - } - } else { - res->best = (LttTime *)elem_time; - } - return -1; - } - return 0; + const LttTime *elem_time = (const LttTime*)a; + /* Explicit non const cast */ + struct search_result *res = (struct search_result *)b; + + if(ltt_time_compare(*elem_time, *(res->time)) < 0) { + /* The usertrace was created before the schedchange */ + /* Get larger keys */ + return 1; + } else if(ltt_time_compare(*elem_time, *(res->time)) >= 0) { + /* The usertrace was created after the schedchange time */ + /* Get smaller keys */ + if(res->best) { + if(ltt_time_compare(*elem_time, *res->best) < 0) { + res->best = (LttTime *)elem_time; + } + } else { + res->best = (LttTime *)elem_time; + } + return -1; + } + return 0; } static LttvTracefileState *ltt_state_usertrace_find(LttvTraceState *tcs, - guint pid, const LttTime *timestamp) -{ - LttvTracefileState *tfs = NULL; - struct search_result res; - /* Find the usertrace associated with a pid and time interval. - * Search in the usertraces by PID (within a hash) and then, for each - * corresponding element of the array, find the first one with creation - * timestamp the lowest, but higher or equal to "timestamp". */ - res.time = timestamp; - res.best = NULL; - GTree *usertrace_tree = g_hash_table_lookup(tcs->usertraces, - GUINT_TO_POINTER(pid)); - if(usertrace_tree) { - g_tree_search(usertrace_tree, search_usertrace, &res); - if(res.best) - tfs = g_tree_lookup(usertrace_tree, res.best); - } - - return tfs; + guint pid, const LttTime *timestamp) +{ + LttvTracefileState *tfs = NULL; + struct search_result res; + /* Find the usertrace associated with a pid and time interval. + * Search in the usertraces by PID (within a hash) and then, for each + * corresponding element of the array, find the first one with creation + * timestamp the lowest, but higher or equal to "timestamp". */ + res.time = timestamp; + res.best = NULL; + GTree *usertrace_tree = g_hash_table_lookup(tcs->usertraces, + GUINT_TO_POINTER(pid)); + if(usertrace_tree) { + g_tree_search(usertrace_tree, search_usertrace, &res); + if(res.best) + tfs = g_tree_lookup(usertrace_tree, res.best); + } + + return tfs; } /* Return a new and initialized LttvProcessState structure */ -LttvProcessState * -lttv_state_create_process(LttvTraceState *tcs, LttvProcessState *parent, - guint cpu, guint pid, guint tgid, GQuark name, const LttTime *timestamp) -{ - LttvProcessState *process = g_new(LttvProcessState, 1); - - LttvExecutionState *es; - - char buffer[128]; - - process->pid = pid; - process->tgid = tgid; - process->cpu = cpu; - process->name = name; - process->brand = LTTV_STATE_UNBRANDED; - //process->last_cpu = tfs->cpu_name; - //process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf); - process->type = LTTV_STATE_USER_THREAD; - process->usertrace = ltt_state_usertrace_find(tcs, pid, timestamp); - process->current_function = 0; //function 0x0 by default. - - g_info("Process %u, core %p", process->pid, process); - g_hash_table_insert(tcs->processes, process, process); - - if(parent) { - process->ppid = parent->pid; - process->creation_time = *timestamp; - } - - /* No parent. This process exists but we are missing all information about - its creation. The birth time is set to zero but we remember the time of - insertion */ - - else { - process->ppid = 0; - process->creation_time = ltt_time_zero; - } - - process->insertion_time = *timestamp; - sprintf(buffer,"%d-%lu.%lu",pid, process->creation_time.tv_sec, - process->creation_time.tv_nsec); - process->pid_time = g_quark_from_string(buffer); - process->cpu = cpu; - process->free_events = 0; - //process->last_cpu = tfs->cpu_name; - //process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf); - process->execution_stack = g_array_sized_new(FALSE, FALSE, - sizeof(LttvExecutionState), PREALLOCATED_EXECUTION_STACK); - process->execution_stack = g_array_set_size(process->execution_stack, 2); - es = process->state = &g_array_index(process->execution_stack, - LttvExecutionState, 0); - es->t = LTTV_STATE_USER_MODE; - es->n = LTTV_STATE_SUBMODE_NONE; - es->entry = *timestamp; - //g_assert(timestamp->tv_sec != 0); - es->change = *timestamp; - es->cum_cpu_time = ltt_time_zero; - es->s = LTTV_STATE_RUN; - - es = process->state = &g_array_index(process->execution_stack, - LttvExecutionState, 1); - es->t = LTTV_STATE_SYSCALL; - es->n = LTTV_STATE_SUBMODE_NONE; - es->entry = *timestamp; - //g_assert(timestamp->tv_sec != 0); - es->change = *timestamp; - es->cum_cpu_time = ltt_time_zero; - es->s = LTTV_STATE_WAIT_FORK; - - /* Allocate an empty function call stack. If it's empty, use 0x0. */ - process->user_stack = g_array_sized_new(FALSE, FALSE, - sizeof(guint64), 0); - - process->fds = g_hash_table_new(g_direct_hash, g_direct_equal); - - return process; -} - -LttvProcessState *lttv_state_find_process(LttvTraceState *ts, guint cpu, - guint pid) -{ - LttvProcessState key; - LttvProcessState *process; - - key.pid = pid; - key.cpu = cpu; - process = g_hash_table_lookup(ts->processes, &key); - return process; +LttvProcessState *lttv_state_create_process(LttvTraceState *tcs, + LttvProcessState *parent, guint cpu, guint pid, + guint tgid, GQuark name, const LttTime *timestamp) +{ + LttvProcessState *process = g_new(LttvProcessState, 1); + + LttvExecutionState *es; + + char buffer[128]; + + process->pid = pid; + process->tgid = tgid; + process->cpu = cpu; + process->name = name; + process->brand = LTTV_STATE_UNBRANDED; + //process->last_cpu = tfs->cpu_name; + //process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf); + process->type = LTTV_STATE_USER_THREAD; + process->usertrace = ltt_state_usertrace_find(tcs, pid, timestamp); + process->current_function = 0; //function 0x0 by default. + + g_info("Process %u, core %p", process->pid, process); + g_hash_table_insert(tcs->processes, process, process); + + if(parent) { + process->ppid = parent->pid; + process->creation_time = *timestamp; + } + + /* No parent. This process exists but we are missing all information about + its creation. The birth time is set to zero but we remember the time of + insertion */ + + else { + process->ppid = 0; + process->creation_time = ltt_time_zero; + } + + process->insertion_time = *timestamp; + sprintf(buffer,"%d-%lu.%lu",pid, process->creation_time.tv_sec, + process->creation_time.tv_nsec); + process->pid_time = g_quark_from_string(buffer); + process->cpu = cpu; + process->free_events = 0; + //process->last_cpu = tfs->cpu_name; + //process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf); + process->execution_stack = g_array_sized_new(FALSE, FALSE, + sizeof(LttvExecutionState), PREALLOCATED_EXECUTION_STACK); + process->execution_stack = g_array_set_size(process->execution_stack, 2); + es = process->state = &g_array_index(process->execution_stack, + LttvExecutionState, 0); + es->t = LTTV_STATE_USER_MODE; + es->n = LTTV_STATE_SUBMODE_NONE; + es->entry = *timestamp; + //g_assert(timestamp->tv_sec != 0); + es->change = *timestamp; + es->cum_cpu_time = ltt_time_zero; + es->s = LTTV_STATE_RUN; + + es = process->state = &g_array_index(process->execution_stack, + LttvExecutionState, 1); + es->t = LTTV_STATE_SYSCALL; + es->n = LTTV_STATE_SUBMODE_NONE; + es->entry = *timestamp; + //g_assert(timestamp->tv_sec != 0); + es->change = *timestamp; + es->cum_cpu_time = ltt_time_zero; + es->s = LTTV_STATE_WAIT_FORK; + + /* Allocate an empty function call stack. If it's empty, use 0x0. */ + process->user_stack = g_array_sized_new(FALSE, FALSE, + sizeof(guint64), 0); + + process->fds = g_hash_table_new(g_direct_hash, g_direct_equal); + + return process; } LttvProcessState * -lttv_state_find_process_or_create(LttvTraceState *ts, guint cpu, guint pid, - const LttTime *timestamp) -{ - LttvProcessState *process = lttv_state_find_process(ts, cpu, pid); - LttvExecutionState *es; - - /* Put ltt_time_zero creation time for unexisting processes */ - if(unlikely(process == NULL)) { - process = lttv_state_create_process(ts, - NULL, cpu, pid, 0, LTTV_STATE_UNNAMED, timestamp); - /* We are not sure is it's a kernel thread or normal thread, put the - * bottom stack state to unknown */ - process->execution_stack = - g_array_set_size(process->execution_stack, 1); - process->state = es = - &g_array_index(process->execution_stack, LttvExecutionState, 0); - es->t = LTTV_STATE_MODE_UNKNOWN; - es->s = LTTV_STATE_UNNAMED; - } - return process; +lttv_state_find_process(LttvTraceState *ts, guint cpu, guint pid) +{ + LttvProcessState key; + LttvProcessState *process; + + key.pid = pid; + key.cpu = cpu; + process = g_hash_table_lookup(ts->processes, &key); + return process; +} + +LttvProcessState *lttv_state_find_process_or_create(LttvTraceState *ts, + guint cpu, guint pid, const LttTime *timestamp) +{ + LttvProcessState *process = lttv_state_find_process(ts, cpu, pid); + LttvExecutionState *es; + + /* Put ltt_time_zero creation time for unexisting processes */ + if(unlikely(process == NULL)) { + process = lttv_state_create_process(ts, + NULL, cpu, pid, 0, LTTV_STATE_UNNAMED, timestamp); + /* We are not sure is it's a kernel thread or normal thread, put the + * bottom stack state to unknown */ + process->execution_stack = + g_array_set_size(process->execution_stack, 1); + process->state = es = + &g_array_index(process->execution_stack, LttvExecutionState, 0); + es->t = LTTV_STATE_MODE_UNKNOWN; + es->s = LTTV_STATE_UNNAMED; + } + return process; } /* FIXME : this function should be called when we receive an event telling that @@ -2473,844 +2472,845 @@ lttv_state_find_process_or_create(LttvTraceState *ts, guint cpu, guint pid, */ static int exit_process(LttvTracefileState *tfs, LttvProcessState *process) { - LttvTraceState *ts = LTTV_TRACE_STATE(tfs->parent.t_context); - LttvProcessState key; + LttvTraceState *ts = LTTV_TRACE_STATE(tfs->parent.t_context); + LttvProcessState key; - /* Wait for both schedule with exit dead and process free to happen. - * They can happen in any order. */ - if (++(process->free_events) < 2) - return 0; + /* Wait for both schedule with exit dead and process free to happen. + * They can happen in any order. */ + if (++(process->free_events) < 2) + return 0; - key.pid = process->pid; - key.cpu = process->cpu; - g_hash_table_remove(ts->processes, &key); - g_array_free(process->execution_stack, TRUE); - g_array_free(process->user_stack, TRUE); + key.pid = process->pid; + key.cpu = process->cpu; + g_hash_table_remove(ts->processes, &key); + g_array_free(process->execution_stack, TRUE); + g_array_free(process->user_stack, TRUE); - /* the following also clears the content */ - g_hash_table_destroy(process->fds); + /* the following also clears the content */ + g_hash_table_destroy(process->fds); - g_free(process); - return 1; + g_free(process); + return 1; } static void free_process_state(gpointer key, gpointer value,gpointer user_data) { - g_array_free(((LttvProcessState *)value)->execution_stack, TRUE); - g_array_free(((LttvProcessState *)value)->user_stack, TRUE); + g_array_free(((LttvProcessState *)value)->execution_stack, TRUE); + g_array_free(((LttvProcessState *)value)->user_stack, TRUE); - /* the following also clears the content */ - g_hash_table_destroy(((LttvProcessState *)value)->fds); + /* the following also clears the content */ + g_hash_table_destroy(((LttvProcessState *)value)->fds); - g_free(value); + g_free(value); } static void lttv_state_free_process_table(GHashTable *processes) { - g_hash_table_foreach(processes, free_process_state, NULL); - g_hash_table_destroy(processes); + g_hash_table_foreach(processes, free_process_state, NULL); + g_hash_table_destroy(processes); } static gboolean syscall_entry(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - guint cpu = s->cpu; - LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; - LttvProcessState *process = ts->running_process[cpu]; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - struct marker_field *f = lttv_trace_get_hook_field(th, 0); - LttvExecutionSubmode submode; - LttvNameTables *nt = ((LttvTraceState *)(s->parent.t_context))->name_tables; + LttvTracefileState *s = (LttvTracefileState *)call_data; + guint cpu = s->cpu; + LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; + LttvProcessState *process = ts->running_process[cpu]; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + struct marker_field *f = lttv_trace_get_hook_field(th, 0); + LttvExecutionSubmode submode; + LttvNameTables *nt = ((LttvTraceState *)(s->parent.t_context))->name_tables; - guint syscall = ltt_event_get_unsigned(e, f); - expand_syscall_table(ts, syscall); - submode = nt->syscall_names[syscall]; - /* There can be no system call from PID 0 : unknown state */ - if(process->pid != 0) - push_state(s, LTTV_STATE_SYSCALL, submode); - return FALSE; + guint syscall = ltt_event_get_unsigned(e, f); + expand_syscall_table(ts, syscall); + submode = nt->syscall_names[syscall]; + /* There can be no system call from PID 0 : unknown state */ + if(process->pid != 0) + push_state(s, LTTV_STATE_SYSCALL, submode); + return FALSE; } static gboolean syscall_exit(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - guint cpu = s->cpu; - LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; - LttvProcessState *process = ts->running_process[cpu]; + LttvTracefileState *s = (LttvTracefileState *)call_data; + guint cpu = s->cpu; + LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; + LttvProcessState *process = ts->running_process[cpu]; - /* There can be no system call from PID 0 : unknown state */ - if(process->pid != 0) - pop_state(s, LTTV_STATE_SYSCALL); - return FALSE; + /* There can be no system call from PID 0 : unknown state */ + if(process->pid != 0) + pop_state(s, LTTV_STATE_SYSCALL); + return FALSE; } static gboolean trap_entry(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - struct marker_field *f = lttv_trace_get_hook_field(th, 0); - LttvNameTables *nt = ((LttvTraceState *)(s->parent.t_context))->name_tables; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + struct marker_field *f = lttv_trace_get_hook_field(th, 0); + LttvNameTables *nt = ((LttvTraceState *)(s->parent.t_context))->name_tables; - LttvExecutionSubmode submode; + LttvExecutionSubmode submode; - guint64 trap = ltt_event_get_long_unsigned(e, f); + guint64 trap = ltt_event_get_long_unsigned(e, f); - expand_trap_table(ts, trap); + expand_trap_table(ts, trap); - submode = nt->trap_names[trap]; + submode = nt->trap_names[trap]; - push_state(s, LTTV_STATE_TRAP, submode); + push_state(s, LTTV_STATE_TRAP, submode); - /* update cpu status */ - cpu_push_mode(s->cpu_state, LTTV_CPU_TRAP); + /* update cpu status */ + cpu_push_mode(s->cpu_state, LTTV_CPU_TRAP); - /* update trap status */ - g_array_append_val(s->cpu_state->trap_stack, trap); - ts->trap_states[trap].running++; + /* update trap status */ + g_array_append_val(s->cpu_state->trap_stack, trap); + ts->trap_states[trap].running++; - return FALSE; + return FALSE; } static gboolean trap_exit(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; - pop_state(s, LTTV_STATE_TRAP); + pop_state(s, LTTV_STATE_TRAP); - /* update cpu status */ - cpu_pop_mode(s->cpu_state); + /* update cpu status */ + cpu_pop_mode(s->cpu_state); - /* update trap status */ - if (s->cpu_state->trap_stack->len > 0) { - gint last = g_array_index(s->cpu_state->trap_stack, gint, s->cpu_state->trap_stack->len-1); - if(ts->trap_states[last].running) - ts->trap_states[last].running--; - g_array_remove_index(s->cpu_state->trap_stack, s->cpu_state->trap_stack->len-1); - } - return FALSE; + /* update trap status */ + if (s->cpu_state->trap_stack->len > 0) { + gint last = g_array_index(s->cpu_state->trap_stack, gint, + s->cpu_state->trap_stack->len-1); + if(ts->trap_states[last].running) + ts->trap_states[last].running--; + g_array_remove_index(s->cpu_state->trap_stack, + s->cpu_state->trap_stack->len-1); + } + return FALSE; } static gboolean irq_entry(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - //guint8 ev_id = ltt_event_eventtype_id(e); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - struct marker_field *f = lttv_trace_get_hook_field(th, 0); - LttvNameTables *nt = ((LttvTraceState *)(s->parent.t_context))->name_tables; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + //guint8 ev_id = ltt_event_eventtype_id(e); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + struct marker_field *f = lttv_trace_get_hook_field(th, 0); + LttvNameTables *nt = ((LttvTraceState *)(s->parent.t_context))->name_tables; - LttvExecutionSubmode submode; - guint64 irq = ltt_event_get_long_unsigned(e, f); + LttvExecutionSubmode submode; + guint64 irq = ltt_event_get_long_unsigned(e, f); - expand_irq_table(ts, irq); + expand_irq_table(ts, irq); - submode = nt->irq_names[irq]; + submode = nt->irq_names[irq]; - /* Do something with the info about being in user or system mode when int? */ - push_state(s, LTTV_STATE_IRQ, submode); + /* Do something with the info about being in user or system mode when int? */ + push_state(s, LTTV_STATE_IRQ, submode); - /* update cpu status */ - cpu_push_mode(s->cpu_state, LTTV_CPU_IRQ); + /* update cpu status */ + cpu_push_mode(s->cpu_state, LTTV_CPU_IRQ); - /* update irq status */ - g_array_append_val(s->cpu_state->irq_stack, irq); - irq_push_mode(&ts->irq_states[irq], LTTV_IRQ_BUSY); + /* update irq status */ + g_array_append_val(s->cpu_state->irq_stack, irq); + irq_push_mode(&ts->irq_states[irq], LTTV_IRQ_BUSY); - return FALSE; + return FALSE; } static gboolean soft_irq_exit(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; - pop_state(s, LTTV_STATE_SOFT_IRQ); + pop_state(s, LTTV_STATE_SOFT_IRQ); - /* update cpu status */ - cpu_pop_mode(s->cpu_state); + /* update cpu status */ + cpu_pop_mode(s->cpu_state); - /* update softirq status */ - if (s->cpu_state->softirq_stack->len > 0) { - gint last = g_array_index(s->cpu_state->softirq_stack, gint, s->cpu_state->softirq_stack->len-1); - if(ts->soft_irq_states[last].running) - ts->soft_irq_states[last].running--; - g_array_remove_index(s->cpu_state->softirq_stack, s->cpu_state->softirq_stack->len-1); - } - return FALSE; + /* update softirq status */ + if (s->cpu_state->softirq_stack->len > 0) { + gint last = g_array_index(s->cpu_state->softirq_stack, gint, s->cpu_state->softirq_stack->len-1); + if(ts->soft_irq_states[last].running) + ts->soft_irq_states[last].running--; + g_array_remove_index(s->cpu_state->softirq_stack, s->cpu_state->softirq_stack->len-1); + } + return FALSE; } static gboolean irq_exit(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; - pop_state(s, LTTV_STATE_IRQ); + pop_state(s, LTTV_STATE_IRQ); - /* update cpu status */ - cpu_pop_mode(s->cpu_state); + /* update cpu status */ + cpu_pop_mode(s->cpu_state); - /* update irq status */ - if (s->cpu_state->irq_stack->len > 0) { - gint last = g_array_index(s->cpu_state->irq_stack, gint, s->cpu_state->irq_stack->len-1); - g_array_remove_index(s->cpu_state->irq_stack, s->cpu_state->irq_stack->len-1); - irq_pop_mode(&ts->irq_states[last]); - } + /* update irq status */ + if (s->cpu_state->irq_stack->len > 0) { + gint last = g_array_index(s->cpu_state->irq_stack, gint, s->cpu_state->irq_stack->len-1); + g_array_remove_index(s->cpu_state->irq_stack, s->cpu_state->irq_stack->len-1); + irq_pop_mode(&ts->irq_states[last]); + } - return FALSE; + return FALSE; } static gboolean soft_irq_raise(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - //guint8 ev_id = ltt_event_eventtype_id(e); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - struct marker_field *f = lttv_trace_get_hook_field(th, 0); - LttvNameTables *nt = ((LttvTraceState *)(s->parent.t_context))->name_tables; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + //guint8 ev_id = ltt_event_eventtype_id(e); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + struct marker_field *f = lttv_trace_get_hook_field(th, 0); + LttvNameTables *nt = ((LttvTraceState *)(s->parent.t_context))->name_tables; - LttvExecutionSubmode submode; - guint64 softirq = ltt_event_get_long_unsigned(e, f); - guint64 nb_softirqs = nt->nb_soft_irqs; + LttvExecutionSubmode submode; + guint64 softirq = ltt_event_get_long_unsigned(e, f); + guint64 nb_softirqs = nt->nb_soft_irqs; - if(softirq < nb_softirqs) { - submode = nt->soft_irq_names[softirq]; - } else { - /* Fixup an incomplete irq table */ - GString *string = g_string_new(""); - g_string_printf(string, "softirq %" PRIu64, softirq); - submode = g_quark_from_string(string->str); - g_string_free(string, TRUE); - } + if(softirq < nb_softirqs) { + submode = nt->soft_irq_names[softirq]; + } else { + /* Fixup an incomplete irq table */ + GString *string = g_string_new(""); + g_string_printf(string, "softirq %" PRIu64, softirq); + submode = g_quark_from_string(string->str); + g_string_free(string, TRUE); + } - /* update softirq status */ - /* a soft irq raises are not cumulative */ - ts->soft_irq_states[softirq].pending=1; + /* update softirq status */ + /* a soft irq raises are not cumulative */ + ts->soft_irq_states[softirq].pending=1; - return FALSE; + return FALSE; } static gboolean soft_irq_entry(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - //guint8 ev_id = ltt_event_eventtype_id(e); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - struct marker_field *f = lttv_trace_get_hook_field(th, 0); - LttvExecutionSubmode submode; - guint64 softirq = ltt_event_get_long_unsigned(e, f); - expand_soft_irq_table(ts, softirq); - LttvNameTables *nt = ((LttvTraceState *)(s->parent.t_context))->name_tables; - submode = nt->soft_irq_names[softirq]; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + //guint8 ev_id = ltt_event_eventtype_id(e); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + struct marker_field *f = lttv_trace_get_hook_field(th, 0); + LttvExecutionSubmode submode; + guint64 softirq = ltt_event_get_long_unsigned(e, f); + expand_soft_irq_table(ts, softirq); + LttvNameTables *nt = ((LttvTraceState *)(s->parent.t_context))->name_tables; + submode = nt->soft_irq_names[softirq]; - /* Do something with the info about being in user or system mode when int? */ - push_state(s, LTTV_STATE_SOFT_IRQ, submode); + /* Do something with the info about being in user or system mode when int? */ + push_state(s, LTTV_STATE_SOFT_IRQ, submode); - /* update cpu status */ - cpu_push_mode(s->cpu_state, LTTV_CPU_SOFT_IRQ); + /* update cpu status */ + cpu_push_mode(s->cpu_state, LTTV_CPU_SOFT_IRQ); - /* update softirq status */ - g_array_append_val(s->cpu_state->softirq_stack, softirq); - if(ts->soft_irq_states[softirq].pending) - ts->soft_irq_states[softirq].pending--; - ts->soft_irq_states[softirq].running++; + /* update softirq status */ + g_array_append_val(s->cpu_state->softirq_stack, softirq); + if(ts->soft_irq_states[softirq].pending) + ts->soft_irq_states[softirq].pending--; + ts->soft_irq_states[softirq].running++; - return FALSE; + return FALSE; } static gboolean enum_interrupt(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; - LttvNameTables *nt = ts->name_tables; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - //guint8 ev_id = ltt_event_eventtype_id(e); - LttvTraceHook *th = (LttvTraceHook *)hook_data; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; + LttvNameTables *nt = ts->name_tables; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + //guint8 ev_id = ltt_event_eventtype_id(e); + LttvTraceHook *th = (LttvTraceHook *)hook_data; - GQuark action = g_quark_from_string(ltt_event_get_string(e, - lttv_trace_get_hook_field(th, 0))); - guint irq = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 1)); + GQuark action = g_quark_from_string(ltt_event_get_string(e, + lttv_trace_get_hook_field(th, 0))); + guint irq = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 1)); - expand_irq_table(ts, irq); - nt->irq_names[irq] = action; + expand_irq_table(ts, irq); + nt->irq_names[irq] = action; - return FALSE; + return FALSE; } static gboolean bdev_request_issue(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - //guint8 ev_id = ltt_event_eventtype_id(e); - LttvTraceHook *th = (LttvTraceHook *)hook_data; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + //guint8 ev_id = ltt_event_eventtype_id(e); + LttvTraceHook *th = (LttvTraceHook *)hook_data; - guint major = ltt_event_get_long_unsigned(e, - lttv_trace_get_hook_field(th, 0)); - guint minor = ltt_event_get_long_unsigned(e, - lttv_trace_get_hook_field(th, 1)); - guint oper = ltt_event_get_long_unsigned(e, - lttv_trace_get_hook_field(th, 2)); - guint16 devcode = MKDEV(major,minor); + guint major = ltt_event_get_long_unsigned(e, + lttv_trace_get_hook_field(th, 0)); + guint minor = ltt_event_get_long_unsigned(e, + lttv_trace_get_hook_field(th, 1)); + guint oper = ltt_event_get_long_unsigned(e, + lttv_trace_get_hook_field(th, 2)); + guint16 devcode = MKDEV(major,minor); - /* have we seen this block device before? */ - gpointer bdev = get_hashed_bdevstate(ts, devcode); + /* have we seen this block device before? */ + gpointer bdev = get_hashed_bdevstate(ts, devcode); - if(oper == 0) - bdev_push_mode(bdev, LTTV_BDEV_BUSY_READING); - else - bdev_push_mode(bdev, LTTV_BDEV_BUSY_WRITING); + if(oper == 0) + bdev_push_mode(bdev, LTTV_BDEV_BUSY_READING); + else + bdev_push_mode(bdev, LTTV_BDEV_BUSY_WRITING); - return FALSE; + return FALSE; } static gboolean bdev_request_complete(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - LttvTraceHook *th = (LttvTraceHook *)hook_data; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + LttvTraceHook *th = (LttvTraceHook *)hook_data; - guint major = ltt_event_get_long_unsigned(e, - lttv_trace_get_hook_field(th, 0)); - guint minor = ltt_event_get_long_unsigned(e, - lttv_trace_get_hook_field(th, 1)); - //guint oper = ltt_event_get_long_unsigned(e, - // lttv_trace_get_hook_field(th, 2)); - guint16 devcode = MKDEV(major,minor); + guint major = ltt_event_get_long_unsigned(e, + lttv_trace_get_hook_field(th, 0)); + guint minor = ltt_event_get_long_unsigned(e, + lttv_trace_get_hook_field(th, 1)); + //guint oper = ltt_event_get_long_unsigned(e, + // lttv_trace_get_hook_field(th, 2)); + guint16 devcode = MKDEV(major,minor); - /* have we seen this block device before? */ - gpointer bdev = get_hashed_bdevstate(ts, devcode); + /* have we seen this block device before? */ + gpointer bdev = get_hashed_bdevstate(ts, devcode); - /* update block device */ - bdev_pop_mode(bdev); + /* update block device */ + bdev_pop_mode(bdev); - return FALSE; + return FALSE; } static void push_function(LttvTracefileState *tfs, guint64 funcptr) { - guint64 *new_func; - - LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; - guint cpu = tfs->cpu; - LttvProcessState *process = ts->running_process[cpu]; + guint64 *new_func; + + LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; + guint cpu = tfs->cpu; + LttvProcessState *process = ts->running_process[cpu]; - guint depth = process->user_stack->len; + guint depth = process->user_stack->len; - process->user_stack = - g_array_set_size(process->user_stack, depth + 1); - - new_func = &g_array_index(process->user_stack, guint64, depth); - *new_func = funcptr; - process->current_function = funcptr; + process->user_stack = + g_array_set_size(process->user_stack, depth + 1); + + new_func = &g_array_index(process->user_stack, guint64, depth); + *new_func = funcptr; + process->current_function = funcptr; } static void pop_function(LttvTracefileState *tfs, guint64 funcptr) { - guint cpu = tfs->cpu; - LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; - LttvProcessState *process = ts->running_process[cpu]; - - if(process->current_function != funcptr){ - g_info("Different functions (%lu.%09lu): ignore it\n", - tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); - g_info("process state has %" PRIu64 " when pop_function is %" PRIu64 "\n", - process->current_function, funcptr); - g_info("{ %u, %u, %s, %s, %s }\n", - process->pid, - process->ppid, - g_quark_to_string(process->name), - g_quark_to_string(process->brand), - g_quark_to_string(process->state->s)); - return; - } - guint depth = process->user_stack->len; - - if(depth == 0){ - g_info("Trying to pop last function on stack (%lu.%09lu): ignore it\n", - tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); - return; - } - - process->user_stack = - g_array_set_size(process->user_stack, depth - 1); - process->current_function = - g_array_index(process->user_stack, guint64, depth - 2); + guint cpu = tfs->cpu; + LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; + LttvProcessState *process = ts->running_process[cpu]; + + if(process->current_function != funcptr){ + g_info("Different functions (%lu.%09lu): ignore it\n", + tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); + g_info("process state has %" PRIu64 " when pop_function is %" PRIu64 "\n", + process->current_function, funcptr); + g_info("{ %u, %u, %s, %s, %s }\n", + process->pid, + process->ppid, + g_quark_to_string(process->name), + g_quark_to_string(process->brand), + g_quark_to_string(process->state->s)); + return; + } + guint depth = process->user_stack->len; + + if(depth == 0){ + g_info("Trying to pop last function on stack (%lu.%09lu): ignore it\n", + tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec); + return; + } + + process->user_stack = + g_array_set_size(process->user_stack, depth - 1); + process->current_function = + g_array_index(process->user_stack, guint64, depth - 2); } static gboolean function_entry(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - //guint8 ev_id = ltt_event_eventtype_id(e); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - struct marker_field *f = lttv_trace_get_hook_field(th, 0); - guint64 funcptr = ltt_event_get_long_unsigned(e, f); + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + //guint8 ev_id = ltt_event_eventtype_id(e); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + struct marker_field *f = lttv_trace_get_hook_field(th, 0); + guint64 funcptr = ltt_event_get_long_unsigned(e, f); - push_function(s, funcptr); - return FALSE; + push_function(s, funcptr); + return FALSE; } static gboolean function_exit(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - //guint8 ev_id = ltt_event_eventtype_id(e); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - struct marker_field *f = lttv_trace_get_hook_field(th, 0); - guint64 funcptr = ltt_event_get_long_unsigned(e, f); + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + //guint8 ev_id = ltt_event_eventtype_id(e); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + struct marker_field *f = lttv_trace_get_hook_field(th, 0); + guint64 funcptr = ltt_event_get_long_unsigned(e, f); - pop_function(s, funcptr); - return FALSE; + pop_function(s, funcptr); + return FALSE; } static gboolean dump_syscall(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; - LttvNameTables *nt = ts->name_tables; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - guint id; - guint64 address; - char *symbol; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; + LttvNameTables *nt = ts->name_tables; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + guint id; + guint64 address; + char *symbol; - id = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); - address = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 1)); - symbol = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 2)); + id = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); + address = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 1)); + symbol = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 2)); - expand_syscall_table(ts, id); - nt->syscall_names[id] = g_quark_from_string(symbol); + expand_syscall_table(ts, id); + nt->syscall_names[id] = g_quark_from_string(symbol); - return FALSE; + return FALSE; } static gboolean dump_kprobe(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - guint64 ip; - char *symbol; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + guint64 ip; + char *symbol; - ip = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 0)); - symbol = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 1)); + ip = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 0)); + symbol = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 1)); - expand_kprobe_table(ts, ip, symbol); + expand_kprobe_table(ts, ip, symbol); - return FALSE; + return FALSE; } static gboolean dump_softirq(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; - LttvNameTables *nt = ts->name_tables; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - guint id; - guint64 address; - char *symbol; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; + LttvNameTables *nt = ts->name_tables; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + guint id; + guint64 address; + char *symbol; - id = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); - address = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 1)); - symbol = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 2)); + id = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); + address = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 1)); + symbol = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 2)); - expand_soft_irq_table(ts, id); - nt->soft_irq_names[id] = g_quark_from_string(symbol); + expand_soft_irq_table(ts, id); + nt->soft_irq_names[id] = g_quark_from_string(symbol); - return FALSE; + return FALSE; } static gboolean sched_try_wakeup(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - LttvProcessState *process; - gint woken_pid; - guint woken_cpu; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + LttvProcessState *process; + gint woken_pid; + guint woken_cpu; - woken_pid = ltt_event_get_int(e, lttv_trace_get_hook_field(th, 0)); - woken_cpu = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 1)); + woken_pid = ltt_event_get_int(e, lttv_trace_get_hook_field(th, 0)); + woken_cpu = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 1)); - process = lttv_state_find_process_or_create( - (LttvTraceState*)s->parent.t_context, - woken_cpu, woken_pid, - &s->parent.timestamp); - process->state->s = LTTV_STATE_WAIT_CPU; - process->state->change = s->parent.timestamp; + process = lttv_state_find_process_or_create( + (LttvTraceState*)s->parent.t_context, + woken_cpu, woken_pid, + &s->parent.timestamp); + process->state->s = LTTV_STATE_WAIT_CPU; + process->state->change = s->parent.timestamp; - g_debug("Wakeup: process %d on CPU %u\n", woken_pid, woken_cpu); + g_debug("Wakeup: process %d on CPU %u\n", woken_pid, woken_cpu); - return FALSE; + return FALSE; } static gboolean schedchange(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - guint cpu = s->cpu; - LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; - LttvProcessState *process = ts->running_process[cpu]; - //LttvProcessState *old_process = ts->running_process[cpu]; - - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - guint pid_in, pid_out; - gint64 state_out; - - pid_out = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); - pid_in = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 1)); - state_out = ltt_event_get_long_int(e, lttv_trace_get_hook_field(th, 2)); - - if(likely(process != NULL)) { - - /* We could not know but it was not the idle process executing. - This should only happen at the beginning, before the first schedule - event, and when the initial information (current process for each CPU) - is missing. It is not obvious how we could, after the fact, compensate - the wrongly attributed statistics. */ - - //This test only makes sense once the state is known and if there is no - //missing events. We need to silently ignore schedchange coming after a - //process_free, or it causes glitches. (FIXME) - //if(unlikely(process->pid != pid_out)) { - // g_assert(process->pid == 0); - //} - if(process->pid == 0 - && process->state->t == LTTV_STATE_MODE_UNKNOWN) { - if(pid_out == 0) { - /* Scheduling out of pid 0 at beginning of the trace : - * we know for sure it is in syscall mode at this point. */ - g_assert(process->execution_stack->len == 1); - process->state->t = LTTV_STATE_SYSCALL; - process->state->s = LTTV_STATE_WAIT; - process->state->change = s->parent.timestamp; - process->state->entry = s->parent.timestamp; - } - } else { - if(unlikely(process->state->s == LTTV_STATE_EXIT)) { - process->state->s = LTTV_STATE_ZOMBIE; - process->state->change = s->parent.timestamp; - } else { - if(unlikely(state_out == 0)) process->state->s = LTTV_STATE_WAIT_CPU; - else process->state->s = LTTV_STATE_WAIT; - process->state->change = s->parent.timestamp; - } - - if(state_out == 32 || state_out == 64) { /* EXIT_DEAD || TASK_DEAD */ - /* see sched.h for states */ - if (!exit_process(s, process)) { - process->state->s = LTTV_STATE_DEAD; - process->state->change = s->parent.timestamp; + LttvTracefileState *s = (LttvTracefileState *)call_data; + guint cpu = s->cpu; + LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; + LttvProcessState *process = ts->running_process[cpu]; + //LttvProcessState *old_process = ts->running_process[cpu]; + + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + guint pid_in, pid_out; + gint64 state_out; + + pid_out = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); + pid_in = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 1)); + state_out = ltt_event_get_long_int(e, lttv_trace_get_hook_field(th, 2)); + + if(likely(process != NULL)) { + + /* We could not know but it was not the idle process executing. + This should only happen at the beginning, before the first schedule + event, and when the initial information (current process for each CPU) + is missing. It is not obvious how we could, after the fact, compensate + the wrongly attributed statistics. */ + + //This test only makes sense once the state is known and if there is no + //missing events. We need to silently ignore schedchange coming after a + //process_free, or it causes glitches. (FIXME) + //if(unlikely(process->pid != pid_out)) { + // g_assert(process->pid == 0); + //} + if(process->pid == 0 + && process->state->t == LTTV_STATE_MODE_UNKNOWN) { + if(pid_out == 0) { + /* Scheduling out of pid 0 at beginning of the trace : + * we know for sure it is in syscall mode at this point. */ + g_assert(process->execution_stack->len == 1); + process->state->t = LTTV_STATE_SYSCALL; + process->state->s = LTTV_STATE_WAIT; + process->state->change = s->parent.timestamp; + process->state->entry = s->parent.timestamp; + } + } else { + if(unlikely(process->state->s == LTTV_STATE_EXIT)) { + process->state->s = LTTV_STATE_ZOMBIE; + process->state->change = s->parent.timestamp; + } else { + if(unlikely(state_out == 0)) process->state->s = LTTV_STATE_WAIT_CPU; + else process->state->s = LTTV_STATE_WAIT; + process->state->change = s->parent.timestamp; + } + + if(state_out == 32 || state_out == 64) { /* EXIT_DEAD || TASK_DEAD */ + /* see sched.h for states */ + if (!exit_process(s, process)) { + process->state->s = LTTV_STATE_DEAD; + process->state->change = s->parent.timestamp; } - } - } - } - process = ts->running_process[cpu] = - lttv_state_find_process_or_create( - (LttvTraceState*)s->parent.t_context, - cpu, pid_in, - &s->parent.timestamp); - process->state->s = LTTV_STATE_RUN; - process->cpu = cpu; - if(process->usertrace) - process->usertrace->cpu = cpu; + } + } + } + process = ts->running_process[cpu] = lttv_state_find_process_or_create( + (LttvTraceState*)s->parent.t_context, + cpu, pid_in, + &s->parent.timestamp); + process->state->s = LTTV_STATE_RUN; + process->cpu = cpu; + if(process->usertrace) + process->usertrace->cpu = cpu; // process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)s)->tf); - process->state->change = s->parent.timestamp; - - /* update cpu status */ - if(pid_in == 0) - /* going to idle task */ - cpu_set_base_mode(s->cpu_state, LTTV_CPU_IDLE); - else { - /* scheduling a real task. - * we must be careful here: - * if we just schedule()'ed to a process that is - * in a trap, we must put the cpu in trap mode - */ - cpu_set_base_mode(s->cpu_state, LTTV_CPU_BUSY); - if(process->state->t == LTTV_STATE_TRAP) - cpu_push_mode(s->cpu_state, LTTV_CPU_TRAP); - } - - return FALSE; + process->state->change = s->parent.timestamp; + + /* update cpu status */ + if(pid_in == 0) + /* going to idle task */ + cpu_set_base_mode(s->cpu_state, LTTV_CPU_IDLE); + else { + /* scheduling a real task. + * we must be careful here: + * if we just schedule()'ed to a process that is + * in a trap, we must put the cpu in trap mode + */ + cpu_set_base_mode(s->cpu_state, LTTV_CPU_BUSY); + if(process->state->t == LTTV_STATE_TRAP) + cpu_push_mode(s->cpu_state, LTTV_CPU_TRAP); + } + + return FALSE; } static gboolean process_fork(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - guint parent_pid; - guint child_pid; /* In the Linux Kernel, there is one PID per thread. */ - guint child_tgid; /* tgid in the Linux kernel is the "real" POSIX PID. */ - //LttvProcessState *zombie_process; - guint cpu = s->cpu; - LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; - LttvProcessState *process = ts->running_process[cpu]; - LttvProcessState *child_process; - struct marker_field *f; - - /* Parent PID */ - parent_pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); - - /* Child PID */ - child_pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 1)); - s->parent.target_pid = child_pid; - - /* Child TGID */ - f = lttv_trace_get_hook_field(th, 2); - if (likely(f)) - child_tgid = ltt_event_get_unsigned(e, f); - else - child_tgid = 0; - - /* Mathieu : it seems like the process might have been scheduled in before the - * fork, and, in a rare case, might be the current process. This might happen - * in a SMP case where we don't have enough precision on the clocks. - * - * Test reenabled after precision fixes on time. (Mathieu) */ + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + guint parent_pid; + guint child_pid; /* In the Linux Kernel, there is one PID per thread. */ + guint child_tgid; /* tgid in the Linux kernel is the "real" POSIX PID. */ + //LttvProcessState *zombie_process; + guint cpu = s->cpu; + LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; + LttvProcessState *process = ts->running_process[cpu]; + LttvProcessState *child_process; + struct marker_field *f; + + /* Parent PID */ + parent_pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); + + /* Child PID */ + child_pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 1)); + s->parent.target_pid = child_pid; + + /* Child TGID */ + f = lttv_trace_get_hook_field(th, 2); + if (likely(f)) + child_tgid = ltt_event_get_unsigned(e, f); + else + child_tgid = 0; + + /* Mathieu : it seems like the process might have been scheduled in before the + * fork, and, in a rare case, might be the current process. This might happen + * in a SMP case where we don't have enough precision on the clocks. + * + * Test reenabled after precision fixes on time. (Mathieu) */ #if 0 - zombie_process = lttv_state_find_process(ts, ANY_CPU, child_pid); - - if(unlikely(zombie_process != NULL)) { - /* Reutilisation of PID. Only now we are sure that the old PID - * has been released. FIXME : should know when release_task happens instead. - */ - guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t); - guint i; - for(i=0; i< num_cpus; i++) { - g_assert(zombie_process != ts->running_process[i]); - } - - exit_process(s, zombie_process); - } + zombie_process = lttv_state_find_process(ts, ANY_CPU, child_pid); + + if(unlikely(zombie_process != NULL)) { + /* Reutilisation of PID. Only now we are sure that the old PID + * has been released. FIXME : should know when release_task happens instead. + */ + guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t); + guint i; + for(i=0; i< num_cpus; i++) { + g_assert(zombie_process != ts->running_process[i]); + } + + exit_process(s, zombie_process); + } #endif //0 - g_assert(process->pid != child_pid); - // FIXME : Add this test in the "known state" section - // g_assert(process->pid == parent_pid); - child_process = lttv_state_find_process(ts, ANY_CPU, child_pid); - if(child_process == NULL) { - child_process = lttv_state_create_process(ts, process, cpu, - child_pid, child_tgid, - LTTV_STATE_UNNAMED, &s->parent.timestamp); - } else { - /* The process has already been created : due to time imprecision between - * multiple CPUs : it has been scheduled in before creation. Note that we - * shouldn't have this kind of imprecision. - * - * Simply put a correct parent. - */ - g_error("Process %u has been created at [%lu.%09lu] " - "and inserted at [%lu.%09lu] before \n" - "fork on cpu %u[%lu.%09lu].\n" - "Probably an unsynchronized TSC problem on the traced machine.", - child_pid, - child_process->creation_time.tv_sec, - child_process->creation_time.tv_nsec, - child_process->insertion_time.tv_sec, - child_process->insertion_time.tv_nsec, - cpu, ltt_event_time(e).tv_sec, ltt_event_time(e).tv_nsec); - //g_assert(0); /* This is a problematic case : the process has been created - // before the fork event */ - child_process->ppid = process->pid; - child_process->tgid = child_tgid; - } - g_assert(child_process->name == LTTV_STATE_UNNAMED); - child_process->name = process->name; - child_process->brand = process->brand; - - return FALSE; + g_assert(process->pid != child_pid); + // FIXME : Add this test in the "known state" section + // g_assert(process->pid == parent_pid); + child_process = lttv_state_find_process(ts, ANY_CPU, child_pid); + if(child_process == NULL) { + child_process = lttv_state_create_process(ts, process, cpu, + child_pid, child_tgid, + LTTV_STATE_UNNAMED, &s->parent.timestamp); + } else { + /* The process has already been created : due to time imprecision between + * multiple CPUs : it has been scheduled in before creation. Note that we + * shouldn't have this kind of imprecision. + * + * Simply put a correct parent. + */ + g_error("Process %u has been created at [%lu.%09lu] " + "and inserted at [%lu.%09lu] before \n" + "fork on cpu %u[%lu.%09lu].\n" + "Probably an unsynchronized TSC problem on the traced machine.", + child_pid, + child_process->creation_time.tv_sec, + child_process->creation_time.tv_nsec, + child_process->insertion_time.tv_sec, + child_process->insertion_time.tv_nsec, + cpu, ltt_event_time(e).tv_sec, ltt_event_time(e).tv_nsec); + //g_assert(0); /* This is a problematic case : the process has been created + // before the fork event */ + child_process->ppid = process->pid; + child_process->tgid = child_tgid; + } + g_assert(child_process->name == LTTV_STATE_UNNAMED); + child_process->name = process->name; + child_process->brand = process->brand; + + return FALSE; } /* We stamp a newly created process as kernel_thread. * The thread should not be running yet. */ static gboolean process_kernel_thread(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - guint pid; - LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; - LttvProcessState *process; - LttvExecutionState *es; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + guint pid; + LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; + LttvProcessState *process; + LttvExecutionState *es; - /* PID */ - pid = (guint)ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 0)); - s->parent.target_pid = pid; + /* PID */ + pid = (guint)ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 0)); + s->parent.target_pid = pid; - process = lttv_state_find_process_or_create(ts, ANY_CPU, pid, - <t_time_zero); - if (process->state->s != LTTV_STATE_DEAD) { - process->execution_stack = - g_array_set_size(process->execution_stack, 1); - es = process->state = - &g_array_index(process->execution_stack, LttvExecutionState, 0); - es->t = LTTV_STATE_SYSCALL; - } - process->type = LTTV_STATE_KERNEL_THREAD; + process = lttv_state_find_process_or_create(ts, ANY_CPU, pid, + <t_time_zero); + if (process->state->s != LTTV_STATE_DEAD) { + process->execution_stack = + g_array_set_size(process->execution_stack, 1); + es = process->state = + &g_array_index(process->execution_stack, LttvExecutionState, 0); + es->t = LTTV_STATE_SYSCALL; + } + process->type = LTTV_STATE_KERNEL_THREAD; - return FALSE; + return FALSE; } static gboolean process_exit(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - guint pid; - LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; - LttvProcessState *process; // = ts->running_process[cpu]; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + guint pid; + LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; + LttvProcessState *process; // = ts->running_process[cpu]; - pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); - s->parent.target_pid = pid; + pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); + s->parent.target_pid = pid; - // FIXME : Add this test in the "known state" section - // g_assert(process->pid == pid); + // FIXME : Add this test in the "known state" section + // g_assert(process->pid == pid); - process = lttv_state_find_process(ts, ANY_CPU, pid); - if(likely(process != NULL)) { - process->state->s = LTTV_STATE_EXIT; - } - return FALSE; + process = lttv_state_find_process(ts, ANY_CPU, pid); + if(likely(process != NULL)) { + process->state->s = LTTV_STATE_EXIT; + } + return FALSE; } static gboolean process_free(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - guint release_pid; - LttvProcessState *process; - - /* PID of the process to release */ - release_pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); - s->parent.target_pid = release_pid; - - g_assert(release_pid != 0); - - process = lttv_state_find_process(ts, ANY_CPU, release_pid); - if(likely(process != NULL)) - exit_process(s, process); - return FALSE; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + guint release_pid; + LttvProcessState *process; + + /* PID of the process to release */ + release_pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); + s->parent.target_pid = release_pid; + + g_assert(release_pid != 0); + + process = lttv_state_find_process(ts, ANY_CPU, release_pid); + if(likely(process != NULL)) + exit_process(s, process); + return FALSE; //DISABLED - if(likely(process != NULL)) { - /* release_task is happening at kernel level : we can now safely release - * the data structure of the process */ - //This test is fun, though, as it may happen that - //at time t : CPU 0 : process_free - //at time t+150ns : CPU 1 : schedule out - //Clearly due to time imprecision, we disable it. (Mathieu) - //If this weird case happen, we have no choice but to put the - //Currently running process on the cpu to 0. - //I re-enable it following time precision fixes. (Mathieu) - //Well, in the case where an process is freed by a process on another CPU - //and still scheduled, it happens that this is the schedchange that will - //drop the last reference count. Do not free it here! - guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t); - guint i; - for(i=0; i< num_cpus; i++) { - //g_assert(process != ts->running_process[i]); - if(process == ts->running_process[i]) { - //ts->running_process[i] = lttv_state_find_process(ts, i, 0); - break; - } - } - if(i == num_cpus) /* process is not scheduled */ - exit_process(s, process); - } - - return FALSE; + if(likely(process != NULL)) { + /* release_task is happening at kernel level : we can now safely release + * the data structure of the process */ + //This test is fun, though, as it may happen that + //at time t : CPU 0 : process_free + //at time t+150ns : CPU 1 : schedule out + //Clearly due to time imprecision, we disable it. (Mathieu) + //If this weird case happen, we have no choice but to put the + //Currently running process on the cpu to 0. + //I re-enable it following time precision fixes. (Mathieu) + //Well, in the case where an process is freed by a process on another CPU + //and still scheduled, it happens that this is the schedchange that will + //drop the last reference count. Do not free it here! + guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t); + guint i; + for(i=0; i< num_cpus; i++) { + //g_assert(process != ts->running_process[i]); + if(process == ts->running_process[i]) { + //ts->running_process[i] = lttv_state_find_process(ts, i, 0); + break; + } + } + if(i == num_cpus) /* process is not scheduled */ + exit_process(s, process); + } + + return FALSE; } static gboolean process_exec(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - //gchar *name; - guint cpu = s->cpu; - LttvProcessState *process = ts->running_process[cpu]; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + //gchar *name; + guint cpu = s->cpu; + LttvProcessState *process = ts->running_process[cpu]; #if 0//how to use a sequence that must be transformed in a string - /* PID of the process to release */ - guint64 name_len = ltt_event_field_element_number(e, - lttv_trace_get_hook_field(th, 0)); - //name = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 0)); - LttField *child = ltt_event_field_element_select(e, - lttv_trace_get_hook_field(th, 0), 0); - gchar *name_begin = - (gchar*)(ltt_event_data(e)+ltt_event_field_offset(e, child)); - gchar *null_term_name = g_new(gchar, name_len+1); - memcpy(null_term_name, name_begin, name_len); - null_term_name[name_len] = '\0'; - process->name = g_quark_from_string(null_term_name); + /* PID of the process to release */ + guint64 name_len = ltt_event_field_element_number(e, + lttv_trace_get_hook_field(th, 0)); + //name = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 0)); + LttField *child = ltt_event_field_element_select(e, + lttv_trace_get_hook_field(th, 0), 0); + gchar *name_begin = + (gchar*)(ltt_event_data(e)+ltt_event_field_offset(e, child)); + gchar *null_term_name = g_new(gchar, name_len+1); + memcpy(null_term_name, name_begin, name_len); + null_term_name[name_len] = '\0'; + process->name = g_quark_from_string(null_term_name); #endif //0 - process->name = g_quark_from_string(ltt_event_get_string(e, - lttv_trace_get_hook_field(th, 0))); - process->brand = LTTV_STATE_UNBRANDED; - //g_free(null_term_name); - return FALSE; + process->name = g_quark_from_string(ltt_event_get_string(e, + lttv_trace_get_hook_field(th, 0))); + process->brand = LTTV_STATE_UNBRANDED; + //g_free(null_term_name); + return FALSE; } static gboolean thread_brand(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - gchar *name; - guint cpu = s->cpu; - LttvProcessState *process = ts->running_process[cpu]; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + gchar *name; + guint cpu = s->cpu; + LttvProcessState *process = ts->running_process[cpu]; - name = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 0)); - process->brand = g_quark_from_string(name); + name = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 0)); + process->brand = g_quark_from_string(name); - return FALSE; + return FALSE; } static gboolean fs_open(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - LttvTraceHook *th = (LttvTraceHook *)hook_data; - struct marker_field *f; - guint cpu = s->cpu; - int fd; - char *filename; - LttvProcessState *process = ts->running_process[cpu]; + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState *)s->parent.t_context; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + LttvTraceHook *th = (LttvTraceHook *)hook_data; + struct marker_field *f; + guint cpu = s->cpu; + int fd; + char *filename; + LttvProcessState *process = ts->running_process[cpu]; - f = lttv_trace_get_hook_field(th, 0); - fd = ltt_event_get_int(e, f); + f = lttv_trace_get_hook_field(th, 0); + fd = ltt_event_get_int(e, f); - f = lttv_trace_get_hook_field(th, 1); - filename = ltt_event_get_string(e, f); + f = lttv_trace_get_hook_field(th, 1); + filename = ltt_event_get_string(e, f); - g_hash_table_insert(process->fds, (gpointer)(long)fd, - (gpointer)(unsigned long)g_quark_from_string(filename)); + g_hash_table_insert(process->fds, (gpointer)(long)fd, + (gpointer)(unsigned long)g_quark_from_string(filename)); - return FALSE; + return FALSE; } static void print_stack(LttvProcessState *process) @@ -3319,619 +3319,616 @@ static void print_stack(LttvProcessState *process) int i; g_debug("Execution stack for process %u %s:\n", - process->pid, g_quark_to_string(process->name)); + process->pid, g_quark_to_string(process->name)); for (i = 0; i < process->execution_stack->len; i++) { es = &g_array_index(process->execution_stack, - LttvExecutionState, i); + LttvExecutionState, i); g_debug("Depth %d mode %s submode %s status %s\n", - i, g_quark_to_string(es->t), - g_quark_to_string(es->n), - g_quark_to_string(es->s)); + i, g_quark_to_string(es->t), + g_quark_to_string(es->n), + g_quark_to_string(es->s)); } } -static void fix_process(gpointer key, gpointer value, - gpointer user_data) -{ - LttvProcessState *process; - LttvExecutionState *es; - process = (LttvProcessState *)value; - LttTime *timestamp = (LttTime*)user_data; - - print_stack(process); - - if(process->type == LTTV_STATE_KERNEL_THREAD) { - es = &g_array_index(process->execution_stack, LttvExecutionState, 0); - if(es->t == LTTV_STATE_MODE_UNKNOWN) { - es->t = LTTV_STATE_SYSCALL; - es->n = LTTV_STATE_SUBMODE_NONE; - es->entry = *timestamp; - es->change = *timestamp; - es->cum_cpu_time = ltt_time_zero; - if(es->s == LTTV_STATE_UNNAMED) - es->s = LTTV_STATE_WAIT; - } - } else { - es = &g_array_index(process->execution_stack, LttvExecutionState, 0); - if(es->t == LTTV_STATE_MODE_UNKNOWN) { - es->t = LTTV_STATE_USER_MODE; - es->n = LTTV_STATE_SUBMODE_NONE; - es->entry = *timestamp; - //g_assert(timestamp->tv_sec != 0); - es->change = *timestamp; - es->cum_cpu_time = ltt_time_zero; - if(es->s == LTTV_STATE_UNNAMED) - es->s = LTTV_STATE_RUN; - - if(process->execution_stack->len == 1) { - /* Still in bottom unknown mode, means we either: - * - never did a system call - * - are scheduled out from user mode. - * May be either in user mode, syscall mode, running or waiting.*/ - /* CHECK : we may be tagging syscall mode when being user mode - * (should be fixed now) */ - if (es->s == LTTV_STATE_WAIT_CPU) { - /* nothing to do: scheduled out from userspace */ +static void fix_process(gpointer key, gpointer value, gpointer user_data) +{ + LttvProcessState *process; + LttvExecutionState *es; + process = (LttvProcessState *)value; + LttTime *timestamp = (LttTime*)user_data; + + print_stack(process); + + if(process->type == LTTV_STATE_KERNEL_THREAD) { + es = &g_array_index(process->execution_stack, LttvExecutionState, 0); + if(es->t == LTTV_STATE_MODE_UNKNOWN) { + es->t = LTTV_STATE_SYSCALL; + es->n = LTTV_STATE_SUBMODE_NONE; + es->entry = *timestamp; + es->change = *timestamp; + es->cum_cpu_time = ltt_time_zero; + if(es->s == LTTV_STATE_UNNAMED) + es->s = LTTV_STATE_WAIT; + } } else { - process->execution_stack = - g_array_set_size(process->execution_stack, 2); - es = process->state = &g_array_index(process->execution_stack, - LttvExecutionState, 1); - es->t = LTTV_STATE_SYSCALL; - es->n = LTTV_STATE_SUBMODE_NONE; - es->entry = *timestamp; - //g_assert(timestamp->tv_sec != 0); - es->change = *timestamp; - es->cum_cpu_time = ltt_time_zero; - if(es->s == LTTV_STATE_WAIT_FORK) - es->s = LTTV_STATE_WAIT; + es = &g_array_index(process->execution_stack, LttvExecutionState, 0); + if(es->t == LTTV_STATE_MODE_UNKNOWN) { + es->t = LTTV_STATE_USER_MODE; + es->n = LTTV_STATE_SUBMODE_NONE; + es->entry = *timestamp; + //g_assert(timestamp->tv_sec != 0); + es->change = *timestamp; + es->cum_cpu_time = ltt_time_zero; + if(es->s == LTTV_STATE_UNNAMED) + es->s = LTTV_STATE_RUN; + + if(process->execution_stack->len == 1) { + /* Still in bottom unknown mode, means we either: + * - never did a system call + * - are scheduled out from user mode. + * May be either in user mode, syscall mode, running or waiting.*/ + /* CHECK : we may be tagging syscall mode when being user mode + * (should be fixed now) */ + if (es->s == LTTV_STATE_WAIT_CPU) { + /* nothing to do: scheduled out from userspace */ + } else { + process->execution_stack = + g_array_set_size(process->execution_stack, 2); + es = process->state = &g_array_index(process->execution_stack, + LttvExecutionState, 1); + es->t = LTTV_STATE_SYSCALL; + es->n = LTTV_STATE_SUBMODE_NONE; + es->entry = *timestamp; + //g_assert(timestamp->tv_sec != 0); + es->change = *timestamp; + es->cum_cpu_time = ltt_time_zero; + if(es->s == LTTV_STATE_WAIT_FORK) + es->s = LTTV_STATE_WAIT; + } + } + } } - } - } - } } static gboolean statedump_end(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; - LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; - //LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - //LttvTraceHook *th = (LttvTraceHook *)hook_data; - - /* For all processes */ - /* if kernel thread, if stack[0] is unknown, set to syscall mode, wait */ - /* else, if stack[0] is unknown, set to user mode, running */ + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; + LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; + //LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + //LttvTraceHook *th = (LttvTraceHook *)hook_data; - g_hash_table_foreach(ts->processes, fix_process, &tfc->timestamp); + /* For all processes */ + /* if kernel thread, if stack[0] is unknown, set to syscall mode, wait */ + /* else, if stack[0] is unknown, set to user mode, running */ - return FALSE; + g_hash_table_foreach(ts->processes, fix_process, &tfc->timestamp); + + return FALSE; } static gboolean enum_process_state(void *hook_data, void *call_data) { - LttvTracefileState *s = (LttvTracefileState *)call_data; - LttEvent *e = ltt_tracefile_get_event(s->parent.tf); - //It's slow : optimise later by doing this before reading trace. - LttvTraceHook *th = (LttvTraceHook *)hook_data; - guint parent_pid; - guint pid; - guint tgid; - gchar * command; - guint cpu = s->cpu; - LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; - LttvProcessState *process = ts->running_process[cpu]; - LttvProcessState *parent_process; - struct marker_field *f; - GQuark type, mode, submode, status; - LttvExecutionState *es; - guint i, nb_cpus; - - /* PID */ - pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); - s->parent.target_pid = pid; - - /* Parent PID */ - parent_pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 1)); - - /* Command name */ - command = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 2)); - - /* type */ - f = lttv_trace_get_hook_field(th, 3); - type = ltt_enum_string_get(f, ltt_event_get_unsigned(e, f)); - - //FIXME: type is rarely used, enum must match possible types. - - /* mode */ - f = lttv_trace_get_hook_field(th, 4); - mode = ltt_enum_string_get(f,ltt_event_get_unsigned(e, f)); - - /* submode */ - f = lttv_trace_get_hook_field(th, 5); - submode = ltt_enum_string_get(f, ltt_event_get_unsigned(e, f)); - - /* status */ - f = lttv_trace_get_hook_field(th, 6); - status = ltt_enum_string_get(f, ltt_event_get_unsigned(e, f)); - - /* TGID */ - f = lttv_trace_get_hook_field(th, 7); - if(f) - tgid = ltt_event_get_unsigned(e, f); - else - tgid = 0; - - if(pid == 0) { - nb_cpus = ltt_trace_get_num_cpu(ts->parent.t); - for(i=0; ippid = parent_pid; - process->tgid = tgid; - process->name = g_quark_from_string(command); - es = - &g_array_index(process->execution_stack, LttvExecutionState, 0); - process->type = LTTV_STATE_KERNEL_THREAD; - } - - } else { - /* The process might exist if a process was forked while performing the - * state dump. */ - process = lttv_state_find_process(ts, ANY_CPU, pid); - if(process == NULL) { - parent_process = lttv_state_find_process(ts, ANY_CPU, parent_pid); - process = lttv_state_create_process(ts, parent_process, cpu, - pid, tgid, g_quark_from_string(command), - &s->parent.timestamp); - - /* Keep the stack bottom : a running user mode */ - /* Disabled because of inconsistencies in the current statedump states. */ - if(type == LTTV_STATE_KERNEL_THREAD) { - /* Only keep the bottom - * FIXME Kernel thread : can be in syscall or interrupt or trap. */ - /* Will cause expected trap when in fact being syscall (even after end of - * statedump event) - * Will cause expected interrupt when being syscall. (only before end of - * statedump event) */ - // This will cause a "popping last state on stack, ignoring it." - process->execution_stack = g_array_set_size(process->execution_stack, 1); - es = process->state = &g_array_index(process->execution_stack, - LttvExecutionState, 0); - process->type = LTTV_STATE_KERNEL_THREAD; - es->t = LTTV_STATE_MODE_UNKNOWN; - es->s = LTTV_STATE_UNNAMED; - es->n = LTTV_STATE_SUBMODE_UNKNOWN; - #if 0 - es->t = LTTV_STATE_SYSCALL; - es->s = status; - es->n = submode; - #endif //0 - } else { - /* User space process : - * bottom : user mode - * either currently running or scheduled out. - * can be scheduled out because interrupted in (user mode or in syscall) - * or because of an explicit call to the scheduler in syscall. Note that - * the scheduler call comes after the irq_exit, so never in interrupt - * context. */ - // temp workaround : set size to 1 : only have user mode bottom of stack. - // will cause g_info message of expected syscall mode when in fact being - // in user mode. Can also cause expected trap when in fact being user - // mode in the event of a page fault reenabling interrupts in the handler. - // Expected syscall and trap can also happen after the end of statedump - // This will cause a "popping last state on stack, ignoring it." - process->execution_stack = g_array_set_size(process->execution_stack, 1); - es = process->state = &g_array_index(process->execution_stack, - LttvExecutionState, 0); - es->t = LTTV_STATE_MODE_UNKNOWN; - es->s = LTTV_STATE_UNNAMED; - es->n = LTTV_STATE_SUBMODE_UNKNOWN; - #if 0 - es->t = LTTV_STATE_USER_MODE; - es->s = status; - es->n = submode; - #endif //0 - } - #if 0 - /* UNKNOWN STATE */ - { - es = process->state = &g_array_index(process->execution_stack, - LttvExecutionState, 1); - es->t = LTTV_STATE_MODE_UNKNOWN; - es->s = LTTV_STATE_UNNAMED; - es->n = LTTV_STATE_SUBMODE_UNKNOWN; - } - #endif //0 - } else { - /* The process has already been created : - * Probably was forked while dumping the process state or - * was simply scheduled in prior to get the state dump event. - */ - process->ppid = parent_pid; - process->tgid = tgid; - process->name = g_quark_from_string(command); - process->type = type; - es = - &g_array_index(process->execution_stack, LttvExecutionState, 0); + LttvTracefileState *s = (LttvTracefileState *)call_data; + LttEvent *e = ltt_tracefile_get_event(s->parent.tf); + //It's slow : optimise later by doing this before reading trace. + LttvTraceHook *th = (LttvTraceHook *)hook_data; + guint parent_pid; + guint pid; + guint tgid; + gchar * command; + guint cpu = s->cpu; + LttvTraceState *ts = (LttvTraceState*)s->parent.t_context; + LttvProcessState *process = ts->running_process[cpu]; + LttvProcessState *parent_process; + struct marker_field *f; + GQuark type, mode, submode, status; + LttvExecutionState *es; + guint i, nb_cpus; + + /* PID */ + pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); + s->parent.target_pid = pid; + + /* Parent PID */ + parent_pid = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 1)); + + /* Command name */ + command = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 2)); + + /* type */ + f = lttv_trace_get_hook_field(th, 3); + type = ltt_enum_string_get(f, ltt_event_get_unsigned(e, f)); + + //FIXME: type is rarely used, enum must match possible types. + + /* mode */ + f = lttv_trace_get_hook_field(th, 4); + mode = ltt_enum_string_get(f,ltt_event_get_unsigned(e, f)); + + /* submode */ + f = lttv_trace_get_hook_field(th, 5); + submode = ltt_enum_string_get(f, ltt_event_get_unsigned(e, f)); + + /* status */ + f = lttv_trace_get_hook_field(th, 6); + status = ltt_enum_string_get(f, ltt_event_get_unsigned(e, f)); + + /* TGID */ + f = lttv_trace_get_hook_field(th, 7); + if(f) + tgid = ltt_event_get_unsigned(e, f); + else + tgid = 0; + + if(pid == 0) { + nb_cpus = ltt_trace_get_num_cpu(ts->parent.t); + for(i=0; ippid = parent_pid; + process->tgid = tgid; + process->name = g_quark_from_string(command); + es = &g_array_index(process->execution_stack, LttvExecutionState, 0); + process->type = LTTV_STATE_KERNEL_THREAD; + } + + } else { + /* The process might exist if a process was forked while performing the + * state dump. */ + process = lttv_state_find_process(ts, ANY_CPU, pid); + if(process == NULL) { + parent_process = lttv_state_find_process(ts, ANY_CPU, parent_pid); + process = lttv_state_create_process(ts, parent_process, cpu, + pid, tgid, g_quark_from_string(command), + &s->parent.timestamp); + + /* Keep the stack bottom : a running user mode */ + /* Disabled because of inconsistencies in the current statedump states. */ + if(type == LTTV_STATE_KERNEL_THREAD) { + /* Only keep the bottom + * FIXME Kernel thread : can be in syscall or interrupt or trap. */ + /* Will cause expected trap when in fact being syscall (even after end of + * statedump event) + * Will cause expected interrupt when being syscall. (only before end of + * statedump event) */ + // This will cause a "popping last state on stack, ignoring it." + process->execution_stack = g_array_set_size(process->execution_stack, 1); + es = process->state = &g_array_index(process->execution_stack, + LttvExecutionState, 0); + process->type = LTTV_STATE_KERNEL_THREAD; + es->t = LTTV_STATE_MODE_UNKNOWN; + es->s = LTTV_STATE_UNNAMED; + es->n = LTTV_STATE_SUBMODE_UNKNOWN; +#if 0 + es->t = LTTV_STATE_SYSCALL; + es->s = status; + es->n = submode; +#endif //0 + } else { + /* User space process : + * bottom : user mode + * either currently running or scheduled out. + * can be scheduled out because interrupted in (user mode or in syscall) + * or because of an explicit call to the scheduler in syscall. Note that + * the scheduler call comes after the irq_exit, so never in interrupt + * context. */ + // temp workaround : set size to 1 : only have user mode bottom of stack. + // will cause g_info message of expected syscall mode when in fact being + // in user mode. Can also cause expected trap when in fact being user + // mode in the event of a page fault reenabling interrupts in the handler. + // Expected syscall and trap can also happen after the end of statedump + // This will cause a "popping last state on stack, ignoring it." + process->execution_stack = g_array_set_size(process->execution_stack, 1); + es = process->state = &g_array_index(process->execution_stack, + LttvExecutionState, 0); + es->t = LTTV_STATE_MODE_UNKNOWN; + es->s = LTTV_STATE_UNNAMED; + es->n = LTTV_STATE_SUBMODE_UNKNOWN; + #if 0 + es->t = LTTV_STATE_USER_MODE; + es->s = status; + es->n = submode; + #endif //0 + } + #if 0 + /* UNKNOWN STATE */ + { + es = process->state = &g_array_index(process->execution_stack, + LttvExecutionState, 1); + es->t = LTTV_STATE_MODE_UNKNOWN; + es->s = LTTV_STATE_UNNAMED; + es->n = LTTV_STATE_SUBMODE_UNKNOWN; + } + #endif //0 + } else { + /* The process has already been created : + * Probably was forked while dumping the process state or + * was simply scheduled in prior to get the state dump event. + */ + process->ppid = parent_pid; + process->tgid = tgid; + process->name = g_quark_from_string(command); + process->type = type; + es = &g_array_index(process->execution_stack, LttvExecutionState, 0); #if 0 - if(es->t == LTTV_STATE_MODE_UNKNOWN) { - if(type == LTTV_STATE_KERNEL_THREAD) - es->t = LTTV_STATE_SYSCALL; - else - es->t = LTTV_STATE_USER_MODE; - } + if(es->t == LTTV_STATE_MODE_UNKNOWN) { + if(type == LTTV_STATE_KERNEL_THREAD) + es->t = LTTV_STATE_SYSCALL; + else + es->t = LTTV_STATE_USER_MODE; + } #endif //0 - /* Don't mess around with the stack, it will eventually become - * ok after the end of state dump. */ - } - } - - return FALSE; + /* Don't mess around with the stack, it will eventually become + * ok after the end of state dump. */ + } + } + + return FALSE; } gint lttv_state_hook_add_event_hooks(void *hook_data, void *call_data) { - LttvTracesetState *tss = (LttvTracesetState*)(call_data); + LttvTracesetState *tss = (LttvTracesetState*)(call_data); - lttv_state_add_event_hooks(tss); + lttv_state_add_event_hooks(tss); - return 0; + return 0; } void lttv_state_add_event_hooks(LttvTracesetState *self) { - LttvTraceset *traceset = self->parent.ts; - - guint i, j, k, nb_trace, nb_tracefile; - - LttvTraceState *ts; - - LttvTracefileState *tfs; - - GArray *hooks; - - LttvTraceHook *th; - - LttvAttributeValue val; - - nb_trace = lttv_traceset_number(traceset); - for(i = 0 ; i < nb_trace ; i++) { - ts = (LttvTraceState *)self->parent.traces[i]; - - /* Find the eventtype id for the following events and register the - associated by id hooks. */ - - hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 20); - //hooks = g_array_set_size(hooks, 19); // Max possible number of hooks. - //hn = 0; - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SYSCALL_ENTRY, - FIELD_ARRAY(LTT_FIELD_SYSCALL_ID), - syscall_entry, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SYSCALL_EXIT, - NULL, - syscall_exit, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_TRAP_ENTRY, - FIELD_ARRAY(LTT_FIELD_TRAP_ID), - trap_entry, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_TRAP_EXIT, - NULL, - trap_exit, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_PAGE_FAULT_ENTRY, - FIELD_ARRAY(LTT_FIELD_TRAP_ID), - trap_entry, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_PAGE_FAULT_EXIT, - NULL, - trap_exit, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY, - FIELD_ARRAY(LTT_FIELD_TRAP_ID), - trap_entry, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_PAGE_FAULT_NOSEM_EXIT, - NULL, - trap_exit, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_IRQ_ENTRY, - FIELD_ARRAY(LTT_FIELD_IRQ_ID), - irq_entry, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_IRQ_EXIT, - NULL, - irq_exit, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SOFT_IRQ_RAISE, - FIELD_ARRAY(LTT_FIELD_SOFT_IRQ_ID), - soft_irq_raise, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SOFT_IRQ_ENTRY, - FIELD_ARRAY(LTT_FIELD_SOFT_IRQ_ID), - soft_irq_entry, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SOFT_IRQ_EXIT, - NULL, - soft_irq_exit, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SCHED_SCHEDULE, - FIELD_ARRAY(LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, - LTT_FIELD_PREV_STATE), - schedchange, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SCHED_TRY_WAKEUP, - FIELD_ARRAY(LTT_FIELD_PID, LTT_FIELD_CPU_ID, LTT_FIELD_STATE), - sched_try_wakeup, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_PROCESS_FORK, - FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID, - LTT_FIELD_CHILD_TGID), - process_fork, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_KTHREAD_CREATE, - FIELD_ARRAY(LTT_FIELD_PID), - process_kernel_thread, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_PROCESS_EXIT, - FIELD_ARRAY(LTT_FIELD_PID), - process_exit, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_PROCESS_FREE, - FIELD_ARRAY(LTT_FIELD_PID), - process_free, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_FS, - LTT_EVENT_EXEC, - FIELD_ARRAY(LTT_FIELD_FILENAME), - process_exec, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_USERSPACE, - LTT_EVENT_THREAD_BRAND, - FIELD_ARRAY(LTT_FIELD_NAME), - thread_brand, NULL, &hooks); - - /* statedump-related hooks */ - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_TASK_STATE, - LTT_EVENT_PROCESS_STATE, - FIELD_ARRAY(LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME, - LTT_FIELD_TYPE, LTT_FIELD_MODE, LTT_FIELD_SUBMODE, - LTT_FIELD_STATUS, LTT_FIELD_TGID), - enum_process_state, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_GLOBAL_STATE, - LTT_EVENT_STATEDUMP_END, - NULL, - statedump_end, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_IRQ_STATE, - LTT_EVENT_LIST_INTERRUPT, - FIELD_ARRAY(LTT_FIELD_ACTION, LTT_FIELD_IRQ_ID), - enum_interrupt, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_BLOCK, - LTT_EVENT_REQUEST_ISSUE, - FIELD_ARRAY(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION), - bdev_request_issue, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_BLOCK, - LTT_EVENT_REQUEST_COMPLETE, - FIELD_ARRAY(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION), - bdev_request_complete, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_USERSPACE, - LTT_EVENT_FUNCTION_ENTRY, - FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), - function_entry, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_USERSPACE, - LTT_EVENT_FUNCTION_EXIT, - FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), - function_exit, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_SYSCALL_STATE, - LTT_EVENT_SYS_CALL_TABLE, - FIELD_ARRAY(LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL), - dump_syscall, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_KPROBE_STATE, - LTT_EVENT_KPROBE_TABLE, - FIELD_ARRAY(LTT_FIELD_IP, LTT_FIELD_SYMBOL), - dump_kprobe, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_SOFTIRQ_STATE, - LTT_EVENT_SOFTIRQ_VEC, - FIELD_ARRAY(LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL), - dump_softirq, NULL, &hooks); - - lttv_trace_find_hook(ts->parent.t, - LTT_CHANNEL_FS, - LTT_EVENT_OPEN, - FIELD_ARRAY(LTT_FIELD_FD, LTT_FIELD_FILENAME), - fs_open, NULL, &hooks); - - /* Add these hooks to each event_by_id hooks list */ - - nb_tracefile = ts->parent.tracefiles->len; - - for(j = 0 ; j < nb_tracefile ; j++) { - tfs = - LTTV_TRACEFILE_STATE(g_array_index(ts->parent.tracefiles, - LttvTracefileContext*, j)); - - for(k = 0 ; k < hooks->len ; k++) { - th = &g_array_index(hooks, LttvTraceHook, k); - if (th->mdata == tfs->parent.tf->mdata) - lttv_hooks_add( - lttv_hooks_by_id_find(tfs->parent.event_by_id, th->id), - th->h, - th, - LTTV_PRIO_STATE); - } - } - lttv_attribute_find(ts->parent.a, LTTV_STATE_HOOKS, LTTV_POINTER, &val); - *(val.v_pointer) = hooks; - } + LttvTraceset *traceset = self->parent.ts; + + guint i, j, k, nb_trace, nb_tracefile; + + LttvTraceState *ts; + + LttvTracefileState *tfs; + + GArray *hooks; + + LttvTraceHook *th; + + LttvAttributeValue val; + + nb_trace = lttv_traceset_number(traceset); + for(i = 0 ; i < nb_trace ; i++) { + ts = (LttvTraceState *)self->parent.traces[i]; + + /* Find the eventtype id for the following events and register the + associated by id hooks. */ + + hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 20); + //hooks = g_array_set_size(hooks, 19); // Max possible number of hooks. + //hn = 0; + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SYSCALL_ENTRY, + FIELD_ARRAY(LTT_FIELD_SYSCALL_ID), + syscall_entry, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SYSCALL_EXIT, + NULL, + syscall_exit, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_TRAP_ENTRY, + FIELD_ARRAY(LTT_FIELD_TRAP_ID), + trap_entry, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_TRAP_EXIT, + NULL, + trap_exit, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_PAGE_FAULT_ENTRY, + FIELD_ARRAY(LTT_FIELD_TRAP_ID), + trap_entry, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_PAGE_FAULT_EXIT, + NULL, + trap_exit, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY, + FIELD_ARRAY(LTT_FIELD_TRAP_ID), + trap_entry, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_PAGE_FAULT_NOSEM_EXIT, + NULL, + trap_exit, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_IRQ_ENTRY, + FIELD_ARRAY(LTT_FIELD_IRQ_ID), + irq_entry, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_IRQ_EXIT, + NULL, + irq_exit, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SOFT_IRQ_RAISE, + FIELD_ARRAY(LTT_FIELD_SOFT_IRQ_ID), + soft_irq_raise, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SOFT_IRQ_ENTRY, + FIELD_ARRAY(LTT_FIELD_SOFT_IRQ_ID), + soft_irq_entry, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SOFT_IRQ_EXIT, + NULL, + soft_irq_exit, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SCHED_SCHEDULE, + FIELD_ARRAY(LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, + LTT_FIELD_PREV_STATE), + schedchange, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SCHED_TRY_WAKEUP, + FIELD_ARRAY(LTT_FIELD_PID, LTT_FIELD_CPU_ID, LTT_FIELD_STATE), + sched_try_wakeup, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_PROCESS_FORK, + FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID, + LTT_FIELD_CHILD_TGID), + process_fork, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_KTHREAD_CREATE, + FIELD_ARRAY(LTT_FIELD_PID), + process_kernel_thread, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_PROCESS_EXIT, + FIELD_ARRAY(LTT_FIELD_PID), + process_exit, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_PROCESS_FREE, + FIELD_ARRAY(LTT_FIELD_PID), + process_free, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_FS, + LTT_EVENT_EXEC, + FIELD_ARRAY(LTT_FIELD_FILENAME), + process_exec, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_USERSPACE, + LTT_EVENT_THREAD_BRAND, + FIELD_ARRAY(LTT_FIELD_NAME), + thread_brand, NULL, &hooks); + + /* statedump-related hooks */ + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_TASK_STATE, + LTT_EVENT_PROCESS_STATE, + FIELD_ARRAY(LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME, + LTT_FIELD_TYPE, LTT_FIELD_MODE, LTT_FIELD_SUBMODE, + LTT_FIELD_STATUS, LTT_FIELD_TGID), + enum_process_state, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_GLOBAL_STATE, + LTT_EVENT_STATEDUMP_END, + NULL, + statedump_end, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_IRQ_STATE, + LTT_EVENT_LIST_INTERRUPT, + FIELD_ARRAY(LTT_FIELD_ACTION, LTT_FIELD_IRQ_ID), + enum_interrupt, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_BLOCK, + LTT_EVENT_REQUEST_ISSUE, + FIELD_ARRAY(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION), + bdev_request_issue, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_BLOCK, + LTT_EVENT_REQUEST_COMPLETE, + FIELD_ARRAY(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION), + bdev_request_complete, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_USERSPACE, + LTT_EVENT_FUNCTION_ENTRY, + FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), + function_entry, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_USERSPACE, + LTT_EVENT_FUNCTION_EXIT, + FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), + function_exit, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_SYSCALL_STATE, + LTT_EVENT_SYS_CALL_TABLE, + FIELD_ARRAY(LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL), + dump_syscall, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_KPROBE_STATE, + LTT_EVENT_KPROBE_TABLE, + FIELD_ARRAY(LTT_FIELD_IP, LTT_FIELD_SYMBOL), + dump_kprobe, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_SOFTIRQ_STATE, + LTT_EVENT_SOFTIRQ_VEC, + FIELD_ARRAY(LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL), + dump_softirq, NULL, &hooks); + + lttv_trace_find_hook(ts->parent.t, + LTT_CHANNEL_FS, + LTT_EVENT_OPEN, + FIELD_ARRAY(LTT_FIELD_FD, LTT_FIELD_FILENAME), + fs_open, NULL, &hooks); + + /* Add these hooks to each event_by_id hooks list */ + + nb_tracefile = ts->parent.tracefiles->len; + + for(j = 0 ; j < nb_tracefile ; j++) { + tfs = + LTTV_TRACEFILE_STATE(g_array_index(ts->parent.tracefiles, + LttvTracefileContext*, j)); + + for(k = 0 ; k < hooks->len ; k++) { + th = &g_array_index(hooks, LttvTraceHook, k); + if (th->mdata == tfs->parent.tf->mdata) + lttv_hooks_add( + lttv_hooks_by_id_find(tfs->parent.event_by_id, th->id), + th->h, + th, + LTTV_PRIO_STATE); + } + } + lttv_attribute_find(ts->parent.a, LTTV_STATE_HOOKS, LTTV_POINTER, &val); + *(val.v_pointer) = hooks; + } } gint lttv_state_hook_remove_event_hooks(void *hook_data, void *call_data) { - LttvTracesetState *tss = (LttvTracesetState*)(call_data); + LttvTracesetState *tss = (LttvTracesetState*)(call_data); - lttv_state_remove_event_hooks(tss); + lttv_state_remove_event_hooks(tss); - return 0; + return 0; } void lttv_state_remove_event_hooks(LttvTracesetState *self) { - LttvTraceset *traceset = self->parent.ts; + LttvTraceset *traceset = self->parent.ts; - guint i, j, k, nb_trace, nb_tracefile; + guint i, j, k, nb_trace, nb_tracefile; - LttvTraceState *ts; + LttvTraceState *ts; - LttvTracefileState *tfs; + LttvTracefileState *tfs; - GArray *hooks; + GArray *hooks; - LttvTraceHook *th; + LttvTraceHook *th; - LttvAttributeValue val; + LttvAttributeValue val; - nb_trace = lttv_traceset_number(traceset); - for(i = 0 ; i < nb_trace ; i++) { - ts = LTTV_TRACE_STATE(self->parent.traces[i]); + nb_trace = lttv_traceset_number(traceset); + for(i = 0 ; i < nb_trace ; i++) { + ts = LTTV_TRACE_STATE(self->parent.traces[i]); - lttv_attribute_find(ts->parent.a, LTTV_STATE_HOOKS, LTTV_POINTER, &val); - hooks = *(val.v_pointer); + lttv_attribute_find(ts->parent.a, LTTV_STATE_HOOKS, LTTV_POINTER, &val); + hooks = *(val.v_pointer); - /* Remove these hooks from each event_by_id hooks list */ + /* Remove these hooks from each event_by_id hooks list */ - nb_tracefile = ts->parent.tracefiles->len; + nb_tracefile = ts->parent.tracefiles->len; - for(j = 0 ; j < nb_tracefile ; j++) { - tfs = - LTTV_TRACEFILE_STATE(g_array_index(ts->parent.tracefiles, - LttvTracefileContext*, j)); + for(j = 0 ; j < nb_tracefile ; j++) { + tfs = + LTTV_TRACEFILE_STATE(g_array_index(ts->parent.tracefiles, + LttvTracefileContext*, j)); - for(k = 0 ; k < hooks->len ; k++) { - th = &g_array_index(hooks, LttvTraceHook, k); - if (th->mdata == tfs->parent.tf->mdata) - lttv_hooks_remove_data( - lttv_hooks_by_id_find(tfs->parent.event_by_id, th->id), - th->h, - th); - } - } - lttv_trace_hook_remove_all(&hooks); - g_array_free(hooks, TRUE); - } + for(k = 0 ; k < hooks->len ; k++) { + th = &g_array_index(hooks, LttvTraceHook, k); + if (th->mdata == tfs->parent.tf->mdata) + lttv_hooks_remove_data( + lttv_hooks_by_id_find(tfs->parent.event_by_id, th->id), + th->h, + th); + } + } + lttv_trace_hook_remove_all(&hooks); + g_array_free(hooks, TRUE); + } } static gboolean state_save_event_hook(void *hook_data, void *call_data) { - guint *event_count = (guint*)hook_data; + guint *event_count = (guint*)hook_data; + + /* Only save at LTTV_STATE_SAVE_INTERVAL */ + if(likely((*event_count)++ < LTTV_STATE_SAVE_INTERVAL)) + return FALSE; + else + *event_count = 0; - /* Only save at LTTV_STATE_SAVE_INTERVAL */ - if(likely((*event_count)++ < LTTV_STATE_SAVE_INTERVAL)) - return FALSE; - else - *event_count = 0; - - LttvTracefileState *self = (LttvTracefileState *)call_data; + LttvTracefileState *self = (LttvTracefileState *)call_data; - LttvTraceState *tcs = (LttvTraceState *)(self->parent.t_context); + LttvTraceState *tcs = (LttvTraceState *)(self->parent.t_context); - LttvAttribute *saved_states_tree, *saved_state_tree; + LttvAttribute *saved_states_tree, *saved_state_tree; - LttvAttributeValue value; + LttvAttributeValue value; - saved_states_tree = lttv_attribute_find_subdir(tcs->parent.t_a, - LTTV_STATE_SAVED_STATES); - saved_state_tree = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); - value = lttv_attribute_add(saved_states_tree, - lttv_attribute_get_number(saved_states_tree), LTTV_GOBJECT); - *(value.v_gobject) = (GObject *)saved_state_tree; - value = lttv_attribute_add(saved_state_tree, LTTV_STATE_TIME, LTTV_TIME); - *(value.v_time) = self->parent.timestamp; - lttv_state_save(tcs, saved_state_tree); - g_debug("Saving state at time %lu.%lu", self->parent.timestamp.tv_sec, - self->parent.timestamp.tv_nsec); + saved_states_tree = lttv_attribute_find_subdir(tcs->parent.t_a, + LTTV_STATE_SAVED_STATES); + saved_state_tree = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); + value = lttv_attribute_add(saved_states_tree, + lttv_attribute_get_number(saved_states_tree), LTTV_GOBJECT); + *(value.v_gobject) = (GObject *)saved_state_tree; + value = lttv_attribute_add(saved_state_tree, LTTV_STATE_TIME, LTTV_TIME); + *(value.v_time) = self->parent.timestamp; + lttv_state_save(tcs, saved_state_tree); + g_debug("Saving state at time %lu.%lu", self->parent.timestamp.tv_sec, + self->parent.timestamp.tv_nsec); - *(tcs->max_time_state_recomputed_in_seek) = self->parent.timestamp; + *(tcs->max_time_state_recomputed_in_seek) = self->parent.timestamp; - return FALSE; + return FALSE; } static gboolean state_save_after_trace_hook(void *hook_data, void *call_data) { - LttvTraceState *tcs = (LttvTraceState *)(call_data); - - *(tcs->max_time_state_recomputed_in_seek) = tcs->parent.time_span.end_time; + LttvTraceState *tcs = (LttvTraceState *)(call_data); - return FALSE; + *(tcs->max_time_state_recomputed_in_seek) = tcs->parent.time_span.end_time; + + return FALSE; } guint lttv_state_current_cpu(LttvTracefileState *tfs) { - return tfs->cpu; + return tfs->cpu; } @@ -3939,631 +3936,620 @@ guint lttv_state_current_cpu(LttvTracefileState *tfs) #if 0 static gboolean block_start(void *hook_data, void *call_data) { - LttvTracefileState *self = (LttvTracefileState *)call_data; - - LttvTracefileState *tfcs; + LttvTracefileState *self = (LttvTracefileState *)call_data; - LttvTraceState *tcs = (LttvTraceState *)(self->parent.t_context); + LttvTracefileState *tfcs; - LttEventPosition *ep; + LttvTraceState *tcs = (LttvTraceState *)(self->parent.t_context); - guint i, nb_block, nb_event, nb_tracefile; + LttEventPosition *ep; - LttTracefile *tf; + guint i, nb_block, nb_event, nb_tracefile; - LttvAttribute *saved_states_tree, *saved_state_tree; + LttTracefile *tf; - LttvAttributeValue value; + LttvAttribute *saved_states_tree, *saved_state_tree; - ep = ltt_event_position_new(); + LttvAttributeValue value; - nb_tracefile = tcs->parent.tracefiles->len; + ep = ltt_event_position_new(); - /* Count the number of events added since the last block end in any - tracefile. */ + nb_tracefile = tcs->parent.tracefiles->len; - for(i = 0 ; i < nb_tracefile ; i++) { - tfcs = - LTTV_TRACEFILE_STATE(&g_array_index(tcs->parent.tracefiles, - LttvTracefileContext, i)); - ltt_event_position(tfcs->parent.e, ep); - ltt_event_position_get(ep, &nb_block, &nb_event, &tf); - tcs->nb_event += nb_event - tfcs->saved_position; - tfcs->saved_position = nb_event; - } - g_free(ep); + /* Count the number of events added since the last block end in any + tracefile. */ - if(tcs->nb_event >= tcs->save_interval) { - saved_states_tree = lttv_attribute_find_subdir(tcs->parent.t_a, - LTTV_STATE_SAVED_STATES); - saved_state_tree = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); - value = lttv_attribute_add(saved_states_tree, - lttv_attribute_get_number(saved_states_tree), LTTV_GOBJECT); - *(value.v_gobject) = (GObject *)saved_state_tree; - value = lttv_attribute_add(saved_state_tree, LTTV_STATE_TIME, LTTV_TIME); - *(value.v_time) = self->parent.timestamp; - lttv_state_save(tcs, saved_state_tree); - tcs->nb_event = 0; - g_debug("Saving state at time %lu.%lu", self->parent.timestamp.tv_sec, - self->parent.timestamp.tv_nsec); - } - *(tcs->max_time_state_recomputed_in_seek) = self->parent.timestamp; - return FALSE; + for(i = 0 ; i < nb_tracefile ; i++) { + tfcs = + LTTV_TRACEFILE_STATE(&g_array_index(tcs->parent.tracefiles, + LttvTracefileContext, i)); + ltt_event_position(tfcs->parent.e, ep); + ltt_event_position_get(ep, &nb_block, &nb_event, &tf); + tcs->nb_event += nb_event - tfcs->saved_position; + tfcs->saved_position = nb_event; + } + g_free(ep); + + if(tcs->nb_event >= tcs->save_interval) { + saved_states_tree = lttv_attribute_find_subdir(tcs->parent.t_a, + LTTV_STATE_SAVED_STATES); + saved_state_tree = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); + value = lttv_attribute_add(saved_states_tree, + lttv_attribute_get_number(saved_states_tree), LTTV_GOBJECT); + *(value.v_gobject) = (GObject *)saved_state_tree; + value = lttv_attribute_add(saved_state_tree, LTTV_STATE_TIME, LTTV_TIME); + *(value.v_time) = self->parent.timestamp; + lttv_state_save(tcs, saved_state_tree); + tcs->nb_event = 0; + g_debug("Saving state at time %lu.%lu", self->parent.timestamp.tv_sec, + self->parent.timestamp.tv_nsec); + } + *(tcs->max_time_state_recomputed_in_seek) = self->parent.timestamp; + return FALSE; } #endif //0 #if 0 static gboolean block_end(void *hook_data, void *call_data) { - LttvTracefileState *self = (LttvTracefileState *)call_data; + LttvTracefileState *self = (LttvTracefileState *)call_data; - LttvTraceState *tcs = (LttvTraceState *)(self->parent.t_context); + LttvTraceState *tcs = (LttvTraceState *)(self->parent.t_context); - LttTracefile *tf; + LttTracefile *tf; - LttEventPosition *ep; + LttEventPosition *ep; - guint nb_block, nb_event; + guint nb_block, nb_event; - ep = ltt_event_position_new(); - ltt_event_position(self->parent.e, ep); - ltt_event_position_get(ep, &nb_block, &nb_event, &tf); - tcs->nb_event += nb_event - self->saved_position + 1; - self->saved_position = 0; - *(tcs->max_time_state_recomputed_in_seek) = self->parent.timestamp; - g_free(ep); + ep = ltt_event_position_new(); + ltt_event_position(self->parent.e, ep); + ltt_event_position_get(ep, &nb_block, &nb_event, &tf); + tcs->nb_event += nb_event - self->saved_position + 1; + self->saved_position = 0; + *(tcs->max_time_state_recomputed_in_seek) = self->parent.timestamp; + g_free(ep); - return FALSE; + return FALSE; } #endif //0 #if 0 void lttv_state_save_add_event_hooks(LttvTracesetState *self) { - LttvTraceset *traceset = self->parent.ts; + LttvTraceset *traceset = self->parent.ts; - guint i, j, nb_trace, nb_tracefile; + guint i, j, nb_trace, nb_tracefile; - LttvTraceState *ts; + LttvTraceState *ts; - LttvTracefileState *tfs; + LttvTracefileState *tfs; - LttvTraceHook hook_start, hook_end; + LttvTraceHook hook_start, hook_end; - nb_trace = lttv_traceset_number(traceset); - for(i = 0 ; i < nb_trace ; i++) { - ts = (LttvTraceState *)self->parent.traces[i]; + nb_trace = lttv_traceset_number(traceset); + for(i = 0 ; i < nb_trace ; i++) { + ts = (LttvTraceState *)self->parent.traces[i]; - lttv_trace_find_hook(ts->parent.t, "core","block_start",NULL, - NULL, NULL, block_start, &hook_start); - lttv_trace_find_hook(ts->parent.t, "core","block_end",NULL, - NULL, NULL, block_end, &hook_end); + lttv_trace_find_hook(ts->parent.t, "core","block_start",NULL, + NULL, NULL, block_start, &hook_start); + lttv_trace_find_hook(ts->parent.t, "core","block_end",NULL, + NULL, NULL, block_end, &hook_end); - nb_tracefile = ts->parent.tracefiles->len; + nb_tracefile = ts->parent.tracefiles->len; - for(j = 0 ; j < nb_tracefile ; j++) { - tfs = - LTTV_TRACEFILE_STATE(&g_array_index(ts->parent.tracefiles, - LttvTracefileContext, j)); - lttv_hooks_add(lttv_hooks_by_id_find(tfs->parent.event_by_id, - hook_start.id), hook_start.h, NULL, LTTV_PRIO_STATE); - lttv_hooks_add(lttv_hooks_by_id_find(tfs->parent.event_by_id, - hook_end.id), hook_end.h, NULL, LTTV_PRIO_STATE); - } - } + for(j = 0 ; j < nb_tracefile ; j++) { + tfs = + LTTV_TRACEFILE_STATE(&g_array_index(ts->parent.tracefiles, + LttvTracefileContext, j)); + lttv_hooks_add(lttv_hooks_by_id_find(tfs->parent.event_by_id, + hook_start.id), hook_start.h, NULL, LTTV_PRIO_STATE); + lttv_hooks_add(lttv_hooks_by_id_find(tfs->parent.event_by_id, + hook_end.id), hook_end.h, NULL, LTTV_PRIO_STATE); + } + } } #endif //0 void lttv_state_save_add_event_hooks(LttvTracesetState *self) { - LttvTraceset *traceset = self->parent.ts; + LttvTraceset *traceset = self->parent.ts; - guint i, j, nb_trace, nb_tracefile; + guint i, j, nb_trace, nb_tracefile; - LttvTraceState *ts; + LttvTraceState *ts; - LttvTracefileState *tfs; + LttvTracefileState *tfs; - nb_trace = lttv_traceset_number(traceset); - for(i = 0 ; i < nb_trace ; i++) { + nb_trace = lttv_traceset_number(traceset); + for(i = 0 ; i < nb_trace ; i++) { - ts = (LttvTraceState *)self->parent.traces[i]; - nb_tracefile = ts->parent.tracefiles->len; + ts = (LttvTraceState *)self->parent.traces[i]; + nb_tracefile = ts->parent.tracefiles->len; - if(ts->has_precomputed_states) continue; + if(ts->has_precomputed_states) continue; - guint *event_count = g_new(guint, 1); - *event_count = 0; + guint *event_count = g_new(guint, 1); + *event_count = 0; - for(j = 0 ; j < nb_tracefile ; j++) { - tfs = - LTTV_TRACEFILE_STATE(g_array_index(ts->parent.tracefiles, - LttvTracefileContext*, j)); - lttv_hooks_add(tfs->parent.event, - state_save_event_hook, - event_count, - LTTV_PRIO_STATE); + for(j = 0 ; j < nb_tracefile ; j++) { + tfs = + LTTV_TRACEFILE_STATE(g_array_index(ts->parent.tracefiles, + LttvTracefileContext*, j)); + lttv_hooks_add(tfs->parent.event, + state_save_event_hook, + event_count, + LTTV_PRIO_STATE); + + } + } + + lttv_process_traceset_begin(&self->parent, + NULL, NULL, NULL, NULL, NULL); - } - } - - lttv_process_traceset_begin(&self->parent, - NULL, NULL, NULL, NULL, NULL); - } gint lttv_state_save_hook_add_event_hooks(void *hook_data, void *call_data) { - LttvTracesetState *tss = (LttvTracesetState*)(call_data); + LttvTracesetState *tss = (LttvTracesetState*)(call_data); - lttv_state_save_add_event_hooks(tss); + lttv_state_save_add_event_hooks(tss); - return 0; + return 0; } #if 0 void lttv_state_save_remove_event_hooks(LttvTracesetState *self) { - LttvTraceset *traceset = self->parent.ts; + LttvTraceset *traceset = self->parent.ts; - guint i, j, nb_trace, nb_tracefile; + guint i, j, nb_trace, nb_tracefile; - LttvTraceState *ts; + LttvTraceState *ts; - LttvTracefileState *tfs; + LttvTracefileState *tfs; - LttvTraceHook hook_start, hook_end; + LttvTraceHook hook_start, hook_end; - nb_trace = lttv_traceset_number(traceset); - for(i = 0 ; i < nb_trace ; i++) { - ts = LTTV_TRACE_STATE(self->parent.traces[i]); + nb_trace = lttv_traceset_number(traceset); + for(i = 0 ; i < nb_trace ; i++) { + ts = LTTV_TRACE_STATE(self->parent.traces[i]); - lttv_trace_find_hook(ts->parent.t, "core","block_start",NULL, - NULL, NULL, block_start, &hook_start); + lttv_trace_find_hook(ts->parent.t, "core","block_start",NULL, + NULL, NULL, block_start, &hook_start); - lttv_trace_find_hook(ts->parent.t, "core","block_end",NULL, - NULL, NULL, block_end, &hook_end); + lttv_trace_find_hook(ts->parent.t, "core","block_end",NULL, + NULL, NULL, block_end, &hook_end); - nb_tracefile = ts->parent.tracefiles->len; + nb_tracefile = ts->parent.tracefiles->len; - for(j = 0 ; j < nb_tracefile ; j++) { - tfs = - LTTV_TRACEFILE_STATE(&g_array_index(ts->parent.tracefiles, - LttvTracefileContext, j)); - lttv_hooks_remove_data(lttv_hooks_by_id_find( - tfs->parent.event_by_id, hook_start.id), hook_start.h, NULL); - lttv_hooks_remove_data(lttv_hooks_by_id_find( - tfs->parent.event_by_id, hook_end.id), hook_end.h, NULL); - } - } + for(j = 0 ; j < nb_tracefile ; j++) { + tfs = + LTTV_TRACEFILE_STATE(&g_array_index(ts->parent.tracefiles, + LttvTracefileContext, j)); + lttv_hooks_remove_data(lttv_hooks_by_id_find( + tfs->parent.event_by_id, hook_start.id), hook_start.h, NULL); + lttv_hooks_remove_data(lttv_hooks_by_id_find( + tfs->parent.event_by_id, hook_end.id), hook_end.h, NULL); + } + } } #endif //0 void lttv_state_save_remove_event_hooks(LttvTracesetState *self) { - LttvTraceset *traceset = self->parent.ts; + LttvTraceset *traceset = self->parent.ts; - guint i, j, nb_trace, nb_tracefile; + guint i, j, nb_trace, nb_tracefile; - LttvTraceState *ts; + LttvTraceState *ts; - LttvTracefileState *tfs; + LttvTracefileState *tfs; - LttvHooks *after_trace = lttv_hooks_new(); - - lttv_hooks_add(after_trace, - state_save_after_trace_hook, - NULL, - LTTV_PRIO_STATE); + LttvHooks *after_trace = lttv_hooks_new(); - - lttv_process_traceset_end(&self->parent, - NULL, after_trace, NULL, NULL, NULL); + lttv_hooks_add(after_trace, + state_save_after_trace_hook, + NULL, + LTTV_PRIO_STATE); + + + lttv_process_traceset_end(&self->parent, + NULL, after_trace, NULL, NULL, NULL); - lttv_hooks_destroy(after_trace); - - nb_trace = lttv_traceset_number(traceset); - for(i = 0 ; i < nb_trace ; i++) { + lttv_hooks_destroy(after_trace); + + nb_trace = lttv_traceset_number(traceset); + for(i = 0 ; i < nb_trace ; i++) { - ts = (LttvTraceState *)self->parent.traces[i]; - nb_tracefile = ts->parent.tracefiles->len; + ts = (LttvTraceState *)self->parent.traces[i]; + nb_tracefile = ts->parent.tracefiles->len; - if(ts->has_precomputed_states) continue; + if(ts->has_precomputed_states) continue; - guint *event_count = NULL; + guint *event_count = NULL; - for(j = 0 ; j < nb_tracefile ; j++) { - tfs = - LTTV_TRACEFILE_STATE(g_array_index(ts->parent.tracefiles, - LttvTracefileContext*, j)); - event_count = lttv_hooks_remove(tfs->parent.event, - state_save_event_hook); - } - if(event_count) g_free(event_count); - } + for(j = 0 ; j < nb_tracefile ; j++) { + tfs = + LTTV_TRACEFILE_STATE(g_array_index(ts->parent.tracefiles, + LttvTracefileContext*, j)); + event_count = lttv_hooks_remove(tfs->parent.event, + state_save_event_hook); + } + if(event_count) g_free(event_count); + } } gint lttv_state_save_hook_remove_event_hooks(void *hook_data, void *call_data) { - LttvTracesetState *tss = (LttvTracesetState*)(call_data); + LttvTracesetState *tss = (LttvTracesetState*)(call_data); - lttv_state_save_remove_event_hooks(tss); + lttv_state_save_remove_event_hooks(tss); - return 0; + return 0; } void lttv_state_traceset_seek_time_closest(LttvTracesetState *self, LttTime t) { - LttvTraceset *traceset = self->parent.ts; + LttvTraceset *traceset = self->parent.ts; + + guint i, nb_trace; - guint i, nb_trace; + int min_pos, mid_pos, max_pos; - int min_pos, mid_pos, max_pos; + guint call_rest = 0; - guint call_rest = 0; + LttvTraceState *tcs; - LttvTraceState *tcs; + LttvAttributeValue value; - LttvAttributeValue value; + LttvAttributeType type; - LttvAttributeType type; + LttvAttributeName name; - LttvAttributeName name; + gboolean is_named; - gboolean is_named; + LttvAttribute *saved_states_tree, *saved_state_tree, *closest_tree = NULL; - LttvAttribute *saved_states_tree, *saved_state_tree, *closest_tree = NULL; + //g_tree_destroy(self->parent.pqueue); + //self->parent.pqueue = g_tree_new(compare_tracefile); - //g_tree_destroy(self->parent.pqueue); - //self->parent.pqueue = g_tree_new(compare_tracefile); - - g_info("Entering seek_time_closest for time %lu.%lu", t.tv_sec, t.tv_nsec); - - nb_trace = lttv_traceset_number(traceset); - for(i = 0 ; i < nb_trace ; i++) { - tcs = (LttvTraceState *)self->parent.traces[i]; + g_info("Entering seek_time_closest for time %lu.%lu", t.tv_sec, t.tv_nsec); - if(ltt_time_compare(t, *(tcs->max_time_state_recomputed_in_seek)) < 0) { - saved_states_tree = lttv_attribute_find_subdir(tcs->parent.t_a, - LTTV_STATE_SAVED_STATES); - min_pos = -1; + nb_trace = lttv_traceset_number(traceset); + for(i = 0 ; i < nb_trace ; i++) { + tcs = (LttvTraceState *)self->parent.traces[i]; - if(saved_states_tree) { - max_pos = lttv_attribute_get_number(saved_states_tree) - 1; - mid_pos = max_pos / 2; - while(min_pos < max_pos) { - type = lttv_attribute_get(saved_states_tree, mid_pos, &name, &value, - &is_named); - g_assert(type == LTTV_GOBJECT); - saved_state_tree = *((LttvAttribute **)(value.v_gobject)); - type = lttv_attribute_get_by_name(saved_state_tree, LTTV_STATE_TIME, - &value); - g_assert(type == LTTV_TIME); - if(ltt_time_compare(*(value.v_time), t) < 0) { - min_pos = mid_pos; - closest_tree = saved_state_tree; - } - else max_pos = mid_pos - 1; + if(ltt_time_compare(t, *(tcs->max_time_state_recomputed_in_seek)) < 0) { + saved_states_tree = lttv_attribute_find_subdir(tcs->parent.t_a, + LTTV_STATE_SAVED_STATES); + min_pos = -1; - mid_pos = (min_pos + max_pos + 1) / 2; - } - } + if(saved_states_tree) { + max_pos = lttv_attribute_get_number(saved_states_tree) - 1; + mid_pos = max_pos / 2; + while(min_pos < max_pos) { + type = lttv_attribute_get(saved_states_tree, mid_pos, + &name, &value, &is_named); + g_assert(type == LTTV_GOBJECT); + saved_state_tree = *((LttvAttribute **)(value.v_gobject)); + type = lttv_attribute_get_by_name(saved_state_tree, + LTTV_STATE_TIME, &value); + g_assert(type == LTTV_TIME); + if(ltt_time_compare(*(value.v_time), t) < 0) { + min_pos = mid_pos; + closest_tree = saved_state_tree; + } + else max_pos = mid_pos - 1; - /* restore the closest earlier saved state */ - if(min_pos != -1) { - lttv_state_restore(tcs, closest_tree); - call_rest = 1; - } + mid_pos = (min_pos + max_pos + 1) / 2; + } + } - /* There is no saved state, yet we want to have it. Restart at T0 */ - else { - restore_init_state(tcs); - lttv_process_trace_seek_time(&(tcs->parent), ltt_time_zero); - } - } - /* We want to seek quickly without restoring/updating the state */ - else { - restore_init_state(tcs); - lttv_process_trace_seek_time(&(tcs->parent), t); - } - } - if(!call_rest) g_info("NOT Calling restore"); + /* restore the closest earlier saved state */ + if(min_pos != -1) { + lttv_state_restore(tcs, closest_tree); + call_rest = 1; + } + + /* There is no saved state, yet we want to have it. Restart at T0 */ + else { + restore_init_state(tcs); + lttv_process_trace_seek_time(&(tcs->parent), ltt_time_zero); + } + } + /* We want to seek quickly without restoring/updating the state */ + else { + restore_init_state(tcs); + lttv_process_trace_seek_time(&(tcs->parent), t); + } + } + if(!call_rest) g_info("NOT Calling restore"); } -static void -traceset_state_instance_init (GTypeInstance *instance, gpointer g_class) +static void traceset_state_instance_init (GTypeInstance *instance, gpointer g_class) { } -static void -traceset_state_finalize (LttvTracesetState *self) +static void traceset_state_finalize (LttvTracesetState *self) { - G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE))-> - finalize(G_OBJECT(self)); + G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACESET_CONTEXT_TYPE))-> + finalize(G_OBJECT(self)); } -static void -traceset_state_class_init (LttvTracesetContextClass *klass) +static void traceset_state_class_init (LttvTracesetContextClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - gobject_class->finalize = (void (*)(GObject *self)) traceset_state_finalize; - klass->init = (void (*)(LttvTracesetContext *self, LttvTraceset *ts))init; - klass->fini = (void (*)(LttvTracesetContext *self))fini; - klass->new_traceset_context = new_traceset_context; - klass->new_trace_context = new_trace_context; - klass->new_tracefile_context = new_tracefile_context; + gobject_class->finalize = (void (*)(GObject *self)) traceset_state_finalize; + klass->init = (void (*)(LttvTracesetContext *self, LttvTraceset *ts))init; + klass->fini = (void (*)(LttvTracesetContext *self))fini; + klass->new_traceset_context = new_traceset_context; + klass->new_trace_context = new_trace_context; + klass->new_tracefile_context = new_tracefile_context; } -GType -lttv_traceset_state_get_type(void) +GType lttv_traceset_state_get_type(void) { - static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof (LttvTracesetStateClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) traceset_state_class_init, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (LttvTracesetState), - 0, /* n_preallocs */ - (GInstanceInitFunc) traceset_state_instance_init, /* instance_init */ - NULL /* value handling */ - }; + static GType type = 0; + if (type == 0) { + static const GTypeInfo info = { + sizeof (LttvTracesetStateClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) traceset_state_class_init, /* class_init */ + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (LttvTracesetState), + 0, /* n_preallocs */ + (GInstanceInitFunc) traceset_state_instance_init, /* instance_init */ + NULL /* value handling */ + }; - type = g_type_register_static (LTTV_TRACESET_CONTEXT_TYPE, "LttvTracesetStateType", - &info, 0); - } - return type; + type = g_type_register_static (LTTV_TRACESET_CONTEXT_TYPE, "LttvTracesetStateType", + &info, 0); + } + return type; } -static void -trace_state_instance_init (GTypeInstance *instance, gpointer g_class) +static void trace_state_instance_init (GTypeInstance *instance, gpointer g_class) { } -static void -trace_state_finalize (LttvTraceState *self) +static void trace_state_finalize (LttvTraceState *self) { - G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACE_CONTEXT_TYPE))-> - finalize(G_OBJECT(self)); + G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACE_CONTEXT_TYPE))-> + finalize(G_OBJECT(self)); } -static void -trace_state_class_init (LttvTraceStateClass *klass) +static void trace_state_class_init (LttvTraceStateClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - gobject_class->finalize = (void (*)(GObject *self)) trace_state_finalize; - klass->state_save = state_save; - klass->state_restore = state_restore; - klass->state_saved_free = state_saved_free; + gobject_class->finalize = (void (*)(GObject *self)) trace_state_finalize; + klass->state_save = state_save; + klass->state_restore = state_restore; + klass->state_saved_free = state_saved_free; } -GType -lttv_trace_state_get_type(void) +GType lttv_trace_state_get_type(void) { - static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof (LttvTraceStateClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) trace_state_class_init, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (LttvTraceState), - 0, /* n_preallocs */ - (GInstanceInitFunc) trace_state_instance_init, /* instance_init */ - NULL /* value handling */ - }; + static GType type = 0; + if (type == 0) { + static const GTypeInfo info = { + sizeof (LttvTraceStateClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) trace_state_class_init, /* class_init */ + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (LttvTraceState), + 0, /* n_preallocs */ + (GInstanceInitFunc) trace_state_instance_init, /* instance_init */ + NULL /* value handling */ + }; - type = g_type_register_static (LTTV_TRACE_CONTEXT_TYPE, - "LttvTraceStateType", &info, 0); - } - return type; + type = g_type_register_static (LTTV_TRACE_CONTEXT_TYPE, + "LttvTraceStateType", &info, 0); + } + return type; } -static void -tracefile_state_instance_init (GTypeInstance *instance, gpointer g_class) +static void tracefile_state_instance_init (GTypeInstance *instance, + gpointer g_class) { } -static void -tracefile_state_finalize (LttvTracefileState *self) +static void tracefile_state_finalize (LttvTracefileState *self) { - G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACEFILE_CONTEXT_TYPE))-> - finalize(G_OBJECT(self)); + G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACEFILE_CONTEXT_TYPE))-> + finalize(G_OBJECT(self)); } -static void -tracefile_state_class_init (LttvTracefileStateClass *klass) +static void tracefile_state_class_init (LttvTracefileStateClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - gobject_class->finalize = (void (*)(GObject *self)) tracefile_state_finalize; + gobject_class->finalize = (void (*)(GObject *self)) tracefile_state_finalize; } -GType -lttv_tracefile_state_get_type(void) +GType lttv_tracefile_state_get_type(void) { - static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof (LttvTracefileStateClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) tracefile_state_class_init, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (LttvTracefileState), - 0, /* n_preallocs */ - (GInstanceInitFunc) tracefile_state_instance_init, /* instance_init */ - NULL /* value handling */ - }; + static GType type = 0; + if (type == 0) { + static const GTypeInfo info = { + sizeof (LttvTracefileStateClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) tracefile_state_class_init, /* class_init */ + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (LttvTracefileState), + 0, /* n_preallocs */ + (GInstanceInitFunc) tracefile_state_instance_init, /* instance_init */ + NULL /* value handling */ + }; - type = g_type_register_static (LTTV_TRACEFILE_CONTEXT_TYPE, - "LttvTracefileStateType", &info, 0); - } - return type; + type = g_type_register_static (LTTV_TRACEFILE_CONTEXT_TYPE, + "LttvTracefileStateType", &info, 0); + } + return type; } static void module_init() { - LTTV_STATE_UNNAMED = g_quark_from_string(""); - LTTV_STATE_UNBRANDED = g_quark_from_string(""); - LTTV_STATE_MODE_UNKNOWN = g_quark_from_string("MODE_UNKNOWN"); - LTTV_STATE_USER_MODE = g_quark_from_string("USER_MODE"); - LTTV_STATE_SYSCALL = g_quark_from_string("SYSCALL"); - LTTV_STATE_TRAP = g_quark_from_string("TRAP"); - LTTV_STATE_IRQ = g_quark_from_string("IRQ"); - LTTV_STATE_SOFT_IRQ = g_quark_from_string("SOFTIRQ"); - LTTV_STATE_SUBMODE_UNKNOWN = g_quark_from_string("UNKNOWN"); - LTTV_STATE_SUBMODE_NONE = g_quark_from_string("NONE"); - LTTV_STATE_WAIT_FORK = g_quark_from_string("WAIT_FORK"); - LTTV_STATE_WAIT_CPU = g_quark_from_string("WAIT_CPU"); - LTTV_STATE_EXIT = g_quark_from_string("EXIT"); - LTTV_STATE_ZOMBIE = g_quark_from_string("ZOMBIE"); - LTTV_STATE_WAIT = g_quark_from_string("WAIT"); - LTTV_STATE_RUN = g_quark_from_string("RUN"); - LTTV_STATE_DEAD = g_quark_from_string("DEAD"); - LTTV_STATE_USER_THREAD = g_quark_from_string("USER_THREAD"); - LTTV_STATE_KERNEL_THREAD = g_quark_from_string("KERNEL_THREAD"); - LTTV_STATE_TRACEFILES = g_quark_from_string("tracefiles"); - LTTV_STATE_PROCESSES = g_quark_from_string("processes"); - LTTV_STATE_PROCESS = g_quark_from_string("process"); - LTTV_STATE_RUNNING_PROCESS = g_quark_from_string("running_process"); - LTTV_STATE_EVENT = g_quark_from_string("event"); - LTTV_STATE_SAVED_STATES = g_quark_from_string("saved states"); - LTTV_STATE_SAVED_STATES_TIME = g_quark_from_string("saved states time"); - LTTV_STATE_TIME = g_quark_from_string("time"); - LTTV_STATE_HOOKS = g_quark_from_string("saved state hooks"); - LTTV_STATE_NAME_TABLES = g_quark_from_string("name tables"); - LTTV_STATE_TRACE_STATE_USE_COUNT = - g_quark_from_string("trace_state_use_count"); - LTTV_STATE_RESOURCE_CPUS = g_quark_from_string("cpu resource states"); - LTTV_STATE_RESOURCE_CPUS = g_quark_from_string("cpu count"); - LTTV_STATE_RESOURCE_IRQS = g_quark_from_string("irq resource states"); - LTTV_STATE_RESOURCE_SOFT_IRQS = g_quark_from_string("soft irq resource states"); - LTTV_STATE_RESOURCE_TRAPS = g_quark_from_string("trap resource states"); - LTTV_STATE_RESOURCE_BLKDEVS = g_quark_from_string("blkdevs resource states"); - - LTT_CHANNEL_FD_STATE = g_quark_from_string("fd_state"); - LTT_CHANNEL_GLOBAL_STATE = g_quark_from_string("global_state"); - LTT_CHANNEL_IRQ_STATE = g_quark_from_string("irq_state"); - LTT_CHANNEL_MODULE_STATE = g_quark_from_string("module_state"); - LTT_CHANNEL_NETIF_STATE = g_quark_from_string("netif_state"); - LTT_CHANNEL_SOFTIRQ_STATE = g_quark_from_string("softirq_state"); - LTT_CHANNEL_SWAP_STATE = g_quark_from_string("swap_state"); - LTT_CHANNEL_SYSCALL_STATE = g_quark_from_string("syscall_state"); - LTT_CHANNEL_TASK_STATE = g_quark_from_string("task_state"); - LTT_CHANNEL_VM_STATE = g_quark_from_string("vm_state"); - LTT_CHANNEL_KPROBE_STATE = g_quark_from_string("kprobe_state"); - LTT_CHANNEL_FS = g_quark_from_string("fs"); - LTT_CHANNEL_KERNEL = g_quark_from_string("kernel"); - LTT_CHANNEL_MM = g_quark_from_string("mm"); - LTT_CHANNEL_USERSPACE = g_quark_from_string("userspace"); - LTT_CHANNEL_BLOCK = g_quark_from_string("block"); - - LTT_EVENT_SYSCALL_ENTRY = g_quark_from_string("syscall_entry"); - LTT_EVENT_SYSCALL_EXIT = g_quark_from_string("syscall_exit"); - LTT_EVENT_TRAP_ENTRY = g_quark_from_string("trap_entry"); - LTT_EVENT_TRAP_EXIT = g_quark_from_string("trap_exit"); - LTT_EVENT_PAGE_FAULT_ENTRY = g_quark_from_string("page_fault_entry"); - LTT_EVENT_PAGE_FAULT_EXIT = g_quark_from_string("page_fault_exit"); - LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY = g_quark_from_string("page_fault_nosem_entry"); - LTT_EVENT_PAGE_FAULT_NOSEM_EXIT = g_quark_from_string("page_fault_nosem_exit"); - LTT_EVENT_IRQ_ENTRY = g_quark_from_string("irq_entry"); - LTT_EVENT_IRQ_EXIT = g_quark_from_string("irq_exit"); - LTT_EVENT_SOFT_IRQ_RAISE = g_quark_from_string("softirq_raise"); - LTT_EVENT_SOFT_IRQ_ENTRY = g_quark_from_string("softirq_entry"); - LTT_EVENT_SOFT_IRQ_EXIT = g_quark_from_string("softirq_exit"); - LTT_EVENT_SCHED_SCHEDULE = g_quark_from_string("sched_schedule"); - LTT_EVENT_SCHED_TRY_WAKEUP = g_quark_from_string("sched_try_wakeup"); - LTT_EVENT_PROCESS_FORK = g_quark_from_string("process_fork"); - LTT_EVENT_KTHREAD_CREATE = g_quark_from_string("kthread_create"); - LTT_EVENT_PROCESS_EXIT = g_quark_from_string("process_exit"); - LTT_EVENT_PROCESS_FREE = g_quark_from_string("process_free"); - LTT_EVENT_EXEC = g_quark_from_string("exec"); - LTT_EVENT_PROCESS_STATE = g_quark_from_string("process_state"); - LTT_EVENT_STATEDUMP_END = g_quark_from_string("statedump_end"); - LTT_EVENT_FUNCTION_ENTRY = g_quark_from_string("function_entry"); - LTT_EVENT_FUNCTION_EXIT = g_quark_from_string("function_exit"); - LTT_EVENT_THREAD_BRAND = g_quark_from_string("thread_brand"); - LTT_EVENT_REQUEST_ISSUE = g_quark_from_string("_blk_request_issue"); - LTT_EVENT_REQUEST_COMPLETE = g_quark_from_string("_blk_request_complete"); - LTT_EVENT_LIST_INTERRUPT = g_quark_from_string("interrupt"); - LTT_EVENT_SYS_CALL_TABLE = g_quark_from_string("sys_call_table"); - LTT_EVENT_SOFTIRQ_VEC = g_quark_from_string("softirq_vec"); - LTT_EVENT_KPROBE_TABLE = g_quark_from_string("kprobe_table"); - LTT_EVENT_KPROBE = g_quark_from_string("kprobe"); - LTT_EVENT_OPEN = g_quark_from_string("open"); - LTT_EVENT_READ = g_quark_from_string("read"); - LTT_EVENT_POLL_EVENT = g_quark_from_string("poll_event"); - - LTT_FIELD_SYSCALL_ID = g_quark_from_string("syscall_id"); - LTT_FIELD_TRAP_ID = g_quark_from_string("trap_id"); - LTT_FIELD_IRQ_ID = g_quark_from_string("irq_id"); - LTT_FIELD_SOFT_IRQ_ID = g_quark_from_string("softirq_id"); - LTT_FIELD_PREV_PID = g_quark_from_string("prev_pid"); - LTT_FIELD_NEXT_PID = g_quark_from_string("next_pid"); - LTT_FIELD_PREV_STATE = g_quark_from_string("prev_state"); - LTT_FIELD_PARENT_PID = g_quark_from_string("parent_pid"); - LTT_FIELD_CHILD_PID = g_quark_from_string("child_pid"); - LTT_FIELD_PID = g_quark_from_string("pid"); - LTT_FIELD_TGID = g_quark_from_string("tgid"); - LTT_FIELD_CHILD_TGID = g_quark_from_string("child_tgid"); - LTT_FIELD_FILENAME = g_quark_from_string("filename"); - LTT_FIELD_NAME = g_quark_from_string("name"); - LTT_FIELD_TYPE = g_quark_from_string("type"); - LTT_FIELD_MODE = g_quark_from_string("mode"); - LTT_FIELD_SUBMODE = g_quark_from_string("submode"); - LTT_FIELD_STATUS = g_quark_from_string("status"); - LTT_FIELD_THIS_FN = g_quark_from_string("this_fn"); - LTT_FIELD_CALL_SITE = g_quark_from_string("call_site"); - LTT_FIELD_MAJOR = g_quark_from_string("major"); - LTT_FIELD_MINOR = g_quark_from_string("minor"); - LTT_FIELD_OPERATION = g_quark_from_string("direction"); - LTT_FIELD_ACTION = g_quark_from_string("action"); - LTT_FIELD_ID = g_quark_from_string("id"); - LTT_FIELD_ADDRESS = g_quark_from_string("address"); - LTT_FIELD_SYMBOL = g_quark_from_string("symbol"); - LTT_FIELD_IP = g_quark_from_string("ip"); - LTT_FIELD_FD = g_quark_from_string("fd"); - LTT_FIELD_STATE = g_quark_from_string("state"); - LTT_FIELD_CPU_ID = g_quark_from_string("cpu_id"); - - LTTV_CPU_UNKNOWN = g_quark_from_string("unknown"); - LTTV_CPU_IDLE = g_quark_from_string("idle"); - LTTV_CPU_BUSY = g_quark_from_string("busy"); - LTTV_CPU_IRQ = g_quark_from_string("irq"); - LTTV_CPU_SOFT_IRQ = g_quark_from_string("softirq"); - LTTV_CPU_TRAP = g_quark_from_string("trap"); - - LTTV_IRQ_UNKNOWN = g_quark_from_string("unknown"); - LTTV_IRQ_IDLE = g_quark_from_string("idle"); - LTTV_IRQ_BUSY = g_quark_from_string("busy"); - - LTTV_BDEV_UNKNOWN = g_quark_from_string("unknown"); - LTTV_BDEV_IDLE = g_quark_from_string("idle"); - LTTV_BDEV_BUSY_READING = g_quark_from_string("busy_reading"); - LTTV_BDEV_BUSY_WRITING = g_quark_from_string("busy_writing"); + LTTV_STATE_UNNAMED = g_quark_from_string(""); + LTTV_STATE_UNBRANDED = g_quark_from_string(""); + LTTV_STATE_MODE_UNKNOWN = g_quark_from_string("MODE_UNKNOWN"); + LTTV_STATE_USER_MODE = g_quark_from_string("USER_MODE"); + LTTV_STATE_SYSCALL = g_quark_from_string("SYSCALL"); + LTTV_STATE_TRAP = g_quark_from_string("TRAP"); + LTTV_STATE_IRQ = g_quark_from_string("IRQ"); + LTTV_STATE_SOFT_IRQ = g_quark_from_string("SOFTIRQ"); + LTTV_STATE_SUBMODE_UNKNOWN = g_quark_from_string("UNKNOWN"); + LTTV_STATE_SUBMODE_NONE = g_quark_from_string("NONE"); + LTTV_STATE_WAIT_FORK = g_quark_from_string("WAIT_FORK"); + LTTV_STATE_WAIT_CPU = g_quark_from_string("WAIT_CPU"); + LTTV_STATE_EXIT = g_quark_from_string("EXIT"); + LTTV_STATE_ZOMBIE = g_quark_from_string("ZOMBIE"); + LTTV_STATE_WAIT = g_quark_from_string("WAIT"); + LTTV_STATE_RUN = g_quark_from_string("RUN"); + LTTV_STATE_DEAD = g_quark_from_string("DEAD"); + LTTV_STATE_USER_THREAD = g_quark_from_string("USER_THREAD"); + LTTV_STATE_KERNEL_THREAD = g_quark_from_string("KERNEL_THREAD"); + LTTV_STATE_TRACEFILES = g_quark_from_string("tracefiles"); + LTTV_STATE_PROCESSES = g_quark_from_string("processes"); + LTTV_STATE_PROCESS = g_quark_from_string("process"); + LTTV_STATE_RUNNING_PROCESS = g_quark_from_string("running_process"); + LTTV_STATE_EVENT = g_quark_from_string("event"); + LTTV_STATE_SAVED_STATES = g_quark_from_string("saved states"); + LTTV_STATE_SAVED_STATES_TIME = g_quark_from_string("saved states time"); + LTTV_STATE_TIME = g_quark_from_string("time"); + LTTV_STATE_HOOKS = g_quark_from_string("saved state hooks"); + LTTV_STATE_NAME_TABLES = g_quark_from_string("name tables"); + LTTV_STATE_TRACE_STATE_USE_COUNT = + g_quark_from_string("trace_state_use_count"); + LTTV_STATE_RESOURCE_CPUS = g_quark_from_string("cpu resource states"); + LTTV_STATE_RESOURCE_CPUS = g_quark_from_string("cpu count"); + LTTV_STATE_RESOURCE_IRQS = g_quark_from_string("irq resource states"); + LTTV_STATE_RESOURCE_SOFT_IRQS = g_quark_from_string("soft irq resource states"); + LTTV_STATE_RESOURCE_TRAPS = g_quark_from_string("trap resource states"); + LTTV_STATE_RESOURCE_BLKDEVS = g_quark_from_string("blkdevs resource states"); + + LTT_CHANNEL_FD_STATE = g_quark_from_string("fd_state"); + LTT_CHANNEL_GLOBAL_STATE = g_quark_from_string("global_state"); + LTT_CHANNEL_IRQ_STATE = g_quark_from_string("irq_state"); + LTT_CHANNEL_MODULE_STATE = g_quark_from_string("module_state"); + LTT_CHANNEL_NETIF_STATE = g_quark_from_string("netif_state"); + LTT_CHANNEL_SOFTIRQ_STATE = g_quark_from_string("softirq_state"); + LTT_CHANNEL_SWAP_STATE = g_quark_from_string("swap_state"); + LTT_CHANNEL_SYSCALL_STATE = g_quark_from_string("syscall_state"); + LTT_CHANNEL_TASK_STATE = g_quark_from_string("task_state"); + LTT_CHANNEL_VM_STATE = g_quark_from_string("vm_state"); + LTT_CHANNEL_KPROBE_STATE = g_quark_from_string("kprobe_state"); + LTT_CHANNEL_FS = g_quark_from_string("fs"); + LTT_CHANNEL_KERNEL = g_quark_from_string("kernel"); + LTT_CHANNEL_MM = g_quark_from_string("mm"); + LTT_CHANNEL_USERSPACE = g_quark_from_string("userspace"); + LTT_CHANNEL_BLOCK = g_quark_from_string("block"); + + LTT_EVENT_SYSCALL_ENTRY = g_quark_from_string("syscall_entry"); + LTT_EVENT_SYSCALL_EXIT = g_quark_from_string("syscall_exit"); + LTT_EVENT_TRAP_ENTRY = g_quark_from_string("trap_entry"); + LTT_EVENT_TRAP_EXIT = g_quark_from_string("trap_exit"); + LTT_EVENT_PAGE_FAULT_ENTRY = g_quark_from_string("page_fault_entry"); + LTT_EVENT_PAGE_FAULT_EXIT = g_quark_from_string("page_fault_exit"); + LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY = g_quark_from_string("page_fault_nosem_entry"); + LTT_EVENT_PAGE_FAULT_NOSEM_EXIT = g_quark_from_string("page_fault_nosem_exit"); + LTT_EVENT_IRQ_ENTRY = g_quark_from_string("irq_entry"); + LTT_EVENT_IRQ_EXIT = g_quark_from_string("irq_exit"); + LTT_EVENT_SOFT_IRQ_RAISE = g_quark_from_string("softirq_raise"); + LTT_EVENT_SOFT_IRQ_ENTRY = g_quark_from_string("softirq_entry"); + LTT_EVENT_SOFT_IRQ_EXIT = g_quark_from_string("softirq_exit"); + LTT_EVENT_SCHED_SCHEDULE = g_quark_from_string("sched_schedule"); + LTT_EVENT_SCHED_TRY_WAKEUP = g_quark_from_string("sched_try_wakeup"); + LTT_EVENT_PROCESS_FORK = g_quark_from_string("process_fork"); + LTT_EVENT_KTHREAD_CREATE = g_quark_from_string("kthread_create"); + LTT_EVENT_PROCESS_EXIT = g_quark_from_string("process_exit"); + LTT_EVENT_PROCESS_FREE = g_quark_from_string("process_free"); + LTT_EVENT_EXEC = g_quark_from_string("exec"); + LTT_EVENT_PROCESS_STATE = g_quark_from_string("process_state"); + LTT_EVENT_STATEDUMP_END = g_quark_from_string("statedump_end"); + LTT_EVENT_FUNCTION_ENTRY = g_quark_from_string("function_entry"); + LTT_EVENT_FUNCTION_EXIT = g_quark_from_string("function_exit"); + LTT_EVENT_THREAD_BRAND = g_quark_from_string("thread_brand"); + LTT_EVENT_REQUEST_ISSUE = g_quark_from_string("_blk_request_issue"); + LTT_EVENT_REQUEST_COMPLETE = g_quark_from_string("_blk_request_complete"); + LTT_EVENT_LIST_INTERRUPT = g_quark_from_string("interrupt"); + LTT_EVENT_SYS_CALL_TABLE = g_quark_from_string("sys_call_table"); + LTT_EVENT_SOFTIRQ_VEC = g_quark_from_string("softirq_vec"); + LTT_EVENT_KPROBE_TABLE = g_quark_from_string("kprobe_table"); + LTT_EVENT_KPROBE = g_quark_from_string("kprobe"); + LTT_EVENT_OPEN = g_quark_from_string("open"); + LTT_EVENT_READ = g_quark_from_string("read"); + LTT_EVENT_POLL_EVENT = g_quark_from_string("poll_event"); + + LTT_FIELD_SYSCALL_ID = g_quark_from_string("syscall_id"); + LTT_FIELD_TRAP_ID = g_quark_from_string("trap_id"); + LTT_FIELD_IRQ_ID = g_quark_from_string("irq_id"); + LTT_FIELD_SOFT_IRQ_ID = g_quark_from_string("softirq_id"); + LTT_FIELD_PREV_PID = g_quark_from_string("prev_pid"); + LTT_FIELD_NEXT_PID = g_quark_from_string("next_pid"); + LTT_FIELD_PREV_STATE = g_quark_from_string("prev_state"); + LTT_FIELD_PARENT_PID = g_quark_from_string("parent_pid"); + LTT_FIELD_CHILD_PID = g_quark_from_string("child_pid"); + LTT_FIELD_PID = g_quark_from_string("pid"); + LTT_FIELD_TGID = g_quark_from_string("tgid"); + LTT_FIELD_CHILD_TGID = g_quark_from_string("child_tgid"); + LTT_FIELD_FILENAME = g_quark_from_string("filename"); + LTT_FIELD_NAME = g_quark_from_string("name"); + LTT_FIELD_TYPE = g_quark_from_string("type"); + LTT_FIELD_MODE = g_quark_from_string("mode"); + LTT_FIELD_SUBMODE = g_quark_from_string("submode"); + LTT_FIELD_STATUS = g_quark_from_string("status"); + LTT_FIELD_THIS_FN = g_quark_from_string("this_fn"); + LTT_FIELD_CALL_SITE = g_quark_from_string("call_site"); + LTT_FIELD_MAJOR = g_quark_from_string("major"); + LTT_FIELD_MINOR = g_quark_from_string("minor"); + LTT_FIELD_OPERATION = g_quark_from_string("direction"); + LTT_FIELD_ACTION = g_quark_from_string("action"); + LTT_FIELD_ID = g_quark_from_string("id"); + LTT_FIELD_ADDRESS = g_quark_from_string("address"); + LTT_FIELD_SYMBOL = g_quark_from_string("symbol"); + LTT_FIELD_IP = g_quark_from_string("ip"); + LTT_FIELD_FD = g_quark_from_string("fd"); + LTT_FIELD_STATE = g_quark_from_string("state"); + LTT_FIELD_CPU_ID = g_quark_from_string("cpu_id"); + + LTTV_CPU_UNKNOWN = g_quark_from_string("unknown"); + LTTV_CPU_IDLE = g_quark_from_string("idle"); + LTTV_CPU_BUSY = g_quark_from_string("busy"); + LTTV_CPU_IRQ = g_quark_from_string("irq"); + LTTV_CPU_SOFT_IRQ = g_quark_from_string("softirq"); + LTTV_CPU_TRAP = g_quark_from_string("trap"); + + LTTV_IRQ_UNKNOWN = g_quark_from_string("unknown"); + LTTV_IRQ_IDLE = g_quark_from_string("idle"); + LTTV_IRQ_BUSY = g_quark_from_string("busy"); + + LTTV_BDEV_UNKNOWN = g_quark_from_string("unknown"); + LTTV_BDEV_IDLE = g_quark_from_string("idle"); + LTTV_BDEV_BUSY_READING = g_quark_from_string("busy_reading"); + LTTV_BDEV_BUSY_WRITING = g_quark_from_string("busy_writing"); } static void module_destroy() @@ -4572,8 +4558,8 @@ static void module_destroy() LTTV_MODULE("state", "State computation", \ - "Update the system state, possibly saving it at intervals", \ - module_init, module_destroy) + "Update the system state, possibly saving it at intervals", \ + module_init, module_destroy) diff --git a/lttv/lttv/state.h b/lttv/lttv/state.h index 25d5a062..1e6efb57 100644 --- a/lttv/lttv/state.h +++ b/lttv/lttv/state.h @@ -56,95 +56,95 @@ /* Channel Quarks */ extern GQuark - LTT_CHANNEL_FD_STATE, - LTT_CHANNEL_GLOBAL_STATE, - LTT_CHANNEL_IRQ_STATE, - LTT_CHANNEL_MODULE_STATE, - LTT_CHANNEL_NETIF_STATE, - LTT_CHANNEL_SOFTIRQ_STATE, - LTT_CHANNEL_SWAP_STATE, - LTT_CHANNEL_SYSCALL_STATE, - LTT_CHANNEL_TASK_STATE, - LTT_CHANNEL_VM_STATE, - LTT_CHANNEL_KPROBE_STATE, - LTT_CHANNEL_FS, - LTT_CHANNEL_KERNEL, - LTT_CHANNEL_MM, - LTT_CHANNEL_USERSPACE, - LTT_CHANNEL_BLOCK; + LTT_CHANNEL_FD_STATE, + LTT_CHANNEL_GLOBAL_STATE, + LTT_CHANNEL_IRQ_STATE, + LTT_CHANNEL_MODULE_STATE, + LTT_CHANNEL_NETIF_STATE, + LTT_CHANNEL_SOFTIRQ_STATE, + LTT_CHANNEL_SWAP_STATE, + LTT_CHANNEL_SYSCALL_STATE, + LTT_CHANNEL_TASK_STATE, + LTT_CHANNEL_VM_STATE, + LTT_CHANNEL_KPROBE_STATE, + LTT_CHANNEL_FS, + LTT_CHANNEL_KERNEL, + LTT_CHANNEL_MM, + LTT_CHANNEL_USERSPACE, + LTT_CHANNEL_BLOCK; /* Events Quarks */ extern GQuark - LTT_EVENT_SYSCALL_ENTRY, - LTT_EVENT_SYSCALL_EXIT, - LTT_EVENT_TRAP_ENTRY, - LTT_EVENT_TRAP_EXIT, - LTT_EVENT_PAGE_FAULT_ENTRY, - LTT_EVENT_PAGE_FAULT_EXIT, - LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY, - LTT_EVENT_PAGE_FAULT_NOSEM_EXIT, - LTT_EVENT_IRQ_ENTRY, - LTT_EVENT_IRQ_EXIT, - LTT_EVENT_SOFT_IRQ_RAISE, - LTT_EVENT_SOFT_IRQ_ENTRY, - LTT_EVENT_SOFT_IRQ_EXIT, - LTT_EVENT_SCHED_SCHEDULE, - LTT_EVENT_SCHED_TRY_WAKEUP, - LTT_EVENT_PROCESS_FORK, - LTT_EVENT_KTHREAD_CREATE, - LTT_EVENT_PROCESS_EXIT, - LTT_EVENT_PROCESS_FREE, - LTT_EVENT_EXEC, - LTT_EVENT_PROCESS_STATE, - LTT_EVENT_STATEDUMP_END, - LTT_EVENT_FUNCTION_ENTRY, - LTT_EVENT_FUNCTION_EXIT, - LTT_EVENT_THREAD_BRAND, - LTT_EVENT_REQUEST_ISSUE, - LTT_EVENT_REQUEST_COMPLETE, - LTT_EVENT_LIST_INTERRUPT, - LTT_EVENT_SYS_CALL_TABLE, - LTT_EVENT_SOFTIRQ_VEC, - LTT_EVENT_KPROBE_TABLE, - LTT_EVENT_KPROBE, - LTT_EVENT_OPEN, - LTT_EVENT_READ, - LTT_EVENT_POLL_EVENT; + LTT_EVENT_SYSCALL_ENTRY, + LTT_EVENT_SYSCALL_EXIT, + LTT_EVENT_TRAP_ENTRY, + LTT_EVENT_TRAP_EXIT, + LTT_EVENT_PAGE_FAULT_ENTRY, + LTT_EVENT_PAGE_FAULT_EXIT, + LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY, + LTT_EVENT_PAGE_FAULT_NOSEM_EXIT, + LTT_EVENT_IRQ_ENTRY, + LTT_EVENT_IRQ_EXIT, + LTT_EVENT_SOFT_IRQ_RAISE, + LTT_EVENT_SOFT_IRQ_ENTRY, + LTT_EVENT_SOFT_IRQ_EXIT, + LTT_EVENT_SCHED_SCHEDULE, + LTT_EVENT_SCHED_TRY_WAKEUP, + LTT_EVENT_PROCESS_FORK, + LTT_EVENT_KTHREAD_CREATE, + LTT_EVENT_PROCESS_EXIT, + LTT_EVENT_PROCESS_FREE, + LTT_EVENT_EXEC, + LTT_EVENT_PROCESS_STATE, + LTT_EVENT_STATEDUMP_END, + LTT_EVENT_FUNCTION_ENTRY, + LTT_EVENT_FUNCTION_EXIT, + LTT_EVENT_THREAD_BRAND, + LTT_EVENT_REQUEST_ISSUE, + LTT_EVENT_REQUEST_COMPLETE, + LTT_EVENT_LIST_INTERRUPT, + LTT_EVENT_SYS_CALL_TABLE, + LTT_EVENT_SOFTIRQ_VEC, + LTT_EVENT_KPROBE_TABLE, + LTT_EVENT_KPROBE, + LTT_EVENT_OPEN, + LTT_EVENT_READ, + LTT_EVENT_POLL_EVENT; /* Fields Quarks */ extern GQuark - LTT_FIELD_SYSCALL_ID, - LTT_FIELD_TRAP_ID, - LTT_FIELD_IRQ_ID, - LTT_FIELD_SOFT_IRQ_ID, - LTT_FIELD_PREV_PID, - LTT_FIELD_NEXT_PID, - LTT_FIELD_PREV_STATE, - LTT_FIELD_PARENT_PID, - LTT_FIELD_CHILD_PID, - LTT_FIELD_PID, - LTT_FIELD_TGID, - LTT_FIELD_FILENAME, - LTT_FIELD_NAME, - LTT_FIELD_TYPE, - LTT_FIELD_MODE, - LTT_FIELD_SUBMODE, - LTT_FIELD_STATUS, - LTT_FIELD_THIS_FN, - LTT_FIELD_CALL_SITE, - LTT_FIELD_MINOR, - LTT_FIELD_MAJOR, - LTT_FIELD_OPERATION, - LTT_FIELD_ACTION, - LTT_FIELD_ID, - LTT_FIELD_ADDRESS, - LTT_FIELD_SYMBOL, - LTT_FIELD_IP, - LTT_FIELD_FD, - LTT_FIELD_STATE, - LTT_FIELD_CPU_ID; + LTT_FIELD_SYSCALL_ID, + LTT_FIELD_TRAP_ID, + LTT_FIELD_IRQ_ID, + LTT_FIELD_SOFT_IRQ_ID, + LTT_FIELD_PREV_PID, + LTT_FIELD_NEXT_PID, + LTT_FIELD_PREV_STATE, + LTT_FIELD_PARENT_PID, + LTT_FIELD_CHILD_PID, + LTT_FIELD_PID, + LTT_FIELD_TGID, + LTT_FIELD_FILENAME, + LTT_FIELD_NAME, + LTT_FIELD_TYPE, + LTT_FIELD_MODE, + LTT_FIELD_SUBMODE, + LTT_FIELD_STATUS, + LTT_FIELD_THIS_FN, + LTT_FIELD_CALL_SITE, + LTT_FIELD_MINOR, + LTT_FIELD_MAJOR, + LTT_FIELD_OPERATION, + LTT_FIELD_ACTION, + LTT_FIELD_ID, + LTT_FIELD_ADDRESS, + LTT_FIELD_SYMBOL, + LTT_FIELD_IP, + LTT_FIELD_FD, + LTT_FIELD_STATE, + LTT_FIELD_CPU_ID; typedef struct _LttvTracesetState LttvTracesetState; typedef struct _LttvTracesetStateClass LttvTracesetStateClass; @@ -191,12 +191,12 @@ void lttv_state_traceset_seek_time_closest(LttvTracesetState *self, LttTime t); typedef GQuark LttvExecutionMode; extern LttvExecutionMode - LTTV_STATE_USER_MODE, - LTTV_STATE_SYSCALL, - LTTV_STATE_TRAP, - LTTV_STATE_IRQ, - LTTV_STATE_SOFT_IRQ, - LTTV_STATE_MODE_UNKNOWN; + LTTV_STATE_USER_MODE, + LTTV_STATE_SYSCALL, + LTTV_STATE_TRAP, + LTTV_STATE_IRQ, + LTTV_STATE_SOFT_IRQ, + LTTV_STATE_MODE_UNKNOWN; /* The submode number depends on the execution mode. For user mode or kernel @@ -208,8 +208,8 @@ extern LttvExecutionMode typedef GQuark LttvExecutionSubmode; extern LttvExecutionSubmode - LTTV_STATE_SUBMODE_NONE, - LTTV_STATE_SUBMODE_UNKNOWN; + LTTV_STATE_SUBMODE_NONE, + LTTV_STATE_SUBMODE_UNKNOWN; /* The process status is one of "running", "wait-cpu" (runnable), or "wait-*" where "*" describes the resource waited for (e.g. timer, process, @@ -218,95 +218,94 @@ extern LttvExecutionSubmode typedef GQuark LttvProcessStatus; extern LttvProcessStatus - LTTV_STATE_UNNAMED, - LTTV_STATE_WAIT_FORK, - LTTV_STATE_WAIT_CPU, - LTTV_STATE_EXIT, - LTTV_STATE_ZOMBIE, - LTTV_STATE_WAIT, - LTTV_STATE_RUN, - LTTV_STATE_DEAD; + LTTV_STATE_UNNAMED, + LTTV_STATE_WAIT_FORK, + LTTV_STATE_WAIT_CPU, + LTTV_STATE_EXIT, + LTTV_STATE_ZOMBIE, + LTTV_STATE_WAIT, + LTTV_STATE_RUN, + LTTV_STATE_DEAD; extern GQuark - LTTV_STATE_UNBRANDED; + LTTV_STATE_UNBRANDED; typedef GQuark LttvProcessType; extern LttvProcessType - LTTV_STATE_USER_THREAD, - LTTV_STATE_KERNEL_THREAD; + LTTV_STATE_USER_THREAD, + LTTV_STATE_KERNEL_THREAD; typedef GQuark LttvCPUMode; extern LttvCPUMode - LTTV_CPU_UNKNOWN, - LTTV_CPU_IDLE, - LTTV_CPU_BUSY, - LTTV_CPU_IRQ, - LTTV_CPU_SOFT_IRQ, - LTTV_CPU_TRAP; + LTTV_CPU_UNKNOWN, + LTTV_CPU_IDLE, + LTTV_CPU_BUSY, + LTTV_CPU_IRQ, + LTTV_CPU_SOFT_IRQ, + LTTV_CPU_TRAP; typedef GQuark LttvIRQMode; extern LttvIRQMode - LTTV_IRQ_UNKNOWN, - LTTV_IRQ_IDLE, - LTTV_IRQ_BUSY; + LTTV_IRQ_UNKNOWN, + LTTV_IRQ_IDLE, + LTTV_IRQ_BUSY; typedef GQuark LttvBdevMode; extern LttvBdevMode - LTTV_BDEV_UNKNOWN, - LTTV_BDEV_IDLE, - LTTV_BDEV_BUSY_READING, - LTTV_BDEV_BUSY_WRITING; + LTTV_BDEV_UNKNOWN, + LTTV_BDEV_IDLE, + LTTV_BDEV_BUSY_READING, + LTTV_BDEV_BUSY_WRITING; typedef struct _LttvExecutionState { - LttvExecutionMode t; - LttvExecutionSubmode n; - LttTime entry; - LttTime change; - LttTime cum_cpu_time; - LttvProcessStatus s; + LttvExecutionMode t; + LttvExecutionSubmode n; + LttTime entry; + LttTime change; + LttTime cum_cpu_time; + LttvProcessStatus s; } LttvExecutionState; typedef struct _LttvProcessState { - guint pid; - guint tgid; - guint ppid; - LttTime creation_time; - LttTime insertion_time; - GQuark name; - GQuark brand; - GQuark pid_time; - GArray *execution_stack; /* Array of LttvExecutionState */ - LttvExecutionState *state; /* Top of interrupt stack */ - /* WARNING : each time the execution_stack size is modified, the state - * must be reget : g_array_set_size can have to move the array. - * (Mathieu) */ - guint cpu; /* CPU where process is scheduled (being either in - the active or inactive runqueue)*/ -// guint last_tracefile_index; /* index in the trace for cpu tracefile */ - LttvTracefileState *usertrace; /* Associated usertrace */ - /* opened file descriptors, address map?... */ - GArray *user_stack; /* User space function call stack */ - guint64 current_function; - LttvProcessType type; /* kernel thread or user space ? */ - guint target_pid; /* target PID of the current event. */ - guint free_events; /* 0 : none, 1 : free or exit dead, 2 : should delete */ - GHashTable *fds; /* hash table of int (file descriptor) -> GQuark (file name) */ + guint pid; + guint tgid; + guint ppid; + LttTime creation_time; + LttTime insertion_time; + GQuark name; + GQuark brand; + GQuark pid_time; + GArray *execution_stack; /* Array of LttvExecutionState */ + LttvExecutionState *state; /* Top of interrupt stack */ + /* WARNING : each time the execution_stack size is modified, the state + * must be reget : g_array_set_size can have to move the array. + * (Mathieu) */ + guint cpu; /* CPU where process is scheduled (being either in + the active or inactive runqueue)*/ +// guint last_tracefile_index; /* index in the trace for cpu tracefile */ + LttvTracefileState *usertrace; /* Associated usertrace */ + /* opened file descriptors, address map?... */ + GArray *user_stack; /* User space function call stack */ + guint64 current_function; + LttvProcessType type; /* kernel thread or user space ? */ + guint target_pid; /* target PID of the current event. */ + guint free_events; /* 0 : none, 1 : free or exit dead, 2 : should delete */ + GHashTable *fds; /* hash table of int (file descriptor) -> GQuark (file name) */ } LttvProcessState; #define ANY_CPU 0 /* For clarity sake : a call to lttv_state_find_process for a PID != 0 will search on any cpu automatically. */ -LttvProcessState * -lttv_state_find_process(LttvTraceState *ts, guint cpu, guint pid); +LttvProcessState *lttv_state_find_process(LttvTraceState *ts, guint cpu, + guint pid); -LttvProcessState * -lttv_state_find_process_or_create(LttvTraceState *ts, guint cpu, guint pid, - const LttTime *timestamp); +LttvProcessState *lttv_state_find_process_or_create(LttvTraceState *ts, + guint cpu, guint pid, const LttTime *timestamp); -LttvProcessState * -lttv_state_create_process(LttvTraceState *tcs, LttvProcessState *parent, - guint cpu, guint pid, guint tgid, GQuark name, const LttTime *timestamp); +LttvProcessState *lttv_state_create_process(LttvTraceState *tcs, + LttvProcessState *parent, guint cpu, guint pid, + guint tgid, GQuark name, const LttTime *timestamp); void lttv_state_write(LttvTraceState *self, LttTime t, FILE *fp); void lttv_state_write_raw(LttvTraceState *self, LttTime t, FILE *fp); @@ -322,11 +321,11 @@ void lttv_state_write_raw(LttvTraceState *self, LttTime t, FILE *fp); #define LTTV_TRACESET_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACESET_STATE_TYPE, LttvTracesetStateClass)) struct _LttvTracesetState { - LttvTracesetContext parent; + LttvTracesetContext parent; }; struct _LttvTracesetStateClass { - LttvTracesetContextClass parent; + LttvTracesetContextClass parent; }; GType lttv_traceset_state_get_type (void); @@ -340,74 +339,74 @@ GType lttv_traceset_state_get_type (void); #define LTTV_TRACE_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_STATE_TYPE, LttvTraceStateClass)) typedef struct _LttvCPUState { - GArray *mode_stack; - GArray *irq_stack; - GArray *softirq_stack; - GArray *trap_stack; + GArray *mode_stack; + GArray *irq_stack; + GArray *softirq_stack; + GArray *trap_stack; } LttvCPUState; typedef struct _LttvIRQState { - GArray *mode_stack; + GArray *mode_stack; } LttvIRQState; typedef struct _LttvSoftIRQState { - guint pending; /* number of times it is pending */ - guint running; /* number of times it is currently running (on different processors) */ + guint pending; /* number of times it is pending */ + guint running; /* number of times it is currently running (on different processors) */ } LttvSoftIRQState; typedef struct _LttvTrapState { - guint running; /* number of times it is currently running (on different processors) */ + guint running; /* number of times it is currently running (on different processors) */ } LttvTrapState; typedef struct _LttvBdevState { - GArray *mode_stack; + GArray *mode_stack; } LttvBdevState; typedef struct _LttvNameTables { - GQuark *syscall_names; - guint nb_syscalls; - GQuark *trap_names; - guint nb_traps; - GQuark *irq_names; - guint nb_irqs; - GQuark *soft_irq_names; - guint nb_soft_irqs; - GHashTable *kprobe_hash; + GQuark *syscall_names; + guint nb_syscalls; + GQuark *trap_names; + guint nb_traps; + GQuark *irq_names; + guint nb_irqs; + GQuark *soft_irq_names; + guint nb_soft_irqs; + GHashTable *kprobe_hash; } LttvNameTables; struct _LttvTraceState { - LttvTraceContext parent; - - GHashTable *processes; /* LttvProcessState objects indexed by pid and - last_cpu */ - GHashTable *usertraces; /* GPtrArray objects indexed by pid, containing - pointers to LttvTracefileState objects. */ - guint nb_event, save_interval; - /* Block/char devices, locks, memory pages... */ - GQuark *eventtype_names; - LttvNameTables *name_tables; - LttTime *max_time_state_recomputed_in_seek; - GHashTable *kprobe_hash; - - /* Array of per cpu running process */ - LttvProcessState **running_process; - gboolean has_precomputed_states; - LttvCPUState *cpu_states; /* state of each cpu */ - /* FIXME should be a g_array to deal with resize and copy. */ - LttvIRQState *irq_states; /* state of each irq handler */ - /* FIXME should be a g_array to deal with resize and copy. */ - LttvSoftIRQState *soft_irq_states; /* state of each softirq */ - /* FIXME should be a g_array to deal with resize and copy. */ - LttvTrapState *trap_states; /* state of each trap */ - GHashTable *bdev_states; /* state of the block devices */ + LttvTraceContext parent; + + GHashTable *processes; /* LttvProcessState objects indexed by pid and + last_cpu */ + GHashTable *usertraces; /* GPtrArray objects indexed by pid, containing + pointers to LttvTracefileState objects. */ + guint nb_event, save_interval; + /* Block/char devices, locks, memory pages... */ + GQuark *eventtype_names; + LttvNameTables *name_tables; + LttTime *max_time_state_recomputed_in_seek; + GHashTable *kprobe_hash; + + /* Array of per cpu running process */ + LttvProcessState **running_process; + gboolean has_precomputed_states; + LttvCPUState *cpu_states; /* state of each cpu */ + /* FIXME should be a g_array to deal with resize and copy. */ + LttvIRQState *irq_states; /* state of each irq handler */ + /* FIXME should be a g_array to deal with resize and copy. */ + LttvSoftIRQState *soft_irq_states; /* state of each softirq */ + /* FIXME should be a g_array to deal with resize and copy. */ + LttvTrapState *trap_states; /* state of each trap */ + GHashTable *bdev_states; /* state of the block devices */ }; struct _LttvTraceStateClass { - LttvTraceContextClass parent; + LttvTraceContextClass parent; - void (*state_save) (LttvTraceState *self, LttvAttribute *container); - void (*state_restore) (LttvTraceState *self, LttvAttribute *container); - void (*state_saved_free) (LttvTraceState *self, LttvAttribute *container); + void (*state_save) (LttvTraceState *self, LttvAttribute *container); + void (*state_restore) (LttvTraceState *self, LttvAttribute *container); + void (*state_saved_free) (LttvTraceState *self, LttvAttribute *container); }; GType lttv_trace_state_get_type (void); @@ -417,10 +416,10 @@ void lttv_state_save(LttvTraceState *self, LttvAttribute *container); void lttv_state_restore(LttvTraceState *self, LttvAttribute *container); void lttv_state_state_saved_free(LttvTraceState *self, - LttvAttribute *container); + LttvAttribute *container); int lttv_state_pop_state_cleanup(LttvProcessState *process, - LttvTracefileState *tfs); + LttvTracefileState *tfs); #define LTTV_TRACEFILE_STATE_TYPE (lttv_tracefile_state_get_type ()) #define LTTV_TRACEFILE_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACEFILE_STATE_TYPE, LttvTracefileState)) @@ -430,27 +429,27 @@ int lttv_state_pop_state_cleanup(LttvProcessState *process, #define LTTV_TRACEFILE_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_STATE_TYPE, LttvTracefileStateClass)) struct _LttvTracefileState { - LttvTracefileContext parent; + LttvTracefileContext parent; - GQuark tracefile_name; - guint cpu; /* Current cpu of the tracefile */ /* perhaps merge in cpu_state */ - LttvCPUState *cpu_state; /* cpu resource state */ + GQuark tracefile_name; + guint cpu; /* Current cpu of the tracefile */ /* perhaps merge in cpu_state */ + LttvCPUState *cpu_state; /* cpu resource state */ }; struct _LttvTracefileStateClass { - LttvTracefileContextClass parent; + LttvTracefileContextClass parent; }; GType lttv_tracefile_state_get_type (void); static inline guint lttv_state_get_target_pid(LttvTracefileState *tfs) { - LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; - guint cpu = tfs->cpu; - LttvProcessState *process = ts->running_process[cpu]; + LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; + guint cpu = tfs->cpu; + LttvProcessState *process = ts->running_process[cpu]; - if(tfs->parent.target_pid >= 0) return tfs->parent.target_pid; - else return process->pid; + if(tfs->parent.target_pid >= 0) return tfs->parent.target_pid; + else return process->pid; } diff --git a/lttv/lttv/stats.c b/lttv/lttv/stats.c index 24b4ad4c..5c533ce4 100644 --- a/lttv/lttv/stats.c +++ b/lttv/lttv/stats.c @@ -33,1375 +33,1356 @@ #define MAX_64_HEX_STRING_LEN 19 GQuark - LTTV_STATS_PROCESS_UNKNOWN, - LTTV_STATS_PROCESSES, - LTTV_STATS_CPU, - LTTV_STATS_MODE_TYPES, - LTTV_STATS_MODES, - LTTV_STATS_SUBMODES, - LTTV_STATS_FUNCTIONS, - LTTV_STATS_EVENT_TYPES, - LTTV_STATS_CPU_TIME, - LTTV_STATS_CUMULATIVE_CPU_TIME, - LTTV_STATS_ELAPSED_TIME, - LTTV_STATS_EVENTS, - LTTV_STATS_EVENTS_COUNT, - LTTV_STATS_USE_COUNT, - LTTV_STATS, - LTTV_STATS_TRACEFILES, - LTTV_STATS_SUMMED, - LTTV_STATS_BEFORE_HOOKS, - LTTV_STATS_AFTER_HOOKS; - -static void -find_event_tree(LttvTracefileStats *tfcs, GQuark pid_time, guint cpu, - guint64 function, - GQuark mode, GQuark sub_mode, LttvAttribute **events_tree, - LttvAttribute **event_types_tree); + LTTV_STATS_PROCESS_UNKNOWN, + LTTV_STATS_PROCESSES, + LTTV_STATS_CPU, + LTTV_STATS_MODE_TYPES, + LTTV_STATS_MODES, + LTTV_STATS_SUBMODES, + LTTV_STATS_FUNCTIONS, + LTTV_STATS_EVENT_TYPES, + LTTV_STATS_CPU_TIME, + LTTV_STATS_CUMULATIVE_CPU_TIME, + LTTV_STATS_ELAPSED_TIME, + LTTV_STATS_EVENTS, + LTTV_STATS_EVENTS_COUNT, + LTTV_STATS_USE_COUNT, + LTTV_STATS, + LTTV_STATS_TRACEFILES, + LTTV_STATS_SUMMED, + LTTV_STATS_BEFORE_HOOKS, + LTTV_STATS_AFTER_HOOKS; + +static void find_event_tree(LttvTracefileStats *tfcs, GQuark pid_time, + guint cpu, guint64 function, + GQuark mode, GQuark sub_mode, LttvAttribute **events_tree, + LttvAttribute **event_types_tree); static void lttv_stats_init(LttvTracesetStats *self) { - guint i, j, nb_trace, nb_tracefile; + guint i, j, nb_trace, nb_tracefile; - LttvTraceContext *tc; + LttvTraceContext *tc; - LttvTraceStats *tcs; + LttvTraceStats *tcs; - LttvTracefileContext **tfs; - LttvTracefileStats *tfcs; - - LttvAttributeValue v; + LttvTracefileContext **tfs; + LttvTracefileStats *tfcs; - LttvAttribute *tracefiles_stats; + LttvAttributeValue v; - LttvTraceset *ts = self->parent.parent.ts; + LttvAttribute *tracefiles_stats; - self->stats = lttv_attribute_find_subdir( - lttv_traceset_attribute(self->parent.parent.ts), - LTTV_STATS); - lttv_attribute_find(lttv_traceset_attribute(self->parent.parent.ts), - LTTV_STATS_USE_COUNT, - LTTV_UINT, &v); + LttvTraceset *ts = self->parent.parent.ts; - (*(v.v_uint))++; - if(*(v.v_uint) == 1) { - g_assert(lttv_attribute_get_number(self->stats) == 0); - } + self->stats = lttv_attribute_find_subdir( + lttv_traceset_attribute(self->parent.parent.ts), LTTV_STATS); + lttv_attribute_find(lttv_traceset_attribute(self->parent.parent.ts), + LTTV_STATS_USE_COUNT, + LTTV_UINT, &v); - nb_trace = lttv_traceset_number(ts); + (*(v.v_uint))++; + if(*(v.v_uint) == 1) { + g_assert(lttv_attribute_get_number(self->stats) == 0); + } - for(i = 0 ; i < nb_trace ; i++) { - tc = self->parent.parent.traces[i]; - tcs = LTTV_TRACE_STATS(tc); + nb_trace = lttv_traceset_number(ts); - tcs->stats = lttv_attribute_find_subdir(tcs->parent.parent.t_a,LTTV_STATS); - tracefiles_stats = lttv_attribute_find_subdir(tcs->parent.parent.t_a, - LTTV_STATS_TRACEFILES); - lttv_attribute_find(tcs->parent.parent.t_a, LTTV_STATS_USE_COUNT, - LTTV_UINT, &v); + for(i = 0 ; i < nb_trace ; i++) { + tc = self->parent.parent.traces[i]; + tcs = LTTV_TRACE_STATS(tc); - (*(v.v_uint))++; - if(*(v.v_uint) == 1) { - g_assert(lttv_attribute_get_number(tcs->stats) == 0); - } + tcs->stats = lttv_attribute_find_subdir(tcs->parent.parent.t_a, + LTTV_STATS); + tracefiles_stats = lttv_attribute_find_subdir(tcs->parent.parent.t_a, + LTTV_STATS_TRACEFILES); + lttv_attribute_find(tcs->parent.parent.t_a, LTTV_STATS_USE_COUNT, + LTTV_UINT, &v); - nb_tracefile = tc->tracefiles->len; + (*(v.v_uint))++; + if(*(v.v_uint) == 1) { + g_assert(lttv_attribute_get_number(tcs->stats) == 0); + } - for(j = 0 ; j < nb_tracefile ; j++) { - tfs = &g_array_index(tc->tracefiles, - LttvTracefileContext*, j); - tfcs = LTTV_TRACEFILE_STATS(*tfs); - tfcs->stats = lttv_attribute_find_subdir(tracefiles_stats, - ltt_tracefile_long_name(tfcs->parent.parent.tf)); - guint cpu = tfcs->parent.cpu; - find_event_tree(tfcs, LTTV_STATS_PROCESS_UNKNOWN, - cpu, - 0x0ULL, - LTTV_STATE_MODE_UNKNOWN, - LTTV_STATE_SUBMODE_UNKNOWN, &tfcs->current_events_tree, - &tfcs->current_event_types_tree); - } - } + nb_tracefile = tc->tracefiles->len; + + for(j = 0 ; j < nb_tracefile ; j++) { + tfs = &g_array_index(tc->tracefiles, LttvTracefileContext*, j); + tfcs = LTTV_TRACEFILE_STATS(*tfs); + tfcs->stats = lttv_attribute_find_subdir(tracefiles_stats, + ltt_tracefile_long_name(tfcs->parent.parent.tf)); + guint cpu = tfcs->parent.cpu; + find_event_tree(tfcs, LTTV_STATS_PROCESS_UNKNOWN, + cpu, + 0x0ULL, + LTTV_STATE_MODE_UNKNOWN, + LTTV_STATE_SUBMODE_UNKNOWN, &tfcs->current_events_tree, + &tfcs->current_event_types_tree); + } + } } static void lttv_stats_fini(LttvTracesetStats *self) { - guint i, j, nb_trace, nb_tracefile; + guint i, j, nb_trace, nb_tracefile; + + LttvTraceset *ts; - LttvTraceset *ts; + LttvTraceContext *tc; - LttvTraceContext *tc; + LttvTraceStats *tcs; - LttvTraceStats *tcs; + LttvTracefileContext *tfc; - LttvTracefileContext *tfc; + LttvTracefileStats *tfcs; - LttvTracefileStats *tfcs; - - LttvAttributeValue v; + LttvAttributeValue v; - LttvAttribute *tracefiles_stats; + LttvAttribute *tracefiles_stats; - lttv_attribute_find(self->parent.parent.ts_a, LTTV_STATS_USE_COUNT, - LTTV_UINT, &v); - (*(v.v_uint))--; + lttv_attribute_find(self->parent.parent.ts_a, LTTV_STATS_USE_COUNT, + LTTV_UINT, &v); + (*(v.v_uint))--; - if(*(v.v_uint) == 0) { - lttv_attribute_remove_by_name(self->parent.parent.ts_a, LTTV_STATS); - } - self->stats = NULL; + if(*(v.v_uint) == 0) { + lttv_attribute_remove_by_name(self->parent.parent.ts_a, LTTV_STATS); + } + self->stats = NULL; - ts = self->parent.parent.ts; - nb_trace = lttv_traceset_number(ts); + ts = self->parent.parent.ts; + nb_trace = lttv_traceset_number(ts); - for(i = 0 ; i < nb_trace ; i++) { - tcs = (LttvTraceStats *)(tc = (LTTV_TRACESET_CONTEXT(self)->traces[i])); + for(i = 0 ; i < nb_trace ; i++) { + tcs = (LttvTraceStats *)(tc = (LTTV_TRACESET_CONTEXT(self)->traces[i])); - lttv_attribute_find(tcs->parent.parent.t_a, LTTV_STATS_USE_COUNT, - LTTV_UINT, &v); - (*(v.v_uint))--; + lttv_attribute_find(tcs->parent.parent.t_a, LTTV_STATS_USE_COUNT, + LTTV_UINT, &v); + (*(v.v_uint))--; - if(*(v.v_uint) == 0) { - lttv_attribute_remove_by_name(tcs->parent.parent.t_a,LTTV_STATS); - tracefiles_stats = lttv_attribute_find_subdir(tcs->parent.parent.t_a, - LTTV_STATS_TRACEFILES); - lttv_attribute_remove_by_name(tcs->parent.parent.t_a, - LTTV_STATS_TRACEFILES); - } - tcs->stats = NULL; + if(*(v.v_uint) == 0) { + lttv_attribute_remove_by_name(tcs->parent.parent.t_a,LTTV_STATS); + tracefiles_stats = lttv_attribute_find_subdir(tcs->parent.parent.t_a, + LTTV_STATS_TRACEFILES); + lttv_attribute_remove_by_name(tcs->parent.parent.t_a, + LTTV_STATS_TRACEFILES); + } + tcs->stats = NULL; - nb_tracefile = tc->tracefiles->len; + nb_tracefile = tc->tracefiles->len; - for(j = 0 ; j < nb_tracefile ; j++) { - tfc = g_array_index(tc->tracefiles, - LttvTracefileContext*, j); - tfcs = (LttvTracefileStats *)tfc; - tfcs->stats = NULL; - tfcs->current_events_tree = NULL; - tfcs->current_event_types_tree = NULL; - } - } + for(j = 0 ; j < nb_tracefile ; j++) { + tfc = g_array_index(tc->tracefiles, LttvTracefileContext*, j); + tfcs = (LttvTracefileStats *)tfc; + tfcs->stats = NULL; + tfcs->current_events_tree = NULL; + tfcs->current_event_types_tree = NULL; + } + } } void lttv_stats_reset(LttvTracesetStats *self) { - lttv_stats_fini(self); - lttv_stats_init(self); + lttv_stats_fini(self); + lttv_stats_init(self); } -static void -init(LttvTracesetStats *self, LttvTraceset *ts) +static void init(LttvTracesetStats *self, LttvTraceset *ts) { - LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_STATE_TYPE))-> - init((LttvTracesetContext *)self, ts); - - lttv_stats_init(self); + LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_STATE_TYPE))-> + init((LttvTracesetContext *)self, ts); + + lttv_stats_init(self); } -static void -fini(LttvTracesetStats *self) +static void fini(LttvTracesetStats *self) { - lttv_stats_fini(self); + lttv_stats_fini(self); - LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_STATE_TYPE))-> - fini((LttvTracesetContext *)self); + LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek(LTTV_TRACESET_STATE_TYPE))-> + fini((LttvTracesetContext *)self); } -static LttvTracesetContext * -new_traceset_context(LttvTracesetContext *self) +static LttvTracesetContext *new_traceset_context(LttvTracesetContext *self) { - return LTTV_TRACESET_CONTEXT(g_object_new(LTTV_TRACESET_STATS_TYPE, NULL)); + return LTTV_TRACESET_CONTEXT(g_object_new(LTTV_TRACESET_STATS_TYPE, NULL)); } -static LttvTraceContext * -new_trace_context(LttvTracesetContext *self) +static LttvTraceContext *new_trace_context(LttvTracesetContext *self) { - return LTTV_TRACE_CONTEXT(g_object_new(LTTV_TRACE_STATS_TYPE, NULL)); + return LTTV_TRACE_CONTEXT(g_object_new(LTTV_TRACE_STATS_TYPE, NULL)); } -static LttvTracefileContext * -new_tracefile_context(LttvTracesetContext *self) +static LttvTracefileContext *new_tracefile_context(LttvTracesetContext *self) { - return LTTV_TRACEFILE_CONTEXT(g_object_new(LTTV_TRACEFILE_STATS_TYPE, NULL)); + return LTTV_TRACEFILE_CONTEXT(g_object_new(LTTV_TRACEFILE_STATS_TYPE, NULL)); } -static void -traceset_stats_instance_init (GTypeInstance *instance, gpointer g_class) +static void traceset_stats_instance_init (GTypeInstance *instance, + gpointer g_class) { } -static void -traceset_stats_finalize (LttvTracesetStats *self) +static void traceset_stats_finalize (LttvTracesetStats *self) { - G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACESET_STATE_TYPE))-> - finalize(G_OBJECT(self)); + G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACESET_STATE_TYPE))-> + finalize(G_OBJECT(self)); } -static void -traceset_stats_class_init (LttvTracesetContextClass *klass) +static void traceset_stats_class_init (LttvTracesetContextClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - gobject_class->finalize = (void (*)(GObject *self)) traceset_stats_finalize; - klass->init = (void (*)(LttvTracesetContext *self, LttvTraceset *ts))init; - klass->fini = (void (*)(LttvTracesetContext *self))fini; - klass->new_traceset_context = new_traceset_context; - klass->new_trace_context = new_trace_context; - klass->new_tracefile_context = new_tracefile_context; + gobject_class->finalize = (void (*)(GObject *self)) traceset_stats_finalize; + klass->init = (void (*)(LttvTracesetContext *self, LttvTraceset *ts))init; + klass->fini = (void (*)(LttvTracesetContext *self))fini; + klass->new_traceset_context = new_traceset_context; + klass->new_trace_context = new_trace_context; + klass->new_tracefile_context = new_tracefile_context; } -GType -lttv_traceset_stats_get_type(void) +GType lttv_traceset_stats_get_type(void) { - static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof (LttvTracesetStatsClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) traceset_stats_class_init, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (LttvTracesetStats), - 0, /* n_preallocs */ - (GInstanceInitFunc) traceset_stats_instance_init, /* instance_init */ - NULL /* Value handling */ - }; + static GType type = 0; + if (type == 0) { + static const GTypeInfo info = { + sizeof (LttvTracesetStatsClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) traceset_stats_class_init, /* class_init */ + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (LttvTracesetStats), + 0, /* n_preallocs */ + (GInstanceInitFunc) traceset_stats_instance_init, /* instance_init */ + NULL /* Value handling */ + }; - type = g_type_register_static (LTTV_TRACESET_STATE_TYPE, - "LttvTracesetStatsType", - &info, 0); - } - return type; + type = g_type_register_static (LTTV_TRACESET_STATE_TYPE, + "LttvTracesetStatsType", &info, 0); + } + return type; } -static void -trace_stats_instance_init (GTypeInstance *instance, gpointer g_class) +static void trace_stats_instance_init (GTypeInstance *instance, + gpointer g_class) { } -static void -trace_stats_finalize (LttvTraceStats *self) +static void trace_stats_finalize (LttvTraceStats *self) { - G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACE_STATE_TYPE))-> - finalize(G_OBJECT(self)); + G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACE_STATE_TYPE))-> + finalize(G_OBJECT(self)); } -static void -trace_stats_class_init (LttvTraceContextClass *klass) +static void trace_stats_class_init (LttvTraceContextClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - gobject_class->finalize = (void (*)(GObject *self)) trace_stats_finalize; + gobject_class->finalize = (void (*)(GObject *self)) trace_stats_finalize; } -GType -lttv_trace_stats_get_type(void) +GType lttv_trace_stats_get_type(void) { - static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof (LttvTraceStatsClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) trace_stats_class_init, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (LttvTraceStats), - 0, /* n_preallocs */ - (GInstanceInitFunc) trace_stats_instance_init, /* instance_init */ - NULL /* Value handling */ - }; + static GType type = 0; + if (type == 0) { + static const GTypeInfo info = { + sizeof (LttvTraceStatsClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) trace_stats_class_init, /* class_init */ + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (LttvTraceStats), + 0, /* n_preallocs */ + (GInstanceInitFunc) trace_stats_instance_init, /* instance_init */ + NULL /* Value handling */ + }; - type = g_type_register_static (LTTV_TRACE_STATE_TYPE, - "LttvTraceStatsType", &info, 0); - } - return type; + type = g_type_register_static (LTTV_TRACE_STATE_TYPE, + "LttvTraceStatsType", &info, 0); + } + return type; } -static void -tracefile_stats_instance_init (GTypeInstance *instance, gpointer g_class) +static void tracefile_stats_instance_init (GTypeInstance *instance, + gpointer g_class) { } -static void -tracefile_stats_finalize (LttvTracefileStats *self) +static void tracefile_stats_finalize (LttvTracefileStats *self) { - G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACEFILE_STATE_TYPE))-> - finalize(G_OBJECT(self)); + G_OBJECT_CLASS(g_type_class_peek(LTTV_TRACEFILE_STATE_TYPE))-> + finalize(G_OBJECT(self)); } -static void -tracefile_stats_class_init (LttvTracefileStatsClass *klass) +static void tracefile_stats_class_init (LttvTracefileStatsClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - gobject_class->finalize = (void (*)(GObject *self)) tracefile_stats_finalize; + gobject_class->finalize = (void (*)(GObject *self)) tracefile_stats_finalize; } -GType -lttv_tracefile_stats_get_type(void) +GType lttv_tracefile_stats_get_type(void) { - static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof (LttvTracefileStatsClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) tracefile_stats_class_init, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (LttvTracefileStats), - 0, /* n_preallocs */ - (GInstanceInitFunc) tracefile_stats_instance_init, /* instance_init */ - NULL /* Value handling */ - }; + static GType type = 0; + if (type == 0) { + static const GTypeInfo info = { + sizeof (LttvTracefileStatsClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) tracefile_stats_class_init, /* class_init */ + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (LttvTracefileStats), + 0, /* n_preallocs */ + (GInstanceInitFunc) tracefile_stats_instance_init, /* instance_init */ + NULL /* Value handling */ + }; - type = g_type_register_static (LTTV_TRACEFILE_STATE_TYPE, - "LttvTracefileStatsType", &info, 0); - } - return type; + type = g_type_register_static (LTTV_TRACEFILE_STATE_TYPE, + "LttvTracefileStatsType", &info, 0); + } + return type; } -static void -find_event_tree(LttvTracefileStats *tfcs, - GQuark pid_time, - guint cpu, - guint64 function, - GQuark mode, - GQuark sub_mode, - LttvAttribute **events_tree, - LttvAttribute **event_types_tree) +static void find_event_tree(LttvTracefileStats *tfcs, + GQuark pid_time, + guint cpu, + guint64 function, + GQuark mode, + GQuark sub_mode, + LttvAttribute **events_tree, + LttvAttribute **event_types_tree) { - LttvAttribute *a; - gchar fstring[MAX_64_HEX_STRING_LEN]; - gint ret; + LttvAttribute *a; + gchar fstring[MAX_64_HEX_STRING_LEN]; + gint ret; - ret = snprintf(fstring, MAX_64_HEX_STRING_LEN-1, - "0x%" PRIX64, function) > 0; - g_assert(ret > 0); - fstring[MAX_64_HEX_STRING_LEN-1] = '\0'; + ret = snprintf(fstring, MAX_64_HEX_STRING_LEN-1, + "0x%" PRIX64, function) > 0; + g_assert(ret > 0); + fstring[MAX_64_HEX_STRING_LEN-1] = '\0'; - LttvTraceStats *tcs = (LttvTraceStats*)tfcs->parent.parent.t_context; - a = lttv_attribute_find_subdir(tcs->stats, LTTV_STATS_PROCESSES); - a = lttv_attribute_find_subdir(a, pid_time); - a = lttv_attribute_find_subdir(a, LTTV_STATS_CPU); - a = lttv_attribute_find_subdir_unnamed(a, cpu); - a = lttv_attribute_find_subdir(a, LTTV_STATS_FUNCTIONS); - a = lttv_attribute_find_subdir(a, g_quark_from_string(fstring)); - a = lttv_attribute_find_subdir(a, LTTV_STATS_MODE_TYPES); - a = lttv_attribute_find_subdir(a, mode); - a = lttv_attribute_find_subdir(a, LTTV_STATS_SUBMODES); - a = lttv_attribute_find_subdir(a, sub_mode); - *events_tree = a; - a = lttv_attribute_find_subdir(a, LTTV_STATS_EVENT_TYPES); - *event_types_tree = a; + LttvTraceStats *tcs = (LttvTraceStats*)tfcs->parent.parent.t_context; + a = lttv_attribute_find_subdir(tcs->stats, LTTV_STATS_PROCESSES); + a = lttv_attribute_find_subdir(a, pid_time); + a = lttv_attribute_find_subdir(a, LTTV_STATS_CPU); + a = lttv_attribute_find_subdir_unnamed(a, cpu); + a = lttv_attribute_find_subdir(a, LTTV_STATS_FUNCTIONS); + a = lttv_attribute_find_subdir(a, g_quark_from_string(fstring)); + a = lttv_attribute_find_subdir(a, LTTV_STATS_MODE_TYPES); + a = lttv_attribute_find_subdir(a, mode); + a = lttv_attribute_find_subdir(a, LTTV_STATS_SUBMODES); + a = lttv_attribute_find_subdir(a, sub_mode); + *events_tree = a; + a = lttv_attribute_find_subdir(a, LTTV_STATS_EVENT_TYPES); + *event_types_tree = a; } static void update_event_tree(LttvTracefileStats *tfcs) { - guint cpu = tfcs->parent.cpu; - LttvTraceState *ts = (LttvTraceState *)tfcs->parent.parent.t_context; - LttvProcessState *process = ts->running_process[cpu]; - LttvExecutionState *es = process->state; + guint cpu = tfcs->parent.cpu; + LttvTraceState *ts = (LttvTraceState *)tfcs->parent.parent.t_context; + LttvProcessState *process = ts->running_process[cpu]; + LttvExecutionState *es = process->state; - find_event_tree(tfcs, process->pid_time, - cpu, - process->current_function, - es->t, es->n, &(tfcs->current_events_tree), - &(tfcs->current_event_types_tree)); + find_event_tree(tfcs, process->pid_time, + cpu, + process->current_function, + es->t, es->n, &(tfcs->current_events_tree), + &(tfcs->current_event_types_tree)); } /* Update the trace event tree for the specified cpu */ static void update_trace_event_tree(LttvTraceStats *tcs) { - LttvTracefileStats *tfcs; - LttvTraceContext *tc = (LttvTraceContext*)tcs; - guint j, nb_tracefile; + LttvTracefileStats *tfcs; + LttvTraceContext *tc = (LttvTraceContext*)tcs; + guint j, nb_tracefile; - /* For each tracefile, update the event tree */ - nb_tracefile = tc->tracefiles->len; - for(j = 0; j < nb_tracefile; j++) { - tfcs = LTTV_TRACEFILE_STATS(g_array_index(tc->tracefiles, - LttvTracefileContext*, j)); - update_event_tree(tfcs); - } + /* For each tracefile, update the event tree */ + nb_tracefile = tc->tracefiles->len; + for(j = 0; j < nb_tracefile; j++) { + tfcs = LTTV_TRACEFILE_STATS(g_array_index(tc->tracefiles, + LttvTracefileContext*, j)); + update_event_tree(tfcs); + } } static void mode_change(LttvTracefileStats *tfcs) { - LttvTraceState *ts = (LttvTraceState *)tfcs->parent.parent.t_context; - guint cpu = tfcs->parent.cpu; - LttvProcessState *process = ts->running_process[cpu]; - LttvAttributeValue cpu_time; + LttvTraceState *ts = (LttvTraceState *)tfcs->parent.parent.t_context; + guint cpu = tfcs->parent.cpu; + LttvProcessState *process = ts->running_process[cpu]; + LttvAttributeValue cpu_time; - LttTime delta; + LttTime delta; - if(process->state->s == LTTV_STATE_RUN && - process->state->t != LTTV_STATE_MODE_UNKNOWN) - delta = ltt_time_sub(tfcs->parent.parent.timestamp, - process->state->change); - else - delta = ltt_time_zero; + if(process->state->s == LTTV_STATE_RUN && + process->state->t != LTTV_STATE_MODE_UNKNOWN) + delta = ltt_time_sub(tfcs->parent.parent.timestamp, + process->state->change); + else + delta = ltt_time_zero; - lttv_attribute_find(tfcs->current_events_tree, LTTV_STATS_CPU_TIME, - LTTV_TIME, &cpu_time); - *(cpu_time.v_time) = ltt_time_add(*(cpu_time.v_time), delta); + lttv_attribute_find(tfcs->current_events_tree, LTTV_STATS_CPU_TIME, + LTTV_TIME, &cpu_time); + *(cpu_time.v_time) = ltt_time_add(*(cpu_time.v_time), delta); - process->state->cum_cpu_time = ltt_time_add(process->state->cum_cpu_time, - delta); + process->state->cum_cpu_time = ltt_time_add(process->state->cum_cpu_time, + delta); } /* Note : every mode_end must come with a cumulative cpu time update in the * after hook. */ static void mode_end(LttvTracefileStats *tfcs) { - LttvTraceState *ts = (LttvTraceState *)tfcs->parent.parent.t_context; - guint cpu = tfcs->parent.cpu; - LttvProcessState *process = ts->running_process[cpu]; - LttvAttributeValue elapsed_time, cpu_time, cum_cpu_time; + LttvTraceState *ts = (LttvTraceState *)tfcs->parent.parent.t_context; + guint cpu = tfcs->parent.cpu; + LttvProcessState *process = ts->running_process[cpu]; + LttvAttributeValue elapsed_time, cpu_time, cum_cpu_time; - LttTime delta; + LttTime delta; - /* FIXME put there in case of a missing update after a state modification */ - //void *lasttree = tfcs->current_events_tree; - //update_event_tree(tfcs); - //g_assert (lasttree == tfcs->current_events_tree); - lttv_attribute_find(tfcs->current_events_tree, LTTV_STATS_ELAPSED_TIME, - LTTV_TIME, &elapsed_time); + /* FIXME put there in case of a missing update after a state modification */ + //void *lasttree = tfcs->current_events_tree; + //update_event_tree(tfcs); + //g_assert (lasttree == tfcs->current_events_tree); + lttv_attribute_find(tfcs->current_events_tree, LTTV_STATS_ELAPSED_TIME, + LTTV_TIME, &elapsed_time); - if(process->state->t != LTTV_STATE_MODE_UNKNOWN) { - delta = ltt_time_sub(tfcs->parent.parent.timestamp, - process->state->entry); - } else - delta = ltt_time_zero; + if(process->state->t != LTTV_STATE_MODE_UNKNOWN) { + delta = ltt_time_sub(tfcs->parent.parent.timestamp, + process->state->entry); + } else + delta = ltt_time_zero; - *(elapsed_time.v_time) = ltt_time_add(*(elapsed_time.v_time), delta); + *(elapsed_time.v_time) = ltt_time_add(*(elapsed_time.v_time), delta); - lttv_attribute_find(tfcs->current_events_tree, LTTV_STATS_CPU_TIME, - LTTV_TIME, &cpu_time); + lttv_attribute_find(tfcs->current_events_tree, LTTV_STATS_CPU_TIME, + LTTV_TIME, &cpu_time); - /* if it is a running mode, we must count its cpu time */ - if(process->state->s == LTTV_STATE_RUN && - process->state->t != LTTV_STATE_MODE_UNKNOWN) - delta = ltt_time_sub(tfcs->parent.parent.timestamp, - process->state->change); - else - delta = ltt_time_zero; + /* if it is a running mode, we must count its cpu time */ + if(process->state->s == LTTV_STATE_RUN && + process->state->t != LTTV_STATE_MODE_UNKNOWN) + delta = ltt_time_sub(tfcs->parent.parent.timestamp, + process->state->change); + else + delta = ltt_time_zero; - *(cpu_time.v_time) = ltt_time_add(*(cpu_time.v_time), delta); - process->state->cum_cpu_time = ltt_time_add(process->state->cum_cpu_time, - delta); + *(cpu_time.v_time) = ltt_time_add(*(cpu_time.v_time), delta); + process->state->cum_cpu_time = ltt_time_add(process->state->cum_cpu_time, + delta); - lttv_attribute_find(tfcs->current_events_tree, LTTV_STATS_CUMULATIVE_CPU_TIME, - LTTV_TIME, &cum_cpu_time); - *(cum_cpu_time.v_time) = ltt_time_add(*(cum_cpu_time.v_time), - process->state->cum_cpu_time); + lttv_attribute_find(tfcs->current_events_tree, LTTV_STATS_CUMULATIVE_CPU_TIME, + LTTV_TIME, &cum_cpu_time); + *(cum_cpu_time.v_time) = ltt_time_add(*(cum_cpu_time.v_time), + process->state->cum_cpu_time); } static void after_mode_end(LttvTracefileStats *tfcs) { - LttvTraceState *ts = (LttvTraceState *)tfcs->parent.parent.t_context; - guint cpu = tfcs->parent.cpu; - LttvProcessState *process = ts->running_process[cpu]; + LttvTraceState *ts = (LttvTraceState *)tfcs->parent.parent.t_context; + guint cpu = tfcs->parent.cpu; + LttvProcessState *process = ts->running_process[cpu]; - LttTime nested_delta; + LttTime nested_delta; - nested_delta = process->state->cum_cpu_time; - process->state->cum_cpu_time = ltt_time_zero; /* For after traceset hook */ + nested_delta = process->state->cum_cpu_time; + process->state->cum_cpu_time = ltt_time_zero; /* For after traceset hook */ - update_event_tree(tfcs); + update_event_tree(tfcs); - process->state->cum_cpu_time = ltt_time_add(process->state->cum_cpu_time, - nested_delta); + process->state->cum_cpu_time = ltt_time_add(process->state->cum_cpu_time, + nested_delta); } static gboolean before_syscall_entry(void *hook_data, void *call_data) { - mode_change((LttvTracefileStats *)call_data); - return FALSE; + mode_change((LttvTracefileStats *)call_data); + return FALSE; } static gboolean after_syscall_entry(void *hook_data, void *call_data) { - update_event_tree((LttvTracefileStats *)call_data); - return FALSE; + update_event_tree((LttvTracefileStats *)call_data); + return FALSE; } static gboolean before_syscall_exit(void *hook_data, void *call_data) { - mode_end((LttvTracefileStats *)call_data); - return FALSE; + mode_end((LttvTracefileStats *)call_data); + return FALSE; } static gboolean after_syscall_exit(void *hook_data, void *call_data) { - after_mode_end((LttvTracefileStats *)call_data); - return FALSE; + after_mode_end((LttvTracefileStats *)call_data); + return FALSE; } static gboolean before_trap_entry(void *hook_data, void *call_data) { - mode_change((LttvTracefileStats *)call_data); - return FALSE; + mode_change((LttvTracefileStats *)call_data); + return FALSE; } static gboolean after_trap_entry(void *hook_data, void *call_data) { - update_event_tree((LttvTracefileStats *)call_data); - return FALSE; + update_event_tree((LttvTracefileStats *)call_data); + return FALSE; } static gboolean before_trap_exit(void *hook_data, void *call_data) { - mode_end((LttvTracefileStats *)call_data); - return FALSE; + mode_end((LttvTracefileStats *)call_data); + return FALSE; } static gboolean after_trap_exit(void *hook_data, void *call_data) { - after_mode_end((LttvTracefileStats *)call_data); - return FALSE; + after_mode_end((LttvTracefileStats *)call_data); + return FALSE; } static gboolean before_irq_entry(void *hook_data, void *call_data) { - mode_change((LttvTracefileStats *)call_data); - return FALSE; + mode_change((LttvTracefileStats *)call_data); + return FALSE; } static gboolean after_irq_entry(void *hook_data, void *call_data) { - update_event_tree((LttvTracefileStats *)call_data); - return FALSE; + update_event_tree((LttvTracefileStats *)call_data); + return FALSE; } static gboolean before_irq_exit(void *hook_data, void *call_data) { - mode_end((LttvTracefileStats *)call_data); - return FALSE; + mode_end((LttvTracefileStats *)call_data); + return FALSE; } static gboolean after_irq_exit(void *hook_data, void *call_data) { - after_mode_end((LttvTracefileStats *)call_data); - return FALSE; + after_mode_end((LttvTracefileStats *)call_data); + return FALSE; } static gboolean before_soft_irq_entry(void *hook_data, void *call_data) { - mode_change((LttvTracefileStats *)call_data); - return FALSE; + mode_change((LttvTracefileStats *)call_data); + return FALSE; } static gboolean after_soft_irq_entry(void *hook_data, void *call_data) { - update_event_tree((LttvTracefileStats *)call_data); - return FALSE; + update_event_tree((LttvTracefileStats *)call_data); + return FALSE; } static gboolean before_soft_irq_exit(void *hook_data, void *call_data) { - mode_end((LttvTracefileStats *)call_data); - return FALSE; + mode_end((LttvTracefileStats *)call_data); + return FALSE; } static gboolean after_soft_irq_exit(void *hook_data, void *call_data) { - after_mode_end((LttvTracefileStats *)call_data); - return FALSE; + after_mode_end((LttvTracefileStats *)call_data); + return FALSE; } static gboolean before_function_entry(void *hook_data, void *call_data) { - mode_change((LttvTracefileStats *)call_data); - return FALSE; + mode_change((LttvTracefileStats *)call_data); + return FALSE; } static gboolean after_function_entry(void *hook_data, void *call_data) { - update_event_tree((LttvTracefileStats *)call_data); - return FALSE; + update_event_tree((LttvTracefileStats *)call_data); + return FALSE; } static gboolean before_function_exit(void *hook_data, void *call_data) { - mode_end((LttvTracefileStats *)call_data); - return FALSE; + mode_end((LttvTracefileStats *)call_data); + return FALSE; } static gboolean after_function_exit(void *hook_data, void *call_data) { - after_mode_end((LttvTracefileStats *)call_data); - return FALSE; + after_mode_end((LttvTracefileStats *)call_data); + return FALSE; } static gboolean before_schedchange(void *hook_data, void *call_data) { - LttvTracefileStats *tfcs = (LttvTracefileStats *)call_data; + LttvTracefileStats *tfcs = (LttvTracefileStats *)call_data; - LttEvent *e = ltt_tracefile_get_event(tfcs->parent.parent.tf); + LttEvent *e = ltt_tracefile_get_event(tfcs->parent.parent.tf); - LttvTraceHook *th = (LttvTraceHook *)hook_data; + LttvTraceHook *th = (LttvTraceHook *)hook_data; - guint pid_in, pid_out; - - gint64 state_out; + guint pid_in, pid_out; - pid_out = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); - pid_in = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 1)); - state_out = ltt_event_get_long_int(e, lttv_trace_get_hook_field(th, 2)); + gint64 state_out; - /* compute the time for the process to schedule out */ - mode_change(tfcs); + pid_out = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); + pid_in = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 1)); + state_out = ltt_event_get_long_int(e, lttv_trace_get_hook_field(th, 2)); - return FALSE; + /* compute the time for the process to schedule out */ + mode_change(tfcs); + + return FALSE; } static gboolean after_schedchange(void *hook_data, void *call_data) { - LttvTracefileStats *tfcs = (LttvTracefileStats *)call_data; + LttvTracefileStats *tfcs = (LttvTracefileStats *)call_data; + + LttvTraceState *ts = (LttvTraceState*)tfcs->parent.parent.t_context; - LttvTraceState *ts = (LttvTraceState*)tfcs->parent.parent.t_context; + LttEvent *e = ltt_tracefile_get_event(tfcs->parent.parent.tf); - LttEvent *e = ltt_tracefile_get_event(tfcs->parent.parent.tf); + LttvTraceHook *th = (LttvTraceHook *)hook_data; - LttvTraceHook *th = (LttvTraceHook *)hook_data; + guint pid_in, pid_out; - guint pid_in, pid_out; - - gint64 state_out; + gint64 state_out; - LttvProcessState *process; + LttvProcessState *process; - pid_out = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); - pid_in = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 1)); - state_out = ltt_event_get_long_int(e, lttv_trace_get_hook_field(th, 2)); + pid_out = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 0)); + pid_in = ltt_event_get_unsigned(e, lttv_trace_get_hook_field(th, 1)); + state_out = ltt_event_get_long_int(e, lttv_trace_get_hook_field(th, 2)); - /* get the information for the process scheduled in */ - guint cpu = tfcs->parent.cpu; - process = ts->running_process[cpu]; + /* get the information for the process scheduled in */ + guint cpu = tfcs->parent.cpu; + process = ts->running_process[cpu]; - find_event_tree(tfcs, process->pid_time, - cpu, - process->current_function, - process->state->t, process->state->n, &(tfcs->current_events_tree), - &(tfcs->current_event_types_tree)); + find_event_tree(tfcs, process->pid_time, + cpu, + process->current_function, + process->state->t, process->state->n, &(tfcs->current_events_tree), + &(tfcs->current_event_types_tree)); - /* compute the time waiting for the process to schedule in */ - mode_change(tfcs); + /* compute the time waiting for the process to schedule in */ + mode_change(tfcs); - return FALSE; + return FALSE; } static gboolean process_fork(void *hook_data, void *call_data) { - return FALSE; + return FALSE; } static gboolean process_exit(void *hook_data, void *call_data) { - update_event_tree((LttvTracefileStats *)call_data); - return FALSE; + update_event_tree((LttvTracefileStats *)call_data); + return FALSE; } static gboolean before_enum_process_state(void *hook_data, void *call_data) { #if 0 - /* Broken : adds up time in the current process doing the dump */ - LttvTracefileStats *tfcs = (LttvTracefileStats *)call_data; - mode_end(tfcs); - after_mode_end(tfcs); - mode_change(tfcs); + /* Broken : adds up time in the current process doing the dump */ + LttvTracefileStats *tfcs = (LttvTracefileStats *)call_data; + mode_end(tfcs); + after_mode_end(tfcs); + mode_change(tfcs); #endif //0 - return FALSE; + return FALSE; } static gboolean after_enum_process_state(void *hook_data, void *call_data) { - LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; - LttvTraceStats *tcs = (LttvTraceStats*)tfc->t_context; - update_trace_event_tree(tcs); - return FALSE; + LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; + LttvTraceStats *tcs = (LttvTraceStats*)tfc->t_context; + update_trace_event_tree(tcs); + return FALSE; } static gboolean after_statedump_end(void *hook_data, void *call_data) { - LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; - LttvTraceStats *tcs = (LttvTraceStats*)tfc->t_context; - update_trace_event_tree(tcs); - return FALSE; + LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; + LttvTraceStats *tcs = (LttvTraceStats*)tfc->t_context; + update_trace_event_tree(tcs); + return FALSE; } static gboolean process_free(void *hook_data, void *call_data) { - return FALSE; + return FALSE; } static gboolean every_event(void *hook_data, void *call_data) { - LttvTracefileStats *tfcs = (LttvTracefileStats *)call_data; + LttvTracefileStats *tfcs = (LttvTracefileStats *)call_data; - LttEvent *e = ltt_tracefile_get_event(tfcs->parent.parent.tf); + LttEvent *e = ltt_tracefile_get_event(tfcs->parent.parent.tf); - LttvAttributeValue v; + LttvAttributeValue v; - struct marker_info *info; + struct marker_info *info; - /* The current branch corresponds to the tracefile/process/interrupt state. - Statistics are added within it, to count the number of events of this - type occuring in this context. A quark has been pre-allocated for each - event type and is used as name. */ + /* The current branch corresponds to the tracefile/process/interrupt state. + Statistics are added within it, to count the number of events of this + type occuring in this context. A quark has been pre-allocated for each + event type and is used as name. */ - info = marker_get_info_from_id(tfcs->parent.parent.tf->mdata, e->event_id); + info = marker_get_info_from_id(tfcs->parent.parent.tf->mdata, e->event_id); - lttv_attribute_find(tfcs->current_event_types_tree, - info->name, LTTV_UINT, &v); - (*(v.v_uint))++; - return FALSE; + lttv_attribute_find(tfcs->current_event_types_tree, + info->name, LTTV_UINT, &v); + (*(v.v_uint))++; + return FALSE; } struct cleanup_state_struct { - LttvTraceState *ts; - LttTime current_time; + LttvTraceState *ts; + LttTime current_time; }; //static void lttv_stats_cleanup_process_state(LttvTraceState *ts, -// LttvProcessState *process, LttTime current_time) +// LttvProcessState *process, LttTime current_time) static void lttv_stats_cleanup_process_state(gpointer key, gpointer value, - gpointer user_data) -{ - struct cleanup_state_struct *cleanup_closure = - (struct cleanup_state_struct *)user_data; - LttvTraceState *ts = cleanup_closure->ts; - LttvProcessState *process = (LttvProcessState *)value; - LttTime current_time = cleanup_closure->current_time; - LttvTracefileStats **tfs = (LttvTracefileStats **) - &g_array_index(ts->parent.tracefiles, LttvTracefileContext*, - process->cpu); - int cleanup_empty = 0; - LttTime nested_delta = ltt_time_zero; - - /* FIXME : ok, this is a hack. The time is infinite here :( */ - //LttTime save_time = (*tfs)->parent.parent.timestamp; - //LttTime start, end; - //ltt_trace_time_span_get(ts->parent.t, &start, &end); - //(*tfs)->parent.parent.timestamp = end; - - do { - if(ltt_time_compare(process->state->cum_cpu_time, ltt_time_zero) != 0) { - find_event_tree(*tfs, process->pid_time, - process->cpu, - process->current_function, - process->state->t, process->state->n, &((*tfs)->current_events_tree), - &((*tfs)->current_event_types_tree)); - /* Call mode_end only if not at end of trace */ - if(ltt_time_compare(current_time, ltt_time_infinite) != 0) - mode_end(*tfs); - nested_delta = process->state->cum_cpu_time; - } - cleanup_empty = lttv_state_pop_state_cleanup(process, - (LttvTracefileState *)*tfs); - process->state->cum_cpu_time = ltt_time_add(process->state->cum_cpu_time, - nested_delta); - - } while(cleanup_empty != 1); - - //(*tfs)->parent.parent.timestamp = save_time; + gpointer user_data) +{ + struct cleanup_state_struct *cleanup_closure = + (struct cleanup_state_struct *)user_data; + LttvTraceState *ts = cleanup_closure->ts; + LttvProcessState *process = (LttvProcessState *)value; + LttTime current_time = cleanup_closure->current_time; + LttvTracefileStats **tfs = (LttvTracefileStats **) + &g_array_index(ts->parent.tracefiles, LttvTracefileContext*, + process->cpu); + int cleanup_empty = 0; + LttTime nested_delta = ltt_time_zero; + + /* FIXME : ok, this is a hack. The time is infinite here :( */ + //LttTime save_time = (*tfs)->parent.parent.timestamp; + //LttTime start, end; + //ltt_trace_time_span_get(ts->parent.t, &start, &end); + //(*tfs)->parent.parent.timestamp = end; + + do { + if(ltt_time_compare(process->state->cum_cpu_time, ltt_time_zero) != 0) { + find_event_tree(*tfs, process->pid_time, + process->cpu, + process->current_function, + process->state->t, process->state->n, &((*tfs)-> + current_events_tree), + &((*tfs)->current_event_types_tree)); + /* Call mode_end only if not at end of trace */ + if(ltt_time_compare(current_time, ltt_time_infinite) != 0) + mode_end(*tfs); + nested_delta = process->state->cum_cpu_time; + } + cleanup_empty = lttv_state_pop_state_cleanup(process, + (LttvTracefileState *)*tfs); + process->state->cum_cpu_time = ltt_time_add(process->state->cum_cpu_time, + nested_delta); + + } while(cleanup_empty != 1); + + //(*tfs)->parent.parent.timestamp = save_time; } /* For each cpu, for each of their stacked states, * perform sum of needed values. */ static void lttv_stats_cleanup_state(LttvTraceStats *tcs, LttTime current_time) { - LttvTraceState *ts = (LttvTraceState *)tcs; - struct cleanup_state_struct cleanup_closure; + LttvTraceState *ts = (LttvTraceState *)tcs; + struct cleanup_state_struct cleanup_closure; #if 0 - guint nb_cpus, i; + guint nb_cpus, i; - nb_cpus = ltt_trace_get_num_cpu(ts->parent.t); - - for(i=0; irunning_process[i], current_time); - } + nb_cpus = ltt_trace_get_num_cpu(ts->parent.t); + + for(i=0; irunning_process[i], current_time); + } #endif //0 - cleanup_closure.ts = ts; - cleanup_closure.current_time = current_time; - g_hash_table_foreach(ts->processes, lttv_stats_cleanup_process_state, - &cleanup_closure); -} - -void -lttv_stats_sum_trace(LttvTraceStats *self, LttvAttribute *ts_stats, - LttTime current_time) -{ - LttvAttribute *sum_container = self->stats; - - LttvAttributeType type; - - LttvAttributeValue value; - - LttvAttributeName name; - - gboolean is_named; - - unsigned sum; - - int trace_is_summed; - - int i, j, k, l, m, nb_process, nb_cpu, nb_mode_type, nb_submode, - nb_event_type, nf, nb_functions; - - LttvAttribute *main_tree, *processes_tree, *process_tree, *cpus_tree, - *cpu_tree, *mode_tree, *mode_types_tree, *submodes_tree, - *submode_tree, *event_types_tree, *mode_events_tree, - *cpu_functions_tree, - *function_tree, - *function_mode_types_tree, - *trace_cpu_tree; - - - main_tree = sum_container; - - lttv_attribute_find(sum_container, - LTTV_STATS_SUMMED, - LTTV_UINT, &value); - trace_is_summed = *(value.v_uint); - *(value.v_uint) = 1; - - /* First cleanup the state : sum all stalled information (never ending - * states). */ - if(!trace_is_summed) - lttv_stats_cleanup_state(self, current_time); - - processes_tree = lttv_attribute_find_subdir(main_tree, - LTTV_STATS_PROCESSES); - nb_process = lttv_attribute_get_number(processes_tree); - - for(i = 0 ; i < nb_process ; i++) { - type = lttv_attribute_get(processes_tree, i, &name, &value, &is_named); - process_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); - - cpus_tree = lttv_attribute_find_subdir(process_tree, LTTV_STATS_CPU); - nb_cpu = lttv_attribute_get_number(cpus_tree); - - for(j = 0 ; j < nb_cpu ; j++) { - type = lttv_attribute_get(cpus_tree, j, &name, &value, &is_named); - cpu_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); - - trace_cpu_tree = lttv_attribute_find_subdir(main_tree, LTTV_STATS_CPU); - trace_cpu_tree = lttv_attribute_find_subdir_unnamed(trace_cpu_tree, name); - cpu_functions_tree = lttv_attribute_find_subdir(cpu_tree, - LTTV_STATS_FUNCTIONS); - nb_functions = lttv_attribute_get_number(cpu_functions_tree); - - for(nf=0; nf < nb_functions; nf++) { - type = lttv_attribute_get(cpu_functions_tree, nf, &name, &value, - &is_named); - function_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); - function_mode_types_tree = lttv_attribute_find_subdir(function_tree, - LTTV_STATS_MODE_TYPES); - nb_mode_type = lttv_attribute_get_number(function_mode_types_tree); - for(k = 0 ; k < nb_mode_type ; k++) { - type = lttv_attribute_get(function_mode_types_tree, k, &name, &value, - &is_named); - mode_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); - - submodes_tree = lttv_attribute_find_subdir(mode_tree, - LTTV_STATS_SUBMODES); - mode_events_tree = lttv_attribute_find_subdir(mode_tree, - LTTV_STATS_EVENTS); - mode_types_tree = lttv_attribute_find_subdir(mode_tree, - LTTV_STATS_MODE_TYPES); - - nb_submode = lttv_attribute_get_number(submodes_tree); - - for(l = 0 ; l < nb_submode ; l++) { - type = lttv_attribute_get(submodes_tree, l, &name, &value, - &is_named); - submode_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); - - event_types_tree = lttv_attribute_find_subdir(submode_tree, - LTTV_STATS_EVENT_TYPES); - nb_event_type = lttv_attribute_get_number(event_types_tree); - - sum = 0; - for(m = 0 ; m < nb_event_type ; m++) { - type = lttv_attribute_get(event_types_tree, m, &name, &value, - &is_named); - sum += *(value.v_uint); - } - lttv_attribute_find(submode_tree, LTTV_STATS_EVENTS_COUNT, - LTTV_UINT, &value); - *(value.v_uint) = sum; - - type = lttv_attribute_get(submodes_tree, l, &name, &value, - &is_named); - submode_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); - if(!trace_is_summed) { - lttv_attribute_recursive_add(mode_events_tree, event_types_tree); - lttv_attribute_recursive_add(mode_types_tree, submode_tree); - } - } - if(!trace_is_summed) { - lttv_attribute_recursive_add(function_tree, mode_types_tree); - } - } - if(!trace_is_summed) { - lttv_attribute_recursive_add(cpu_tree, function_tree); - lttv_attribute_recursive_add(process_tree, function_tree); - lttv_attribute_recursive_add(trace_cpu_tree, function_tree); - lttv_attribute_recursive_add(main_tree, function_tree); - } - lttv_attribute_recursive_add(ts_stats, function_tree); - } - } - } + cleanup_closure.ts = ts; + cleanup_closure.current_time = current_time; + g_hash_table_foreach(ts->processes, lttv_stats_cleanup_process_state, + &cleanup_closure); +} + +void lttv_stats_sum_trace(LttvTraceStats *self, LttvAttribute *ts_stats, + LttTime current_time) +{ + LttvAttribute *sum_container = self->stats; + + LttvAttributeType type; + + LttvAttributeValue value; + + LttvAttributeName name; + + gboolean is_named; + + unsigned sum; + + int trace_is_summed; + + int i, j, k, l, m, nb_process, nb_cpu, nb_mode_type, nb_submode, + nb_event_type, nf, nb_functions; + + LttvAttribute *main_tree, *processes_tree, *process_tree, *cpus_tree, + *cpu_tree, *mode_tree, *mode_types_tree, *submodes_tree, + *submode_tree, *event_types_tree, *mode_events_tree, + *cpu_functions_tree, + *function_tree, + *function_mode_types_tree, + *trace_cpu_tree; + + + main_tree = sum_container; + + lttv_attribute_find(sum_container, + LTTV_STATS_SUMMED, + LTTV_UINT, &value); + trace_is_summed = *(value.v_uint); + *(value.v_uint) = 1; + + /* First cleanup the state : sum all stalled information (never ending + * states). */ + if(!trace_is_summed) + lttv_stats_cleanup_state(self, current_time); + + processes_tree = lttv_attribute_find_subdir(main_tree, + LTTV_STATS_PROCESSES); + nb_process = lttv_attribute_get_number(processes_tree); + + for(i = 0 ; i < nb_process ; i++) { + type = lttv_attribute_get(processes_tree, i, &name, &value, &is_named); + process_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); + + cpus_tree = lttv_attribute_find_subdir(process_tree, LTTV_STATS_CPU); + nb_cpu = lttv_attribute_get_number(cpus_tree); + + for(j = 0 ; j < nb_cpu ; j++) { + type = lttv_attribute_get(cpus_tree, j, &name, &value, &is_named); + cpu_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); + + trace_cpu_tree = lttv_attribute_find_subdir(main_tree, + LTTV_STATS_CPU); + trace_cpu_tree = lttv_attribute_find_subdir_unnamed(trace_cpu_tree, name); + cpu_functions_tree = lttv_attribute_find_subdir(cpu_tree, + LTTV_STATS_FUNCTIONS); + nb_functions = lttv_attribute_get_number(cpu_functions_tree); + + for(nf=0; nf < nb_functions; nf++) { + type = lttv_attribute_get(cpu_functions_tree, nf, &name, &value, + &is_named); + function_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); + function_mode_types_tree = lttv_attribute_find_subdir(function_tree, + LTTV_STATS_MODE_TYPES); + nb_mode_type = lttv_attribute_get_number(function_mode_types_tree); + for(k = 0 ; k < nb_mode_type ; k++) { + type = lttv_attribute_get(function_mode_types_tree, k, &name, + &value, &is_named); + mode_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); + + submodes_tree = lttv_attribute_find_subdir(mode_tree, + LTTV_STATS_SUBMODES); + mode_events_tree = lttv_attribute_find_subdir(mode_tree, + LTTV_STATS_EVENTS); + mode_types_tree = lttv_attribute_find_subdir(mode_tree, + LTTV_STATS_MODE_TYPES); + + nb_submode = lttv_attribute_get_number(submodes_tree); + + for(l = 0 ; l < nb_submode ; l++) { + type = lttv_attribute_get(submodes_tree, l, &name, &value, + &is_named); + submode_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); + + event_types_tree = lttv_attribute_find_subdir(submode_tree, + LTTV_STATS_EVENT_TYPES); + nb_event_type = lttv_attribute_get_number(event_types_tree); + + sum = 0; + for(m = 0 ; m < nb_event_type ; m++) { + type = lttv_attribute_get(event_types_tree, m, &name, + &value, &is_named); + sum += *(value.v_uint); + } + lttv_attribute_find(submode_tree, LTTV_STATS_EVENTS_COUNT, + LTTV_UINT, &value); + *(value.v_uint) = sum; + + type = lttv_attribute_get(submodes_tree, l, &name, &value, + &is_named); + submode_tree = LTTV_ATTRIBUTE(*(value.v_gobject)); + if(!trace_is_summed) { + lttv_attribute_recursive_add(mode_events_tree, event_types_tree); + lttv_attribute_recursive_add(mode_types_tree, submode_tree); + } + } + if(!trace_is_summed) { + lttv_attribute_recursive_add(function_tree, mode_types_tree); + } + } + if(!trace_is_summed) { + lttv_attribute_recursive_add(cpu_tree, function_tree); + lttv_attribute_recursive_add(process_tree, function_tree); + lttv_attribute_recursive_add(trace_cpu_tree, function_tree); + lttv_attribute_recursive_add(main_tree, function_tree); + } + lttv_attribute_recursive_add(ts_stats, function_tree); + } + } + } } gboolean lttv_stats_sum_traceset_hook(void *hook_data, void *call_data) { - struct sum_traceset_closure *closure = - (struct sum_traceset_closure *)call_data; - lttv_stats_sum_traceset(closure->tss, closure->current_time); - return 0; + struct sum_traceset_closure *closure = + (struct sum_traceset_closure *)call_data; + lttv_stats_sum_traceset(closure->tss, closure->current_time); + return 0; } -void -lttv_stats_sum_traceset(LttvTracesetStats *self, LttTime current_time) +void lttv_stats_sum_traceset(LttvTracesetStats *self, LttTime current_time) { - LttvTraceset *traceset = self->parent.parent.ts; - LttvAttribute *sum_container = self->stats; + LttvTraceset *traceset = self->parent.parent.ts; + LttvAttribute *sum_container = self->stats; - LttvTraceStats *tcs; + LttvTraceStats *tcs; - int i, nb_trace; + int i, nb_trace; - LttvAttributeValue value; + LttvAttributeValue value; - lttv_attribute_find(sum_container, LTTV_STATS_SUMMED, - LTTV_UINT, &value); - if(*(value.v_uint) != 0) return; - *(value.v_uint) = 1; + lttv_attribute_find(sum_container, LTTV_STATS_SUMMED, + LTTV_UINT, &value); + if(*(value.v_uint) != 0) return; + *(value.v_uint) = 1; - nb_trace = lttv_traceset_number(traceset); + nb_trace = lttv_traceset_number(traceset); - for(i = 0 ; i < nb_trace ; i++) { - tcs = (LttvTraceStats *)(self->parent.parent.traces[i]); - lttv_stats_sum_trace(tcs, self->stats, current_time); - // lttv_attribute_recursive_add(sum_container, tcs->stats); - } + for(i = 0 ; i < nb_trace ; i++) { + tcs = (LttvTraceStats *)(self->parent.parent.traces[i]); + lttv_stats_sum_trace(tcs, self->stats, current_time); + // lttv_attribute_recursive_add(sum_container, tcs->stats); + } } // Hook wrapper. call_data is a traceset context. gboolean lttv_stats_hook_add_event_hooks(void *hook_data, void *call_data) { - LttvTracesetStats *tss = (LttvTracesetStats*)call_data; + LttvTracesetStats *tss = (LttvTracesetStats*)call_data; - lttv_stats_add_event_hooks(tss); + lttv_stats_add_event_hooks(tss); - return 0; + return 0; } void lttv_stats_add_event_hooks(LttvTracesetStats *self) { - LttvTraceset *traceset = self->parent.parent.ts; - - guint i, j, k, nb_trace, nb_tracefile; - - LttvTraceStats *ts; - - LttvTracefileStats *tfs; - - GArray *hooks, *before_hooks, *after_hooks; - - LttvTraceHook *th; - - LttvAttributeValue val; - - nb_trace = lttv_traceset_number(traceset); - for(i = 0 ; i < nb_trace ; i++) { - ts = (LttvTraceStats *)self->parent.parent.traces[i]; - - /* Find the eventtype id for the following events and register the - associated by id hooks. */ - - hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 12); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SYSCALL_ENTRY, - FIELD_ARRAY(LTT_FIELD_SYSCALL_ID), - before_syscall_entry, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SYSCALL_EXIT, - NULL, - before_syscall_exit, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_TRAP_ENTRY, - FIELD_ARRAY(LTT_FIELD_TRAP_ID), - before_trap_entry, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_TRAP_EXIT, - NULL, - before_trap_exit, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_IRQ_ENTRY, - FIELD_ARRAY(LTT_FIELD_IRQ_ID), - before_irq_entry, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_IRQ_EXIT, - NULL, - before_irq_exit, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SOFT_IRQ_ENTRY, - FIELD_ARRAY(LTT_FIELD_SOFT_IRQ_ID), - before_soft_irq_entry, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SOFT_IRQ_EXIT, - NULL, - before_soft_irq_exit, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SCHED_SCHEDULE, - FIELD_ARRAY(LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE), - before_schedchange, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_USERSPACE, - LTT_EVENT_FUNCTION_ENTRY, - FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), - before_function_entry, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_USERSPACE, - LTT_EVENT_FUNCTION_EXIT, - FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), - before_function_exit, NULL, - &hooks); - - /* statedump-related hooks */ - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_TASK_STATE, - LTT_EVENT_PROCESS_STATE, - FIELD_ARRAY(LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME), - before_enum_process_state, NULL, - &hooks); - - before_hooks = hooks; - - hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 16); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SYSCALL_ENTRY, - FIELD_ARRAY(LTT_FIELD_SYSCALL_ID), - after_syscall_entry, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SYSCALL_EXIT, - NULL, - after_syscall_exit, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_TRAP_ENTRY, - FIELD_ARRAY(LTT_FIELD_TRAP_ID), - after_trap_entry, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_TRAP_EXIT, - NULL, - after_trap_exit, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_IRQ_ENTRY, - FIELD_ARRAY(LTT_FIELD_IRQ_ID), - after_irq_entry, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_IRQ_EXIT, - NULL, - after_irq_exit, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SOFT_IRQ_ENTRY, - FIELD_ARRAY(LTT_FIELD_SOFT_IRQ_ID), - after_soft_irq_entry, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SOFT_IRQ_EXIT, - NULL, - after_soft_irq_exit, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_SCHED_SCHEDULE, - FIELD_ARRAY(LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE), - after_schedchange, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_PROCESS_FORK, - FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID), - process_fork, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_PROCESS_EXIT, - FIELD_ARRAY(LTT_FIELD_PID), - process_exit, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_KERNEL, - LTT_EVENT_PROCESS_FREE, - FIELD_ARRAY(LTT_FIELD_PID), - process_free, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_USERSPACE, - LTT_EVENT_FUNCTION_ENTRY, - FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), - after_function_entry, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_USERSPACE, - LTT_EVENT_FUNCTION_EXIT, - FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), - after_function_exit, NULL, - &hooks); - - /* statedump-related hooks */ - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_TASK_STATE, - LTT_EVENT_PROCESS_STATE, - FIELD_ARRAY(LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME), - after_enum_process_state, NULL, - &hooks); - - lttv_trace_find_hook(ts->parent.parent.t, - LTT_CHANNEL_GLOBAL_STATE, - LTT_EVENT_STATEDUMP_END, - NULL, - after_statedump_end, NULL, - &hooks); - - after_hooks = hooks; - - /* Add these hooks to each event_by_id hooks list */ - - nb_tracefile = ts->parent.parent.tracefiles->len; - - for(j = 0 ; j < nb_tracefile ; j++) { - tfs = LTTV_TRACEFILE_STATS(g_array_index(ts->parent.parent.tracefiles, - LttvTracefileContext*, j)); - lttv_hooks_add(tfs->parent.parent.event, every_event, NULL, - LTTV_PRIO_DEFAULT); - - for(k = 0 ; k < before_hooks->len ; k++) { - th = &g_array_index(before_hooks, LttvTraceHook, k); - if (th->mdata == tfs->parent.parent.tf->mdata) - lttv_hooks_add( - lttv_hooks_by_id_find(tfs->parent.parent.event_by_id, th->id), - th->h, - th, - LTTV_PRIO_STATS_BEFORE_STATE); - } - for(k = 0 ; k < after_hooks->len ; k++) { - th = &g_array_index(after_hooks, LttvTraceHook, k); - if (th->mdata == tfs->parent.parent.tf->mdata) - lttv_hooks_add( - lttv_hooks_by_id_find(tfs->parent.parent.event_by_id, th->id), - th->h, - th, - LTTV_PRIO_STATS_AFTER_STATE); - } - } - lttv_attribute_find(self->parent.parent.a, LTTV_STATS_BEFORE_HOOKS, - LTTV_POINTER, &val); - *(val.v_pointer) = before_hooks; - lttv_attribute_find(self->parent.parent.a, LTTV_STATS_AFTER_HOOKS, - LTTV_POINTER, &val); - *(val.v_pointer) = after_hooks; - } + LttvTraceset *traceset = self->parent.parent.ts; + + guint i, j, k, nb_trace, nb_tracefile; + + LttvTraceStats *ts; + + LttvTracefileStats *tfs; + + GArray *hooks, *before_hooks, *after_hooks; + + LttvTraceHook *th; + + LttvAttributeValue val; + + nb_trace = lttv_traceset_number(traceset); + for(i = 0 ; i < nb_trace ; i++) { + ts = (LttvTraceStats *)self->parent.parent.traces[i]; + + /* Find the eventtype id for the following events and register the + associated by id hooks. */ + + hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 12); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SYSCALL_ENTRY, + FIELD_ARRAY(LTT_FIELD_SYSCALL_ID), + before_syscall_entry, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SYSCALL_EXIT, + NULL, + before_syscall_exit, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_TRAP_ENTRY, + FIELD_ARRAY(LTT_FIELD_TRAP_ID), + before_trap_entry, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_TRAP_EXIT, + NULL, + before_trap_exit, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_IRQ_ENTRY, + FIELD_ARRAY(LTT_FIELD_IRQ_ID), + before_irq_entry, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_IRQ_EXIT, + NULL, + before_irq_exit, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SOFT_IRQ_ENTRY, + FIELD_ARRAY(LTT_FIELD_SOFT_IRQ_ID), + before_soft_irq_entry, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SOFT_IRQ_EXIT, + NULL, + before_soft_irq_exit, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SCHED_SCHEDULE, + FIELD_ARRAY(LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE), + before_schedchange, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_USERSPACE, + LTT_EVENT_FUNCTION_ENTRY, + FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), + before_function_entry, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_USERSPACE, + LTT_EVENT_FUNCTION_EXIT, + FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), + before_function_exit, NULL, + &hooks); + + /* statedump-related hooks */ + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_TASK_STATE, + LTT_EVENT_PROCESS_STATE, + FIELD_ARRAY(LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME), + before_enum_process_state, NULL, + &hooks); + + before_hooks = hooks; + + hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 16); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SYSCALL_ENTRY, + FIELD_ARRAY(LTT_FIELD_SYSCALL_ID), + after_syscall_entry, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SYSCALL_EXIT, + NULL, + after_syscall_exit, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_TRAP_ENTRY, + FIELD_ARRAY(LTT_FIELD_TRAP_ID), + after_trap_entry, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_TRAP_EXIT, + NULL, + after_trap_exit, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_IRQ_ENTRY, + FIELD_ARRAY(LTT_FIELD_IRQ_ID), + after_irq_entry, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_IRQ_EXIT, + NULL, + after_irq_exit, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SOFT_IRQ_ENTRY, + FIELD_ARRAY(LTT_FIELD_SOFT_IRQ_ID), + after_soft_irq_entry, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SOFT_IRQ_EXIT, + NULL, + after_soft_irq_exit, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_SCHED_SCHEDULE, + FIELD_ARRAY(LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE), + after_schedchange, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_PROCESS_FORK, + FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID), + process_fork, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_PROCESS_EXIT, + FIELD_ARRAY(LTT_FIELD_PID), + process_exit, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_KERNEL, + LTT_EVENT_PROCESS_FREE, + FIELD_ARRAY(LTT_FIELD_PID), + process_free, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_USERSPACE, + LTT_EVENT_FUNCTION_ENTRY, + FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), + after_function_entry, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_USERSPACE, + LTT_EVENT_FUNCTION_EXIT, + FIELD_ARRAY(LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE), + after_function_exit, NULL, + &hooks); + + /* statedump-related hooks */ + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_TASK_STATE, + LTT_EVENT_PROCESS_STATE, + FIELD_ARRAY(LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME), + after_enum_process_state, NULL, + &hooks); + + lttv_trace_find_hook(ts->parent.parent.t, + LTT_CHANNEL_GLOBAL_STATE, + LTT_EVENT_STATEDUMP_END, + NULL, + after_statedump_end, NULL, + &hooks); + + after_hooks = hooks; + + /* Add these hooks to each event_by_id hooks list */ + + nb_tracefile = ts->parent.parent.tracefiles->len; + + for(j = 0 ; j < nb_tracefile ; j++) { + tfs = LTTV_TRACEFILE_STATS(g_array_index(ts->parent.parent.tracefiles, + LttvTracefileContext*, j)); + lttv_hooks_add(tfs->parent.parent.event, every_event, NULL, + LTTV_PRIO_DEFAULT); + + for(k = 0 ; k < before_hooks->len ; k++) { + th = &g_array_index(before_hooks, LttvTraceHook, k); + if (th->mdata == tfs->parent.parent.tf->mdata) + lttv_hooks_add( + lttv_hooks_by_id_find(tfs->parent.parent.event_by_id, th->id), + th->h, + th, + LTTV_PRIO_STATS_BEFORE_STATE); + } + for(k = 0 ; k < after_hooks->len ; k++) { + th = &g_array_index(after_hooks, LttvTraceHook, k); + if (th->mdata == tfs->parent.parent.tf->mdata) + lttv_hooks_add( + lttv_hooks_by_id_find(tfs->parent.parent.event_by_id, th->id), + th->h, + th, + LTTV_PRIO_STATS_AFTER_STATE); + } + } + lttv_attribute_find(self->parent.parent.a, LTTV_STATS_BEFORE_HOOKS, + LTTV_POINTER, &val); + *(val.v_pointer) = before_hooks; + lttv_attribute_find(self->parent.parent.a, LTTV_STATS_AFTER_HOOKS, + LTTV_POINTER, &val); + *(val.v_pointer) = after_hooks; + } } // Hook wrapper. call_data is a traceset context. gboolean lttv_stats_hook_remove_event_hooks(void *hook_data, void *call_data) { - LttvTracesetStats *tss = (LttvTracesetStats*)call_data; + LttvTracesetStats *tss = (LttvTracesetStats*)call_data; - lttv_stats_remove_event_hooks(tss); + lttv_stats_remove_event_hooks(tss); - return 0; + return 0; } void lttv_stats_remove_event_hooks(LttvTracesetStats *self) { - LttvTraceset *traceset = self->parent.parent.ts; + LttvTraceset *traceset = self->parent.parent.ts; + + guint i, j, k, nb_trace, nb_tracefile; - guint i, j, k, nb_trace, nb_tracefile; + LttvTraceStats *ts; - LttvTraceStats *ts; + LttvTracefileStats *tfs; - LttvTracefileStats *tfs; + GArray *before_hooks, *after_hooks; - GArray *before_hooks, *after_hooks; + LttvTraceHook *th; - LttvTraceHook *th; + LttvAttributeValue val; - LttvAttributeValue val; + nb_trace = lttv_traceset_number(traceset); + for(i = 0 ; i < nb_trace ; i++) { + ts = (LttvTraceStats*)self->parent.parent.traces[i]; + lttv_attribute_find(self->parent.parent.a, LTTV_STATS_BEFORE_HOOKS, + LTTV_POINTER, &val); + before_hooks = *(val.v_pointer); + lttv_attribute_find(self->parent.parent.a, LTTV_STATS_AFTER_HOOKS, + LTTV_POINTER, &val); + after_hooks = *(val.v_pointer); - nb_trace = lttv_traceset_number(traceset); - for(i = 0 ; i < nb_trace ; i++) { - ts = (LttvTraceStats*)self->parent.parent.traces[i]; - lttv_attribute_find(self->parent.parent.a, LTTV_STATS_BEFORE_HOOKS, - LTTV_POINTER, &val); - before_hooks = *(val.v_pointer); - lttv_attribute_find(self->parent.parent.a, LTTV_STATS_AFTER_HOOKS, - LTTV_POINTER, &val); - after_hooks = *(val.v_pointer); + /* Remove these hooks from each event_by_id hooks list */ - /* Remove these hooks from each event_by_id hooks list */ + nb_tracefile = ts->parent.parent.tracefiles->len; - nb_tracefile = ts->parent.parent.tracefiles->len; + for(j = 0 ; j < nb_tracefile ; j++) { + tfs = LTTV_TRACEFILE_STATS(g_array_index(ts->parent.parent.tracefiles, + LttvTracefileContext*, j)); + lttv_hooks_remove_data(tfs->parent.parent.event, every_event, + NULL); - for(j = 0 ; j < nb_tracefile ; j++) { - tfs = LTTV_TRACEFILE_STATS(g_array_index(ts->parent.parent.tracefiles, - LttvTracefileContext*, j)); - lttv_hooks_remove_data(tfs->parent.parent.event, every_event, - NULL); + for(k = 0 ; k < before_hooks->len ; k++) { + th = &g_array_index(before_hooks, LttvTraceHook, k); + if (th->mdata == tfs->parent.parent.tf->mdata) + lttv_hooks_remove_data( + lttv_hooks_by_id_find(tfs->parent.parent.event_by_id, th->id), + th->h, + th); + } + for(k = 0 ; k < after_hooks->len ; k++) { + th = &g_array_index(after_hooks, LttvTraceHook, k); + if (th->mdata == tfs->parent.parent.tf->mdata) + lttv_hooks_remove_data( + lttv_hooks_by_id_find(tfs->parent.parent.event_by_id, th->id), + th->h, + th); - for(k = 0 ; k < before_hooks->len ; k++) { - th = &g_array_index(before_hooks, LttvTraceHook, k); - if (th->mdata == tfs->parent.parent.tf->mdata) - lttv_hooks_remove_data( - lttv_hooks_by_id_find(tfs->parent.parent.event_by_id, th->id), - th->h, - th); - } - for(k = 0 ; k < after_hooks->len ; k++) { - th = &g_array_index(after_hooks, LttvTraceHook, k); - if (th->mdata == tfs->parent.parent.tf->mdata) - lttv_hooks_remove_data( - lttv_hooks_by_id_find(tfs->parent.parent.event_by_id, th->id), - th->h, - th); - - } - } - g_debug("lttv_stats_remove_event_hooks()"); - lttv_trace_hook_remove_all(&before_hooks); - lttv_trace_hook_remove_all(&after_hooks); - g_array_free(before_hooks, TRUE); - g_array_free(after_hooks, TRUE); - } + } + } + g_debug("lttv_stats_remove_event_hooks()"); + lttv_trace_hook_remove_all(&before_hooks); + lttv_trace_hook_remove_all(&after_hooks); + g_array_free(before_hooks, TRUE); + g_array_free(after_hooks, TRUE); + } } static void module_init() { - LTTV_STATS_PROCESS_UNKNOWN = g_quark_from_string("unknown process"); - LTTV_STATS_PROCESSES = g_quark_from_string("processes"); - LTTV_STATS_CPU = g_quark_from_string("cpu"); - LTTV_STATS_MODE_TYPES = g_quark_from_string("mode_types"); - LTTV_STATS_MODES = g_quark_from_string("modes"); - LTTV_STATS_SUBMODES = g_quark_from_string("submodes"); - LTTV_STATS_FUNCTIONS = g_quark_from_string("functions"); - LTTV_STATS_EVENT_TYPES = g_quark_from_string("event_types"); - LTTV_STATS_CPU_TIME = g_quark_from_string("cpu time"); - LTTV_STATS_CUMULATIVE_CPU_TIME = g_quark_from_string("cumulative cpu time (includes nested routines and modes)"); - LTTV_STATS_ELAPSED_TIME = g_quark_from_string("elapsed time (includes per process waiting time)"); - LTTV_STATS_EVENTS = g_quark_from_string("events"); - LTTV_STATS_EVENTS_COUNT = g_quark_from_string("events count"); - LTTV_STATS_BEFORE_HOOKS = g_quark_from_string("saved stats before hooks"); - LTTV_STATS_AFTER_HOOKS = g_quark_from_string("saved stats after hooks"); - LTTV_STATS_USE_COUNT = g_quark_from_string("stats_use_count"); - LTTV_STATS = g_quark_from_string("statistics"); - LTTV_STATS_TRACEFILES = g_quark_from_string("tracefiles statistics"); - LTTV_STATS_SUMMED = g_quark_from_string("statistics summed"); + LTTV_STATS_PROCESS_UNKNOWN = g_quark_from_string("unknown process"); + LTTV_STATS_PROCESSES = g_quark_from_string("processes"); + LTTV_STATS_CPU = g_quark_from_string("cpu"); + LTTV_STATS_MODE_TYPES = g_quark_from_string("mode_types"); + LTTV_STATS_MODES = g_quark_from_string("modes"); + LTTV_STATS_SUBMODES = g_quark_from_string("submodes"); + LTTV_STATS_FUNCTIONS = g_quark_from_string("functions"); + LTTV_STATS_EVENT_TYPES = g_quark_from_string("event_types"); + LTTV_STATS_CPU_TIME = g_quark_from_string("cpu time"); + LTTV_STATS_CUMULATIVE_CPU_TIME = g_quark_from_string("cumulative cpu time (includes nested routines and modes)"); + LTTV_STATS_ELAPSED_TIME = g_quark_from_string("elapsed time (includes per process waiting time)"); + LTTV_STATS_EVENTS = g_quark_from_string("events"); + LTTV_STATS_EVENTS_COUNT = g_quark_from_string("events count"); + LTTV_STATS_BEFORE_HOOKS = g_quark_from_string("saved stats before hooks"); + LTTV_STATS_AFTER_HOOKS = g_quark_from_string("saved stats after hooks"); + LTTV_STATS_USE_COUNT = g_quark_from_string("stats_use_count"); + LTTV_STATS = g_quark_from_string("statistics"); + LTTV_STATS_TRACEFILES = g_quark_from_string("tracefiles statistics"); + LTTV_STATS_SUMMED = g_quark_from_string("statistics summed"); } static void module_destroy() @@ -1410,8 +1391,8 @@ static void module_destroy() LTTV_MODULE("stats", "Compute processes statistics", \ - "Accumulate statistics for event types, processes and CPUs", \ - module_init, module_destroy, "state"); + "Accumulate statistics for event types, processes and CPUs", \ + module_init, module_destroy, "state"); /* Change the places where stats are called (create/read/write stats) diff --git a/lttv/lttv/stats.h b/lttv/lttv/stats.h index f2eed92d..837282c1 100644 --- a/lttv/lttv/stats.h +++ b/lttv/lttv/stats.h @@ -143,20 +143,20 @@ extern GQuark - LTTV_STATS_PROCESS_UNKNOWN, - LTTV_STATS_PROCESSES, - LTTV_STATS_CPU, - LTTV_STATS_MODE_TYPES, - LTTV_STATS_SUBMODES, - LTTV_STATS_FUNCTIONS, - LTTV_STATS_EVENT_TYPES, - LTTV_STATS_CPU_TIME, - LTTV_STATS_CUMULATIVE_CPU_TIME, - LTTV_STATS_ELAPSED_TIME, - LTTV_STATS_EVENTS, - LTTV_STATS_EVENTS_COUNT, - LTTV_STATS_BEFORE_HOOKS, - LTTV_STATS_AFTER_HOOKS; + LTTV_STATS_PROCESS_UNKNOWN, + LTTV_STATS_PROCESSES, + LTTV_STATS_CPU, + LTTV_STATS_MODE_TYPES, + LTTV_STATS_SUBMODES, + LTTV_STATS_FUNCTIONS, + LTTV_STATS_EVENT_TYPES, + LTTV_STATS_CPU_TIME, + LTTV_STATS_CUMULATIVE_CPU_TIME, + LTTV_STATS_ELAPSED_TIME, + LTTV_STATS_EVENTS, + LTTV_STATS_EVENTS_COUNT, + LTTV_STATS_BEFORE_HOOKS, + LTTV_STATS_AFTER_HOOKS; typedef struct _LttvTracesetStats LttvTracesetStats; @@ -182,7 +182,7 @@ gboolean lttv_stats_sum_traceset_hook(void *hook_data, void *call_data); void lttv_stats_sum_traceset(LttvTracesetStats *self, LttTime current_time); void lttv_stats_sum_trace(LttvTraceStats *self, LttvAttribute *ts_stats, - LttTime current_time); + LttTime current_time); /* Reset all statistics containers */ void lttv_stats_reset(LttvTracesetStats *self); @@ -199,13 +199,13 @@ void lttv_stats_reset(LttvTracesetStats *self); #define LTTV_TRACESET_STATS_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACESET_STATS_TYPE, LttvTracesetStatsClass)) struct _LttvTracesetStats { - LttvTracesetState parent; + LttvTracesetState parent; - LttvAttribute *stats; + LttvAttribute *stats; }; struct _LttvTracesetStatsClass { - LttvTracesetStateClass parent; + LttvTracesetStateClass parent; }; GType lttv_traceset_stats_get_type (void); @@ -219,13 +219,13 @@ GType lttv_traceset_stats_get_type (void); #define LTTV_TRACE_STATS_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_STATS_TYPE, LttvTraceStatsClass)) struct _LttvTraceStats { - LttvTraceState parent; + LttvTraceState parent; - LttvAttribute *stats; + LttvAttribute *stats; }; struct _LttvTraceStatsClass { - LttvTraceStateClass parent; + LttvTraceStateClass parent; }; GType lttv_trace_stats_get_type (void); @@ -239,22 +239,22 @@ GType lttv_trace_stats_get_type (void); #define LTTV_TRACEFILE_STATS_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_STATS_TYPE, LttvTracefileStatsClass)) struct _LttvTracefileStats { - LttvTracefileState parent; + LttvTracefileState parent; - LttvAttribute *stats; - LttvAttribute *current_events_tree; - LttvAttribute *current_event_types_tree; + LttvAttribute *stats; + LttvAttribute *current_events_tree; + LttvAttribute *current_event_types_tree; }; struct _LttvTracefileStatsClass { - LttvTracefileStateClass parent; + LttvTracefileStateClass parent; }; GType lttv_tracefile_stats_get_type (void); struct sum_traceset_closure { - LttvTracesetStats *tss; - LttTime current_time; + LttvTracesetStats *tss; + LttTime current_time; }; diff --git a/lttv/lttv/tracecontext.c b/lttv/lttv/tracecontext.c index a013b2e6..136b2eec 100644 --- a/lttv/lttv/tracecontext.c +++ b/lttv/lttv/tracecontext.c @@ -30,56 +30,56 @@ gint compare_tracefile(gconstpointer a, gconstpointer b) { - gint comparison = 0; - - const LttvTracefileContext *trace_a = (const LttvTracefileContext *)a; - const LttvTracefileContext *trace_b = (const LttvTracefileContext *)b; - - if(likely(trace_a != trace_b)) { - comparison = ltt_time_compare(trace_a->timestamp, trace_b->timestamp); - if(unlikely(comparison == 0)) { - if(trace_a->index < trace_b->index) comparison = -1; - else if(trace_a->index > trace_b->index) comparison = 1; - else if(trace_a->t_context->index < trace_b->t_context->index) - comparison = -1; - else if(trace_a->t_context->index > trace_b->t_context->index) - comparison = 1; - } - } - return comparison; + gint comparison = 0; + + const LttvTracefileContext *trace_a = (const LttvTracefileContext *)a; + const LttvTracefileContext *trace_b = (const LttvTracefileContext *)b; + + if(likely(trace_a != trace_b)) { + comparison = ltt_time_compare(trace_a->timestamp, trace_b->timestamp); + if(unlikely(comparison == 0)) { + if(trace_a->index < trace_b->index) comparison = -1; + else if(trace_a->index > trace_b->index) comparison = 1; + else if(trace_a->t_context->index < trace_b->t_context->index) + comparison = -1; + else if(trace_a->t_context->index > trace_b->t_context->index) + comparison = 1; + } + } + return comparison; } typedef struct _LttvTracefileContextPosition { - LttEventPosition *event; - LttvTracefileContext *tfc; - gboolean used; /* Tells if the tfc is at end of traceset position */ + LttEventPosition *event; + LttvTracefileContext *tfc; + gboolean used; /* Tells if the tfc is at end of traceset position */ } LttvTracefileContextPosition; struct _LttvTracesetContextPosition { - GArray *tfcp; /* Array of LttvTracefileContextPosition */ - LttTime timestamp; /* Current time at the saved position */ - /* If ltt_time_infinite : no position is - * set, else, a position is set (may be end - * of trace, with ep->len == 0) */ + GArray *tfcp; /* Array of LttvTracefileContextPosition */ + LttTime timestamp; /* Current time at the saved position */ + /* If ltt_time_infinite : no position is + * set, else, a position is set (may be end + * of trace, with ep->len == 0) */ }; void lttv_context_init(LttvTracesetContext *self, LttvTraceset *ts) { - LTTV_TRACESET_CONTEXT_GET_CLASS(self)->init(self, ts); + LTTV_TRACESET_CONTEXT_GET_CLASS(self)->init(self, ts); } void lttv_context_fini(LttvTracesetContext *self) { - LTTV_TRACESET_CONTEXT_GET_CLASS(self)->fini(self); + LTTV_TRACESET_CONTEXT_GET_CLASS(self)->fini(self); } LttvTracesetContext * lttv_context_new_traceset_context(LttvTracesetContext *self) { - return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_traceset_context(self); + return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_traceset_context(self); } @@ -88,14 +88,14 @@ lttv_context_new_traceset_context(LttvTracesetContext *self) LttvTraceContext * lttv_context_new_trace_context(LttvTracesetContext *self) { - return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_trace_context(self); + return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_trace_context(self); } LttvTracefileContext * lttv_context_new_tracefile_context(LttvTracesetContext *self) { - return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_tracefile_context(self); + return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_tracefile_context(self); } /**************************************************************************** @@ -112,526 +112,515 @@ lttv_context_new_tracefile_context(LttvTracesetContext *self) void lttv_traceset_context_compute_time_span(LttvTracesetContext *self, TimeInterval *time_span) { - LttvTraceset * traceset = self->ts; - int numTraces = lttv_traceset_number(traceset); - int i; - LttTime s, e; - LttvTraceContext *tc; - LttTrace * trace; - - time_span->start_time.tv_sec = 0; - time_span->start_time.tv_nsec = 0; - time_span->end_time.tv_sec = 0; - time_span->end_time.tv_nsec = 0; - - for(i=0; itraces[i]; - trace = tc->t; - - ltt_trace_time_span_get(trace, &s, &e); - tc->time_span.start_time = s; - tc->time_span.end_time = e; - - if(i==0){ - time_span->start_time = s; - time_span->end_time = e; - }else{ - if(s.tv_sec < time_span->start_time.tv_sec - || (s.tv_sec == time_span->start_time.tv_sec - && s.tv_nsec < time_span->start_time.tv_nsec)) - time_span->start_time = s; - if(e.tv_sec > time_span->end_time.tv_sec - || (e.tv_sec == time_span->end_time.tv_sec - && e.tv_nsec > time_span->end_time.tv_nsec)) - time_span->end_time = e; - } - } + LttvTraceset * traceset = self->ts; + int numTraces = lttv_traceset_number(traceset); + int i; + LttTime s, e; + LttvTraceContext *tc; + LttTrace * trace; + + time_span->start_time.tv_sec = 0; + time_span->start_time.tv_nsec = 0; + time_span->end_time.tv_sec = 0; + time_span->end_time.tv_nsec = 0; + + for(i=0; itraces[i]; + trace = tc->t; + + ltt_trace_time_span_get(trace, &s, &e); + tc->time_span.start_time = s; + tc->time_span.end_time = e; + + if(i==0){ + time_span->start_time = s; + time_span->end_time = e; + } else { + if(s.tv_sec < time_span->start_time.tv_sec + || (s.tv_sec == time_span->start_time.tv_sec + && s.tv_nsec < time_span->start_time.tv_nsec)) + time_span->start_time = s; + if(e.tv_sec > time_span->end_time.tv_sec + || (e.tv_sec == time_span->end_time.tv_sec + && e.tv_nsec > time_span->end_time.tv_nsec)) + time_span->end_time = e; + } + } } static void init_tracefile_context(LttTracefile *tracefile, - LttvTraceContext *tc) + LttvTraceContext *tc) { - LttvTracefileContext *tfc; - LttvTracesetContext *tsc = tc->ts_context; - - tfc = LTTV_TRACESET_CONTEXT_GET_CLASS(tsc)->new_tracefile_context(tsc); + LttvTracefileContext *tfc; + LttvTracesetContext *tsc = tc->ts_context; - tfc->index = tc->tracefiles->len; - tc->tracefiles = g_array_append_val(tc->tracefiles, tfc); + tfc = LTTV_TRACESET_CONTEXT_GET_CLASS(tsc)->new_tracefile_context(tsc); - tfc->tf = tracefile; + tfc->index = tc->tracefiles->len; + tc->tracefiles = g_array_append_val(tc->tracefiles, tfc); - tfc->t_context = tc; - tfc->event = lttv_hooks_new(); - tfc->event_by_id = lttv_hooks_by_id_new(); - tfc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); - tfc->target_pid = -1; + tfc->tf = tracefile; + + tfc->t_context = tc; + tfc->event = lttv_hooks_new(); + tfc->event_by_id = lttv_hooks_by_id_new(); + tfc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); + tfc->target_pid = -1; } static void init(LttvTracesetContext *self, LttvTraceset *ts) { - guint i, nb_trace; - - LttvTraceContext *tc; - - GData **tracefiles_groups; - - struct compute_tracefile_group_args args; - - nb_trace = lttv_traceset_number(ts); - self->ts = ts; - self->traces = g_new(LttvTraceContext *, nb_trace); - self->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); - self->ts_a = lttv_traceset_attribute(ts); - for(i = 0 ; i < nb_trace ; i++) { - tc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_trace_context(self); - self->traces[i] = tc; - - tc->ts_context = self; - tc->index = i; - tc->vt = lttv_traceset_get(ts, i); - tc->t = lttv_trace(tc->vt); - tc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); - tc->t_a = lttv_trace_attribute(tc->vt); - tc->tracefiles = g_array_sized_new(FALSE, TRUE, - sizeof(LttvTracefileContext*), 10); - - tracefiles_groups = ltt_trace_get_tracefiles_groups(tc->t); - if(tracefiles_groups != NULL) { - args.func = (ForEachTraceFileFunc)init_tracefile_context; - args.func_args = tc; - - g_datalist_foreach(tracefiles_groups, - (GDataForeachFunc)compute_tracefile_group, - &args); - } - + guint i, nb_trace; + + LttvTraceContext *tc; + + GData **tracefiles_groups; + + struct compute_tracefile_group_args args; + + nb_trace = lttv_traceset_number(ts); + self->ts = ts; + self->traces = g_new(LttvTraceContext *, nb_trace); + self->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); + self->ts_a = lttv_traceset_attribute(ts); + for(i = 0 ; i < nb_trace ; i++) { + tc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_trace_context(self); + self->traces[i] = tc; + + tc->ts_context = self; + tc->index = i; + tc->vt = lttv_traceset_get(ts, i); + tc->t = lttv_trace(tc->vt); + tc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); + tc->t_a = lttv_trace_attribute(tc->vt); + tc->tracefiles = g_array_sized_new(FALSE, TRUE, + sizeof(LttvTracefileContext*), 10); + + tracefiles_groups = ltt_trace_get_tracefiles_groups(tc->t); + if(tracefiles_groups != NULL) { + args.func = (ForEachTraceFileFunc)init_tracefile_context; + args.func_args = tc; + + g_datalist_foreach(tracefiles_groups, + (GDataForeachFunc)compute_tracefile_group, + &args); + } + #if 0 - nb_control = ltt_trace_control_tracefile_number(tc->t); - nb_per_cpu = ltt_trace_per_cpu_tracefile_number(tc->t); - nb_tracefile = nb_control + nb_per_cpu; - tc->tracefiles = g_new(LttvTracefileContext *, nb_tracefile); - - for(j = 0 ; j < nb_tracefile ; j++) { - tfc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_tracefile_context(self); - tc->tracefiles[j] = tfc; - tfc->index = j; - - if(j < nb_control) { - tfc->control = TRUE; - tfc->tf = ltt_trace_control_tracefile_get(tc->t, j); - } - else { - tfc->control = FALSE; - tfc->tf = ltt_trace_per_cpu_tracefile_get(tc->t, j - nb_control); - } - - tfc->t_context = tc; - tfc->e = ltt_event_new(); - tfc->event = lttv_hooks_new(); - tfc->event_by_id = lttv_hooks_by_id_new(); - tfc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); - } + nb_control = ltt_trace_control_tracefile_number(tc->t); + nb_per_cpu = ltt_trace_per_cpu_tracefile_number(tc->t); + nb_tracefile = nb_control + nb_per_cpu; + tc->tracefiles = g_new(LttvTracefileContext *, nb_tracefile); + + for(j = 0 ; j < nb_tracefile ; j++) { + tfc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_tracefile_context(self); + tc->tracefiles[j] = tfc; + tfc->index = j; + + if(j < nb_control) { + tfc->control = TRUE; + tfc->tf = ltt_trace_control_tracefile_get(tc->t, j); + } else { + tfc->control = FALSE; + tfc->tf = ltt_trace_per_cpu_tracefile_get(tc->t, j - nb_control); + } + + tfc->t_context = tc; + tfc->e = ltt_event_new(); + tfc->event = lttv_hooks_new(); + tfc->event_by_id = lttv_hooks_by_id_new(); + tfc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); + } #endif //0 - } - self->sync_position = lttv_traceset_context_position_new(self); - self->pqueue = g_tree_new(compare_tracefile); - lttv_process_traceset_seek_time(self, ltt_time_zero); - lttv_traceset_context_compute_time_span(self, &self->time_span); + } + self->sync_position = lttv_traceset_context_position_new(self); + self->pqueue = g_tree_new(compare_tracefile); + lttv_process_traceset_seek_time(self, ltt_time_zero); + lttv_traceset_context_compute_time_span(self, &self->time_span); } void fini(LttvTracesetContext *self) { - guint i, j, nb_trace, nb_tracefile; + guint i, j, nb_trace, nb_tracefile; - LttvTraceContext *tc; + LttvTraceContext *tc; - LttvTracefileContext **tfc; + LttvTracefileContext **tfc; - LttvTraceset *ts = self->ts; + LttvTraceset *ts = self->ts; - g_tree_destroy(self->pqueue); - g_object_unref(self->a); - lttv_traceset_context_position_destroy(self->sync_position); + g_tree_destroy(self->pqueue); + g_object_unref(self->a); + lttv_traceset_context_position_destroy(self->sync_position); - nb_trace = lttv_traceset_number(ts); + nb_trace = lttv_traceset_number(ts); - for(i = 0 ; i < nb_trace ; i++) { - tc = self->traces[i]; + for(i = 0 ; i < nb_trace ; i++) { + tc = self->traces[i]; - g_object_unref(tc->a); + g_object_unref(tc->a); - nb_tracefile = tc->tracefiles->len; + nb_tracefile = tc->tracefiles->len; - for(j = 0 ; j < nb_tracefile ; j++) { - tfc = &g_array_index(tc->tracefiles, LttvTracefileContext*, j); - lttv_hooks_destroy((*tfc)->event); - lttv_hooks_by_id_destroy((*tfc)->event_by_id); - g_object_unref((*tfc)->a); - g_object_unref(*tfc); - } - g_array_free(tc->tracefiles, TRUE); - g_object_unref(tc); - } - g_free(self->traces); + for(j = 0 ; j < nb_tracefile ; j++) { + tfc = &g_array_index(tc->tracefiles, LttvTracefileContext*, j); + lttv_hooks_destroy((*tfc)->event); + lttv_hooks_by_id_destroy((*tfc)->event_by_id); + g_object_unref((*tfc)->a); + g_object_unref(*tfc); + } + g_array_free(tc->tracefiles, TRUE); + g_object_unref(tc); + } + g_free(self->traces); } void lttv_traceset_context_add_hooks(LttvTracesetContext *self, - LttvHooks *before_traceset, - LttvHooks *before_trace, - LttvHooks *before_tracefile, - LttvHooks *event, - LttvHooksByIdChannelArray *event_by_id_channel) + LttvHooks *before_traceset, + LttvHooks *before_trace, + LttvHooks *before_tracefile, + LttvHooks *event, + LttvHooksByIdChannelArray *event_by_id_channel) { - LttvTraceset *ts = self->ts; + LttvTraceset *ts = self->ts; - guint i, nb_trace; + guint i, nb_trace; - LttvTraceContext *tc; + LttvTraceContext *tc; - lttv_hooks_call(before_traceset, self); + lttv_hooks_call(before_traceset, self); - nb_trace = lttv_traceset_number(ts); + nb_trace = lttv_traceset_number(ts); - for(i = 0 ; i < nb_trace ; i++) { - tc = self->traces[i]; - lttv_trace_context_add_hooks(tc, - before_trace, - before_tracefile, - event, - event_by_id_channel); - } + for(i = 0 ; i < nb_trace ; i++) { + tc = self->traces[i]; + lttv_trace_context_add_hooks(tc, + before_trace, + before_tracefile, + event, + event_by_id_channel); + } } void lttv_traceset_context_remove_hooks(LttvTracesetContext *self, - LttvHooks *after_traceset, - LttvHooks *after_trace, - LttvHooks *after_tracefile, - LttvHooks *event, - LttvHooksByIdChannelArray *event_by_id_channel) + LttvHooks *after_traceset, + LttvHooks *after_trace, + LttvHooks *after_tracefile, + LttvHooks *event, + LttvHooksByIdChannelArray *event_by_id_channel) { - LttvTraceset *ts = self->ts; + LttvTraceset *ts = self->ts; - guint i, nb_trace; + guint i, nb_trace; - LttvTraceContext *tc; + LttvTraceContext *tc; - nb_trace = lttv_traceset_number(ts); + nb_trace = lttv_traceset_number(ts); - for(i = 0 ; i < nb_trace ; i++) { - tc = self->traces[i]; - lttv_trace_context_remove_hooks(tc, - after_trace, - after_tracefile, - event, - event_by_id_channel); - } + for(i = 0 ; i < nb_trace ; i++) { + tc = self->traces[i]; + lttv_trace_context_remove_hooks(tc, + after_trace, + after_tracefile, + event, + event_by_id_channel); + } - lttv_hooks_call(after_traceset, self); + lttv_hooks_call(after_traceset, self); } void lttv_trace_context_add_hooks(LttvTraceContext *self, - LttvHooks *before_trace, - LttvHooks *before_tracefile, - LttvHooks *event, - LttvHooksByIdChannelArray *event_by_id_channel) + LttvHooks *before_trace, + LttvHooks *before_tracefile, + LttvHooks *event, + LttvHooksByIdChannelArray *event_by_id_channel) { - guint i, j, nb_tracefile; - LttvTracefileContext **tfc; - LttTracefile *tf; - - lttv_hooks_call(before_trace, self); - - nb_tracefile = self->tracefiles->len; - - for(i = 0 ; i < nb_tracefile ; i++) { - tfc = &g_array_index(self->tracefiles, LttvTracefileContext*, i); - tf = (*tfc)->tf; - lttv_tracefile_context_add_hooks(*tfc, - before_tracefile, - event, - NULL); - if (event_by_id_channel) { - for(j = 0; j < event_by_id_channel->array->len; j++) { - LttvHooksByIdChannel *hooks = &g_array_index(event_by_id_channel->array, - LttvHooksByIdChannel, j); - if (tf->name == hooks->channel) - lttv_tracefile_context_add_hooks(*tfc, - NULL, - NULL, - hooks->hooks_by_id); - } - } - } + guint i, j, nb_tracefile; + LttvTracefileContext **tfc; + LttTracefile *tf; + + lttv_hooks_call(before_trace, self); + + nb_tracefile = self->tracefiles->len; + + for(i = 0 ; i < nb_tracefile ; i++) { + tfc = &g_array_index(self->tracefiles, LttvTracefileContext*, i); + tf = (*tfc)->tf; + lttv_tracefile_context_add_hooks(*tfc, + before_tracefile, + event, + NULL); + if (event_by_id_channel) { + for(j = 0; j < event_by_id_channel->array->len; j++) { + LttvHooksByIdChannel *hooks = + &g_array_index(event_by_id_channel->array, + LttvHooksByIdChannel, j); + if (tf->name == hooks->channel) + lttv_tracefile_context_add_hooks(*tfc, + NULL, + NULL, + hooks->hooks_by_id); + } + } + } } void lttv_trace_context_remove_hooks(LttvTraceContext *self, - LttvHooks *after_trace, - LttvHooks *after_tracefile, - LttvHooks *event, - LttvHooksByIdChannelArray *event_by_id_channel) + LttvHooks *after_trace, + LttvHooks *after_tracefile, + LttvHooks *event, + LttvHooksByIdChannelArray *event_by_id_channel) { - guint i, j, nb_tracefile; - LttvTracefileContext **tfc; - LttTracefile *tf; - - nb_tracefile = self->tracefiles->len; - - for(i = 0 ; i < nb_tracefile ; i++) { - tfc = &g_array_index(self->tracefiles, LttvTracefileContext*, i); - tf = (*tfc)->tf; - if (event_by_id_channel) { - for(j = 0; j < event_by_id_channel->array->len; j++) { - LttvHooksByIdChannel *hooks = &g_array_index(event_by_id_channel->array, - LttvHooksByIdChannel, j); - if (tf->name == hooks->channel) - lttv_tracefile_context_remove_hooks(*tfc, - NULL, - NULL, - hooks->hooks_by_id); - } - } - lttv_tracefile_context_remove_hooks(*tfc, - after_tracefile, - event, - NULL); - - } - - lttv_hooks_call(after_trace, self); + guint i, j, nb_tracefile; + LttvTracefileContext **tfc; + LttTracefile *tf; + + nb_tracefile = self->tracefiles->len; + + for(i = 0 ; i < nb_tracefile ; i++) { + tfc = &g_array_index(self->tracefiles, LttvTracefileContext*, i); + tf = (*tfc)->tf; + if (event_by_id_channel) { + for(j = 0; j < event_by_id_channel->array->len; j++) { + LttvHooksByIdChannel *hooks = + &g_array_index(event_by_id_channel->array, + LttvHooksByIdChannel, j); + if (tf->name == hooks->channel) + lttv_tracefile_context_remove_hooks(*tfc, + NULL, + NULL, + hooks->hooks_by_id); + } + } + lttv_tracefile_context_remove_hooks(*tfc, + after_tracefile, + event, + NULL); + + } + + lttv_hooks_call(after_trace, self); } void lttv_tracefile_context_add_hooks(LttvTracefileContext *self, - LttvHooks *before_tracefile, - LttvHooks *event, - LttvHooksById *event_by_id) + LttvHooks *before_tracefile, + LttvHooks *event, + LttvHooksById *event_by_id) { - guint i, index; - LttvHooks *hook; - - lttv_hooks_call(before_tracefile, self); - lttv_hooks_add_list(self->event, event); - if(event_by_id != NULL) { - for(i = 0; i < event_by_id->array->len; i++) { - index = g_array_index(event_by_id->array, guint, i); - hook = lttv_hooks_by_id_find(self->event_by_id, index); - lttv_hooks_add_list(hook, lttv_hooks_by_id_get(event_by_id, index)); - } - } + guint i, index; + LttvHooks *hook; + + lttv_hooks_call(before_tracefile, self); + lttv_hooks_add_list(self->event, event); + if(event_by_id != NULL) { + for(i = 0; i < event_by_id->array->len; i++) { + index = g_array_index(event_by_id->array, guint, i); + hook = lttv_hooks_by_id_find(self->event_by_id, index); + lttv_hooks_add_list(hook, lttv_hooks_by_id_get(event_by_id, index)); + } + } } void lttv_tracefile_context_remove_hooks(LttvTracefileContext *self, - LttvHooks *after_tracefile, - LttvHooks *event, - LttvHooksById *event_by_id) + LttvHooks *after_tracefile, + LttvHooks *event, + LttvHooksById *event_by_id) { - guint i, index; - - LttvHooks *hook; - - lttv_hooks_remove_list(self->event, event); - if(event_by_id != NULL) { - for(i = 0; i < event_by_id->array->len; i++) { - index = g_array_index(event_by_id->array, guint, i); - hook = lttv_hooks_by_id_get(self->event_by_id, index); - if(hook != NULL) - lttv_hooks_remove_list(hook, lttv_hooks_by_id_get(event_by_id, index)); - } - } - - lttv_hooks_call(after_tracefile, self); + guint i, index; + + LttvHooks *hook; + + lttv_hooks_remove_list(self->event, event); + if(event_by_id != NULL) { + for(i = 0; i < event_by_id->array->len; i++) { + index = g_array_index(event_by_id->array, guint, i); + hook = lttv_hooks_by_id_get(self->event_by_id, index); + if(hook != NULL) + lttv_hooks_remove_list(hook, lttv_hooks_by_id_get(event_by_id, index)); + } + } + + lttv_hooks_call(after_tracefile, self); } -static LttvTracesetContext * -new_traceset_context(LttvTracesetContext *self) +static LttvTracesetContext *new_traceset_context(LttvTracesetContext *self) { - return g_object_new(LTTV_TRACESET_CONTEXT_TYPE, NULL); + return g_object_new(LTTV_TRACESET_CONTEXT_TYPE, NULL); } -static LttvTraceContext * -new_trace_context(LttvTracesetContext *self) +static LttvTraceContext *new_trace_context(LttvTracesetContext *self) { - return g_object_new(LTTV_TRACE_CONTEXT_TYPE, NULL); + return g_object_new(LTTV_TRACE_CONTEXT_TYPE, NULL); } -static LttvTracefileContext * -new_tracefile_context(LttvTracesetContext *self) +static LttvTracefileContext *new_tracefile_context(LttvTracesetContext *self) { - return g_object_new(LTTV_TRACEFILE_CONTEXT_TYPE, NULL); + return g_object_new(LTTV_TRACEFILE_CONTEXT_TYPE, NULL); } -static void -traceset_context_instance_init (GTypeInstance *instance, gpointer g_class) +static void traceset_context_instance_init(GTypeInstance *instance, + gpointer g_class) { - /* Be careful of anything which would not work well with shallow copies */ + /* Be careful of anything which would not work well with shallow copies */ } -static void -traceset_context_finalize (LttvTracesetContext *self) +static void traceset_context_finalize(LttvTracesetContext *self) { - G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACESET_CONTEXT_TYPE))) - ->finalize(G_OBJECT(self)); + G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACESET_CONTEXT_TYPE))) + ->finalize(G_OBJECT(self)); } -static void -traceset_context_class_init (LttvTracesetContextClass *klass) +static void traceset_context_class_init(LttvTracesetContextClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->finalize = (void (*)(GObject *self))traceset_context_finalize; - klass->init = init; - klass->fini = fini; - klass->new_traceset_context = new_traceset_context; - klass->new_trace_context = new_trace_context; - klass->new_tracefile_context = new_tracefile_context; + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->finalize = (void (*)(GObject *self))traceset_context_finalize; + klass->init = init; + klass->fini = fini; + klass->new_traceset_context = new_traceset_context; + klass->new_trace_context = new_trace_context; + klass->new_tracefile_context = new_tracefile_context; } -GType -lttv_traceset_context_get_type(void) +GType lttv_traceset_context_get_type(void) { - static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof (LttvTracesetContextClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) traceset_context_class_init, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (LttvTracesetContext), - 0, /* n_preallocs */ - (GInstanceInitFunc) traceset_context_instance_init, /* instance_init */ - NULL /* Value handling */ - }; - - type = g_type_register_static (G_TYPE_OBJECT, "LttvTracesetContextType", - &info, 0); - } - return type; + static GType type = 0; + if (type == 0) { + static const GTypeInfo info = { + sizeof (LttvTracesetContextClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) traceset_context_class_init, /* class_init */ + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (LttvTracesetContext), + 0, /* n_preallocs */ + (GInstanceInitFunc) traceset_context_instance_init, /* instance_init */ + NULL /* Value handling */ + }; + + type = g_type_register_static (G_TYPE_OBJECT, "LttvTracesetContextType", + &info, 0); + } + return type; } static void trace_context_instance_init (GTypeInstance *instance, gpointer g_class) { - /* Be careful of anything which would not work well with shallow copies */ + /* Be careful of anything which would not work well with shallow copies */ } -static void -trace_context_finalize (LttvTraceContext *self) +static void trace_context_finalize (LttvTraceContext *self) { - G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACE_CONTEXT_TYPE)))-> - finalize(G_OBJECT(self)); + G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACE_CONTEXT_TYPE)))-> + finalize(G_OBJECT(self)); } -static void -trace_context_class_init (LttvTraceContextClass *klass) +static void trace_context_class_init (LttvTraceContextClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - gobject_class->finalize = (void (*)(GObject *self)) trace_context_finalize; + gobject_class->finalize = (void (*)(GObject *self)) trace_context_finalize; } -GType -lttv_trace_context_get_type(void) +GType lttv_trace_context_get_type(void) { - static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof (LttvTraceContextClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) trace_context_class_init, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (LttvTraceContext), - 0, /* n_preallocs */ - (GInstanceInitFunc) trace_context_instance_init, /* instance_init */ - NULL /* Value handling */ - }; - - type = g_type_register_static (G_TYPE_OBJECT, "LttvTraceContextType", - &info, 0); - } - return type; + static GType type = 0; + if (type == 0) { + static const GTypeInfo info = { + sizeof (LttvTraceContextClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) trace_context_class_init, /* class_init */ + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (LttvTraceContext), + 0, /* n_preallocs */ + (GInstanceInitFunc) trace_context_instance_init, /* instance_init */ + NULL /* Value handling */ + }; + + type = g_type_register_static (G_TYPE_OBJECT, "LttvTraceContextType", + &info, 0); + } + return type; } -static void -tracefile_context_instance_init (GTypeInstance *instance, gpointer g_class) +static void tracefile_context_instance_init (GTypeInstance *instance, + gpointer g_class) { - /* Be careful of anything which would not work well with shallow copies */ + /* Be careful of anything which would not work well with shallow copies */ } -static void -tracefile_context_finalize (LttvTracefileContext *self) +static void tracefile_context_finalize (LttvTracefileContext *self) { - G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACEFILE_CONTEXT_TYPE))) - ->finalize(G_OBJECT(self)); + G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACEFILE_CONTEXT_TYPE))) + ->finalize(G_OBJECT(self)); } -static void -tracefile_context_class_init (LttvTracefileContextClass *klass) +static void tracefile_context_class_init (LttvTracefileContextClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - gobject_class->finalize = (void (*)(GObject *self))tracefile_context_finalize; + gobject_class->finalize = (void (*)(GObject *self))tracefile_context_finalize; } -GType -lttv_tracefile_context_get_type(void) +GType lttv_tracefile_context_get_type(void) { - static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof (LttvTracefileContextClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) tracefile_context_class_init, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (LttvTracefileContext), - 0, /* n_preallocs */ - (GInstanceInitFunc) tracefile_context_instance_init, /* instance_init */ - NULL /* Value handling */ - }; - - type = g_type_register_static (G_TYPE_OBJECT, "LttvTracefileContextType", - &info, 0); - } - return type; + static GType type = 0; + if (type == 0) { + static const GTypeInfo info = { + sizeof (LttvTracefileContextClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) tracefile_context_class_init, /* class_init */ + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (LttvTracefileContext), + 0, /* n_preallocs */ + (GInstanceInitFunc) tracefile_context_instance_init, /* instance_init */ + NULL /* Value handling */ + }; + + type = g_type_register_static (G_TYPE_OBJECT, "LttvTracefileContextType", + &info, 0); + } + return type; } static gboolean get_first(gpointer key, gpointer value, gpointer user_data) { - g_assert(key == value); - *((LttvTracefileContext **)user_data) = (LttvTracefileContext *)value; - return TRUE; + g_assert(key == value); + *((LttvTracefileContext **)user_data) = (LttvTracefileContext *)value; + return TRUE; } #ifdef DEBUG @@ -640,189 +629,189 @@ static LttTime test_time; static gboolean test_tree(gpointer key, gpointer value, gpointer user_data) { - LttvTracefileContext *tfc = (LttvTracefileContext *)key; - - g_debug("Tracefile name %s, time %lu.%lu, tfi %u, ti %u", - g_quark_to_string(ltt_tracefile_name(tfc->tf)), - tfc->timestamp.tv_sec, tfc->timestamp.tv_nsec, - tfc->index, tfc->t_context->index); - - if(user_data != NULL) { - if(((LttvTracefileContext *)user_data) == (LttvTracefileContext *)value) { - g_assert(compare_tracefile(user_data, value) == 0); - } else - g_assert(compare_tracefile(user_data, value) != 0); - } - g_assert(ltt_time_compare(test_time, tfc->timestamp) <= 0); - test_time.tv_sec = tfc->timestamp.tv_sec; - test_time.tv_nsec = tfc->timestamp.tv_nsec; - - - //g_assert(((LttvTracefileContext *)user_data) != (LttvTracefileContext *)value); - return FALSE; + LttvTracefileContext *tfc = (LttvTracefileContext *)key; + + g_debug("Tracefile name %s, time %lu.%lu, tfi %u, ti %u", + g_quark_to_string(ltt_tracefile_name(tfc->tf)), + tfc->timestamp.tv_sec, tfc->timestamp.tv_nsec, + tfc->index, tfc->t_context->index); + + if(user_data != NULL) { + if(((LttvTracefileContext *)user_data) == (LttvTracefileContext *)value) { + g_assert(compare_tracefile(user_data, value) == 0); + } else + g_assert(compare_tracefile(user_data, value) != 0); + } + g_assert(ltt_time_compare(test_time, tfc->timestamp) <= 0); + test_time.tv_sec = tfc->timestamp.tv_sec; + test_time.tv_nsec = tfc->timestamp.tv_nsec; + + + //g_assert(((LttvTracefileContext *)user_data) != (LttvTracefileContext *)value); + return FALSE; } #endif //DEBUG void lttv_process_traceset_begin(LttvTracesetContext *self, - LttvHooks *before_traceset, - LttvHooks *before_trace, - LttvHooks *before_tracefile, - LttvHooks *event, - LttvHooksByIdChannelArray *event_by_id_channel) + LttvHooks *before_traceset, + LttvHooks *before_trace, + LttvHooks *before_tracefile, + LttvHooks *event, + LttvHooksByIdChannelArray *event_by_id_channel) { - /* simply add hooks in context. _before hooks are called by add_hooks. */ - /* It calls all before_traceset, before_trace, and before_tracefile hooks. */ - lttv_traceset_context_add_hooks(self, - before_traceset, - before_trace, - before_tracefile, - event, - event_by_id_channel); - + /* simply add hooks in context. _before hooks are called by add_hooks. */ + /* It calls all before_traceset, before_trace, and before_tracefile hooks. */ + lttv_traceset_context_add_hooks(self, + before_traceset, + before_trace, + before_tracefile, + event, + event_by_id_channel); + } //enum read_state { LAST_NONE, LAST_OK, LAST_EMPTY }; /* Note : a _middle must be preceded from a _seek or another middle */ guint lttv_process_traceset_middle(LttvTracesetContext *self, - LttTime end, - gulong nb_events, - const LttvTracesetContextPosition *end_position) + LttTime end, + gulong nb_events, + const LttvTracesetContextPosition *end_position) { - GTree *pqueue = self->pqueue; - - LttvTracefileContext *tfc; - - LttEvent *e; - - unsigned count = 0; - - guint read_ret; - - //enum read_state last_read_state = LAST_NONE; - - gint last_ret = 0; /* return value of the last hook list called */ - - /* Get the next event from the pqueue, call its hooks, - reinsert in the pqueue the following event from the same tracefile - unless the tracefile is finished or the event is later than the - end time. */ - - while(TRUE) { - tfc = NULL; - g_tree_foreach(pqueue, get_first, &tfc); - /* End of traceset : tfc is NULL */ - if(unlikely(tfc == NULL)) - { - return count; - } - - /* Have we reached : - * - the maximum number of events specified? - * - the end position ? - * - the end time ? - * then the read is finished. We leave the queue in the same state and - * break the loop. - */ - - if(unlikely(last_ret == TRUE || - ((count >= nb_events) && (nb_events != G_MAXULONG)) || - (end_position!=NULL&<tv_traceset_context_ctx_pos_compare(self, - end_position) == 0)|| - ltt_time_compare(end, tfc->timestamp) <= 0)) - { - return count; - } - - /* Get the tracefile with an event for the smallest time found. If two - or more tracefiles have events for the same time, hope that lookup - and remove are consistent. */ + GTree *pqueue = self->pqueue; + + LttvTracefileContext *tfc; + + LttEvent *e; + + unsigned count = 0; + + guint read_ret; + + //enum read_state last_read_state = LAST_NONE; + + gint last_ret = 0; /* return value of the last hook list called */ + + /* Get the next event from the pqueue, call its hooks, + reinsert in the pqueue the following event from the same tracefile + unless the tracefile is finished or the event is later than the + end time. */ + + while(TRUE) { + tfc = NULL; + g_tree_foreach(pqueue, get_first, &tfc); + /* End of traceset : tfc is NULL */ + if(unlikely(tfc == NULL)) + { + return count; + } + + /* Have we reached : + * - the maximum number of events specified? + * - the end position ? + * - the end time ? + * then the read is finished. We leave the queue in the same state and + * break the loop. + */ + + if(unlikely(last_ret == TRUE + || ((count >= nb_events) && (nb_events != G_MAXULONG)) + || (end_position!=NULL&<tv_traceset_context_ctx_pos_compare(self, + end_position) == 0) + || ltt_time_compare(end, tfc->timestamp) <= 0)) + { + return count; + } + + /* Get the tracefile with an event for the smallest time found. If two + or more tracefiles have events for the same time, hope that lookup + and remove are consistent. */ #ifdef DEBUG - test_time.tv_sec = 0; - test_time.tv_nsec = 0; - g_debug("test tree before remove"); - g_tree_foreach(pqueue, test_tree, tfc); + test_time.tv_sec = 0; + test_time.tv_nsec = 0; + g_debug("test tree before remove"); + g_tree_foreach(pqueue, test_tree, tfc); #endif //DEBUG - g_tree_remove(pqueue, tfc); + g_tree_remove(pqueue, tfc); #ifdef DEBUG - test_time.tv_sec = 0; - test_time.tv_nsec = 0; - g_debug("test tree after remove"); - g_tree_foreach(pqueue, test_tree, tfc); + test_time.tv_sec = 0; + test_time.tv_nsec = 0; + g_debug("test tree after remove"); + g_tree_foreach(pqueue, test_tree, tfc); #endif //DEBUG - e = ltt_tracefile_get_event(tfc->tf); + e = ltt_tracefile_get_event(tfc->tf); - //if(last_read_state != LAST_EMPTY) { - /* Only call hooks if the last read has given an event or if we are at the - * first pass (not if last read returned end of tracefile) */ - count++; - - tfc->target_pid = -1; /* unset target PID */ - /* Hooks : - * return values : 0 : continue read, 1 : go to next position and stop read, - * 2 : stay at the current position and stop read */ - last_ret = lttv_hooks_call_merge(tfc->event, tfc, - lttv_hooks_by_id_get(tfc->event_by_id, e->event_id), tfc); + //if(last_read_state != LAST_EMPTY) { + /* Only call hooks if the last read has given an event or if we are at the + * first pass (not if last read returned end of tracefile) */ + count++; + + tfc->target_pid = -1; /* unset target PID */ + /* Hooks : + * return values : 0 : continue read, 1 : go to next position and stop read, + * 2 : stay at the current position and stop read */ + last_ret = lttv_hooks_call_merge(tfc->event, tfc, + lttv_hooks_by_id_get(tfc->event_by_id, e->event_id), tfc); #if 0 - /* This is buggy : it won't work well with state computation */ - if(unlikely(last_ret == 2)) { - /* This is a case where we want to stay at this position and stop read. */ - g_tree_insert(pqueue, tfc, tfc); - return count - 1; - } + /* This is buggy : it won't work well with state computation */ + if(unlikely(last_ret == 2)) { + /* This is a case where we want to stay at this position and stop read. */ + g_tree_insert(pqueue, tfc, tfc); + return count - 1; + } #endif //0 - read_ret = ltt_tracefile_read(tfc->tf); - - - if(likely(!read_ret)) { - //g_debug("An event is ready"); - tfc->timestamp = ltt_event_time(e); - g_assert(ltt_time_compare(tfc->timestamp, ltt_time_infinite) != 0); - g_tree_insert(pqueue, tfc, tfc); + read_ret = ltt_tracefile_read(tfc->tf); + + + if(likely(!read_ret)) { + //g_debug("An event is ready"); + tfc->timestamp = ltt_event_time(e); + g_assert(ltt_time_compare(tfc->timestamp, ltt_time_infinite) != 0); + g_tree_insert(pqueue, tfc, tfc); #ifdef DEBUG - test_time.tv_sec = 0; - test_time.tv_nsec = 0; - g_debug("test tree after event ready"); - g_tree_foreach(pqueue, test_tree, NULL); + test_time.tv_sec = 0; + test_time.tv_nsec = 0; + g_debug("test tree after event ready"); + g_tree_foreach(pqueue, test_tree, NULL); #endif //DEBUG - //last_read_state = LAST_OK; - } else { - tfc->timestamp = ltt_time_infinite; - - if(read_ret == ERANGE) { - // last_read_state = LAST_EMPTY; - g_debug("End of trace"); - } else - g_error("Error happened in lttv_process_traceset_middle"); - } - } + //last_read_state = LAST_OK; + } else { + tfc->timestamp = ltt_time_infinite; + + if(read_ret == ERANGE) { + // last_read_state = LAST_EMPTY; + g_debug("End of trace"); + } else + g_error("Error happened in lttv_process_traceset_middle"); + } + } } void lttv_process_traceset_end(LttvTracesetContext *self, - LttvHooks *after_traceset, - LttvHooks *after_trace, - LttvHooks *after_tracefile, - LttvHooks *event, - LttvHooksByIdChannelArray *event_by_id_channel) + LttvHooks *after_traceset, + LttvHooks *after_trace, + LttvHooks *after_tracefile, + LttvHooks *event, + LttvHooksByIdChannelArray *event_by_id_channel) { - /* Remove hooks from context. _after hooks are called by remove_hooks. */ - /* It calls all after_traceset, after_trace, and after_tracefile hooks. */ - lttv_traceset_context_remove_hooks(self, - after_traceset, - after_trace, - after_tracefile, - event, - event_by_id_channel); + /* Remove hooks from context. _after hooks are called by remove_hooks. */ + /* It calls all after_traceset, after_trace, and after_tracefile hooks. */ + lttv_traceset_context_remove_hooks(self, + after_traceset, + after_trace, + after_tracefile, + event, + event_by_id_channel); } /* Subtile modification : @@ -833,114 +822,114 @@ void lttv_process_traceset_end(LttvTracesetContext *self, */ void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start) { - guint i, nb_tracefile; + guint i, nb_tracefile; + + gint ret; + + LttvTracefileContext **tfc; - gint ret; - - LttvTracefileContext **tfc; + nb_tracefile = self->tracefiles->len; - nb_tracefile = self->tracefiles->len; + GTree *pqueue = self->ts_context->pqueue; - GTree *pqueue = self->ts_context->pqueue; + for(i = 0 ; i < nb_tracefile ; i++) { + tfc = &g_array_index(self->tracefiles, LttvTracefileContext*, i); - for(i = 0 ; i < nb_tracefile ; i++) { - tfc = &g_array_index(self->tracefiles, LttvTracefileContext*, i); + g_tree_remove(pqueue, *tfc); - g_tree_remove(pqueue, *tfc); - - ret = ltt_tracefile_seek_time((*tfc)->tf, start); - if(ret == EPERM) g_error("error in lttv_process_trace_seek_time seek"); + ret = ltt_tracefile_seek_time((*tfc)->tf, start); + if(ret == EPERM) g_error("error in lttv_process_trace_seek_time seek"); - if(ret == 0) { /* not ERANGE especially */ - (*tfc)->timestamp = ltt_event_time(ltt_tracefile_get_event((*tfc)->tf)); - g_assert(ltt_time_compare((*tfc)->timestamp, ltt_time_infinite) != 0); - g_tree_insert(pqueue, (*tfc), (*tfc)); - } else { - (*tfc)->timestamp = ltt_time_infinite; - } - } + if(ret == 0) { /* not ERANGE especially */ + (*tfc)->timestamp = ltt_event_time(ltt_tracefile_get_event((*tfc)->tf)); + g_assert(ltt_time_compare((*tfc)->timestamp, ltt_time_infinite) != 0); + g_tree_insert(pqueue, (*tfc), (*tfc)); + } else { + (*tfc)->timestamp = ltt_time_infinite; + } + } #ifdef DEBUG - test_time.tv_sec = 0; - test_time.tv_nsec = 0; - g_debug("test tree after seek_time"); - g_tree_foreach(pqueue, test_tree, NULL); + test_time.tv_sec = 0; + test_time.tv_nsec = 0; + g_debug("test tree after seek_time"); + g_tree_foreach(pqueue, test_tree, NULL); #endif //DEBUG } void lttv_process_traceset_seek_time(LttvTracesetContext *self, LttTime start) { - guint i, nb_trace; + guint i, nb_trace; - LttvTraceContext *tc; + LttvTraceContext *tc; - //g_tree_destroy(self->pqueue); - //self->pqueue = g_tree_new(compare_tracefile); + //g_tree_destroy(self->pqueue); + //self->pqueue = g_tree_new(compare_tracefile); - nb_trace = lttv_traceset_number(self->ts); - for(i = 0 ; i < nb_trace ; i++) { - tc = self->traces[i]; - lttv_process_trace_seek_time(tc, start); - } + nb_trace = lttv_traceset_number(self->ts); + for(i = 0 ; i < nb_trace ; i++) { + tc = self->traces[i]; + lttv_process_trace_seek_time(tc, start); + } } gboolean lttv_process_traceset_seek_position(LttvTracesetContext *self, - const LttvTracesetContextPosition *pos) + const LttvTracesetContextPosition *pos) { - guint i; - /* If a position is set, seek the traceset to this position */ - if(ltt_time_compare(pos->timestamp, ltt_time_infinite) != 0) { - - /* Test to see if the traces has been added to the trace set : - * It should NEVER happen. Clear all positions if a new trace comes in. */ - /* FIXME I know this test is not optimal : should keep a number of - * tracefiles variable in the traceset.. eventually */ - guint num_traces = lttv_traceset_number(self->ts); - guint tf_count = 0; - for(i=0; itraces[i]->tracefiles; - guint j; - guint num_tracefiles = tracefiles->len; - for(j=0;jtfcp->len); - - - //g_tree_destroy(self->pqueue); - //self->pqueue = g_tree_new(compare_tracefile); - - for(i=0;itfcp->len; i++) { - LttvTracefileContextPosition *tfcp = - &g_array_index(pos->tfcp, LttvTracefileContextPosition, i); - - g_tree_remove(self->pqueue, tfcp->tfc); - - if(tfcp->used == TRUE) { - if(ltt_tracefile_seek_position(tfcp->tfc->tf, tfcp->event) != 0) - return 1; - tfcp->tfc->timestamp = - ltt_event_time(ltt_tracefile_get_event(tfcp->tfc->tf)); - g_assert(ltt_time_compare(tfcp->tfc->timestamp, - ltt_time_infinite) != 0); - g_tree_insert(self->pqueue, tfcp->tfc, tfcp->tfc); - - } else { - tfcp->tfc->timestamp = ltt_time_infinite; - } - } - } + guint i; + /* If a position is set, seek the traceset to this position */ + if(ltt_time_compare(pos->timestamp, ltt_time_infinite) != 0) { + + /* Test to see if the traces has been added to the trace set : + * It should NEVER happen. Clear all positions if a new trace comes in. */ + /* FIXME I know this test is not optimal : should keep a number of + * tracefiles variable in the traceset.. eventually */ + guint num_traces = lttv_traceset_number(self->ts); + guint tf_count = 0; + for(i=0; itraces[i]->tracefiles; + guint j; + guint num_tracefiles = tracefiles->len; + for(j=0;jtfcp->len); + + + //g_tree_destroy(self->pqueue); + //self->pqueue = g_tree_new(compare_tracefile); + + for(i=0;itfcp->len; i++) { + LttvTracefileContextPosition *tfcp = + &g_array_index(pos->tfcp, LttvTracefileContextPosition, i); + + g_tree_remove(self->pqueue, tfcp->tfc); + + if(tfcp->used == TRUE) { + if(ltt_tracefile_seek_position(tfcp->tfc->tf, tfcp->event) != 0) + return 1; + tfcp->tfc->timestamp = + ltt_event_time(ltt_tracefile_get_event(tfcp->tfc->tf)); + g_assert(ltt_time_compare(tfcp->tfc->timestamp, + ltt_time_infinite) != 0); + g_tree_insert(self->pqueue, tfcp->tfc, tfcp->tfc); + + } else { + tfcp->tfc->timestamp = ltt_time_infinite; + } + } + } #ifdef DEBUG - test_time.tv_sec = 0; - test_time.tv_nsec = 0; - g_debug("test tree after seek_position"); - g_tree_foreach(self->pqueue, test_tree, NULL); + test_time.tv_sec = 0; + test_time.tv_nsec = 0; + g_debug("test tree after seek_position"); + g_tree_foreach(self->pqueue, test_tree, NULL); #endif //DEBUG - return 0; + return 0; } @@ -948,142 +937,142 @@ gboolean lttv_process_traceset_seek_position(LttvTracesetContext *self, static LttField * find_field(LttEventType *et, const GQuark field) { - LttField *f; - - if(field == 0) return NULL; - - f = ltt_eventtype_field_by_name(et, field); - if (!f) { - g_warning("Cannot find field %s in event %s.%s", g_quark_to_string(field), - g_quark_to_string(ltt_facility_name(ltt_eventtype_facility(et))), - g_quark_to_string(ltt_eventtype_name(et))); - } - - return f; + LttField *f; + + if(field == 0) return NULL; + + f = ltt_eventtype_field_by_name(et, field); + if (!f) { + g_warning("Cannot find field %s in event %s.%s", g_quark_to_string(field), + g_quark_to_string(ltt_facility_name(ltt_eventtype_facility(et))), + g_quark_to_string(ltt_eventtype_name(et))); + } + + return f; } #endif struct marker_info *lttv_trace_hook_get_marker(LttTrace *t, LttvTraceHook *th) { - return marker_get_info_from_id(th->mdata, th->id); + return marker_get_info_from_id(th->mdata, th->id); } int lttv_trace_find_hook(LttTrace *t, GQuark channel_name, GQuark event_name, - GQuark fields[], LttvHook h, gpointer hook_data, GArray **trace_hooks) + GQuark fields[], LttvHook h, gpointer hook_data, + GArray **trace_hooks) { - struct marker_info *info; - guint16 marker_id; - int init_array_size; - GArray *group; - struct marker_data *mdata; - - group = g_datalist_id_get_data(&t->tracefiles, channel_name); - if (unlikely(!group || group->len == 0)) { - g_info("No channel for marker named %s.%s found", - g_quark_to_string(channel_name), g_quark_to_string(event_name)); - return 1; - } - - mdata = g_array_index (group, LttTracefile, 0).mdata; - info = marker_get_info_from_name(mdata, event_name); - if(unlikely(info == NULL)) { - g_info("No marker named %s.%s found", - g_quark_to_string(channel_name), g_quark_to_string(event_name)); - return 1; - } - - init_array_size = (*trace_hooks)->len; - - /* for each marker with the requested name */ - do { - LttvTraceHook tmpth; - int found; - GQuark *f; - struct marker_field *marker_field; - - marker_id = marker_get_id_from_info(mdata, info); - - tmpth.h = h; - tmpth.mdata = mdata; - tmpth.channel = channel_name; - tmpth.id = marker_id; - tmpth.hook_data = hook_data; - tmpth.fields = g_ptr_array_new(); - - /* for each field requested */ - for(f = fields; f && *f != 0; f++) { - found = 0; - for_each_marker_field(marker_field, info) { - if(marker_field->name == *f) { - found = 1; - g_ptr_array_add(tmpth.fields, marker_field); - break; - } - } - if(!found) { - /* Did not find the one of the fields in this instance of the - marker. Print a warning and skip this marker completely. - Still iterate on other markers with same name. */ - g_ptr_array_free(tmpth.fields, TRUE); - g_info("Field %s cannot be found in marker %s.%s", - g_quark_to_string(*f), g_quark_to_string(channel_name), - g_quark_to_string(event_name)); - goto skip_marker; - } - } - /* all fields were found: add the tracehook to the array */ - *trace_hooks = g_array_append_val(*trace_hooks, tmpth); + struct marker_info *info; + guint16 marker_id; + int init_array_size; + GArray *group; + struct marker_data *mdata; + + group = g_datalist_id_get_data(&t->tracefiles, channel_name); + if (unlikely(!group || group->len == 0)) { + g_info("No channel for marker named %s.%s found", + g_quark_to_string(channel_name), g_quark_to_string(event_name)); + return 1; + } + + mdata = g_array_index (group, LttTracefile, 0).mdata; + info = marker_get_info_from_name(mdata, event_name); + if(unlikely(info == NULL)) { + g_info("No marker named %s.%s found", + g_quark_to_string(channel_name), g_quark_to_string(event_name)); + return 1; + } + + init_array_size = (*trace_hooks)->len; + + /* for each marker with the requested name */ + do { + LttvTraceHook tmpth; + int found; + GQuark *f; + struct marker_field *marker_field; + + marker_id = marker_get_id_from_info(mdata, info); + + tmpth.h = h; + tmpth.mdata = mdata; + tmpth.channel = channel_name; + tmpth.id = marker_id; + tmpth.hook_data = hook_data; + tmpth.fields = g_ptr_array_new(); + + /* for each field requested */ + for(f = fields; f && *f != 0; f++) { + found = 0; + for_each_marker_field(marker_field, info) { + if(marker_field->name == *f) { + found = 1; + g_ptr_array_add(tmpth.fields, marker_field); + break; + } + } + if(!found) { + /* Did not find the one of the fields in this instance of the + marker. Print a warning and skip this marker completely. + Still iterate on other markers with same name. */ + g_ptr_array_free(tmpth.fields, TRUE); + g_info("Field %s cannot be found in marker %s.%s", + g_quark_to_string(*f), g_quark_to_string(channel_name), + g_quark_to_string(event_name)); + goto skip_marker; + } + } + /* all fields were found: add the tracehook to the array */ + *trace_hooks = g_array_append_val(*trace_hooks, tmpth); skip_marker: - info = info->next; - } while(info != NULL); - - /* Error if no new trace hook has been added */ - if (init_array_size == (*trace_hooks)->len) { - g_info("No marker of name %s.%s has all requested fields", - g_quark_to_string(channel_name), g_quark_to_string(event_name)); - return 1; - } - return 0; + info = info->next; + } while(info != NULL); + + /* Error if no new trace hook has been added */ + if (init_array_size == (*trace_hooks)->len) { + g_info("No marker of name %s.%s has all requested fields", + g_quark_to_string(channel_name), g_quark_to_string(event_name)); + return 1; + } + return 0; } void lttv_trace_hook_remove_all(GArray **th) { - int i; - for(i=0; i<(*th)->len; i++) { - g_ptr_array_free(g_array_index(*th, LttvTraceHook, i).fields, TRUE); - } - if((*th)->len) - *th = g_array_remove_range(*th, 0, (*th)->len); + int i; + for(i=0; i<(*th)->len; i++) { + g_ptr_array_free(g_array_index(*th, LttvTraceHook, i).fields, TRUE); + } + if((*th)->len) + *th = g_array_remove_range(*th, 0, (*th)->len); } -LttvTracesetContextPosition *lttv_traceset_context_position_new( - const LttvTracesetContext *self) +LttvTracesetContextPosition * +lttv_traceset_context_position_new(const LttvTracesetContext *self) { - guint num_traces = lttv_traceset_number(self->ts); - guint tf_count = 0; - guint i; - - for(i=0; itraces[i]->tracefiles; - guint j; - guint num_tracefiles = tracefiles->len; - for(j=0;jtfcp = g_array_sized_new(FALSE, TRUE, - sizeof(LttvTracefileContextPosition), - tf_count); - g_array_set_size(pos->tfcp, tf_count); - for(i=0;itfcp->len;i++) { - LttvTracefileContextPosition *tfcp = - &g_array_index(pos->tfcp, LttvTracefileContextPosition, i); - tfcp->event = ltt_event_position_new(); - } - - pos->timestamp = ltt_time_infinite; - return pos; + guint num_traces = lttv_traceset_number(self->ts); + guint tf_count = 0; + guint i; + + for(i=0; itraces[i]->tracefiles; + guint j; + guint num_tracefiles = tracefiles->len; + for(j=0;jtfcp = g_array_sized_new(FALSE, TRUE, + sizeof(LttvTracefileContextPosition), + tf_count); + g_array_set_size(pos->tfcp, tf_count); + for(i=0;itfcp->len;i++) { + LttvTracefileContextPosition *tfcp = + &g_array_index(pos->tfcp, LttvTracefileContextPosition, i); + tfcp->event = ltt_event_position_new(); + } + + pos->timestamp = ltt_time_infinite; + return pos; } /* Save all positions, the ones with infinite time will have NULL @@ -1091,190 +1080,191 @@ LttvTracesetContextPosition *lttv_traceset_context_position_new( /* note : a position must be destroyed when a trace is added/removed from a * traceset */ void lttv_traceset_context_position_save(const LttvTracesetContext *self, - LttvTracesetContextPosition *pos) + LttvTracesetContextPosition *pos) { - guint i; - guint num_traces = lttv_traceset_number(self->ts); - guint tf_count = 0; - - pos->timestamp = ltt_time_infinite; - - for(i=0; itraces[i]->tracefiles; - guint j; - guint num_tracefiles = tracefiles->len; - - for(j=0;jtfcp->len); - LttvTracefileContext **tfc = &g_array_index(tracefiles, - LttvTracefileContext*, j); - LttvTracefileContextPosition *tfcp = - &g_array_index(pos->tfcp, LttvTracefileContextPosition, tf_count); - - tfcp->tfc = *tfc; - - if(ltt_time_compare((*tfc)->timestamp, ltt_time_infinite) != 0) { - LttEvent *event = ltt_tracefile_get_event((*tfc)->tf); - ltt_event_position(event, tfcp->event); - if(ltt_time_compare((*tfc)->timestamp, pos->timestamp) < 0) - pos->timestamp = (*tfc)->timestamp; - tfcp->used = TRUE; - } else { - tfcp->used = FALSE; - } - - //g_array_append_val(pos->tfc, *tfc); - //g_array_append_val(pos->ep, ep); - tf_count++; - } - - } + guint i; + guint num_traces = lttv_traceset_number(self->ts); + guint tf_count = 0; + + pos->timestamp = ltt_time_infinite; + + for(i=0; itraces[i]->tracefiles; + guint j; + guint num_tracefiles = tracefiles->len; + + for(j=0;jtfcp->len); + LttvTracefileContext **tfc = &g_array_index(tracefiles, + LttvTracefileContext*, j); + LttvTracefileContextPosition *tfcp = + &g_array_index(pos->tfcp, LttvTracefileContextPosition, tf_count); + + tfcp->tfc = *tfc; + + if(ltt_time_compare((*tfc)->timestamp, ltt_time_infinite) != 0) { + LttEvent *event = ltt_tracefile_get_event((*tfc)->tf); + ltt_event_position(event, tfcp->event); + if(ltt_time_compare((*tfc)->timestamp, pos->timestamp) < 0) + pos->timestamp = (*tfc)->timestamp; + tfcp->used = TRUE; + } else { + tfcp->used = FALSE; + } + + //g_array_append_val(pos->tfc, *tfc); + //g_array_append_val(pos->ep, ep); + tf_count++; + } + + } } void lttv_traceset_context_position_destroy(LttvTracesetContextPosition *pos) { - int i; - - for(i=0;itfcp->len;i++) { - LttvTracefileContextPosition *tfcp = - &g_array_index(pos->tfcp, LttvTracefileContextPosition, i); - g_free(tfcp->event); - tfcp->event = NULL; - tfcp->used = FALSE; - } - g_array_free(pos->tfcp, TRUE); - g_free(pos); + int i; + + for(i=0;itfcp->len;i++) { + LttvTracefileContextPosition *tfcp = + &g_array_index(pos->tfcp, LttvTracefileContextPosition, i); + g_free(tfcp->event); + tfcp->event = NULL; + tfcp->used = FALSE; + } + g_array_free(pos->tfcp, TRUE); + g_free(pos); } void lttv_traceset_context_position_copy(LttvTracesetContextPosition *dest, - const LttvTracesetContextPosition *src) + const LttvTracesetContextPosition *src) { - int i; - LttvTracefileContextPosition *src_tfcp, *dest_tfcp; - - g_assert(src->tfcp->len == dest->tfcp->len); - - for(i=0;itfcp->len;i++) { - src_tfcp = - &g_array_index(src->tfcp, LttvTracefileContextPosition, i); - dest_tfcp = - &g_array_index(dest->tfcp, LttvTracefileContextPosition, i); - - dest_tfcp->used = src_tfcp->used; - dest_tfcp->tfc = src_tfcp->tfc; - - if(src_tfcp->used) { - ltt_event_position_copy( - dest_tfcp->event, - src_tfcp->event); - } - } - dest->timestamp = src->timestamp; + int i; + LttvTracefileContextPosition *src_tfcp, *dest_tfcp; + + g_assert(src->tfcp->len == dest->tfcp->len); + + for(i=0;itfcp->len;i++) { + src_tfcp = + &g_array_index(src->tfcp, LttvTracefileContextPosition, i); + dest_tfcp = + &g_array_index(dest->tfcp, LttvTracefileContextPosition, i); + + dest_tfcp->used = src_tfcp->used; + dest_tfcp->tfc = src_tfcp->tfc; + + if(src_tfcp->used) { + ltt_event_position_copy( + dest_tfcp->event, + src_tfcp->event); + } + } + dest->timestamp = src->timestamp; } gint lttv_traceset_context_ctx_pos_compare(const LttvTracesetContext *self, - const LttvTracesetContextPosition *pos) + const LttvTracesetContextPosition *pos) { - int i; - int ret = 0; - - if(pos->tfcp->len == 0) { - if(lttv_traceset_number(self->ts) == 0) return 0; - else return 1; - } - if(lttv_traceset_number(self->ts) == 0) - return -1; - - for(i=0;itfcp->len;i++) { - LttvTracefileContextPosition *tfcp = - &g_array_index(pos->tfcp, LttvTracefileContextPosition, i); - - if(tfcp->used == FALSE) { - if(ltt_time_compare(tfcp->tfc->timestamp, ltt_time_infinite) < 0) { - ret = -1; - } - } else { - if(ltt_time_compare(tfcp->tfc->timestamp, ltt_time_infinite) == 0) { - ret = 1; - } else { - LttEvent *event = ltt_tracefile_get_event(tfcp->tfc->tf); - - ret = ltt_event_position_compare((LttEventPosition*)event, - tfcp->event); - } - } - if(ret != 0) return ret; - - } - return 0; + int i; + int ret = 0; + + if(pos->tfcp->len == 0) { + if(lttv_traceset_number(self->ts) == 0) return 0; + else return 1; + } + if(lttv_traceset_number(self->ts) == 0) + return -1; + + for(i=0;itfcp->len;i++) { + LttvTracefileContextPosition *tfcp = + &g_array_index(pos->tfcp, LttvTracefileContextPosition, i); + + if(tfcp->used == FALSE) { + if(ltt_time_compare(tfcp->tfc->timestamp, ltt_time_infinite) < 0) { + ret = -1; + } + } else { + if(ltt_time_compare(tfcp->tfc->timestamp, ltt_time_infinite) == 0) { + ret = 1; + } else { + LttEvent *event = ltt_tracefile_get_event(tfcp->tfc->tf); + + ret = ltt_event_position_compare((LttEventPosition*)event, + tfcp->event); + } + } + if(ret != 0) return ret; + + } + return 0; } -gint lttv_traceset_context_pos_pos_compare( - const LttvTracesetContextPosition *pos1, - const LttvTracesetContextPosition *pos2) +gint +lttv_traceset_context_pos_pos_compare(const LttvTracesetContextPosition *pos1, + const LttvTracesetContextPosition *pos2) { - int i, j; - int ret = 0; - - if(ltt_time_compare(pos1->timestamp, ltt_time_infinite) == 0) { - if(ltt_time_compare(pos2->timestamp, ltt_time_infinite) == 0) - return 0; - else - return 1; - } - if(ltt_time_compare(pos2->timestamp, ltt_time_infinite) == 0) - return -1; - - for(i=0;itfcp->len;i++) { - LttvTracefileContextPosition *tfcp1 = - &g_array_index(pos1->tfcp, LttvTracefileContextPosition, i); - - if(tfcp1->used == TRUE) { - for(j=0;jtfcp->len;j++) { - LttvTracefileContextPosition *tfcp2 = - &g_array_index(pos2->tfcp, LttvTracefileContextPosition, j); - - if(tfcp1->tfc == tfcp2->tfc) { - if(tfcp2->used == TRUE) - ret = ltt_event_position_compare(tfcp1->event, tfcp2->event); - else - ret = -1; - - if(ret != 0) return ret; - } - } - - } else { - for(j=0;jtfcp->len;j++) { - LttvTracefileContextPosition *tfcp2 = - &g_array_index(pos2->tfcp, LttvTracefileContextPosition, j); - - if(tfcp1->tfc == tfcp2->tfc) - if(tfcp2->used == TRUE) ret = 1; - if(ret != 0) return ret; - } - } - } - return 0; + int i, j; + int ret = 0; + + if(ltt_time_compare(pos1->timestamp, ltt_time_infinite) == 0) { + if(ltt_time_compare(pos2->timestamp, ltt_time_infinite) == 0) + return 0; + else + return 1; + } + if(ltt_time_compare(pos2->timestamp, ltt_time_infinite) == 0) + return -1; + + for(i=0;itfcp->len;i++) { + LttvTracefileContextPosition *tfcp1 = + &g_array_index(pos1->tfcp, LttvTracefileContextPosition, i); + + if(tfcp1->used == TRUE) { + for(j=0;jtfcp->len;j++) { + LttvTracefileContextPosition *tfcp2 = + &g_array_index(pos2->tfcp, LttvTracefileContextPosition, j); + + if(tfcp1->tfc == tfcp2->tfc) { + if(tfcp2->used == TRUE) + ret = ltt_event_position_compare(tfcp1->event, tfcp2->event); + else + ret = -1; + + if(ret != 0) return ret; + } + } + + } else { + for(j=0;jtfcp->len;j++) { + LttvTracefileContextPosition *tfcp2 = + &g_array_index(pos2->tfcp, LttvTracefileContextPosition, j); + + if(tfcp1->tfc == tfcp2->tfc) + if(tfcp2->used == TRUE) ret = 1; + if(ret != 0) return ret; + } + } + } + return 0; } -LttTime lttv_traceset_context_position_get_time( - const LttvTracesetContextPosition *pos) +LttTime +lttv_traceset_context_position_get_time(const LttvTracesetContextPosition *pos) { - return pos->timestamp; + return pos->timestamp; } -LttvTracefileContext *lttv_traceset_context_get_current_tfc(LttvTracesetContext *self) +LttvTracefileContext * +lttv_traceset_context_get_current_tfc(LttvTracesetContext *self) { - GTree *pqueue = self->pqueue; - LttvTracefileContext *tfc = NULL; + GTree *pqueue = self->pqueue; + LttvTracefileContext *tfc = NULL; - g_tree_foreach(pqueue, get_first, &tfc); + g_tree_foreach(pqueue, get_first, &tfc); - return tfc; + return tfc; } /* lttv_process_traceset_synchronize_tracefiles @@ -1286,10 +1276,10 @@ LttvTracefileContext *lttv_traceset_context_get_current_tfc(LttvTracesetContext */ void lttv_process_traceset_synchronize_tracefiles(LttvTracesetContext *tsc) { - int retval; + int retval; - retval= lttv_process_traceset_seek_position(tsc, tsc->sync_position); - g_assert_cmpint(retval, ==, 0); + retval= lttv_process_traceset_seek_position(tsc, tsc->sync_position); + g_assert_cmpint(retval, ==, 0); } @@ -1297,72 +1287,72 @@ void lttv_process_traceset_synchronize_tracefiles(LttvTracesetContext *tsc) void lttv_process_traceset_get_sync_data(LttvTracesetContext *tsc) { - lttv_traceset_context_position_save(tsc, tsc->sync_position); + lttv_traceset_context_position_save(tsc, tsc->sync_position); } struct seek_back_data { - guint first_event; /* Index of the first event in the array : we will always - overwrite at this position : this is a circular array. - */ - guint events_found; - guint n; /* number of events requested */ - GPtrArray *array; /* array of LttvTracesetContextPositions pointers */ - LttvFilter *filter1; - LttvFilter *filter2; - LttvFilter *filter3; - gpointer data; - check_handler *check; - gboolean *stop_flag; - guint raw_event_count; + guint first_event; /* Index of the first event in the array : we will always + overwrite at this position : this is a circular array. + */ + guint events_found; + guint n; /* number of events requested */ + GPtrArray *array; /* array of LttvTracesetContextPositions pointers */ + LttvFilter *filter1; + LttvFilter *filter2; + LttvFilter *filter3; + gpointer data; + check_handler *check; + gboolean *stop_flag; + guint raw_event_count; }; static gint seek_back_event_hook(void *hook_data, void* call_data) { - struct seek_back_data *sd = (struct seek_back_data*)hook_data; - LttvTracefileContext *tfc = (LttvTracefileContext*)call_data; - LttvTracesetContext *tsc = tfc->t_context->ts_context; - LttvTracesetContextPosition *pos; - - if(sd->check && sd->check(sd->raw_event_count, sd->stop_flag, sd->data)) - return TRUE; - sd->raw_event_count++; - - if(sd->filter1 != NULL && sd->filter1->head != NULL && - !lttv_filter_tree_parse(sd->filter1->head, - ltt_tracefile_get_event(tfc->tf), - tfc->tf, - tfc->t_context->t, - tfc,NULL,NULL)) { - return FALSE; - } - if(sd->filter2 != NULL && sd->filter2->head != NULL && - !lttv_filter_tree_parse(sd->filter2->head, - ltt_tracefile_get_event(tfc->tf), - tfc->tf, - tfc->t_context->t, - tfc,NULL,NULL)) { - return FALSE; - } - if(sd->filter3 != NULL && sd->filter3->head != NULL && - !lttv_filter_tree_parse(sd->filter3->head, - ltt_tracefile_get_event(tfc->tf), - tfc->tf, - tfc->t_context->t, - tfc,NULL,NULL)) { - return FALSE; - } - - pos = (LttvTracesetContextPosition*)g_ptr_array_index (sd->array, - sd->first_event); - - lttv_traceset_context_position_save(tsc, pos); - - if(sd->first_event >= sd->array->len - 1) sd->first_event = 0; - else sd->first_event++; - - sd->events_found = min(sd->n, sd->events_found + 1); - - return FALSE; + struct seek_back_data *sd = (struct seek_back_data*)hook_data; + LttvTracefileContext *tfc = (LttvTracefileContext*)call_data; + LttvTracesetContext *tsc = tfc->t_context->ts_context; + LttvTracesetContextPosition *pos; + + if(sd->check && sd->check(sd->raw_event_count, sd->stop_flag, sd->data)) + return TRUE; + sd->raw_event_count++; + + if(sd->filter1 != NULL && sd->filter1->head != NULL && + !lttv_filter_tree_parse(sd->filter1->head, + ltt_tracefile_get_event(tfc->tf), + tfc->tf, + tfc->t_context->t, + tfc,NULL,NULL)) { + return FALSE; + } + if(sd->filter2 != NULL && sd->filter2->head != NULL && + !lttv_filter_tree_parse(sd->filter2->head, + ltt_tracefile_get_event(tfc->tf), + tfc->tf, + tfc->t_context->t, + tfc,NULL,NULL)) { + return FALSE; + } + if(sd->filter3 != NULL && sd->filter3->head != NULL && + !lttv_filter_tree_parse(sd->filter3->head, + ltt_tracefile_get_event(tfc->tf), + tfc->tf, + tfc->t_context->t, + tfc,NULL,NULL)) { + return FALSE; + } + + pos = (LttvTracesetContextPosition*)g_ptr_array_index (sd->array, + sd->first_event); + + lttv_traceset_context_position_save(tsc, pos); + + if(sd->first_event >= sd->array->len - 1) sd->first_event = 0; + else sd->first_event++; + + sd->events_found = min(sd->n, sd->events_found + 1); + + return FALSE; } /* Seek back n events back from the current position. @@ -1392,207 +1382,207 @@ static gint seek_back_event_hook(void *hook_data, void* call_data) * contain any hook, as process_traceset_middle is used in this routine. */ guint lttv_process_traceset_seek_n_backward(LttvTracesetContext *self, - guint n, LttTime first_offset, - seek_time_fct time_seeker, - check_handler *check, - gboolean *stop_flag, - LttvFilter *filter1, - LttvFilter *filter2, - LttvFilter *filter3, - gpointer data) + guint n, LttTime first_offset, + seek_time_fct time_seeker, + check_handler *check, + gboolean *stop_flag, + LttvFilter *filter1, + LttvFilter *filter2, + LttvFilter *filter3, + gpointer data) { - if(lttv_traceset_number(self->ts) == 0) return 0; - g_assert(ltt_time_compare(first_offset, ltt_time_zero) != 0); - - guint i; - LttvTracesetContextPosition *next_iter_end_pos = - lttv_traceset_context_position_new(self); - LttvTracesetContextPosition *end_pos = - lttv_traceset_context_position_new(self); - LttvTracesetContextPosition *saved_pos = - lttv_traceset_context_position_new(self); - LttTime time; - LttTime asked_time; - LttTime time_offset; - struct seek_back_data sd; - LttvHooks *hooks = lttv_hooks_new(); - int retval; - - sd.first_event = 0; - sd.events_found = 0; - sd.array = g_ptr_array_sized_new(n); - sd.filter1 = filter1; - sd.filter2 = filter2; - sd.filter3 = filter3; - sd.data = data; - sd.n = n; - sd.check = check; - sd.stop_flag = stop_flag; - sd.raw_event_count = 0; - g_ptr_array_set_size(sd.array, n); - for(i=0;its) == 0) return 0; + g_assert(ltt_time_compare(first_offset, ltt_time_zero) != 0); + + guint i; + LttvTracesetContextPosition *next_iter_end_pos = + lttv_traceset_context_position_new(self); + LttvTracesetContextPosition *end_pos = + lttv_traceset_context_position_new(self); + LttvTracesetContextPosition *saved_pos = + lttv_traceset_context_position_new(self); + LttTime time; + LttTime asked_time; + LttTime time_offset; + struct seek_back_data sd; + LttvHooks *hooks = lttv_hooks_new(); + int retval; + + sd.first_event = 0; + sd.events_found = 0; + sd.array = g_ptr_array_sized_new(n); + sd.filter1 = filter1; + sd.filter2 = filter2; + sd.filter3 = filter3; + sd.data = data; + sd.n = n; + sd.check = check; + sd.stop_flag = stop_flag; + sd.raw_event_count = 0; + g_ptr_array_set_size(sd.array, n); + for(i=0;itime_span.end_time) > 0) { - time = self->time_span.end_time; - } - time_offset = first_offset; + lttv_traceset_context_position_save(self, next_iter_end_pos); + lttv_traceset_context_position_save(self, saved_pos); + /* Get the current time from which we will offset */ + time = lttv_traceset_context_position_get_time(next_iter_end_pos); + /* the position saved might be end of traceset... */ + if(ltt_time_compare(time, self->time_span.end_time) > 0) { + time = self->time_span.end_time; + } + time_offset = first_offset; - lttv_hooks_add(hooks, seek_back_event_hook, &sd, LTTV_PRIO_DEFAULT); - - lttv_process_traceset_begin(self, NULL, NULL, NULL, hooks, NULL); - - while(1) { - lttv_traceset_context_position_copy(end_pos, next_iter_end_pos); - - /* We must seek the traceset back to time - time_offset */ - /* this time becomes the new reference time */ - if(ltt_time_compare(time, time_offset) > 0) - time = ltt_time_sub(time, time_offset); - else - time = self->time_span.start_time; - asked_time = time; - - time_seeker(self, time); - lttv_traceset_context_position_save(self, next_iter_end_pos); - /* Resync the time in case of a seek_closest */ - time = lttv_traceset_context_position_get_time(next_iter_end_pos); - if(ltt_time_compare(time, self->time_span.end_time) > 0) { - time = self->time_span.end_time; - } - - /* Process the traceset, calling a hook which adds events - * to the array, overwriting the tail. It changes first_event and - * events_found too. */ - /* We would like to have a clean context here : no other hook than our's */ - - lttv_process_traceset_middle(self, ltt_time_infinite, - G_MAXUINT, end_pos); - - /* stop criteria : - n events found - * - asked_time < beginning of trace */ - if(sd.events_found < n) { - if(sd.first_event > 0) { - /* Save the first position */ - LttvTracesetContextPosition *pos = - (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, 0); - lttv_traceset_context_position_copy(saved_pos, pos); - } - g_assert(n-sd.events_found <= sd.array->len); - /* Change array size to n - events_found */ - for(i=n-sd.events_found;ilen;i++) { - LttvTracesetContextPosition *pos = - (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, i); - lttv_traceset_context_position_destroy(pos); - } - g_ptr_array_set_size(sd.array, n-sd.events_found); - sd.first_event = 0; - - /* - * Did not fill our event list and started before the beginning of the - * trace. There is no hope to fill it then. - * It is OK to compare with trace start time here because we explicitely - * seeked by time (not by position), so we cannot miss multiple event - * happening exactly at trace start. - */ - if(ltt_time_compare(asked_time, self->time_span.start_time) == 0) - break; - - } else break; /* Second end criterion : n events found */ - - time_offset = ltt_time_mul(time_offset, BACKWARD_SEEK_MUL); - } - - lttv_traceset_context_position_destroy(end_pos); - lttv_traceset_context_position_destroy(next_iter_end_pos); - - lttv_process_traceset_end(self, NULL, NULL, NULL, hooks, NULL); - - if(sd.events_found >= n) { - /* Seek the traceset to the first event in the circular array */ - LttvTracesetContextPosition *pos = - (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, - sd.first_event); - retval= lttv_process_traceset_seek_position(self, pos); - g_assert_cmpint(retval, ==, 0); - } else { - /* Will seek to the last saved position : in the worst case, it will be the - * original position (if events_found is 0) */ - retval= lttv_process_traceset_seek_position(self, saved_pos); - g_assert_cmpint(retval, ==, 0); - } - - for(i=0;ilen;i++) { - LttvTracesetContextPosition *pos = - (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, i); - lttv_traceset_context_position_destroy(pos); - } - g_ptr_array_free(sd.array, TRUE); - - lttv_hooks_destroy(hooks); - - lttv_traceset_context_position_destroy(saved_pos); - - return sd.events_found; + lttv_hooks_add(hooks, seek_back_event_hook, &sd, LTTV_PRIO_DEFAULT); + + lttv_process_traceset_begin(self, NULL, NULL, NULL, hooks, NULL); + + while(1) { + lttv_traceset_context_position_copy(end_pos, next_iter_end_pos); + + /* We must seek the traceset back to time - time_offset */ + /* this time becomes the new reference time */ + if(ltt_time_compare(time, time_offset) > 0) + time = ltt_time_sub(time, time_offset); + else + time = self->time_span.start_time; + asked_time = time; + + time_seeker(self, time); + lttv_traceset_context_position_save(self, next_iter_end_pos); + /* Resync the time in case of a seek_closest */ + time = lttv_traceset_context_position_get_time(next_iter_end_pos); + if(ltt_time_compare(time, self->time_span.end_time) > 0) { + time = self->time_span.end_time; + } + + /* Process the traceset, calling a hook which adds events + * to the array, overwriting the tail. It changes first_event and + * events_found too. */ + /* We would like to have a clean context here : no other hook than our's */ + + lttv_process_traceset_middle(self, ltt_time_infinite, + G_MAXUINT, end_pos); + + /* stop criteria : - n events found + * - asked_time < beginning of trace */ + if(sd.events_found < n) { + if(sd.first_event > 0) { + /* Save the first position */ + LttvTracesetContextPosition *pos = + (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, 0); + lttv_traceset_context_position_copy(saved_pos, pos); + } + g_assert(n-sd.events_found <= sd.array->len); + /* Change array size to n - events_found */ + for(i=n-sd.events_found;ilen;i++) { + LttvTracesetContextPosition *pos = + (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, i); + lttv_traceset_context_position_destroy(pos); + } + g_ptr_array_set_size(sd.array, n-sd.events_found); + sd.first_event = 0; + + /* + * Did not fill our event list and started before the beginning of the + * trace. There is no hope to fill it then. + * It is OK to compare with trace start time here because we explicitely + * seeked by time (not by position), so we cannot miss multiple event + * happening exactly at trace start. + */ + if(ltt_time_compare(asked_time, self->time_span.start_time) == 0) + break; + + } else break; /* Second end criterion : n events found */ + + time_offset = ltt_time_mul(time_offset, BACKWARD_SEEK_MUL); + } + + lttv_traceset_context_position_destroy(end_pos); + lttv_traceset_context_position_destroy(next_iter_end_pos); + + lttv_process_traceset_end(self, NULL, NULL, NULL, hooks, NULL); + + if(sd.events_found >= n) { + /* Seek the traceset to the first event in the circular array */ + LttvTracesetContextPosition *pos = + (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, + sd.first_event); + retval= lttv_process_traceset_seek_position(self, pos); + g_assert_cmpint(retval, ==, 0); + } else { + /* Will seek to the last saved position : in the worst case, it will be the + * original position (if events_found is 0) */ + retval= lttv_process_traceset_seek_position(self, saved_pos); + g_assert_cmpint(retval, ==, 0); + } + + for(i=0;ilen;i++) { + LttvTracesetContextPosition *pos = + (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, i); + lttv_traceset_context_position_destroy(pos); + } + g_ptr_array_free(sd.array, TRUE); + + lttv_hooks_destroy(hooks); + + lttv_traceset_context_position_destroy(saved_pos); + + return sd.events_found; } struct seek_forward_data { - guint event_count; /* event counter */ - guint n; /* requested number of events to jump over */ - LttvFilter *filter1; - LttvFilter *filter2; - LttvFilter *filter3; - gpointer data; - check_handler *check; - gboolean *stop_flag; - guint raw_event_count; /* event counter */ + guint event_count; /* event counter */ + guint n; /* requested number of events to jump over */ + LttvFilter *filter1; + LttvFilter *filter2; + LttvFilter *filter3; + gpointer data; + check_handler *check; + gboolean *stop_flag; + guint raw_event_count; /* event counter */ }; static gint seek_forward_event_hook(void *hook_data, void* call_data) { - struct seek_forward_data *sd = (struct seek_forward_data*)hook_data; - LttvTracefileContext *tfc = (LttvTracefileContext*)call_data; - - if(sd->check && sd->check(sd->raw_event_count, sd->stop_flag, sd->data)) - return TRUE; - sd->raw_event_count++; - - if(sd->filter1 != NULL && sd->filter1->head != NULL && - !lttv_filter_tree_parse(sd->filter1->head, - ltt_tracefile_get_event(tfc->tf), - tfc->tf, - tfc->t_context->t, - tfc,NULL,NULL)) { - return FALSE; - } - if(sd->filter2 != NULL && sd->filter2->head != NULL && - !lttv_filter_tree_parse(sd->filter2->head, - ltt_tracefile_get_event(tfc->tf), - tfc->tf, - tfc->t_context->t, - tfc,NULL,NULL)) { - return FALSE; - } - if(sd->filter3 != NULL && sd->filter3->head != NULL && - !lttv_filter_tree_parse(sd->filter3->head, - ltt_tracefile_get_event(tfc->tf), - tfc->tf, - tfc->t_context->t, - tfc,NULL,NULL)) { - return FALSE; - } - - sd->event_count++; - if(sd->event_count >= sd->n) - return TRUE; - return FALSE; + struct seek_forward_data *sd = (struct seek_forward_data*)hook_data; + LttvTracefileContext *tfc = (LttvTracefileContext*)call_data; + + if(sd->check && sd->check(sd->raw_event_count, sd->stop_flag, sd->data)) + return TRUE; + sd->raw_event_count++; + + if(sd->filter1 != NULL && sd->filter1->head != NULL && + !lttv_filter_tree_parse(sd->filter1->head, + ltt_tracefile_get_event(tfc->tf), + tfc->tf, + tfc->t_context->t, + tfc,NULL,NULL)) { + return FALSE; + } + if(sd->filter2 != NULL && sd->filter2->head != NULL && + !lttv_filter_tree_parse(sd->filter2->head, + ltt_tracefile_get_event(tfc->tf), + tfc->tf, + tfc->t_context->t, + tfc,NULL,NULL)) { + return FALSE; + } + if(sd->filter3 != NULL && sd->filter3->head != NULL && + !lttv_filter_tree_parse(sd->filter3->head, + ltt_tracefile_get_event(tfc->tf), + tfc->tf, + tfc->t_context->t, + tfc,NULL,NULL)) { + return FALSE; + } + + sd->event_count++; + if(sd->event_count >= sd->n) + return TRUE; + return FALSE; } /* Seek back n events forward from the current position (1 to n) @@ -1606,49 +1596,49 @@ static gint seek_forward_event_hook(void *hook_data, void* call_data) * returns : the number of events jumped over (may be less than requested if end * of traceset reached) */ guint lttv_process_traceset_seek_n_forward(LttvTracesetContext *self, - guint n, - check_handler *check, - gboolean *stop_flag, - LttvFilter *filter1, - LttvFilter *filter2, - LttvFilter *filter3, - gpointer data) + guint n, + check_handler *check, + gboolean *stop_flag, + LttvFilter *filter1, + LttvFilter *filter2, + LttvFilter *filter3, + gpointer data) { - struct seek_forward_data sd; - sd.event_count = 0; - sd.n = n; - sd.filter1 = filter1; - sd.filter2 = filter2; - sd.filter3 = filter3; - sd.data = data; - sd.check = check; - sd.stop_flag = stop_flag; - sd.raw_event_count = 0; - - if(sd.event_count >= sd.n) return sd.event_count; - - LttvHooks *hooks = lttv_hooks_new(); - - lttv_hooks_add(hooks, seek_forward_event_hook, &sd, LTTV_PRIO_DEFAULT); - - lttv_process_traceset_begin(self, NULL, NULL, NULL, hooks, NULL); - - /* it will end on the end of traceset, or the fact that the - * hook returns TRUE. - */ - lttv_process_traceset_middle(self, ltt_time_infinite, - G_MAXUINT, NULL); - - /* Here, our position is either the end of traceset, or the exact position - * after n events : leave it like this. This might be placed on an event that - * will be filtered out, we don't care : all we know is that the following - * event filtered in will be the right one. */ - - lttv_process_traceset_end(self, NULL, NULL, NULL, hooks, NULL); - - lttv_hooks_destroy(hooks); - - return sd.event_count; + struct seek_forward_data sd; + sd.event_count = 0; + sd.n = n; + sd.filter1 = filter1; + sd.filter2 = filter2; + sd.filter3 = filter3; + sd.data = data; + sd.check = check; + sd.stop_flag = stop_flag; + sd.raw_event_count = 0; + + if(sd.event_count >= sd.n) return sd.event_count; + + LttvHooks *hooks = lttv_hooks_new(); + + lttv_hooks_add(hooks, seek_forward_event_hook, &sd, LTTV_PRIO_DEFAULT); + + lttv_process_traceset_begin(self, NULL, NULL, NULL, hooks, NULL); + + /* it will end on the end of traceset, or the fact that the + * hook returns TRUE. + */ + lttv_process_traceset_middle(self, ltt_time_infinite, + G_MAXUINT, NULL); + + /* Here, our position is either the end of traceset, or the exact position + * after n events : leave it like this. This might be placed on an event that + * will be filtered out, we don't care : all we know is that the following + * event filtered in will be the right one. */ + + lttv_process_traceset_end(self, NULL, NULL, NULL, hooks, NULL); + + lttv_hooks_destroy(hooks); + + return sd.event_count; } diff --git a/lttv/lttv/tracecontext.h b/lttv/lttv/tracecontext.h index 49952d77..acedeea6 100644 --- a/lttv/lttv/tracecontext.h +++ b/lttv/lttv/tracecontext.h @@ -92,27 +92,27 @@ typedef struct _LttvFilter LttvFilter; #define LTTV_TRACESET_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACESET_CONTEXT_TYPE, LttvTracesetContextClass)) struct _LttvTracesetContext { - GObject parent; + GObject parent; - LttvTraceset *ts; - LttvTraceContext **traces; - LttvAttribute *a; - LttvAttribute *ts_a; - TimeInterval time_span; - GTree *pqueue; + LttvTraceset *ts; + LttvTraceContext **traces; + LttvAttribute *a; + LttvAttribute *ts_a; + TimeInterval time_span; + GTree *pqueue; - LttvTracesetContextPosition *sync_position; /* position at which to sync the - trace context */ + LttvTracesetContextPosition *sync_position; /* position at which to sync the + trace context */ }; struct _LttvTracesetContextClass { - GObjectClass parent; + GObjectClass parent; - void (*init) (LttvTracesetContext *self, LttvTraceset *ts); - void (*fini) (LttvTracesetContext *self); - LttvTracesetContext* (*new_traceset_context) (LttvTracesetContext *self); - LttvTraceContext* (*new_trace_context) (LttvTracesetContext *self); - LttvTracefileContext* (*new_tracefile_context) (LttvTracesetContext *self); + void (*init) (LttvTracesetContext *self, LttvTraceset *ts); + void (*fini) (LttvTracesetContext *self); + LttvTracesetContext* (*new_traceset_context) (LttvTracesetContext *self); + LttvTraceContext* (*new_trace_context) (LttvTracesetContext *self); + LttvTracefileContext* (*new_tracefile_context) (LttvTracesetContext *self); }; GType lttv_traceset_context_get_type (void); @@ -124,7 +124,7 @@ void lttv_context_fini(LttvTracesetContext *self); LttvTracesetContext * lttv_context_new_traceset_context(LttvTracesetContext *self); -LttvTraceContext * +LttvTraceContext * lttv_context_new_trace_context(LttvTracesetContext *self); LttvTracefileContext * @@ -139,21 +139,21 @@ lttv_context_new_tracefile_context(LttvTracesetContext *self); #define LTTV_TRACE_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContextClass)) struct _LttvTraceContext { - GObject parent; - - LttvTracesetContext *ts_context; - guint index; /* in ts_context->traces */ - LttTrace *t; - LttvTrace *vt; - //LttvTracefileContext **tracefiles; - GArray *tracefiles; - LttvAttribute *a; - LttvAttribute *t_a; - TimeInterval time_span; + GObject parent; + + LttvTracesetContext *ts_context; + guint index; /* in ts_context->traces */ + LttTrace *t; + LttvTrace *vt; + //LttvTracefileContext **tracefiles; + GArray *tracefiles; + LttvAttribute *a; + LttvAttribute *t_a; + TimeInterval time_span; }; struct _LttvTraceContextClass { - GObjectClass parent; + GObjectClass parent; }; GType lttv_trace_context_get_type (void); @@ -166,33 +166,33 @@ GType lttv_trace_context_get_type (void); #define LTTV_TRACEFILE_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContextClass)) struct _LttvTracefileContext { - GObject parent; + GObject parent; - LttvTraceContext *t_context; + LttvTraceContext *t_context; // gboolean control; - guint index; /* in ts_context->tracefiles */ - LttTracefile *tf; + guint index; /* in ts_context->tracefiles */ + LttTracefile *tf; // LttEvent *e; - LttvHooks *event; - LttvHooksById *event_by_id; - LttTime timestamp; - LttvAttribute *a; - gint target_pid; /* Target PID of the event. + LttvHooks *event; + LttvHooksById *event_by_id; + LttTime timestamp; + LttvAttribute *a; + gint target_pid; /* Target PID of the event. Updated by state.c. -1 means unset. */ }; struct _LttvTracefileContextClass { - GObjectClass parent; + GObjectClass parent; }; GType lttv_tracefile_context_get_type (void); /* Run through the events in a traceset in sorted order calling all the - hooks appropriately. It starts at the current time and runs until end or - nb_events are processed. */ + hooks appropriately. It starts at the current time and runs until end or + nb_events are processed. */ void lttv_process_traceset(LttvTracesetContext *self, LttTime end, - unsigned nb_events); + unsigned nb_events); /* Process traceset can also be done in smaller pieces calling begin, * then seek and middle repeatedly, and end. The middle function return the @@ -201,80 +201,80 @@ void lttv_process_traceset(LttvTracesetContext *self, LttTime end, void lttv_process_traceset_begin(LttvTracesetContext *self, - LttvHooks *before_traceset, - LttvHooks *before_trace, - LttvHooks *before_tracefile, - LttvHooks *event, - LttvHooksByIdChannelArray *event_by_id_channel); + LttvHooks *before_traceset, + LttvHooks *before_trace, + LttvHooks *before_tracefile, + LttvHooks *event, + LttvHooksByIdChannelArray *event_by_id_channel); guint lttv_process_traceset_middle(LttvTracesetContext *self, - LttTime end, - gulong nb_events, - const LttvTracesetContextPosition *end_position); + LttTime end, + gulong nb_events, + const LttvTracesetContextPosition *end_position); void lttv_process_traceset_end(LttvTracesetContext *self, - LttvHooks *after_traceset, - LttvHooks *after_trace, - LttvHooks *after_tracefile, - LttvHooks *event, - LttvHooksByIdChannelArray *event_by_id_channel); + LttvHooks *after_traceset, + LttvHooks *after_trace, + LttvHooks *after_tracefile, + LttvHooks *event, + LttvHooksByIdChannelArray *event_by_id_channel); void lttv_process_traceset_seek_time(LttvTracesetContext *self, LttTime start); void lttv_traceset_context_compute_time_span(LttvTracesetContext *self, - TimeInterval *time_span); + TimeInterval *time_span); gboolean lttv_process_traceset_seek_position(LttvTracesetContext *self, - const LttvTracesetContextPosition *pos); + const LttvTracesetContextPosition *pos); void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start); void lttv_traceset_context_add_hooks(LttvTracesetContext *self, - LttvHooks *before_traceset, - LttvHooks *before_trace, - LttvHooks *before_tracefile, - LttvHooks *event, - LttvHooksByIdChannelArray *event_by_id_channel); + LttvHooks *before_traceset, + LttvHooks *before_trace, + LttvHooks *before_tracefile, + LttvHooks *event, + LttvHooksByIdChannelArray *event_by_id_channel); void lttv_traceset_context_remove_hooks(LttvTracesetContext *self, - LttvHooks *after_traceset, - LttvHooks *after_trace, - LttvHooks *after_tracefile, - LttvHooks *event, - LttvHooksByIdChannelArray *event_by_id_channel); + LttvHooks *after_traceset, + LttvHooks *after_trace, + LttvHooks *after_tracefile, + LttvHooks *event, + LttvHooksByIdChannelArray *event_by_id_channel); void lttv_trace_context_add_hooks(LttvTraceContext *self, - LttvHooks *before_trace, - LttvHooks *before_tracefile, - LttvHooks *event, - LttvHooksByIdChannelArray *event_by_id_channel); + LttvHooks *before_trace, + LttvHooks *before_tracefile, + LttvHooks *event, + LttvHooksByIdChannelArray *event_by_id_channel); void lttv_trace_context_remove_hooks(LttvTraceContext *self, - LttvHooks *after_trace, - LttvHooks *after_tracefile, - LttvHooks *event, - LttvHooksByIdChannelArray *event_by_id_channel); + LttvHooks *after_trace, + LttvHooks *after_tracefile, + LttvHooks *event, + LttvHooksByIdChannelArray *event_by_id_channel); void lttv_tracefile_context_add_hooks(LttvTracefileContext *self, - LttvHooks *before_tracefile, - LttvHooks *event, - LttvHooksById *event_by_id); + LttvHooks *before_tracefile, + LttvHooks *event, + LttvHooksById *event_by_id); void lttv_tracefile_context_remove_hooks(LttvTracefileContext *self, - LttvHooks *after_tracefile, - LttvHooks *event, - LttvHooksById *event_by_id); + LttvHooks *after_tracefile, + LttvHooks *event, + LttvHooksById *event_by_id); typedef struct _LttvTraceHook { - LttvHook h; - struct marker_data *mdata; - GQuark channel; - guint16 id; /* id of the marker associated with this hook */ - GPtrArray *fields; /* struct marker_fields pointers */ - gpointer hook_data; + LttvHook h; + struct marker_data *mdata; + GQuark channel; + guint16 id; /* id of the marker associated with this hook */ + GPtrArray *fields; /* struct marker_fields pointers */ + gpointer hook_data; } LttvTraceHook; /* Get the head of marker list corresponding to the given trace hook. @@ -297,7 +297,8 @@ void lttv_trace_hook_remove_all(GArray **th); */ int lttv_trace_find_hook(LttTrace *t, GQuark facility_name, GQuark event_name, - GQuark fields[], LttvHook h, gpointer hook_data, GArray **trace_hooks); + GQuark fields[], LttvHook h, gpointer hook_data, + GArray **trace_hooks); static inline struct marker_field * lttv_trace_get_hook_field(LttvTraceHook *hook, unsigned int index) @@ -308,46 +309,46 @@ lttv_trace_get_hook_field(LttvTraceHook *hook, unsigned int index) #if 0 static inline GQuark lttv_merge_facility_event_name(GQuark fac, GQuark ev) { - char *tmp; - const char *sfac, *sev; - GQuark ret; - - sfac = g_quark_to_string(fac); - sev = g_quark_to_string(ev); - tmp = g_new(char, strlen(sfac) + strlen(sev) + 3); /* 3: _ \0 \0 */ - strcpy(tmp, sfac); - strcat(tmp, "_"); - strcat(tmp, sev); - ret = g_quark_from_string(tmp); - g_free(tmp); - return ret; + char *tmp; + const char *sfac, *sev; + GQuark ret; + + sfac = g_quark_to_string(fac); + sev = g_quark_to_string(ev); + tmp = g_new(char, strlen(sfac) + strlen(sev) + 3); /* 3: _ \0 \0 */ + strcpy(tmp, sfac); + strcat(tmp, "_"); + strcat(tmp, sev); + ret = g_quark_from_string(tmp); + g_free(tmp); + return ret; } #endif //0 -LttvTracefileContext *lttv_traceset_context_get_current_tfc( - LttvTracesetContext *self); +LttvTracefileContext * +lttv_traceset_context_get_current_tfc(LttvTracesetContext *self); -LttvTracesetContextPosition *lttv_traceset_context_position_new( - const LttvTracesetContext *self); +LttvTracesetContextPosition * +lttv_traceset_context_position_new(const LttvTracesetContext *self); void lttv_traceset_context_position_save(const LttvTracesetContext *self, - LttvTracesetContextPosition *pos); + LttvTracesetContextPosition *pos); void lttv_traceset_context_position_destroy(LttvTracesetContextPosition *pos); void lttv_traceset_context_position_copy(LttvTracesetContextPosition *dest, - const LttvTracesetContextPosition *src); + const LttvTracesetContextPosition *src); -gint lttv_traceset_context_pos_pos_compare( - const LttvTracesetContextPosition *pos1, - const LttvTracesetContextPosition *pos2); +gint +lttv_traceset_context_pos_pos_compare(const LttvTracesetContextPosition *pos1, + const LttvTracesetContextPosition *pos2); gint lttv_traceset_context_ctx_pos_compare(const LttvTracesetContext *self, - const LttvTracesetContextPosition *pos2); + const LttvTracesetContextPosition *pos2); -LttTime lttv_traceset_context_position_get_time( - const LttvTracesetContextPosition *pos); +LttTime +lttv_traceset_context_position_get_time(const LttvTracesetContextPosition *pos); gint compare_tracefile(gconstpointer a, gconstpointer b); @@ -369,26 +370,27 @@ static const LttTime seek_back_default_offset = { 1, 0 }; typedef gboolean check_handler(guint count, gboolean *stop_flag, gpointer data); guint lttv_process_traceset_seek_n_forward(LttvTracesetContext *self, - guint n, - check_handler *check, - gboolean *stop_flag, - LttvFilter *filter1, - LttvFilter *filter2, - LttvFilter *filter3, - gpointer data); + guint n, + check_handler *check, + gboolean *stop_flag, + LttvFilter *filter1, + LttvFilter *filter2, + LttvFilter *filter3, + gpointer data); + typedef void (*seek_time_fct)(LttvTracesetContext *self, LttTime start); /* If first_offset is ltt_time_zero, it will choose a default value */ guint lttv_process_traceset_seek_n_backward(LttvTracesetContext *self, - guint n, - LttTime first_offset, - seek_time_fct, - check_handler *check, - gboolean *stop_flag, - LttvFilter *filter1, - LttvFilter *filter2, - LttvFilter *filter3, - gpointer data); + guint n, + LttTime first_offset, + seek_time_fct, + check_handler *check, + gboolean *stop_flag, + LttvFilter *filter1, + LttvFilter *filter2, + LttvFilter *filter3, + gpointer data); #define FIELD_ARRAY(val...) ((GQuark[]){ val, 0 }) diff --git a/lttv/lttv/traceset.c b/lttv/lttv/traceset.c index 181bdd53..45d63143 100644 --- a/lttv/lttv/traceset.c +++ b/lttv/lttv/traceset.c @@ -31,184 +31,183 @@ */ struct _LttvTraceset { - char * filename; - GPtrArray *traces; - LttvAttribute *a; + char * filename; + GPtrArray *traces; + LttvAttribute *a; }; struct _LttvTrace { - LttTrace *t; - LttvAttribute *a; - guint ref_count; + LttTrace *t; + LttvAttribute *a; + guint ref_count; }; LttvTraceset *lttv_traceset_new() { - LttvTraceset *s; + LttvTraceset *s; - s = g_new(LttvTraceset, 1); - s->filename = NULL; - s->traces = g_ptr_array_new(); - s->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); - return s; + s = g_new(LttvTraceset, 1); + s->filename = NULL; + s->traces = g_ptr_array_new(); + s->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); + return s; } char * lttv_traceset_name(LttvTraceset * s) { - return s->filename; + return s->filename; } LttvTrace *lttv_trace_new(LttTrace *t) { - LttvTrace *new_trace; + LttvTrace *new_trace; - new_trace = g_new(LttvTrace, 1); - new_trace->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); - new_trace->t = t; - new_trace->ref_count = 0; - return new_trace; + new_trace = g_new(LttvTrace, 1); + new_trace->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); + new_trace->t = t; + new_trace->ref_count = 0; + return new_trace; } LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig) { - guint i; - LttvTraceset *s; - LttvTrace * trace; + guint i; + LttvTraceset *s; + LttvTrace * trace; - s = g_new(LttvTraceset, 1); - s->filename = NULL; - s->traces = g_ptr_array_new(); - for(i=0;itraces->len;i++) - { - trace = g_ptr_array_index(s_orig->traces, i); - trace->ref_count++; + s = g_new(LttvTraceset, 1); + s->filename = NULL; + s->traces = g_ptr_array_new(); + for(i=0;itraces->len;i++) + { + trace = g_ptr_array_index(s_orig->traces, i); + trace->ref_count++; - g_ptr_array_add(s->traces, - trace); - } - s->a = LTTV_ATTRIBUTE(lttv_iattribute_deep_copy(LTTV_IATTRIBUTE(s_orig->a))); - return s; + g_ptr_array_add(s->traces, trace); + } + s->a = LTTV_ATTRIBUTE(lttv_iattribute_deep_copy(LTTV_IATTRIBUTE(s_orig->a))); + return s; } LttvTraceset *lttv_traceset_load(const gchar *filename) { - LttvTraceset *s = g_new(LttvTraceset,1); - FILE *tf; - - s->filename = g_strdup(filename); - tf = fopen(filename,"r"); + LttvTraceset *s = g_new(LttvTraceset,1); + FILE *tf; - g_critical("NOT IMPLEMENTED : load traceset data from a XML file"); - - fclose(tf); - return s; + s->filename = g_strdup(filename); + tf = fopen(filename,"r"); + + g_critical("NOT IMPLEMENTED : load traceset data from a XML file"); + + fclose(tf); + return s; } gint lttv_traceset_save(LttvTraceset *s) { - FILE *tf; + FILE *tf; - tf = fopen(s->filename, "w"); - - g_critical("NOT IMPLEMENTED : save traceset data in a XML file"); + tf = fopen(s->filename, "w"); - fclose(tf); - return 0; + g_critical("NOT IMPLEMENTED : save traceset data in a XML file"); + + fclose(tf); + return 0; } void lttv_traceset_destroy(LttvTraceset *s) { - guint i; + guint i; - for(i=0;itraces->len;i++) { - LttvTrace *trace = g_ptr_array_index(s->traces, i); - lttv_trace_unref(trace); - if(lttv_trace_get_ref_number(trace) == 0) - lttv_trace_destroy(trace); - } - g_ptr_array_free(s->traces, TRUE); - g_object_unref(s->a); - g_free(s); + for(i=0;itraces->len;i++) { + LttvTrace *trace = g_ptr_array_index(s->traces, i); + lttv_trace_unref(trace); + if(lttv_trace_get_ref_number(trace) == 0) + lttv_trace_destroy(trace); + } + g_ptr_array_free(s->traces, TRUE); + g_object_unref(s->a); + g_free(s); } void lttv_trace_destroy(LttvTrace *t) { - g_object_unref(t->a); - g_free(t); + g_object_unref(t->a); + g_free(t); } void lttv_traceset_add(LttvTraceset *s, LttvTrace *t) { - t->ref_count++; - g_ptr_array_add(s->traces, t); + t->ref_count++; + g_ptr_array_add(s->traces, t); } unsigned lttv_traceset_number(LttvTraceset *s) { - return s->traces->len; + return s->traces->len; } LttvTrace *lttv_traceset_get(LttvTraceset *s, unsigned i) { - g_assert(s->traces->len > i); - return ((LttvTrace *)s->traces->pdata[i]); + g_assert(s->traces->len > i); + return ((LttvTrace *)s->traces->pdata[i]); } void lttv_traceset_remove(LttvTraceset *s, unsigned i) { - LttvTrace * t; - g_assert(s->traces->len > i); - t = (LttvTrace *)s->traces->pdata[i]; - t->ref_count--; - g_ptr_array_remove_index(s->traces, i); + LttvTrace * t; + g_assert(s->traces->len > i); + t = (LttvTrace *)s->traces->pdata[i]; + t->ref_count--; + g_ptr_array_remove_index(s->traces, i); } /* A set of attributes is attached to each trace set, trace and tracefile - to store user defined data as needed. */ + to store user defined data as needed. */ LttvAttribute *lttv_traceset_attribute(LttvTraceset *s) { - return s->a; + return s->a; } LttvAttribute *lttv_trace_attribute(LttvTrace *t) { - return t->a; + return t->a; } LttTrace *lttv_trace(LttvTrace *t) { - return t->t; + return t->t; } guint lttv_trace_get_ref_number(LttvTrace * t) { - return t->ref_count; + return t->ref_count; } guint lttv_trace_ref(LttvTrace * t) { - t->ref_count++; - - return t->ref_count; + t->ref_count++; + + return t->ref_count; } guint lttv_trace_unref(LttvTrace * t) { - if(likely(t->ref_count > 0)) - t->ref_count--; + if(likely(t->ref_count > 0)) + t->ref_count--; - return t->ref_count; + return t->ref_count; } -- 2.34.1