control flow view works (state computation enabled) : has bugs with multiple cpus
[lttv.git] / ltt / branches / poly / lttv / lttv / state.c
index f2af9a37fa7fc76147d926ca745c643336103091..6ee5e32e1dc9d04a7cdbfbb0ad521e53789dd8ff 100644 (file)
@@ -179,7 +179,7 @@ restore_init_state(LttvTraceState *self)
     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 = ((LttvTracefileContext*)tfcs)->index;
+    tfcs->process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfcs)->tf);
   }
 }
 
@@ -204,7 +204,7 @@ init(LttvTracesetState *self, LttvTraceset *ts)
   nb_trace = lttv_traceset_number(ts);
   for(i = 0 ; i < nb_trace ; i++) {
     tc = self->parent.traces[i];
-    tcs = (LttvTraceState *)tc;
+    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);
@@ -372,7 +372,9 @@ static void copy_process_state(gpointer key, gpointer value,gpointer user_data)
   *new_process = *process;
   new_process->execution_stack = g_array_sized_new(FALSE, FALSE, 
       sizeof(LttvExecutionState), PREALLOCATED_EXECUTION_STACK);
-  g_array_set_size(new_process->execution_stack,process->execution_stack->len);
+  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);
@@ -436,9 +438,11 @@ static void state_save(LttvTraceState *self, LttvAttribute *container)
     *(value.v_uint) = tfcs->process->pid;
     value = lttv_attribute_add(tracefile_tree, LTTV_STATE_EVENT, 
         LTTV_POINTER);
-    LttEvent *e = ltt_tracefile_get_event(tfcs->parent.tf);
-    if(e == NULL) *(value.v_pointer) = NULL;
-    else {
+    /* Only save the position of the tfs is in the pqueue */
+    if(!g_tree_lookup(self->parent.ts_context->pqueue, &tfcs->parent)) {
+      *(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;
@@ -484,6 +488,9 @@ static void state_restore(LttvTraceState *self, LttvAttribute *container)
 
   nb_tracefile = self->parent.tracefiles->len;
 
+  g_tree_destroy(tsc->pqueue);
+  tsc->pqueue = g_tree_new(compare_tracefile);
   for(i = 0 ; i < nb_tracefile ; i++) {
     tfcs = 
           LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles,
@@ -501,18 +508,20 @@ static void state_restore(LttvTraceState *self, LttvAttribute *container)
     type = lttv_attribute_get_by_name(tracefile_tree, LTTV_STATE_EVENT, 
         &value);
     g_assert(type == LTTV_POINTER);
-    g_assert(*(value.v_pointer) != NULL);
+    //g_assert(*(value.v_pointer) != NULL);
     ep = *(value.v_pointer);
     g_assert(tfcs->parent.t_context != NULL);
     
-    g_tree_destroy(tsc->pqueue);
-    tsc->pqueue = g_tree_new(compare_tracefile);
-    
     LttvTracefileContext *tfc = LTTV_TRACEFILE_CONTEXT(tfcs);
     
-    g_assert(ltt_tracefile_seek_position(tfc->tf, ep) == 0);
-    tfc->timestamp = ltt_event_time(ltt_tracefile_get_event(tfc->tf));
-    g_tree_insert(tsc->pqueue, tfc, tfc);
+    if(ep != NULL) {
+      g_assert(ltt_tracefile_seek_position(tfc->tf, ep) == 0);
+      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(tsc->pqueue, tfc, tfc);
+    } else {
+      tfc->timestamp = ltt_time_infinite;
+    }
   }
 }
 
@@ -642,7 +651,7 @@ create_name_tables(LttvTraceState *tcs)
 
   GQuark f_name, e_name;
 
-  LttvTraceHook *h;
+  LttvTraceHook h;
 
   LttvTraceHookByFacility *thf;
 
@@ -675,15 +684,15 @@ create_name_tables(LttvTraceState *tcs)
   if(lttv_trace_find_hook(tcs->parent.t,
       LTT_FACILITY_KERNEL, LTT_EVENT_SYSCALL_ENTRY,
       LTT_FIELD_SYSCALL_ID, 0, 0,
-      NULL, h))
+      NULL, NULL, &h))
     return;
   
-  thf = lttv_trace_hook_get_first(h);
+  thf = lttv_trace_hook_get_first(&h);
   
   t = ltt_field_type(thf->f1);
   nb = ltt_type_element_number(t);
   
