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