9e01e6d4 |
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 | #ifdef HAVE_CONFIG_H |
20 | #include <config.h> |
21 | #endif |
22 | |
23 | #include <gtk/gtk.h> |
24 | #include <gdk/gdk.h> |
25 | #include <glib.h> |
26 | #include <string.h> |
27 | #include <stdlib.h> |
28 | #include <math.h> |
29 | |
30 | #include "processlist.h" |
31 | #include "drawing.h" |
32 | #include "drawitem.h" |
33 | |
34 | #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format) |
58a9b31b |
35 | //#define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format) |
9e01e6d4 |
36 | |
37 | /* Preallocated Size of the index_to_pixmap array */ |
38 | #define ALLOCATE_PROCESSES 1000 |
39 | |
40 | /***************************************************************************** |
41 | * Methods to synchronize process list * |
42 | *****************************************************************************/ |
43 | |
44 | |
fb93b151 |
45 | gint resource_sort_func ( GtkTreeModel *model, |
46 | GtkTreeIter *it_a, |
47 | GtkTreeIter *it_b, |
48 | gpointer user_data) |
49 | { |
50 | gchar *a_name; |
51 | gchar *b_name; |
52 | |
53 | gtk_tree_model_get(model, it_a, NAME_COLUMN, &a_name, -1); |
54 | |
55 | gtk_tree_model_get(model, it_b, NAME_COLUMN, &b_name, -1); |
56 | |
57 | return strcmp(a_name, b_name); |
58 | } |
9e01e6d4 |
59 | |
67f72973 |
60 | static guint ru_numeric_hash_fct(gconstpointer key) |
9e01e6d4 |
61 | { |
d0e4ae2f |
62 | ResourceUniqueNumeric *ru = (ResourceUniqueNumeric *)key; |
67f72973 |
63 | int tmp = (ru->trace_num << 8) ^ ru->id; |
64 | |
65 | return g_int_hash(&tmp); |
9e01e6d4 |
66 | } |
67 | |
67f72973 |
68 | static gboolean ru_numeric_equ_fct(gconstpointer a, gconstpointer b) |
9e01e6d4 |
69 | { |
67f72973 |
70 | const ResourceUniqueNumeric *pa = (const ResourceUniqueNumeric *)a; |
71 | const ResourceUniqueNumeric *pb = (const ResourceUniqueNumeric *)b; |
9e01e6d4 |
72 | |
67f72973 |
73 | if(pa->id == pb->id && pa->trace_num == pb->trace_num) |
74 | return TRUE; |
9e01e6d4 |
75 | |
67f72973 |
76 | return FALSE; |
9e01e6d4 |
77 | } |
78 | |
79 | void destroy_hash_key(gpointer key); |
80 | |
81 | void destroy_hash_data(gpointer data); |
82 | |
83 | |
84 | gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer data) |
85 | { |
86 | ControlFlowData *control_flow_data = |
87 | (ControlFlowData*)g_object_get_data( |
88 | G_OBJECT(widget), |
67f72973 |
89 | "resourceview_data"); |
9e01e6d4 |
90 | Drawing_t *drawing = control_flow_data->drawing; |
91 | unsigned int cell_height = |
92 | get_cell_height(GTK_TREE_VIEW(control_flow_data->process_list->process_list_widget)); |
93 | |
94 | switch(event->direction) { |
95 | case GDK_SCROLL_UP: |
96 | gtk_adjustment_set_value(control_flow_data->v_adjust, |
97 | gtk_adjustment_get_value(control_flow_data->v_adjust) - cell_height); |
98 | break; |
99 | case GDK_SCROLL_DOWN: |
100 | gtk_adjustment_set_value(control_flow_data->v_adjust, |
101 | gtk_adjustment_get_value(control_flow_data->v_adjust) + cell_height); |
102 | break; |
103 | default: |
104 | g_error("should only scroll up and down."); |
105 | } |
106 | return TRUE; |
107 | } |
108 | |
27274b95 |
109 | void expand_event(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *arg2, gpointer user_data) |
110 | { |
111 | ControlFlowData *resourceview_data = |
112 | (ControlFlowData*)g_object_get_data( |
113 | G_OBJECT(treeview), |
114 | "resourceview_data"); |
115 | ProcessList *process_list = (ProcessList *) user_data; |
116 | ResourceUnique *rup; |
117 | HashedResourceData *hrd; |
118 | gboolean result; |
119 | |
120 | GtkTreeModel *model; |
121 | GtkTreeIter child; |
122 | |
123 | /* Determine which trace has been expanded */ |
124 | model = gtk_tree_view_get_model(treeview); |
125 | |
126 | /* mark each of the trace's resources invisible */ |
127 | result = gtk_tree_model_iter_children(model, &child, iter); |
128 | |
129 | /* for each child of the collapsed row */ |
130 | while(result) { |
131 | /* hide the item */ |
132 | gtk_tree_model_get(model, &child, DATA_COLUMN, &hrd, -1); |
133 | hrd->hidden=0; |
134 | |
135 | /* find next */ |
136 | result = gtk_tree_model_iter_next(model, &child); |
137 | } |
138 | |
139 | update_index_to_pixmap(process_list); |
140 | |
141 | gtk_widget_queue_draw(resourceview_data->drawing->drawing_area); |
142 | } |
143 | |
144 | void collapse_event(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *arg2, gpointer user_data) |
145 | { |
146 | ControlFlowData *resourceview_data = |
147 | (ControlFlowData*)g_object_get_data( |
148 | G_OBJECT(treeview), |
149 | "resourceview_data"); |
150 | ProcessList *process_list = (ProcessList *) user_data; |
151 | ResourceUnique *rup; |
152 | HashedResourceData *hrd; |
153 | gboolean result; |
154 | |
155 | GtkTreeModel *model; |
156 | GtkTreeIter child; |
157 | |
158 | /* Determine which trace has been expanded */ |
159 | model = gtk_tree_view_get_model(treeview); |
160 | |
161 | /* mark each of the trace's resources invisible */ |
162 | result = gtk_tree_model_iter_children(model, &child, iter); |
163 | |
164 | /* for each child of the collapsed row */ |
165 | while(result) { |
166 | char *name; |
167 | /* hide the item */ |
168 | gtk_tree_model_get(model, &child, NAME_COLUMN, &name, DATA_COLUMN, &hrd, -1); |
169 | hrd->hidden=1; |
170 | |
171 | /* find next */ |
172 | result = gtk_tree_model_iter_next(model, &child); |
173 | } |
174 | |
175 | update_index_to_pixmap(process_list); |
176 | |
177 | gtk_widget_queue_draw(resourceview_data->drawing->drawing_area); |
178 | } |
179 | |
67f72973 |
180 | static gboolean update_index_to_pixmap_each (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, UpdateIndexPixmapArg *arg) |
9e01e6d4 |
181 | { |
67f72973 |
182 | guint array_index = arg->count; |
183 | HashedResourceData *hdata; |
184 | gchar *name; |
185 | |
186 | gtk_tree_model_get(model, iter, NAME_COLUMN, &name, DATA_COLUMN, &hdata, -1); |
187 | |
188 | g_assert(array_index < arg->process_list->index_to_pixmap->len); |
9e01e6d4 |
189 | |
27274b95 |
190 | if(hdata->hidden == 0) { |
191 | GdkPixmap **pixmap = |
192 | (GdkPixmap**)&g_ptr_array_index(arg->process_list->index_to_pixmap, array_index); |
193 | *pixmap = hdata->pixmap; |
9e01e6d4 |
194 | |
27274b95 |
195 | arg->count++; |
196 | } |
9e01e6d4 |
197 | |
67f72973 |
198 | return FALSE; |
9e01e6d4 |
199 | } |
200 | |
9e01e6d4 |
201 | void update_index_to_pixmap(ProcessList *process_list) |
202 | { |
67f72973 |
203 | int i, items=0; |
204 | UpdateIndexPixmapArg arg; |
205 | |
206 | for(i=0; i<RV_RESOURCE_COUNT; i++) { |
207 | items += g_hash_table_size(process_list->restypes[i].hash_table); |
208 | } |
209 | |
27274b95 |
210 | /* we don't know the exact number of items there will be, |
211 | * so set an upper bound */ |
67f72973 |
212 | g_ptr_array_set_size(process_list->index_to_pixmap, items); |
213 | |
214 | arg.count = 0; |
215 | arg.process_list = process_list; |
216 | |
d0e4ae2f |
217 | gtk_tree_model_foreach(GTK_TREE_MODEL(process_list->list_store), |
67f72973 |
218 | (GtkTreeModelForeachFunc)update_index_to_pixmap_each, &arg); |
27274b95 |
219 | |
220 | /* now that we know the exact number of items, set it */ |
221 | g_ptr_array_set_size(process_list->index_to_pixmap, arg.count); |
9e01e6d4 |
222 | } |
223 | |
224 | |
67f72973 |
225 | static void update_pixmap_size_each(void *key, |
58a9b31b |
226 | HashedResourceData *value, |
9e01e6d4 |
227 | guint width) |
228 | { |
229 | GdkPixmap *old_pixmap = value->pixmap; |
230 | |
231 | value->pixmap = |
232 | gdk_pixmap_new(old_pixmap, |
233 | width, |
234 | value->height, |
235 | -1); |
236 | |
237 | gdk_pixmap_unref(old_pixmap); |
238 | } |
239 | |
240 | |
241 | void update_pixmap_size(ProcessList *process_list, guint width) |
242 | { |
67f72973 |
243 | int i; |
244 | for(i=0; i<RV_RESOURCE_COUNT; i++) { |
245 | g_hash_table_foreach(process_list->restypes[i].hash_table, |
9e01e6d4 |
246 | (GHFunc)update_pixmap_size_each, |
247 | (gpointer)width); |
67f72973 |
248 | } |
9e01e6d4 |
249 | } |
250 | |
251 | |
252 | typedef struct _CopyPixmap { |
253 | GdkDrawable *dest; |
254 | GdkGC *gc; |
255 | GdkDrawable *src; |
256 | gint xsrc, ysrc, xdest, ydest, width, height; |
257 | } CopyPixmap; |
258 | |
67f72973 |
259 | static void copy_pixmap_region_each(void *key, |
58a9b31b |
260 | HashedResourceData *value, |
9e01e6d4 |
261 | CopyPixmap *cp) |
262 | { |
263 | GdkPixmap *src = cp->src; |
264 | GdkPixmap *dest = cp->dest; |
265 | |
266 | if(dest == NULL) |
267 | dest = value->pixmap; |
268 | if(src == NULL) |
269 | src = value->pixmap; |
270 | |
271 | gdk_draw_drawable (dest, |
272 | cp->gc, |
273 | src, |
274 | cp->xsrc, cp->ysrc, |
275 | cp->xdest, cp->ydest, |
276 | cp->width, cp->height); |
277 | } |
278 | |
9e01e6d4 |
279 | void copy_pixmap_region(ProcessList *process_list, GdkDrawable *dest, |
280 | GdkGC *gc, GdkDrawable *src, |
281 | gint xsrc, gint ysrc, |
282 | gint xdest, gint ydest, gint width, gint height) |
283 | { |
67f72973 |
284 | int i; |
9e01e6d4 |
285 | CopyPixmap cp = { dest, gc, src, xsrc, ysrc, xdest, ydest, width, height }; |
286 | |
67f72973 |
287 | for(i=0; i<RV_RESOURCE_COUNT; i++) { |
288 | g_hash_table_foreach(process_list->restypes[i].hash_table, |
9e01e6d4 |
289 | (GHFunc)copy_pixmap_region_each, |
290 | &cp); |
67f72973 |
291 | } |
9e01e6d4 |
292 | } |
293 | |
294 | |
295 | |
296 | typedef struct _RectanglePixmap { |
297 | gboolean filled; |
298 | gint x, y, width, height; |
299 | GdkGC *gc; |
300 | } RectanglePixmap; |
301 | |
67f72973 |
302 | static void rectangle_pixmap_each(void *key, |
58a9b31b |
303 | HashedResourceData *value, |
9e01e6d4 |
304 | RectanglePixmap *rp) |
305 | { |
306 | if(rp->height == -1) |
307 | rp->height = value->height; |
308 | |
309 | gdk_draw_rectangle (value->pixmap, |
310 | rp->gc, |
311 | rp->filled, |
312 | rp->x, rp->y, |
313 | rp->width, rp->height); |
314 | } |
315 | |
9e01e6d4 |
316 | void rectangle_pixmap(ProcessList *process_list, GdkGC *gc, |
317 | gboolean filled, gint x, gint y, gint width, gint height) |
318 | { |
67f72973 |
319 | int i; |
9e01e6d4 |
320 | RectanglePixmap rp = { filled, x, y, width, height, gc }; |
321 | |
67f72973 |
322 | for(i=0; i<RV_RESOURCE_COUNT; i++) { |
323 | g_hash_table_foreach(process_list->restypes[i].hash_table, |
9e01e6d4 |
324 | (GHFunc)rectangle_pixmap_each, |
325 | &rp); |
67f72973 |
326 | } |
9e01e6d4 |
327 | } |
328 | |
9e01e6d4 |
329 | /* Renders each pixmaps into on big drawable */ |
330 | void copy_pixmap_to_screen(ProcessList *process_list, |
331 | GdkDrawable *dest, |
332 | GdkGC *gc, |
333 | gint x, gint y, |
334 | gint width, gint height) |
335 | { |
336 | if(process_list->index_to_pixmap->len == 0) return; |
337 | guint cell_height = process_list->cell_height; |
338 | |
339 | /* Get indexes */ |
340 | gint begin = floor(y/(double)cell_height); |
341 | gint end = MIN(ceil((y+height)/(double)cell_height), |
342 | process_list->index_to_pixmap->len); |
343 | gint i; |
344 | |
345 | for(i=begin; i<end; i++) { |
346 | g_assert(i<process_list->index_to_pixmap->len); |
347 | /* Render the pixmap to the screen */ |
348 | GdkPixmap *pixmap = |
349 | //(GdkPixmap*)g_ptr_array_index(process_list->index_to_pixmap, i); |
350 | GDK_PIXMAP(g_ptr_array_index(process_list->index_to_pixmap, i)); |
351 | |
352 | gdk_draw_drawable (dest, |
353 | gc, |
354 | pixmap, |
355 | x, 0, |
356 | x, i*cell_height, |
357 | width, cell_height); |
358 | |
359 | } |
9e01e6d4 |
360 | } |
361 | |
9e01e6d4 |
362 | ProcessList *processlist_construct(void) |
363 | { |
364 | GtkTreeViewColumn *column; |
365 | GtkCellRenderer *renderer; |
366 | |
367 | ProcessList* process_list = g_new(ProcessList,1); |
368 | |
369 | process_list->number_of_process = 0; |
370 | |
371 | process_list->current_hash_data = NULL; |
372 | |
373 | /* Create the Process list */ |
67f72973 |
374 | process_list->list_store = gtk_tree_store_new ( N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER); |
9e01e6d4 |
375 | |
376 | process_list->process_list_widget = |
377 | gtk_tree_view_new_with_model |
378 | (GTK_TREE_MODEL (process_list->list_store)); |
0dd8209a |
379 | g_object_set(process_list->process_list_widget, "enable-tree-lines", TRUE, NULL); |
9e01e6d4 |
380 | |
381 | g_object_unref (G_OBJECT (process_list->list_store)); |
382 | |
fb93b151 |
383 | gtk_tree_sortable_set_default_sort_func( |
384 | GTK_TREE_SORTABLE(process_list->list_store), |
385 | resource_sort_func, |
386 | NULL, |
387 | NULL); |
388 | |
0dd8209a |
389 | |
fb93b151 |
390 | gtk_tree_sortable_set_sort_column_id( |
391 | GTK_TREE_SORTABLE(process_list->list_store), |
392 | GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, |
393 | GTK_SORT_ASCENDING); |
9e01e6d4 |
394 | |
9e01e6d4 |
395 | gtk_tree_view_set_headers_visible( |
396 | GTK_TREE_VIEW(process_list->process_list_widget), TRUE); |
397 | |
398 | /* Create a column, associating the "text" attribute of the |
399 | * cell_renderer to the first column of the model */ |
400 | /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */ |
401 | renderer = gtk_cell_renderer_text_new (); |
402 | process_list->renderer = renderer; |
403 | |
404 | gint vertical_separator; |
405 | gtk_widget_style_get (GTK_WIDGET (process_list->process_list_widget), |
406 | "vertical-separator", &vertical_separator, |
407 | NULL); |
408 | gtk_cell_renderer_get_size(renderer, |
409 | GTK_WIDGET(process_list->process_list_widget), |
410 | NULL, |
411 | NULL, |
412 | NULL, |
413 | NULL, |
414 | &process_list->cell_height); |
27274b95 |
415 | |
416 | g_signal_connect(process_list->process_list_widget, "row-expanded", G_CALLBACK(expand_event), process_list); |
417 | g_signal_connect(process_list->process_list_widget, "row-collapsed", G_CALLBACK(collapse_event), process_list); |
9e01e6d4 |
418 | |
419 | #if GTK_CHECK_VERSION(2,4,15) |
420 | guint ypad; |
421 | g_object_get(G_OBJECT(renderer), "ypad", &ypad, NULL); |
422 | |
423 | process_list->cell_height += ypad; |
424 | #endif |
425 | process_list->cell_height += vertical_separator; |
426 | |
427 | |
c4e6f4dc |
428 | column = gtk_tree_view_column_new_with_attributes ( "Resource", |
9e01e6d4 |
429 | renderer, |
430 | "text", |
58a9b31b |
431 | NAME_COLUMN, |
9e01e6d4 |
432 | NULL); |
433 | gtk_tree_view_column_set_alignment (column, 0.0); |
434 | gtk_tree_view_column_set_fixed_width (column, 45); |
435 | gtk_tree_view_append_column ( |
436 | GTK_TREE_VIEW (process_list->process_list_widget), column); |
437 | |
438 | process_list->button = column->button; |
9e01e6d4 |
439 | |
440 | g_object_set_data_full( |
441 | G_OBJECT(process_list->process_list_widget), |
442 | "process_list_Data", |
443 | process_list, |
444 | (GDestroyNotify)processlist_destroy); |
445 | |
446 | process_list->index_to_pixmap = g_ptr_array_sized_new(ALLOCATE_PROCESSES); |
67f72973 |
447 | |
448 | process_list->restypes[RV_RESOURCE_MACHINE].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct); |
449 | process_list->restypes[RV_RESOURCE_CPU].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct); |
450 | process_list->restypes[RV_RESOURCE_IRQ].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct); |
0305fe77 |
451 | process_list->restypes[RV_RESOURCE_SOFT_IRQ].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct); |
38726a78 |
452 | process_list->restypes[RV_RESOURCE_TRAP].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct); |
67f72973 |
453 | process_list->restypes[RV_RESOURCE_BDEV].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct); |
0dd8209a |
454 | |
9e01e6d4 |
455 | return process_list; |
456 | } |
457 | |
458 | void processlist_destroy(ProcessList *process_list) |
459 | { |
67f72973 |
460 | int i; |
461 | |
9e01e6d4 |
462 | g_debug("processlist_destroy %p", process_list); |
67f72973 |
463 | |
464 | for(i=0; i<RV_RESOURCE_COUNT; i++) { |
465 | g_hash_table_destroy(process_list->restypes[i].hash_table); |
466 | process_list->restypes[i].hash_table = NULL; |
467 | } |
9e01e6d4 |
468 | g_ptr_array_free(process_list->index_to_pixmap, TRUE); |
469 | |
470 | g_free(process_list); |
471 | g_debug("processlist_destroy end"); |
472 | } |
473 | |
67f72973 |
474 | static gboolean remove_hash_item(void *key, |
58a9b31b |
475 | HashedResourceData *hashed_process_data, |
9e01e6d4 |
476 | ProcessList *process_list) |
477 | { |
478 | GtkTreeIter iter; |
479 | |
480 | iter = hashed_process_data->y_iter; |
481 | |
67f72973 |
482 | gtk_tree_store_remove (process_list->list_store, &iter); |
9e01e6d4 |
483 | gdk_pixmap_unref(hashed_process_data->pixmap); |
484 | |
58a9b31b |
485 | // TODO pmf: check this; might be needed |
486 | // if(likely(process_list->current_hash_data != NULL)) { |
487 | // if(likely(hashed_process_data == |
488 | // process_list->current_hash_data[process_info->trace_num][process_info->cpu])) |
489 | // process_list->current_hash_data[process_info->trace_num][process_info->cpu] = NULL; |
490 | // } |
9e01e6d4 |
491 | return TRUE; /* remove the element from the hash table */ |
492 | } |
493 | |
494 | void processlist_clear(ProcessList *process_list) |
495 | { |
67f72973 |
496 | int i; |
497 | |
9e01e6d4 |
498 | g_info("processlist_clear %p", process_list); |
499 | |
67f72973 |
500 | for(i=RV_RESOURCE_COUNT-1; i>=0; i--) { |
501 | g_hash_table_foreach_remove(process_list->restypes[i].hash_table, |
502 | (GHRFunc)remove_hash_item, |
503 | (gpointer)process_list); |
504 | } |
9e01e6d4 |
505 | process_list->number_of_process = 0; |
506 | update_index_to_pixmap(process_list); |
507 | } |
508 | |
509 | |
510 | GtkWidget *processlist_get_widget(ProcessList *process_list) |
511 | { |
512 | return process_list->process_list_widget; |
513 | } |
514 | |
515 | |
516 | void destroy_hash_key(gpointer key) |
517 | { |
518 | g_free(key); |
519 | } |
520 | |
521 | void destroy_hash_data(gpointer data) |
522 | { |
523 | g_free(data); |
524 | } |
525 | |
37b0f1ed |
526 | GQuark make_cpu_name(ControlFlowData *resourceview_data, guint trace_num, guint id) |
527 | { |
528 | GQuark name; |
529 | gchar *str; |
530 | |
531 | str = g_strdup_printf("CPU%u", id); |
532 | name = g_quark_from_string(str); |
533 | g_free(str); |
534 | |
535 | return name; |
536 | } |
537 | |
538 | GQuark make_irq_name(ControlFlowData *resourceview_data, guint trace_num, guint id) |
539 | { |
540 | GQuark name; |
541 | gchar *str; |
542 | |
543 | str = g_strdup_printf("IRQ %u", id); |
544 | name = g_quark_from_string(str); |
545 | g_free(str); |
546 | |
547 | return name; |
548 | } |
549 | |
0305fe77 |
550 | GQuark make_soft_irq_name(ControlFlowData *resourceview_data, guint trace_num, guint id) |
551 | { |
552 | GQuark name; |
553 | gchar *str; |
554 | |
555 | str = g_strdup_printf("SOFTIRQ %u", id); |
556 | name = g_quark_from_string(str); |
557 | g_free(str); |
558 | |
559 | return name; |
560 | } |
561 | |
38726a78 |
562 | GQuark make_trap_name(ControlFlowData *resourceview_data, guint trace_num, guint id) |
563 | { |
564 | GQuark name; |
565 | gchar *str; |
566 | |
567 | str = g_strdup_printf("Trap %u", id); |
568 | name = g_quark_from_string(str); |
569 | g_free(str); |
570 | |
571 | return name; |
572 | } |
573 | |
37b0f1ed |
574 | GQuark make_bdev_name(ControlFlowData *resourceview_data, guint trace_num, guint id) |
575 | { |
576 | GQuark name; |
577 | gchar *str; |
578 | |
579 | str = g_strdup_printf("Block (%u,%u)", MAJOR(id), MINOR(id)); |
580 | name = g_quark_from_string(str); |
581 | g_free(str); |
582 | |
583 | return name; |
584 | } |
585 | |
67f72973 |
586 | HashedResourceData *resourcelist_obtain_machine(ControlFlowData *resourceview_data, guint trace_num, guint id) |
9e01e6d4 |
587 | { |
67f72973 |
588 | ResourceUniqueNumeric *ru = g_new(ResourceUniqueNumeric, 1); |
589 | HashedResourceData *data = g_new(HashedResourceData, 1); |
590 | |
591 | /* Prepare hash key */ |
592 | ru->trace_num = trace_num; |
593 | ru->id = id; |
594 | |
595 | /* Search within hash table */ |
596 | GHashTable *ht = resourceview_data->process_list->restypes[RV_RESOURCE_MACHINE].hash_table; |
597 | data = g_hash_table_lookup(ht, ru); |
598 | |
599 | /* If not found in hash table, add it */ |
600 | if(data == NULL) { |
601 | GQuark name; |
602 | |
603 | data = g_malloc(sizeof(HashedResourceData)); |
604 | /* Prepare hashed data */ |
605 | data->type = RV_RESOURCE_MACHINE; |
606 | data->x.over = 0; |
607 | data->x.over_used = FALSE; |
608 | data->x.over_marked = FALSE; |
609 | data->x.middle = 0; // last |
610 | data->x.middle_used = FALSE; |
611 | data->x.middle_marked = FALSE; |
612 | data->x.under = 0; |
613 | data->x.under_used = FALSE; |
614 | data->x.under_marked = FALSE; |
615 | data->next_good_time = ltt_time_zero; |
27274b95 |
616 | data->hidden = 0; |
67f72973 |
617 | |
618 | data->height = resourceview_data->process_list->cell_height; |
619 | data->pixmap = |
620 | gdk_pixmap_new(resourceview_data->drawing->drawing_area->window, |
621 | resourceview_data->drawing->alloc_width, |
622 | data->height, |
623 | -1); |
624 | g_assert(data->pixmap); |
58a9b31b |
625 | |
67f72973 |
626 | gdk_draw_rectangle (data->pixmap, |
627 | resourceview_data->drawing->drawing_area->style->black_gc, |
628 | TRUE, |
629 | 0, 0, |
630 | resourceview_data->drawing->alloc_width, |
631 | data->height); |
632 | |
633 | /* add to hash table */ |
634 | g_hash_table_insert(ht, ru, data); |
635 | resourceview_data->process_list->number_of_process++; // TODO: check |
636 | |
637 | /* add to process list */ |
638 | { |
639 | gchar *str; |
640 | str = g_strdup_printf("Trace %u", id); |
641 | name = g_quark_from_string(str); |
642 | g_free(str); |
643 | } |
644 | |
645 | gtk_tree_store_append(resourceview_data->process_list->list_store, &data->y_iter, NULL); |
646 | gtk_tree_store_set(resourceview_data->process_list->list_store, &data->y_iter, |
647 | NAME_COLUMN, g_quark_to_string(name), DATA_COLUMN, data, |
648 | -1); |
649 | |
650 | update_index_to_pixmap(resourceview_data->process_list); |
651 | |
652 | int heightall = data->height * resourceview_data->process_list->number_of_process; |
653 | |
654 | gtk_widget_set_size_request(resourceview_data->drawing->drawing_area, |
655 | -1, |
656 | heightall); |
9e01e6d4 |
657 | |
67f72973 |
658 | gtk_widget_queue_draw(resourceview_data->drawing->drawing_area); |
659 | } |
660 | |
27274b95 |
661 | /* expand the newly added machine */ |
662 | { |
663 | GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(resourceview_data->process_list->process_list_widget)); |
664 | GtkTreePath *path; |
665 | path = gtk_tree_model_get_path(model, &data->y_iter); |
666 | |
667 | gtk_tree_view_expand_row(GTK_TREE_VIEW(resourceview_data->process_list->process_list_widget), path, FALSE); |
668 | |
669 | gtk_tree_path_free(path); |
670 | } |
67f72973 |
671 | |
672 | return data; |
673 | } |
674 | |
37b0f1ed |
675 | HashedResourceData *resourcelist_obtain_generic(ControlFlowData *resourceview_data, gint res_type, guint trace_num, guint id, GQuark (*make_name_func)(ControlFlowData *resourceview_data, guint trace_num, guint id)) |
67f72973 |
676 | { |
677 | ResourceUniqueNumeric *ru = g_new(ResourceUniqueNumeric, 1); |
678 | HashedResourceData *data = g_new(HashedResourceData, 1); |
9e01e6d4 |
679 | |
67f72973 |
680 | /* Prepare hash key */ |
27274b95 |
681 | ru->ru.type = &(resourceview_data->process_list->restypes[res_type]); |
67f72973 |
682 | ru->trace_num = trace_num; |
683 | ru->id = id; |
9e01e6d4 |
684 | |
67f72973 |
685 | /* Search within hash table */ |
37b0f1ed |
686 | GHashTable *ht = resourceview_data->process_list->restypes[res_type].hash_table; |
67f72973 |
687 | data = g_hash_table_lookup(ht, ru); |
688 | |
689 | /* If not found in hash table, add it */ |
690 | if(data == NULL) { |
691 | GQuark name; |
692 | HashedResourceData *parent; |
693 | |
694 | /* Find the parent machine */ |
695 | parent = resourcelist_obtain_machine(resourceview_data, trace_num, trace_num); |
696 | |
697 | /* Prepare hashed data */ |
698 | data = g_malloc(sizeof(HashedResourceData)); |
699 | |
37b0f1ed |
700 | data->type = res_type; |
67f72973 |
701 | data->x.over = 0; |
702 | data->x.over_used = FALSE; |
703 | data->x.over_marked = FALSE; |
704 | data->x.middle = 0; // last |
705 | data->x.middle_used = FALSE; |
706 | data->x.middle_marked = FALSE; |
707 | data->x.under = 0; |
708 | data->x.under_used = FALSE; |
709 | data->x.under_marked = FALSE; |
710 | data->next_good_time = ltt_time_zero; |
711 | |
712 | data->height = resourceview_data->process_list->cell_height; |
713 | data->pixmap = |
714 | gdk_pixmap_new(resourceview_data->drawing->drawing_area->window, |
715 | resourceview_data->drawing->alloc_width, |
716 | data->height, |
717 | -1); |
718 | |
719 | gdk_draw_rectangle (data->pixmap, |
720 | resourceview_data->drawing->drawing_area->style->black_gc, |
721 | TRUE, |
722 | 0, 0, |
723 | resourceview_data->drawing->alloc_width, |
724 | data->height); |
9e01e6d4 |
725 | |
67f72973 |
726 | /* add to hash table */ |
727 | g_hash_table_insert(ht, ru, data); |
728 | resourceview_data->process_list->number_of_process++; // TODO: check |
9e01e6d4 |
729 | |
67f72973 |
730 | /* add to process list */ |
37b0f1ed |
731 | name = make_name_func(resourceview_data, trace_num, id); |
9e01e6d4 |
732 | |
67f72973 |
733 | gtk_tree_store_append(resourceview_data->process_list->list_store, &data->y_iter, &parent->y_iter); |
734 | gtk_tree_store_set(resourceview_data->process_list->list_store, &data->y_iter, |
735 | NAME_COLUMN, g_quark_to_string(name), DATA_COLUMN, data, |
736 | -1); |
9e01e6d4 |
737 | |
27274b95 |
738 | /* Determine if we should add it hidden or not */ |
739 | { |
740 | gboolean result; |
741 | GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(resourceview_data->process_list->process_list_widget)); |
742 | GtkTreeIter parent_iter; |
743 | |
744 | result = gtk_tree_model_iter_parent(model, &parent_iter, &data->y_iter); |
745 | GtkTreePath *path = gtk_tree_model_get_path(model, &parent_iter); |
746 | data->hidden = gtk_tree_view_row_expanded(GTK_TREE_VIEW(resourceview_data->process_list->process_list_widget), path)?0:1; |
747 | gtk_tree_path_free(path); |
748 | } |
749 | |
750 | |
67f72973 |
751 | update_index_to_pixmap(resourceview_data->process_list); |
752 | |
753 | int heightall = data->height * resourceview_data->process_list->number_of_process; |
754 | |
755 | gtk_widget_set_size_request(resourceview_data->drawing->drawing_area, |
756 | -1, |
757 | heightall); |
758 | |
759 | gtk_widget_queue_draw(resourceview_data->drawing->drawing_area); |
760 | } |
761 | |
762 | return data; |
763 | } |
764 | |
37b0f1ed |
765 | HashedResourceData *resourcelist_obtain_cpu(ControlFlowData *resourceview_data, guint trace_num, guint id) |
67f72973 |
766 | { |
37b0f1ed |
767 | return resourcelist_obtain_generic(resourceview_data, RV_RESOURCE_CPU, trace_num, id, make_cpu_name); |
768 | } |
67f72973 |
769 | |
37b0f1ed |
770 | HashedResourceData *resourcelist_obtain_irq(ControlFlowData *resourceview_data, guint trace_num, guint id) |
771 | { |
772 | return resourcelist_obtain_generic(resourceview_data, RV_RESOURCE_IRQ, trace_num, id, make_irq_name); |
67f72973 |
773 | } |
9e01e6d4 |
774 | |
0305fe77 |
775 | HashedResourceData *resourcelist_obtain_soft_irq(ControlFlowData *resourceview_data, guint trace_num, guint id) |
776 | { |
777 | return resourcelist_obtain_generic(resourceview_data, RV_RESOURCE_SOFT_IRQ, trace_num, id, make_soft_irq_name); |
778 | } |
779 | |
38726a78 |
780 | HashedResourceData *resourcelist_obtain_trap(ControlFlowData *resourceview_data, guint trace_num, guint id) |
781 | { |
782 | return resourcelist_obtain_generic(resourceview_data, RV_RESOURCE_TRAP, trace_num, id, make_trap_name); |
783 | } |
784 | |
67f72973 |
785 | HashedResourceData *resourcelist_obtain_bdev(ControlFlowData *resourceview_data, guint trace_num, guint id) |
9e01e6d4 |
786 | { |
37b0f1ed |
787 | return resourcelist_obtain_generic(resourceview_data, RV_RESOURCE_BDEV, trace_num, id, make_bdev_name); |
9e01e6d4 |
788 | } |
37b0f1ed |
789 | |