-  lttv_trace_hook_destroy(h);
+  lttv_trace_hook_destroy(&h);
 
   /* CHECK syscalls should be an enum but currently are not!  
   name_tables->syscall_names = g_new(GQuark, nb);
@@ -703,15 +712,15 @@ create_name_tables(LttvTraceState *tcs)
   if(lttv_trace_find_hook(tcs->parent.t, LTT_FACILITY_KERNEL,
         LTT_EVENT_TRAP_ENTRY,
         LTT_FIELD_TRAP_ID, 0, 0,
-        NULL, h))
+        NULL, NULL, &h))
     return;
 
-  thf = lttv_trace_hook_get_first(h);
+  thf = lttv_trace_hook_get_first(&h);
 
   t = ltt_field_type(thf->f1);
   nb = ltt_type_element_number(t);
 
-  lttv_trace_hook_destroy(h);
+  lttv_trace_hook_destroy(&h);
 
   /*
   name_tables->trap_names = g_new(GQuark, nb);
@@ -730,15 +739,15 @@ create_name_tables(LttvTraceState *tcs)
   if(lttv_trace_find_hook(tcs->parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_IRQ_ENTRY,
         LTT_FIELD_IRQ_ID, 0, 0,
-        NULL, h))
+        NULL, NULL, &h))
     return;
   
-  thf = lttv_trace_hook_get_first(h);
+  thf = lttv_trace_hook_get_first(&h);
   
   t = ltt_field_type(thf->f1);
   nb = ltt_type_element_number(t);
 
-  lttv_trace_hook_destroy(h);
+  lttv_trace_hook_destroy(&h);
 
   /*
   name_tables->irq_names = g_new(GQuark, nb);
@@ -794,7 +803,6 @@ free_name_tables(LttvTraceState *tcs)
   g_free(name_tables);
 } 
 
-
 static void push_state(LttvTracefileState *tfs, LttvExecutionMode t, 
     guint state_id)
 {
@@ -804,7 +812,12 @@ static void push_state(LttvTracefileState *tfs, LttvExecutionMode t,
 
   guint depth = process->execution_stack->len;
 
-  g_array_set_size(process->execution_stack, depth + 1);
+  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;
@@ -840,7 +853,8 @@ static void pop_state(LttvTracefileState *tfs, LttvExecutionMode t)
     return;
   }
 
-  g_array_set_size(process->execution_stack, depth - 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;
@@ -866,7 +880,7 @@ lttv_state_create_process(LttvTracefileState *tfs, LttvProcessState *parent,
        
   process->pid = pid;
   process->last_cpu = tfs->cpu_name;
-  process->last_cpu_index = ((LttvTracefileContext*)tfs)->index;
+  process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf);
   g_info("Process %u, core %p", process->pid, process);
   g_hash_table_insert(tcs->processes, process, process);
 
@@ -891,10 +905,10 @@ lttv_state_create_process(LttvTracefileState *tfs, LttvProcessState *parent,
          process->creation_time.tv_nsec);
   process->pid_time = g_quark_from_string(buffer);
   process->last_cpu = tfs->cpu_name;
-  process->last_cpu_index = ((LttvTracefileContext*)tfs)->index;
+  process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf);
   process->execution_stack = g_array_sized_new(FALSE, FALSE, 
       sizeof(LttvExecutionState), PREALLOCATED_EXECUTION_STACK);
-  g_array_set_size(process->execution_stack, 1);
+  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_USER_MODE;
@@ -1051,11 +1065,12 @@ static gboolean schedchange(void *hook_data, void *call_data)
   LttvTracefileState *s = (LttvTracefileState *)call_data;
   LttEvent *e = ltt_tracefile_get_event(s->parent.tf);
   LttvTraceHookByFacility *thf = (LttvTraceHookByFacility *)hook_data;
-  guint pid_in, pid_out, state_out;
+  guint pid_in, pid_out;
+  gint state_out;
 
   pid_out = ltt_event_get_unsigned(e, thf->f1);
   pid_in = ltt_event_get_unsigned(e, thf->f2);
-  state_out = ltt_event_get_unsigned(e, thf->f3);
+  state_out = ltt_event_get_int(e, thf->f3);
 
   if(likely(s->process != NULL)) {
 
@@ -1065,9 +1080,11 @@ static gboolean schedchange(void *hook_data, void *call_data)
        is missing. It is not obvious how we could, after the fact, compensate
        the wrongly attributed statistics. */
 
-    if(unlikely(s->process->pid != pid_out)) {
-      g_assert(s->process->pid == 0);
-    }
+    //This test only makes sense once the state is known and if there is no
+    //missing events.
+    //if(unlikely(s->process->pid != pid_out)) {
+    //  g_assert(s->process->pid == 0);
+    //}
 
     if(unlikely(s->process->state->s == LTTV_STATE_EXIT)) {
       s->process->state->s = LTTV_STATE_ZOMBIE;
@@ -1087,7 +1104,7 @@ static gboolean schedchange(void *hook_data, void *call_data)
   s->process = lttv_state_find_process_or_create(s, pid_in);
   s->process->state->s = LTTV_STATE_RUN;
   s->process->last_cpu = s->cpu_name;
-  s->process->last_cpu_index = ((LttvTracefileContext*)s)->index;
+  s->process->last_cpu_index = ltt_tracefile_num(((LttvTracefileContext*)s)->tf);
   s->process->state->change = s->parent.timestamp;
   return FALSE;
 }
@@ -1205,66 +1222,66 @@ void lttv_state_add_event_hooks(LttvTracesetState *self)
        associated by id hooks. */
 
     hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 10);
