| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2003-2004 Mathieu Desnoyers |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License Version 2 as |
| 6 | * published by the Free Software Foundation; |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 16 | * MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | |
| 20 | |
| 21 | #ifndef _PROCESS_LIST_H |
| 22 | #define _PROCESS_LIST_H |
| 23 | |
| 24 | #include <gtk/gtk.h> |
| 25 | #include <lttv/state.h> |
| 26 | #include <ltt/ltt.h> |
| 27 | |
| 28 | #include "drawitem.h" |
| 29 | |
| 30 | /* The process list |
| 31 | * |
| 32 | * Tasks : |
| 33 | * Create a process list |
| 34 | * contains the data for the process list |
| 35 | * tells the height of the process list widget |
| 36 | * provides methods to add/remove process from the list |
| 37 | * note : the sync with drawing is left to the caller. |
| 38 | * provides helper function to convert a process unique identifier to |
| 39 | * pixels (in height). |
| 40 | * |
| 41 | * //FIXME : connect the scrolled window adjustment with the list. |
| 42 | */ |
| 43 | |
| 44 | typedef struct _ProcessInfo { |
| 45 | |
| 46 | guint pid; |
| 47 | guint cpu; |
| 48 | guint ppid; |
| 49 | LttTime birth; |
| 50 | guint trace_num; |
| 51 | |
| 52 | // gint height_cache; |
| 53 | |
| 54 | } ProcessInfo; |
| 55 | |
| 56 | typedef struct _HashedProcessData { |
| 57 | |
| 58 | GtkTreeIter y_iter; // Access quickly to y pos. |
| 59 | // DrawContext *draw_context; |
| 60 | /* Information on current drawing */ |
| 61 | struct { |
| 62 | guint over; |
| 63 | gboolean over_used; /* inform the user that information is incomplete */ |
| 64 | gboolean over_marked; /* inform the user that information is incomplete */ |
| 65 | guint middle; |
| 66 | gboolean middle_used; /* inform the user that information is incomplete */ |
| 67 | gboolean middle_marked;/* inform the user that information is incomplete */ |
| 68 | guint under; |
| 69 | gboolean under_used; /* inform the user that information is incomplete */ |
| 70 | gboolean under_marked; /* inform the user that information is incomplete */ |
| 71 | } x; /* last x position saved by after state update */ |
| 72 | |
| 73 | LttTime next_good_time; /* precalculate the next time where the next |
| 74 | pixel is.*/ |
| 75 | // FIXME : add info on last event ? |
| 76 | |
| 77 | } HashedProcessData; |
| 78 | |
| 79 | struct _ProcessList { |
| 80 | |
| 81 | GtkWidget *process_list_widget; |
| 82 | GtkListStore *list_store; |
| 83 | GtkWidget *button; /* one button of the tree view */ |
| 84 | |
| 85 | /* A hash table by PID to speed up process position find in the list */ |
| 86 | GHashTable *process_hash; |
| 87 | |
| 88 | guint number_of_process; |
| 89 | gint cell_height_cache; |
| 90 | |
| 91 | /* Current process, one per cpu */ |
| 92 | HashedProcessData **current_hash_data; |
| 93 | |
| 94 | }; |
| 95 | |
| 96 | |
| 97 | typedef struct _ProcessList ProcessList; |
| 98 | |
| 99 | ProcessList *processlist_construct(void); |
| 100 | void processlist_destroy(ProcessList *process_list); |
| 101 | GtkWidget *processlist_get_widget(ProcessList *process_list); |
| 102 | |
| 103 | void processlist_clear(ProcessList *process_list); |
| 104 | |
| 105 | // out : success (0) and height |
| 106 | /* CPU num is only used for PID 0 */ |
| 107 | int processlist_add(ProcessList *process_list, guint pid, guint cpu, guint ppid, |
| 108 | LttTime *birth, guint trace_num, const gchar *name, guint *height, |
| 109 | ProcessInfo **process_info, |
| 110 | HashedProcessData **hashed_process_data); |
| 111 | // out : success (0) and height |
| 112 | int processlist_remove(ProcessList *process_list, guint pid, guint cpu, |
| 113 | LttTime *birth, guint trace_num); |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | static inline gint get_cell_height(ProcessList *process_list, |
| 120 | GtkTreeView *tree_view) |
| 121 | { |
| 122 | gint height = process_list->cell_height_cache; |
| 123 | if(height != -1) return height; |
| 124 | else { |
| 125 | GtkTreeViewColumn *Column = gtk_tree_view_get_column(tree_view, 0); |
| 126 | |
| 127 | gtk_tree_view_column_cell_get_size(Column, NULL, NULL, NULL, NULL, |
| 128 | &process_list->cell_height_cache); |
| 129 | } |
| 130 | return process_list->cell_height_cache; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | |
| 135 | static inline guint processlist_get_height(ProcessList *process_list) |
| 136 | { |
| 137 | return get_cell_height(process_list, |
| 138 | (GtkTreeView*)process_list->process_list_widget) |
| 139 | * process_list->number_of_process ; |
| 140 | } |
| 141 | |
| 142 | |
| 143 | static inline HashedProcessData *processlist_get_process_data( |
| 144 | ProcessList *process_list, |
| 145 | guint pid, guint cpu, LttTime *birth, guint trace_num) |
| 146 | { |
| 147 | ProcessInfo process_info; |
| 148 | |
| 149 | process_info.pid = pid; |
| 150 | if(pid == 0) |
| 151 | process_info.cpu = cpu; |
| 152 | else |
| 153 | process_info.cpu = 0; |
| 154 | process_info.birth = *birth; |
| 155 | process_info.trace_num = trace_num; |
| 156 | |
| 157 | return (HashedProcessData*)g_hash_table_lookup( |
| 158 | process_list->process_hash, |
| 159 | &process_info); |
| 160 | } |
| 161 | |
| 162 | |
| 163 | static inline gint processlist_get_pixels_from_data( ProcessList *process_list, |
| 164 | HashedProcessData *hashed_process_data, |
| 165 | guint *y, |
| 166 | guint *height) |
| 167 | { |
| 168 | gint *path_indices; |
| 169 | GtkTreePath *tree_path; |
| 170 | |
| 171 | tree_path = gtk_tree_model_get_path((GtkTreeModel*)process_list->list_store, |
| 172 | &hashed_process_data->y_iter); |
| 173 | path_indices = gtk_tree_path_get_indices (tree_path); |
| 174 | |
| 175 | *height = get_cell_height(process_list, |
| 176 | (GtkTreeView*)process_list->process_list_widget); |
| 177 | *y = *height * path_indices[0]; |
| 178 | gtk_tree_path_free(tree_path); |
| 179 | |
| 180 | return 0; |
| 181 | |
| 182 | } |
| 183 | |
| 184 | |
| 185 | |
| 186 | #endif // _PROCESS_LIST_H |