git-svn-id: http://ltt.polymtl.ca/svn@252 04897980-b3bd-0310-b5e0-8ef037075253
[lttv.git] / ltt / branches / poly / lttv / state.c
index b60f22f23cfdda8a67c85a2237dcf71d14d260c5..a76918a24669c26ba47339b12091fbbf848e0c72 100644 (file)
@@ -23,6 +23,8 @@ static GQuark
 
 void remove_all_processes(GHashTable *processes);
 
+LttvProcessState *create_process(LttvTracefileState *tfs, 
+                                LttvProcessState *parent, guint pid);
 
 static void
 init(LttvTracesetState *self, LttvTraceset *ts)
@@ -36,6 +38,8 @@ init(LttvTracesetState *self, LttvTraceset *ts)
   LttvTracefileContext *tfc;
 
   LttvTracefileState *tfcs;
+  
+  LttTime timestamp = {0,0};
 
   LTTV_TRACESET_CONTEXT_CLASS(g_type_class_peek_parent(LTTV_TRACESET_STATE_GET_CLASS(self)))->init((LttvTracesetContext *)self, ts);
 
@@ -47,13 +51,15 @@ init(LttvTracesetState *self, LttvTraceset *ts)
     nb_tracefile = ltt_trace_control_tracefile_number(tc->t);
     for(j = 0 ; j < nb_tracefile ; j++) {
       tfcs = (LttvTracefileState *)tfc = tc->control_tracefiles[j];
-      tfcs->process = NULL;
+      tfc->timestamp = timestamp;
+      tfcs->process = create_process(tfcs, NULL,0);
     }
 
     nb_tracefile = ltt_trace_per_cpu_tracefile_number(tc->t);
     for(j = 0 ; j < nb_tracefile ; j++) {
       tfcs = (LttvTracefileState *)tfc = tc->per_cpu_tracefiles[j];
-      tfcs->process = NULL;
+      tfc->timestamp = timestamp;
+      tfcs->process = create_process(tfcs, NULL,0);
     }
   }
 }
@@ -78,21 +84,21 @@ fini(LttvTracesetState *self)
 }
 
 
-LttvTracesetContext *
+static LttvTracesetContext *
 new_traceset_context(LttvTracesetContext *self)
 {
   return LTTV_TRACESET_CONTEXT(g_object_new(LTTV_TRACESET_STATE_TYPE, NULL));
 }
 
 
-LttvTraceContext * 
+static LttvTraceContext * 
 new_trace_context(LttvTracesetContext *self)
 {
   return LTTV_TRACE_CONTEXT(g_object_new(LTTV_TRACE_STATE_TYPE, NULL));
 }
 
 
-LttvTracefileContext *
+static LttvTracefileContext *
 new_tracefile_context(LttvTracesetContext *self)
 {
   return LTTV_TRACEFILE_CONTEXT(g_object_new(LTTV_TRACEFILE_STATE_TYPE, NULL));
@@ -106,9 +112,9 @@ traceset_state_instance_init (GTypeInstance *instance, gpointer g_class)
 
 
 static void
-traceset_state_finalize (LttvTracesetContext *self)
+traceset_state_finalize (LttvTracesetState *self)
 {
-  G_OBJECT_CLASS(g_type_class_peek_parent(LTTV_TRACESET_STATE_GET_CLASS(self)))->finalize(G_OBJECT(self));
+  G_OBJECT_CLASS(g_type_class_peek_parent(g_type_class_peek_parent(LTTV_TRACESET_STATE_GET_CLASS(self))))->finalize(G_OBJECT(self));
 }
 
 
@@ -157,9 +163,9 @@ trace_state_instance_init (GTypeInstance *instance, gpointer g_class)
 
 
 static void
-trace_state_finalize (LttvTraceContext *self)
+trace_state_finalize (LttvTraceState *self)
 {
-  G_OBJECT_CLASS(g_type_class_peek_parent(LTTV_TRACE_STATE_GET_CLASS(self)))->finalize(G_OBJECT(self));
+  G_OBJECT_CLASS(g_type_class_peek_parent(g_type_class_peek_parent(LTTV_TRACE_STATE_GET_CLASS(self))))->finalize(G_OBJECT(self));
 }
 
 
@@ -184,7 +190,7 @@ lttv_trace_state_get_type(void)
       (GClassInitFunc) trace_state_class_init,   /* class_init */
       NULL,   /* class_finalize */
       NULL,   /* class_data */
-      sizeof (LttvTracesetState),
+      sizeof (LttvTraceState),
       0,      /* n_preallocs */
       (GInstanceInitFunc) trace_state_instance_init    /* instance_init */
     };
