git-svn-id: http://ltt.polymtl.ca/svn@462 04897980-b3bd-0310-b5e0-8ef037075253
[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,
36 N_COLUMNS
f0d936c0 37};
38
39
a56a1ba4 40gint process_sort_func ( GtkTreeModel *model,
41 GtkTreeIter *it_a,
42 GtkTreeIter *it_b,
43 gpointer user_data)
fa2c4dbe 44{
a56a1ba4 45 GValue a, b;
46
47 memset(&a, 0, sizeof(GValue));
48 memset(&b, 0, sizeof(GValue));
49
50 /* Order by PID */
51 gtk_tree_model_get_value( model,
52 it_a,
53 PID_COLUMN,
54 &a);
55
56 gtk_tree_model_get_value( model,
57 it_b,
58 PID_COLUMN,
59 &b);
60
61 if(G_VALUE_TYPE(&a) == G_TYPE_UINT
62 && G_VALUE_TYPE(&b) == G_TYPE_UINT )
63 {
64 if(g_value_get_uint(&a) > g_value_get_uint(&b))
65 {
66 g_value_unset(&a);
67 g_value_unset(&b);
68 return 1;
69 }
70 if(g_value_get_uint(&a) < g_value_get_uint(&b))
71 {
72 g_value_unset(&a);
73 g_value_unset(&b);
74 return 0;
75 }
76 }
77
78 g_value_unset(&a);
79 g_value_unset(&b);
80
81
82 /* Order by birth second */
83 gtk_tree_model_get_value( model,
84 it_a,
85 BIRTH_S_COLUMN,
86 &a);
87
88 gtk_tree_model_get_value( model,
89 it_b,
90 BIRTH_S_COLUMN,
91 &b);
92
93
94 if(G_VALUE_TYPE(&a) == G_TYPE_ULONG
95 && G_VALUE_TYPE(&b) == G_TYPE_ULONG )
96 {
97 if(g_value_get_ulong(&a) > g_value_get_ulong(&b))
98 {
99 g_value_unset(&a);
100 g_value_unset(&b);
101 return 1;
102 }
103 if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
104 {
105 g_value_unset(&a);
106 g_value_unset(&b);
107 return 0;
108 }
109
110 }
111
112 g_value_unset(&a);
113 g_value_unset(&b);
114
115 /* Order by birth nanosecond */
116 gtk_tree_model_get_value( model,
117 it_a,
118 BIRTH_NS_COLUMN,
119 &a);
120
121 gtk_tree_model_get_value( model,
122 it_b,
123 BIRTH_NS_COLUMN,
124 &b);
125
126
127 if(G_VALUE_TYPE(&a) == G_TYPE_ULONG
128 && G_VALUE_TYPE(&b) == G_TYPE_ULONG )
129 {
130 if(g_value_get_ulong(&a) > g_value_get_ulong(&b))
131 {
132 g_value_unset(&a);
133 g_value_unset(&b);
134 return 1;
135 }
136 // Final condition
137 //if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
138 //{
139 // g_value_unset(&a);
140 // g_value_unset(&b);
141 // return 0;
142 //}
143
144 }
145
146 g_value_unset(&a);
147 g_value_unset(&b);
148
149 return 0;
fa2c4dbe 150
151}
152
fa2c4dbe 153guint hash_fct(gconstpointer key)
154{
a56a1ba4 155 return ((ProcessInfo*)key)->pid;
fa2c4dbe 156}
157
158gboolean equ_fct(gconstpointer a, gconstpointer b)
159{
a56a1ba4 160 if(((ProcessInfo*)a)->pid != ((ProcessInfo*)b)->pid)
161 return 0;
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)
164 return 0;
165// g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_sec,((ProcessInfo*)b)->birth.tv_sec);
166
167 if(((ProcessInfo*)a)->birth.tv_nsec != ((ProcessInfo*)b)->birth.tv_nsec)
168 return 0;
169// g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_nsec,((ProcessInfo*)b)->birth.tv_nsec);
170
171 return 1;
fa2c4dbe 172}
173
4c69e0cc 174void destroy_hash_key(gpointer key);
fa2c4dbe 175
4c69e0cc 176void destroy_hash_data(gpointer data);
fa2c4dbe 177
178
179
180
4c69e0cc 181ProcessList *processlist_construct(void)
f0d936c0 182{
a56a1ba4 183 GtkTreeViewColumn *column;
184 GtkCellRenderer *renderer;
185
ba90bc77 186 ProcessList* process_list = g_new(ProcessList,1);
a56a1ba4 187
ba90bc77 188 process_list->number_of_process = 0;
a56a1ba4 189
190 /* Create the Process list */
f5d980bf 191 process_list->list_store = gtk_list_store_new ( N_COLUMNS,
a56a1ba4 192 G_TYPE_STRING,
193 G_TYPE_UINT,
194 G_TYPE_ULONG,
195 G_TYPE_ULONG);
196
197
f5d980bf 198 process_list->process_list_widget =
a56a1ba4 199 gtk_tree_view_new_with_model
f5d980bf 200 (GTK_TREE_MODEL (process_list->list_store));
a56a1ba4 201
f5d980bf 202 g_object_unref (G_OBJECT (process_list->list_store));
a56a1ba4 203
204 gtk_tree_sortable_set_sort_func(
f5d980bf 205 GTK_TREE_SORTABLE(process_list->list_store),
a56a1ba4 206 PID_COLUMN,
207 process_sort_func,
208 NULL,
209 NULL);
210
211 gtk_tree_sortable_set_sort_column_id(
f5d980bf 212 GTK_TREE_SORTABLE(process_list->list_store),
a56a1ba4 213 PID_COLUMN,
214 GTK_SORT_ASCENDING);
215
14963be0 216 process_list->process_hash = g_hash_table_new_full(
a56a1ba4 217 hash_fct, equ_fct,
218 destroy_hash_key, destroy_hash_data
219 );
220
221
222 gtk_tree_view_set_headers_visible(
f5d980bf 223 GTK_TREE_VIEW(process_list->process_list_widget), FALSE);
a56a1ba4 224
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",
230 renderer,
231 "text",
232 PROCESS_COLUMN,
233 NULL);
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 (
f5d980bf 237 GTK_TREE_VIEW (process_list->process_list_widget), column);
a56a1ba4 238
239 column = gtk_tree_view_column_new_with_attributes ( "PID",
240 renderer,
241 "text",
242 PID_COLUMN,
243 NULL);
244 gtk_tree_view_append_column (
f5d980bf 245 GTK_TREE_VIEW (process_list->process_list_widget), column);
a56a1ba4 246
247
248 column = gtk_tree_view_column_new_with_attributes ( "Birth sec",
249 renderer,
250 "text",
251 BIRTH_S_COLUMN,
252 NULL);
253 gtk_tree_view_append_column (
f5d980bf 254 GTK_TREE_VIEW (process_list->process_list_widget), column);
a56a1ba4 255
256 //gtk_tree_view_column_set_visible(column, 0);
257 //
258 column = gtk_tree_view_column_new_with_attributes ( "Birth nsec",
259 renderer,
260 "text",
261 BIRTH_NS_COLUMN,
262 NULL);
263 gtk_tree_view_append_column (
f5d980bf 264 GTK_TREE_VIEW (process_list->process_list_widget), column);
a56a1ba4 265
266 //gtk_tree_view_column_set_visible(column, 0);
267
268 g_object_set_data_full(
f5d980bf 269 G_OBJECT(process_list->process_list_widget),
ba90bc77 270 "process_list_Data",
271 process_list,
a56a1ba4 272 (GDestroyNotify)processlist_destroy);
273
ba90bc77 274 return process_list;
f0d936c0 275}
ba90bc77 276void processlist_destroy(ProcessList *process_list)
f0d936c0 277{
14963be0 278 g_hash_table_destroy(process_list->process_hash);
279 process_list->process_hash = NULL;
f0d936c0 280
ba90bc77 281 g_free(process_list);
f0d936c0 282}
283
ba90bc77 284GtkWidget *processlist_get_widget(ProcessList *process_list)
f0d936c0 285{
f5d980bf 286 return process_list->process_list_widget;
f0d936c0 287}
288
289
290
f5d980bf 291gint get_cell_height(GtkTreeView *tree_view)
f0d936c0 292{
a56a1ba4 293 gint height;
f5d980bf 294 GtkTreeViewColumn *Column = gtk_tree_view_get_column(tree_view, 0);
a56a1ba4 295 //GList *Render_List = gtk_tree_view_column_get_cell_renderers(Column);
296 //GtkCellRenderer *Renderer = g_list_first(Render_List)->data;
297
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);
301
302 return height;
f0d936c0 303}
304
4c69e0cc 305void destroy_hash_key(gpointer key)
f0d936c0 306{
a56a1ba4 307 g_free(key);
fa2c4dbe 308}
309
4c69e0cc 310void destroy_hash_data(gpointer data)
fa2c4dbe 311{
a56a1ba4 312 g_free(data);
fa2c4dbe 313}
314
ba90bc77 315int processlist_add( ProcessList *process_list,
a56a1ba4 316 guint pid,
317 LttTime *birth,
318 gchar *name,
319 guint *height,
f5d980bf 320 HashedProcessData **pm_hashed_process_data)
fa2c4dbe 321{
a56a1ba4 322 GtkTreeIter iter ;
323 ProcessInfo *Process_Info = g_new(ProcessInfo, 1);
14963be0 324 HashedProcessData *hashed_process_data = g_new(HashedProcessData, 1);
f5d980bf 325 *pm_hashed_process_data = hashed_process_data;
a56a1ba4 326
327 Process_Info->pid = pid;
328 Process_Info->birth = *birth;
329
14963be0 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;
a56a1ba4 374
375 /* Add a new row to the model */
f5d980bf 376 gtk_list_store_append ( process_list->list_store, &iter);
a56a1ba4 377 //g_critical ( "iter before : %s", gtk_tree_path_to_string (
378 // gtk_tree_model_get_path (
f5d980bf 379 // GTK_TREE_MODEL(process_list->list_store),
a56a1ba4 380 // &iter)));
f5d980bf 381 gtk_list_store_set ( process_list->list_store, &iter,
a56a1ba4 382 PROCESS_COLUMN, name,
383 PID_COLUMN, pid,
384 BIRTH_S_COLUMN, birth->tv_sec,
385 BIRTH_NS_COLUMN, birth->tv_nsec,
386 -1);
f5d980bf 387 hashed_process_data->row_ref = gtk_tree_row_reference_new (
388 GTK_TREE_MODEL(process_list->list_store),
a56a1ba4 389 gtk_tree_model_get_path(
f5d980bf 390 GTK_TREE_MODEL(process_list->list_store),
a56a1ba4 391 &iter));
14963be0 392 g_hash_table_insert( process_list->process_hash,
a56a1ba4 393 (gpointer)Process_Info,
14963be0 394 (gpointer)hashed_process_data);
a56a1ba4 395
396 //g_critical ( "iter after : %s", gtk_tree_path_to_string (
397 // gtk_tree_model_get_path (
f5d980bf 398 // GTK_TREE_MODEL(process_list->list_store),
a56a1ba4 399 // &iter)));
ba90bc77 400 process_list->number_of_process++;
a56a1ba4 401
f5d980bf 402 *height = get_cell_height(GTK_TREE_VIEW(process_list->process_list_widget))
ba90bc77 403 * process_list->number_of_process ;
a56a1ba4 404
405
406 return 0;
407
f0d936c0 408}
409
ba90bc77 410int processlist_remove( ProcessList *process_list,
a56a1ba4 411 guint pid,
412 LttTime *birth)
f0d936c0 413{
a56a1ba4 414 ProcessInfo Process_Info;
415 gint *path_indices;
14963be0 416 HashedProcessData *hashed_process_data;
a56a1ba4 417 GtkTreeIter iter;
418
419 Process_Info.pid = pid;
420 Process_Info.birth = *birth;
421
422
14963be0 423 if(hashed_process_data =
a56a1ba4 424 (HashedProcessData*)g_hash_table_lookup(
14963be0 425 process_list->process_hash,
a56a1ba4 426 &Process_Info))
427 {
428 gtk_tree_model_get_iter (
f5d980bf 429 GTK_TREE_MODEL(process_list->list_store),
a56a1ba4 430 &iter,
431 gtk_tree_row_reference_get_path(
f5d980bf 432 (GtkTreeRowReference*)hashed_process_data->row_ref)
a56a1ba4 433 );
434
f5d980bf 435 gtk_list_store_remove (process_list->list_store, &iter);
a56a1ba4 436
14963be0 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);
453
454 g_hash_table_remove(process_list->process_hash,
a56a1ba4 455 &Process_Info);
456
ba90bc77 457 process_list->number_of_process--;
a56a1ba4 458
459 return 0;
460 } else {
461 return 1;
462 }
fa2c4dbe 463}
464
465
ba90bc77 466guint processlist_get_height(ProcessList *process_list)
fa2c4dbe 467{
f5d980bf 468 return get_cell_height(GTK_TREE_VIEW(process_list->process_list_widget))
ba90bc77 469 * process_list->number_of_process ;
f0d936c0 470}
fa2c4dbe 471
472
ba90bc77 473gint processlist_get_process_pixels( ProcessList *process_list,
a56a1ba4 474 guint pid, LttTime *birth,
475 guint *y,
476 guint *height,
f5d980bf 477 HashedProcessData **pm_hashed_process_data)
fa2c4dbe 478{
a56a1ba4 479 ProcessInfo Process_Info;
480 gint *path_indices;
481 GtkTreePath *tree_path;
14963be0 482 HashedProcessData *hashed_process_data = NULL;
a56a1ba4 483
484 Process_Info.pid = pid;
485 Process_Info.birth = *birth;
486
14963be0 487 if(hashed_process_data =
a56a1ba4 488 (HashedProcessData*)g_hash_table_lookup(
14963be0 489 process_list->process_hash,
a56a1ba4 490 &Process_Info))
491 {
492 tree_path = gtk_tree_row_reference_get_path(
f5d980bf 493 hashed_process_data->row_ref);
a56a1ba4 494 path_indices = gtk_tree_path_get_indices (tree_path);
495
496 *height = get_cell_height(
f5d980bf 497 GTK_TREE_VIEW(process_list->process_list_widget));
a56a1ba4 498 *y = *height * path_indices[0];
f5d980bf 499 *pm_hashed_process_data = hashed_process_data;
a56a1ba4 500 return 0;
501 } else {
f5d980bf 502 *pm_hashed_process_data = hashed_process_data;
a56a1ba4 503 return 1;
504 }
fa2c4dbe 505
fa2c4dbe 506}
8b90e648 507
508
ba90bc77 509gint processlist_get_pixels_from_data( ProcessList *process_list,
a56a1ba4 510 ProcessInfo *process_info,
14963be0 511 HashedProcessData *hashed_process_data,
a56a1ba4 512 guint *y,
513 guint *height)
8b90e648 514{
a56a1ba4 515 gint *path_indices;
516 GtkTreePath *tree_path;
8b90e648 517
a56a1ba4 518 tree_path = gtk_tree_row_reference_get_path(
f5d980bf 519 hashed_process_data->row_ref);
a56a1ba4 520 path_indices = gtk_tree_path_get_indices (tree_path);
8b90e648 521
a56a1ba4 522 *height = get_cell_height(
f5d980bf 523 GTK_TREE_VIEW(process_list->process_list_widget));
a56a1ba4 524 *y = *height * path_indices[0];
8b90e648 525
a56a1ba4 526 return 0;
8b90e648 527
528}
This page took 0.050553 seconds and 4 git commands to generate.