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 | { |
67f72973 |
62 | ResourceUniqueNumeric *ru = (const ResourceUniqueNumeric *)key; |
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 | |
67f72973 |
109 | static gboolean update_index_to_pixmap_each (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, UpdateIndexPixmapArg *arg) |
9e01e6d4 |
110 | { |
67f72973 |
111 | guint array_index = arg->count; |
112 | HashedResourceData *hdata; |
113 | gchar *name; |
114 | |
115 | gtk_tree_model_get(model, iter, NAME_COLUMN, &name, DATA_COLUMN, &hdata, -1); |
116 | |
117 | g_assert(array_index < arg->process_list->index_to_pixmap->len); |
9e01e6d4 |
118 | |
67f72973 |
119 | GdkPixmap **pixmap = |
120 | (GdkPixmap**)&g_ptr_array_index(arg->process_list->index_to_pixmap, array_index); |
121 | *pixmap = hdata->pixmap; |
9e01e6d4 |
122 | |
67f72973 |
123 | arg->count++; |
9e01e6d4 |
124 | |
67f72973 |
125 | return FALSE; |
9e01e6d4 |
126 | } |
127 | |
9e01e6d4 |
128 | void update_index_to_pixmap(ProcessList *process_list) |
129 | { |
67f72973 |
130 | int i, items=0; |
131 | UpdateIndexPixmapArg arg; |
132 | |
133 | for(i=0; i<RV_RESOURCE_COUNT; i++) { |
134 | items += g_hash_table_size(process_list->restypes[i].hash_table); |
135 | } |
136 | |
137 | g_ptr_array_set_size(process_list->index_to_pixmap, items); |
138 | |
139 | arg.count = 0; |
140 | arg.process_list = process_list; |
141 | |
142 | gtk_tree_model_foreach(process_list->list_store, |
143 | (GtkTreeModelForeachFunc)update_index_to_pixmap_each, &arg); |
9e01e6d4 |
144 | } |
145 | |
146 | |
67f72973 |
147 | static void update_pixmap_size_each(void *key, |
58a9b31b |
148 | HashedResourceData *value, |
9e01e6d4 |
149 | guint width) |
150 | { |
151 | GdkPixmap *old_pixmap = value->pixmap; |
152 | |
153 | value->pixmap = |
154 | gdk_pixmap_new(old_pixmap, |
155 | width, |
156 | value->height, |
157 | -1); |
158 | |
159 | gdk_pixmap_unref(old_pixmap); |
160 | } |
161 | |
162 | |
163 | void update_pixmap_size(ProcessList *process_list, guint width) |
164 | { |
67f72973 |
165 | int i; |
166 | for(i=0; i<RV_RESOURCE_COUNT; i++) { |
167 | g_hash_table_foreach(process_list->restypes[i].hash_table, |
9e01e6d4 |
168 | (GHFunc)update_pixmap_size_each, |
169 | (gpointer)width); |
67f72973 |
170 | } |
9e01e6d4 |
171 | } |
172 | |
173 | |
174 | typedef struct _CopyPixmap { |
175 | GdkDrawable *dest; |
176 | GdkGC *gc; |
177 | GdkDrawable *src; |
178 | gint xsrc, ysrc, xdest, ydest, width, height; |
179 | } CopyPixmap; |
180 | |
67f72973 |
181 | static void copy_pixmap_region_each(void *key, |
58a9b31b |
182 | HashedResourceData *value, |
9e01e6d4 |
183 | CopyPixmap *cp) |
184 | { |
185 | GdkPixmap *src = cp->src; |
186 | GdkPixmap *dest = cp->dest; |
187 | |
188 | if(dest == NULL) |
189 | dest = value->pixmap; |
190 | if(src == NULL) |
191 | src = value->pixmap; |
192 | |
193 | gdk_draw_drawable (dest, |
194 | cp->gc, |
195 | src, |
196 | cp->xsrc, cp->ysrc, |
197 | cp->xdest, cp->ydest, |
198 | cp->width, cp->height); |
199 | } |
200 | |
9e01e6d4 |
201 | void copy_pixmap_region(ProcessList *process_list, GdkDrawable *dest, |
202 | GdkGC *gc, GdkDrawable *src, |
203 | gint xsrc, gint ysrc, |
204 | gint xdest, gint ydest, gint width, gint height) |
205 | { |
67f72973 |
206 | int i; |
9e01e6d4 |
207 | CopyPixmap cp = { dest, gc, src, xsrc, ysrc, xdest, ydest, width, height }; |
208 | |
67f72973 |
209 | for(i=0; i<RV_RESOURCE_COUNT; i++) { |
210 | g_hash_table_foreach(process_list->restypes[i].hash_table, |
9e01e6d4 |
211 | (GHFunc)copy_pixmap_region_each, |
212 | &cp); |
67f72973 |
213 | } |
9e01e6d4 |
214 | } |
215 | |
216 | |
217 | |
218 | typedef struct _RectanglePixmap { |
219 | gboolean filled; |
220 | gint x, y, width, height; |
221 | GdkGC *gc; |
222 | } RectanglePixmap; |
223 | |
67f72973 |
224 | static void rectangle_pixmap_each(void *key, |
58a9b31b |
225 | HashedResourceData *value, |
9e01e6d4 |
226 | RectanglePixmap *rp) |
227 | { |
228 | if(rp->height == -1) |
229 | rp->height = value->height; |
230 | |
231 | gdk_draw_rectangle (value->pixmap, |
232 | rp->gc, |
233 | rp->filled, |
234 | rp->x, rp->y, |
235 | rp->width, rp->height); |
236 | } |
237 | |
9e01e6d4 |
238 | void rectangle_pixmap(ProcessList *process_list, GdkGC *gc, |
239 | gboolean filled, gint x, gint y, gint width, gint height) |
240 | { |
67f72973 |
241 | int i; |
9e01e6d4 |
242 | RectanglePixmap rp = { filled, x, y, width, height, gc }; |
243 | |
67f72973 |
244 | for(i=0; i<RV_RESOURCE_COUNT; i++) { |
245 | g_hash_table_foreach(process_list->restypes[i].hash_table, |
9e01e6d4 |
246 | (GHFunc)rectangle_pixmap_each, |
247 | &rp); |
67f72973 |
248 | } |
9e01e6d4 |
249 | } |
250 | |
9e01e6d4 |
251 | /* Renders each pixmaps into on big drawable */ |
252 | void copy_pixmap_to_screen(ProcessList *process_list, |
253 | GdkDrawable *dest, |
254 | GdkGC *gc, |
255 | gint x, gint y, |
256 | gint width, gint height) |
257 | { |
258 | if(process_list->index_to_pixmap->len == 0) return; |
259 | guint cell_height = process_list->cell_height; |
260 | |
261 | /* Get indexes */ |
262 | gint begin = floor(y/(double)cell_height); |
263 | gint end = MIN(ceil((y+height)/(double)cell_height), |
264 | process_list->index_to_pixmap->len); |
265 | gint i; |
266 | |
267 | for(i=begin; i<end; i++) { |
268 | g_assert(i<process_list->index_to_pixmap->len); |
269 | /* Render the pixmap to the screen */ |
270 | GdkPixmap *pixmap = |
271 | //(GdkPixmap*)g_ptr_array_index(process_list->index_to_pixmap, i); |
272 | GDK_PIXMAP(g_ptr_array_index(process_list->index_to_pixmap, i)); |
273 | |
274 | gdk_draw_drawable (dest, |
275 | gc, |
276 | pixmap, |
277 | x, 0, |
278 | x, i*cell_height, |
279 | width, cell_height); |
280 | |
281 | } |
9e01e6d4 |
282 | } |
283 | |
9e01e6d4 |
284 | ProcessList *processlist_construct(void) |
285 | { |
286 | GtkTreeViewColumn *column; |
287 | GtkCellRenderer *renderer; |
288 | |
289 | ProcessList* process_list = g_new(ProcessList,1); |
290 | |
291 | process_list->number_of_process = 0; |
292 | |
293 | process_list->current_hash_data = NULL; |
294 | |
295 | /* Create the Process list */ |
67f72973 |
296 | process_list->list_store = gtk_tree_store_new ( N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER); |
9e01e6d4 |
297 | |
298 | process_list->process_list_widget = |
299 | gtk_tree_view_new_with_model |
300 | (GTK_TREE_MODEL (process_list->list_store)); |
67f72973 |
301 | g_object_set(process_list->process_list_widget, "enable-tree-lines", TRUE, NULL); |
9e01e6d4 |
302 | |
303 | g_object_unref (G_OBJECT (process_list->list_store)); |
304 | |
fb93b151 |
305 | gtk_tree_sortable_set_default_sort_func( |
306 | GTK_TREE_SORTABLE(process_list->list_store), |
307 | resource_sort_func, |
308 | NULL, |
309 | NULL); |
310 | |
311 | |
312 | gtk_tree_sortable_set_sort_column_id( |
313 | GTK_TREE_SORTABLE(process_list->list_store), |
314 | GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, |
315 | GTK_SORT_ASCENDING); |
9e01e6d4 |
316 | |
9e01e6d4 |
317 | gtk_tree_view_set_headers_visible( |
318 | GTK_TREE_VIEW(process_list->process_list_widget), TRUE); |
319 | |
320 | /* Create a column, associating the "text" attribute of the |
321 | * cell_renderer to the first column of the model */ |
322 | /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */ |
323 | renderer = gtk_cell_renderer_text_new (); |
324 | process_list->renderer = renderer; |
325 | |
326 | gint vertical_separator; |
327 | gtk_widget_style_get (GTK_WIDGET (process_list->process_list_widget), |
328 | "vertical-separator", &vertical_separator, |
329 | NULL); |
330 | gtk_cell_renderer_get_size(renderer, |
331 | GTK_WIDGET(process_list->process_list_widget), |
332 | NULL, |
333 | NULL, |
334 | NULL, |
335 | NULL, |
336 | &process_list->cell_height); |
337 | |
338 | #if GTK_CHECK_VERSION(2,4,15) |
339 | guint ypad; |
340 | g_object_get(G_OBJECT(renderer), "ypad", &ypad, NULL); |
341 | |
342 | process_list->cell_height += ypad; |
343 | #endif |
344 | process_list->cell_height += vertical_separator; |
345 | |
346 | |
c4e6f4dc |
347 | column = gtk_tree_view_column_new_with_attributes ( "Resource", |
9e01e6d4 |
348 | renderer, |
349 | "text", |
58a9b31b |
350 | NAME_COLUMN, |
9e01e6d4 |
351 | NULL); |
352 | gtk_tree_view_column_set_alignment (column, 0.0); |
353 | gtk_tree_view_column_set_fixed_width (column, 45); |
354 | gtk_tree_view_append_column ( |
355 | GTK_TREE_VIEW (process_list->process_list_widget), column); |
356 | |
357 | process_list->button = column->button; |
9e01e6d4 |
358 | |
359 | g_object_set_data_full( |
360 | G_OBJECT(process_list->process_list_widget), |
361 | "process_list_Data", |
362 | process_list, |
363 | (GDestroyNotify)processlist_destroy); |
364 | |
365 | process_list->index_to_pixmap = g_ptr_array_sized_new(ALLOCATE_PROCESSES); |
67f72973 |
366 | |
367 | process_list->restypes[RV_RESOURCE_MACHINE].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct); |
368 | process_list->restypes[RV_RESOURCE_CPU].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct); |
369 | process_list->restypes[RV_RESOURCE_IRQ].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct); |
370 | process_list->restypes[RV_RESOURCE_BDEV].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct); |
9e01e6d4 |
371 | |
372 | return process_list; |
373 | } |
374 | |
375 | void processlist_destroy(ProcessList *process_list) |
376 | { |
67f72973 |
377 | int i; |
378 | |
9e01e6d4 |
379 | g_debug("processlist_destroy %p", process_list); |
67f72973 |
380 | |
381 | for(i=0; i<RV_RESOURCE_COUNT; i++) { |
382 | g_hash_table_destroy(process_list->restypes[i].hash_table); |
383 | process_list->restypes[i].hash_table = NULL; |
384 | } |
9e01e6d4 |
385 | g_ptr_array_free(process_list->index_to_pixmap, TRUE); |
386 | |
387 | g_free(process_list); |
388 | g_debug("processlist_destroy end"); |
389 | } |
390 | |
67f72973 |
391 | static gboolean remove_hash_item(void *key, |
58a9b31b |
392 | HashedResourceData *hashed_process_data, |
9e01e6d4 |
393 | ProcessList *process_list) |
394 | { |
395 | GtkTreeIter iter; |
396 | |
397 | iter = hashed_process_data->y_iter; |
398 | |
67f72973 |
399 | gtk_tree_store_remove (process_list->list_store, &iter); |
9e01e6d4 |
400 | gdk_pixmap_unref(hashed_process_data->pixmap); |
401 | |
58a9b31b |
402 | // TODO pmf: check this; might be needed |
403 | // if(likely(process_list->current_hash_data != NULL)) { |
404 | // if(likely(hashed_process_data == |
405 | // process_list->current_hash_data[process_info->trace_num][process_info->cpu])) |
406 | // process_list->current_hash_data[process_info->trace_num][process_info->cpu] = NULL; |
407 | // } |
9e01e6d4 |
408 | return TRUE; /* remove the element from the hash table */ |
409 | } |
410 | |
411 | void processlist_clear(ProcessList *process_list) |
412 | { |
67f72973 |
413 | int i; |
414 | |
9e01e6d4 |
415 | g_info("processlist_clear %p", process_list); |
416 | |
67f72973 |
417 | for(i=RV_RESOURCE_COUNT-1; i>=0; i--) { |
418 | g_hash_table_foreach_remove(process_list->restypes[i].hash_table, |
419 | (GHRFunc)remove_hash_item, |
420 | (gpointer)process_list); |
421 | } |
9e01e6d4 |
422 | process_list->number_of_process = 0; |
423 | update_index_to_pixmap(process_list); |
424 | } |
425 | |
426 | |
427 | GtkWidget *processlist_get_widget(ProcessList *process_list) |
428 | { |
429 | return process_list->process_list_widget; |
430 | } |
431 | |
432 | |
433 | void destroy_hash_key(gpointer key) |
434 | { |
435 | g_free(key); |
436 | } |
437 | |
438 | void destroy_hash_data(gpointer data) |
439 | { |
440 | g_free(data); |
441 | } |
442 | |
67f72973 |
443 | HashedResourceData *resourcelist_obtain_machine(ControlFlowData *resourceview_data, guint trace_num, guint id) |
9e01e6d4 |
444 | { |
67f72973 |
445 | ResourceUniqueNumeric *ru = g_new(ResourceUniqueNumeric, 1); |
446 | HashedResourceData *data = g_new(HashedResourceData, 1); |
447 | |
448 | /* Prepare hash key */ |
449 | ru->trace_num = trace_num; |
450 | ru->id = id; |
451 | |
452 | /* Search within hash table */ |
453 | GHashTable *ht = resourceview_data->process_list->restypes[RV_RESOURCE_MACHINE].hash_table; |
454 | data = g_hash_table_lookup(ht, ru); |
455 | |
456 | /* If not found in hash table, add it */ |
457 | if(data == NULL) { |
458 | GQuark name; |
459 | |
460 | data = g_malloc(sizeof(HashedResourceData)); |
461 | /* Prepare hashed data */ |
462 | data->type = RV_RESOURCE_MACHINE; |
463 | data->x.over = 0; |
464 | data->x.over_used = FALSE; |
465 | data->x.over_marked = FALSE; |
466 | data->x.middle = 0; // last |
467 | data->x.middle_used = FALSE; |
468 | data->x.middle_marked = FALSE; |
469 | data->x.under = 0; |
470 | data->x.under_used = FALSE; |
471 | data->x.under_marked = FALSE; |
472 | data->next_good_time = ltt_time_zero; |
473 | |
474 | data->height = resourceview_data->process_list->cell_height; |
475 | data->pixmap = |
476 | gdk_pixmap_new(resourceview_data->drawing->drawing_area->window, |
477 | resourceview_data->drawing->alloc_width, |
478 | data->height, |
479 | -1); |
480 | g_assert(data->pixmap); |
58a9b31b |
481 | |
67f72973 |
482 | gdk_draw_rectangle (data->pixmap, |
483 | resourceview_data->drawing->drawing_area->style->black_gc, |
484 | TRUE, |
485 | 0, 0, |
486 | resourceview_data->drawing->alloc_width, |
487 | data->height); |
488 | |
489 | /* add to hash table */ |
490 | g_hash_table_insert(ht, ru, data); |
491 | resourceview_data->process_list->number_of_process++; // TODO: check |
492 | |
493 | /* add to process list */ |
494 | { |
495 | gchar *str; |
496 | str = g_strdup_printf("Trace %u", id); |
497 | name = g_quark_from_string(str); |
498 | g_free(str); |
499 | } |
500 | |
501 | gtk_tree_store_append(resourceview_data->process_list->list_store, &data->y_iter, NULL); |
502 | gtk_tree_store_set(resourceview_data->process_list->list_store, &data->y_iter, |
503 | NAME_COLUMN, g_quark_to_string(name), DATA_COLUMN, data, |
504 | -1); |
505 | |
506 | update_index_to_pixmap(resourceview_data->process_list); |
507 | |
508 | int heightall = data->height * resourceview_data->process_list->number_of_process; |
509 | |
510 | gtk_widget_set_size_request(resourceview_data->drawing->drawing_area, |
511 | -1, |
512 | heightall); |
9e01e6d4 |
513 | |
67f72973 |
514 | gtk_widget_queue_draw(resourceview_data->drawing->drawing_area); |
515 | } |
516 | |
517 | gtk_tree_view_expand_all(resourceview_data->process_list->process_list_widget); |
518 | |
519 | return data; |
520 | } |
521 | |
522 | HashedResourceData *resourcelist_obtain_cpu(ControlFlowData *resourceview_data, guint trace_num, guint id) |
523 | { |
524 | ResourceUniqueNumeric *ru = g_new(ResourceUniqueNumeric, 1); |
525 | HashedResourceData *data = g_new(HashedResourceData, 1); |
9e01e6d4 |
526 | |
67f72973 |
527 | /* Prepare hash key */ |
528 | ru->trace_num = trace_num; |
529 | ru->id = id; |
9e01e6d4 |
530 | |
67f72973 |
531 | /* Search within hash table */ |
532 | GHashTable *ht = resourceview_data->process_list->restypes[RV_RESOURCE_CPU].hash_table; |
533 | data = g_hash_table_lookup(ht, ru); |
534 | |
535 | /* If not found in hash table, add it */ |
536 | if(data == NULL) { |
537 | GQuark name; |
538 | HashedResourceData *parent; |
539 | |
540 | /* Find the parent machine */ |
541 | parent = resourcelist_obtain_machine(resourceview_data, trace_num, trace_num); |
542 | |
543 | /* Prepare hashed data */ |
544 | data = g_malloc(sizeof(HashedResourceData)); |
545 | |
546 | data->type = RV_RESOURCE_CPU; |
547 | data->x.over = 0; |
548 | data->x.over_used = FALSE; |
549 | data->x.over_marked = FALSE; |
550 | data->x.middle = 0; // last |
551 | data->x.middle_used = FALSE; |
552 | data->x.middle_marked = FALSE; |
553 | data->x.under = 0; |
554 | data->x.under_used = FALSE; |
555 | data->x.under_marked = FALSE; |
556 | data->next_good_time = ltt_time_zero; |
557 | |
558 | data->height = resourceview_data->process_list->cell_height; |
559 | data->pixmap = |
560 | gdk_pixmap_new(resourceview_data->drawing->drawing_area->window, |
561 | resourceview_data->drawing->alloc_width, |
562 | data->height, |
563 | -1); |
564 | |
565 | gdk_draw_rectangle (data->pixmap, |
566 | resourceview_data->drawing->drawing_area->style->black_gc, |
567 | TRUE, |
568 | 0, 0, |
569 | resourceview_data->drawing->alloc_width, |
570 | data->height); |
9e01e6d4 |
571 | |
67f72973 |
572 | /* add to hash table */ |
573 | g_hash_table_insert(ht, ru, data); |
574 | resourceview_data->process_list->number_of_process++; // TODO: check |
9e01e6d4 |
575 | |
67f72973 |
576 | /* add to process list */ |
577 | { |
578 | gchar *str; |
579 | str = g_strdup_printf("CPU%u", id); |
580 | name = g_quark_from_string(str); |
581 | g_free(str); |
582 | } |
9e01e6d4 |
583 | |
67f72973 |
584 | gtk_tree_store_append(resourceview_data->process_list->list_store, &data->y_iter, &parent->y_iter); |
585 | gtk_tree_store_set(resourceview_data->process_list->list_store, &data->y_iter, |
586 | NAME_COLUMN, g_quark_to_string(name), DATA_COLUMN, data, |
587 | -1); |
9e01e6d4 |
588 | |
67f72973 |
589 | update_index_to_pixmap(resourceview_data->process_list); |
590 | |
591 | int heightall = data->height * resourceview_data->process_list->number_of_process; |
592 | |
593 | gtk_widget_set_size_request(resourceview_data->drawing->drawing_area, |
594 | -1, |
595 | heightall); |
596 | |
597 | gtk_widget_queue_draw(resourceview_data->drawing->drawing_area); |
598 | } |
599 | |
600 | return data; |
601 | } |
602 | |
603 | HashedResourceData *resourcelist_obtain_irq(ControlFlowData *resourceview_data, guint trace_num, guint id) |
604 | { |
605 | ResourceUniqueNumeric *ru = g_new(ResourceUniqueNumeric, 1); |
606 | HashedResourceData *data = g_new(HashedResourceData, 1); |
607 | |
608 | /* Prepare hash key */ |
609 | ru->trace_num = trace_num; |
610 | ru->id = id; |
9e01e6d4 |
611 | |
67f72973 |
612 | /* Search within hash table */ |
613 | GHashTable *ht = resourceview_data->process_list->restypes[RV_RESOURCE_IRQ].hash_table; |
614 | data = g_hash_table_lookup(ht, ru); |
615 | |
616 | /* If not found in hash table, add it */ |
617 | if(data == NULL) { |
618 | GQuark name; |
619 | HashedResourceData *parent; |
620 | |
621 | /* Find the parent machine */ |
622 | parent = resourcelist_obtain_machine(resourceview_data, trace_num, trace_num); |
623 | |
624 | /* Prepare hashed data */ |
625 | data = g_malloc(sizeof(HashedResourceData)); |
626 | |
627 | data->type = RV_RESOURCE_IRQ; |
628 | data->x.over = 0; |
629 | data->x.over_used = FALSE; |
630 | data->x.over_marked = FALSE; |
631 | data->x.middle = 0; // last |
632 | data->x.middle_used = FALSE; |
633 | data->x.middle_marked = FALSE; |
634 | data->x.under = 0; |
635 | data->x.under_used = FALSE; |
636 | data->x.under_marked = FALSE; |
637 | data->next_good_time = ltt_time_zero; |
638 | |
639 | data->height = resourceview_data->process_list->cell_height; |
640 | data->pixmap = |
641 | gdk_pixmap_new(resourceview_data->drawing->drawing_area->window, |
642 | resourceview_data->drawing->alloc_width, |
643 | data->height, |
644 | -1); |
645 | |
646 | gdk_draw_rectangle (data->pixmap, |
647 | resourceview_data->drawing->drawing_area->style->black_gc, |
9e01e6d4 |
648 | TRUE, |
649 | 0, 0, |
67f72973 |
650 | resourceview_data->drawing->alloc_width, |
651 | data->height); |
9e01e6d4 |
652 | |
67f72973 |
653 | /* add to hash table */ |
654 | g_hash_table_insert(ht, ru, data); |
655 | resourceview_data->process_list->number_of_process++; // TODO: check |
9e01e6d4 |
656 | |
67f72973 |
657 | /* add to process list */ |
658 | { |
659 | gchar *str; |
660 | str = g_strdup_printf("IRQ %u", id); |
661 | name = g_quark_from_string(str); |
662 | g_free(str); |
663 | } |
664 | |
665 | gtk_tree_store_append(resourceview_data->process_list->list_store, &data->y_iter, &parent->y_iter); |
666 | gtk_tree_store_set(resourceview_data->process_list->list_store, &data->y_iter, |
667 | NAME_COLUMN, g_quark_to_string(name), DATA_COLUMN, data, |
668 | -1); |
669 | |
670 | update_index_to_pixmap(resourceview_data->process_list); |
9e01e6d4 |
671 | |
67f72973 |
672 | int heightall = data->height * resourceview_data->process_list->number_of_process; |
673 | |
674 | gtk_widget_set_size_request(resourceview_data->drawing->drawing_area, |
675 | -1, |
676 | heightall); |
677 | |
678 | gtk_widget_queue_draw(resourceview_data->drawing->drawing_area); |
679 | } |
680 | |
681 | return data; |
682 | } |
9e01e6d4 |
683 | |
67f72973 |
684 | HashedResourceData *resourcelist_obtain_bdev(ControlFlowData *resourceview_data, guint trace_num, guint id) |
9e01e6d4 |
685 | { |
67f72973 |
686 | ResourceUniqueNumeric *ru = g_new(ResourceUniqueNumeric, 1); |
687 | HashedResourceData *data = g_new(HashedResourceData, 1); |
688 | |
689 | /* Prepare hash key */ |
690 | ru->trace_num = trace_num; |
691 | ru->id = id; |
692 | |
693 | /* Search within hash table */ |
694 | GHashTable *ht = resourceview_data->process_list->restypes[RV_RESOURCE_BDEV].hash_table; |
695 | data = g_hash_table_lookup(ht, ru); |
696 | |
697 | /* If not found in hash table, add it */ |
698 | if(data == NULL) { |
699 | GQuark name; |
700 | HashedResourceData *parent; |
701 | |
702 | /* Find the parent machine */ |
703 | parent = resourcelist_obtain_machine(resourceview_data, trace_num, trace_num); |
704 | |
705 | /* Prepare hashed data */ |
706 | data = g_malloc(sizeof(HashedResourceData)); |
707 | |
708 | data->type = RV_RESOURCE_BDEV; |
709 | data->x.over = 0; |
710 | data->x.over_used = FALSE; |
711 | data->x.over_marked = FALSE; |
712 | data->x.middle = 0; // last |
713 | data->x.middle_used = FALSE; |
714 | data->x.middle_marked = FALSE; |
715 | data->x.under = 0; |
716 | data->x.under_used = FALSE; |
717 | data->x.under_marked = FALSE; |
718 | data->next_good_time = ltt_time_zero; |
719 | |
720 | data->height = resourceview_data->process_list->cell_height; |
721 | data->pixmap = |
722 | gdk_pixmap_new(resourceview_data->drawing->drawing_area->window, |
723 | resourceview_data->drawing->alloc_width, |
724 | data->height, |
725 | -1); |
9e01e6d4 |
726 | |
67f72973 |
727 | gdk_draw_rectangle (data->pixmap, |
728 | resourceview_data->drawing->drawing_area->style->black_gc, |
729 | TRUE, |
730 | 0, 0, |
731 | resourceview_data->drawing->alloc_width, |
732 | data->height); |
9e01e6d4 |
733 | |
67f72973 |
734 | /* add to hash table */ |
735 | g_hash_table_insert(ht, ru, data); |
736 | resourceview_data->process_list->number_of_process++; // TODO: check |
9e01e6d4 |
737 | |
67f72973 |
738 | /* add to process list */ |
739 | { |
740 | gchar *str; |
741 | str = g_strdup_printf("Block (%u,%u)", MAJOR(id), MINOR(id)); |
742 | name = g_quark_from_string(str); |
743 | g_free(str); |
744 | } |
9e01e6d4 |
745 | |
67f72973 |
746 | gtk_tree_store_append(resourceview_data->process_list->list_store, &data->y_iter, &parent->y_iter); |
747 | gtk_tree_store_set(resourceview_data->process_list->list_store, &data->y_iter, |
748 | NAME_COLUMN, g_quark_to_string(name), DATA_COLUMN, data, |
749 | -1); |
750 | |
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 | } |
9e01e6d4 |
761 | |
67f72973 |
762 | return data; |
9e01e6d4 |
763 | } |