/* Add a list of hooks to the list h */
-void lttv_hooks_add(LttvHooks *h, LttvHooks *list);
+void lttv_hooks_add_list(LttvHooks *h, LttvHooks *list);
/* Remove a hook from the list. Return the hook data. */
/* Remove a list of hooks from the hooks list in h. */
-void lttv_hooks_remove_data(LttvHooks *h, LttvHook *list);
+void lttv_hooks_remove_data_list(LttvHooks *h, LttvHook *list);
/* Return the number of hooks in the list */
/* Sometimes different hooks need to be called based on the case. The
case is represented by an unsigned integer id */
-typedef struct _LttvHooksById LttvHooksById;
+typedef GPtrArray LttvHooksById;
/* Create and destroy a hooks by id list */
#ifndef PROCESSTRACE_H
#define PROCESSTRACE_H
+#include <lttv/traceset.h>
#include <lttv/attribute.h>
#include <lttv/hook.h>
#include <ltt/ltt.h>
tracefile contexts may be subtyped as needed. Indeed, both the contexts
and the hooks are defined by the caller. */
+
+typedef struct _LttvTracesetContext LttvTracesetContext;
+typedef struct _LttvTracesetContextClass LttvTracesetContextClass;
+
+typedef struct _LttvTraceContext LttvTraceContext;
+typedef struct _LttvTraceContextClass LttvTraceContextClass;
+
+typedef struct _LttvTracefileContext LttvTracefileContext;
+typedef struct _LttvTracefileContextClass LttvTracefileContextClass;
+
#define LTTV_TRACESET_CONTEXT_TYPE (lttv_traceset_context_get_type ())
#define LTTV_TRACESET_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACESET_CONTEXT_TYPE, LttvTracesetContext))
#define LTTV_TRACESET_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACESET_CONTEXT_TYPE, LttvTracesetContextClass))
#define LTTV_IS_TRACESET_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACESET_CONTEXT_TYPE))
#define LTTV_TRACESET_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACESET_CONTEXT_TYPE, LttvTracesetContextClass))
-typedef struct _LttvTracesetContext LttvTracesetContext;
-typedef struct _LttvTracesetContextClass LttvTracesetContextClass;
-
struct _LttvTracesetContext {
GObject parent;
#define LTTV_IS_TRACE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACE_CONTEXT_TYPE))
#define LTTV_TRACE_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContextClass))
-typedef struct _LttvTraceContext LttvTraceContext;
-typedef struct _LttvTraceContextClass LttvTraceContextClass;
-
struct _LttvTraceContext {
GObject parent;
LttvTracesetContext *ts_context;
guint index; /* in ts_context->traces */
- LttvTrace *t;
+ LttTrace *t;
LttvHooks *check;
LttvHooks *before;
LttvHooks *after;
#define LTTV_IS_TRACEFILE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACEFILE_CONTEXT_TYPE))
#define LTTV_TRACEFILE_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContextClass))
-typedef struct _LttvTracefileContext LttvTracefileContext;
-typedef struct _LttvTracefileContextClass LttvTracefileContextClass;
-
struct _LttvTracefileContext {
GObject parent;
LttvTraceContext *t_context;
gboolean control;
guint index; /* in ts_context->control/per_cpu_tracefiles */
- LttvTracefile *tf;
+ LttTracefile *tf;
LttvHooks *check;
LttvHooks *before;
LttvHooks *after;
- LttvEvent *e;
+ LttEvent *e;
LttvHooks *check_event;
LttvHooks *before_event;
LttvHooksById *before_event_by_id;
LttvHooks *after_event;
LttvHooksById *after_event_by_id;
- LttTime *time;
+ LttTime timestamp;
LttvAttribute *a;
};
GType lttv_tracefile_context_get_type (void);
-void lttv_process_trace(LttvTime start, LttvTime end, LttvTraceset *traceset,
+void lttv_process_trace(LttTime start, LttTime end, LttvTraceset *traceset,
LttvTracesetContext *context);
void lttv_traceset_context_add_hooks(LttvTracesetContext *self,
LttvHooks *check_trace,
LttvHooks *before_trace,
LttvHooks *after_trace,
+ LttvHooks *check_tracefile,
+ LttvHooks *before_tracefile,
+ LttvHooks *after_tracefile,
LttvHooks *check_event,
LttvHooks *before_event,
- LttvHooks *after_event)
+ LttvHooks *after_event);
void lttv_traceset_context_remove_hooks(LttvTracesetContext *self,
LttvHooks *before_traceset,
LttvHooks *check_trace,
LttvHooks *before_trace,
LttvHooks *after_trace,
+ LttvHooks *check_tracefile,
+ LttvHooks *before_tracefile,
+ LttvHooks *after_tracefile,
LttvHooks *check_event,
LttvHooks *before_event,
- LttvHooks *after_event)
+ LttvHooks *after_event);
#endif // PROCESSTRACE_H
#ifndef STATE_H
#define STATE_H
+#include <glib.h>
#include <lttv/processTrace.h>
/* The operating system state kept during the trace analysis
contains a subset of the real operating system state,
sufficient for the analysis, and possibly organized quite differently.
- The state information is added to LttvTraceSetContext, LttvTraceContext
+ The state information is added to LttvTracesetContext, LttvTraceContext
and LttvTracefileContext objects, used by processTrace, through
subtyping. The context objects already reflect the multiple tracefiles
(one per cpu) per trace and multiple traces per trace set. The state
like enumerations. */
+typedef struct _LttvTracesetState LttvTracesetState;
+typedef struct _LttvTracesetStateClass LttvTracesetStateClass;
+
+typedef struct _LttvTraceState LttvTraceState;
+typedef struct _LttvTraceStateClass LttvTraceStateClass;
+
+typedef struct _LttvTracefileState LttvTracefileState;
+typedef struct _LttvTracefileStateClass LttvTracefileStateClass;
+
gboolean lttv_state_add_event_hooks(LttvTracesetState *self);
gboolean lttv_state_remove_event_hooks(LttvTracesetState *self);
typedef GQuark LttvInterruptType;
+extern LttvInterruptType
+ LTTV_STATE_USER_MODE,
+ LTTV_STATE_SYSCALL,
+ LTTV_STATE_TRAP,
+ LTTV_STATE_IRQ;
+
/* The interrupt number depends on the interrupt type. For user mode or kernel
thread, which are the normal mode (interrupt stack bottom), it is set to
typedef GQuark LttvProcessStatus;
+extern LttvProcessStatus
+ LTTV_STATE_UNNAMED,
+ LTTV_STATE_WAIT_FORK,
+ LTTV_STATE_WAIT_CPU,
+ LTTV_STATE_EXIT,
+ LTTV_STATE_WAIT,
+ LTTV_STATE_RUN;
-typedef _LttvInterruptState {
+
+typedef struct _LttvInterruptState {
LttvInterruptType t;
LttvInterruptNumber n;
LttvTime entry;
} LttvProcessState;
-/* The LttvTraceSetState, LttvTraceState and LttvTracefileState types
+/* The LttvTracesetState, LttvTraceState and LttvTracefileState types
inherit from the corresponding Context objects defined in processTrace. */
#define LTTV_TRACESET_STATE_TYPE (lttv_traceset_state_get_type ())
-#define LTTV_TRACESET_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACESET_STATE_TYPE, LttvTraceSetState))
-#define LTTV_TRACESET_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACESET_STATE_TYPE, LttvTraceSetStateClass))
+#define LTTV_TRACESET_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACESET_STATE_TYPE, LttvTracesetState))
+#define LTTV_TRACESET_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACESET_STATE_TYPE, LttvTracesetStateClass))
#define LTTV_IS_TRACESET_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACESET_STATE_TYPE))
#define LTTV_IS_TRACESET_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACESET_STATE_TYPE))
-#define LTTV_TRACESET_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACESET_STATE_TYPE, LttvTraceSetStateClass))
-
-typedef struct _LttvTraceSetState LttvTraceSetState;
-typedef struct _LttvTraceSetStateClass LttvTraceSetStateClass;
+#define LTTV_TRACESET_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACESET_STATE_TYPE, LttvTracesetStateClass))
-struct _LttvTraceSetState {
- LttvTraceSetContext parent;
+struct _LttvTracesetState {
+ LttvTracesetContext parent;
};
struct _LttvTracesetStateClass {
- LttvTraceSetClass parent;
+ LttvTracesetContextClass parent;
};
GType lttv_traceset_state_get_type (void);
#define LTTV_IS_TRACE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACE_STATE_TYPE))
#define LTTV_TRACE_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_STATE_TYPE, LttvTraceStateClass))
-typedef struct _LttvTraceState LttvTraceState;
-typedef struct _LttvTraceStateClass LttvTraceStateClass;
-
struct _LttvTraceState {
LttvTraceContext parent;
#define LTTV_IS_TRACEFILE_STATE_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACEFILE_STATE_TYPE))
#define LTTV_TRACEFILE_STATE_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_STATE_TYPE, LttvTracefileStateClass))
-typedef struct _LttvTracefileState LttvTracefileState;
-typedef struct _LttvTracefileStateClass LttvTracefileStateClass;
-
struct _LttvTracefileState {
LttvTracefileContext parent;
unsigned long dv_ulong;
float dv_float;
double dv_double;
- timespec dv_timespec;
+ LttvTime dv_time;
gpointer dv_pointer;
char *dv_string;
- gobject *dv_gobject;
+ GObject *dv_gobject;
} AttributeValue;
} Attribute;
-GType
-lttv_attribute_get_type (void)
+LttvAttributeValue address_of_value(LttvAttributeType t, AttributeValue *v)
{
- static GType type = 0;
- if (type == 0) {
- static const GTypeInfo info = {
- sizeof (LttvAttributeClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- attribute_class_init, /* class_init */
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (LttvAttribute),
- 0, /* n_preallocs */
- attribute_instance_init /* instance_init */
- };
+ 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;
+ }
+ return va;
+}
- 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);
+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;
}
- return type;
+ return v;
}
a = &g_array_index(self->attributes, Attribute, i);
*name = a->name;
- *v = address_of_value(a->type, a->value);
+ *v = address_of_value(a->type, &(a->value));
return a->type;
}
unsigned i;
- i = (unsigned)g_hash_table_lookup(self->names, (gconstpointer)name);
- if(i == 0) return LTTV_NONE;
+ gpointer p;
+
+ p = g_hash_table_lookup(self->names, GUINT_TO_POINTER(name));
+ if(p == NULL) return LTTV_NONE;
+ i = POINTER_TO_GUINT(p);
i--;
a = &g_array_index(self->attributes, Attribute, i);
- *v = address_of_value(a->type, a->value);
+ *v = address_of_value(a->type, &(a->value));
return a->type;
}
Attribute a, *pa;
- i = (unsigned)g_hash_table_lookup(self->names, (gconstpointer)name);
+ i = (unsigned)g_hash_table_lookup(self->names, GUINT_TO_POINTER(name));
if(i != 0) g_error("duplicate entry in attribute table");
- a->name = name;
- a->type = t;
- a->value = init_value(t);
+ a.name = name;
+ 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, (gconstpointer)name, (gconstpointer)i + 1);
- return address_of_value(pa->value, t);
+ 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));
}
/* Remove the array element and its entry in the name index */
- g_hash_table_remove(self->names, (gconspointer)a->name);
+ g_hash_table_remove(self->names, GUINT_TO_POINTER(a->name));
g_array_remove_index_fast(self->attributes, i);
/* 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, (gconstpointer)a->name);
- g_hash_table_insert(self->names, (gconstpointer)a->name, i + 1);
+ 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
{
unsigned i;
- i = (unsigned)g_hash_table_lookup(self->names, (gconstpointer)name);
+ i = (unsigned)g_hash_table_lookup(self->names, GUINT_TO_POINTER(name));
if(i == 0) g_error("remove by name non existent attribute");
lttv_attribute_remove(self, i - 1);
LttvAttribute *new;
- i = (unsigned)g_hash_table_lookup(self->names, (gconstpointer)name);
+ i = (unsigned)g_hash_table_lookup(self->names, GUINT_TO_POINTER(name));
if(i != 0) {
a = g_array_index(self->attributes, Attribute, i - 1);
- if(a->type == LTTV_GOBJECT && LTTV_IS_IATTRIBUTE(a->value->dv_gobject)) {
- return LTTV_IATTRIBUTE(a->value->dv_gobject);
+ if(a.type == LTTV_GOBJECT && LTTV_IS_IATTRIBUTE(a.value.dv_gobject)) {
+ return LTTV_IATTRIBUTE(a.value.dv_gobject);
}
else return NULL;
}
- new = g_object_new(LTTV_ATTRIBUTE_TYPE);
- *(lttv_attribute_add(self, name, LTTV_GOBJECT)->v_gobject) = new;
- return new;
+ new = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
+ *(lttv_attribute_add(self, name, LTTV_GOBJECT).v_gobject) = G_OBJECT(new);
+ return (LttvIAttribute *)new;
}
gboolean
Attribute *a;
- i = (unsigned)g_hash_table_lookup(self->names, (gconstpointer)name);
+ i = (unsigned)g_hash_table_lookup(self->names, GUINT_TO_POINTER(name));
if(i != 0) {
a = &g_array_index(self->attributes, Attribute, i - 1);
if(a->type != t) return FALSE;
- *v = address_of_value(a->value, t);
+ *v = address_of_value(t, &(a->value));
return TRUE;
}
}
-static guint
-quark_hash(gconstpointer key)
-{
- return (guint)key;
-}
-
-
-static gboolean
-quark_equal(gconstpointer a, gconstpointer b)
-{
- return (a == b)
-}
-
static void
attribute_instance_init (GTypeInstance *instance, gpointer g_class)
{
LttvAttribute *self = (LttvAttribute *)instance;
- self->names = g_hash_table_new(quark_hash, quark_equal);
- self->attributes = g_array_new(FALSE, FALSE,
- sizeof(Attribute));
+ self->names = g_hash_table_new(g_direct_hash, g_direct_equal);
+ self->attributes = g_array_new(FALSE, FALSE, sizeof(Attribute));
}
{
g_hash_table_free(self->names);
g_array_free(self->attributes, TRUE);
- G_OBJECT_CLASS(g_type_class_peek_parent(LTTV_ATTRIBUTE_TYPE))->finalize(self);
+ G_OBJECT_CLASS(g_type_class_peek_parent(LTTV_ATTRIBUTE_GET_CLASS(self)))->finalize(G_OBJECT(self));
}
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
- gobject_class->finalize = attribute_finalize;
+ 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 */
+ };
+
+ 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;
+}
+
+
#include <lttv/lttv.h>
#include <lttv/attribute.h>
#include <lttv/hook.h>
+#include <lttv/option.h>
#include <lttv/module.h>
#include <lttv/processTrace.h>
#include <lttv/state.h>
}
-static void process_traceset(void *hook_data, void *call_data)
+static gboolean process_traceset(void *hook_data, void *call_data)
{
LttvTracesetState *tc;
LttTime start, end;
- tc = g_object_new(LTTV_TRACESET_STATE);
+ tc = g_object_new(LTTV_TRACESET_STATE_TYPE, NULL);
lttv_context_init(LTTV_TRACESET_CONTEXT(tc), traceset);
lttv_traceset_context_add_hooks(LTTV_TRACESET_CONTEXT(tc),
- before_traceset, after_traceset, before_trace, after_trace,
- before_tracefile, after_tracefile, before_event, after_event);
+ before_traceset, after_traceset, NULL, before_trace, after_trace,
+ NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
lttv_state_add_event_hooks(tc);
start.tv_sec = 0;
end.tv_sec = G_MAXULONG;
end.tv_nsec = G_MAXULONG;
- lttv_process_trace(start, end, traceset, tc);
+ lttv_process_trace(start, end, traceset, LTTV_TRACESET_CONTEXT(tc));
lttv_traceset_context_remove_hooks(LTTV_TRACESET_CONTEXT(tc),
- before_traceset, after_traceset, before_trace, after_trace,
- before_tracefile, after_tracefile, before_event, after_event);
+ before_traceset, after_traceset, NULL, before_trace, after_trace,
+ NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
lttv_state_remove_event_hooks(tc);
lttv_context_fini(LTTV_TRACESET_CONTEXT(tc));
void init(LttvModule *self, int argc, char **argv)
{
- LttvAttribute_value *value;
+ LttvAttributeValue value;
- LttvIAttributes *attributes = LTTV_IATTRIBUTES(lttv_global_attributes());
+ LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
lttv_option_add("trace", 't',
"add a trace to the trace set to analyse",
"pathname of the directory containing the trace",
- LTTV_OPT_STRING, &aTrace, lttv_trace_option, NULL);
+ LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
traceset = lttv_traceset_new();
g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
LTTV_POINTER, &value));
- *(value->v_pointer) = before_traceset;
+ *(value.v_pointer) = before_traceset;
g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
LTTV_POINTER, &value));
- *(value->v_pointer) = after_traceset;
+ *(value.v_pointer) = after_traceset;
g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
LTTV_POINTER, &value));
- *(value->v_pointer) = before_trace;
+ *(value.v_pointer) = before_trace;
g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
LTTV_POINTER, &value));
- *(value->v_pointer) = after_trace;
+ *(value.v_pointer) = after_trace;
g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
LTTV_POINTER, &value));
- *(value->v_pointer) = before_tracefile;
+ *(value.v_pointer) = before_tracefile;
g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
LTTV_POINTER, &value));
- *(value->v_pointer) = after_tracefile;
+ *(value.v_pointer) = after_tracefile;
g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
LTTV_POINTER, &value));
- *(value->v_pointer) = before_event;
+ *(value.v_pointer) = before_event;
g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
LTTV_POINTER, &value));
- *(value->v_pointer) = after_event;
+ *(value.v_pointer) = after_event;
g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
LTTV_POINTER, &value));
- g_assert((main_hooks = *(value->v_pointer)) != NULL);
+ g_assert((main_hooks = *(value.v_pointer)) != NULL);
lttv_hooks_add(main_hooks, process_traceset, NULL);
}
{
guint i, nb;
- lttv_hooks_remove(main_hooks, process_traceset, NULL);
+ lttv_hooks_remove_data(main_hooks, process_traceset, NULL);
lttv_option_remove("trace");
lttv_hooks_destroy(after_event);
nb = lttv_traceset_number(traceset);
- for(i = 0 ; i < nb, i++) {
- ltt_trace_close(lttv_traceset_get(traceset);
+ for(i = 0 ; i < nb ; i++) {
+ ltt_trace_close(lttv_traceset_get(traceset, i));
}
}
+
#include <lttv/hook.h>
typedef struct _LttvHookClosure {
- lttv_hook hook;
+ LttvHook hook;
void *hook_data;
} LttvHookClosure;
{
guint i;
+ if(list == NULL) return;
for(i = 0 ; i < list->len; i++) {
g_array_append_val(h,g_array_index(list, LttvHookClosure, i));
}
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);
}
-void lttv_hooks_remove_by_position(LttvHooks *h, unsigned i);
+void lttv_hooks_remove_by_position(LttvHooks *h, unsigned i)
{
- g_array_remove_index(h, i)
+ g_array_remove_index(h, i);
}
LttvHookClosure *c;
+ guint i;
+
if(h != NULL) {
for(i = 0 ; i < h->len ; i++) {
c = &g_array_index(h, LttvHookClosure, i);
{
LttvHookClosure *c;
+ guint i;
+
for(i = 0 ; i < h->len ; i++) {
c = &g_array_index(h, LttvHookClosure, i);
if(c->hook(c->hook_data,call_data)) return TRUE;
}
-LttvHooks *lttv_hooks_by_id_find(LttvHooksById *h, unsigned id);
+LttvHooks *lttv_hooks_by_id_find(LttvHooksById *h, unsigned id)
{
if(h->len <= id) g_ptr_array_set_size(h, id + 1);
if(h->pdata[id] == NULL) h->pdata[id] = lttv_hooks_new();
+#include <lttv/iattribute.h>
+
static void
-lttv_iattribute_base_init (gpointer g_class)
+lttv_iattribute_base_init (gpointer klass)
{
static gboolean initialized = FALSE;
}
-void lttv_iattribute_add(LttvIAttribute *self, LttvAttributeName name,
- LttvAttributeType t, LttvAttributeValue *v)
+LttvAttributeValue lttv_iattribute_add(LttvIAttribute *self,
+ LttvAttributeName name, LttvAttributeType t)
{
- return LTTV_IATTRIBUTE_GET_CLASS (self)->add (self, name, t, v);
+ return LTTV_IATTRIBUTE_GET_CLASS (self)->add (self, name, t);
}
LttvIAttribute* lttv_iattribute_create_subdir(LttvIAttribute *self,
LttvAttributeName name)
{
- return LTTV_IATTRIBUTE_GET_CLASS (self)->get_number (self, name);
+ return LTTV_IATTRIBUTE_GET_CLASS (self)->create_subdir (self, name);
}
if(found_type == t) return TRUE;
if(found_type == LTTV_NONE) {
- v = lttv_iattribute_add(self, name, t);
+ *v = lttv_iattribute_add(self, name, t);
return TRUE;
}
gboolean lttv_iattribute_find_by_path(LttvIAttribute *self, char *path,
LttvAttributeType t, LttvAttributeValue *v)
{
- char *cursor;
-
LttvIAttribute *node = self;
LttvAttributeType found_type;
return FALSE;
}
- while(cursor = components;;) {
+ for(cursor = components;;) {
name = g_quark_from_string(*cursor);
cursor++;
LttvIAttribute *lttv_iattribute_shallow_copy(LttvIAttribute *self)
{
- LttvIAttribute copy;
+ LttvIAttribute *copy;
LttvAttributeType t;
int nb_attributes = lttv_iattribute_get_number(self);
- copy = LTTV_IATTRIBUTE(g_object_new(G_OBJECT_TYPE(self)));
+ copy = LTTV_IATTRIBUTE(g_object_new(G_OBJECT_TYPE(self),NULL));
for(i = 0 ; i < nb_attributes ; i++) {
t = lttv_iattribute_get(self, i, &name, &v);
v_copy = lttv_iattribute_add(copy, name, t);
- lttv_iattribute_copy_value(v_copy, v);
+ lttv_iattribute_copy_value(t, v_copy, v);
}
}
LttvIAttribute *lttv_iattribute_deep_copy(LttvIAttribute *self)
{
- LttvIAttribute copy, child;
+ LttvIAttribute *copy, *child;
LttvAttributeType t;
int nb_attributes = lttv_iattribute_get_number(self);
- copy = LTTV_IATTRIBUTE(g_object_new(G_OBJECT_TYPE(self)));
+ copy = LTTV_IATTRIBUTE(g_object_new(G_OBJECT_TYPE(self), NULL));
for(i = 0 ; i < nb_attributes ; i++) {
t = lttv_iattribute_get(self, i, &name, &v);
v_copy = lttv_iattribute_add(copy, name, t);
- if(t == LTTV_GOBJECT && LTTV_IS_IATTRIBUTE(*(v->v_gobject))) {
- child = LTTV_IATTRIBUTE(*(v->v_gobject));
- *(v_copy->v_gobject) = lttv_iattribute_deep_copy(child);
+ 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);
}
{
switch(t) {
case LTTV_INT:
- *(dest->v_int) = *(src->v_int);
+ *(dest.v_int) = *(src.v_int);
break;
case LTTV_UINT:
- *(dest->v_uint) = *(src->v_uint);
+ *(dest.v_uint) = *(src.v_uint);
break;
case LTTV_LONG:
- *(dest->v_long) = *(src->v_long);
+ *(dest.v_long) = *(src.v_long);
break;
case LTTV_ULONG:
- *(dest->v_ulong) = *(src->v_ulong);
+ *(dest.v_ulong) = *(src.v_ulong);
break;
case LTTV_FLOAT:
- *(dest->v_float) = *(src->v_float);
+ *(dest.v_float) = *(src.v_float);
break;
case LTTV_DOUBLE:
- *(dest->v_double) = *(src->v_double);
+ *(dest.v_double) = *(src.v_double);
break;
case LTTV_TIME:
- *(dest->v_time) = *(src->v_time);
+ *(dest.v_time) = *(src.v_time);
break;
case LTTV_POINTER:
- *(dest->v_pointer) = *(src->v_pointer);
+ *(dest.v_pointer) = *(src.v_pointer);
break;
case LTTV_STRING:
- *(dest->v_string) = *(src->v_string);
+ *(dest.v_string) = *(src.v_string);
break;
case LTTV_GOBJECT:
- *(dest->v_gobject) = *(src->v_gobject);
+ *(dest.v_gobject) = *(src.v_gobject);
break;
case LTTV_NONE:
#include <lttv/hook.h>
#include <lttv/module.h>
#include <lttv/lttv.h>
+#include <lttv/iattribute.h>
#include <lttv/attribute.h>
#include <lttv/option.h>
#include <lttv/traceset.h>
void lttv_module_init(int argc, char **argv);
void lttv_module_destroy();
+void lttv_state_init(int argc, char **argv);
+void lttv_state_destroy();
+
/* The main program maintains a few central data structures and relies
on modules for the rest. These data structures may be accessed by modules
through an exported API */
-static LttvIAttributes *attributes;
+static LttvIAttribute *attributes;
static LttvHooks
*before_options,
int main(int argc, char **argv) {
- LttvAttributeValue *value;
+ LttvAttributeValue value;
#ifdef MEMDEBUG
g_mem_set_vtable(glib_mem_profiler_table);
g_mem_profile();
#endif
- attributes = LTTV_IATTRIBUTES(g_object_new(LTTV_ATTRIBUTES_TYPE));
+ attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL));
before_options = lttv_hooks_new();
after_options = lttv_hooks_new();
g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/before",
LTTV_POINTER, &value));
- *(value->v_pointer) = before_options;
+ *(value.v_pointer) = before_options;
g_assert(lttv_iattribute_find_by_path(attributes, "hooks/options/after",
LTTV_POINTER, &value));
- *(value->v_pointer) = after_options;
+ *(value.v_pointer) = after_options;
g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
LTTV_POINTER, &value));
- *(value->v_pointer) = before_main;
+ *(value.v_pointer) = before_main;
g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/after",
LTTV_POINTER, &value));
- *(value->v_pointer) = after_main;
+ *(value.v_pointer) = after_main;
/* Initialize the command line options processing */
lttv_option_init(argc,argv);
lttv_module_init(argc,argv);
+ lttv_state_init(argc,argv);
/* Initialize the module loading */
/* Add some built-in options */
lttv_option_add("module",'m', "load a module", "name of module to load",
- LTTV_OPT_STRING, &aModule, lttv_module_option, NULL);
+ 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, &aModulePath,
+ "directory to add to the path", LTTV_OPT_STRING, &a_module_path,
lttv_module_path_option, NULL);
lttv_hooks_call(before_options, NULL);
lttv_hooks_call(before_main, NULL);
lttv_hooks_call(after_main, NULL);
+ lttv_state_destroy();
lttv_module_destroy();
lttv_option_destroy();
}
-lttv_attributes *lttv_global_attributes()
+LttvAttribute *lttv_global_attributes()
{
return attributes;
}
void lttv_module_path_option(void *hook_data)
{
- lttv_module_path_add(a_path);
+ lttv_module_path_add(a_module_path);
}
}
-static LttvModuleInfo *
+static LttvModule *
module_load(const char *name, int argc, char **argv)
{
GModule *gm;
int i;
char *pathname;
+
+ const char *module_name;
LttvModuleInit init_function;
/* Check if the module was already opened using the hopefully canonical name
returned by g_module_name. */
- pathname = g_module_name(gm);
+ module_name = g_module_name(gm);
- m = g_hash_table_lookup(modules, pathname);
+ m = g_hash_table_lookup(modules, module_name);
if(m == NULL) {
/* Module loaded for the first time. Insert it in the table and call the
init function if any. */
- m = g_new(LttvModule);
+ m = g_new(LttvModule, 1);
m->module = gm;
m->ref_count = 0;
m->load_count = 0;
m->dependents = g_ptr_array_new();
- g_hash_table_insert(modules, pathname, m);
+ g_hash_table_insert(modules, (gpointer)module_name, m);
if(!g_module_symbol(gm, "init", (gpointer)&init_function)) {
g_warning("module %s (%s) has no init function", name, pathname);
}
-LttvModuleInfo *
+LttvModule *
lttv_module_load(const char *name, int argc, char **argv)
{
LttvModule *m = module_load(name, argc, argv);
char *pathname;
- guint len;
+ guint i, len;
/* Decrement the reference count */
g_hash_table_foreach(modules, list_independent, independent_modules);
for(i = 0 ; i < independent_modules->len ; i++) {
- m = (LttvModule)independent_modules->pdata[i];
+ m = (LttvModule *)independent_modules->pdata[i];
while(m->load_count > 0) lttv_module_unload(m);
}
-#include <popt.h>
+#include <popt.h>
+#include <glib.h>
#include <lttv/option.h>
typedef struct _LttvOption {
- const char *long_name;
+ char *long_name;
char char_name;
- const char *description;
- const char *arg_description;
+ char *description;
+ char *arg_description;
LttvOptionType t;
gpointer p;
- LttvOptionHook h;
+ LttvOptionHook hook;
gpointer hook_data;
} LttvOption;
{
LttvOption option;
- GPtrArray list = g_ptr_array_new();
+ GPtrArray *list = g_ptr_array_new();
int i;
option->arg_description = g_strdup(arg_description);
option->t = t;
option->p = p;
- option->h = h;
+ option->hook = h;
option->hook_data = hook_data;
g_hash_table_insert(options, option->long_name, option);
}
static void
build_popts(GPtrArray **plist, struct poptOption **ppopts, poptContext *pc,
- int argv, char **argv)
+ int argc, char **argv)
{
LttvOption *option;
{
g_ptr_array_free(*plist, TRUE); *plist = NULL;
g_free(*ppopts); *ppopts = NULL;
- poptFreeContext(*c);
+ poptFreeContext(*pc);
}
#include <lttv/processTrace.h>
+#include <ltt/event.h>
-void lttv_context_init(LttvTracesetContext *self)
+void lttv_context_init(LttvTracesetContext *self, LttvTraceset *ts)
{
- LTTV_TRACESET_CONTEXT_GET_CLASS(self)->init(self);
+ LTTV_TRACESET_CONTEXT_GET_CLASS(self)->init(self, ts);
}
nb_trace = lttv_traceset_number(ts);
self->ts = ts;
- self->traces = g_new((LttvTraceContext *), nb_trace);
+ self->traces = g_new(LttvTraceContext *, nb_trace);
self->before = lttv_hooks_new();
self->after = lttv_hooks_new();
- self->attributes = g_object_new(LTTV_ATTRIBUTE_TYPE);
+ self->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
for(i = 0 ; i < nb_trace ; i++) {
- tc = self->new_trace_context();
+ tc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_trace_context(self);
self->traces[i] = tc;
tc->ts_context = self;
tc->check = lttv_hooks_new();
tc->before = lttv_hooks_new();
tc->after = lttv_hooks_new();
- tc->attributes = g_object_new(LTTV_ATTRIBUTE_TYPE);
+ tc->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->control_tracefiles = g_new((LttvTracefileContext *), nb_control);
- tc->per_cpu_tracefiles = g_new((LttvTracefileContext *), nb_per_cpu);
+ tc->control_tracefiles = g_new(LttvTracefileContext *, nb_control);
+ tc->per_cpu_tracefiles = g_new(LttvTracefileContext *, nb_per_cpu);
for(j = 0 ; j < nb_tracefile ; j++) {
- tfc = self->new_tracefile_context();
+ tfc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_tracefile_context(self);
if(j < nb_control) {
tc->control_tracefiles[j] = tfc;
tfc->control = TRUE;
tfc->index = j;
- tfc->tf = ltt_trace_control_tracefile_get(j);
+ tfc->tf = ltt_trace_control_tracefile_get(tc->t, j);
}
else {
tc->per_cpu_tracefiles[j - nb_control] = tfc;
tfc->control = FALSE;
tfc->index = j - nb_control;
- tfc->tf = ltt_trace_per_cpu_tracefile_get(j - nb_control);
+ tfc->tf = ltt_trace_per_cpu_tracefile_get(tc->t, j - nb_control);
}
tfc->t_context = tc;
tfc->check = lttv_hooks_new();
tfc->before_event_by_id = lttv_hooks_by_id_new();
tfc->after_event = lttv_hooks_new();
tfc->after_event_by_id = lttv_hooks_by_id_new();
- tfc->attributes = g_object_new(LTTV_ATTRIBUTE_TYPE);
+ tfc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
}
}
}
LttvTracefileContext *tfc;
- LttvTraceset *ts = tc->ts;
+ LttvTraceset *ts = self->ts;
lttv_hooks_destroy(self->before);
lttv_hooks_destroy(self->after);
- g_object_unref(self->attributes);
+ g_object_unref(self->a);
nb_trace = lttv_traceset_number(ts);
lttv_hooks_destroy(tc->check);
lttv_hooks_destroy(tc->before);
lttv_hooks_destroy(tc->after);
- g_object_unref(tc->attributes);
+ g_object_unref(tc->a);
nb_control = ltt_trace_control_tracefile_number(tc->t);
nb_per_cpu = ltt_trace_per_cpu_tracefile_number(tc->t);
lttv_hooks_by_id_destroy(tfc->before_event_by_id);
lttv_hooks_destroy(tfc->after_event);
lttv_hooks_by_id_destroy(tfc->after_event_by_id);
- g_object_unref(tfc->attributes);
+ g_object_unref(tfc->a);
g_object_unref(tfc);
}
g_free(tc->control_tracefiles);
LttvHooks *check_trace,
LttvHooks *before_trace,
LttvHooks *after_trace,
+ LttvHooks *check_tracefile,
+ LttvHooks *before_tracefile,
+ LttvHooks *after_tracefile,
LttvHooks *check_event,
LttvHooks *before_event,
LttvHooks *after_event)
LttvHooks *check_trace,
LttvHooks *before_trace,
LttvHooks *after_trace,
+ LttvHooks *check_tracefile,
+ LttvHooks *before_tracefile,
+ LttvHooks *after_tracefile,
LttvHooks *check_event,
LttvHooks *before_event,
LttvHooks *after_event)
LttvTracesetContext *
new_traceset_context(LttvTracesetContext *self)
{
- return g_object_new(LTTV_TRACESET_CONTEXT_TYPE);
+ return g_object_new(LTTV_TRACESET_CONTEXT_TYPE, NULL);
}
LttvTraceContext *
new_trace_context(LttvTracesetContext *self)
{
- return g_object_new(LTTV_TRACE_CONTEXT_TYPE);
+ return g_object_new(LTTV_TRACE_CONTEXT_TYPE, NULL);
}
LttvTracefileContext *
new_tracefile_context(LttvTracesetContext *self)
{
- return g_object_new(LTTV_TRACEFILE_CONTEXT_TYPE);
-}
-
-
-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 */
- traceset_context_class_init, /* class_init */
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (LttvTracesetContext),
- 0, /* n_preallocs */
- traceset_context_instance_init /* instance_init */
- };
-
- type = g_type_register_static (G_TYPE_OBJECT, "LttvTracesetContextType",
- &info, 0);
- }
- return type;
+ return g_object_new(LTTV_TRACEFILE_CONTEXT_TYPE, NULL);
}
static void
traceset_context_finalize (LttvTracesetContext *self)
{
- G_OBJECT_CLASS(g_type_class_peek_parent(LTTV_TRACESET_CONTEXT_TYPE))->finalize(self);
+ G_OBJECT_CLASS(g_type_class_peek_parent(LTTV_TRACESET_CONTEXT_GET_CLASS(self)))->finalize(G_OBJECT(self));
}
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
- gobject_class->finalize = traceset_context_finalize;
+ gobject_class->finalize = (void (*)(GObject *self))traceset_context_finalize;
klass->init = init;
klass->fini = fini;
klass->new_traceset_context = new_traceset_context;
GType
-lttv_trace_context_get_type(void)
+lttv_traceset_context_get_type(void)
{
static GType type = 0;
if (type == 0) {
static const GTypeInfo info = {
- sizeof (LttvTraceContextClass),
+ sizeof (LttvTracesetContextClass),
NULL, /* base_init */
NULL, /* base_finalize */
- trace_context_class_init, /* class_init */
+ (GClassInitFunc) traceset_context_class_init, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
- sizeof (LttvTraceSetContext),
+ sizeof (LttvTracesetContext),
0, /* n_preallocs */
- trace_context_instance_init /* instance_init */
+ (GInstanceInitFunc) traceset_context_instance_init /* instance_init */
};
- type = g_type_register_static (G_TYPE_OBJECT, "LttvTraceContextType",
+ type = g_type_register_static (G_TYPE_OBJECT, "LttvTracesetContextType",
&info, 0);
}
return type;
static void
trace_context_finalize (LttvTraceContext *self)
{
- G_OBJECT_CLASS(g_type_class_peek_parent(LTTV_TRACE_CONTEXT_TYPE))->finalize(self);
+ G_OBJECT_CLASS(g_type_class_peek_parent(LTTV_TRACE_CONTEXT_GET_CLASS(self)))->finalize(G_OBJECT(self));
}
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
- gobject_class->finalize = trace_context_finalize;
+ gobject_class->finalize = (void (*)(GObject *self)) trace_context_finalize;
}
GType
-lttv_tracefile_context_get_type(void)
+lttv_trace_context_get_type(void)
{
static GType type = 0;
if (type == 0) {
static const GTypeInfo info = {
- sizeof (LttvTracefileContextClass),
+ sizeof (LttvTraceContextClass),
NULL, /* base_init */
NULL, /* base_finalize */
- tracefile_context_class_init, /* class_init */
+ (GClassInitFunc) trace_context_class_init, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
- sizeof (LttvTracefileContext),
+ sizeof (LttvTracesetContext),
0, /* n_preallocs */
- tracefile_context_instance_init /* instance_init */
+ (GInstanceInitFunc) trace_context_instance_init /* instance_init */
};
- type = g_type_register_static (G_TYPE_OBJECT, "LttvTracefileContextType",
+ type = g_type_register_static (G_TYPE_OBJECT, "LttvTraceContextType",
&info, 0);
}
return type;
static void
tracefile_context_finalize (LttvTracefileContext *self)
{
- G_OBJECT_CLASS(g_type_class_peek_parent(LTTV_TRACEFILE_CONTEXT_TYPE))->finalize(self);
+ G_OBJECT_CLASS(g_type_class_peek_parent(LTTV_TRACEFILE_CONTEXT_GET_CLASS(self)))->finalize(G_OBJECT(self));
}
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
- gobject_class->finalize = tracefile_context_finalize;
+ gobject_class->finalize = (void (*)(GObject *self))tracefile_context_finalize;
+}
+
+
+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 */
+ };
+
+ type = g_type_register_static (G_TYPE_OBJECT, "LttvTracefileContextType",
+ &info, 0);
+ }
+ return type;
}
-guint compare_tracefile(gconstpointer a, gconstpointer b)
+gint compare_tracefile(gconstpointer a, gconstpointer b)
{
- if((LttvTime *)a->tv_sec > (LttvTime *)b->tv_sec) return 1;
- if((LttvTime *)a->tv_sec < (LttvTime *)b->tv_sec) return -1;
- if((LttvTime *)a->tv_nsec > (LttvTime *)b->tv_nsec) return 1;
- if((LttvTime *)a->tv_nsec < (LttvTime *)b->tv_nsec) return -1;
+ if(((LttvTime *)a)->tv_sec > ((LttvTime *)b)->tv_sec) return 1;
+ if(((LttvTime *)a)->tv_sec < ((LttvTime *)b)->tv_sec) return -1;
+ if(((LttvTime *)a)->tv_nsec > ((LttvTime *)b)->tv_nsec) return 1;
+ if(((LttvTime *)a)->tv_nsec < ((LttvTime *)b)->tv_nsec) return -1;
return 0;
}
}
-void lttv_process_trace(LttvTime start, LttvTime end, LttvTraceset *traceset,
+void lttv_process_trace(LttTime start, LttTime end, LttvTraceset *traceset,
LttvTracesetContext *context)
{
GPtrArray *traces = g_ptr_array_new();
GTree *pqueue = g_tree_new(compare_tracefile);
- guint i, j, nbi, nbj, id;
+ guint i, j, nbi, nbj, id, nb_control, nb_cpu;
LttTrace *trace;
tfc->e = event;
if(event != NULL) {
- tfc->time = ltt_event_time(event);
- g_tree_insert(pqueue, &(tfc->time), tfc);
+ tfc->timestamp = ltt_event_time(event);
+ g_tree_insert(pqueue, &(tfc->timestamp), tfc);
}
}
}
unless the tracefile is finished or the event is later than the
start time. */
- while() {
+ while(TRUE) {
tfc = NULL;
g_tree_foreach(pqueue, get_first, &tfc);
if(tfc == NULL) break;
or more tracefiles have events for the same time, hope that lookup
and remove are consistent. */
- tfc = g_tree_lookup(pqueue, &(tfc->time));
- g_tree_remove(pqueue, &(tfc->time));
+ tfc = g_tree_lookup(pqueue, &(tfc->timestamp));
+ g_tree_remove(pqueue, &(tfc->timestamp));
if(!lttv_hooks_call(tfc->check_event, context)) {
id = lttv_event_id(tfc->e);
event = ltt_tracefile_read(tfc->tf);
if(event != NULL) {
tfc->e = event;
- tfc->time = ltt_event_time(event);
- g_tree_insert(pqueue, &(tfc->time), tfc);
+ tfc->timestamp = ltt_event_time(event);
+ g_tree_insert(pqueue, &(tfc->timestamp), tfc);
}
}
}
g_assert(j == tracefiles->len);
- lttv_hooks_call(after_traceset, context);
+ lttv_hooks_call(context->after, context);
/* Free the traces, tracefiles and pqueue */
g_ptr_array_free(tracefiles, TRUE);
g_ptr_array_free(traces, TRUE);
- g_tree_destroy(pqueue, TRUE);
+ g_tree_destroy(pqueue);
}
#include <lttv/state.h>
+LttvInterruptType
+ LTTV_STATE_USER_MODE,
+ LTTV_STATE_SYSCALL,
+ LTTV_STATE_TRAP,
+ LTTV_STATE_IRQ;
+
+
+LttvProcessStatus
+ LTTV_STATE_UNNAMED,
+ LTTV_STATE_WAIT_FORK,
+ LTTV_STATE_WAIT_CPU,
+ LTTV_STATE_EXIT,
+ LTTV_STATE_WAIT,
+ LTTV_STATE_RUN;
+
static void
init(LttvTracesetState *self, LttvTraceset *ts)
{
guint i, j, nb_trace, nb_tracefile;
- LttvTraceState *tc;
+ LttvTraceContext *tc;
- LttvTracefileState *tfc;
+ LttvTraceState *tcs;
+
+ LttvTracefileContext *tfc;
- LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek_parent(LTTV_TRACESET_STATE_TYPE))->init(self, ts);
+ LttvTracefileState *tfcs;
+
+ LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek_parent(LTTV_TRACESET_STATE_GET_CLASS(self)))->init((LttvTracesetContext *)self, ts);
nb_trace = lttv_traceset_number(ts);
for(i = 0 ; i < nb_trace ; i++) {
- tc = (LttvTraceState *)self->traces[i];
- tc->processes = g_hash_table_new(g_direct_hash, g_direct_equal);
+ tcs = (LttvTraceState *)tc = (LTTV_TRACESET_CONTEXT(self)->traces[i]);
+ tcs->processes = g_hash_table_new(g_direct_hash, g_direct_equal);
nb_tracefile = ltt_trace_control_tracefile_number(tc->t);
for(j = 0 ; j < nb_tracefile ; j++) {
- tfc = tc->control_tracefiles[j];
- tfc->process = NULL;
+ tfcs = (LttvTracefileState *)tfc = tc->control_tracefiles[j];
+ tfcs->process = NULL;
}
nb_tracefile = ltt_trace_per_cpu_tracefile_number(tc->t);
for(j = 0 ; j < nb_tracefile ; j++) {
- tfc = tc->per_cpu_tracefiles[j];
- tfc->process = NULL;
+ tfcs = (LttvTracefileState *)tfc = tc->per_cpu_tracefiles[j];
+ tfcs->process = NULL;
}
}
}
{
guint i, j, nb_trace, nb_tracefile;
- LttvTraceState *tc;
+ LttvTraceState *tcs;
- LttvTracefileState *tfc;
+ LttvTracefileState *tfcs;
- nb_trace = lttv_traceset_number(ts);
+ nb_trace = lttv_traceset_number(LTTV_TRACESET_CONTEXT(self)->ts);
for(i = 0 ; i < nb_trace ; i++) {
- tc = (LttvTraceState *)self->traces[i];
- remove_all_processes(tc->processes);
- g_hash_table_destroy(tc->processes);
+ tcs = (LttvTraceState *)(LTTV_TRACESET_CONTEXT(self)->traces[i]);
+ remove_all_processes(tcs->processes);
+ g_hash_table_destroy(tcs->processes);
}
- LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek_parent(LTTV_TRACESET_STATE_TYPE))->fini(self);
+ LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek_parent(LTTV_TRACESET_STATE_GET_CLASS(self)))->fini((LttvTracesetContext *)self);
}
LttvTracesetContext *
new_traceset_context(LttvTracesetContext *self)
{
- return LTTV_TRACESET_CONTEXT(g_object_new(LTTV_TRACESET_STATE_TYPE));
+ return LTTV_TRACESET_CONTEXT(g_object_new(LTTV_TRACESET_STATE_TYPE, NULL));
}
LttvTraceContext *
new_trace_context(LttvTracesetContext *self)
{
- return LTTV_TRACE_CONTEXT(g_object_new(LTTV_TRACE_STATE_TYPE));
+ return LTTV_TRACE_CONTEXT(g_object_new(LTTV_TRACE_STATE_TYPE, NULL));
}
LttvTracefileContext *
new_tracefile_context(LttvTracesetContext *self)
{
- return LTTV_TRACEFILE_CONTEXT(g_object_new(LTTV_TRACEFILE_STATE_TYPE));
+ return LTTV_TRACEFILE_CONTEXT(g_object_new(LTTV_TRACEFILE_STATE_TYPE, NULL));
+}
+
+
+static void
+traceset_state_instance_init (GTypeInstance *instance, gpointer g_class)
+{
+}
+
+
+static void
+traceset_state_finalize (LttvTracesetContext *self)
+{
+ G_OBJECT_CLASS(g_type_class_peek_parent(LTTV_TRACESET_STATE_GET_CLASS(self)))->finalize(G_OBJECT(self));
+}
+
+
+static void
+traceset_state_class_init (LttvTracesetContextClass *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;
}
sizeof (LttvTracesetStateClass),
NULL, /* base_init */
NULL, /* base_finalize */
- traceset_state_class_init, /* class_init */
+ (GClassInitFunc) traceset_state_class_init, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (LttvTracesetContext),
0, /* n_preallocs */
- traceset_state_instance_init /* instance_init */
+ (GInstanceInitFunc) traceset_state_instance_init /* instance_init */
};
type = g_type_register_static (LTTV_TRACESET_CONTEXT_TYPE, "LttvTracesetStateType",
static void
-traceset_state_instance_init (GTypeInstance *instance, gpointer g_class)
+trace_state_instance_init (GTypeInstance *instance, gpointer g_class)
{
}
static void
-traceset_context_finalize (LttvTracesetContext *self)
+trace_state_finalize (LttvTraceContext *self)
{
- G_OBJECT_CLASS(g_type_class_peek_parent(LTTV_TRACESET_STATE_TYPE))->finalize(self);
+ G_OBJECT_CLASS(g_type_class_peek_parent(LTTV_TRACE_STATE_GET_CLASS(self)))->finalize(G_OBJECT(self));
}
static void
-traceset_state_class_init (LttvTracesetContextClass *klass)
+trace_state_class_init (LttvTraceContextClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
- gobject_class->finalize = traceset_state_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;
+ gobject_class->finalize = (void (*)(GObject *self)) trace_state_finalize;
}
sizeof (LttvTraceStateClass),
NULL, /* base_init */
NULL, /* base_finalize */
- trace_state_class_init, /* class_init */
+ (GClassInitFunc) trace_state_class_init, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (LttvTracesetState),
0, /* n_preallocs */
- trace_state_instance_init /* instance_init */
+ (GInstanceInitFunc) trace_state_instance_init /* instance_init */
};
type = g_type_register_static (LTTV_TRACE_CONTEXT_TYPE,
static void
-trace_state_instance_init (GTypeInstance *instance, gpointer g_class)
+tracefile_state_instance_init (GTypeInstance *instance, gpointer g_class)
{
}
static void
-trace_state_finalize (LttvTraceContext *self)
+tracefile_state_finalize (LttvTracefileState *self)
{
- G_OBJECT_CLASS(g_type_class_peek_parent(LTTV_TRACE_STATE_TYPE))->finalize(self);
+ G_OBJECT_CLASS(g_type_class_peek_parent(LTTV_TRACEFILE_STATE_GET_CLASS(self)))->finalize(G_OBJECT(self));
}
static void
-trace_state_class_init (LttvTraceContextClass *klass)
+tracefile_state_class_init (LttvTracefileStateClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
- gobject_class->finalize = trace_state_finalize;
+ gobject_class->finalize = (void (*)(GObject *self)) tracefile_state_finalize;
}
sizeof (LttvTracefileStateClass),
NULL, /* base_init */
NULL, /* base_finalize */
- tracefile_state_class_init, /* class_init */
+ (GClassInitFunc) tracefile_state_class_init, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (LttvTracefileState),
0, /* n_preallocs */
- tracefile_state_instance_init /* instance_init */
+ (GInstanceInitFunc) tracefile_state_instance_init /* instance_init */
};
type = g_type_register_static (LTTV_TRACEFILE_CONTEXT_TYPE,
}
-static void
-tracefile_state_instance_init (GTypeInstance *instance, gpointer g_class)
-{
-}
-
-
-static void
-tracefile_state_finalize (LttvTracefileState *self)
-{
- G_OBJECT_CLASS(g_type_class_peek_parent(LTTV_TRACEFILE_STATE_TYPE))->finalize(self);
-}
-
-
-static void
-tracefile_state_class_init (LttvTracefileStateClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-
- gobject_class->finalize = tracefile_state_finalize;
-}
-
-
struct HookData {
LttField *f1;
LttField *f2;
LttField *f3;
-}
+};
struct HookId {
guint id;
void *hook_data;
gboolean free_hook_data;
-}
+};
-void push_state(LttvTracefileState *tfs, LttvInterruptType t, guint state_id)
+static void push_state(LttvTracefileState *tfs, LttvInterruptType t,
+ guint state_id)
{
- LttvInterruptState intr;
+ LttvInterruptState *intr;
LttvProcessState *process = tfs->process;
intr = &g_array_index(process->interrupt_stack, LttvInterruptState, depth);
intr->t = t;
intr->n = state_id;
- intr->entry = tfs->time;
- intr->last_change = tfs->time;
+ intr->entry = intr->last_change = LTTV_TRACEFILE_CONTEXT(tfs)->timestamp;
intr->s = process->state->s;
}
-void pop_state(LttvTracefileState *tfs, LttvInterruptType t)
+static void pop_state(LttvTracefileState *tfs, LttvInterruptType t)
{
LttvProcessState *process = tfs->process;
}
-LttvProcessState *create_process(LttvTraceState *tfs, LttvProcessState *parent,
- guint pid)
+LttvProcessState *create_process(LttvTracefileState *tfs,
+ LttvProcessState *parent, guint pid)
{
LttvProcessState *process = g_new(LttvProcessState, 1);
LttvInterruptState *intr;
- g_hash_table_insert(tfs->ts->processes, pid, process);
+ LttvTraceContext *tc;
+
+ LttvTraceContext *tcs;
+
+ tcs = (LttvTraceState *)tc = LTTV_TRACEFILE_CONTEXT(tfs)->ts;
+
+ g_hash_table_insert(tcs->processes, GUINT_TO_POINTER(pid), process);
process->pid = pid;
- process->birth = tfs->time;
+ process->birth = tfs->timestamp;
process->name = LTTV_STATE_UNNAMED;
process->interrupt_stack = g_array_new(FALSE, FALSE,
sizeof(LttvInterruptState));
g_array_set_size(process->interrupt_stack, 1);
- intr = process->state = process->interrupt_stack->data;
+ intr = process->state = &g_array_index(process->interrupt_stack,
+ LttvInterruptState, 0);
intr->t = LTTV_STATE_USER_MODE
intr->n = 0;
- intr->entry = tfs->time;
- intr->last_change = tfs->time;
+ intr->entry = tfs->timestamp;
+ intr->last_change = tfs->timestamp;
intr->s = LTTV_STATE_WAIT_FORK;
}
struct LttvTracefileState *s = (LttvTraceFileState *)call_data;
- push_state(s, STATE_SYSCALL, ltt_event_get_unsigned(s->e, f));
+ push_state(s, LTTV_STATE_SYSCALL, ltt_event_get_unsigned(s->e, f));
return FALSE;
}
{
struct LttvTracefileState *s = (LttvTraceFileState *)call_data;
- pop_state(s, STATE_SYSCALL);
+ pop_state(s, LTTV_STATE_SYSCALL);
return FALSE;
}
struct LttvTracefileState *s = (LttvTraceFileState *)call_data;
- push_state(s, STATE_TRAP, ltt_event_get_unsigned(s->e, f));
+ push_state(s, LTTV_STATE_TRAP, ltt_event_get_unsigned(s->e, f));
return FALSE;
}
{
struct LttvTracefileState *s = (LttvTraceFileState *)call_data;
- pop_state(s, STATE_TRAP);
+ pop_state(s, LTTV_STATE_TRAP);
return FALSE;
}
struct LttvTracefileState *s = (LttvTraceFileState *)call_data;
/* Do something with the info about being in user or system mode when int? */
- push_state(s, STATE_IRQ, ltt_event_get_unsigned(s->e, f));
+ push_state(s, LTTV_STATE_IRQ, ltt_event_get_unsigned(s->e, f));
return FALSE;
}
{
struct LttvTracefileState *s = (LttvTraceFileState *)call_data;
- pop_state(s, STATE_IRQ);
+ pop_state(s, LTTV_STATE_IRQ);
return FALSE;
}
pid_out = ltt_event_get_int(s->e, h->f2);
state_out = ltt_event_get_int(s->e, h->f3);
if(s->process != NULL) {
- if(state_out == 0) s->process->state->s = STATE_WAIT_CPU;
- else if(s->process->state->s == STATE_EXIT)
+ if(state_out == 0) s->process->state->s = LTTV_STATE_WAIT_CPU;
+ else if(s->process->state->s == LTTV_STATE_EXIT)
exit_process(s->tc, s->process);
- else s->process->state->s = STATE_WAIT;
+ else s->process->state->s = LTTV_STATE_WAIT;
}
s->process = find_process(s->tc, pid_in);
- s->process->state->s = STATE_RUN;
+ s->process->state->s = LTTV_STATE_RUN;
return FALSE;
}
struct LttvTracefileState *s = (LttvTraceFileState *)call_data;
if(s->process != NULL) {
- s->process->state->s = STATE_EXIT;
+ s->process->state->s = LTTV_STATE_EXIT;
}
return FALSE;
}
hook_id = g_array_index(hooks, struct HookId, k);
lttv_hooks_add(lttv_hooks_by_id_find(tfc->before_event_by_id,
hook_id->id), hook_id->h, hook_id->hook_data);
+ }
}
- lttv_attribute_find(self->a, STATE_HOOKS, LTTV_POINTER, val);
+ lttv_attribute_find(self->a, LTTV_STATE_HOOKS, LTTV_POINTER, val);
val->v_pointer = hooks;
}
}
nb_trace = lttv_traceset_number(ts);
for(i = 0 ; i < nb_trace ; i++) {
tc = (LttvTraceState *)self->traces[i];
- lttv_attribute_find(self->a, STATE_HOOKS, LTTV_POINTER, val);
+ lttv_attribute_find(self->a, LTTV_STATE_HOOKS, LTTV_POINTER, val);
hooks = val->v_pointer;
/* Add these hooks to each before_event_by_id hooks list */
hook_id = g_array_index(hooks, struct HookId, k);
lttv_hooks_remove_data(lttv_hooks_by_id_find(tfc->before_event_by_id,
hook_id->id), hook_id->h, hook_id->hook_data);
- }
- for(k = 0 ; k < hooks->len ; k++) {
- hook_id = g_array_index(hooks, struct HookId, k);
- if(hook_id->free_hook_data) g_free(hook_id->hook_data);
+
+ }
+ for(k = 0 ; k < hooks->len ; k++) {
+ hook_id = g_array_index(hooks, struct HookId, k);
+ if(hook_id->free_hook_data) g_free(hook_id->hook_data);
+ }
}
g_array_free(hooks, TRUE);
}
}
+void lttv_state_init(int argc, char **argv)
+{
+ LTTV_STATE_UNNAMED = g_quark_from_string("unnamed");
+ LTTV_STATE_USER_MODE = g_quark_from_string("user mode");
+ LTTV_STATE_WAIT_FORK = g_quark_from_string("wait fork");
+ LTTV_STATE_SYSCALL = g_quark_from_string("system call");
+ LTTV_STATE_TRAP = g_quark_from_string("trap");
+ LTTV_STATE_IRQ = g_quark_from_string("irq");
+ LTTV_STATE_WAIT_CPU = g_quark_from_string("wait for cpu");
+ LTTV_STATE_EXIT = g_quark_from_string("exiting");
+ LTTV_STATE_WAIT = g_quark_from_string("wait for I/O");
+ LTTV_STATE_RUN = g_quark_from_string("running");
+ LTTV_STATE_HOOKS = g_quark_from_string("saved state hooks");
+}
-
-
-
+void lttv_state_destroy()
+{
+}
#include <lttv/attribute.h>
#include <lttv/iattribute.h>
#include <lttv/state.h>
+#include <ltt/ltt.h>
+#include <ltt/event.h>
+#include <ltt/type.h>
+#include <ltt/trace.h>
+#include <stdio.h>
static gboolean
a_field_names,
*before_event;
-void init(int argc, char **argv)
-{
- LttvAttributeValue *value;
+void print_field(LttEvent *e, LttField *f, GString *s, gboolean field_names) {
- LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
+ LttType *type;
- a_file_name = NULL;
- lttv_option_add("output", 'o',
- "output file where the text is written",
- "file name",
- LTTV_OPT_STRING, &a_file_name, NULL, NULL);
+ LttField *element;
- a_field_names = FALSE;
- lttv_option_add("field_names", 'l',
- "write the field names for each event",
- "",
- LTTV_OPT_NONE, &a_field_names, NULL, NULL);
+ char *name;
- a_state = FALSE;
- lttv_option_add("process_state", 's',
- "write the pid and state for each event",
- "",
- LTTV_OPT_NONE, &a_state, NULL, NULL);
+ int nb, i;
- g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
- LTTV_POINTER, &value));
- g_assert((before_event = *(value->v_pointer)) != NULL);
- lttv_hooks_add(before_event, write_event_content, NULL);
+ type = ltt_field_type(f);
+ switch(ltt_type_class(type)) {
+ case LTT_INT:
+ g_string_append_printf(s, " %ld", ltt_event_get_long_int(e,f));
+ break;
- g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
- LTTV_POINTER, &value));
- g_assert((before_trace = *(value->v_pointer)) != NULL);
- lttv_hooks_add(before_trace, write_trace_header, NULL);
+ case LTT_UINT:
+ g_string_append_printf(s, " %lu", ltt_event_get_long_unsigned(e,f));
+ break;
- g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
- LTTV_POINTER, &value));
- g_assert((before_traceset = *(value->v_pointer)) != NULL);
- lttv_hooks_add(before_traceset, write_traceset_header, NULL);
+ case LTT_FLOAT:
+ g_string_append_printf(s, " %g", ltt_event_get_double(e,f));
+ break;
- g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
- LTTV_POINTER, &value));
- g_assert((after_traceset = *(value->v_pointer)) != NULL);
- lttv_hooks_add(after_traceset, write_traceset_footer, NULL);
+ case LTT_STRING:
+ g_string_append_printf(s, " \"%s\"", ltt_event_get_string(e,f));
+ break;
+
+ case LTT_ENUM:
+ g_string_append_printf(s, " %s", ltt_enum_string_get(type,
+ event_get_unsigned(e,f)));
+ break;
+
+ case LTT_ARRAY:
+ case LTT_SEQUENCE:
+ g_string_append_printf(s, " {");
+ nb = ltt_event_field_element_number(e,f);
+ element = ltt_field_element(f);
+ for(i = 0 ; i < nb ; i++) {
+ ltt_event_field_element_select(e,f,i);
+ print_field(e, element, s, field_names);
+ }
+ g_string_append_printf(s, " }");
+ break;
+
+ case LTT_STRUCT:
+ g_string_append_printf(s, " {");
+ nb = ltt_type_member_number(type);
+ for(i = 0 ; i < nb ; i++) {
+ element = ltt_field_member(f,i);
+ if(name) {
+ ltt_type_member_type(type, i, &name);
+ g_string_append_printf(s, " %s = ", field_names);
+ }
+ print_field(e, element, s, field_names);
+ }
+ g_string_append_printf(s, " }");
+ break;
+ }
}
-void destroy()
+void lttv_event_to_string(LttEvent *e, LttTracefile *tf, GString *s,
+ gboolean mandatory_fields, gboolean field_names)
{
- lttv_option_remove("output");
+ LttFacility *facility;
- lttv_option_remove("field_names");
+ LttEventType *event_type;
- lttv_option_remove("process_state");
+ LttType *type;
+
+ LttField *field;
- lttv_hooks_remove(before_event, write_event, NULL);
+ LttTime time;
- lttv_hooks_remove(before_trace, write_trace_header, NULL);
+ g_string_set_size(s,0);
- lttv_hooks_remove(before_trace, write_traceset_header, NULL);
+ facility = ltt_event_facility(e);
+ event_type = ltt_event_eventtype(e);
+ field = ltt_event_field(e);
- lttv_hooks_remove(before_trace, write_traceset_footer, NULL);
-}
+ if(mandatory_fields) {
+ time = ltt_event_time(e);
+ g_string_append_printf(s,"%s.%s: %ld.%ld (%s)",ltt_facility_name(facility),
+ ltt_eventtype_name(event_type), (long)time.tv_sec, time.tv_nsec,
+ ltt_tracefile_name(tf));
+ }
+
+ print_field(e, field, s, field_names);
+}
/* Insert the hooks before and after each trace and tracefile, and for each
static GString *a_string;
-static static gboolean write_traceset_header(void *hook_data, void *call_data)
+static gboolean write_traceset_header(void *hook_data, void *call_data)
{
LttvTracesetContext *tc = (LttvTracesetContext *)call_data;
/* Print the trace set header */
fprintf(a_file,"Trace set contains %d traces\n\n",
- lttv_traceset_number(tc->ta);
+ lttv_traceset_number(tc->ts));
return FALSE;
}
-static static gboolean write_traceset_footer(void *hook_data, void *call_data)
+static gboolean write_traceset_footer(void *hook_data, void *call_data)
{
LttvTracesetContext *tc = (LttvTracesetContext *)call_data;
- if(a_file_name != NULL) a_file = fclose(a_file);
-
fprintf(a_file,"End trace set\n\n");
+ if(a_file_name != NULL) fclose(a_file);
+
return FALSE;
}
if(a_state) {
g_string_append_printf(a_string, " %s",
- g_quark_to_string(tfs->process->state->s);
+ g_quark_to_string(tfs->process->state->s));
}
- fputs(s, c->fd);
+ fputs(a_string->str, a_file);
return FALSE;
}
-void lttv_event_to_string(LttEvent *e, LttTracefile *tf, g_string *s,
- gboolean mandatory_fields, gboolean field_names)
+void init(int argc, char **argv)
{
- LttFacility *facility;
+ LttvAttributeValue value;
- LttEventType *event_type;
-
- LttType *type;
-
- LttField *field;
-
- LttTime time;
-
- g_string_set_size(s,0);
-
- facility = lttv_event_facility(e);
- eventtype = ltt_event_eventtype(e);
- field = ltt_event_field(e);
+ LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
- if(mandatory_fields) {
- time = ltt_event_time(e);
- g_string_append_printf(s,"%s.%s: %ld.%ld (%s)",ltt_facility_name(facility),
- ltt_eventtype_name(eventtype), (long)time.tv_sec, time.tv_nsec,
- ltt_tracefile_name(tf));
- }
+ a_file_name = NULL;
+ lttv_option_add("output", 'o',
+ "output file where the text is written",
+ "file name",
+ LTTV_OPT_STRING, &a_file_name, NULL, NULL);
- print_field(e,f,s, field_names);
-}
+ a_field_names = FALSE;
+ lttv_option_add("field_names", 'l',
+ "write the field names for each event",
+ "",
+ LTTV_OPT_NONE, &a_field_names, NULL, NULL);
+ a_state = FALSE;
+ lttv_option_add("process_state", 's',
+ "write the pid and state for each event",
+ "",
+ LTTV_OPT_NONE, &a_state, NULL, NULL);
-void print_field(LttEvent *e, LttField *f, g_string *s, gboolean field_names) {
+ g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
+ LTTV_POINTER, &value));
+ g_assert((before_event = *(value.v_pointer)) != NULL);
+ lttv_hooks_add(before_event, write_event_content, NULL);
- LttType *type;
+ g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
+ LTTV_POINTER, &value));
+ g_assert((before_trace = *(value.v_pointer)) != NULL);
+ lttv_hooks_add(before_trace, write_trace_header, NULL);
- LttField *element;
+ g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
+ LTTV_POINTER, &value));
+ g_assert((before_traceset = *(value.v_pointer)) != NULL);
+ lttv_hooks_add(before_traceset, write_traceset_header, NULL);
- char *name;
+ g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
+ LTTV_POINTER, &value));
+ g_assert((after_traceset = *(value.v_pointer)) != NULL);
+ lttv_hooks_add(after_traceset, write_traceset_footer, NULL);
+}
- int nb, i;
- type = ltt_field_type(f);
- switch(ltt_type_class(type)) {
- case LTT_INT:
- g_string_append_printf(s, " %ld", ltt_event_get_long_int(e,f));
- break;
+void destroy()
+{
+ lttv_option_remove("output");
- case LTT_UINT:
- g_string_append_printf(s, " %lu", ltt_event_get_long_unsigned(e,f));
- break;
+ lttv_option_remove("field_names");
- case LTT_FLOAT:
- g_string_append_printf(s, " %g", ltt_event_get_double(e,f));
- break;
+ lttv_option_remove("process_state");
- case LTT_STRING:
- g_string_append_printf(s, " \"%s\"", ltt_event_get_string(e,f));
- break;
+ lttv_hooks_remove_data(before_event, write_event_content, NULL);
- case LTT_ENUM:
- g_string_append_printf(s, " %s", ltt_enum_string_get(type,
- event_get_unsigned(e,f));
- break;
+ lttv_hooks_remove_data(before_trace, write_trace_header, NULL);
- case LTT_ARRAY:
- case LTT_SEQUENCE:
- g_string_append_printf(s, " {");
- nb = ltt_event_field_element_number(e,f);
- element = ltt_field_element(f);
- for(i = 0 ; i < nb ; i++) {
- ltt_event_field_element_select(e,f,i);
- print_field(e,element,s);
- }
- g_string_append_printf(s, " }");
- break;
+ lttv_hooks_remove_data(before_trace, write_traceset_header, NULL);
- case LTT_STRUCT:
- g_string_append_printf(s, " {");
- nb = ltt_type_member_number(type);
- for(i = 0 ; i < nb ; i++) {
- element = ltt_field_member(f,i);
- if(name) {
- ltt_type_member_type(type, &name);
- g_string_append_printf(s, " %s = ", field_names);
- }
- print_field(e,element,s);
- }
- g_string_append_printf(s, " }");
- break;
- }
+ lttv_hooks_remove_data(before_trace, write_traceset_footer, NULL);
}