state.c: fix statedump end fixup, add "print_stack()" helper
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 7 Apr 2010 15:31:36 +0000 (11:31 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 7 Apr 2010 15:31:36 +0000 (11:31 -0400)
Detect threads scheduled out from usermode and don't flag them as "syscall"
inappropriately.

Also add some debugging infrastructure for statedump end event (print_stack()).

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
lttv/lttv/state.c

index 27adae2c1abdd1a22322621c79bcee799411e286..25af4116000fc457adf4d7eff7f1d11b0f942bbd 100644 (file)
@@ -3313,6 +3313,25 @@ static gboolean fs_open(void *hook_data, void *call_data)
   return FALSE;
 }
 
+static void print_stack(LttvProcessState *process)
+{
+       LttvExecutionState *es;
+       int i;
+
+       g_debug("Execution stack for process %u %s:\n",
+               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);
+               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));
+       }
+
+}
+
 static void fix_process(gpointer key, gpointer value,
    gpointer user_data)
 {
@@ -3321,6 +3340,8 @@ static void fix_process(gpointer key, gpointer value,
   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) {
@@ -3345,21 +3366,28 @@ static void fix_process(gpointer key, gpointer value,
         es->s = LTTV_STATE_RUN;
 
       if(process->execution_stack->len == 1) {
-        /* Still in bottom unknown mode, means never did a system call
+        /* 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.*/
-       /* FIXME : we may be tagging syscall mode when being user mode */
-        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;
+       /* 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;
+       }
       }
     }
   }
This page took 0.027121 seconds and 4 git commands to generate.