| 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 | #ifndef _PROCESS_LIST_H |
| 20 | #define _PROCESS_LIST_H |
| 21 | |
| 22 | #include <gtk/gtk.h> |
| 23 | #include <gdk/gdk.h> |
| 24 | #include <lttv/state.h> |
| 25 | #include <ltt/ltt.h> |
| 26 | |
| 27 | #include "drawitem.h" |
| 28 | #include "cfv.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 | */ |
| 42 | |
| 43 | /* Unique identifiers for resource types */ |
| 44 | #define RV_RESOURCE_MACHINE 0 |
| 45 | #define RV_RESOURCE_CPU 1 |
| 46 | #define RV_RESOURCE_IRQ 2 |
| 47 | #define RV_RESOURCE_SOFT_IRQ 3 |
| 48 | #define RV_RESOURCE_TRAP 4 |
| 49 | #define RV_RESOURCE_BDEV 5 |
| 50 | #define RV_RESOURCE_COUNT 6 |
| 51 | |
| 52 | /* Enumeration of the columns */ |
| 53 | enum |
| 54 | { |
| 55 | NAME_COLUMN, |
| 56 | DATA_COLUMN, |
| 57 | N_COLUMNS |
| 58 | }; |
| 59 | |
| 60 | /* |
| 61 | typedef struct _ResourceInfo { |
| 62 | GQuark name; |
| 63 | guint trace_num; |
| 64 | guint type; |
| 65 | guint64 id; |
| 66 | } ResourceInfo; |
| 67 | */ |
| 68 | |
| 69 | struct _ResourceType { |
| 70 | /* a hashtable containing the data of each resource of this type */ |
| 71 | GHashTable *hash_table; |
| 72 | }; |
| 73 | typedef struct _ResourceType ResourceType; |
| 74 | |
| 75 | typedef struct _ResourceUnique { |
| 76 | ResourceType *type; |
| 77 | void *priv; |
| 78 | } ResourceUnique; |
| 79 | |
| 80 | typedef struct _ResourceUniqueNumeric { |
| 81 | ResourceUnique ru; |
| 82 | guint trace_num; |
| 83 | guint id; |
| 84 | } ResourceUniqueNumeric; |
| 85 | |
| 86 | typedef struct _HashedResourceData { |
| 87 | guint type; |
| 88 | |
| 89 | GdkPixmap *pixmap; // Pixmap slice containing drawing buffer for the PID |
| 90 | gint height; // height of the pixmap |
| 91 | GtkTreeIter y_iter; // Access quickly to y pos. |
| 92 | // DrawContext *draw_context; |
| 93 | /* Information on current drawing */ |
| 94 | struct { |
| 95 | guint over; |
| 96 | gboolean over_used; /* inform the user that information is incomplete */ |
| 97 | gboolean over_marked; /* inform the user that information is incomplete */ |
| 98 | guint middle; |
| 99 | gboolean middle_used; /* inform the user that information is incomplete */ |
| 100 | gboolean middle_marked;/* inform the user that information is incomplete */ |
| 101 | guint under; |
| 102 | gboolean under_used; /* inform the user that information is incomplete */ |
| 103 | gboolean under_marked; /* inform the user that information is incomplete */ |
| 104 | } x; /* last x position saved by after state update */ |
| 105 | |
| 106 | LttTime next_good_time; /* precalculate the next time where the next |
| 107 | pixel is.*/ |
| 108 | gint hidden; |
| 109 | |
| 110 | } HashedResourceData; |
| 111 | |
| 112 | struct _ProcessList { |
| 113 | |
| 114 | GtkWidget *process_list_widget; |
| 115 | GtkTreeStore *list_store; |
| 116 | GtkWidget *button; /* one button of the tree view */ |
| 117 | GtkCellRenderer *renderer; |
| 118 | |
| 119 | /* A hash table by PID to speed up process position find in the list */ |
| 120 | // GHashTable *process_hash; |
| 121 | |
| 122 | guint number_of_process; |
| 123 | gint cell_height; |
| 124 | |
| 125 | /* Current process pointer, one per cpu, one per trace */ |
| 126 | HashedResourceData ***current_hash_data; |
| 127 | |
| 128 | /* Array containing index -> pixmap correspondance. Must be updated |
| 129 | * every time the process list is reordered, process added or removed */ |
| 130 | GPtrArray * index_to_pixmap; |
| 131 | |
| 132 | ResourceType restypes[RV_RESOURCE_COUNT]; |
| 133 | }; |
| 134 | |
| 135 | typedef struct _UpdateIndexPixmapArg { |
| 136 | ProcessList *process_list; |
| 137 | guint count; |
| 138 | } UpdateIndexPixmapArg; |
| 139 | |
| 140 | #ifndef TYPE_PROCESSLIST_DEFINED |
| 141 | #define TYPE_PROCESSLIST_DEFINED |
| 142 | typedef struct _ProcessList ProcessList; |
| 143 | #endif //TYPE_PROCESSLIST_DEFINED |
| 144 | |
| 145 | |
| 146 | #ifndef TYPE_DRAWING_T_DEFINED |
| 147 | #define TYPE_DRAWING_T_DEFINED |
| 148 | typedef struct _Drawing_t Drawing_t; |
| 149 | #endif //TYPE_DRAWING_T_DEFINED |
| 150 | |
| 151 | ProcessList *processlist_construct(void); |
| 152 | void processlist_destroy(ProcessList *process_list); |
| 153 | GtkWidget *processlist_get_widget(ProcessList *process_list); |
| 154 | |
| 155 | void processlist_clear(ProcessList *process_list); |
| 156 | |
| 157 | // out : success (0) and height |
| 158 | /* CPU num is only used for PID 0 */ |
| 159 | //int resourcelist_add( ProcessList *process_list, Drawing_t *drawing, guint trace_num, |
| 160 | // GQuark name, guint type, guint id, guint *height, ResourceInfo **pm_resource_info, |
| 161 | // HashedResourceData **pm_hashed_resource_data, GQuark parent); |
| 162 | |
| 163 | // out : success (0) and height |
| 164 | int processlist_remove(ProcessList *process_list, guint pid, guint cpu, |
| 165 | LttTime *birth, guint trace_num); |
| 166 | |
| 167 | /* Set the name of a process */ |
| 168 | void processlist_set_name(ProcessList *process_list, |
| 169 | GQuark name, |
| 170 | HashedResourceData *hashed_process_data); |
| 171 | |
| 172 | void processlist_set_brand(ProcessList *process_list, |
| 173 | GQuark brand, |
| 174 | HashedResourceData *hashed_process_data); |
| 175 | |
| 176 | /* Set the ppid of a process */ |
| 177 | void processlist_set_tgid(ProcessList *process_list, |
| 178 | guint tgid, |
| 179 | HashedResourceData *hashed_process_data); |
| 180 | void processlist_set_ppid(ProcessList *process_list, |
| 181 | guint ppid, |
| 182 | HashedResourceData *hashed_process_data); |
| 183 | |
| 184 | |
| 185 | /* Synchronize the list at the left and the drawing */ |
| 186 | void update_index_to_pixmap(ProcessList *process_list); |
| 187 | |
| 188 | /* Update the width of each pixmap buffer for each process */ |
| 189 | void update_pixmap_size(ProcessList *process_list, guint width); |
| 190 | |
| 191 | |
| 192 | /* Put src and/or dest to NULL to copy from/to the each PID specific pixmap */ |
| 193 | void copy_pixmap_region(ProcessList *process_list, GdkDrawable *dest, |
| 194 | GdkGC *gc, GdkDrawable *src, |
| 195 | gint xsrc, gint ysrc, |
| 196 | gint xdest, gint ydest, gint width, gint height); |
| 197 | |
| 198 | /* If height is -1, the height of each pixmap is used */ |
| 199 | void rectangle_pixmap(ProcessList *process_list, GdkGC *gc, |
| 200 | gboolean filled, gint x, gint y, gint width, gint height); |
| 201 | |
| 202 | /* Renders each pixmaps into on big drawable */ |
| 203 | void copy_pixmap_to_screen(ProcessList *process_list, |
| 204 | GdkDrawable *dest, |
| 205 | GdkGC *gc, |
| 206 | gint x, gint y, |
| 207 | gint width, gint height); |
| 208 | |
| 209 | static inline gint get_cell_height(GtkTreeView *TreeView) |
| 210 | { |
| 211 | gint height; |
| 212 | GtkTreeViewColumn *column = gtk_tree_view_get_column(TreeView, 0); |
| 213 | |
| 214 | gtk_tree_view_column_cell_get_size(column, NULL, NULL, NULL, NULL, &height); |
| 215 | |
| 216 | gint vertical_separator; |
| 217 | gtk_widget_style_get (GTK_WIDGET (TreeView), |
| 218 | "vertical-separator", &vertical_separator, |
| 219 | NULL); |
| 220 | height += vertical_separator; |
| 221 | |
| 222 | return height; |
| 223 | } |
| 224 | |
| 225 | static inline guint processlist_get_height(ProcessList *process_list) |
| 226 | { |
| 227 | return process_list->cell_height * process_list->number_of_process ; |
| 228 | } |
| 229 | |
| 230 | |
| 231 | //static inline HashedResourceData *processlist_get_process_data( |
| 232 | // ProcessList *process_list, GQuark resource_name, guint trace_num) |
| 233 | //{ |
| 234 | // ResourceInfo resource_info; |
| 235 | // |
| 236 | //// process_info.pid = pid; |
| 237 | //// if(pid == 0) |
| 238 | //// process_info.cpu = cpu; |
| 239 | //// else |
| 240 | //// process_info.cpu = ANY_CPU; |
| 241 | //// process_info.birth = *birth; |
| 242 | //// process_info.trace_num = trace_num; |
| 243 | // resource_info.name = resource_name; |
| 244 | // resource_info.trace_num = trace_num; |
| 245 | // |
| 246 | // return (HashedResourceData*)g_hash_table_lookup( |
| 247 | // process_list->process_hash, |
| 248 | // &resource_info); |
| 249 | //} |
| 250 | // |
| 251 | |
| 252 | static inline gint processlist_get_pixels_from_data( ProcessList *process_list, |
| 253 | HashedResourceData *hashed_process_data, |
| 254 | guint *y, |
| 255 | guint *height) |
| 256 | { |
| 257 | gint *path_indices; |
| 258 | GtkTreePath *tree_path; |
| 259 | |
| 260 | tree_path = gtk_tree_model_get_path((GtkTreeModel*)process_list->list_store, |
| 261 | &hashed_process_data->y_iter); |
| 262 | path_indices = gtk_tree_path_get_indices (tree_path); |
| 263 | |
| 264 | *height = get_cell_height((GtkTreeView*)process_list->process_list_widget); |
| 265 | *y = *height * path_indices[0]; |
| 266 | gtk_tree_path_free(tree_path); |
| 267 | |
| 268 | return 0; |
| 269 | |
| 270 | } |
| 271 | |
| 272 | static inline guint processlist_get_index_from_data(ProcessList *process_list, |
| 273 | HashedResourceData *hashed_process_data) |
| 274 | { |
| 275 | gint *path_indices; |
| 276 | GtkTreePath *tree_path; |
| 277 | guint ret; |
| 278 | gint depth; |
| 279 | |
| 280 | tree_path = gtk_tree_model_get_path((GtkTreeModel*)process_list->list_store, |
| 281 | &hashed_process_data->y_iter); |
| 282 | path_indices = gtk_tree_path_get_indices (tree_path); |
| 283 | depth = gtk_tree_path_get_depth(tree_path); |
| 284 | |
| 285 | // ret = path_indices[1]+path_indices[0]+1; |
| 286 | ret = path_indices[0]; |
| 287 | if(depth>1) |
| 288 | ret+= 1+path_indices[1]; |
| 289 | |
| 290 | gtk_tree_path_free(tree_path); |
| 291 | |
| 292 | return ret; |
| 293 | } |
| 294 | |
| 295 | /* Return the hash table used to store the data of each resource of a given resource type */ |
| 296 | |
| 297 | static inline GHashTable *resourcelist_get_resource_hash_table(ControlFlowData *resourceview_data, guint type) |
| 298 | { |
| 299 | return resourceview_data->process_list->restypes[type].hash_table; |
| 300 | } |
| 301 | |
| 302 | HashedResourceData *resourcelist_obtain_cpu(ControlFlowData *resourceview_data, guint trace_num, guint id); |
| 303 | HashedResourceData *resourcelist_obtain_irq(ControlFlowData *resourceview_data, guint trace_num, guint id); |
| 304 | HashedResourceData *resourcelist_obtain_soft_irq(ControlFlowData *resourceview_data, guint trace_num, guint id); |
| 305 | HashedResourceData *resourcelist_obtain_trap(ControlFlowData *resourceview_data, guint trace_num, guint id); |
| 306 | HashedResourceData *resourcelist_obtain_bdev(ControlFlowData *resourceview_data, guint trace_num, guint id); |
| 307 | |
| 308 | #endif // _PROCESS_LIST_H |