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