fix memleak
[lttv.git] / ltt / branches / poly / lttv / modules / gui / controlflow / eventhooks.c
index e5b66cc9722b438059ed23d72dbcd74084c7bfe7..a31234c633dd893f77217e1f6342d671d04f265d 100644 (file)
@@ -69,6 +69,7 @@
 #include <lttv/state.h>
 #include <lttvwindow/lttvwindow.h>
 #include <lttvwindow/lttvwindowtraces.h>
+#include <lttvwindow/support.h>
 
 
 #include "eventhooks.h"
@@ -79,6 +80,8 @@
 
 #define MAX_PATH_LEN 256
 
+extern GSList *g_legend_list;
+
 #if 0
 typedef struct _ProcessAddClosure {
   ControlFlowData *cfd;
@@ -256,13 +259,53 @@ h_guicontrolflow(Tab *tab)
   lttvwindow_register_continue_notify(tab,
                                       continue_notify,
                                       control_flow_data);
-  //request_background_data(control_flow_data);
+  request_background_data(control_flow_data);
   
 
   return guicontrolflow_get_widget(control_flow_data) ;
   
 }
 
+void legend_destructor(GtkWindow *legend)
+{
+  g_legend_list = g_slist_remove(g_legend_list, legend);
+}
+
+/* Create a popup legend */
+GtkWidget *
+h_legend(Tab *tab)
+{
+  g_info("h_legend, %p", tab);
+
+  GtkWindow *legend = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
+  g_legend_list = g_slist_append(
+      g_legend_list,
+      legend);
+  g_object_set_data_full(
+      G_OBJECT(legend),
+      "legend",
+      legend,
+      (GDestroyNotify)legend_destructor);
+  
+  gtk_window_set_title(legend, "Control Flow View Legend");
+
+  GtkWidget *pixmap = create_pixmap(GTK_WIDGET(legend), "lttv-color-list.png");
+  
+ // GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixmap(
+ //                               GDK_PIXMAP(pixmap), NULL));
+  
+  gtk_container_add(GTK_CONTAINER(legend), GTK_WIDGET(pixmap));
+
+  gtk_widget_show(GTK_WIDGET(pixmap));
+  gtk_widget_show(GTK_WIDGET(legend));
+  
+
+  return NULL; /* This is a popup window */
+}
+
+
 int event_selected_hook(void *hook_data, void *call_data)
 {
   ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
@@ -385,6 +428,7 @@ int before_schedchange_hook(void *hook_data, void *call_data)
   LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
 
   LttvTracefileState *tfs = (LttvTracefileState *)call_data;
+  LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
 
   LttEvent *e;
   e = ltt_tracefile_get_event(tfc->tf);
@@ -410,12 +454,12 @@ int before_schedchange_hook(void *hook_data, void *call_data)
      * draw items from the beginning of the read for it. If it is not
      * present, it's a new process and it was not present : it will
      * be added after the state update.  */
-    LttvProcessState *process;
+    guint cpu = ltt_tracefile_num(tfc->tf);
+    LttvProcessState *process = ts->running_process[cpu];
     /* unknown state, bad current pid */
-    if(tfs->process->pid != pid_out)
-      process = lttv_state_find_process(tfs, pid_out);
-    else
-      process = tfs->process;
+    if(process->pid != pid_out)
+      process = lttv_state_find_process(ts,
+          ltt_tracefile_num(tfc->tf), pid_out);
     
     if(process != NULL) {
       /* Well, the process_out existed : we must get it in the process hash
@@ -429,24 +473,23 @@ int before_schedchange_hook(void *hook_data, void *call_data)
       
       hashed_process_data = processlist_get_process_data(process_list,
               pid_out,
-              process->last_cpu_index,
+              process->cpu,
               &birth,
               tfc->t_context->index);
       if(hashed_process_data == NULL)
       {
         g_assert(pid_out == 0 || pid_out != process->ppid);
-        const gchar *name = g_quark_to_string(process->name);
         /* Process not present */
         ProcessInfo *process_info;
         Drawing_t *drawing = control_flow_data->drawing;
         processlist_add(process_list,
             drawing,
             pid_out,
-            process->last_cpu_index,
+            process->cpu,
             process->ppid,
             &birth,
             tfc->t_context->index,
-            name,
+            process->name,
             &pl_height,
             &process_info,
             &hashed_process_data);
@@ -571,10 +614,11 @@ int before_schedchange_hook(void *hook_data, void *call_data)
      * present, it's a new process and it was not present : it will
      * be added after the state update.  */
     LttvProcessState *process;
-    process = lttv_state_find_process(tfs, pid_in);
+    process = lttv_state_find_process(ts,
+        ltt_tracefile_num(tfc->tf), pid_in);
     
     if(process != NULL) {
-      /* Well, the process_out existed : we must get it in the process hash
+      /* Well, the process existed : we must get it in the process hash
        * or add it, and draw its items.
        */
        /* Add process to process list (if not present) */
@@ -585,24 +629,23 @@ int before_schedchange_hook(void *hook_data, void *call_data)
       
       hashed_process_data = processlist_get_process_data(process_list,
               pid_in,
-              process->last_cpu_index,
+              process->cpu,
               &birth,
               tfc->t_context->index);
       if(hashed_process_data == NULL)
       {
         g_assert(pid_in == 0 || pid_in != process->ppid);
-        const gchar *name = g_quark_to_string(process->name);
         /* Process not present */
         ProcessInfo *process_info;
         Drawing_t *drawing = control_flow_data->drawing;
         processlist_add(process_list,
             drawing,
             pid_in,
-            process->last_cpu_index,
+            process->cpu,
             process->ppid,
             &birth,
             tfc->t_context->index,
-            name,
+            process->name,
             &pl_height,
             &process_info,
             &hashed_process_data);
@@ -1353,6 +1396,8 @@ int after_schedchange_hook(void *hook_data, void *call_data)
 
   LttvTracefileState *tfs = (LttvTracefileState *)call_data;
 
+  LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
+
   LttEvent *e;
   e = ltt_tracefile_get_event(tfc->tf);
 
@@ -1375,8 +1420,10 @@ int after_schedchange_hook(void *hook_data, void *call_data)
 
 
   /* Find process pid_in in the list... */
-  //process_in = lttv_state_find_process(tfs, pid_in);
-  process_in = tfs->process;
+  //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in);
+  //process_in = tfs->process;
+  guint cpu = ltt_tracefile_num(tfc->tf);
+  process_in = ts->running_process[cpu];
   /* It should exist, because we are after the state update. */
 #ifdef EXTRA_CHECK
   g_assert(process_in != NULL);
@@ -1385,24 +1432,23 @@ int after_schedchange_hook(void *hook_data, void *call_data)
 
   hashed_process_data_in = processlist_get_process_data(process_list,
           pid_in,
-          process_in->last_cpu_index,
+          process_in->cpu,
           &birth,
           tfc->t_context->index);
   if(hashed_process_data_in == NULL)
   {
     g_assert(pid_in == 0 || pid_in != process_in->ppid);
-    const gchar *name = g_quark_to_string(process_in->name);
     ProcessInfo *process_info;
     Drawing_t *drawing = control_flow_data->drawing;
     /* Process not present */
     processlist_add(process_list,
         drawing,
         pid_in,
-        process_in->last_cpu_index,
+        process_in->cpu,
         process_in->ppid,
         &birth,
         tfc->t_context->index,
-        name,
+        process_in->name,
         &pl_height,
         &process_info,
         &hashed_process_data_in);
@@ -1412,7 +1458,7 @@ int after_schedchange_hook(void *hook_data, void *call_data)
         gtk_widget_queue_draw(drawing->drawing_area);
   }
   /* Set the current process */
-  process_list->current_hash_data[process_in->last_cpu_index] =
+  process_list->current_hash_data[process_in->cpu] =
                                              hashed_process_data_in;
 
   if(ltt_time_compare(hashed_process_data_in->next_good_time,
@@ -1960,6 +2006,8 @@ int before_execmode_hook(void *hook_data, void *call_data)
 
   LttvTracefileState *tfs = (LttvTracefileState *)call_data;
 
+  LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
+
   LttEvent *e;
   e = ltt_tracefile_get_event(tfc->tf);
 
@@ -1970,7 +2018,9 @@ int before_execmode_hook(void *hook_data, void *call_data)
    * time to do it.
    */
   /* For the pid */
-  LttvProcessState *process = tfs->process;
+  //LttvProcessState *process = tfs->process;
+  guint cpu = ltt_tracefile_num(tfc->tf);
+  LttvProcessState *process = ts->running_process[cpu];
   g_assert(process != NULL);
 
   guint pid = process->pid;
@@ -1984,12 +2034,12 @@ int before_execmode_hook(void *hook_data, void *call_data)
   ProcessList *process_list = control_flow_data->process_list;
   LttTime birth = process->creation_time;
  
-  if(likely(process_list->current_hash_data[ltt_tracefile_num(tfc->tf)] != NULL)) {
-    hashed_process_data = process_list->current_hash_data[ltt_tracefile_num(tfc->tf)];
+  if(likely(process_list->current_hash_data[cpu] != NULL)) {
+    hashed_process_data = process_list->current_hash_data[cpu];
   } else {
     hashed_process_data = processlist_get_process_data(process_list,
             pid,
-            process->last_cpu_index,
+            process->cpu,
             &birth,
             tfc->t_context->index);
     if(unlikely(hashed_process_data == NULL))
@@ -1998,15 +2048,14 @@ int before_execmode_hook(void *hook_data, void *call_data)
       ProcessInfo *process_info;
       /* Process not present */
       Drawing_t *drawing = control_flow_data->drawing;
-      const gchar *name = g_quark_to_string(process->name);
       processlist_add(process_list,
           drawing,
           pid,
-          process->last_cpu_index,
+          process->cpu,
           process->ppid,
           &birth,
           tfc->t_context->index,
-          name,
+          process->name,
           &pl_height,
           &process_info,
           &hashed_process_data);
@@ -2016,7 +2065,7 @@ int before_execmode_hook(void *hook_data, void *call_data)
         gtk_widget_queue_draw(drawing->drawing_area);
     }
     /* Set the current process */
-    process_list->current_hash_data[process->last_cpu_index] =
+    process_list->current_hash_data[process->cpu] =
                                                hashed_process_data;
   }
 
@@ -2139,6 +2188,7 @@ int before_execmode_hook(void *hook_data, void *call_data)
  * This function adds items to be drawn in a queue for each process.
  * 
  */
+#if 0
 int after_execmode_hook(void *hook_data, void *call_data)
 {
   /**************** DOES NOTHING!! *************/
@@ -2241,7 +2291,7 @@ int after_execmode_hook(void *hook_data, void *call_data)
   }
   return 0;
 }
-
+#endif //0
 
 
 
@@ -2268,13 +2318,17 @@ int before_process_exit_hook(void *hook_data, void *call_data)
 
   LttvTracefileState *tfs = (LttvTracefileState *)call_data;
 
+  LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
+
   LttEvent *e;
   e = ltt_tracefile_get_event(tfc->tf);
 
   LttTime evtime = ltt_event_time(e);
 
   /* Add process to process list (if not present) */
-  LttvProcessState *process = tfs->process;
+  //LttvProcessState *process = tfs->process;
+  guint cpu = ltt_tracefile_num(tfc->tf);
+  LttvProcessState *process = ts->running_process[cpu];
   guint pid = process->pid;
   LttTime birth;
   guint pl_height = 0;
@@ -2286,12 +2340,12 @@ int before_process_exit_hook(void *hook_data, void *call_data)
 
   birth = process->creation_time;
 
-  if(likely(process_list->current_hash_data[ltt_tracefile_num(tfc->tf)] != NULL)) {
-    hashed_process_data = process_list->current_hash_data[ltt_tracefile_num(tfc->tf)];
+  if(likely(process_list->current_hash_data[cpu] != NULL)) {
+    hashed_process_data = process_list->current_hash_data[cpu];
   } else {
     hashed_process_data = processlist_get_process_data(process_list,
           pid,
-          process->last_cpu_index,
+          process->cpu,
           &birth,
           tfc->t_context->index);
     if(unlikely(hashed_process_data == NULL))
@@ -2299,16 +2353,15 @@ int before_process_exit_hook(void *hook_data, void *call_data)
       g_assert(pid == 0 || pid != process->ppid);
       /* Process not present */
       Drawing_t *drawing = control_flow_data->drawing;
-      const gchar *name = g_quark_to_string(process->name);
       ProcessInfo *process_info;
       processlist_add(process_list,
           drawing,
           pid,
-          process->last_cpu_index,
+          process->cpu,
           process->ppid,
           &birth,
           tfc->t_context->index,
-          name,
+          process->name,
           &pl_height,
           &process_info,
           &hashed_process_data);
@@ -2454,6 +2507,8 @@ int before_process_release_hook(void *hook_data, void *call_data)
 
   LttvTracefileState *tfs = (LttvTracefileState *)call_data;
 
+  LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
+
   LttEvent *e;
   e = ltt_tracefile_get_event(tfc->tf);
 
@@ -2469,7 +2524,7 @@ int before_process_release_hook(void *hook_data, void *call_data)
   /* Don't care about the process if it's not in the state hash already :
    * that means a process that has never done anything in the trace and
    * unknown suddently gets destroyed : no state meaningful to show. */
-  LttvProcessState *process = lttv_state_find_process(tfs, pid);
+  LttvProcessState *process = lttv_state_find_process(ts, ANY_CPU, pid);
 
   if(process != NULL) {
     LttTime birth;
@@ -2484,7 +2539,7 @@ int before_process_release_hook(void *hook_data, void *call_data)
      * action done by the parent. */
     hashed_process_data = processlist_get_process_data(process_list,
           pid,
-          process->last_cpu_index,
+          process->cpu,
           &birth,
           tfc->t_context->index);
     if(unlikely(hashed_process_data == NULL))
@@ -2492,16 +2547,15 @@ int before_process_release_hook(void *hook_data, void *call_data)
       g_assert(pid == 0 || pid != process->ppid);
       /* Process not present */
       Drawing_t *drawing = control_flow_data->drawing;
-      const gchar *name = g_quark_to_string(process->name);
       ProcessInfo *process_info;
       processlist_add(process_list,
           drawing,
           pid,
-          process->last_cpu_index,
+          process->cpu,
           process->ppid,
           &birth,
           tfc->t_context->index,
-          name,
+          process->name,
           &pl_height,
           &process_info,
           &hashed_process_data);
@@ -2853,7 +2907,6 @@ int before_process_hook(void *hook_data, void *call_data)
         g_assert(pid == 0 || pid != process->ppid);
         /* Process not present */
         Drawing_t *drawing = control_flow_data->drawing;
-        const gchar *name = g_quark_to_string(process->name);
         ProcessInfo *process_info;
         processlist_add(process_list,
             drawing,
@@ -2862,7 +2915,7 @@ int before_process_hook(void *hook_data, void *call_data)
             process->ppid,
             &birth,
             tfc->t_context->index,
-            name,
+            process->name,
             &pl_height,
             &process_info,
             &hashed_process_data);
@@ -3009,6 +3062,8 @@ int after_process_fork_hook(void *hook_data, void *call_data)
 
   LttvTracefileState *tfs = (LttvTracefileState *)call_data;
 
+  LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
+
   LttEvent *e;
   e = ltt_tracefile_get_event(tfc->tf);
 
@@ -3028,7 +3083,7 @@ int after_process_fork_hook(void *hook_data, void *call_data)
   ProcessList *process_list = control_flow_data->process_list;
 
   /* Find child in the list... */
-  process_child = lttv_state_find_process(tfs, child_pid);
+  process_child = lttv_state_find_process(ts, ANY_CPU, child_pid);
   /* It should exist, because we are after the state update. */
   g_assert(process_child != NULL);
 
@@ -3038,7 +3093,7 @@ int after_process_fork_hook(void *hook_data, void *call_data)
    * on its child. */
   hashed_process_data_child = processlist_get_process_data(process_list,
           child_pid,
-          process_child->last_cpu_index,
+          process_child->cpu,
           &birth,
           tfc->t_context->index);
   if(likely(hashed_process_data_child == NULL))
@@ -3046,16 +3101,15 @@ int after_process_fork_hook(void *hook_data, void *call_data)
     g_assert(child_pid == 0 || child_pid != process_child->ppid);
     /* Process not present */
     Drawing_t *drawing = control_flow_data->drawing;
-    const gchar *name = g_quark_to_string(process_child->name);
     ProcessInfo *process_info;
     processlist_add(process_list,
         drawing,
         child_pid,
-        process_child->last_cpu_index,
+        process_child->cpu,
         process_child->ppid,
         &birth,
         tfc->t_context->index,
-        name,
+        process_child->name,
         &pl_height,
         &process_info,
         &hashed_process_data_child);
@@ -3128,13 +3182,21 @@ int after_process_exit_hook(void *hook_data, void *call_data)
 
   LttvTracefileState *tfs = (LttvTracefileState *)call_data;
 
+  LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
+
   LttEvent *e;
   e = ltt_tracefile_get_event(tfc->tf);
 
   LttTime evtime = ltt_event_time(e);
 
   /* Add process to process list (if not present) */
-  LttvProcessState *process = tfs->process;
+  //LttvProcessState *process = tfs->process;
+  guint cpu = ltt_tracefile_num(tfc->tf);
+  LttvProcessState *process = ts->running_process[cpu];
+
+  /* It should exist, because we are after the state update. */
+  g_assert(process != NULL);
+
   guint pid = process->pid;
   LttTime birth;
   guint pl_height = 0;
@@ -3142,17 +3204,14 @@ int after_process_exit_hook(void *hook_data, void *call_data)
 
   ProcessList *process_list = control_flow_data->process_list;
 
-  /* It should exist, because we are after the state update. */
-  g_assert(process != NULL);
-
   birth = process->creation_time;
 
-  if(likely(process_list->current_hash_data[ltt_tracefile_num(tfc->tf)] != NULL) ){
-    hashed_process_data = process_list->current_hash_data[ltt_tracefile_num(tfc->tf)];
+  if(likely(process_list->current_hash_data[cpu] != NULL) ){
+    hashed_process_data = process_list->current_hash_data[cpu];
   } else {
     hashed_process_data = processlist_get_process_data(process_list,
             pid,
-            process->last_cpu_index,
+            process->cpu,
             &birth,
             tfc->t_context->index);
     if(unlikely(hashed_process_data == NULL))
@@ -3160,16 +3219,15 @@ int after_process_exit_hook(void *hook_data, void *call_data)
       g_assert(pid == 0 || pid != process->ppid);
       /* Process not present */
       Drawing_t *drawing = control_flow_data->drawing;
-      const gchar *name = g_quark_to_string(process->name);
       ProcessInfo *process_info;
       processlist_add(process_list,
           drawing,
           pid,
-          process->last_cpu_index,
+          process->cpu,
           process->ppid,
           &birth,
           tfc->t_context->index,
-          name,
+          process->name,
           &pl_height,
           &process_info,
           &hashed_process_data);
@@ -3180,7 +3238,7 @@ int after_process_exit_hook(void *hook_data, void *call_data)
     }
 
     /* Set the current process */
-    process_list->current_hash_data[process->last_cpu_index] =
+    process_list->current_hash_data[process->cpu] =
                                              hashed_process_data;
   }
 
@@ -3425,6 +3483,78 @@ int after_process_hook(void *hook_data, void *call_data)
 }
 #endif //0
 
+/* Get the filename of the process to print */
+int after_fs_exec_hook(void *hook_data, void *call_data)
+{
+  LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data;
+  EventsRequest *events_request = (EventsRequest*)thf->hook_data;
+  ControlFlowData *control_flow_data = events_request->viewer_data;
+
+  LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
+
+  LttvTracefileState *tfs = (LttvTracefileState *)call_data;
+
+  LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
+
+  guint cpu = ltt_tracefile_num(tfc->tf);
+  LttvProcessState *process = ts->running_process[cpu];
+  g_assert(process != NULL);
+
+  guint pid = process->pid;
+
+  /* Well, the process_out existed : we must get it in the process hash
+   * or add it, and draw its items.
+   */
+   /* Add process to process list (if not present) */
+  guint pl_height = 0;
+  HashedProcessData *hashed_process_data = NULL;
+  ProcessList *process_list = control_flow_data->process_list;
+  LttTime birth = process->creation_time;
+  if(likely(process_list->current_hash_data[cpu] != NULL)) {
+    hashed_process_data = process_list->current_hash_data[cpu];
+  } else {
+    hashed_process_data = processlist_get_process_data(process_list,
+            pid,
+            process->cpu,
+            &birth,
+            tfc->t_context->index);
+    if(unlikely(hashed_process_data == NULL))
+    {
+      g_assert(pid == 0 || pid != process->ppid);
+      ProcessInfo *process_info;
+      /* Process not present */
+      Drawing_t *drawing = control_flow_data->drawing;
+      processlist_add(process_list,
+          drawing,
+          pid,
+          process->cpu,
+          process->ppid,
+          &birth,
+          tfc->t_context->index,
+          process->name,
+          &pl_height,
+          &process_info,
+          &hashed_process_data);
+        gtk_widget_set_size_request(drawing->drawing_area,
+                                    -1,
+                                    pl_height);
+        gtk_widget_queue_draw(drawing->drawing_area);
+    }
+    /* Set the current process */
+    process_list->current_hash_data[process->cpu] =
+                                               hashed_process_data;
+  }
+
+  processlist_set_name(process_list, process->name, hashed_process_data);
+
+  return 0;
+
+}
+
+
+
+
 gint update_time_window_hook(void *hook_data, void *call_data)
 {
   ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
@@ -3837,7 +3967,9 @@ void draw_closure(gpointer key, gpointer value, gpointer user_data)
     g_assert(lttv_traceset_number(tsc->ts) > 0);
 #endif //EXTRA_CHECK
     LttvTraceContext *tc = tsc->traces[process_info->trace_num];
+    LttvTraceState *ts = (LttvTraceState*)tc;
 
+#if 0
     //FIXME : optimize data structures.
     LttvTracefileState *tfs;
     LttvTracefileContext *tfc;
@@ -3851,13 +3983,13 @@ void draw_closure(gpointer key, gpointer value, gpointer user_data)
     }
     g_assert(i<tc->tracefiles->len);
     tfs = LTTV_TRACEFILE_STATE(tfc);
-
+#endif //0
  //   LttvTracefileState *tfs =
  //    (LttvTracefileState*)tsc->traces[process_info->trace_num]->
  //                        tracefiles[process_info->cpu];
  
     LttvProcessState *process;
-    process = lttv_state_find_process(tfs,
+    process = lttv_state_find_process(ts, process_info->cpu,
                                       process_info->pid);
 
     if(unlikely(process != NULL)) {
This page took 0.030905 seconds and 4 git commands to generate.