fix tree
[lttv.git] / ltt / branches / poly / lttv / modules / gui / controlflow / processlist.c
index 55c82b6f0586f8ed31fce60adee0f049c3aa294c..e49b74ac3f3a3caddb18946e0fbf5a10b5f5796d 100644 (file)
  * MA 02111-1307, USA.
  */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <gtk/gtk.h>
+#include <gdk/gdk.h>
 #include <glib.h>
 #include <string.h>
 #include <stdlib.h>
@@ -27,7 +32,6 @@
 #include "drawitem.h"
 
 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
-#define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
 
 /* Preallocated Size of the index_to_pixmap array */
 #define ALLOCATE_PROCESSES 1000
  *                       Methods to synchronize process list                 *
  *****************************************************************************/
 
-//static inline guint get_cpu_number_from_name(GQuark name);
-  
-/* Enumeration of the columns */
-enum
-{
-  PROCESS_COLUMN,
-  PID_COLUMN,
-  PPID_COLUMN,
-  CPU_COLUMN,
-  BIRTH_S_COLUMN,
-  BIRTH_NS_COLUMN,
-  TRACE_COLUMN,
-  N_COLUMNS
-};
-
 
 gint process_sort_func  ( GtkTreeModel *model,
         GtkTreeIter *it_a,
@@ -58,35 +47,41 @@ gint process_sort_func  ( GtkTreeModel *model,
         gpointer user_data)
 {
   gchar *a_name;
-  guint a_pid, a_ppid, a_cpu;
+  gchar *a_brand;
+  guint a_pid, a_tgid, a_ppid, a_cpu;
   gulong a_birth_s, a_birth_ns;
-  gulong a_trace;
+  guint a_trace;
 
   gchar *b_name;
-  guint b_pid, b_ppid, b_cpu;
+  gchar *b_brand;
+  guint b_pid, b_tgid, b_ppid, b_cpu;
   gulong b_birth_s, b_birth_ns;
-  gulong b_trace;
+  guint b_trace;
 
   gtk_tree_model_get(model,
            it_a,
-           0, &a_name,
-           1, &a_pid,
-           2, &a_ppid,
-           3, &a_cpu,
-           4, &a_birth_s,
-           5, &a_birth_ns,
-           6, &a_trace,
+           PROCESS_COLUMN, &a_name,
+           BRAND_COLUMN, &a_brand,
+           PID_COLUMN, &a_pid,
+           TGID_COLUMN, &a_tgid,
+           PPID_COLUMN, &a_ppid,
+           CPU_COLUMN, &a_cpu,
+           BIRTH_S_COLUMN, &a_birth_s,
+           BIRTH_NS_COLUMN, &a_birth_ns,
+           TRACE_COLUMN, &a_trace,
            -1);
 
   gtk_tree_model_get(model,
            it_b,
-           0, &b_name,
-           1, &b_pid,
-           2, &b_ppid,
-           3, &b_cpu,
-           4, &b_birth_s,
-           5, &b_birth_ns,
-           6, &b_trace,
+           PROCESS_COLUMN, &b_name,
+           BRAND_COLUMN, &b_brand,
+           PID_COLUMN, &b_pid,
+           TGID_COLUMN, &b_tgid,
+           PPID_COLUMN, &b_ppid,
+           CPU_COLUMN, &b_cpu,
+           BIRTH_S_COLUMN, &b_birth_s,
+           BIRTH_NS_COLUMN, &b_birth_ns,
+           TRACE_COLUMN, &b_trace,
            -1);
 
   
@@ -136,11 +131,11 @@ static gboolean process_list_equ_fct(gconstpointer a, gconstpointer b)
 
   if(likely(pa->pid != pb->pid))
     ret = FALSE;
-  else if(likely((pa->pid == 0 && (pa->cpu != pb->cpu))))
+  if(likely((pa->pid == 0 && (pa->cpu != pb->cpu))))
     ret = FALSE;
-  else if(unlikely(ltt_time_compare(pa->birth, pb->birth) != 0))
+  if(unlikely(ltt_time_compare(pa->birth, pb->birth) != 0))
     ret = FALSE;
-  else if(unlikely(pa->trace_num != pb->trace_num))
+  if(unlikely(pa->trace_num != pb->trace_num))
     ret = FALSE;
 
   return ret;
@@ -151,6 +146,32 @@ void destroy_hash_key(gpointer key);
 void destroy_hash_data(gpointer data);
 
 
+gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer data)
+{
+  ControlFlowData *control_flow_data = 
+      (ControlFlowData*)g_object_get_data(
+                G_OBJECT(widget),
+                "control_flow_data");
+  Drawing_t *drawing = control_flow_data->drawing;
+       unsigned int cell_height =
+               get_cell_height(GTK_TREE_VIEW(control_flow_data->process_list->process_list_widget));
+
+  switch(event->direction) {
+    case GDK_SCROLL_UP:
+      gtk_adjustment_set_value(control_flow_data->v_adjust,
+        gtk_adjustment_get_value(control_flow_data->v_adjust) - cell_height);
+      break;
+    case GDK_SCROLL_DOWN:
+      gtk_adjustment_set_value(control_flow_data->v_adjust,
+        gtk_adjustment_get_value(control_flow_data->v_adjust) + cell_height);
+      break;
+    default:
+      g_error("should only scroll up and down.");
+  }
+       return TRUE;
+}
+
+
 static void update_index_to_pixmap_each(ProcessInfo *key,
                                         HashedProcessData *value,
                                         ProcessList *process_list)
@@ -166,7 +187,7 @@ static void update_index_to_pixmap_each(ProcessInfo *key,
 }
 
 
-static void update_index_to_pixmap(ProcessList *process_list)
+void update_index_to_pixmap(ProcessList *process_list)
 {
   g_ptr_array_set_size(process_list->index_to_pixmap,
                        g_hash_table_size(process_list->process_hash));
@@ -288,7 +309,6 @@ void copy_pixmap_to_screen(ProcessList *process_list,
   if(process_list->index_to_pixmap->len == 0) return;
   guint cell_height = process_list->cell_height;
 
-  //cell_height = 24; //FIXME
   /* Get indexes */
   gint begin = floor(y/(double)cell_height);
   gint end = MIN(ceil((y+height)/(double)cell_height),
@@ -299,7 +319,8 @@ void copy_pixmap_to_screen(ProcessList *process_list,
     g_assert(i<process_list->index_to_pixmap->len);
     /* Render the pixmap to the screen */
     GdkPixmap *pixmap = 
-      (GdkPixmap*)g_ptr_array_index(process_list->index_to_pixmap, i);
+      //(GdkPixmap*)g_ptr_array_index(process_list->index_to_pixmap, i);
+      GDK_PIXMAP(g_ptr_array_index(process_list->index_to_pixmap, i));
 
     gdk_draw_drawable (dest,
         gc,
@@ -334,32 +355,36 @@ ProcessList *processlist_construct(void)
 
   /* Create the Process list */
   process_list->list_store = gtk_list_store_new (  N_COLUMNS,
+              G_TYPE_STRING,
               G_TYPE_STRING,
               G_TYPE_UINT,
               G_TYPE_UINT,
               G_TYPE_UINT,
+              G_TYPE_UINT,
               G_TYPE_ULONG,
               G_TYPE_ULONG,
-              G_TYPE_ULONG);
+              G_TYPE_UINT);
 
 
   process_list->process_list_widget = 
     gtk_tree_view_new_with_model
     (GTK_TREE_MODEL (process_list->list_store));
+
   g_object_unref (G_OBJECT (process_list->list_store));
 
-  gtk_tree_sortable_set_sort_func(
+  gtk_tree_sortable_set_default_sort_func(
       GTK_TREE_SORTABLE(process_list->list_store),
-      PID_COLUMN,
       process_sort_func,
       NULL,
       NULL);
-  
+
   gtk_tree_sortable_set_sort_column_id(
       GTK_TREE_SORTABLE(process_list->list_store),
-      PID_COLUMN,
+      GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
       GTK_SORT_ASCENDING);
-  
+
+
   process_list->process_hash = g_hash_table_new_full(
       process_list_hash_fct, process_list_equ_fct,
       destroy_hash_key, destroy_hash_data
@@ -375,6 +400,12 @@ ProcessList *processlist_construct(void)
   renderer = gtk_cell_renderer_text_new ();
   process_list->renderer = renderer;
 
+       gint vertical_separator;
+       gint tree_line_width;
+       gtk_widget_style_get (GTK_WIDGET (process_list->process_list_widget),
+                       "vertical-separator", &vertical_separator,
+                       "tree-line-width", &tree_line_width,
+                       NULL);
   gtk_cell_renderer_get_size(renderer,
       GTK_WIDGET(process_list->process_list_widget),
       NULL,
@@ -382,24 +413,51 @@ ProcessList *processlist_construct(void)
       NULL,
       NULL,
       &process_list->cell_height);
-  
+
+  process_list->cell_height += vertical_separator;
+  process_list->cell_height += tree_line_width;
+
   column = gtk_tree_view_column_new_with_attributes ( "Process",
                 renderer,
                 "text",
                 PROCESS_COLUMN,
                 NULL);
   gtk_tree_view_column_set_alignment (column, 0.0);
-  gtk_tree_view_column_set_fixed_width (column, 45);
+  gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
+  gtk_tree_view_column_set_resizable(column, TRUE);
   gtk_tree_view_append_column (
     GTK_TREE_VIEW (process_list->process_list_widget), column);
   
   process_list->button = column->button;
-  
+  column = gtk_tree_view_column_new_with_attributes ( "Brand",
+                renderer,
+                "text",
+                BRAND_COLUMN,
+                NULL);
+  gtk_tree_view_column_set_alignment (column, 0.0);
+  gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
+  gtk_tree_view_column_set_resizable(column, TRUE);
+  gtk_tree_view_append_column (
+    GTK_TREE_VIEW (process_list->process_list_widget), column);
+
   column = gtk_tree_view_column_new_with_attributes ( "PID",
                 renderer,
                 "text",
                 PID_COLUMN,
                 NULL);
+  gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
+  gtk_tree_view_column_set_resizable(column, TRUE);
+  gtk_tree_view_append_column (
+    GTK_TREE_VIEW (process_list->process_list_widget), column);
+
+  column = gtk_tree_view_column_new_with_attributes ( "TGID",
+                renderer,
+                "text",
+                TGID_COLUMN,
+                NULL);
+  gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
+  gtk_tree_view_column_set_resizable(column, TRUE);
   gtk_tree_view_append_column (
     GTK_TREE_VIEW (process_list->process_list_widget), column);
 
@@ -408,6 +466,8 @@ ProcessList *processlist_construct(void)
                 "text",
                 PPID_COLUMN,
                 NULL);
+  gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
+  gtk_tree_view_column_set_resizable(column, TRUE);
   gtk_tree_view_append_column (
     GTK_TREE_VIEW (process_list->process_list_widget), column);
   
@@ -416,6 +476,8 @@ ProcessList *processlist_construct(void)
                 "text",
                 CPU_COLUMN,
                 NULL);
+  gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
+  gtk_tree_view_column_set_resizable(column, TRUE);
   gtk_tree_view_append_column (
     GTK_TREE_VIEW (process_list->process_list_widget), column);
 
@@ -424,6 +486,8 @@ ProcessList *processlist_construct(void)
                 "text",
                 BIRTH_S_COLUMN,
                 NULL);
+  gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
+  gtk_tree_view_column_set_resizable(column, TRUE);
   gtk_tree_view_append_column (
     GTK_TREE_VIEW (process_list->process_list_widget), column);
 
@@ -434,6 +498,8 @@ ProcessList *processlist_construct(void)
                 "text",
                 BIRTH_NS_COLUMN,
                 NULL);
+  gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
+  gtk_tree_view_column_set_resizable(column, TRUE);
   gtk_tree_view_append_column (
     GTK_TREE_VIEW (process_list->process_list_widget), column);
 
@@ -442,6 +508,8 @@ ProcessList *processlist_construct(void)
                 "text",
                 TRACE_COLUMN,
                 NULL);
+  gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
+  gtk_tree_view_column_set_resizable(column, TRUE);
   gtk_tree_view_append_column (
     GTK_TREE_VIEW (process_list->process_list_widget), column);
 
@@ -483,8 +551,8 @@ static gboolean remove_hash_item(ProcessInfo *process_info,
 
   if(likely(process_list->current_hash_data != NULL)) {
     if(likely(hashed_process_data ==
-                process_list->current_hash_data[process_info->cpu]))
-      process_list->current_hash_data[process_info->cpu] = NULL;
+                process_list->current_hash_data[process_info->trace_num][process_info->cpu]))
+      process_list->current_hash_data[process_info->trace_num][process_info->cpu] = NULL;
   }
   return TRUE; /* remove the element from the hash table */
 }
