module name change oops
[lttv.git] / ltt / branches / poly / lttv / modules / gui / controlflow / processlist.c
CommitLineData
f0d936c0 1
fa2c4dbe 2#include <gtk/gtk.h>
3#include <glib.h>
d66666fe 4
5#include "processlist.h"
6#include "drawitem.h"
fa2c4dbe 7
f0d936c0 8/*****************************************************************************
9 * Methods to synchronize process list *
10 *****************************************************************************/
11
f0d936c0 12/* Enumeration of the columns */
13enum
14{
a56a1ba4 15 PROCESS_COLUMN,
16 PID_COLUMN,
17 BIRTH_S_COLUMN,
18 BIRTH_NS_COLUMN,
19 N_COLUMNS
f0d936c0 20};
21
22
a56a1ba4 23gint process_sort_func ( GtkTreeModel *model,
24 GtkTreeIter *it_a,
25 GtkTreeIter *it_b,
26 gpointer user_data)
fa2c4dbe 27{
a56a1ba4 28 GValue a, b;
29
30 memset(&a, 0, sizeof(GValue));
31 memset(&b, 0, sizeof(GValue));
32
33 /* Order by PID */
34 gtk_tree_model_get_value( model,
35 it_a,
36 PID_COLUMN,
37 &a);
38
39 gtk_tree_model_get_value( model,
40 it_b,
41 PID_COLUMN,
42 &b);
43
44 if(G_VALUE_TYPE(&a) == G_TYPE_UINT
45 && G_VALUE_TYPE(&b) == G_TYPE_UINT )
46 {
47 if(g_value_get_uint(&a) > g_value_get_uint(&b))
48 {
49 g_value_unset(&a);
50 g_value_unset(&b);
51 return 1;
52 }
53 if(g_value_get_uint(&a) < g_value_get_uint(&b))
54 {
55 g_value_unset(&a);
56 g_value_unset(&b);
57 return 0;
58 }
59 }
60
61 g_value_unset(&a);
62 g_value_unset(&b);
63
64
65 /* Order by birth second */
66 gtk_tree_model_get_value( model,
67 it_a,
68 BIRTH_S_COLUMN,
69 &a);
70
71 gtk_tree_model_get_value( model,
72 it_b,
73 BIRTH_S_COLUMN,
74 &b);
75
76
77 if(G_VALUE_TYPE(&a) == G_TYPE_ULONG
78 && G_VALUE_TYPE(&b) == G_TYPE_ULONG )
79 {
80 if(g_value_get_ulong(&a) > g_value_get_ulong(&b))
81 {
82 g_value_unset(&a);
83 g_value_unset(&b);
84 return 1;
85 }
86 if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
87 {
88 g_value_unset(&a);
89 g_value_unset(&b);
90 return 0;
91 }
92
93 }
94
95 g_value_unset(&a);
96 g_value_unset(&b);
97
98 /* Order by birth nanosecond */
99 gtk_tree_model_get_value( model,
100 it_a,
101 BIRTH_NS_COLUMN,
102 &a);
103
104 gtk_tree_model_get_value( model,
105 it_b,
106 BIRTH_NS_COLUMN,
107 &b);
108
109
110 if(G_VALUE_TYPE(&a) == G_TYPE_ULONG
111 && G_VALUE_TYPE(&b) == G_TYPE_ULONG )
112 {
113 if(g_value_get_ulong(&a) > g_value_get_ulong(&b))
114 {
115 g_value_unset(&a);
116 g_value_unset(&b);
117 return 1;
118 }
119 // Final condition
120 //if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
121 //{
122 // g_value_unset(&a);
123 // g_value_unset(&b);
124 // return 0;
125 //}
126
127 }
128
129 g_value_unset(&a);
130 g_value_unset(&b);
131
132 return 0;
fa2c4dbe 133
134}
135
fa2c4dbe 136guint hash_fct(gconstpointer key)
137{
a56a1ba4 138 return ((ProcessInfo*)key)->pid;
fa2c4dbe 139}
140
141gboolean equ_fct(gconstpointer a, gconstpointer b)
142{
a56a1ba4 143 if(((ProcessInfo*)a)->pid != ((ProcessInfo*)b)->pid)
144 return 0;
145// g_critical("compare %u and %u",((ProcessInfo*)a)->pid,((ProcessInfo*)b)->pid);
146 if(((ProcessInfo*)a)->birth.tv_sec != ((ProcessInfo*)b)->birth.tv_sec)
147 return 0;
148// g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_sec,((ProcessInfo*)b)->birth.tv_sec);
149
150 if(((ProcessInfo*)a)->birth.tv_nsec != ((ProcessInfo*)b)->birth.tv_nsec)
151 return 0;
152// g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_nsec,((ProcessInfo*)b)->birth.tv_nsec);
153
154 return 1;
fa2c4dbe 155}
156
4c69e0cc 157void destroy_hash_key(gpointer key);
fa2c4dbe 158
4c69e0cc 159void destroy_hash_data(gpointer data);
fa2c4dbe 160
161
162
163
4c69e0cc 164ProcessList *processlist_construct(void)
f0d936c0 165{
a56a1ba4 166 GtkTreeViewColumn *column;
167 GtkCellRenderer *renderer;
168
ba90bc77 169 ProcessList* process_list = g_new(ProcessList,1);
a56a1ba4 170
ba90bc77 171 process_list->number_of_process = 0;
a56a1ba4 172
173 /* Create the Process list */
f5d980bf 174 process_list->list_store = gtk_list_store_new ( N_COLUMNS,
a56a1ba4 175 G_TYPE_STRING,
176 G_TYPE_UINT,
177 G_TYPE_ULONG,
178 G_TYPE_ULONG);
179
180
f5d980bf 181 process_list->process_list_widget =
a56a1ba4 182 gtk_tree_view_new_with_model
f5d980bf 183 (GTK_TREE_MODEL (process_list->list_store));
a56a1ba4 184
f5d980bf 185 g_object_unref (G_OBJECT (process_list->list_store));
a56a1ba4 186
187 gtk_tree_sortable_set_sort_func(
f5d980bf 188 GTK_TREE_SORTABLE(process_list->list_store),
a56a1ba4 189 PID_COLUMN,
190 process_sort_func,
191 NULL,
192 NULL);
193
194 gtk_tree_sortable_set_sort_column_id(
f5d980bf 195 GTK_TREE_SORTABLE(process_list->list_store),
a56a1ba4 196 PID_COLUMN,
197 GTK_SORT_ASCENDING);
198
14963be0 199 process_list->process_hash = g_hash_table_new_full(
a56a1ba4 200 hash_fct, equ_fct,
201 destroy_hash_key, destroy_hash_data
202 );
203
204
205 gtk_tree_view_set_headers_visible(
f5d980bf 206 GTK_TREE_VIEW(process_list->process_list_widget), FALSE);
a56a1ba4 207
208 /* Create a column, associating the "text" attribute of the
209 * cell_renderer to the first column of the model */
210 /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */
211 renderer = gtk_cell_renderer_text_new ();
212 column = gtk_tree_view_column_new_with_attributes ( "Process",
213 renderer,
214 "text",
215 PROCESS_COLUMN,
216 NULL);
217 gtk_tree_view_column_set_alignment (column, 0.0);
218 gtk_tree_view_column_set_fixed_width (column, 45);
219 gtk_tree_view_append_column (
f5d980bf 220 GTK_TREE_VIEW (process_list->process_list_widget), column);
a56a1ba4 221
222 column = gtk_tree_view_column_new_with_attributes ( "PID",
223 renderer,
224 "text",
225 PID_COLUMN,
226 NULL);
227 gtk_tree_view_append_column (
f5d980bf 228 GTK_TREE_VIEW (process_list->process_list_widget), column);
a56a1ba4 229
230
231 column = gtk_tree_view_column_new_with_attributes ( "Birth sec",
232 renderer,
233 "text",
234 BIRTH_S_COLUMN,
235 NULL);
236 gtk_tree_view_append_column (
f5d980bf 237 GTK_TREE_VIEW (process_list->process_list_widget), column);
a56a1ba4 238
239 //gtk_tree_view_column_set_visible(column, 0);
240 //
241 column = gtk_tree_view_column_new_with_attributes ( "Birth nsec",
242 renderer,
243 "text",
244 BIRTH_NS_COLUMN,
245 NULL);
246 gtk_tree_view_append_column (
f5d980bf 247 GTK_TREE_VIEW (process_list->process_list_widget), column);
a56a1ba4 248
249 //gtk_tree_view_column_set_visible(column, 0);
250
251 g_object_set_data_full(
f5d980bf 252 G_OBJECT(process_list->process_list_widget),
ba90bc77 253 "process_list_Data",
254 process_list,
a56a1ba4 255 (GDestroyNotify)processlist_destroy);
256
ba90bc77 257 return process_list;
f0d936c0 258}
ba90bc77 259void processlist_destroy(ProcessList *process_list)
f0d936c0 260{
14963be0 261 g_hash_table_destroy(process_list->process_hash);
262 process_list->process_hash = NULL;
f0d936c0 263
ba90bc77 264 g_free(process_list);
f0d936c0 265}
266
ba90bc77 267GtkWidget *processlist_get_widget(ProcessList *process_list)
f0d936c0 268{
f5d980bf 269 return process_list->process_list_widget;
f0d936c0 270}
271
272
273
f5d980bf 274gint get_cell_height(GtkTreeView *tree_view)
f0d936c0 275{
a56a1ba4 276 gint height;
f5d980bf 277 GtkTreeViewColumn *Column = gtk_tree_view_get_column(tree_view, 0);
a56a1ba4 278 //GList *Render_List = gtk_tree_view_column_get_cell_renderers(Column);
279 //GtkCellRenderer *Renderer = g_list_first(Render_List)->data;
280
281 //g_list_free(Render_List);
282 gtk_tree_view_column_cell_get_size(Column, NULL, NULL, NULL, NULL, &height);
283 //g_critical("cell 0 height : %u",height);
284
285 return height;
f0d936c0 286}
287
4c69e0cc 288void destroy_hash_key(gpointer key)
f0d936c0 289{
a56a1ba4 290 g_free(key);
fa2c4dbe 291}
292
4c69e0cc 293void destroy_hash_data(gpointer data)
fa2c4dbe 294{
a56a1ba4 295 g_free(data);
fa2c4dbe 296}
297
ba90bc77 298int processlist_add( ProcessList *process_list,
a56a1ba4 299 guint pid,
300 LttTime *birth,
301 gchar *name,
302 guint *height,
f5d980bf 303 HashedProcessData **pm_hashed_process_data)
fa2c4dbe 304{
a56a1ba4 305 GtkTreeIter iter ;
306 ProcessInfo *Process_Info = g_new(ProcessInfo, 1);
14963be0 307 HashedProcessData *hashed_process_data = g_new(HashedProcessData, 1);
f5d980bf 308 *pm_hashed_process_data = hashed_process_data;
a56a1ba4 309
310 Process_Info->pid = pid;
311 Process_Info->birth = *birth;
312
14963be0 313 hashed_process_data->draw_context = g_new(DrawContext, 1);
314 hashed_process_data->draw_context->drawable = NULL;
315 hashed_process_data->draw_context->gc = NULL;
316 hashed_process_data->draw_context->pango_layout = NULL;
317 hashed_process_data->draw_context->current = g_new(DrawInfo,1);
318 hashed_process_data->draw_context->current->over = g_new(ItemInfo,1);
319 hashed_process_data->draw_context->current->over->x = -1;
320 hashed_process_data->draw_context->current->over->y = -1;
321 hashed_process_data->draw_context->current->middle = g_new(ItemInfo,1);
322 hashed_process_data->draw_context->current->middle->x = -1;
323 hashed_process_data->draw_context->current->middle->y = -1;
324 hashed_process_data->draw_context->current->under = g_new(ItemInfo,1);
325 hashed_process_data->draw_context->current->under->x = -1;
326 hashed_process_data->draw_context->current->under->y = -1;
327 hashed_process_data->draw_context->current->modify_over = g_new(ItemInfo,1);
328 hashed_process_data->draw_context->current->modify_over->x = -1;
329 hashed_process_data->draw_context->current->modify_over->y = -1;
330 hashed_process_data->draw_context->current->modify_middle = g_new(ItemInfo,1);
331 hashed_process_data->draw_context->current->modify_middle->x = -1;
332 hashed_process_data->draw_context->current->modify_middle->y = -1;
333 hashed_process_data->draw_context->current->modify_under = g_new(ItemInfo,1);
334 hashed_process_data->draw_context->current->modify_under->x = -1;
335 hashed_process_data->draw_context->current->modify_under->y = -1;
336 hashed_process_data->draw_context->current->status = LTTV_STATE_UNNAMED;
337 hashed_process_data->draw_context->previous = g_new(DrawInfo,1);
338 hashed_process_data->draw_context->previous->over = g_new(ItemInfo,1);
339 hashed_process_data->draw_context->previous->over->x = -1;
340 hashed_process_data->draw_context->previous->over->y = -1;
341 hashed_process_data->draw_context->previous->middle = g_new(ItemInfo,1);
342 hashed_process_data->draw_context->previous->middle->x = -1;
343 hashed_process_data->draw_context->previous->middle->y = -1;
344 hashed_process_data->draw_context->previous->under = g_new(ItemInfo,1);
345 hashed_process_data->draw_context->previous->under->x = -1;
346 hashed_process_data->draw_context->previous->under->y = -1;
347 hashed_process_data->draw_context->previous->modify_over = g_new(ItemInfo,1);
348 hashed_process_data->draw_context->previous->modify_over->x = -1;
349 hashed_process_data->draw_context->previous->modify_over->y = -1;
350 hashed_process_data->draw_context->previous->modify_middle = g_new(ItemInfo,1);
351 hashed_process_data->draw_context->previous->modify_middle->x = -1;
352 hashed_process_data->draw_context->previous->modify_middle->y = -1;
353 hashed_process_data->draw_context->previous->modify_under = g_new(ItemInfo,1);
354 hashed_process_data->draw_context->previous->modify_under->x = -1;
355 hashed_process_data->draw_context->previous->modify_under->y = -1;
356 hashed_process_data->draw_context->previous->status = LTTV_STATE_UNNAMED;
a56a1ba4 357
358 /* Add a new row to the model */
f5d980bf 359 gtk_list_store_append ( process_list->list_store, &iter);
a56a1ba4 360 //g_critical ( "iter before : %s", gtk_tree_path_to_string (
361 // gtk_tree_model_get_path (
f5d980bf 362 // GTK_TREE_MODEL(process_list->list_store),
a56a1ba4 363 // &iter)));
f5d980bf 364 gtk_list_store_set ( process_list->list_store, &iter,
a56a1ba4 365 PROCESS_COLUMN, name,
366 PID_COLUMN, pid,
367 BIRTH_S_COLUMN, birth->tv_sec,
368 BIRTH_NS_COLUMN, birth->tv_nsec,
369 -1);
f5d980bf 370 hashed_process_data->row_ref = gtk_tree_row_reference_new (
371 GTK_TREE_MODEL(process_list->list_store),
a56a1ba4 372 gtk_tree_model_get_path(
f5d980bf 373 GTK_TREE_MODEL(process_list->list_store),
a56a1ba4 374 &iter));
14963be0 375 g_hash_table_insert( process_list->process_hash,
a56a1ba4 376 (gpointer)Process_Info,
14963be0 377 (gpointer)hashed_process_data);
a56a1ba4 378
379 //g_critical ( "iter after : %s", gtk_tree_path_to_string (
380 // gtk_tree_model_get_path (
f5d980bf 381 // GTK_TREE_MODEL(process_list->list_store),
a56a1ba4 382 // &iter)));
ba90bc77 383 process_list->number_of_process++;
a56a1ba4 384
f5d980bf 385 *height = get_cell_height(GTK_TREE_VIEW(process_list->process_list_widget))
ba90bc77 386 * process_list->number_of_process ;
a56a1ba4 387
388
389 return 0;
390
f0d936c0 391}
392
ba90bc77 393int processlist_remove( ProcessList *process_list,
a56a1ba4 394 guint pid,
395 LttTime *birth)
f0d936c0 396{
a56a1ba4 397 ProcessInfo Process_Info;
398 gint *path_indices;
14963be0 399 HashedProcessData *hashed_process_data;
a56a1ba4 400 GtkTreeIter iter;
401
402 Process_Info.pid = pid;
403 Process_Info.birth = *birth;
404
405
14963be0 406 if(hashed_process_data =
a56a1ba4 407 (HashedProcessData*)g_hash_table_lookup(
14963be0 408 process_list->process_hash,
a56a1ba4 409 &Process_Info))
410 {
411 gtk_tree_model_get_iter (
f5d980bf 412 GTK_TREE_MODEL(process_list->list_store),
a56a1ba4 413 &iter,
414 gtk_tree_row_reference_get_path(
f5d980bf 415 (GtkTreeRowReference*)hashed_process_data->row_ref)
a56a1ba4 416 );
417
f5d980bf 418 gtk_list_store_remove (process_list->list_store, &iter);
a56a1ba4 419
14963be0 420 g_free(hashed_process_data->draw_context->previous->modify_under);
421 g_free(hashed_process_data->draw_context->previous->modify_middle);
422 g_free(hashed_process_data->draw_context->previous->modify_over);
423 g_free(hashed_process_data->draw_context->previous->under);
424 g_free(hashed_process_data->draw_context->previous->middle);
425 g_free(hashed_process_data->draw_context->previous->over);
426 g_free(hashed_process_data->draw_context->previous);
427 g_free(hashed_process_data->draw_context->current->modify_under);
428 g_free(hashed_process_data->draw_context->current->modify_middle);
429 g_free(hashed_process_data->draw_context->current->modify_over);
430 g_free(hashed_process_data->draw_context->current->under);
431 g_free(hashed_process_data->draw_context->current->middle);
432 g_free(hashed_process_data->draw_context->current->over);
433 g_free(hashed_process_data->draw_context->current);
434 g_free(hashed_process_data->draw_context);
435 g_free(hashed_process_data);
436
437 g_hash_table_remove(process_list->process_hash,
a56a1ba4 438 &Process_Info);
439
ba90bc77 440 process_list->number_of_process--;
a56a1ba4 441
442 return 0;
443 } else {
444 return 1;
445 }
fa2c4dbe 446}
447
448
ba90bc77 449guint processlist_get_height(ProcessList *process_list)
fa2c4dbe 450{
f5d980bf 451 return get_cell_height(GTK_TREE_VIEW(process_list->process_list_widget))
ba90bc77 452 * process_list->number_of_process ;
f0d936c0 453}
fa2c4dbe 454
455
ba90bc77 456gint processlist_get_process_pixels( ProcessList *process_list,
a56a1ba4 457 guint pid, LttTime *birth,
458 guint *y,
459 guint *height,
f5d980bf 460 HashedProcessData **pm_hashed_process_data)
fa2c4dbe 461{
a56a1ba4 462 ProcessInfo Process_Info;
463 gint *path_indices;
464 GtkTreePath *tree_path;
14963be0 465 HashedProcessData *hashed_process_data = NULL;
a56a1ba4 466
467 Process_Info.pid = pid;
468 Process_Info.birth = *birth;
469
14963be0 470 if(hashed_process_data =
a56a1ba4 471 (HashedProcessData*)g_hash_table_lookup(
14963be0 472 process_list->process_hash,
a56a1ba4 473 &Process_Info))
474 {
475 tree_path = gtk_tree_row_reference_get_path(
f5d980bf 476 hashed_process_data->row_ref);
a56a1ba4 477 path_indices = gtk_tree_path_get_indices (tree_path);
478
479 *height = get_cell_height(
f5d980bf 480 GTK_TREE_VIEW(process_list->process_list_widget));
a56a1ba4 481 *y = *height * path_indices[0];
f5d980bf 482 *pm_hashed_process_data = hashed_process_data;
a56a1ba4 483 return 0;
484 } else {
f5d980bf 485 *pm_hashed_process_data = hashed_process_data;
a56a1ba4 486 return 1;
487 }
fa2c4dbe 488
fa2c4dbe 489}
8b90e648 490
491
ba90bc77 492gint processlist_get_pixels_from_data( ProcessList *process_list,
a56a1ba4 493 ProcessInfo *process_info,
14963be0 494 HashedProcessData *hashed_process_data,
a56a1ba4 495 guint *y,
496 guint *height)
8b90e648 497{
a56a1ba4 498 gint *path_indices;
499 GtkTreePath *tree_path;
8b90e648 500
a56a1ba4 501 tree_path = gtk_tree_row_reference_get_path(
f5d980bf 502 hashed_process_data->row_ref);
a56a1ba4 503 path_indices = gtk_tree_path_get_indices (tree_path);
8b90e648 504
a56a1ba4 505 *height = get_cell_height(
f5d980bf 506 GTK_TREE_VIEW(process_list->process_list_widget));
a56a1ba4 507 *y = *height * path_indices[0];
8b90e648 508
a56a1ba4 509 return 0;
8b90e648 510
511}
This page took 0.050627 seconds and 4 git commands to generate.