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 */
45 gint
process_sort_func ( GtkTreeModel
*model
,
52 memset(&a
, 0, sizeof(GValue
));
53 memset(&b
, 0, sizeof(GValue
));
56 gtk_tree_model_get_value( model
,
61 gtk_tree_model_get_value( model
,
66 if(G_VALUE_TYPE(&a
) == G_TYPE_UINT
67 && G_VALUE_TYPE(&b
) == G_TYPE_UINT
)
69 if(g_value_get_uint(&a
) > g_value_get_uint(&b
))
75 if(g_value_get_uint(&a
) < g_value_get_uint(&b
))
87 /* Order by birth second */
88 gtk_tree_model_get_value( model
,
93 gtk_tree_model_get_value( model
,
99 if(G_VALUE_TYPE(&a
) == G_TYPE_ULONG
100 && G_VALUE_TYPE(&b
) == G_TYPE_ULONG
)
102 if(g_value_get_ulong(&a
) > g_value_get_ulong(&b
))
108 if(g_value_get_ulong(&a
) < g_value_get_ulong(&b
))
120 /* Order by birth nanosecond */
121 gtk_tree_model_get_value( model
,
126 gtk_tree_model_get_value( model
,
132 if(G_VALUE_TYPE(&a
) == G_TYPE_ULONG
133 && G_VALUE_TYPE(&b
) == G_TYPE_ULONG
)
135 if(g_value_get_ulong(&a
) > g_value_get_ulong(&b
))
142 //if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
144 // g_value_unset(&a);
145 // g_value_unset(&b);
154 /* Order by trace_num */
155 gtk_tree_model_get_value( model
,
160 gtk_tree_model_get_value( model
,
165 if(G_VALUE_TYPE(&a
) == G_TYPE_ULONG
166 && G_VALUE_TYPE(&b
) == G_TYPE_ULONG
)
168 if(g_value_get_ulong(&a
) > g_value_get_ulong(&b
))
174 if(g_value_get_ulong(&a
) < g_value_get_ulong(&b
))
189 guint
hash_fct(gconstpointer key
)
191 return ((ProcessInfo
*)key
)->pid
;
194 gboolean
equ_fct(gconstpointer a
, gconstpointer b
)
196 if(((ProcessInfo
*)a
)->pid
!= ((ProcessInfo
*)b
)->pid
)
198 // g_critical("compare %u and %u",((ProcessInfo*)a)->pid,((ProcessInfo*)b)->pid);
199 if(((ProcessInfo
*)a
)->birth
.tv_sec
!= ((ProcessInfo
*)b
)->birth
.tv_sec
)
201 // g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_sec,((ProcessInfo*)b)->birth.tv_sec);
203 if(((ProcessInfo
*)a
)->birth
.tv_nsec
!= ((ProcessInfo
*)b
)->birth
.tv_nsec
)
205 // g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_nsec,((ProcessInfo*)b)->birth.tv_nsec);
207 if(((ProcessInfo
*)a
)->trace_num
!= ((ProcessInfo
*)b
)->trace_num
)
213 void destroy_hash_key(gpointer key
);
215 void destroy_hash_data(gpointer data
);
220 ProcessList
*processlist_construct(void)
222 GtkTreeViewColumn
*column
;
223 GtkCellRenderer
*renderer
;
225 ProcessList
* process_list
= g_new(ProcessList
,1);
227 process_list
->number_of_process
= 0;
229 /* Create the Process list */
230 process_list
->list_store
= gtk_list_store_new ( N_COLUMNS
,
238 process_list
->process_list_widget
=
239 gtk_tree_view_new_with_model
240 (GTK_TREE_MODEL (process_list
->list_store
));
241 g_object_unref (G_OBJECT (process_list
->list_store
));
243 gtk_tree_sortable_set_sort_func(
244 GTK_TREE_SORTABLE(process_list
->list_store
),
250 gtk_tree_sortable_set_sort_column_id(
251 GTK_TREE_SORTABLE(process_list
->list_store
),
255 process_list
->process_hash
= g_hash_table_new_full(
257 destroy_hash_key
, destroy_hash_data
261 gtk_tree_view_set_headers_visible(
262 GTK_TREE_VIEW(process_list
->process_list_widget
), TRUE
);
264 /* Create a column, associating the "text" attribute of the
265 * cell_renderer to the first column of the model */
266 /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */
267 renderer
= gtk_cell_renderer_text_new ();
268 column
= gtk_tree_view_column_new_with_attributes ( "Process",
273 gtk_tree_view_column_set_alignment (column
, 0.0);
274 gtk_tree_view_column_set_fixed_width (column
, 45);
275 gtk_tree_view_append_column (
276 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
278 process_list
->button
= column
->button
;
280 column
= gtk_tree_view_column_new_with_attributes ( "PID",
285 gtk_tree_view_append_column (
286 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
289 column
= gtk_tree_view_column_new_with_attributes ( "Birth sec",
294 gtk_tree_view_append_column (
295 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
297 //gtk_tree_view_column_set_visible(column, 0);
299 column
= gtk_tree_view_column_new_with_attributes ( "Birth nsec",
304 gtk_tree_view_append_column (
305 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
307 column
= gtk_tree_view_column_new_with_attributes ( "TRACE",
312 gtk_tree_view_append_column (
313 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
316 //gtk_tree_view_column_set_visible(column, 0);
318 g_object_set_data_full(
319 G_OBJECT(process_list
->process_list_widget
),
322 (GDestroyNotify
)processlist_destroy
);
327 void processlist_destroy(ProcessList
*process_list
)
329 g_debug("processlist_destroy %p", process_list
);
330 g_hash_table_destroy(process_list
->process_hash
);
331 process_list
->process_hash
= NULL
;
333 g_free(process_list
);
334 g_debug("processlist_destroy end");
337 static gboolean
remove_hash_item(ProcessInfo
*process_info
,
338 HashedProcessData
*hashed_process_data
,
339 ProcessList
*process_list
)
341 GtkTreePath
*tree_path
;
344 tree_path
= gtk_tree_row_reference_get_path(
345 hashed_process_data
->row_ref
);
347 gtk_tree_model_get_iter (
348 GTK_TREE_MODEL(process_list
->list_store
),
351 gtk_tree_path_free(tree_path
);
353 gtk_list_store_remove (process_list
->list_store
, &iter
);
355 return TRUE
; /* remove the element from the hash table */
358 void processlist_clear(ProcessList
*process_list
)
360 g_info("processlist_clear %p", process_list
);
362 g_hash_table_foreach_remove(process_list
->process_hash
,
363 (GHRFunc
)remove_hash_item
,
364 (gpointer
)process_list
);
365 process_list
->number_of_process
= 0;
369 GtkWidget
*processlist_get_widget(ProcessList
*process_list
)
371 return process_list
->process_list_widget
;
376 gint
get_cell_height(GtkTreeView
*tree_view
)
379 GtkTreeViewColumn
*Column
= gtk_tree_view_get_column(tree_view
, 0);
380 //GList *Render_List = gtk_tree_view_column_get_cell_renderers(Column);
381 //GtkCellRenderer *Renderer = g_list_first(Render_List)->data;
383 //g_list_free(Render_List);
384 gtk_tree_view_column_cell_get_size(Column
, NULL
, NULL
, NULL
, NULL
, &height
);
385 //g_critical("cell 0 height : %u",height);
390 void destroy_hash_key(gpointer key
)
395 void destroy_hash_data(gpointer data
)
400 int processlist_add( ProcessList
*process_list
,
406 HashedProcessData
**pm_hashed_process_data
)
409 ProcessInfo
*Process_Info
= g_new(ProcessInfo
, 1);
410 HashedProcessData
*hashed_process_data
= g_new(HashedProcessData
, 1);
411 *pm_hashed_process_data
= hashed_process_data
;
413 Process_Info
->pid
= pid
;
414 Process_Info
->birth
= *birth
;
415 Process_Info
->trace_num
= trace_num
;
417 /* When we create it from before state update, we are sure that the
418 * last event occured before the beginning of the global area.
420 * If it is created after state update, this value (0) will be
421 * overriden by the new state before anything is drawn.
423 hashed_process_data
->x
= 0;
426 hashed_process_data
->draw_context
= g_new(DrawContext
, 1);
427 hashed_process_data
->draw_context
->drawable
= NULL
;
428 hashed_process_data
->draw_context
->gc
= NULL
;
429 hashed_process_data
->draw_context
->pango_layout
= NULL
;
430 hashed_process_data
->draw_context
->current
= g_new(DrawInfo
,1);
431 hashed_process_data
->draw_context
->current
->over
= g_new(ItemInfo
,1);
432 hashed_process_data
->draw_context
->current
->over
->x
= -1;
433 hashed_process_data
->draw_context
->current
->over
->y
= -1;
434 hashed_process_data
->draw_context
->current
->middle
= g_new(ItemInfo
,1);
435 hashed_process_data
->draw_context
->current
->middle
->x
= -1;
436 hashed_process_data
->draw_context
->current
->middle
->y
= -1;
437 hashed_process_data
->draw_context
->current
->under
= g_new(ItemInfo
,1);
438 hashed_process_data
->draw_context
->current
->under
->x
= -1;
439 hashed_process_data
->draw_context
->current
->under
->y
= -1;
440 hashed_process_data
->draw_context
->current
->modify_over
= g_new(ItemInfo
,1);
441 hashed_process_data
->draw_context
->current
->modify_over
->x
= -1;
442 hashed_process_data
->draw_context
->current
->modify_over
->y
= -1;
443 hashed_process_data
->draw_context
->current
->modify_middle
= g_new(ItemInfo
,1);
444 hashed_process_data
->draw_context
->current
->modify_middle
->x
= -1;
445 hashed_process_data
->draw_context
->current
->modify_middle
->y
= -1;
446 hashed_process_data
->draw_context
->current
->modify_under
= g_new(ItemInfo
,1);
447 hashed_process_data
->draw_context
->current
->modify_under
->x
= -1;
448 hashed_process_data
->draw_context
->current
->modify_under
->y
= -1;
449 hashed_process_data
->draw_context
->current
->status
= LTTV_STATE_UNNAMED
;
450 hashed_process_data
->draw_context
->previous
= g_new(DrawInfo
,1);
451 hashed_process_data
->draw_context
->previous
->over
= g_new(ItemInfo
,1);
452 hashed_process_data
->draw_context
->previous
->over
->x
= -1;
453 hashed_process_data
->draw_context
->previous
->over
->y
= -1;
454 hashed_process_data
->draw_context
->previous
->middle
= g_new(ItemInfo
,1);
455 hashed_process_data
->draw_context
->previous
->middle
->x
= -1;
456 hashed_process_data
->draw_context
->previous
->middle
->y
= -1;
457 hashed_process_data
->draw_context
->previous
->under
= g_new(ItemInfo
,1);
458 hashed_process_data
->draw_context
->previous
->under
->x
= -1;
459 hashed_process_data
->draw_context
->previous
->under
->y
= -1;
460 hashed_process_data
->draw_context
->previous
->modify_over
= g_new(ItemInfo
,1);
461 hashed_process_data
->draw_context
->previous
->modify_over
->x
= -1;
462 hashed_process_data
->draw_context
->previous
->modify_over
->y
= -1;
463 hashed_process_data
->draw_context
->previous
->modify_middle
= g_new(ItemInfo
,1);
464 hashed_process_data
->draw_context
->previous
->modify_middle
->x
= -1;
465 hashed_process_data
->draw_context
->previous
->modify_middle
->y
= -1;
466 hashed_process_data
->draw_context
->previous
->modify_under
= g_new(ItemInfo
,1);
467 hashed_process_data
->draw_context
->previous
->modify_under
->x
= -1;
468 hashed_process_data
->draw_context
->previous
->modify_under
->y
= -1;
469 hashed_process_data
->draw_context
->previous
->status
= LTTV_STATE_UNNAMED
;
472 /* Add a new row to the model */
473 gtk_list_store_append ( process_list
->list_store
, &iter
);
474 //g_critical ( "iter before : %s", gtk_tree_path_to_string (
475 // gtk_tree_model_get_path (
476 // GTK_TREE_MODEL(process_list->list_store),
478 gtk_list_store_set ( process_list
->list_store
, &iter
,
479 PROCESS_COLUMN
, name
,
481 BIRTH_S_COLUMN
, birth
->tv_sec
,
482 BIRTH_NS_COLUMN
, birth
->tv_nsec
,
483 TRACE_COLUMN
, trace_num
,
485 hashed_process_data
->row_ref
= gtk_tree_row_reference_new (
486 GTK_TREE_MODEL(process_list
->list_store
),
487 gtk_tree_model_get_path(
488 GTK_TREE_MODEL(process_list
->list_store
),
490 g_hash_table_insert( process_list
->process_hash
,
491 (gpointer
)Process_Info
,
492 (gpointer
)hashed_process_data
);
494 //g_critical ( "iter after : %s", gtk_tree_path_to_string (
495 // gtk_tree_model_get_path (
496 // GTK_TREE_MODEL(process_list->list_store),
498 process_list
->number_of_process
++;
500 *height
= get_cell_height(GTK_TREE_VIEW(process_list
->process_list_widget
))
501 * process_list
->number_of_process
;
508 int processlist_remove( ProcessList
*process_list
,
513 ProcessInfo Process_Info
;
515 HashedProcessData
*hashed_process_data
;
518 Process_Info
.pid
= pid
;
519 Process_Info
.birth
= *birth
;
520 Process_Info
.trace_num
= trace_num
;
523 if(hashed_process_data
=
524 (HashedProcessData
*)g_hash_table_lookup(
525 process_list
->process_hash
,
528 GtkTreePath
*tree_path
;
530 tree_path
= gtk_tree_row_reference_get_path(
531 hashed_process_data
->row_ref
);
533 gtk_tree_model_get_iter (
534 GTK_TREE_MODEL(process_list
->list_store
),
537 gtk_tree_path_free(tree_path
);
539 gtk_list_store_remove (process_list
->list_store
, &iter
);
541 g_hash_table_remove(process_list
->process_hash
,
544 process_list
->number_of_process
--;
553 guint
processlist_get_height(ProcessList
*process_list
)
555 return get_cell_height(GTK_TREE_VIEW(process_list
->process_list_widget
))
556 * process_list
->number_of_process
;
560 gint
processlist_get_process_pixels( ProcessList
*process_list
,
561 guint pid
, LttTime
*birth
, guint trace_num
,
564 HashedProcessData
**pm_hashed_process_data
)
566 ProcessInfo Process_Info
;
568 GtkTreePath
*tree_path
;
569 HashedProcessData
*hashed_process_data
= NULL
;
571 Process_Info
.pid
= pid
;
572 Process_Info
.birth
= *birth
;
573 Process_Info
.trace_num
= trace_num
;
575 if(hashed_process_data
=
576 (HashedProcessData
*)g_hash_table_lookup(
577 process_list
->process_hash
,
580 tree_path
= gtk_tree_row_reference_get_path(
581 hashed_process_data
->row_ref
);
582 path_indices
= gtk_tree_path_get_indices (tree_path
);
584 *height
= get_cell_height(
585 GTK_TREE_VIEW(process_list
->process_list_widget
));
586 *y
= *height
* path_indices
[0];
587 *pm_hashed_process_data
= hashed_process_data
;
588 gtk_tree_path_free(tree_path
);
592 *pm_hashed_process_data
= hashed_process_data
;
599 gint
processlist_get_pixels_from_data( ProcessList
*process_list
,
600 ProcessInfo
*process_info
,
601 HashedProcessData
*hashed_process_data
,
606 GtkTreePath
*tree_path
;
608 tree_path
= gtk_tree_row_reference_get_path(
609 hashed_process_data
->row_ref
);
610 path_indices
= gtk_tree_path_get_indices (tree_path
);
612 *height
= get_cell_height(
613 GTK_TREE_VIEW(process_list
->process_list_widget
));
614 *y
= *height
* path_indices
[0];
615 gtk_tree_path_free(tree_path
);