convert from svn repository: remove tags directory
[lttv.git] / trunk / lttv / lttv / modules / gui / resourceview / processlist.c
CommitLineData
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 45gint 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 60static 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 68static 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
79void destroy_hash_key(gpointer key);
80
81void destroy_hash_data(gpointer data);
82
83
84gboolean 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 109void 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
144void 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 180static 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 201void 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
53f78441 217 /* If cell_height is still 0, the only element in the tree is a temporary
218 * element that has no pixmap, see also processlist_construct() */
219 if (process_list->cell_height != 0) {
220 gtk_tree_model_foreach(GTK_TREE_MODEL(process_list->list_store),
67f72973 221 (GtkTreeModelForeachFunc)update_index_to_pixmap_each, &arg);
53f78441 222 }
27274b95 223
224 /* now that we know the exact number of items, set it */
225 g_ptr_array_set_size(process_list->index_to_pixmap, arg.count);
9e01e6d4 226}
227
228
67f72973 229static void update_pixmap_size_each(void *key,
58a9b31b 230 HashedResourceData *value,
9e01e6d4 231 guint width)
232{
233 GdkPixmap *old_pixmap = value->pixmap;
234
235 value->pixmap =
236 gdk_pixmap_new(old_pixmap,
237 width,
238 value->height,
239 -1);
240
241 gdk_pixmap_unref(old_pixmap);
242}
243
244
245void update_pixmap_size(ProcessList *process_list, guint width)
246{
67f72973 247 int i;
248 for(i=0; i<RV_RESOURCE_COUNT; i++) {
43ed82b5 249 g_hash_table_foreach(process_list->restypes[i].hash_table,
250 (GHFunc)update_pixmap_size_each,
251 GUINT_TO_POINTER(width));
67f72973 252 }
9e01e6d4 253}
254
255
256typedef struct _CopyPixmap {
257 GdkDrawable *dest;
258 GdkGC *gc;
259 GdkDrawable *src;
260 gint xsrc, ysrc, xdest, ydest, width, height;
261} CopyPixmap;
262
67f72973 263static void copy_pixmap_region_each(void *key,
58a9b31b 264 HashedResourceData *value,
9e01e6d4 265 CopyPixmap *cp)
266{
267 GdkPixmap *src = cp->src;
268 GdkPixmap *dest = cp->dest;
269
270 if(dest == NULL)
271 dest = value->pixmap;
272 if(src == NULL)
273 src = value->pixmap;
274
275 gdk_draw_drawable (dest,
276 cp->gc,
277 src,
278 cp->xsrc, cp->ysrc,
279 cp->xdest, cp->ydest,
280 cp->width, cp->height);
281}
282
9e01e6d4 283void copy_pixmap_region(ProcessList *process_list, GdkDrawable *dest,
284 GdkGC *gc, GdkDrawable *src,
285 gint xsrc, gint ysrc,
286 gint xdest, gint ydest, gint width, gint height)
287{
67f72973 288 int i;
9e01e6d4 289 CopyPixmap cp = { dest, gc, src, xsrc, ysrc, xdest, ydest, width, height };
290
67f72973 291 for(i=0; i<RV_RESOURCE_COUNT; i++) {
292 g_hash_table_foreach(process_list->restypes[i].hash_table,
9e01e6d4 293 (GHFunc)copy_pixmap_region_each,
294 &cp);
67f72973 295 }
9e01e6d4 296}
297
298
299
300typedef struct _RectanglePixmap {
301 gboolean filled;
302 gint x, y, width, height;
303 GdkGC *gc;
304} RectanglePixmap;
305
67f72973 306static void rectangle_pixmap_each(void *key,
58a9b31b 307 HashedResourceData *value,
9e01e6d4 308 RectanglePixmap *rp)
309{
310 if(rp->height == -1)
311 rp->height = value->height;
312
313 gdk_draw_rectangle (value->pixmap,
314 rp->gc,
315 rp->filled,
316 rp->x, rp->y,
317 rp->width, rp->height);
318}
319
9e01e6d4 320void rectangle_pixmap(ProcessList *process_list, GdkGC *gc,
321 gboolean filled, gint x, gint y, gint width, gint height)
322{
67f72973 323 int i;
9e01e6d4 324 RectanglePixmap rp = { filled, x, y, width, height, gc };
325
67f72973 326 for(i=0; i<RV_RESOURCE_COUNT; i++) {
327 g_hash_table_foreach(process_list->restypes[i].hash_table,
9e01e6d4 328 (GHFunc)rectangle_pixmap_each,
329 &rp);
67f72973 330 }
9e01e6d4 331}
332
9e01e6d4 333/* Renders each pixmaps into on big drawable */
334void copy_pixmap_to_screen(ProcessList *process_list,
335 GdkDrawable *dest,
336 GdkGC *gc,
337 gint x, gint y,
338 gint width, gint height)
339{
340 if(process_list->index_to_pixmap->len == 0) return;
341 guint cell_height = process_list->cell_height;
342
343 /* Get indexes */
344 gint begin = floor(y/(double)cell_height);
345 gint end = MIN(ceil((y+height)/(double)cell_height),
346 process_list->index_to_pixmap->len);
347 gint i;
348
349 for(i=begin; i<end; i++) {
350 g_assert(i<process_list->index_to_pixmap->len);
351 /* Render the pixmap to the screen */
352 GdkPixmap *pixmap =
353 //(GdkPixmap*)g_ptr_array_index(process_list->index_to_pixmap, i);
354 GDK_PIXMAP(g_ptr_array_index(process_list->index_to_pixmap, i));
355
356 gdk_draw_drawable (dest,
357 gc,
358 pixmap,
359 x, 0,
360 x, i*cell_height,
361 width, cell_height);
362
363 }
9e01e6d4 364}
365
9e01e6d4 366ProcessList *processlist_construct(void)
367{
368 GtkTreeViewColumn *column;
369 GtkCellRenderer *renderer;
370
371 ProcessList* process_list = g_new(ProcessList,1);
372
373 process_list->number_of_process = 0;
374
375 process_list->current_hash_data = NULL;
376
377 /* Create the Process list */
67f72973 378 process_list->list_store = gtk_tree_store_new ( N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER);
9e01e6d4 379
380 process_list->process_list_widget =
381 gtk_tree_view_new_with_model
382 (GTK_TREE_MODEL (process_list->list_store));
0dd8209a 383 g_object_set(process_list->process_list_widget, "enable-tree-lines", TRUE, NULL);
9e01e6d4 384
385 g_object_unref (G_OBJECT (process_list->list_store));
386
fb93b151 387 gtk_tree_sortable_set_default_sort_func(
388 GTK_TREE_SORTABLE(process_list->list_store),
389 resource_sort_func,
390 NULL,
391 NULL);
392
0dd8209a 393
fb93b151 394 gtk_tree_sortable_set_sort_column_id(
395 GTK_TREE_SORTABLE(process_list->list_store),
396 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
397 GTK_SORT_ASCENDING);
9e01e6d4 398
9e01e6d4 399 gtk_tree_view_set_headers_visible(
400 GTK_TREE_VIEW(process_list->process_list_widget), TRUE);
401
402 /* Create a column, associating the "text" attribute of the
403 * cell_renderer to the first column of the model */
404 /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */
405 renderer = gtk_cell_renderer_text_new ();
406 process_list->renderer = renderer;
407
27274b95 408 g_signal_connect(process_list->process_list_widget, "row-expanded", G_CALLBACK(expand_event), process_list);
409 g_signal_connect(process_list->process_list_widget, "row-collapsed", G_CALLBACK(collapse_event), process_list);
9e01e6d4 410
53f78441 411 /* Add a temporary row to the model to get the cell size when the first
412 * real process is added. */
413 GtkTreeIter iter;
414 GtkTreePath *path;
415 path = gtk_tree_path_new_first();
416 gtk_tree_model_get_iter (gtk_tree_view_get_model(GTK_TREE_VIEW(
417 process_list->process_list_widget)), &iter, path);
418 gtk_tree_store_append(process_list->list_store, &iter, NULL);
419 gtk_tree_path_free(path);
420
421 process_list->cell_height = 0; // not ready to get size yet.
9e01e6d4 422
c4e6f4dc 423 column = gtk_tree_view_column_new_with_attributes ( "Resource",
9e01e6d4 424 renderer,
425 "text",
58a9b31b 426 NAME_COLUMN,
9e01e6d4 427 NULL);
428 gtk_tree_view_column_set_alignment (column, 0.0);
429 gtk_tree_view_column_set_fixed_width (column, 45);
430 gtk_tree_view_append_column (
431 GTK_TREE_VIEW (process_list->process_list_widget), column);
432
433 process_list->button = column->button;
9e01e6d4 434
435 g_object_set_data_full(
436 G_OBJECT(process_list->process_list_widget),
437 "process_list_Data",
438 process_list,
439 (GDestroyNotify)processlist_destroy);
440
441 process_list->index_to_pixmap = g_ptr_array_sized_new(ALLOCATE_PROCESSES);
67f72973 442
443 process_list->restypes[RV_RESOURCE_MACHINE].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct);
444 process_list->restypes[RV_RESOURCE_CPU].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct);
445 process_list->restypes[RV_RESOURCE_IRQ].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct);
0305fe77 446 process_list->restypes[RV_RESOURCE_SOFT_IRQ].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct);
38726a78 447 process_list->restypes[RV_RESOURCE_TRAP].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct);
67f72973 448 process_list->restypes[RV_RESOURCE_BDEV].hash_table = g_hash_table_new(ru_numeric_hash_fct, ru_numeric_equ_fct);
0dd8209a 449
9e01e6d4 450 return process_list;
451}
452
453void processlist_destroy(ProcessList *process_list)
454{
67f72973 455 int i;
456
9e01e6d4 457 g_debug("processlist_destroy %p", process_list);
67f72973 458
459 for(i=0; i<RV_RESOURCE_COUNT; i++) {
460 g_hash_table_destroy(process_list->restypes[i].hash_table);
461 process_list->restypes[i].hash_table = NULL;
462 }
9e01e6d4 463 g_ptr_array_free(process_list->index_to_pixmap, TRUE);
464
465 g_free(process_list);
466 g_debug("processlist_destroy end");
467}
468
67f72973 469static gboolean remove_hash_item(void *key,
58a9b31b 470 HashedResourceData *hashed_process_data,
9e01e6d4 471 ProcessList *process_list)
472{
473 GtkTreeIter iter;
474
475 iter = hashed_process_data->y_iter;
476
67f72973 477 gtk_tree_store_remove (process_list->list_store, &iter);
9e01e6d4 478 gdk_pixmap_unref(hashed_process_data->pixmap);
479
58a9b31b 480// TODO pmf: check this; might be needed
481// if(likely(process_list->current_hash_data != NULL)) {
482// if(likely(hashed_process_data ==
483// process_list->current_hash_data[process_info->trace_num][process_info->cpu]))
484// process_list->current_hash_data[process_info->trace_num][process_info->cpu] = NULL;
485// }
9e01e6d4 486 return TRUE; /* remove the element from the hash table */
487}
488
489void processlist_clear(ProcessList *process_list)
490{
67f72973 491 int i;
492
9e01e6d4 493 g_info("processlist_clear %p", process_list);
494
67f72973 495 for(i=RV_RESOURCE_COUNT-1; i>=0; i--) {
496 g_hash_table_foreach_remove(process_list->restypes[i].hash_table,
497 (GHRFunc)remove_hash_item,
498 (gpointer)process_list);
499 }
9e01e6d4 500 process_list->number_of_process = 0;
501 update_index_to_pixmap(process_list);
502}
503
504
505GtkWidget *processlist_get_widget(ProcessList *process_list)
506{
507 return process_list->process_list_widget;
508}
509
510
511void destroy_hash_key(gpointer key)
512{
513 g_free(key);
514}
515
516void destroy_hash_data(gpointer data)
517{
518 g_free(data);
519}
520
37b0f1ed 521GQuark make_cpu_name(ControlFlowData *resourceview_data, guint trace_num, guint id)
522{
523 GQuark name;
524 gchar *str;
525
526 str = g_strdup_printf("CPU%u", id);
527 name = g_quark_from_string(str);
528 g_free(str);
529
530 return name;
531}
532
533GQuark make_irq_name(ControlFlowData *resourceview_data, guint trace_num, guint id)
534{
535 GQuark name;
536 gchar *str;
537
538 str = g_strdup_printf("IRQ %u", id);
539 name = g_quark_from_string(str);
540 g_free(str);
541
542 return name;
543}
544
0305fe77 545GQuark make_soft_irq_name(ControlFlowData *resourceview_data, guint trace_num, guint id)
546{
547 GQuark name;
548 gchar *str;
549
550 str = g_strdup_printf("SOFTIRQ %u", id);
551 name = g_quark_from_string(str);
552 g_free(str);
553
554 return name;
555}
556
38726a78 557GQuark make_trap_name(ControlFlowData *resourceview_data, guint trace_num, guint id)
558{
559 GQuark name;
560 gchar *str;
561
562 str = g_strdup_printf("Trap %u", id);
563 name = g_quark_from_string(str);
564 g_free(str);
565
566 return name;
567}
568
37b0f1ed 569GQuark make_bdev_name(ControlFlowData *resourceview_data, guint trace_num, guint id)
570{
571 GQuark name;
572 gchar *str;
573
574 str = g_strdup_printf("Block (%u,%u)", MAJOR(id), MINOR(id));
575 name = g_quark_from_string(str);
576 g_free(str);
577
578 return name;
579}
580
67f72973 581HashedResourceData *resourcelist_obtain_machine(ControlFlowData *resourceview_data, guint trace_num, guint id)
9e01e6d4 582{
67f72973 583 ResourceUniqueNumeric *ru = g_new(ResourceUniqueNumeric, 1);
584 HashedResourceData *data = g_new(HashedResourceData, 1);
585
586 /* Prepare hash key */
587 ru->trace_num = trace_num;
588 ru->id = id;
589
590 /* Search within hash table */
591 GHashTable *ht = resourceview_data->process_list->restypes[RV_RESOURCE_MACHINE].hash_table;
592 data = g_hash_table_lookup(ht, ru);
593
594 /* If not found in hash table, add it */
595 if(data == NULL) {
596 GQuark name;
597
598 data = g_malloc(sizeof(HashedResourceData));
599 /* Prepare hashed data */
600 data->type = RV_RESOURCE_MACHINE;
601 data->x.over = 0;
602 data->x.over_used = FALSE;
603 data->x.over_marked = FALSE;
604 data->x.middle = 0; // last
605 data->x.middle_used = FALSE;
606 data->x.middle_marked = FALSE;
607 data->x.under = 0;
608 data->x.under_used = FALSE;
609 data->x.under_marked = FALSE;
610 data->next_good_time = ltt_time_zero;
27274b95 611 data->hidden = 0;
67f72973 612
53f78441 613 if (resourceview_data->process_list->cell_height == 0) {
614 GtkTreePath *path;
615 GdkRectangle rect;
616 GtkTreeIter iter;
617
618 path = gtk_tree_path_new_first();
619 gtk_tree_model_get_iter(gtk_tree_view_get_model(GTK_TREE_VIEW(
620 resourceview_data->process_list->process_list_widget)),
621 &iter, path);
622 gtk_tree_view_get_background_area(GTK_TREE_VIEW(
623 resourceview_data->process_list->process_list_widget),
624 path, NULL, &rect);
625 gtk_tree_store_remove(resourceview_data->process_list->list_store,
626 &iter);
627 gtk_tree_path_free(path);
628 resourceview_data->process_list->cell_height = rect.height;
629 }
630
67f72973 631 data->height = resourceview_data->process_list->cell_height;
632 data->pixmap =
633 gdk_pixmap_new(resourceview_data->drawing->drawing_area->window,
634 resourceview_data->drawing->alloc_width,
635 data->height,
636 -1);
637 g_assert(data->pixmap);
58a9b31b 638
67f72973 639 gdk_draw_rectangle (data->pixmap,
640 resourceview_data->drawing->drawing_area->style->black_gc,
641 TRUE,
642 0, 0,
643 resourceview_data->drawing->alloc_width,
644 data->height);
645
646 /* add to hash table */
647 g_hash_table_insert(ht, ru, data);
648 resourceview_data->process_list->number_of_process++; // TODO: check
649
650 /* add to process list */
651 {
652 gchar *str;
653 str = g_strdup_printf("Trace %u", id);
654 name = g_quark_from_string(str);
655 g_free(str);
656 }
657
658 gtk_tree_store_append(resourceview_data->process_list->list_store, &data->y_iter, NULL);
659 gtk_tree_store_set(resourceview_data->process_list->list_store, &data->y_iter,
660 NAME_COLUMN, g_quark_to_string(name), DATA_COLUMN, data,
661 -1);
662
663 update_index_to_pixmap(resourceview_data->process_list);
664
665 int heightall = data->height * resourceview_data->process_list->number_of_process;
666
667 gtk_widget_set_size_request(resourceview_data->drawing->drawing_area,
668 -1,
669 heightall);
9e01e6d4 670
67f72973 671 gtk_widget_queue_draw(resourceview_data->drawing->drawing_area);
672 }
673
27274b95 674 /* expand the newly added machine */
675 {
676 GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(resourceview_data->process_list->process_list_widget));
677 GtkTreePath *path;
678 path = gtk_tree_model_get_path(model, &data->y_iter);
679
680 gtk_tree_view_expand_row(GTK_TREE_VIEW(resourceview_data->process_list->process_list_widget), path, FALSE);
681
682 gtk_tree_path_free(path);
683 }
67f72973 684
685 return data;
686}
687
37b0f1ed 688HashedResourceData *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 689{
690 ResourceUniqueNumeric *ru = g_new(ResourceUniqueNumeric, 1);
691 HashedResourceData *data = g_new(HashedResourceData, 1);
9e01e6d4 692
67f72973 693 /* Prepare hash key */
27274b95 694 ru->ru.type = &(resourceview_data->process_list->restypes[res_type]);
67f72973 695 ru->trace_num = trace_num;
86f3d84b 696 g_assert(id != -1);
67f72973 697 ru->id = id;
9e01e6d4 698
67f72973 699 /* Search within hash table */
37b0f1ed 700 GHashTable *ht = resourceview_data->process_list->restypes[res_type].hash_table;
67f72973 701 data = g_hash_table_lookup(ht, ru);
702
703 /* If not found in hash table, add it */
704 if(data == NULL) {
705 GQuark name;
706 HashedResourceData *parent;
707
708 /* Find the parent machine */
709 parent = resourcelist_obtain_machine(resourceview_data, trace_num, trace_num);
710
711 /* Prepare hashed data */
712 data = g_malloc(sizeof(HashedResourceData));
713
37b0f1ed 714 data->type = res_type;
67f72973 715 data->x.over = 0;
716 data->x.over_used = FALSE;
717 data->x.over_marked = FALSE;
718 data->x.middle = 0; // last
719 data->x.middle_used = FALSE;
720 data->x.middle_marked = FALSE;
721 data->x.under = 0;
722 data->x.under_used = FALSE;
723 data->x.under_marked = FALSE;
724 data->next_good_time = ltt_time_zero;
725
53f78441 726 if (resourceview_data->process_list->cell_height == 0) {
727 GtkTreePath *path;
728 GdkRectangle rect;
729 GtkTreeIter iter;
730
731 path = gtk_tree_path_new_first();
732 gtk_tree_model_get_iter(gtk_tree_view_get_model(GTK_TREE_VIEW(
733 resourceview_data->process_list->process_list_widget)), &iter,
734 path);
735 gtk_tree_view_get_background_area(GTK_TREE_VIEW(
736 resourceview_data->process_list->process_list_widget), path,
737 NULL, &rect);
738 gtk_tree_store_remove(resourceview_data->process_list->list_store,
739 &iter);
740 gtk_tree_path_free(path);
741 resourceview_data->process_list->cell_height = rect.height;
742 }
743
67f72973 744 data->height = resourceview_data->process_list->cell_height;
745 data->pixmap =
746 gdk_pixmap_new(resourceview_data->drawing->drawing_area->window,
747 resourceview_data->drawing->alloc_width,
748 data->height,
749 -1);
750
751 gdk_draw_rectangle (data->pixmap,
752 resourceview_data->drawing->drawing_area->style->black_gc,
753 TRUE,
754 0, 0,
755 resourceview_data->drawing->alloc_width,
756 data->height);
9e01e6d4 757
67f72973 758 /* add to hash table */
759 g_hash_table_insert(ht, ru, data);
760 resourceview_data->process_list->number_of_process++; // TODO: check
9e01e6d4 761
67f72973 762 /* add to process list */
37b0f1ed 763 name = make_name_func(resourceview_data, trace_num, id);
9e01e6d4 764
67f72973 765 gtk_tree_store_append(resourceview_data->process_list->list_store, &data->y_iter, &parent->y_iter);
766 gtk_tree_store_set(resourceview_data->process_list->list_store, &data->y_iter,
767 NAME_COLUMN, g_quark_to_string(name), DATA_COLUMN, data,
768 -1);
9e01e6d4 769
27274b95 770 /* Determine if we should add it hidden or not */
771 {
772 gboolean result;
773 GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(resourceview_data->process_list->process_list_widget));
774 GtkTreeIter parent_iter;
775
776 result = gtk_tree_model_iter_parent(model, &parent_iter, &data->y_iter);
777 GtkTreePath *path = gtk_tree_model_get_path(model, &parent_iter);
778 data->hidden = gtk_tree_view_row_expanded(GTK_TREE_VIEW(resourceview_data->process_list->process_list_widget), path)?0:1;
779 gtk_tree_path_free(path);
780 }
781
782
67f72973 783 update_index_to_pixmap(resourceview_data->process_list);
784
785 int heightall = data->height * resourceview_data->process_list->number_of_process;
786
787 gtk_widget_set_size_request(resourceview_data->drawing->drawing_area,
788 -1,
789 heightall);
790
791 gtk_widget_queue_draw(resourceview_data->drawing->drawing_area);
792 }
793
794 return data;
795}
796
37b0f1ed 797HashedResourceData *resourcelist_obtain_cpu(ControlFlowData *resourceview_data, guint trace_num, guint id)
67f72973 798{
37b0f1ed 799 return resourcelist_obtain_generic(resourceview_data, RV_RESOURCE_CPU, trace_num, id, make_cpu_name);
800}
67f72973 801
37b0f1ed 802HashedResourceData *resourcelist_obtain_irq(ControlFlowData *resourceview_data, guint trace_num, guint id)
803{
804 return resourcelist_obtain_generic(resourceview_data, RV_RESOURCE_IRQ, trace_num, id, make_irq_name);
67f72973 805}
9e01e6d4 806
0305fe77 807HashedResourceData *resourcelist_obtain_soft_irq(ControlFlowData *resourceview_data, guint trace_num, guint id)
808{
809 return resourcelist_obtain_generic(resourceview_data, RV_RESOURCE_SOFT_IRQ, trace_num, id, make_soft_irq_name);
810}
811
38726a78 812HashedResourceData *resourcelist_obtain_trap(ControlFlowData *resourceview_data, guint trace_num, guint id)
813{
814 return resourcelist_obtain_generic(resourceview_data, RV_RESOURCE_TRAP, trace_num, id, make_trap_name);
815}
816
67f72973 817HashedResourceData *resourcelist_obtain_bdev(ControlFlowData *resourceview_data, guint trace_num, guint id)
9e01e6d4 818{
37b0f1ed 819 return resourcelist_obtain_generic(resourceview_data, RV_RESOURCE_BDEV, trace_num, id, make_bdev_name);
9e01e6d4 820}
37b0f1ed 821
This page took 0.067707 seconds and 4 git commands to generate.