ed775422c8c07aa5969bddec97124e420b21df11
[lttv.git] / lttv / modules / gui / controlflow / processlist.c
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)
35
36 /* Preallocated Size of the index_to_pixmap array */
37 #define ALLOCATE_PROCESSES 1000
38
39 /*****************************************************************************
40 * Methods to synchronize process list *
41 *****************************************************************************/
42
43
44 gint process_sort_func ( GtkTreeModel *model,
45 GtkTreeIter *it_a,
46 GtkTreeIter *it_b,
47 gpointer user_data)
48 {
49 gchar *a_name;
50 gchar *a_brand;
51 guint a_pid, a_tgid, a_ppid, a_cpu;
52 gulong a_birth_s, a_birth_ns;
53 guint a_trace;
54
55 gchar *b_name;
56 gchar *b_brand;
57 guint b_pid, b_tgid, b_ppid, b_cpu;
58 gulong b_birth_s, b_birth_ns;
59 guint b_trace;
60
61 gtk_tree_model_get(model,
62 it_a,
63 PROCESS_COLUMN, &a_name,
64 BRAND_COLUMN, &a_brand,
65 PID_COLUMN, &a_pid,
66 TGID_COLUMN, &a_tgid,
67 PPID_COLUMN, &a_ppid,
68 CPU_COLUMN, &a_cpu,
69 BIRTH_S_COLUMN, &a_birth_s,
70 BIRTH_NS_COLUMN, &a_birth_ns,
71 TRACE_COLUMN, &a_trace,
72 -1);
73
74 gtk_tree_model_get(model,
75 it_b,
76 PROCESS_COLUMN, &b_name,
77 BRAND_COLUMN, &b_brand,
78 PID_COLUMN, &b_pid,
79 TGID_COLUMN, &b_tgid,
80 PPID_COLUMN, &b_ppid,
81 CPU_COLUMN, &b_cpu,
82 BIRTH_S_COLUMN, &b_birth_s,
83 BIRTH_NS_COLUMN, &b_birth_ns,
84 TRACE_COLUMN, &b_trace,
85 -1);
86
87
88 /* Order by PID */
89 if(a_pid == 0 && b_pid == 0) {
90 /* If 0, order by CPU */
91 if(a_cpu > b_cpu) return 1;
92 if(a_cpu < b_cpu) return -1;
93
94 } else { /* if not 0, order by pid */
95
96 if(a_pid > b_pid) return 1;
97 if(a_pid < b_pid) return -1;
98 }
99
100 /* Order by birth second */
101
102 if(a_birth_s > b_birth_s) return 1;
103 if(a_birth_s < b_birth_s) return -1;
104
105
106 /* Order by birth nanosecond */
107 if(a_birth_ns > b_birth_ns) return 1;
108 if(a_birth_ns < b_birth_ns) return -1;
109
110 /* Order by trace_num */
111 if(a_trace > b_trace) return 1;
112 if(a_trace < b_trace) return -1;
113
114 return 0;
115
116 }
117
118 static guint process_list_hash_fct(gconstpointer key)
119 {
120 guint pid = ((const ProcessInfo*)key)->pid;
121 return ((pid>>8 ^ pid>>4 ^ pid>>2 ^ pid) ^ ((const ProcessInfo*)key)->cpu);
122 }
123
124 /* If hash is good, should be different */
125 static gboolean process_list_equ_fct(gconstpointer a, gconstpointer b)
126 {
127 const ProcessInfo *pa = (const ProcessInfo*)a;
128 const ProcessInfo *pb = (const ProcessInfo*)b;
129
130 gboolean ret = TRUE;
131
132 if(likely(pa->pid != pb->pid))
133 ret = FALSE;
134 if(likely((pa->pid == 0 && (pa->cpu != pb->cpu))))
135 ret = FALSE;
136 //TODO ybrosseau 2012-09-18 Check if we want to reenable birth comparision
137 // We currently do not have valid birth info, so don't compare it
138 /* if(unlikely(ltt_time_compare(pa->birth, pb->birth) != 0))
139 ret = FALSE;*/
140 if(unlikely(pa->trace_num != pb->trace_num))
141 ret = FALSE;
142
143 return ret;
144 }
145
146 void destroy_hash_key(gpointer key);
147
148 void destroy_hash_data(gpointer data);
149
150
151 gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer data)
152 {
153 ControlFlowData *control_flow_data =
154 (ControlFlowData*)g_object_get_data(
155 G_OBJECT(widget),
156 "control_flow_data");
157 unsigned int cell_height =
158 get_cell_height(GTK_TREE_VIEW(control_flow_data->process_list->process_list_widget));
159
160 switch(event->direction) {
161 case GDK_SCROLL_UP:
162 gtk_adjustment_set_value(control_flow_data->v_adjust,
163 gtk_adjustment_get_value(control_flow_data->v_adjust) - cell_height);
164 break;
165 case GDK_SCROLL_DOWN:
166 gtk_adjustment_set_value(control_flow_data->v_adjust,
167 gtk_adjustment_get_value(control_flow_data->v_adjust) + cell_height);
168 break;
169 default:
170 g_error("should only scroll up and down.");
171 }
172 return TRUE;
173 }
174
175
176 static void update_index_to_pixmap_each(ProcessInfo *key,
177 HashedProcessData *value,
178 ProcessList *process_list)
179 {
180 guint array_index = processlist_get_index_from_data(process_list, value);
181
182 g_assert(array_index < process_list->index_to_pixmap->len);
183
184 GdkPixmap **pixmap =
185 (GdkPixmap**)&g_ptr_array_index(process_list->index_to_pixmap, array_index);
186
187 *pixmap = value->pixmap;
188 }
189
190
191 void update_index_to_pixmap(ProcessList *process_list)
192 {
193 g_ptr_array_set_size(process_list->index_to_pixmap,
194 g_hash_table_size(process_list->process_hash));
195 g_hash_table_foreach(process_list->process_hash,
196 (GHFunc)update_index_to_pixmap_each,
197 process_list);
198 }
199
200
201 static void update_pixmap_size_each(ProcessInfo *key,
202 HashedProcessData *value,
203 guint width)
204 {
205 GdkPixmap *old_pixmap = value->pixmap;
206
207 value->pixmap =
208 gdk_pixmap_new(old_pixmap,
209 width,
210 value->height,
211 -1);
212
213 gdk_pixmap_unref(old_pixmap);
214 }
215
216
217 void update_pixmap_size(ProcessList *process_list, guint width)
218 {
219 g_hash_table_foreach(process_list->process_hash,
220 (GHFunc)update_pixmap_size_each,
221 GUINT_TO_POINTER(width));
222 }
223
224
225 typedef struct _CopyPixmap {
226 GdkDrawable *dest;
227 GdkGC *gc;
228 GdkDrawable *src;
229 gint xsrc, ysrc, xdest, ydest, width, height;
230 } CopyPixmap;
231
232 static void copy_pixmap_region_each(ProcessInfo *key,
233 HashedProcessData *value,
234 CopyPixmap *cp)
235 {
236 GdkPixmap *src = cp->src;
237 GdkPixmap *dest = cp->dest;
238
239 if(dest == NULL)
240 dest = value->pixmap;
241 if(src == NULL)
242 src = value->pixmap;
243
244 gdk_draw_drawable (dest,
245 cp->gc,
246 src,
247 cp->xsrc, cp->ysrc,
248 cp->xdest, cp->ydest,
249 cp->width, cp->height);
250 }
251
252
253
254
255 void copy_pixmap_region(ProcessList *process_list, GdkDrawable *dest,
256 GdkGC *gc, GdkDrawable *src,
257 gint xsrc, gint ysrc,
258 gint xdest, gint ydest, gint width, gint height)
259 {
260 CopyPixmap cp = { dest, gc, src, xsrc, ysrc, xdest, ydest, width, height };
261
262 g_hash_table_foreach(process_list->process_hash,
263 (GHFunc)copy_pixmap_region_each,
264 &cp);
265 }
266
267
268
269 typedef struct _RectanglePixmap {
270 gboolean filled;
271 gint x, y, width, height;
272 GdkGC *gc;
273 } RectanglePixmap;
274
275 static void rectangle_pixmap_each(ProcessInfo *key,
276 HashedProcessData *value,
277 RectanglePixmap *rp)
278 {
279 if(rp->height == -1)
280 rp->height = value->height;
281
282 gdk_draw_rectangle (value->pixmap,
283 rp->gc,
284 rp->filled,
285 rp->x, rp->y,
286 rp->width, rp->height);
287 }
288
289
290
291
292 void rectangle_pixmap(ProcessList *process_list, GdkGC *gc,
293 gboolean filled, gint x, gint y, gint width, gint height)
294 {
295 RectanglePixmap rp = { filled, x, y, width, height, gc };
296
297 g_hash_table_foreach(process_list->process_hash,
298 (GHFunc)rectangle_pixmap_each,
299 &rp);
300 }
301
302
303 /* Renders each pixmaps into on big drawable */
304 void copy_pixmap_to_screen(ProcessList *process_list,
305 GdkDrawable *dest,
306 GdkGC *gc,
307 gint x, gint y,
308 gint width, gint height)
309 {
310 if(process_list->index_to_pixmap->len == 0) return;
311 guint cell_height = process_list->cell_height;
312
313 /* Get indexes */
314 gint begin = floor(y/(double)cell_height);
315 gint end = MIN(ceil((y+height)/(double)cell_height),
316 process_list->index_to_pixmap->len);
317 gint i;
318
319 for(i=begin; i<end; i++) {
320 g_assert(i<process_list->index_to_pixmap->len);
321 /* Render the pixmap to the screen */
322 GdkPixmap *pixmap =
323 //(GdkPixmap*)g_ptr_array_index(process_list->index_to_pixmap, i);
324 GDK_PIXMAP(g_ptr_array_index(process_list->index_to_pixmap, i));
325
326 gdk_draw_drawable (dest,
327 gc,
328 pixmap,
329 x, 0,
330 x, i*cell_height,
331 width, cell_height);
332
333 }
334
335
336 }
337
338
339
340
341
342
343
344
345
346 ProcessList *processlist_construct(void)
347 {
348 GtkTreeViewColumn *column;
349 GtkCellRenderer *renderer;
350
351 ProcessList* process_list = g_new(ProcessList,1);
352
353 process_list->number_of_process = 0;
354
355 process_list->current_hash_data = NULL;
356
357 /* Create the Process list */
358 process_list->list_store = gtk_list_store_new ( N_COLUMNS,
359 G_TYPE_STRING,
360 G_TYPE_STRING,
361 G_TYPE_UINT,
362 G_TYPE_UINT,
363 G_TYPE_UINT,
364 G_TYPE_UINT,
365 G_TYPE_ULONG,
366 G_TYPE_ULONG,
367 G_TYPE_UINT);
368
369
370 process_list->process_list_widget =
371 gtk_tree_view_new_with_model
372 (GTK_TREE_MODEL (process_list->list_store));
373
374 g_object_unref (G_OBJECT (process_list->list_store));
375
376 gtk_tree_sortable_set_default_sort_func(
377 GTK_TREE_SORTABLE(process_list->list_store),
378 process_sort_func,
379 NULL,
380 NULL);
381
382
383 gtk_tree_sortable_set_sort_column_id(
384 GTK_TREE_SORTABLE(process_list->list_store),
385 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
386 GTK_SORT_ASCENDING);
387
388
389 process_list->process_hash = g_hash_table_new_full(
390 process_list_hash_fct, process_list_equ_fct,
391 destroy_hash_key, destroy_hash_data
392 );
393
394
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 /* Add a temporary row to the model to get the cell size when the first
405 * real process is added. */
406 GtkTreeIter iter;
407 GtkTreePath *path;
408 path = gtk_tree_path_new_first();
409 gtk_tree_model_get_iter (gtk_tree_view_get_model(GTK_TREE_VIEW(process_list->process_list_widget)), &iter, path);
410 gtk_list_store_append(process_list->list_store, &iter);
411 gtk_tree_path_free(path);
412
413 process_list->cell_height = 0; // not ready to get size yet.
414
415 column = gtk_tree_view_column_new_with_attributes ( "Process",
416 renderer,
417 "text",
418 PROCESS_COLUMN,
419 NULL);
420 gtk_tree_view_column_set_alignment (column, 0.0);
421 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
422 gtk_tree_view_column_set_resizable(column, TRUE);
423 gtk_tree_view_append_column (
424 GTK_TREE_VIEW (process_list->process_list_widget), column);
425
426 process_list->button = column->button;
427
428 column = gtk_tree_view_column_new_with_attributes ( "Brand",
429 renderer,
430 "text",
431 BRAND_COLUMN,
432 NULL);
433 gtk_tree_view_column_set_alignment (column, 0.0);
434 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
435 gtk_tree_view_column_set_resizable(column, TRUE);
436 gtk_tree_view_append_column (
437 GTK_TREE_VIEW (process_list->process_list_widget), column);
438
439 column = gtk_tree_view_column_new_with_attributes ( "PID",
440 renderer,
441 "text",
442 PID_COLUMN,
443 NULL);
444 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
445 gtk_tree_view_column_set_resizable(column, TRUE);
446 gtk_tree_view_append_column (
447 GTK_TREE_VIEW (process_list->process_list_widget), column);
448
449 column = gtk_tree_view_column_new_with_attributes ( "TGID",
450 renderer,
451 "text",
452 TGID_COLUMN,
453 NULL);
454 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
455 gtk_tree_view_column_set_resizable(column, TRUE);
456 gtk_tree_view_append_column (
457 GTK_TREE_VIEW (process_list->process_list_widget), column);
458
459 column = gtk_tree_view_column_new_with_attributes ( "PPID",
460 renderer,
461 "text",
462 PPID_COLUMN,
463 NULL);
464 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
465 gtk_tree_view_column_set_resizable(column, TRUE);
466 gtk_tree_view_append_column (
467 GTK_TREE_VIEW (process_list->process_list_widget), column);
468
469 column = gtk_tree_view_column_new_with_attributes ( "CPU",
470 renderer,
471 "text",
472 CPU_COLUMN,
473 NULL);
474 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
475 gtk_tree_view_column_set_resizable(column, TRUE);
476 gtk_tree_view_append_column (
477 GTK_TREE_VIEW (process_list->process_list_widget), column);
478
479 column = gtk_tree_view_column_new_with_attributes ( "Birth sec",
480 renderer,
481 "text",
482 BIRTH_S_COLUMN,
483 NULL);
484 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
485 gtk_tree_view_column_set_resizable(column, TRUE);
486 gtk_tree_view_append_column (
487 GTK_TREE_VIEW (process_list->process_list_widget), column);
488
489 //gtk_tree_view_column_set_visible(column, 0);
490 //
491 column = gtk_tree_view_column_new_with_attributes ( "Birth nsec",
492 renderer,
493 "text",
494 BIRTH_NS_COLUMN,
495 NULL);
496 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
497 gtk_tree_view_column_set_resizable(column, TRUE);
498 gtk_tree_view_append_column (
499 GTK_TREE_VIEW (process_list->process_list_widget), column);
500
501 column = gtk_tree_view_column_new_with_attributes ( "TRACE",
502 renderer,
503 "text",
504 TRACE_COLUMN,
505 NULL);
506 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
507 gtk_tree_view_column_set_resizable(column, TRUE);
508 gtk_tree_view_append_column (
509 GTK_TREE_VIEW (process_list->process_list_widget), column);
510
511
512 //gtk_tree_view_column_set_visible(column, 0);
513
514 g_object_set_data_full(
515 G_OBJECT(process_list->process_list_widget),
516 "process_list_Data",
517 process_list,
518 (GDestroyNotify)processlist_destroy);
519
520 process_list->index_to_pixmap = g_ptr_array_sized_new(ALLOCATE_PROCESSES);
521
522 return process_list;
523 }
524
525 void processlist_destroy(ProcessList *process_list)
526 {
527 g_debug("processlist_destroy %p", process_list);
528 g_hash_table_destroy(process_list->process_hash);
529 process_list->process_hash = NULL;
530 g_ptr_array_free(process_list->index_to_pixmap, TRUE);
531
532 g_free(process_list);
533 g_debug("processlist_destroy end");
534 }
535
536 static gboolean remove_hash_item(ProcessInfo *process_info,
537 HashedProcessData *hashed_process_data,
538 ProcessList *process_list)
539 {
540 GtkTreeIter iter;
541
542 iter = hashed_process_data->y_iter;
543
544 gtk_list_store_remove (process_list->list_store, &iter);
545 gdk_pixmap_unref(hashed_process_data->pixmap);
546
547 if(likely(process_list->current_hash_data != NULL)) {
548 if(likely(hashed_process_data ==
549 process_list->current_hash_data[process_info->trace_num][process_info->cpu]))
550 process_list->current_hash_data[process_info->trace_num][process_info->cpu] = NULL;
551 }
552 return TRUE; /* remove the element from the hash table */
553 }
554
555 void processlist_clear(ProcessList *process_list)
556 {
557 g_info("processlist_clear %p", process_list);
558
559 g_hash_table_foreach_remove(process_list->process_hash,
560 (GHRFunc)remove_hash_item,
561 (gpointer)process_list);
562 process_list->number_of_process = 0;
563 update_index_to_pixmap(process_list);
564 }
565
566
567 GtkWidget *processlist_get_widget(ProcessList *process_list)
568 {
569 return process_list->process_list_widget;
570 }
571
572
573 void destroy_hash_key(gpointer key)
574 {
575 g_free(key);
576 }
577
578 void destroy_hash_data(gpointer data)
579 {
580 g_free(data);
581 }
582
583
584 void processlist_set_name(ProcessList *process_list,
585 GQuark name,
586 HashedProcessData *hashed_process_data)
587 {
588 gtk_list_store_set ( process_list->list_store, &hashed_process_data->y_iter,
589 PROCESS_COLUMN, g_quark_to_string(name),
590 -1);
591 }
592
593 void processlist_set_brand(ProcessList *process_list,
594 GQuark brand,
595 HashedProcessData *hashed_process_data)
596 {
597 gtk_list_store_set ( process_list->list_store, &hashed_process_data->y_iter,
598 BRAND_COLUMN, g_quark_to_string(brand),
599 -1);
600 }
601
602 void processlist_set_tgid(ProcessList *process_list,
603 guint tgid,
604 HashedProcessData *hashed_process_data)
605 {
606 gtk_list_store_set ( process_list->list_store, &hashed_process_data->y_iter,
607 TGID_COLUMN, tgid,
608 -1);
609 }
610
611 void processlist_set_ppid(ProcessList *process_list,
612 guint ppid,
613 HashedProcessData *hashed_process_data)
614 {
615 gtk_list_store_set ( process_list->list_store, &hashed_process_data->y_iter,
616 PPID_COLUMN, ppid,
617 -1);
618 }
619
620
621 int processlist_add( ProcessList *process_list,
622 Drawing_t *drawing,
623 guint pid,
624 guint tgid,
625 guint cpu,
626 guint ppid,
627 LttTime *birth,
628 guint trace_num,
629 GQuark name,
630 GQuark brand,
631 guint *height,
632 ProcessInfo **pm_process_info,
633 HashedProcessData **pm_hashed_process_data)
634 {
635 ProcessInfo *Process_Info = g_new(ProcessInfo, 1);
636 HashedProcessData *hashed_process_data = g_new(HashedProcessData, 1);
637 *pm_hashed_process_data = hashed_process_data;
638 *pm_process_info = Process_Info;
639
640 Process_Info->pid = pid;
641 Process_Info->tgid = tgid;
642 if(pid == 0)
643 Process_Info->cpu = cpu;
644 else
645 Process_Info->cpu = 0;
646 Process_Info->ppid = ppid;
647 Process_Info->birth = *birth;
648 Process_Info->trace_num = trace_num;
649
650 /* When we create it from before state update, we are sure that the
651 * last event occured before the beginning of the global area.
652 *
653 * If it is created after state update, this value (0) will be
654 * overriden by the new state before anything is drawn.
655 */
656 hashed_process_data->x.over = 0;
657 hashed_process_data->x.over_used = FALSE;
658 hashed_process_data->x.over_marked = FALSE;
659 hashed_process_data->x.middle = 0;
660 hashed_process_data->x.middle_used = FALSE;
661 hashed_process_data->x.middle_marked = FALSE;
662 hashed_process_data->x.under = 0;
663 hashed_process_data->x.under_used = FALSE;
664 hashed_process_data->x.under_marked = FALSE;
665 hashed_process_data->next_good_time = ltt_time_zero;
666
667 if (process_list->cell_height == 0) {
668 GtkTreePath *path;
669 GdkRectangle rect;
670 GtkTreeIter iter;
671
672 path = gtk_tree_path_new_first();
673 gtk_tree_model_get_iter (gtk_tree_view_get_model(GTK_TREE_VIEW(process_list->process_list_widget)), &iter, path);
674 gtk_tree_view_get_background_area(
675 GTK_TREE_VIEW(process_list->process_list_widget),
676 path, NULL, &rect);
677 gtk_list_store_remove(process_list->list_store, &iter);
678 gtk_tree_path_free (path);
679 process_list->cell_height = rect.height;
680 }
681
682 /* Add a new row to the model */
683 gtk_list_store_append ( process_list->list_store,
684 &hashed_process_data->y_iter);
685
686 gtk_list_store_set ( process_list->list_store, &hashed_process_data->y_iter,
687 PROCESS_COLUMN, g_quark_to_string(name),
688 BRAND_COLUMN, g_quark_to_string(brand),
689 PID_COLUMN, pid,
690 TGID_COLUMN, tgid,
691 PPID_COLUMN, ppid,
692 CPU_COLUMN, cpu,
693 BIRTH_S_COLUMN, birth->tv_sec,
694 BIRTH_NS_COLUMN, birth->tv_nsec,
695 TRACE_COLUMN, trace_num,
696 -1);
697 //gtk_tree_view_set_model(GTK_TREE_VIEW(process_list->process_list_widget),
698 // GTK_TREE_MODEL(process_list->list_store));
699 //gtk_container_resize_children(GTK_CONTAINER(process_list->process_list_widget));
700
701 g_hash_table_insert(process_list->process_hash,
702 (gpointer)Process_Info,
703 (gpointer)hashed_process_data);
704
705 process_list->number_of_process++;
706 #if 0
707 GtkTreePath *path;
708 GdkRectangle rect;
709 gtk_widget_queue_draw(process_list->process_list_widget);
710 path = gtk_tree_path_new_first();
711 gtk_tree_view_get_background_area(GTK_TREE_VIEW(process_list->process_list_widget),
712 path, NULL, &rect);
713 gtk_tree_path_free (path);
714 process_list->cell_height = rect.height;
715 #endif //0
716
717
718 hashed_process_data->height = process_list->cell_height;
719 g_assert(hashed_process_data->height != 0);
720
721 *height = hashed_process_data->height * process_list->number_of_process;
722
723 hashed_process_data->pixmap =
724 gdk_pixmap_new(drawing->drawing_area->window,
725 drawing->alloc_width,
726 hashed_process_data->height,
727 -1);
728
729 // Clear the image
730 gdk_draw_rectangle (hashed_process_data->pixmap,
731 drawing->drawing_area->style->black_gc,
732 TRUE,
733 0, 0,
734 drawing->alloc_width,
735 hashed_process_data->height);
736
737 update_index_to_pixmap(process_list);
738
739
740 return 0;
741 }
742
743 int processlist_remove( ProcessList *process_list,
744 guint pid,
745 guint cpu,
746 LttTime *birth,
747 guint trace_num)
748 {
749 ProcessInfo process_info;
750 HashedProcessData *hashed_process_data;
751 GtkTreeIter iter;
752
753 process_info.pid = pid;
754 if(pid == 0)
755 process_info.cpu = cpu;
756 else
757 process_info.cpu = 0;
758 process_info.birth = *birth;
759 process_info.trace_num = trace_num;
760
761
762 hashed_process_data =
763 (HashedProcessData*)g_hash_table_lookup(
764 process_list->process_hash,
765 &process_info);
766 if(likely(hashed_process_data != NULL))
767 {
768 iter = hashed_process_data->y_iter;
769
770 gtk_list_store_remove (process_list->list_store, &iter);
771
772 g_hash_table_remove(process_list->process_hash,
773 &process_info);
774
775 if(likely(process_list->current_hash_data != NULL)) {
776 if(likely(hashed_process_data == process_list->current_hash_data[trace_num][cpu])) {
777 process_list->current_hash_data[trace_num][cpu] = NULL;
778 }
779 }
780
781 gdk_pixmap_unref(hashed_process_data->pixmap);
782
783 update_index_to_pixmap(process_list);
784
785 process_list->number_of_process--;
786
787 return 0;
788 } else {
789 return 1;
790 }
791 }
792
793
794 #if 0
795 static inline guint get_cpu_number_from_name(GQuark name)
796 {
797 const gchar *string;
798 char *begin;
799 guint cpu;
800
801 string = g_quark_to_string(name);
802
803 begin = strrchr(string, '/');
804 begin++;
805
806 g_assert(begin != '\0');
807
808 cpu = strtoul(begin, NULL, 10);
809
810 return cpu;
811 }
812 #endif //0
This page took 0.046894 seconds and 3 git commands to generate.