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 */
40 gint
process_sort_func ( GtkTreeModel
*model
,
47 memset(&a
, 0, sizeof(GValue
));
48 memset(&b
, 0, sizeof(GValue
));
51 gtk_tree_model_get_value( model
,
56 gtk_tree_model_get_value( model
,
61 if(G_VALUE_TYPE(&a
) == G_TYPE_UINT
62 && G_VALUE_TYPE(&b
) == G_TYPE_UINT
)
64 if(g_value_get_uint(&a
) > g_value_get_uint(&b
))
70 if(g_value_get_uint(&a
) < g_value_get_uint(&b
))
82 /* Order by birth second */
83 gtk_tree_model_get_value( model
,
88 gtk_tree_model_get_value( model
,
94 if(G_VALUE_TYPE(&a
) == G_TYPE_ULONG
95 && G_VALUE_TYPE(&b
) == G_TYPE_ULONG
)
97 if(g_value_get_ulong(&a
) > g_value_get_ulong(&b
))
103 if(g_value_get_ulong(&a
) < g_value_get_ulong(&b
))
115 /* Order by birth nanosecond */
116 gtk_tree_model_get_value( model
,
121 gtk_tree_model_get_value( model
,
127 if(G_VALUE_TYPE(&a
) == G_TYPE_ULONG
128 && G_VALUE_TYPE(&b
) == G_TYPE_ULONG
)
130 if(g_value_get_ulong(&a
) > g_value_get_ulong(&b
))
137 //if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
139 // g_value_unset(&a);
140 // g_value_unset(&b);
153 guint
hash_fct(gconstpointer key
)
155 return ((ProcessInfo
*)key
)->pid
;
158 gboolean
equ_fct(gconstpointer a
, gconstpointer b
)
160 if(((ProcessInfo
*)a
)->pid
!= ((ProcessInfo
*)b
)->pid
)
162 // g_critical("compare %u and %u",((ProcessInfo*)a)->pid,((ProcessInfo*)b)->pid);
163 if(((ProcessInfo
*)a
)->birth
.tv_sec
!= ((ProcessInfo
*)b
)->birth
.tv_sec
)
165 // g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_sec,((ProcessInfo*)b)->birth.tv_sec);
167 if(((ProcessInfo
*)a
)->birth
.tv_nsec
!= ((ProcessInfo
*)b
)->birth
.tv_nsec
)
169 // g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_nsec,((ProcessInfo*)b)->birth.tv_nsec);
174 void destroy_hash_key(gpointer key
);
176 void destroy_hash_data(gpointer data
);
181 ProcessList
*processlist_construct(void)
183 GtkTreeViewColumn
*column
;
184 GtkCellRenderer
*renderer
;
186 ProcessList
* process_list
= g_new(ProcessList
,1);
188 process_list
->number_of_process
= 0;
190 /* Create the Process list */
191 process_list
->list_store
= gtk_list_store_new ( N_COLUMNS
,
198 process_list
->process_list_widget
=
199 gtk_tree_view_new_with_model
200 (GTK_TREE_MODEL (process_list
->list_store
));
202 g_object_unref (G_OBJECT (process_list
->list_store
));
204 gtk_tree_sortable_set_sort_func(
205 GTK_TREE_SORTABLE(process_list
->list_store
),
211 gtk_tree_sortable_set_sort_column_id(
212 GTK_TREE_SORTABLE(process_list
->list_store
),
216 process_list
->process_hash
= g_hash_table_new_full(
218 destroy_hash_key
, destroy_hash_data
222 gtk_tree_view_set_headers_visible(
223 GTK_TREE_VIEW(process_list
->process_list_widget
), FALSE
);
225 /* Create a column, associating the "text" attribute of the
226 * cell_renderer to the first column of the model */
227 /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */
228 renderer
= gtk_cell_renderer_text_new ();
229 column
= gtk_tree_view_column_new_with_attributes ( "Process",
234 gtk_tree_view_column_set_alignment (column
, 0.0);
235 gtk_tree_view_column_set_fixed_width (column
, 45);
236 gtk_tree_view_append_column (
237 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
239 column
= gtk_tree_view_column_new_with_attributes ( "PID",
244 gtk_tree_view_append_column (
245 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
248 column
= gtk_tree_view_column_new_with_attributes ( "Birth sec",
253 gtk_tree_view_append_column (
254 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
256 //gtk_tree_view_column_set_visible(column, 0);
258 column
= gtk_tree_view_column_new_with_attributes ( "Birth nsec",
263 gtk_tree_view_append_column (
264 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
266 //gtk_tree_view_column_set_visible(column, 0);
268 g_object_set_data_full(
269 G_OBJECT(process_list
->process_list_widget
),
272 (GDestroyNotify
)processlist_destroy
);
276 void processlist_destroy(ProcessList
*process_list
)
278 g_hash_table_destroy(process_list
->process_hash
);
279 process_list
->process_hash
= NULL
;
281 g_free(process_list
);
284 GtkWidget
*processlist_get_widget(ProcessList
*process_list
)
286 return process_list
->process_list_widget
;
291 gint
get_cell_height(GtkTreeView
*tree_view
)
294 GtkTreeViewColumn
*Column
= gtk_tree_view_get_column(tree_view
, 0);
295 //GList *Render_List = gtk_tree_view_column_get_cell_renderers(Column);
296 //GtkCellRenderer *Renderer = g_list_first(Render_List)->data;
298 //g_list_free(Render_List);
299 gtk_tree_view_column_cell_get_size(Column
, NULL
, NULL
, NULL
, NULL
, &height
);
300 //g_critical("cell 0 height : %u",height);
305 void destroy_hash_key(gpointer key
)
310 void destroy_hash_data(gpointer data
)
315 int processlist_add( ProcessList
*process_list
,
320 HashedProcessData
**pm_hashed_process_data
)
323 ProcessInfo
*Process_Info
= g_new(ProcessInfo
, 1);
324 HashedProcessData
*hashed_process_data
= g_new(HashedProcessData
, 1);
325 *pm_hashed_process_data
= hashed_process_data
;
327 Process_Info
->pid
= pid
;
328 Process_Info
->birth
= *birth
;
330 hashed_process_data
->draw_context
= g_new(DrawContext
, 1);
331 hashed_process_data
->draw_context
->drawable
= NULL
;
332 hashed_process_data
->draw_context
->gc
= NULL
;
333 hashed_process_data
->draw_context
->pango_layout
= NULL
;
334 hashed_process_data
->draw_context
->current
= g_new(DrawInfo
,1);
335 hashed_process_data
->draw_context
->current
->over
= g_new(ItemInfo
,1);
336 hashed_process_data
->draw_context
->current
->over
->x
= -1;
337 hashed_process_data
->draw_context
->current
->over
->y
= -1;
338 hashed_process_data
->draw_context
->current
->middle
= g_new(ItemInfo
,1);
339 hashed_process_data
->draw_context
->current
->middle
->x
= -1;
340 hashed_process_data
->draw_context
->current
->middle
->y
= -1;
341 hashed_process_data
->draw_context
->current
->under
= g_new(ItemInfo
,1);
342 hashed_process_data
->draw_context
->current
->under
->x
= -1;
343 hashed_process_data
->draw_context
->current
->under
->y
= -1;
344 hashed_process_data
->draw_context
->current
->modify_over
= g_new(ItemInfo
,1);
345 hashed_process_data
->draw_context
->current
->modify_over
->x
= -1;
346 hashed_process_data
->draw_context
->current
->modify_over
->y
= -1;
347 hashed_process_data
->draw_context
->current
->modify_middle
= g_new(ItemInfo
,1);
348 hashed_process_data
->draw_context
->current
->modify_middle
->x
= -1;
349 hashed_process_data
->draw_context
->current
->modify_middle
->y
= -1;
350 hashed_process_data
->draw_context
->current
->modify_under
= g_new(ItemInfo
,1);
351 hashed_process_data
->draw_context
->current
->modify_under
->x
= -1;
352 hashed_process_data
->draw_context
->current
->modify_under
->y
= -1;
353 hashed_process_data
->draw_context
->current
->status
= LTTV_STATE_UNNAMED
;
354 hashed_process_data
->draw_context
->previous
= g_new(DrawInfo
,1);
355 hashed_process_data
->draw_context
->previous
->over
= g_new(ItemInfo
,1);
356 hashed_process_data
->draw_context
->previous
->over
->x
= -1;
357 hashed_process_data
->draw_context
->previous
->over
->y
= -1;
358 hashed_process_data
->draw_context
->previous
->middle
= g_new(ItemInfo
,1);
359 hashed_process_data
->draw_context
->previous
->middle
->x
= -1;
360 hashed_process_data
->draw_context
->previous
->middle
->y
= -1;
361 hashed_process_data
->draw_context
->previous
->under
= g_new(ItemInfo
,1);
362 hashed_process_data
->draw_context
->previous
->under
->x
= -1;
363 hashed_process_data
->draw_context
->previous
->under
->y
= -1;
364 hashed_process_data
->draw_context
->previous
->modify_over
= g_new(ItemInfo
,1);
365 hashed_process_data
->draw_context
->previous
->modify_over
->x
= -1;
366 hashed_process_data
->draw_context
->previous
->modify_over
->y
= -1;
367 hashed_process_data
->draw_context
->previous
->modify_middle
= g_new(ItemInfo
,1);
368 hashed_process_data
->draw_context
->previous
->modify_middle
->x
= -1;
369 hashed_process_data
->draw_context
->previous
->modify_middle
->y
= -1;
370 hashed_process_data
->draw_context
->previous
->modify_under
= g_new(ItemInfo
,1);
371 hashed_process_data
->draw_context
->previous
->modify_under
->x
= -1;
372 hashed_process_data
->draw_context
->previous
->modify_under
->y
= -1;
373 hashed_process_data
->draw_context
->previous
->status
= LTTV_STATE_UNNAMED
;
375 /* Add a new row to the model */
376 gtk_list_store_append ( process_list
->list_store
, &iter
);
377 //g_critical ( "iter before : %s", gtk_tree_path_to_string (
378 // gtk_tree_model_get_path (
379 // GTK_TREE_MODEL(process_list->list_store),
381 gtk_list_store_set ( process_list
->list_store
, &iter
,
382 PROCESS_COLUMN
, name
,
384 BIRTH_S_COLUMN
, birth
->tv_sec
,
385 BIRTH_NS_COLUMN
, birth
->tv_nsec
,
387 hashed_process_data
->row_ref
= gtk_tree_row_reference_new (
388 GTK_TREE_MODEL(process_list
->list_store
),
389 gtk_tree_model_get_path(
390 GTK_TREE_MODEL(process_list
->list_store
),
392 g_hash_table_insert( process_list
->process_hash
,
393 (gpointer
)Process_Info
,
394 (gpointer
)hashed_process_data
);
396 //g_critical ( "iter after : %s", gtk_tree_path_to_string (
397 // gtk_tree_model_get_path (
398 // GTK_TREE_MODEL(process_list->list_store),
400 process_list
->number_of_process
++;
402 *height
= get_cell_height(GTK_TREE_VIEW(process_list
->process_list_widget
))
403 * process_list
->number_of_process
;
410 int processlist_remove( ProcessList
*process_list
,
414 ProcessInfo Process_Info
;
416 HashedProcessData
*hashed_process_data
;
419 Process_Info
.pid
= pid
;
420 Process_Info
.birth
= *birth
;
423 if(hashed_process_data
=
424 (HashedProcessData
*)g_hash_table_lookup(
425 process_list
->process_hash
,
428 gtk_tree_model_get_iter (
429 GTK_TREE_MODEL(process_list
->list_store
),
431 gtk_tree_row_reference_get_path(
432 (GtkTreeRowReference
*)hashed_process_data
->row_ref
)
435 gtk_list_store_remove (process_list
->list_store
, &iter
);
437 g_free(hashed_process_data
->draw_context
->previous
->modify_under
);
438 g_free(hashed_process_data
->draw_context
->previous
->modify_middle
);
439 g_free(hashed_process_data
->draw_context
->previous
->modify_over
);
440 g_free(hashed_process_data
->draw_context
->previous
->under
);
441 g_free(hashed_process_data
->draw_context
->previous
->middle
);
442 g_free(hashed_process_data
->draw_context
->previous
->over
);
443 g_free(hashed_process_data
->draw_context
->previous
);
444 g_free(hashed_process_data
->draw_context
->current
->modify_under
);
445 g_free(hashed_process_data
->draw_context
->current
->modify_middle
);
446 g_free(hashed_process_data
->draw_context
->current
->modify_over
);
447 g_free(hashed_process_data
->draw_context
->current
->under
);
448 g_free(hashed_process_data
->draw_context
->current
->middle
);
449 g_free(hashed_process_data
->draw_context
->current
->over
);
450 g_free(hashed_process_data
->draw_context
->current
);
451 g_free(hashed_process_data
->draw_context
);
452 g_free(hashed_process_data
);
454 g_hash_table_remove(process_list
->process_hash
,
457 process_list
->number_of_process
--;
466 guint
processlist_get_height(ProcessList
*process_list
)
468 return get_cell_height(GTK_TREE_VIEW(process_list
->process_list_widget
))
469 * process_list
->number_of_process
;
473 gint
processlist_get_process_pixels( ProcessList
*process_list
,
474 guint pid
, LttTime
*birth
,
477 HashedProcessData
**pm_hashed_process_data
)
479 ProcessInfo Process_Info
;
481 GtkTreePath
*tree_path
;
482 HashedProcessData
*hashed_process_data
= NULL
;
484 Process_Info
.pid
= pid
;
485 Process_Info
.birth
= *birth
;
487 if(hashed_process_data
=
488 (HashedProcessData
*)g_hash_table_lookup(
489 process_list
->process_hash
,
492 tree_path
= gtk_tree_row_reference_get_path(
493 hashed_process_data
->row_ref
);
494 path_indices
= gtk_tree_path_get_indices (tree_path
);
496 *height
= get_cell_height(
497 GTK_TREE_VIEW(process_list
->process_list_widget
));
498 *y
= *height
* path_indices
[0];
499 *pm_hashed_process_data
= hashed_process_data
;
502 *pm_hashed_process_data
= hashed_process_data
;
509 gint
processlist_get_pixels_from_data( ProcessList
*process_list
,
510 ProcessInfo
*process_info
,
511 HashedProcessData
*hashed_process_data
,
516 GtkTreePath
*tree_path
;
518 tree_path
= gtk_tree_row_reference_get_path(
519 hashed_process_data
->row_ref
);
520 path_indices
= gtk_tree_path_get_indices (tree_path
);
522 *height
= get_cell_height(
523 GTK_TREE_VIEW(process_list
->process_list_widget
));
524 *y
= *height
* path_indices
[0];