cpu column added
[lttv.git] / ltt / branches / poly / lttv / lttv / state.c
index aa204e8a01d89a4145b44ac585bee5908a1605e6..e96247403559b6455ce010745ecbcc9db9f5500d 100644 (file)
@@ -41,7 +41,7 @@ LttvProcessStatus
   LTTV_STATE_UNNAMED,
   LTTV_STATE_WAIT_FORK,
   LTTV_STATE_WAIT_CPU,
-  LTTV_STATE_EXIT,
+  LTTV_STATE_ZOMBIE,
   LTTV_STATE_WAIT,
   LTTV_STATE_RUN;
 
@@ -814,27 +814,20 @@ lttv_state_create_process(LttvTracefileState *tfs, LttvProcessState *parent,
   return process;
 }
 
-LttvProcessState *
-lttv_state_find_process_from_trace(LttvTraceState *ts, GQuark cpu, guint pid)
+LttvProcessState *lttv_state_find_process(LttvTracefileState *tfs, 
+    guint pid)
 {
   LttvProcessState key;
   LttvProcessState *process;
 
+  LttvTraceState* ts = (LttvTraceState*)tfs->parent.t_context;
+
   key.pid = pid;
-  key.last_cpu = cpu;
+  key.last_cpu = tfs->cpu_name;
   process = g_hash_table_lookup(ts->processes, &key);
   return process;
 }
 
-
-LttvProcessState *lttv_state_find_process(LttvTracefileState *tfs, 
-    guint pid)
-{
-  LttvTraceState *ts =(LttvTraceState *)tfs->parent.t_context;
-  return lttv_state_find_process_from_trace(ts, tfs->cpu_name, pid);
-}
-
-
 LttvProcessState *
 lttv_state_find_process_or_create(LttvTracefileState *tfs, guint pid)
 {
@@ -844,7 +837,13 @@ lttv_state_find_process_or_create(LttvTracefileState *tfs, guint pid)
   return process;
 }
 
-
+/* FIXME : this function should be called when we receive an event telling that
+ * release_task has been called in the kernel. In happens generally when
+ * the parent waits for its child terminaison, but may also happen in special
+ * cases in the child's exit : when the parent ignores its children SIGCCHLD or
+ * has the flag SA_NOCLDWAIT. It can also happen when the child is part
+ * of a killed thread ground, but isn't the leader.
+ */
 static void exit_process(LttvTracefileState *tfs, LttvProcessState *process) 
 {
   LttvTraceState *ts = LTTV_TRACE_STATE(tfs->parent.t_context);
@@ -970,10 +969,16 @@ static gboolean schedchange(void *hook_data, void *call_data)
       g_assert(s->process->pid == 0);
     }
 
-    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->state->s != LTTV_STATE_ZOMBIE) {
+      if(state_out == 0) s->process->state->s = LTTV_STATE_WAIT_CPU;
+      else s->process->state->s = LTTV_STATE_WAIT;
+    } /* FIXME : we do not remove process here, because the kernel
+       * still has them : they may be zombies. We need to know
+       * exactly when release_task is executed on the PID to 
+       * know when the zombie is destroyed.
+       */
+    //else
+    //  exit_process(s, s->process);
 
     s->process->state->change = s->parent.timestamp;
   }
@@ -989,43 +994,32 @@ static gboolean process_fork(LttvTraceHook *trace_hook, LttvTracefileState *s)
 {
   LttField *f;
   guint child_pid;
+  LttvProcessState *zombie_process;
 
   /* Child PID */
   f = trace_hook->f2;
   child_pid = ltt_event_get_unsigned(s->parent.e, f);
 
-  lttv_state_create_process(s, s->process, child_pid);
+  zombie_process = lttv_state_find_process(s, child_pid);
 
-  return FALSE;
-#if 0
-  LttField *f = ((LttvTraceHook *)hook_data)->f1;
-
-  LttvTracefileState *s = (LttvTracefileState *)call_data;
-
-  guint child_pid;
-
-  child_pid = ltt_event_get_unsigned(s->parent.e, f);
+  if(zombie_process != NULL) {
+    /* Reutilisation of PID. Only now we are sure that the old PID
+     * has been released. FIXME : sould know when release_task happens instead.
+     */
+    exit_process(s, zombie_process);
+  }
   lttv_state_create_process(s, s->process, child_pid);
+
   return FALSE;
-#endif //0
 }
 
 
 static gboolean process_exit(LttvTraceHook *trace_hook, LttvTracefileState *s)
 {
   if(s->process != NULL) {
-    s->process->state->s = LTTV_STATE_EXIT;
-  }
-  return FALSE;
-#if 0
-  LttvTracefileState *s = (LttvTracefileState *)call_data;
-
-  if(s->process != NULL) {
-    s->process->state->s = LTTV_STATE_EXIT;
+    s->process->state->s = LTTV_STATE_ZOMBIE;
   }
   return FALSE;
-#endif //0
 }
 
 gboolean process(void *hook_data, void *call_data)
@@ -1577,7 +1571,7 @@ static void module_init()
   LTTV_STATE_SUBMODE_UNKNOWN = g_quark_from_string("unknown submode");
   LTTV_STATE_SUBMODE_NONE = g_quark_from_string("(no submode)");
   LTTV_STATE_WAIT_CPU = g_quark_from_string("wait for cpu");
-  LTTV_STATE_EXIT = g_quark_from_string("exiting");
+  LTTV_STATE_ZOMBIE = g_quark_from_string("zombie");
   LTTV_STATE_WAIT = g_quark_from_string("wait for I/O");
   LTTV_STATE_RUN = g_quark_from_string("running");
   LTTV_STATE_TRACEFILES = g_quark_from_string("tracefiles");
This page took 0.024519 seconds and 4 git commands to generate.