-    g_array_set_size(hooks, 10);
+    hooks = g_array_set_size(hooks, 10);
 
     ret = lttv_trace_find_hook(ts->parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_SYSCALL_ENTRY,
         LTT_FIELD_SYSCALL_ID, 0, 0,
-        syscall_entry, &g_array_index(hooks, LttvTraceHook, 0));
+        syscall_entry, NULL, &g_array_index(hooks, LttvTraceHook, 0));
     g_assert(!ret);
 
     ret = lttv_trace_find_hook(ts->parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_SYSCALL_EXIT,
         0, 0, 0,
-        syscall_exit, &g_array_index(hooks, LttvTraceHook, 1));
+        syscall_exit, NULL, &g_array_index(hooks, LttvTraceHook, 1));
     g_assert(!ret);
 
     ret = lttv_trace_find_hook(ts->parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_TRAP_ENTRY,
         LTT_FIELD_TRAP_ID, 0, 0,
-        trap_entry, &g_array_index(hooks, LttvTraceHook, 2));
+        trap_entry, NULL, &g_array_index(hooks, LttvTraceHook, 2));
     g_assert(!ret);
 
     ret = lttv_trace_find_hook(ts->parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_TRAP_EXIT,
         0, 0, 0, 
-        trap_exit, &g_array_index(hooks, LttvTraceHook, 3));
+        trap_exit, NULL, &g_array_index(hooks, LttvTraceHook, 3));
     g_assert(!ret);
 
     ret = lttv_trace_find_hook(ts->parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_IRQ_ENTRY,
         LTT_FIELD_IRQ_ID, 0, 0,
-        irq_entry, &g_array_index(hooks, LttvTraceHook, 4));
+        irq_entry, NULL, &g_array_index(hooks, LttvTraceHook, 4));
     g_assert(!ret);
 
     ret = lttv_trace_find_hook(ts->parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_IRQ_EXIT,
         0, 0, 0, 
-        irq_exit, &g_array_index(hooks, LttvTraceHook, 5));
+        irq_exit, NULL, &g_array_index(hooks, LttvTraceHook, 5));
     g_assert(!ret);
 
     ret = lttv_trace_find_hook(ts->parent.t,
         LTT_FACILITY_PROCESS, LTT_EVENT_SCHEDCHANGE,
         LTT_FIELD_OUT, LTT_FIELD_IN, LTT_FIELD_OUT_STATE,
-        schedchange, &g_array_index(hooks, LttvTraceHook, 6));
+        schedchange, NULL, &g_array_index(hooks, LttvTraceHook, 6));
     g_assert(!ret);
 
     ret = lttv_trace_find_hook(ts->parent.t,
         LTT_FACILITY_PROCESS, LTT_EVENT_FORK,
         LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID, 0,
-        process_fork, &g_array_index(hooks, LttvTraceHook, 7));
+        process_fork, NULL, &g_array_index(hooks, LttvTraceHook, 7));
     g_assert(!ret);
 
     ret = lttv_trace_find_hook(ts->parent.t,
         LTT_FACILITY_PROCESS, LTT_EVENT_EXIT,
         LTT_FIELD_PID, 0, 0,
-        process_exit, &g_array_index(hooks, LttvTraceHook, 8));
+        process_exit, NULL, &g_array_index(hooks, LttvTraceHook, 8));
     g_assert(!ret);
     
     ret = lttv_trace_find_hook(ts->parent.t,
         LTT_FACILITY_PROCESS, LTT_EVENT_FREE,
         LTT_FIELD_PID, 0, 0,
-        process_free, &g_array_index(hooks, LttvTraceHook, 9));
+        process_free, NULL, &g_array_index(hooks, LttvTraceHook, 9));
     g_assert(!ret);
 
 
@@ -1346,9 +1363,10 @@ void lttv_state_remove_event_hooks(LttvTracesetState *self)
                     thf->h,
                     thf);
         }
-        lttv_trace_hook_destroy(&g_array_index(hooks, LttvTraceHook, k));
       }
     }
+    for(k = 0 ; k < hooks->len ; k++)
+      lttv_trace_hook_destroy(&g_array_index(hooks, LttvTraceHook, k));
     g_array_free(hooks, TRUE);
   }
 }
@@ -1362,7 +1380,7 @@ static gboolean state_save_event_hook(void *hook_data, void *call_data)
   if(likely((*event_count)++ < LTTV_STATE_SAVE_INTERVAL))
     return FALSE;
   else
-    event_count = 0;
+    *event_count = 0;
   
   LttvTracefileState *self = (LttvTracefileState *)call_data;
 
@@ -1531,10 +1549,9 @@ void lttv_state_save_add_event_hooks(LttvTracesetState *self)
     ts = (LttvTraceState *)self->parent.traces[i];
     nb_tracefile = ts->parent.tracefiles->len;
 
-    guint *event_count = g_new(guint, 1);
-    *event_count = 0;
-
     for(j = 0 ; j < nb_tracefile ; j++) {
+      guint *event_count = g_new(guint, 1);
+      *event_count = 0;
       tfs = 
           LTTV_TRACEFILE_STATE(g_array_index(ts->parent.tracefiles,
                                           LttvTracefileContext*, j));
This page took 0.028973 seconds and 4 git commands to generate.