@@ -205,7 +211,7 @@ 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_GET_CLASS(self)))->finalize(G_OBJECT(self));
+  G_OBJECT_CLASS(g_type_class_peek_parent(g_type_class_peek_parent(LTTV_TRACEFILE_STATE_GET_CLASS(self))))->finalize(G_OBJECT(self));
 }
 
 
@@ -272,6 +278,7 @@ static void push_state(LttvTracefileState *tfs, LttvInterruptType t,
   intr->n = state_id;
   intr->entry = intr->last_change = LTTV_TRACEFILE_CONTEXT(tfs)->timestamp;
   intr->s = process->state->s;
+  process->state = intr;
 }
 
 
@@ -281,7 +288,11 @@ static void pop_state(LttvTracefileState *tfs, LttvInterruptType t)
 
   guint depth = process->interrupt_stack->len - 1;
 
-  g_assert(process->state->t == t);
+  //  g_assert(process->state->t == t);
+  if(process->state->t != t){
+    g_warning("Different interrupt type: ignore it\n");
+    return;
+  }
   g_array_remove_index(process->interrupt_stack, depth);
   depth--;
   process->state = &g_array_index(process->interrupt_stack, LttvInterruptState,
@@ -306,6 +317,7 @@ LttvProcessState *create_process(LttvTracefileState *tfs,
 
   g_hash_table_insert(tcs->processes, GUINT_TO_POINTER(pid), process);
   process->pid = pid;
+  if(parent) process->ppid = parent->pid;
   process->birth = tfc->timestamp;
   process->name = LTTV_STATE_UNNAMED;
   process->interrupt_stack = g_array_new(FALSE, FALSE, 
@@ -318,6 +330,8 @@ LttvProcessState *create_process(LttvTracefileState *tfs,
   intr->entry = tfc->timestamp;
   intr->last_change = tfc->timestamp;
   intr->s = LTTV_STATE_WAIT_FORK;
+
+  return process;
 }
 
 
@@ -424,14 +438,17 @@ gboolean schedchange(void *hook_data, void *call_data)
 
   guint pid_in, pid_out, state_out;
 
-  pid_in = ltt_event_get_int(s->parent.e, h->f1);
-  pid_out = ltt_event_get_int(s->parent.e, h->f2);
-  state_out = ltt_event_get_int(s->parent.e, h->f3);
+  pid_in = ltt_event_get_unsigned(s->parent.e, h->f1);
+  pid_out = ltt_event_get_unsigned(s->parent.e, h->f2);
+  state_out = ltt_event_get_unsigned(s->parent.e, h->f3);
   if(s->process != NULL) {
     if(state_out == 0) s->process->state->s = LTTV_STATE_WAIT_CPU;
     else if(s->process->state->s == LTTV_STATE_EXIT) 
         exit_process(s, s->process);
     else s->process->state->s = LTTV_STATE_WAIT;
+
+    if(s->process->pid == 0)
+      s->process->pid == pid_out;
   }
   s->process = find_process(s, pid_in);
   s->process->state->s = LTTV_STATE_RUN;
@@ -447,7 +464,7 @@ gboolean process_fork(void *hook_data, void *call_data)
 
   guint child_pid;
 
-  child_pid = ltt_event_get_int(s->parent.e, f);
+  child_pid = ltt_event_get_unsigned(s->parent.e, f);
   create_process(s, s->process, child_pid);
   return FALSE;
 }
@@ -512,7 +529,7 @@ find_hook(LttTrace *t, char *facility, char *event,
   et = ltt_facility_eventtype_get_by_name(f, event);
   if(et == NULL) g_error("Event %s does not exist", event);
 
-  hook_id.id = *(ltt_eventtype_id(et)); /* CHECK */
+  hook_id.id = ltt_eventtype_id(et);
   hook_id.h = h;
   hook_id.free_hook_data = FALSE;
   hook_data.f1 = find_field(et, field1);
@@ -560,36 +577,53 @@ lttv_state_add_event_hooks(LttvTracesetState *self)
        associated by id hooks. */
 
     hooks = g_array_new(FALSE, FALSE, sizeof(struct HookId));
-    g_array_add(hooks, find_hook(ts->parent.t, "core","syscall_entry", 
-        "syscall_id", NULL, NULL, syscall_entry));
-    g_array_add(hooks, find_hook(ts->parent.t, "core", "syscall_exit", 
-        NULL, NULL, NULL, syscall_exit));
-    g_array_add(hooks, find_hook(ts->parent.t, "core", "trap_entry", "trap_id",
-        NULL, NULL, trap_entry));
-    g_array_add(hooks, find_hook(ts->parent.t, "core", "trap_exit", NULL, NULL,
-        NULL, trap_exit));
-    g_array_add(hooks, find_hook(ts->parent.t, "core", "irq_entry", "irq_id",
-        NULL, NULL, irq_entry));
-    g_array_add(hooks, find_hook(ts->parent.t, "core", "irq_exit", NULL, NULL,
-        NULL, irq_exit));
-    g_array_add(hooks, find_hook(ts->parent.t, "core", "schedchange", 
-        "in", "out", "out_state", schedchange));
-    g_array_add(hooks, find_hook(ts->parent.t, "core", "process_fork", 
-        "child_pid", NULL, NULL, process_fork));
-    g_array_add(hooks, find_hook(ts->parent.t, "core", "process_exit", 
-        NULL, NULL, NULL, process_exit));
+    hook_id = find_hook(ts->parent.t, "core","syscall_entry","syscall_id", 
+                       NULL, NULL, syscall_entry);
+    g_array_append_val(hooks, hook_id);
+
+    hook_id = find_hook(ts->parent.t, "core", "syscall_exit", 
+                       NULL, NULL, NULL, syscall_exit);
+    g_array_append_val(hooks, hook_id);
+
+    hook_id = find_hook(ts->parent.t, "core", "trap_entry", "trap_id",
+                       NULL, NULL, trap_entry);
+    g_array_append_val(hooks, hook_id);
+
+    hook_id = find_hook(ts->parent.t, "core", "trap_exit", NULL, NULL,
+                       NULL, trap_exit);
+    g_array_append_val(hooks, hook_id);
+
+    hook_id = find_hook(ts->parent.t, "core", "irq_entry", "irq_id",
+                       NULL, NULL, irq_entry);
+    g_array_append_val(hooks, hook_id);
+
+    hook_id = find_hook(ts->parent.t, "core", "irq_exit", NULL, NULL,
+                       NULL, irq_exit);
+    g_array_append_val(hooks, hook_id);
+
+    hook_id = find_hook(ts->parent.t, "core", "schedchange", 
+                       "in", "out", "out_state", schedchange);
+    g_array_append_val(hooks, hook_id);
+
+    hook_id = find_hook(ts->parent.t, "core", "process_fork", 
+                       "child_pid", NULL, NULL, process_fork);
+    g_array_append_val(hooks, hook_id);
+
+    hook_id = find_hook(ts->parent.t, "core", "process_exit", 
+                       NULL, NULL, NULL, process_exit);
+    g_array_append_val(hooks, hook_id);
 
     /* Add these hooks to each before_event_by_id hooks list */
 
     nb_control = ltt_trace_control_tracefile_number(ts->parent.t);
-    nb_per_cpu = ltt_trace_control_tracefile_number(ts->parent.t);
+    nb_per_cpu = ltt_trace_per_cpu_tracefile_number(ts->parent.t);
     nb_tracefile = nb_control + nb_per_cpu;
     for(j = 0 ; j < nb_tracefile ; j++) {
       if(j < nb_control) {
         tfs = LTTV_TRACEFILE_STATE(ts->parent.control_tracefiles[j]);
       }
       else {
-        tfs = LTTV_TRACEFILE_STATE(ts->parent.per_cpu_tracefiles[j]);
+        tfs = LTTV_TRACEFILE_STATE(ts->parent.per_cpu_tracefiles[j-nb_control]);
       }
 
       for(k = 0 ; k < hooks->len ; k++) {
@@ -631,14 +665,14 @@ lttv_state_remove_event_hooks(LttvTracesetState *self)
     /* Add these hooks to each before_event_by_id hooks list */
 
     nb_control = ltt_trace_control_tracefile_number(ts->parent.t);
-    nb_per_cpu = ltt_trace_control_tracefile_number(ts->parent.t);
+    nb_per_cpu = ltt_trace_per_cpu_tracefile_number(ts->parent.t);
     nb_tracefile = nb_control + nb_per_cpu;
     for(j = 0 ; j < nb_tracefile ; j++) {
       if(j < nb_control) {
         tfs = LTTV_TRACEFILE_STATE(ts->parent.control_tracefiles[j]);
       }
       else {
-        tfs = LTTV_TRACEFILE_STATE(ts->parent.per_cpu_tracefiles[j]);
+        tfs = LTTV_TRACEFILE_STATE(ts->parent.per_cpu_tracefiles[j-nb_control]);
       }
 
       for(k = 0 ; k < hooks->len ; k++) {
@@ -646,12 +680,12 @@ lttv_state_remove_event_hooks(LttvTracesetState *self)
         lttv_hooks_remove_data(
             lttv_hooks_by_id_find(tfs->parent.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);
   }
This page took 0.027486 seconds and 4 git commands to generate.