1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Mathieu Desnoyers
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;
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.
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,
22 #include "processlist.h"
25 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
26 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
29 /*****************************************************************************
30 * Methods to synchronize process list *
31 *****************************************************************************/
33 /* Enumeration of the columns */
46 gint
process_sort_func ( GtkTreeModel
*model
,
53 memset(&a
, 0, sizeof(GValue
));
54 memset(&b
, 0, sizeof(GValue
));
57 gtk_tree_model_get_value( model
,
62 gtk_tree_model_get_value( model
,
67 if(G_VALUE_TYPE(&a
) == G_TYPE_UINT
68 && G_VALUE_TYPE(&b
) == G_TYPE_UINT
)
70 if(g_value_get_uint(&a
) > g_value_get_uint(&b
))
76 if(g_value_get_uint(&a
) < g_value_get_uint(&b
))
88 /* Order by birth second */
89 gtk_tree_model_get_value( model
,
94 gtk_tree_model_get_value( model
,
100 if(G_VALUE_TYPE(&a
) == G_TYPE_ULONG
101 && G_VALUE_TYPE(&b
) == G_TYPE_ULONG
)
103 if(g_value_get_ulong(&a
) > g_value_get_ulong(&b
))
109 if(g_value_get_ulong(&a
) < g_value_get_ulong(&b
))
121 /* Order by birth nanosecond */
122 gtk_tree_model_get_value( model
,
127 gtk_tree_model_get_value( model
,
133 if(G_VALUE_TYPE(&a
) == G_TYPE_ULONG
134 && G_VALUE_TYPE(&b
) == G_TYPE_ULONG
)
136 if(g_value_get_ulong(&a
) > g_value_get_ulong(&b
))
143 //if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
145 // g_value_unset(&a);
146 // g_value_unset(&b);
155 /* Order by trace_num */
156 gtk_tree_model_get_value( model
,
161 gtk_tree_model_get_value( model
,
166 if(G_VALUE_TYPE(&a
) == G_TYPE_ULONG
167 && G_VALUE_TYPE(&b
) == G_TYPE_ULONG
)
169 if(g_value_get_ulong(&a
) > g_value_get_ulong(&b
))
175 if(g_value_get_ulong(&a
) < g_value_get_ulong(&b
))
190 guint
hash_fct(gconstpointer key
)
192 return ((ProcessInfo
*)key
)->pid
;
195 gboolean
equ_fct(gconstpointer a
, gconstpointer b
)
197 if(((ProcessInfo
*)a
)->pid
!= ((ProcessInfo
*)b
)->pid
)
199 // g_critical("compare %u and %u",((ProcessInfo*)a)->pid,((ProcessInfo*)b)->pid);
200 if(((ProcessInfo
*)a
)->birth
.tv_sec
!= ((ProcessInfo
*)b
)->birth
.tv_sec
)
202 // g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_sec,((ProcessInfo*)b)->birth.tv_sec);
204 if(((ProcessInfo
*)a
)->birth
.tv_nsec
!= ((ProcessInfo
*)b
)->birth
.tv_nsec
)
206 // g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_nsec,((ProcessInfo*)b)->birth.tv_nsec);
208 if(((ProcessInfo
*)a
)->trace_num
!= ((ProcessInfo
*)b
)->trace_num
)
214 void destroy_hash_key(gpointer key
);
216 void destroy_hash_data(gpointer data
);
221 ProcessList
*processlist_construct(void)
223 GtkTreeViewColumn
*column
;
224 GtkCellRenderer
*renderer
;
226 ProcessList
* process_list
= g_new(ProcessList
,1);
228 process_list
->number_of_process
= 0;
230 /* Create the Process list */
231 process_list
->list_store
= gtk_list_store_new ( N_COLUMNS
,
240 process_list
->process_list_widget
=
241 gtk_tree_view_new_with_model
242 (GTK_TREE_MODEL (process_list
->list_store
));
243 g_object_unref (G_OBJECT (process_list
->list_store
));
245 gtk_tree_sortable_set_sort_func(
246 GTK_TREE_SORTABLE(process_list
->list_store
),
252 gtk_tree_sortable_set_sort_column_id(
253 GTK_TREE_SORTABLE(process_list
->list_store
),
257 process_list
->process_hash
= g_hash_table_new_full(
259 destroy_hash_key
, destroy_hash_data
263 gtk_tree_view_set_headers_visible(
264 GTK_TREE_VIEW(process_list
->process_list_widget
), TRUE
);
266 /* Create a column, associating the "text" attribute of the
267 * cell_renderer to the first column of the model */
268 /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */
269 renderer
= gtk_cell_renderer_text_new ();
270 column
= gtk_tree_view_column_new_with_attributes ( "Process",
275 gtk_tree_view_column_set_alignment (column
, 0.0);
276 gtk_tree_view_column_set_fixed_width (column
, 45);
277 gtk_tree_view_append_column (
278 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
280 process_list
->button
= column
->button
;
282 column
= gtk_tree_view_column_new_with_attributes ( "PID",
287 gtk_tree_view_append_column (
288 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
290 column
= gtk_tree_view_column_new_with_attributes ( "PPID",
295 gtk_tree_view_append_column (
296 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
298 column
= gtk_tree_view_column_new_with_attributes ( "Birth sec",
303 gtk_tree_view_append_column (
304 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
306 //gtk_tree_view_column_set_visible(column, 0);
308 column
= gtk_tree_view_column_new_with_attributes ( "Birth nsec",
313 gtk_tree_view_append_column (
314 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
316 column
= gtk_tree_view_column_new_with_attributes ( "TRACE",
321 gtk_tree_view_append_column (
322 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
325 //gtk_tree_view_column_set_visible(column, 0);
327 g_object_set_data_full(
328 G_OBJECT(process_list
->process_list_widget
),
331 (GDestroyNotify
)processlist_destroy
);
336 void processlist_destroy(ProcessList
*process_list
)
338 g_debug("processlist_destroy %p", process_list
);
339 g_hash_table_destroy(process_list
->process_hash
);
340 process_list
->process_hash
= NULL
;
342 g_free(process_list
);
343 g_debug("processlist_destroy end");
346 static gboolean
remove_hash_item(ProcessInfo
*process_info
,
347 HashedProcessData
*hashed_process_data
,
348 ProcessList
*process_list
)
350 GtkTreePath
*tree_path
;
353 tree_path
= gtk_tree_row_reference_get_path(
354 hashed_process_data
->row_ref
);
356 gtk_tree_model_get_iter (
357 GTK_TREE_MODEL(process_list
->list_store
),
360 gtk_tree_path_free(tree_path
);
362 gtk_list_store_remove (process_list
->list_store
, &iter
);
364 return TRUE
; /* remove the element from the hash table */
367 void processlist_clear(ProcessList
*process_list
)
369 g_info("processlist_clear %p", process_list
);
371 g_hash_table_foreach_remove(process_list
->process_hash
,
372 (GHRFunc
)remove_hash_item
,
373 (gpointer
)process_list
);
374 process_list
->number_of_process
= 0;
378 GtkWidget
*processlist_get_widget(ProcessList
*process_list
)
380 return process_list
->process_list_widget
;
385 gint
get_cell_height(GtkTreeView
*tree_view
)
388 GtkTreeViewColumn
*Column
= gtk_tree_view_get_column(tree_view
, 0);
389 //GList *Render_List = gtk_tree_view_column_get_cell_renderers(Column);
390 //GtkCellRenderer *Renderer = g_list_first(Render_List)->data;
392 //g_list_free(Render_List);
393 gtk_tree_view_column_cell_get_size(Column
, NULL
, NULL
, NULL
, NULL
, &height
);
394 //g_critical("cell 0 height : %u",height);
399 void destroy_hash_key(gpointer key
)
404 void destroy_hash_data(gpointer data
)
409 int processlist_add( ProcessList
*process_list
,
416 HashedProcessData
**pm_hashed_process_data
)
419 ProcessInfo
*Process_Info
= g_new(ProcessInfo
, 1);
420 HashedProcessData
*hashed_process_data
= g_new(HashedProcessData
, 1);
421 *pm_hashed_process_data
= hashed_process_data
;
423 Process_Info
->pid
= pid
;
424 Process_Info
->ppid
= ppid
;
425 Process_Info
->birth
= *birth
;
426 Process_Info
->trace_num
= trace_num
;
428 /* When we create it from before state update, we are sure that the
429 * last event occured before the beginning of the global area.
431 * If it is created after state update, this value (0) will be
432 * overriden by the new state before anything is drawn.
434 hashed_process_data
->x
= 0;
437 hashed_process_data
->draw_context
= g_new(DrawContext
, 1);
438 hashed_process_data
->draw_context
->drawable
= NULL
;
439 hashed_process_data
->draw_context
->gc
= NULL
;
440 hashed_process_data
->draw_context
->pango_layout
= NULL
;
441 hashed_process_data
->draw_context
->current
= g_new(DrawInfo
,1);
442 hashed_process_data
->draw_context
->current
->over
= g_new(ItemInfo
,1);
443 hashed_process_data
->draw_context
->current
->over
->x
= -1;
444 hashed_process_data
->draw_context
->current
->over
->y
= -1;
445 hashed_process_data
->draw_context
->current
->middle
= g_new(ItemInfo
,1);
446 hashed_process_data
->draw_context
->current
->middle
->x
= -1;
447 hashed_process_data
->draw_context
->current
->middle
->y
= -1;
448 hashed_process_data
->draw_context
->current
->under
= g_new(ItemInfo
,1);
449 hashed_process_data
->draw_context
->current
->under
->x
= -1;
450 hashed_process_data
->draw_context
->current
->under
->y
= -1;
451 hashed_process_data
->draw_context
->current
->modify_over
= g_new(ItemInfo
,1);
452 hashed_process_data
->draw_context
->current
->modify_over
->x
= -1;
453 hashed_process_data
->draw_context
->current
->modify_over
->y
= -1;
454 hashed_process_data
->draw_context
->current
->modify_middle
= g_new(ItemInfo
,1);
455 hashed_process_data
->draw_context
->current
->modify_middle
->x
= -1;
456 hashed_process_data
->draw_context
->current
->modify_middle
->y
= -1;
457 hashed_process_data
->draw_context
->current
->modify_under
= g_new(ItemInfo
,1);
458 hashed_process_data
->draw_context
->current
->modify_under
->x
= -1;
459 hashed_process_data
->draw_context
->current
->modify_under
->y
= -1;
460 hashed_process_data
->draw_context
->current
->status
= LTTV_STATE_UNNAMED
;
461 hashed_process_data
->draw_context
->previous
= g_new(DrawInfo
,1);
462 hashed_process_data
->draw_context
->previous
->over
= g_new(ItemInfo
,1);
463 hashed_process_data
->draw_context
->previous
->over
->x
= -1;
464 hashed_process_data
->draw_context
->previous
->over
->y
= -1;
465 hashed_process_data
->draw_context
->previous
->middle
= g_new(ItemInfo
,1);
466 hashed_process_data
->draw_context
->previous
->middle
->x
= -1;
467 hashed_process_data
->draw_context
->previous
->middle
->y
= -1;
468 hashed_process_data
->draw_context
->previous
->under
= g_new(ItemInfo
,1);
469 hashed_process_data
->draw_context
->previous
->under
->x
= -1;
470 hashed_process_data
->draw_context
->previous
->under
->y
= -1;
471 hashed_process_data
->draw_context
->previous
->modify_over
= g_new(ItemInfo
,1);
472 hashed_process_data
->draw_context
->previous
->modify_over
->x
= -1;
473 hashed_process_data
->draw_context
->previous
->modify_over
->y
= -1;
474 hashed_process_data
->draw_context
->previous
->modify_middle
= g_new(ItemInfo
,1);
475 hashed_process_data
->draw_context
->previous
->modify_middle
->x
= -1;
476 hashed_process_data
->draw_context
->previous
->modify_middle
->y
= -1;
477 hashed_process_data
->draw_context
->previous
->modify_under
= g_new(ItemInfo
,1);
478 hashed_process_data
->draw_context
->previous
->modify_under
->x
= -1;
479 hashed_process_data
->draw_context
->previous
->modify_under
->y
= -1;
480 hashed_process_data
->draw_context
->previous
->status
= LTTV_STATE_UNNAMED
;
483 /* Add a new row to the model */
484 gtk_list_store_append ( process_list
->list_store
, &iter
);
485 //g_critical ( "iter before : %s", gtk_tree_path_to_string (
486 // gtk_tree_model_get_path (
487 // GTK_TREE_MODEL(process_list->list_store),
489 gtk_list_store_set ( process_list
->list_store
, &iter
,
490 PROCESS_COLUMN
, name
,
493 BIRTH_S_COLUMN
, birth
->tv_sec
,
494 BIRTH_NS_COLUMN
, birth
->tv_nsec
,
495 TRACE_COLUMN
, trace_num
,
497 hashed_process_data
->row_ref
= gtk_tree_row_reference_new (
498 GTK_TREE_MODEL(process_list
->list_store
),
499 gtk_tree_model_get_path(
500 GTK_TREE_MODEL(process_list
->list_store
),
502 g_hash_table_insert( process_list
->process_hash
,
503 (gpointer
)Process_Info
,
504 (gpointer
)hashed_process_data
);
506 //g_critical ( "iter after : %s", gtk_tree_path_to_string (
507 // gtk_tree_model_get_path (
508 // GTK_TREE_MODEL(process_list->list_store),
510 process_list
->number_of_process
++;
512 *height
= get_cell_height(GTK_TREE_VIEW(process_list
->process_list_widget
))
513 * process_list
->number_of_process
;
520 int processlist_remove( ProcessList
*process_list
,
525 ProcessInfo Process_Info
;
527 HashedProcessData
*hashed_process_data
;
530 Process_Info
.pid
= pid
;
531 Process_Info
.birth
= *birth
;
532 Process_Info
.trace_num
= trace_num
;
535 if(hashed_process_data
=
536 (HashedProcessData
*)g_hash_table_lookup(
537 process_list
->process_hash
,
540 GtkTreePath
*tree_path
;
542 tree_path
= gtk_tree_row_reference_get_path(
543 hashed_process_data
->row_ref
);
545 gtk_tree_model_get_iter (
546 GTK_TREE_MODEL(process_list
->list_store
),
549 gtk_tree_path_free(tree_path
);
551 gtk_list_store_remove (process_list
->list_store
, &iter
);
553 g_hash_table_remove(process_list
->process_hash
,
556 process_list
->number_of_process
--;
565 guint
processlist_get_height(ProcessList
*process_list
)
567 return get_cell_height(GTK_TREE_VIEW(process_list
->process_list_widget
))
568 * process_list
->number_of_process
;
572 gint
processlist_get_process_pixels( ProcessList
*process_list
,
573 guint pid
, LttTime
*birth
, guint trace_num
,
576 HashedProcessData
**pm_hashed_process_data
)
578 ProcessInfo Process_Info
;
580 GtkTreePath
*tree_path
;
581 HashedProcessData
*hashed_process_data
= NULL
;
583 Process_Info
.pid
= pid
;
584 Process_Info
.birth
= *birth
;
585 Process_Info
.trace_num
= trace_num
;
587 if(hashed_process_data
=
588 (HashedProcessData
*)g_hash_table_lookup(
589 process_list
->process_hash
,
592 tree_path
= gtk_tree_row_reference_get_path(
593 hashed_process_data
->row_ref
);
594 path_indices
= gtk_tree_path_get_indices (tree_path
);
596 *height
= get_cell_height(
597 GTK_TREE_VIEW(process_list
->process_list_widget
));
598 *y
= *height
* path_indices
[0];
599 *pm_hashed_process_data
= hashed_process_data
;
600 gtk_tree_path_free(tree_path
);
604 *pm_hashed_process_data
= hashed_process_data
;
611 gint
processlist_get_pixels_from_data( ProcessList
*process_list
,
612 ProcessInfo
*process_info
,
613 HashedProcessData
*hashed_process_data
,
618 GtkTreePath
*tree_path
;
620 tree_path
= gtk_tree_row_reference_get_path(
621 hashed_process_data
->row_ref
);
622 path_indices
= gtk_tree_path_get_indices (tree_path
);
624 *height
= get_cell_height(
625 GTK_TREE_VIEW(process_list
->process_list_widget
));
626 *y
= *height
* path_indices
[0];
627 gtk_tree_path_free(tree_path
);