fix memleak
[lttv.git] / ltt / branches / poly / lttv / modules / gui / controlflow / eventhooks.c
index 9b96e42da2c183c518510c90b7b211aa2ae34d99..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;
@@ -263,6 +266,46 @@ h_guicontrolflow(Tab *tab)
   
 }
 
+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;
@@ -415,7 +458,8 @@ int before_schedchange_hook(void *hook_data, void *call_data)
     LttvProcessState *process = ts->running_process[cpu];
     /* unknown state, bad current pid */
     if(process->pid != pid_out)
-      process = lttv_state_find_process(ts, ANY_CPU, 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
@@ -435,7 +479,6 @@ int before_schedchange_hook(void *hook_data, void *call_data)
       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;
@@ -446,7 +489,7 @@ int before_schedchange_hook(void *hook_data, void *call_data)
             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(ts, ANY_CPU, 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) */
@@ -591,7 +635,6 @@ int before_schedchange_hook(void *hook_data, void *call_data)
       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;
@@ -602,7 +645,7 @@ int before_schedchange_hook(void *hook_data, void *call_data)
             process->ppid,
             &birth,
             tfc->t_context->index,
-            name,
+            process->name,
             &pl_height,
             &process_info,
             &hashed_process_data);
@@ -1395,7 +1438,6 @@ int after_schedchange_hook(void *hook_data, void *call_data)
   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 */
@@ -1406,7 +1448,7 @@ int after_schedchange_hook(void *hook_data, void *call_data)
         process_in->ppid,
         &birth,
         tfc->t_context->index,
-        name,
+        process_in->name,
         &pl_height,
         &process_info,
         &hashed_process_data_in);
@@ -2006,7 +2048,6 @@ 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,
@@ -2014,7 +2055,7 @@ int before_execmode_hook(void *hook_data, void *call_data)
           process->ppid,
           &birth,
           tfc->t_context->index,
-          name,
+          process->name,
           &pl_height,
           &process_info,
           &hashed_process_data);
@@ -2312,7 +2353,6 @@ 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,
@@ -2321,7 +2361,7 @@ int before_process_exit_hook(void *hook_data, void *call_data)
           process->ppid,
           &birth,
           tfc->t_context->index,
-          name,
+          process->name,
           &pl_height,
           &process_info,
           &hashed_process_data);
@@ -2507,7 +2547,6 @@ 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,
@@ -2516,7 +2555,7 @@ int before_process_release_hook(void *hook_data, void *call_data)
           process->ppid,
           &birth,
           tfc->t_context->index,
-          name,
+          process->name,
           &pl_height,
           &process_info,
           &hashed_process_data);
@@ -2868,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,
@@ -2877,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);
@@ -3063,7 +3101,6 @@ 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,
@@ -3072,7 +3109,7 @@ int after_process_fork_hook(void *hook_data, void *call_data)
         process_child->ppid,
         &birth,
         tfc->t_context->index,
-        name,
+        process_child->name,
         &pl_height,
         &process_info,
         &hashed_process_data_child);
@@ -3182,7 +3219,6 @@ 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,
@@ -3191,7 +3227,7 @@ int after_process_exit_hook(void *hook_data, void *call_data)
           process->ppid,
           &birth,
           tfc->t_context->index,
-          name,
+          process->name,
           &pl_height,
           &process_info,
           &hashed_process_data);
@@ -3447,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;
This page took 0.026115 seconds and 4 git commands to generate.