make precision correct when calling conversion between LttTime and double
[lttv.git] / ltt / branches / poly / lttv / modules / gui / controlflow / processlist.c
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
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
19 #include <gtk/gtk.h>
20 #include <glib.h>
21
22 #include "processlist.h"
23 #include "drawitem.h"
24
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)
27
28
29 /*****************************************************************************
30 * Methods to synchronize process list *
31 *****************************************************************************/
32
33 /* Enumeration of the columns */
34 enum
35 {
36 PROCESS_COLUMN,
37 PID_COLUMN,
38 BIRTH_S_COLUMN,
39 BIRTH_NS_COLUMN,
40 TRACE_COLUMN,
41 N_COLUMNS
42 };
43
44
45 gint process_sort_func ( GtkTreeModel *model,
46 GtkTreeIter *it_a,
47 GtkTreeIter *it_b,
48 gpointer user_data)
49 {
50 GValue a, b;
51
52 memset(&a, 0, sizeof(GValue));
53 memset(&b, 0, sizeof(GValue));
54
55 /* Order by PID */
56 gtk_tree_model_get_value( model,
57 it_a,
58 PID_COLUMN,
59 &a);
60
61 gtk_tree_model_get_value( model,
62 it_b,
63 PID_COLUMN,
64 &b);
65
66 if(G_VALUE_TYPE(&a) == G_TYPE_UINT
67 && G_VALUE_TYPE(&b) == G_TYPE_UINT )
68 {
69 if(g_value_get_uint(&a) > g_value_get_uint(&b))
70 {
71 g_value_unset(&a);
72 g_value_unset(&b);
73 return 1;
74 }
75 if(g_value_get_uint(&a) < g_value_get_uint(&b))
76 {
77 g_value_unset(&a);
78 g_value_unset(&b);
79 return 0;
80 }
81 }
82
83 g_value_unset(&a);
84 g_value_unset(&b);
85
86
87 /* Order by birth second */
88 gtk_tree_model_get_value( model,
89 it_a,
90 BIRTH_S_COLUMN,
91 &a);
92
93 gtk_tree_model_get_value( model,
94 it_b,
95 BIRTH_S_COLUMN,
96 &b);
97
98
99 if(G_VALUE_TYPE(&a) == G_TYPE_ULONG
100 && G_VALUE_TYPE(&b) == G_TYPE_ULONG )
101 {
102 if(g_value_get_ulong(&a) > g_value_get_ulong(&b))
103 {
104 g_value_unset(&a);
105 g_value_unset(&b);
106 return 1;
107 }
108 if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
109 {
110 g_value_unset(&a);
111 g_value_unset(&b);
112 return 0;
113 }
114
115 }
116
117 g_value_unset(&a);
118 g_value_unset(&b);
119
120 /* Order by birth nanosecond */
121 gtk_tree_model_get_value( model,
122 it_a,
123 BIRTH_NS_COLUMN,
124 &a);
125
126 gtk_tree_model_get_value( model,
127 it_b,
128 BIRTH_NS_COLUMN,
129 &b);
130
131
132 if(G_VALUE_TYPE(&a) == G_TYPE_ULONG
133 && G_VALUE_TYPE(&b) == G_TYPE_ULONG )
134 {
135 if(g_value_get_ulong(&a) > g_value_get_ulong(&b))
136 {
137 g_value_unset(&a);
138 g_value_unset(&b);
139 return 1;
140 }
141 // Final condition
142 //if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
143 //{
144 // g_value_unset(&a);
145 // g_value_unset(&b);
146 // return 0;
147 //}
148
149 }
150
151 g_value_unset(&a);
152 g_value_unset(&b);
153
154 /* Order by trace_num */
155 gtk_tree_model_get_value( model,
156 it_a,
157 TRACE_COLUMN,
158 &a);
159
160 gtk_tree_model_get_value( model,
161 it_b,
162 TRACE_COLUMN,
163 &b);
164
165 if(G_VALUE_TYPE(&a) == G_TYPE_ULONG
166 && G_VALUE_TYPE(&b) == G_TYPE_ULONG )
167 {
168 if(g_value_get_ulong(&a) > g_value_get_ulong(&b))
169 {
170 g_value_unset(&a);
171 g_value_unset(&b);
172 return 1;
173 }
174 if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
175 {
176 g_value_unset(&a);
177 g_value_unset(&b);
178 return 0;
179 }
180
181 }
182
183
184
185 return 0;
186
187 }
188
189 guint hash_fct(gconstpointer key)
190 {
191 return ((ProcessInfo*)key)->pid;
192 }
193
194 gboolean equ_fct(gconstpointer a, gconstpointer b)
195 {
196 if(((ProcessInfo*)a)->pid != ((ProcessInfo*)b)->pid)
197 return 0;
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)
200 return 0;
201 // g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_sec,((ProcessInfo*)b)->birth.tv_sec);
202
203 if(((ProcessInfo*)a)->birth.tv_nsec != ((ProcessInfo*)b)->birth.tv_nsec)
204 return 0;
205 // g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_nsec,((ProcessInfo*)b)->birth.tv_nsec);
206
207 if(((ProcessInfo*)a)->trace_num != ((ProcessInfo*)b)->trace_num)
208 return 0;
209
210 return 1;
211 }
212
213 void destroy_hash_key(gpointer key);
214
215 void destroy_hash_data(gpointer data);
216
217
218
219
220 ProcessList *processlist_construct(void)
221 {
222 GtkTreeViewColumn *column;
223 GtkCellRenderer *renderer;
224
225 ProcessList* process_list = g_new(ProcessList,1);
226
227 process_list->number_of_process = 0;
228
229 /* Create the Process list */
230 process_list->list_store = gtk_list_store_new ( N_COLUMNS,
231 G_TYPE_STRING,
232 G_TYPE_UINT,
233 G_TYPE_ULONG,
234 G_TYPE_ULONG,
235 G_TYPE_ULONG);
236
237
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));
242
243 gtk_tree_sortable_set_sort_func(
244 GTK_TREE_SORTABLE(process_list->list_store),
245 PID_COLUMN,
246 process_sort_func,
247 NULL,
248 NULL);
249
250 gtk_tree_sortable_set_sort_column_id(
251 GTK_TREE_SORTABLE(process_list->list_store),
252 PID_COLUMN,
253 GTK_SORT_ASCENDING);
254
255 process_list->process_hash = g_hash_table_new_full(
256 hash_fct, equ_fct,
257 destroy_hash_key, destroy_hash_data
258 );
259
260
261 gtk_tree_view_set_headers_visible(
262 GTK_TREE_VIEW(process_list->process_list_widget), TRUE);
263
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",
269 renderer,
270 "text",
271 PROCESS_COLUMN,
272 NULL);
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);
277
278 process_list->button = column->button;
279
280 column = gtk_tree_view_column_new_with_attributes ( "PID",
281 renderer,
282 "text",
283 PID_COLUMN,
284 NULL);
285 gtk_tree_view_append_column (
286 GTK_TREE_VIEW (process_list->process_list_widget), column);
287
288
289 column = gtk_tree_view_column_new_with_attributes ( "Birth sec",
290 renderer,
291 "text",
292 BIRTH_S_COLUMN,
293 NULL);
294 gtk_tree_view_append_column (
295 GTK_TREE_VIEW (process_list->process_list_widget), column);
296
297 //gtk_tree_view_column_set_visible(column, 0);
298 //
299 column = gtk_tree_view_column_new_with_attributes ( "Birth nsec",
300 renderer,
301 "text",
302 BIRTH_NS_COLUMN,
303 NULL);
304 gtk_tree_view_append_column (
305 GTK_TREE_VIEW (process_list->process_list_widget), column);
306
307 column = gtk_tree_view_column_new_with_attributes ( "TRACE",
308 renderer,
309 "text",
310 TRACE_COLUMN,
311 NULL);
312 gtk_tree_view_append_column (
313 GTK_TREE_VIEW (process_list->process_list_widget), column);
314
315
316 //gtk_tree_view_column_set_visible(column, 0);
317
318 g_object_set_data_full(
319 G_OBJECT(process_list->process_list_widget),
320 "process_list_Data",
321 process_list,
322 (GDestroyNotify)processlist_destroy);
323
324 return process_list;
325 }
326
327 void processlist_destroy(ProcessList *process_list)
328 {
329 g_debug("processlist_destroy %p", process_list);
330 g_hash_table_destroy(process_list->process_hash);
331 process_list->process_hash = NULL;
332
333 g_free(process_list);
334 g_debug("processlist_destroy end");
335 }
336
337 static gboolean remove_hash_item(ProcessInfo *process_info,
338 HashedProcessData *hashed_process_data,
339 ProcessList *process_list)
340 {
341 GtkTreePath *tree_path;
342 GtkTreeIter iter;
343
344 tree_path = gtk_tree_row_reference_get_path(
345 hashed_process_data->row_ref);
346
347 gtk_tree_model_get_iter (
348 GTK_TREE_MODEL(process_list->list_store),
349 &iter, tree_path);
350
351 gtk_tree_path_free(tree_path);
352
353 gtk_list_store_remove (process_list->list_store, &iter);
354
355 #if 0
356 g_free(hashed_process_data->draw_context->previous->modify_under);
357 g_free(hashed_process_data->draw_context->previous->modify_middle);
358 g_free(hashed_process_data->draw_context->previous->modify_over);
359 g_free(hashed_process_data->draw_context->previous->under);
360 g_free(hashed_process_data->draw_context->previous->middle);
361 g_free(hashed_process_data->draw_context->previous->over);
362 g_free(hashed_process_data->draw_context->previous);
363 g_free(hashed_process_data->draw_context->current->modify_under);
364 g_free(hashed_process_data->draw_context->current->modify_middle);
365 g_free(hashed_process_data->draw_context->current->modify_over);
366 g_free(hashed_process_data->draw_context->current->under);
367 g_free(hashed_process_data->draw_context->current->middle);
368 g_free(hashed_process_data->draw_context->current->over);
369 g_free(hashed_process_data->draw_context->current);
370 g_free(hashed_process_data->draw_context);
371 g_free(hashed_process_data);
372 #endif //0
373
374
375 return TRUE; /* remove the element from the hash table */
376 }
377
378 void processlist_clear(ProcessList *process_list)
379 {
380 g_info("processlist_clear %p", process_list);
381
382 g_hash_table_foreach_remove(process_list->process_hash,
383 (GHRFunc)remove_hash_item,
384 (gpointer)process_list);
385 process_list->number_of_process = 0;
386 }
387
388
389 GtkWidget *processlist_get_widget(ProcessList *process_list)
390 {
391 return process_list->process_list_widget;
392 }
393
394
395
396 gint get_cell_height(GtkTreeView *tree_view)
397 {
398 gint height;
399 GtkTreeViewColumn *Column = gtk_tree_view_get_column(tree_view, 0);
400 //GList *Render_List = gtk_tree_view_column_get_cell_renderers(Column);
401 //GtkCellRenderer *Renderer = g_list_first(Render_List)->data;
402
403 //g_list_free(Render_List);
404 gtk_tree_view_column_cell_get_size(Column, NULL, NULL, NULL, NULL, &height);
405 //g_critical("cell 0 height : %u",height);
406
407 return height;
408 }
409
410 void destroy_hash_key(gpointer key)
411 {
412 g_free(key);
413 }
414
415 void destroy_hash_data(gpointer data)
416 {
417 g_free(data);
418 }
419
420 int processlist_add( ProcessList *process_list,
421 guint pid,
422 LttTime *birth,
423 guint trace_num,
424 const gchar *name,
425 guint *height,
426 HashedProcessData **pm_hashed_process_data)
427 {
428 GtkTreeIter iter ;
429 ProcessInfo *Process_Info = g_new(ProcessInfo, 1);
430 HashedProcessData *hashed_process_data = g_new(HashedProcessData, 1);
431 *pm_hashed_process_data = hashed_process_data;
432
433 Process_Info->pid = pid;
434 Process_Info->birth = *birth;
435 Process_Info->trace_num = trace_num;
436
437 /* When we create it from before state update, we are sure that the
438 * last event occured before the beginning of the global area.
439 *
440 * If it is created after state update, this value (0) will be
441 * overriden by the new state before anything is drawn.
442 */
443 hashed_process_data->x = 0;
444
445 #if 0
446 hashed_process_data->draw_context = g_new(DrawContext, 1);
447 hashed_process_data->draw_context->drawable = NULL;
448 hashed_process_data->draw_context->gc = NULL;
449 hashed_process_data->draw_context->pango_layout = NULL;
450 hashed_process_data->draw_context->current = g_new(DrawInfo,1);
451 hashed_process_data->draw_context->current->over = g_new(ItemInfo,1);
452 hashed_process_data->draw_context->current->over->x = -1;
453 hashed_process_data->draw_context->current->over->y = -1;
454 hashed_process_data->draw_context->current->middle = g_new(ItemInfo,1);
455 hashed_process_data->draw_context->current->middle->x = -1;
456 hashed_process_data->draw_context->current->middle->y = -1;
457 hashed_process_data->draw_context->current->under = g_new(ItemInfo,1);
458 hashed_process_data->draw_context->current->under->x = -1;
459 hashed_process_data->draw_context->current->under->y = -1;
460 hashed_process_data->draw_context->current->modify_over = g_new(ItemInfo,1);
461 hashed_process_data->draw_context->current->modify_over->x = -1;
462 hashed_process_data->draw_context->current->modify_over->y = -1;
463 hashed_process_data->draw_context->current->modify_middle = g_new(ItemInfo,1);
464 hashed_process_data->draw_context->current->modify_middle->x = -1;
465 hashed_process_data->draw_context->current->modify_middle->y = -1;
466 hashed_process_data->draw_context->current->modify_under = g_new(ItemInfo,1);
467 hashed_process_data->draw_context->current->modify_under->x = -1;
468 hashed_process_data->draw_context->current->modify_under->y = -1;
469 hashed_process_data->draw_context->current->status = LTTV_STATE_UNNAMED;
470 hashed_process_data->draw_context->previous = g_new(DrawInfo,1);
471 hashed_process_data->draw_context->previous->over = g_new(ItemInfo,1);
472 hashed_process_data->draw_context->previous->over->x = -1;
473 hashed_process_data->draw_context->previous->over->y = -1;
474 hashed_process_data->draw_context->previous->middle = g_new(ItemInfo,1);
475 hashed_process_data->draw_context->previous->middle->x = -1;
476 hashed_process_data->draw_context->previous->middle->y = -1;
477 hashed_process_data->draw_context->previous->under = g_new(ItemInfo,1);
478 hashed_process_data->draw_context->previous->under->x = -1;
479 hashed_process_data->draw_context->previous->under->y = -1;
480 hashed_process_data->draw_context->previous->modify_over = g_new(ItemInfo,1);
481 hashed_process_data->draw_context->previous->modify_over->x = -1;
482 hashed_process_data->draw_context->previous->modify_over->y = -1;
483 hashed_process_data->draw_context->previous->modify_middle = g_new(ItemInfo,1);
484 hashed_process_data->draw_context->previous->modify_middle->x = -1;
485 hashed_process_data->draw_context->previous->modify_middle->y = -1;
486 hashed_process_data->draw_context->previous->modify_under = g_new(ItemInfo,1);
487 hashed_process_data->draw_context->previous->modify_under->x = -1;
488 hashed_process_data->draw_context->previous->modify_under->y = -1;
489 hashed_process_data->draw_context->previous->status = LTTV_STATE_UNNAMED;
490 #endif //0
491
492 /* Add a new row to the model */
493 gtk_list_store_append ( process_list->list_store, &iter);
494 //g_critical ( "iter before : %s", gtk_tree_path_to_string (
495 // gtk_tree_model_get_path (
496 // GTK_TREE_MODEL(process_list->list_store),
497 // &iter)));
498 gtk_list_store_set ( process_list->list_store, &iter,
499 PROCESS_COLUMN, name,
500 PID_COLUMN, pid,
501 BIRTH_S_COLUMN, birth->tv_sec,
502 BIRTH_NS_COLUMN, birth->tv_nsec,
503 TRACE_COLUMN, trace_num,
504 -1);
505 hashed_process_data->row_ref = gtk_tree_row_reference_new (
506 GTK_TREE_MODEL(process_list->list_store),
507 gtk_tree_model_get_path(
508 GTK_TREE_MODEL(process_list->list_store),
509 &iter));
510 g_hash_table_insert( process_list->process_hash,
511 (gpointer)Process_Info,
512 (gpointer)hashed_process_data);
513
514 //g_critical ( "iter after : %s", gtk_tree_path_to_string (
515 // gtk_tree_model_get_path (
516 // GTK_TREE_MODEL(process_list->list_store),
517 // &iter)));
518 process_list->number_of_process++;
519
520 *height = get_cell_height(GTK_TREE_VIEW(process_list->process_list_widget))
521 * process_list->number_of_process ;
522
523
524 return 0;
525
526 }
527
528 int processlist_remove( ProcessList *process_list,
529 guint pid,
530 LttTime *birth,
531 guint trace_num)
532 {
533 ProcessInfo Process_Info;
534 gint *path_indices;
535 HashedProcessData *hashed_process_data;
536 GtkTreeIter iter;
537
538 Process_Info.pid = pid;
539 Process_Info.birth = *birth;
540 Process_Info.trace_num = trace_num;
541
542
543 if(hashed_process_data =
544 (HashedProcessData*)g_hash_table_lookup(
545 process_list->process_hash,
546 &Process_Info))
547 {
548 GtkTreePath *tree_path;
549
550 tree_path = gtk_tree_row_reference_get_path(
551 hashed_process_data->row_ref);
552
553 gtk_tree_model_get_iter (
554 GTK_TREE_MODEL(process_list->list_store),
555 &iter, tree_path);
556
557 gtk_tree_path_free(tree_path);
558
559 gtk_list_store_remove (process_list->list_store, &iter);
560 #if 0
561 g_free(hashed_process_data->draw_context->previous->modify_under);
562 g_free(hashed_process_data->draw_context->previous->modify_middle);
563 g_free(hashed_process_data->draw_context->previous->modify_over);
564 g_free(hashed_process_data->draw_context->previous->under);
565 g_free(hashed_process_data->draw_context->previous->middle);
566 g_free(hashed_process_data->draw_context->previous->over);
567 g_free(hashed_process_data->draw_context->previous);
568 g_free(hashed_process_data->draw_context->current->modify_under);
569 g_free(hashed_process_data->draw_context->current->modify_middle);
570 g_free(hashed_process_data->draw_context->current->modify_over);
571 g_free(hashed_process_data->draw_context->current->under);
572 g_free(hashed_process_data->draw_context->current->middle);
573 g_free(hashed_process_data->draw_context->current->over);
574 g_free(hashed_process_data->draw_context->current);
575 g_free(hashed_process_data->draw_context);
576 g_free(hashed_process_data);
577 #endif //0
578 g_hash_table_remove(process_list->process_hash,
579 &Process_Info);
580
581 process_list->number_of_process--;
582
583 return 0;
584 } else {
585 return 1;
586 }
587 }
588
589
590 guint processlist_get_height(ProcessList *process_list)
591 {
592 return get_cell_height(GTK_TREE_VIEW(process_list->process_list_widget))
593 * process_list->number_of_process ;
594 }
595
596
597 gint processlist_get_process_pixels( ProcessList *process_list,
598 guint pid, LttTime *birth, guint trace_num,
599 guint *y,
600 guint *height,
601 HashedProcessData **pm_hashed_process_data)
602 {
603 ProcessInfo Process_Info;
604 gint *path_indices;
605 GtkTreePath *tree_path;
606 HashedProcessData *hashed_process_data = NULL;
607
608 Process_Info.pid = pid;
609 Process_Info.birth = *birth;
610 Process_Info.trace_num = trace_num;
611
612 if(hashed_process_data =
613 (HashedProcessData*)g_hash_table_lookup(
614 process_list->process_hash,
615 &Process_Info))
616 {
617 tree_path = gtk_tree_row_reference_get_path(
618 hashed_process_data->row_ref);
619 path_indices = gtk_tree_path_get_indices (tree_path);
620
621 *height = get_cell_height(
622 GTK_TREE_VIEW(process_list->process_list_widget));
623 *y = *height * path_indices[0];
624 *pm_hashed_process_data = hashed_process_data;
625 gtk_tree_path_free(tree_path);
626
627 return 0;
628 } else {
629 *pm_hashed_process_data = hashed_process_data;
630 return 1;
631 }
632
633 }
634
635
636 gint processlist_get_pixels_from_data( ProcessList *process_list,
637 ProcessInfo *process_info,
638 HashedProcessData *hashed_process_data,
639 guint *y,
640 guint *height)
641 {
642 gint *path_indices;
643 GtkTreePath *tree_path;
644
645 tree_path = gtk_tree_row_reference_get_path(
646 hashed_process_data->row_ref);
647 path_indices = gtk_tree_path_get_indices (tree_path);
648
649 *height = get_cell_height(
650 GTK_TREE_VIEW(process_list->process_list_widget));
651 *y = *height * path_indices[0];
652 gtk_tree_path_free(tree_path);
653
654 return 0;
655
656 }
This page took 0.04262 seconds and 4 git commands to generate.