@@ -517,14 +585,54 @@ void destroy_hash_data(gpointer data)
   g_free(data);
 }
 
+
+void processlist_set_name(ProcessList *process_list,
+    GQuark name,
+    HashedProcessData *hashed_process_data)
+{
+  gtk_list_store_set (  process_list->list_store, &hashed_process_data->y_iter,
+        PROCESS_COLUMN, g_quark_to_string(name),
+        -1);
+}
+
+void processlist_set_brand(ProcessList *process_list,
+    GQuark brand,
+    HashedProcessData *hashed_process_data)
+{
+  gtk_list_store_set (  process_list->list_store, &hashed_process_data->y_iter,
+        BRAND_COLUMN, g_quark_to_string(brand),
+        -1);
+}
+
+void processlist_set_tgid(ProcessList *process_list,
+    guint tgid,
+    HashedProcessData *hashed_process_data)
+{
+  gtk_list_store_set (  process_list->list_store, &hashed_process_data->y_iter,
+        TGID_COLUMN, tgid,
+        -1);
+}
+
+void processlist_set_ppid(ProcessList *process_list,
+    guint ppid,
+    HashedProcessData *hashed_process_data)
+{
+  gtk_list_store_set (  process_list->list_store, &hashed_process_data->y_iter,
+        PPID_COLUMN, ppid,
+        -1);
+}
+
+
 int processlist_add(  ProcessList *process_list,
       Drawing_t *drawing,
       guint pid,
+      guint tgid,
       guint cpu,
       guint ppid,
       LttTime *birth,
       guint trace_num,
-      const gchar *name,
+      GQuark name,
+      GQuark brand,
       guint *height,
       ProcessInfo **pm_process_info,
       HashedProcessData **pm_hashed_process_data)
