fix stop
[lttv.git] / ltt / branches / poly / lttv / modules / gui / controlflow / processlist.c
CommitLineData
ce0214a6 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 */
f0d936c0 18
fa2c4dbe 19#include <gtk/gtk.h>
20#include <glib.h>
d66666fe 21
22#include "processlist.h"
23#include "drawitem.h"
fa2c4dbe 24
f0d936c0 25/*****************************************************************************
26 * Methods to synchronize process list *
27 *****************************************************************************/
28
f0d936c0 29/* Enumeration of the columns */
30enum
31{
a56a1ba4 32 PROCESS_COLUMN,
33 PID_COLUMN,
34 BIRTH_S_COLUMN,
35 BIRTH_NS_COLUMN,
d0cd7f09 36 TRACE_COLUMN,
a56a1ba4 37 N_COLUMNS
f0d936c0 38};
39
40
a56a1ba4 41gint process_sort_func ( GtkTreeModel *model,
42 GtkTreeIter *it_a,
43 GtkTreeIter *it_b,
44 gpointer user_data)
fa2c4dbe 45{
a56a1ba4 46 GValue a, b;
47
48 memset(&a, 0, sizeof(GValue));
49 memset(&b, 0, sizeof(GValue));
50
51 /* Order by PID */
52 gtk_tree_model_get_value( model,
53 it_a,
54 PID_COLUMN,
55 &a);
56
57 gtk_tree_model_get_value( model,
58 it_b,
59 PID_COLUMN,
60 &b);
61
62 if(G_VALUE_TYPE(&a) == G_TYPE_UINT
63 && G_VALUE_TYPE(&b) == G_TYPE_UINT )
64 {
65 if(g_value_get_uint(&a) > g_value_get_uint(&b))
66 {
67 g_value_unset(&a);
68 g_value_unset(&b);
69 return 1;
70 }
71 if(g_value_get_uint(&a) < g_value_get_uint(&b))
72 {
73 g_value_unset(&a);
74 g_value_unset(&b);
75 return 0;
76 }
77 }
78
79 g_value_unset(&a);
80 g_value_unset(&b);
81
82
83 /* Order by birth second */
84 gtk_tree_model_get_value( model,
85 it_a,
86 BIRTH_S_COLUMN,
87 &a);
88
89 gtk_tree_model_get_value( model,
90 it_b,
91 BIRTH_S_COLUMN,
92 &b);
93
94
95 if(G_VALUE_TYPE(&a) == G_TYPE_ULONG
96 && G_VALUE_TYPE(&b) == G_TYPE_ULONG )
97 {
98 if(g_value_get_ulong(&a) > g_value_get_ulong(&b))
99 {
100 g_value_unset(&a);
101 g_value_unset(&b);
102 return 1;
103 }
104 if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
105 {
106 g_value_unset(&a);
107 g_value_unset(&b);
108 return 0;
109 }
110
111 }
112
113 g_value_unset(&a);
114 g_value_unset(&b);
115
116 /* Order by birth nanosecond */
117 gtk_tree_model_get_value( model,
118 it_a,
119 BIRTH_NS_COLUMN,
120 &a);
121
122 gtk_tree_model_get_value( model,
123 it_b,
124 BIRTH_NS_COLUMN,
125 &b);
126
127
128 if(G_VALUE_TYPE(&a) == G_TYPE_ULONG
129 && G_VALUE_TYPE(&b) == G_TYPE_ULONG )
130 {
131 if(g_value_get_ulong(&a) > g_value_get_ulong(&b))
132 {
133 g_value_unset(&a);
134 g_value_unset(&b);
135 return 1;
136 }
137 // Final condition
138 //if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
139 //{
140 // g_value_unset(&a);
141 // g_value_unset(&b);
142 // return 0;
143 //}
144
145 }
146
147 g_value_unset(&a);
148 g_value_unset(&b);
149
d0cd7f09 150 /* Order by trace_num */
151 gtk_tree_model_get_value( model,
152 it_a,
153 TRACE_COLUMN,
154 &a);
155
156 gtk_tree_model_get_value( model,
157 it_b,
158 TRACE_COLUMN,
159 &b);
160
161 if(G_VALUE_TYPE(&a) == G_TYPE_ULONG
162 && G_VALUE_TYPE(&b) == G_TYPE_ULONG )
163 {
164 if(g_value_get_ulong(&a) > g_value_get_ulong(&b))
165 {
166 g_value_unset(&a);
167 g_value_unset(&b);
168 return 1;
169 }
170 if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
171 {
172 g_value_unset(&a);
173 g_value_unset(&b);
174 return 0;
175 }
176
177 }
178
179
180
a56a1ba4 181 return 0;
fa2c4dbe 182
183}
184
fa2c4dbe 185guint hash_fct(gconstpointer key)
186{
a56a1ba4 187 return ((ProcessInfo*)key)->pid;
fa2c4dbe 188}
189
190gboolean equ_fct(gconstpointer a, gconstpointer b)
191{
a56a1ba4 192 if(((ProcessInfo*)a)->pid != ((ProcessInfo*)b)->pid)
193 return 0;
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)
196 return 0;
197// g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_sec,((ProcessInfo*)b)->birth.tv_sec);
198
199 if(((ProcessInfo*)a)->birth.tv_nsec != ((ProcessInfo*)b)->birth.tv_nsec)
200 return 0;
201// g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_nsec,((ProcessInfo*)b)->birth.tv_nsec);
202
d0cd7f09 203 if(((ProcessInfo*)a)->trace_num != ((ProcessInfo*)b)->trace_num)
204 return 0;
205
a56a1ba4 206 return 1;
fa2c4dbe 207}
208
4c69e0cc 209void destroy_hash_key(gpointer key);
fa2c4dbe 210
4c69e0cc 211void destroy_hash_data(gpointer data);
fa2c4dbe 212
213
214
215
4c69e0cc 216ProcessList *processlist_construct(void)
f0d936c0 217{
a56a1ba4 218 GtkTreeViewColumn *column;
219 GtkCellRenderer *renderer;
220
ba90bc77 221 ProcessList* process_list = g_new(ProcessList,1);
a56a1ba4 222
ba90bc77 223 process_list->number_of_process = 0;
a56a1ba4 224
225 /* Create the Process list */
f5d980bf 226 process_list->list_store = gtk_list_store_new ( N_COLUMNS,
a56a1ba4 227 G_TYPE_STRING,
228 G_TYPE_UINT,
229 G_TYPE_ULONG,
d0cd7f09 230 G_TYPE_ULONG,
a56a1ba4 231 G_TYPE_ULONG);
232
233
f5d980bf 234 process_list->process_list_widget =
a56a1ba4 235 gtk_tree_view_new_with_model
f5d980bf 236 (GTK_TREE_MODEL (process_list->list_store));
a56a1ba4 237
f5d980bf 238 g_object_unref (G_OBJECT (process_list->list_store));
a56a1ba4 239
240 gtk_tree_sortable_set_sort_func(
f5d980bf 241 GTK_TREE_SORTABLE(process_list->list_store),
a56a1ba4 242 PID_COLUMN,
243 process_sort_func,
244 NULL,
245 NULL);
246
247 gtk_tree_sortable_set_sort_column_id(
f5d980bf 248 GTK_TREE_SORTABLE(process_list->list_store),
a56a1ba4 249 PID_COLUMN,
250 GTK_SORT_ASCENDING);
251
14963be0 252 process_list->process_hash = g_hash_table_new_full(
a56a1ba4 253 hash_fct, equ_fct,
254 destroy_hash_key, destroy_hash_data
255 );
256
257
258 gtk_tree_view_set_headers_visible(
3cb8b205 259 GTK_TREE_VIEW(process_list->process_list_widget), TRUE);
a56a1ba4 260
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",
266 renderer,
267 "text",
268 PROCESS_COLUMN,
269 NULL);
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 (
f5d980bf 273 GTK_TREE_VIEW (process_list->process_list_widget), column);
a56a1ba4 274
275 column = gtk_tree_view_column_new_with_attributes ( "PID",
276 renderer,
277 "text",
278 PID_COLUMN,
279 NULL);
280 gtk_tree_view_append_column (
f5d980bf 281 GTK_TREE_VIEW (process_list->process_list_widget), column);
a56a1ba4 282
283
284 column = gtk_tree_view_column_new_with_attributes ( "Birth sec",
285 renderer,
286 "text",
287 BIRTH_S_COLUMN,
288 NULL);
289 gtk_tree_view_append_column (
f5d980bf 290 GTK_TREE_VIEW (process_list->process_list_widget), column);
a56a1ba4 291
292 //gtk_tree_view_column_set_visible(column, 0);
293 //
294 column = gtk_tree_view_column_new_with_attributes ( "Birth nsec",
295 renderer,
296 "text",
297 BIRTH_NS_COLUMN,
298 NULL);
299 gtk_tree_view_append_column (
f5d980bf 300 GTK_TREE_VIEW (process_list->process_list_widget), column);
a56a1ba4 301
d0cd7f09 302 column = gtk_tree_view_column_new_with_attributes ( "TRACE",
303 renderer,
304 "text",
305 TRACE_COLUMN,
306 NULL);
307 gtk_tree_view_append_column (
308 GTK_TREE_VIEW (process_list->process_list_widget), column);
309
310
a56a1ba4 311 //gtk_tree_view_column_set_visible(column, 0);
312
313 g_object_set_data_full(
f5d980bf 314 G_OBJECT(process_list->process_list_widget),
ba90bc77 315 "process_list_Data",
316 process_list,
a56a1ba4 317 (GDestroyNotify)processlist_destroy);
318
ba90bc77 319 return process_list;
f0d936c0 320}
ba90bc77 321void processlist_destroy(ProcessList *process_list)
f0d936c0 322{
14963be0 323 g_hash_table_destroy(process_list->process_hash);
324 process_list->process_hash = NULL;
f0d936c0 325
ba90bc77 326 g_free(process_list);
f0d936c0 327}
328
ba90bc77 329GtkWidget *processlist_get_widget(ProcessList *process_list)
f0d936c0 330{
f5d980bf 331 return process_list->process_list_widget;
f0d936c0 332}
333
334
335
f5d980bf 336gint get_cell_height(GtkTreeView *tree_view)
f0d936c0 337{
a56a1ba4 338 gint height;
f5d980bf 339 GtkTreeViewColumn *Column = gtk_tree_view_get_column(tree_view, 0);
a56a1ba4 340 //GList *Render_List = gtk_tree_view_column_get_cell_renderers(Column);
341 //GtkCellRenderer *Renderer = g_list_first(Render_List)->data;
342
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);
346
347 return height;
f0d936c0 348}
349
4c69e0cc 350void destroy_hash_key(gpointer key)
f0d936c0 351{
a56a1ba4 352 g_free(key);
fa2c4dbe 353}
354
4c69e0cc 355void destroy_hash_data(gpointer data)
fa2c4dbe 356{
a56a1ba4 357 g_free(data);
fa2c4dbe 358}
359
ba90bc77 360int processlist_add( ProcessList *process_list,
a56a1ba4 361 guint pid,
362 LttTime *birth,
d0cd7f09 363 guint trace_num,
a56a1ba4 364 gchar *name,
365 guint *height,
f5d980bf 366 HashedProcessData **pm_hashed_process_data)
fa2c4dbe 367{
a56a1ba4 368 GtkTreeIter iter ;
369 ProcessInfo *Process_Info = g_new(ProcessInfo, 1);
14963be0 370 HashedProcessData *hashed_process_data = g_new(HashedProcessData, 1);
f5d980bf 371 *pm_hashed_process_data = hashed_process_data;
a56a1ba4 372
373 Process_Info->pid = pid;
374 Process_Info->birth = *birth;
d0cd7f09 375 Process_Info->trace_num = trace_num;
a56a1ba4 376
14963be0 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;
a56a1ba4 421
422 /* Add a new row to the model */
f5d980bf 423 gtk_list_store_append ( process_list->list_store, &iter);
a56a1ba4 424 //g_critical ( "iter before : %s", gtk_tree_path_to_string (
425 // gtk_tree_model_get_path (
f5d980bf 426 // GTK_TREE_MODEL(process_list->list_store),
a56a1ba4 427 // &iter)));
f5d980bf 428 gtk_list_store_set ( process_list->list_store, &iter,
a56a1ba4 429 PROCESS_COLUMN, name,
430 PID_COLUMN, pid,
431 BIRTH_S_COLUMN, birth->tv_sec,
432 BIRTH_NS_COLUMN, birth->tv_nsec,
d0cd7f09 433 TRACE_COLUMN, trace_num,
a56a1ba4 434 -1);
f5d980bf 435 hashed_process_data->row_ref = gtk_tree_row_reference_new (
436 GTK_TREE_MODEL(process_list->list_store),
a56a1ba4 437 gtk_tree_model_get_path(
f5d980bf 438 GTK_TREE_MODEL(process_list->list_store),
a56a1ba4 439 &iter));
14963be0 440 g_hash_table_insert( process_list->process_hash,
a56a1ba4 441 (gpointer)Process_Info,
14963be0 442 (gpointer)hashed_process_data);
a56a1ba4 443
444 //g_critical ( "iter after : %s", gtk_tree_path_to_string (
445 // gtk_tree_model_get_path (
f5d980bf 446 // GTK_TREE_MODEL(process_list->list_store),
a56a1ba4 447 // &iter)));
ba90bc77 448 process_list->number_of_process++;
a56a1ba4 449
f5d980bf 450 *height = get_cell_height(GTK_TREE_VIEW(process_list->process_list_widget))
ba90bc77 451 * process_list->number_of_process ;
a56a1ba4 452
453
454 return 0;
455
f0d936c0 456}
457
ba90bc77 458int processlist_remove( ProcessList *process_list,
a56a1ba4 459 guint pid,
d0cd7f09 460 LttTime *birth,
461 guint trace_num)
f0d936c0 462{
a56a1ba4 463 ProcessInfo Process_Info;
464 gint *path_indices;
14963be0 465 HashedProcessData *hashed_process_data;
a56a1ba4 466 GtkTreeIter iter;
467
468 Process_Info.pid = pid;
469 Process_Info.birth = *birth;
d0cd7f09 470 Process_Info.trace_num = trace_num;
a56a1ba4 471
472
14963be0 473 if(hashed_process_data =
a56a1ba4 474 (HashedProcessData*)g_hash_table_lookup(
14963be0 475 process_list->process_hash,
a56a1ba4 476 &Process_Info))
477 {
478 gtk_tree_model_get_iter (
f5d980bf 479 GTK_TREE_MODEL(process_list->list_store),
a56a1ba4 480 &iter,
481 gtk_tree_row_reference_get_path(
f5d980bf 482 (GtkTreeRowReference*)hashed_process_data->row_ref)
a56a1ba4 483 );
484
f5d980bf 485 gtk_list_store_remove (process_list->list_store, &iter);
a56a1ba4 486
14963be0 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);
503
504 g_hash_table_remove(process_list->process_hash,
a56a1ba4 505 &Process_Info);
506
ba90bc77 507 process_list->number_of_process--;
a56a1ba4 508
509 return 0;
510 } else {
511 return 1;
512 }
fa2c4dbe 513}
514
515
ba90bc77 516guint processlist_get_height(ProcessList *process_list)
fa2c4dbe 517{
f5d980bf 518 return get_cell_height(GTK_TREE_VIEW(process_list->process_list_widget))
ba90bc77 519 * process_list->number_of_process ;
f0d936c0 520}
fa2c4dbe 521
522
ba90bc77 523gint processlist_get_process_pixels( ProcessList *process_list,
d0cd7f09 524 guint pid, LttTime *birth, guint trace_num,
a56a1ba4 525 guint *y,
526 guint *height,
f5d980bf 527 HashedProcessData **pm_hashed_process_data)
fa2c4dbe 528{
a56a1ba4 529 ProcessInfo Process_Info;
530 gint *path_indices;
531 GtkTreePath *tree_path;
14963be0 532 HashedProcessData *hashed_process_data = NULL;
a56a1ba4 533
534 Process_Info.pid = pid;
535 Process_Info.birth = *birth;
d0cd7f09 536 Process_Info.trace_num = trace_num;
a56a1ba4 537
14963be0 538 if(hashed_process_data =
a56a1ba4 539 (HashedProcessData*)g_hash_table_lookup(
14963be0 540 process_list->process_hash,
a56a1ba4 541 &Process_Info))
542 {
543 tree_path = gtk_tree_row_reference_get_path(
f5d980bf 544 hashed_process_data->row_ref);
a56a1ba4 545 path_indices = gtk_tree_path_get_indices (tree_path);
546
547 *height = get_cell_height(
f5d980bf 548 GTK_TREE_VIEW(process_list->process_list_widget));
a56a1ba4 549 *y = *height * path_indices[0];
f5d980bf 550 *pm_hashed_process_data = hashed_process_data;
a56a1ba4 551 return 0;
552 } else {
f5d980bf 553 *pm_hashed_process_data = hashed_process_data;
a56a1ba4 554 return 1;
555 }
fa2c4dbe 556
fa2c4dbe 557}
8b90e648 558
559
ba90bc77 560gint processlist_get_pixels_from_data( ProcessList *process_list,
a56a1ba4 561 ProcessInfo *process_info,
14963be0 562 HashedProcessData *hashed_process_data,
a56a1ba4 563 guint *y,
564 guint *height)
8b90e648 565{
a56a1ba4 566 gint *path_indices;
567 GtkTreePath *tree_path;
8b90e648 568
a56a1ba4 569 tree_path = gtk_tree_row_reference_get_path(
f5d980bf 570 hashed_process_data->row_ref);
a56a1ba4 571 path_indices = gtk_tree_path_get_indices (tree_path);
8b90e648 572
a56a1ba4 573 *height = get_cell_height(
f5d980bf 574 GTK_TREE_VIEW(process_list->process_list_widget));
a56a1ba4 575 *y = *height * path_indices[0];
8b90e648 576
a56a1ba4 577 return 0;
8b90e648 578
579}
This page took 0.053714 seconds and 4 git commands to generate.