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 /*****************************************************************************
26 * Methods to synchronize process list *
27 *****************************************************************************/
29 /* Enumeration of the columns */
41 gint
process_sort_func ( GtkTreeModel
*model
,
48 memset(&a
, 0, sizeof(GValue
));
49 memset(&b
, 0, sizeof(GValue
));
52 gtk_tree_model_get_value( model
,
57 gtk_tree_model_get_value( model
,
62 if(G_VALUE_TYPE(&a
) == G_TYPE_UINT
63 && G_VALUE_TYPE(&b
) == G_TYPE_UINT
)
65 if(g_value_get_uint(&a
) > g_value_get_uint(&b
))
71 if(g_value_get_uint(&a
) < g_value_get_uint(&b
))
83 /* Order by birth second */
84 gtk_tree_model_get_value( model
,
89 gtk_tree_model_get_value( model
,
95 if(G_VALUE_TYPE(&a
) == G_TYPE_ULONG
96 && G_VALUE_TYPE(&b
) == G_TYPE_ULONG
)
98 if(g_value_get_ulong(&a
) > g_value_get_ulong(&b
))
104 if(g_value_get_ulong(&a
) < g_value_get_ulong(&b
))
116 /* Order by birth nanosecond */
117 gtk_tree_model_get_value( model
,
122 gtk_tree_model_get_value( model
,
128 if(G_VALUE_TYPE(&a
) == G_TYPE_ULONG
129 && G_VALUE_TYPE(&b
) == G_TYPE_ULONG
)
131 if(g_value_get_ulong(&a
) > g_value_get_ulong(&b
))
138 //if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
140 // g_value_unset(&a);
141 // g_value_unset(&b);
150 /* Order by trace_num */
151 gtk_tree_model_get_value( model
,
156 gtk_tree_model_get_value( model
,
161 if(G_VALUE_TYPE(&a
) == G_TYPE_ULONG
162 && G_VALUE_TYPE(&b
) == G_TYPE_ULONG
)
164 if(g_value_get_ulong(&a
) > g_value_get_ulong(&b
))
170 if(g_value_get_ulong(&a
) < g_value_get_ulong(&b
))
185 guint
hash_fct(gconstpointer key
)
187 return ((ProcessInfo
*)key
)->pid
;
190 gboolean
equ_fct(gconstpointer a
, gconstpointer b
)
192 if(((ProcessInfo
*)a
)->pid
!= ((ProcessInfo
*)b
)->pid
)
194 // g_critical("compare %u and %u",((ProcessInfo*)a)->pid,((ProcessInfo*)b)->pid);
195 if(((ProcessInfo
*)a
)->birth
.tv_sec
!= ((ProcessInfo
*)b
)->birth
.tv_sec
)
197 // g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_sec,((ProcessInfo*)b)->birth.tv_sec);
199 if(((ProcessInfo
*)a
)->birth
.tv_nsec
!= ((ProcessInfo
*)b
)->birth
.tv_nsec
)
201 // g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_nsec,((ProcessInfo*)b)->birth.tv_nsec);
203 if(((ProcessInfo
*)a
)->trace_num
!= ((ProcessInfo
*)b
)->trace_num
)
209 void destroy_hash_key(gpointer key
);
211 void destroy_hash_data(gpointer data
);
216 ProcessList
*processlist_construct(void)
218 GtkTreeViewColumn
*column
;
219 GtkCellRenderer
*renderer
;
221 ProcessList
* process_list
= g_new(ProcessList
,1);
223 process_list
->number_of_process
= 0;
225 /* Create the Process list */
226 process_list
->list_store
= gtk_list_store_new ( N_COLUMNS
,
234 process_list
->process_list_widget
=
235 gtk_tree_view_new_with_model
236 (GTK_TREE_MODEL (process_list
->list_store
));
238 g_object_unref (G_OBJECT (process_list
->list_store
));
240 gtk_tree_sortable_set_sort_func(
241 GTK_TREE_SORTABLE(process_list
->list_store
),
247 gtk_tree_sortable_set_sort_column_id(
248 GTK_TREE_SORTABLE(process_list
->list_store
),
252 process_list
->process_hash
= g_hash_table_new_full(
254 destroy_hash_key
, destroy_hash_data
258 gtk_tree_view_set_headers_visible(
259 GTK_TREE_VIEW(process_list
->process_list_widget
), TRUE
);
261 /* Create a column, associating the "text" attribute of the
262 * cell_renderer to the first column of the model */
263 /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */
264 renderer
= gtk_cell_renderer_text_new ();
265 column
= gtk_tree_view_column_new_with_attributes ( "Process",
270 gtk_tree_view_column_set_alignment (column
, 0.0);
271 gtk_tree_view_column_set_fixed_width (column
, 45);
272 gtk_tree_view_append_column (
273 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
275 column
= gtk_tree_view_column_new_with_attributes ( "PID",
280 gtk_tree_view_append_column (
281 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
284 column
= gtk_tree_view_column_new_with_attributes ( "Birth sec",
289 gtk_tree_view_append_column (
290 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
292 //gtk_tree_view_column_set_visible(column, 0);
294 column
= gtk_tree_view_column_new_with_attributes ( "Birth nsec",
299 gtk_tree_view_append_column (
300 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
302 column
= gtk_tree_view_column_new_with_attributes ( "TRACE",
307 gtk_tree_view_append_column (
308 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
311 //gtk_tree_view_column_set_visible(column, 0);
313 g_object_set_data_full(
314 G_OBJECT(process_list
->process_list_widget
),
317 (GDestroyNotify
)processlist_destroy
);
321 void processlist_destroy(ProcessList
*process_list
)
323 g_hash_table_destroy(process_list
->process_hash
);
324 process_list
->process_hash
= NULL
;
326 g_free(process_list
);
329 GtkWidget
*processlist_get_widget(ProcessList
*process_list
)
331 return process_list
->process_list_widget
;
336 gint
get_cell_height(GtkTreeView
*tree_view
)
339 GtkTreeViewColumn
*Column
= gtk_tree_view_get_column(tree_view
, 0);
340 //GList *Render_List = gtk_tree_view_column_get_cell_renderers(Column);
341 //GtkCellRenderer *Renderer = g_list_first(Render_List)->data;
343 //g_list_free(Render_List);
344 gtk_tree_view_column_cell_get_size(Column
, NULL
, NULL
, NULL
, NULL
, &height
);
345 //g_critical("cell 0 height : %u",height);
350 void destroy_hash_key(gpointer key
)
355 void destroy_hash_data(gpointer data
)
360 int processlist_add( ProcessList
*process_list
,
366 HashedProcessData
**pm_hashed_process_data
)
369 ProcessInfo
*Process_Info
= g_new(ProcessInfo
, 1);
370 HashedProcessData
*hashed_process_data
= g_new(HashedProcessData
, 1);
371 *pm_hashed_process_data
= hashed_process_data
;
373 Process_Info
->pid
= pid
;
374 Process_Info
->birth
= *birth
;
375 Process_Info
->trace_num
= trace_num
;
377 hashed_process_data
->draw_context
= g_new(DrawContext
, 1);
378 hashed_process_data
->draw_context
->drawable
= NULL
;
379 hashed_process_data
->draw_context
->gc
= NULL
;
380 hashed_process_data
->draw_context
->pango_layout
= NULL
;
381 hashed_process_data
->draw_context
->current
= g_new(DrawInfo
,1);
382 hashed_process_data
->draw_context
->current
->over
= g_new(ItemInfo
,1);
383 hashed_process_data
->draw_context
->current
->over
->x
= -1;
384 hashed_process_data
->draw_context
->current
->over
->y
= -1;
385 hashed_process_data
->draw_context
->current
->middle
= g_new(ItemInfo
,1);
386 hashed_process_data
->draw_context
->current
->middle
->x
= -1;
387 hashed_process_data
->draw_context
->current
->middle
->y
= -1;
388 hashed_process_data
->draw_context
->current
->under
= g_new(ItemInfo
,1);
389 hashed_process_data
->draw_context
->current
->under
->x
= -1;
390 hashed_process_data
->draw_context
->current
->under
->y
= -1;
391 hashed_process_data
->draw_context
->current
->modify_over
= g_new(ItemInfo
,1);
392 hashed_process_data
->draw_context
->current
->modify_over
->x
= -1;
393 hashed_process_data
->draw_context
->current
->modify_over
->y
= -1;
394 hashed_process_data
->draw_context
->current
->modify_middle
= g_new(ItemInfo
,1);
395 hashed_process_data
->draw_context
->current
->modify_middle
->x
= -1;
396 hashed_process_data
->draw_context
->current
->modify_middle
->y
= -1;
397 hashed_process_data
->draw_context
->current
->modify_under
= g_new(ItemInfo
,1);
398 hashed_process_data
->draw_context
->current
->modify_under
->x
= -1;
399 hashed_process_data
->draw_context
->current
->modify_under
->y
= -1;
400 hashed_process_data
->draw_context
->current
->status
= LTTV_STATE_UNNAMED
;
401 hashed_process_data
->draw_context
->previous
= g_new(DrawInfo
,1);
402 hashed_process_data
->draw_context
->previous
->over
= g_new(ItemInfo
,1);
403 hashed_process_data
->draw_context
->previous
->over
->x
= -1;
404 hashed_process_data
->draw_context
->previous
->over
->y
= -1;
405 hashed_process_data
->draw_context
->previous
->middle
= g_new(ItemInfo
,1);
406 hashed_process_data
->draw_context
->previous
->middle
->x
= -1;
407 hashed_process_data
->draw_context
->previous
->middle
->y
= -1;
408 hashed_process_data
->draw_context
->previous
->under
= g_new(ItemInfo
,1);
409 hashed_process_data
->draw_context
->previous
->under
->x
= -1;
410 hashed_process_data
->draw_context
->previous
->under
->y
= -1;
411 hashed_process_data
->draw_context
->previous
->modify_over
= g_new(ItemInfo
,1);
412 hashed_process_data
->draw_context
->previous
->modify_over
->x
= -1;
413 hashed_process_data
->draw_context
->previous
->modify_over
->y
= -1;
414 hashed_process_data
->draw_context
->previous
->modify_middle
= g_new(ItemInfo
,1);
415 hashed_process_data
->draw_context
->previous
->modify_middle
->x
= -1;
416 hashed_process_data
->draw_context
->previous
->modify_middle
->y
= -1;
417 hashed_process_data
->draw_context
->previous
->modify_under
= g_new(ItemInfo
,1);
418 hashed_process_data
->draw_context
->previous
->modify_under
->x
= -1;
419 hashed_process_data
->draw_context
->previous
->modify_under
->y
= -1;
420 hashed_process_data
->draw_context
->previous
->status
= LTTV_STATE_UNNAMED
;
422 /* Add a new row to the model */
423 gtk_list_store_append ( process_list
->list_store
, &iter
);
424 //g_critical ( "iter before : %s", gtk_tree_path_to_string (
425 // gtk_tree_model_get_path (
426 // GTK_TREE_MODEL(process_list->list_store),
428 gtk_list_store_set ( process_list
->list_store
, &iter
,
429 PROCESS_COLUMN
, name
,
431 BIRTH_S_COLUMN
, birth
->tv_sec
,
432 BIRTH_NS_COLUMN
, birth
->tv_nsec
,
433 TRACE_COLUMN
, trace_num
,
435 hashed_process_data
->row_ref
= gtk_tree_row_reference_new (
436 GTK_TREE_MODEL(process_list
->list_store
),
437 gtk_tree_model_get_path(
438 GTK_TREE_MODEL(process_list
->list_store
),
440 g_hash_table_insert( process_list
->process_hash
,
441 (gpointer
)Process_Info
,
442 (gpointer
)hashed_process_data
);
444 //g_critical ( "iter after : %s", gtk_tree_path_to_string (
445 // gtk_tree_model_get_path (
446 // GTK_TREE_MODEL(process_list->list_store),
448 process_list
->number_of_process
++;
450 *height
= get_cell_height(GTK_TREE_VIEW(process_list
->process_list_widget
))
451 * process_list
->number_of_process
;
458 int processlist_remove( ProcessList
*process_list
,
463 ProcessInfo Process_Info
;
465 HashedProcessData
*hashed_process_data
;
468 Process_Info
.pid
= pid
;
469 Process_Info
.birth
= *birth
;
470 Process_Info
.trace_num
= trace_num
;
473 if(hashed_process_data
=
474 (HashedProcessData
*)g_hash_table_lookup(
475 process_list
->process_hash
,
478 gtk_tree_model_get_iter (
479 GTK_TREE_MODEL(process_list
->list_store
),
481 gtk_tree_row_reference_get_path(
482 (GtkTreeRowReference
*)hashed_process_data
->row_ref
)
485 gtk_list_store_remove (process_list
->list_store
, &iter
);
487 g_free(hashed_process_data
->draw_context
->previous
->modify_under
);
488 g_free(hashed_process_data
->draw_context
->previous
->modify_middle
);
489 g_free(hashed_process_data
->draw_context
->previous
->modify_over
);
490 g_free(hashed_process_data
->draw_context
->previous
->under
);
491 g_free(hashed_process_data
->draw_context
->previous
->middle
);
492 g_free(hashed_process_data
->draw_context
->previous
->over
);
493 g_free(hashed_process_data
->draw_context
->previous
);
494 g_free(hashed_process_data
->draw_context
->current
->modify_under
);
495 g_free(hashed_process_data
->draw_context
->current
->modify_middle
);
496 g_free(hashed_process_data
->draw_context
->current
->modify_over
);
497 g_free(hashed_process_data
->draw_context
->current
->under
);
498 g_free(hashed_process_data
->draw_context
->current
->middle
);
499 g_free(hashed_process_data
->draw_context
->current
->over
);
500 g_free(hashed_process_data
->draw_context
->current
);
501 g_free(hashed_process_data
->draw_context
);
502 g_free(hashed_process_data
);
504 g_hash_table_remove(process_list
->process_hash
,
507 process_list
->number_of_process
--;
516 guint
processlist_get_height(ProcessList
*process_list
)
518 return get_cell_height(GTK_TREE_VIEW(process_list
->process_list_widget
))
519 * process_list
->number_of_process
;
523 gint
processlist_get_process_pixels( ProcessList
*process_list
,
524 guint pid
, LttTime
*birth
, guint trace_num
,
527 HashedProcessData
**pm_hashed_process_data
)
529 ProcessInfo Process_Info
;
531 GtkTreePath
*tree_path
;
532 HashedProcessData
*hashed_process_data
= NULL
;
534 Process_Info
.pid
= pid
;
535 Process_Info
.birth
= *birth
;
536 Process_Info
.trace_num
= trace_num
;
538 if(hashed_process_data
=
539 (HashedProcessData
*)g_hash_table_lookup(
540 process_list
->process_hash
,
543 tree_path
= gtk_tree_row_reference_get_path(
544 hashed_process_data
->row_ref
);
545 path_indices
= gtk_tree_path_get_indices (tree_path
);
547 *height
= get_cell_height(
548 GTK_TREE_VIEW(process_list
->process_list_widget
));
549 *y
= *height
* path_indices
[0];
550 *pm_hashed_process_data
= hashed_process_data
;
553 *pm_hashed_process_data
= hashed_process_data
;
560 gint
processlist_get_pixels_from_data( ProcessList
*process_list
,
561 ProcessInfo
*process_info
,
562 HashedProcessData
*hashed_process_data
,
567 GtkTreePath
*tree_path
;
569 tree_path
= gtk_tree_row_reference_get_path(
570 hashed_process_data
->row_ref
);
571 path_indices
= gtk_tree_path_get_indices (tree_path
);
573 *height
= get_cell_height(
574 GTK_TREE_VIEW(process_list
->process_list_widget
));
575 *y
= *height
* path_indices
[0];