@@ -533,8 +641,9 @@ int processlist_add(  ProcessList *process_list,
   HashedProcessData *hashed_process_data = g_new(HashedProcessData, 1);
   *pm_hashed_process_data = hashed_process_data;
   *pm_process_info = Process_Info;
-  
   Process_Info->pid = pid;
+  Process_Info->tgid = tgid;
   if(pid == 0)
     Process_Info->cpu = cpu;
   else
@@ -565,8 +674,10 @@ int processlist_add(  ProcessList *process_list,
                           &hashed_process_data->y_iter);
 
   gtk_list_store_set (  process_list->list_store, &hashed_process_data->y_iter,
-        PROCESS_COLUMN, name,
+        PROCESS_COLUMN, g_quark_to_string(name),
+        BRAND_COLUMN, g_quark_to_string(brand),
         PID_COLUMN, pid,
+        TGID_COLUMN, tgid,
         PPID_COLUMN, ppid,
         CPU_COLUMN, cpu,
         BIRTH_S_COLUMN, birth->tv_sec,
@@ -585,7 +696,6 @@ int processlist_add(  ProcessList *process_list,
 
   hashed_process_data->height = process_list->cell_height;
 
-  //hashed_process_data->height = 24; // FIXME
   g_assert(hashed_process_data->height != 0);
 
   *height = hashed_process_data->height * process_list->number_of_process;
@@ -643,8 +753,8 @@ int processlist_remove( ProcessList *process_list,
         &process_info);
 
     if(likely(process_list->current_hash_data != NULL)) {
-      if(likely(hashed_process_data == process_list->current_hash_data[cpu])) {
-        process_list->current_hash_data[cpu] = NULL;
+      if(likely(hashed_process_data == process_list->current_hash_data[trace_num][cpu])) {
+        process_list->current_hash_data[trace_num][cpu] = NULL;
       }
     }
     
This page took 0.02773 seconds and 4 git commands to generate.