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 | |
4e4d11b3 |
19 | #ifdef HAVE_CONFIG_H |
20 | #include <config.h> |
21 | #endif |
22 | |
fa2c4dbe |
23 | #include <gtk/gtk.h> |
6871f7d1 |
24 | #include <gdk/gdk.h> |
fa2c4dbe |
25 | #include <glib.h> |
a95bc95a |
26 | #include <string.h> |
27 | #include <stdlib.h> |
1c736ed5 |
28 | #include <math.h> |
d66666fe |
29 | |
30 | #include "processlist.h" |
1c736ed5 |
31 | #include "drawing.h" |
d66666fe |
32 | #include "drawitem.h" |
fa2c4dbe |
33 | |
ca0f8a8e |
34 | #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format) |
35 | #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format) |
36 | |
1c736ed5 |
37 | /* Preallocated Size of the index_to_pixmap array */ |
38 | #define ALLOCATE_PROCESSES 1000 |
ca0f8a8e |
39 | |
f0d936c0 |
40 | /***************************************************************************** |
41 | * Methods to synchronize process list * |
42 | *****************************************************************************/ |
43 | |
f0d936c0 |
44 | |
a56a1ba4 |
45 | gint process_sort_func ( GtkTreeModel *model, |
46 | GtkTreeIter *it_a, |
47 | GtkTreeIter *it_b, |
48 | gpointer user_data) |
fa2c4dbe |
49 | { |
117986b7 |
50 | gchar *a_name; |
51 | guint a_pid, a_ppid, a_cpu; |
52 | gulong a_birth_s, a_birth_ns; |
53 | gulong a_trace; |
54 | |
55 | gchar *b_name; |
56 | guint b_pid, b_ppid, b_cpu; |
57 | gulong b_birth_s, b_birth_ns; |
58 | gulong b_trace; |
59 | |
60 | gtk_tree_model_get(model, |
61 | it_a, |
62 | 0, &a_name, |
63 | 1, &a_pid, |
64 | 2, &a_ppid, |
65 | 3, &a_cpu, |
66 | 4, &a_birth_s, |
67 | 5, &a_birth_ns, |
68 | 6, &a_trace, |
69 | -1); |
70 | |
71 | gtk_tree_model_get(model, |
72 | it_b, |
73 | 0, &b_name, |
74 | 1, &b_pid, |
75 | 2, &b_ppid, |
76 | 3, &b_cpu, |
77 | 4, &b_birth_s, |
78 | 5, &b_birth_ns, |
79 | 6, &b_trace, |
80 | -1); |
a56a1ba4 |
81 | |
a56a1ba4 |
82 | |
83 | /* Order by PID */ |
117986b7 |
84 | if(a_pid == 0 && b_pid == 0) { |
85 | /* If 0, order by CPU */ |
86 | if(a_cpu > b_cpu) return 1; |
18e29396 |
87 | if(a_cpu < b_cpu) return -1; |
a56a1ba4 |
88 | |
117986b7 |
89 | } else { /* if not 0, order by pid */ |
a56a1ba4 |
90 | |
117986b7 |
91 | if(a_pid > b_pid) return 1; |
18e29396 |
92 | if(a_pid < b_pid) return -1; |
a56a1ba4 |
93 | } |
94 | |
a56a1ba4 |
95 | /* Order by birth second */ |
a56a1ba4 |
96 | |
117986b7 |
97 | if(a_birth_s > b_birth_s) return 1; |
18e29396 |
98 | if(a_birth_s < b_birth_s) return -1; |
117986b7 |
99 | |
a56a1ba4 |
100 | |
101 | /* Order by birth nanosecond */ |
117986b7 |
102 | if(a_birth_ns > b_birth_ns) return 1; |
18e29396 |
103 | if(a_birth_ns < b_birth_ns) return -1; |
a56a1ba4 |
104 | |
d0cd7f09 |
105 | /* Order by trace_num */ |
117986b7 |
106 | if(a_trace > b_trace) return 1; |
18e29396 |
107 | if(a_trace < b_trace) return -1; |
d0cd7f09 |
108 | |
a56a1ba4 |
109 | return 0; |
fa2c4dbe |
110 | |
111 | } |
112 | |
7893f726 |
113 | static guint process_list_hash_fct(gconstpointer key) |
fa2c4dbe |
114 | { |
2eef04b5 |
115 | guint pid = ((const ProcessInfo*)key)->pid; |
116 | return ((pid>>8 ^ pid>>4 ^ pid>>2 ^ pid) ^ ((const ProcessInfo*)key)->cpu); |
fa2c4dbe |
117 | } |
118 | |
1d1df11d |
119 | /* If hash is good, should be different */ |
7893f726 |
120 | static gboolean process_list_equ_fct(gconstpointer a, gconstpointer b) |
fa2c4dbe |
121 | { |
a95bc95a |
122 | const ProcessInfo *pa = (const ProcessInfo*)a; |
123 | const ProcessInfo *pb = (const ProcessInfo*)b; |
7893f726 |
124 | |
1d1df11d |
125 | gboolean ret = TRUE; |
126 | |
127 | if(likely(pa->pid != pb->pid)) |
128 | ret = FALSE; |
348c6ba8 |
129 | if(likely((pa->pid == 0 && (pa->cpu != pb->cpu)))) |
1d1df11d |
130 | ret = FALSE; |
348c6ba8 |
131 | if(unlikely(ltt_time_compare(pa->birth, pb->birth) != 0)) |
1d1df11d |
132 | ret = FALSE; |
348c6ba8 |
133 | if(unlikely(pa->trace_num != pb->trace_num)) |
1d1df11d |
134 | ret = FALSE; |
135 | |
136 | return ret; |
fa2c4dbe |
137 | } |
138 | |
4c69e0cc |
139 | void destroy_hash_key(gpointer key); |
fa2c4dbe |
140 | |
4c69e0cc |
141 | void destroy_hash_data(gpointer data); |
fa2c4dbe |
142 | |
143 | |
9d7e0c25 |
144 | gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer data) |
145 | { |
146 | ControlFlowData *control_flow_data = |
147 | (ControlFlowData*)g_object_get_data( |
148 | G_OBJECT(widget), |
149 | "control_flow_data"); |
150 | Drawing_t *drawing = control_flow_data->drawing; |
151 | unsigned int cell_height = |
152 | get_cell_height(GTK_TREE_VIEW(control_flow_data->process_list->process_list_widget)); |
153 | |
154 | switch(event->direction) { |
155 | case GDK_SCROLL_UP: |
156 | gtk_adjustment_set_value(control_flow_data->v_adjust, |
157 | gtk_adjustment_get_value(control_flow_data->v_adjust) - cell_height); |
158 | break; |
159 | case GDK_SCROLL_DOWN: |
160 | gtk_adjustment_set_value(control_flow_data->v_adjust, |
161 | gtk_adjustment_get_value(control_flow_data->v_adjust) + cell_height); |
162 | break; |
5e96e7e3 |
163 | default: |
164 | g_error("should only scroll up and down."); |
9d7e0c25 |
165 | } |
166 | return TRUE; |
167 | } |
168 | |
169 | |
1c736ed5 |
170 | static void update_index_to_pixmap_each(ProcessInfo *key, |
171 | HashedProcessData *value, |
172 | ProcessList *process_list) |
173 | { |
174 | guint array_index = processlist_get_index_from_data(process_list, value); |
175 | |
176 | g_assert(array_index < process_list->index_to_pixmap->len); |
177 | |
178 | GdkPixmap **pixmap = |
179 | (GdkPixmap**)&g_ptr_array_index(process_list->index_to_pixmap, array_index); |
180 | |
181 | *pixmap = value->pixmap; |
182 | } |
183 | |
184 | |
7c0125e0 |
185 | void update_index_to_pixmap(ProcessList *process_list) |
1c736ed5 |
186 | { |
187 | g_ptr_array_set_size(process_list->index_to_pixmap, |
188 | g_hash_table_size(process_list->process_hash)); |
189 | g_hash_table_foreach(process_list->process_hash, |
190 | (GHFunc)update_index_to_pixmap_each, |
191 | process_list); |
192 | } |
193 | |
194 | |
195 | static void update_pixmap_size_each(ProcessInfo *key, |
196 | HashedProcessData *value, |
197 | guint width) |
198 | { |
199 | GdkPixmap *old_pixmap = value->pixmap; |
200 | |
201 | value->pixmap = |
202 | gdk_pixmap_new(old_pixmap, |
203 | width, |
204 | value->height, |
205 | -1); |
206 | |
207 | gdk_pixmap_unref(old_pixmap); |
208 | } |
209 | |
210 | |
211 | void update_pixmap_size(ProcessList *process_list, guint width) |
212 | { |
213 | g_hash_table_foreach(process_list->process_hash, |
214 | (GHFunc)update_pixmap_size_each, |
215 | (gpointer)width); |
216 | } |
217 | |
218 | |
219 | typedef struct _CopyPixmap { |
220 | GdkDrawable *dest; |
221 | GdkGC *gc; |
222 | GdkDrawable *src; |
223 | gint xsrc, ysrc, xdest, ydest, width, height; |
224 | } CopyPixmap; |
225 | |
226 | static void copy_pixmap_region_each(ProcessInfo *key, |
227 | HashedProcessData *value, |
228 | CopyPixmap *cp) |
229 | { |
230 | GdkPixmap *src = cp->src; |
231 | GdkPixmap *dest = cp->dest; |
232 | |
233 | if(dest == NULL) |
234 | dest = value->pixmap; |
235 | if(src == NULL) |
236 | src = value->pixmap; |
237 | |
238 | gdk_draw_drawable (dest, |
239 | cp->gc, |
240 | src, |
241 | cp->xsrc, cp->ysrc, |
242 | cp->xdest, cp->ydest, |
243 | cp->width, cp->height); |
244 | } |
245 | |
246 | |
247 | |
248 | |
249 | void copy_pixmap_region(ProcessList *process_list, GdkDrawable *dest, |
250 | GdkGC *gc, GdkDrawable *src, |
251 | gint xsrc, gint ysrc, |
252 | gint xdest, gint ydest, gint width, gint height) |
253 | { |
254 | CopyPixmap cp = { dest, gc, src, xsrc, ysrc, xdest, ydest, width, height }; |
255 | |
256 | g_hash_table_foreach(process_list->process_hash, |
257 | (GHFunc)copy_pixmap_region_each, |
258 | &cp); |
259 | } |
260 | |
261 | |
262 | |
263 | typedef struct _RectanglePixmap { |
264 | gboolean filled; |
265 | gint x, y, width, height; |
266 | GdkGC *gc; |
267 | } RectanglePixmap; |
268 | |
269 | static void rectangle_pixmap_each(ProcessInfo *key, |
270 | HashedProcessData *value, |
271 | RectanglePixmap *rp) |
272 | { |
273 | if(rp->height == -1) |
274 | rp->height = value->height; |
275 | |
276 | gdk_draw_rectangle (value->pixmap, |
277 | rp->gc, |
278 | rp->filled, |
279 | rp->x, rp->y, |
280 | rp->width, rp->height); |
281 | } |
282 | |
283 | |
284 | |
285 | |
286 | void rectangle_pixmap(ProcessList *process_list, GdkGC *gc, |
287 | gboolean filled, gint x, gint y, gint width, gint height) |
288 | { |
289 | RectanglePixmap rp = { filled, x, y, width, height, gc }; |
290 | |
291 | g_hash_table_foreach(process_list->process_hash, |
292 | (GHFunc)rectangle_pixmap_each, |
293 | &rp); |
294 | } |
295 | |
296 | |
297 | /* Renders each pixmaps into on big drawable */ |
298 | void copy_pixmap_to_screen(ProcessList *process_list, |
299 | GdkDrawable *dest, |
300 | GdkGC *gc, |
301 | gint x, gint y, |
302 | gint width, gint height) |
303 | { |
866fefbd |
304 | if(process_list->index_to_pixmap->len == 0) return; |
305 | guint cell_height = process_list->cell_height; |
306 | |
1c736ed5 |
307 | /* Get indexes */ |
308 | gint begin = floor(y/(double)cell_height); |
309 | gint end = MIN(ceil((y+height)/(double)cell_height), |
310 | process_list->index_to_pixmap->len); |
311 | gint i; |
cc09b702 |
312 | |
1c736ed5 |
313 | for(i=begin; i<end; i++) { |
314 | g_assert(i<process_list->index_to_pixmap->len); |
315 | /* Render the pixmap to the screen */ |
316 | GdkPixmap *pixmap = |
6cec4cd2 |
317 | //(GdkPixmap*)g_ptr_array_index(process_list->index_to_pixmap, i); |
318 | GDK_PIXMAP(g_ptr_array_index(process_list->index_to_pixmap, i)); |
1c736ed5 |
319 | |
320 | gdk_draw_drawable (dest, |
321 | gc, |
322 | pixmap, |
323 | x, 0, |
324 | x, i*cell_height, |
325 | width, cell_height); |
326 | |
327 | } |
328 | |
329 | |
330 | } |
331 | |
332 | |
333 | |
334 | |
335 | |
336 | |
337 | |
fa2c4dbe |
338 | |
339 | |
4c69e0cc |
340 | ProcessList *processlist_construct(void) |
f0d936c0 |
341 | { |
a56a1ba4 |
342 | GtkTreeViewColumn *column; |
343 | GtkCellRenderer *renderer; |
344 | |
ba90bc77 |
345 | ProcessList* process_list = g_new(ProcessList,1); |
a56a1ba4 |
346 | |
ba90bc77 |
347 | process_list->number_of_process = 0; |
a56a1ba4 |
348 | |
4e86ae2e |
349 | process_list->current_hash_data = NULL; |
350 | |
a56a1ba4 |
351 | /* Create the Process list */ |
f5d980bf |
352 | process_list->list_store = gtk_list_store_new ( N_COLUMNS, |
a56a1ba4 |
353 | G_TYPE_STRING, |
354 | G_TYPE_UINT, |
e92eabaf |
355 | G_TYPE_UINT, |
a95bc95a |
356 | G_TYPE_UINT, |
a56a1ba4 |
357 | G_TYPE_ULONG, |
d0cd7f09 |
358 | G_TYPE_ULONG, |
a56a1ba4 |
359 | G_TYPE_ULONG); |
360 | |
361 | |
f5d980bf |
362 | process_list->process_list_widget = |
a56a1ba4 |
363 | gtk_tree_view_new_with_model |
f5d980bf |
364 | (GTK_TREE_MODEL (process_list->list_store)); |
f3b7430d |
365 | |
f5d980bf |
366 | g_object_unref (G_OBJECT (process_list->list_store)); |
a56a1ba4 |
367 | |
f3b7430d |
368 | gtk_tree_sortable_set_default_sort_func( |
f5d980bf |
369 | GTK_TREE_SORTABLE(process_list->list_store), |
a56a1ba4 |
370 | process_sort_func, |
371 | NULL, |
372 | NULL); |
80fdc3cb |
373 | |
374 | |
375 | gtk_tree_sortable_set_sort_column_id( |
376 | GTK_TREE_SORTABLE(process_list->list_store), |
377 | GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, |
378 | GTK_SORT_ASCENDING); |
379 | |
380 | |
14963be0 |
381 | process_list->process_hash = g_hash_table_new_full( |
7893f726 |
382 | process_list_hash_fct, process_list_equ_fct, |
a56a1ba4 |
383 | destroy_hash_key, destroy_hash_data |
384 | ); |
385 | |
386 | |
387 | gtk_tree_view_set_headers_visible( |
3cb8b205 |
388 | GTK_TREE_VIEW(process_list->process_list_widget), TRUE); |
a56a1ba4 |
389 | |
390 | /* Create a column, associating the "text" attribute of the |
391 | * cell_renderer to the first column of the model */ |
392 | /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */ |
393 | renderer = gtk_cell_renderer_text_new (); |
866fefbd |
394 | process_list->renderer = renderer; |
395 | |
6871f7d1 |
396 | gint vertical_separator; |
397 | gtk_widget_style_get (GTK_WIDGET (process_list->process_list_widget), |
398 | "vertical-separator", &vertical_separator, |
399 | NULL); |
866fefbd |
400 | gtk_cell_renderer_get_size(renderer, |
401 | GTK_WIDGET(process_list->process_list_widget), |
402 | NULL, |
403 | NULL, |
404 | NULL, |
405 | NULL, |
406 | &process_list->cell_height); |
6871f7d1 |
407 | |
c9b629ae |
408 | #if GTK_CHECK_VERSION(2,4,15) |
409 | guint ypad; |
410 | g_object_get(G_OBJECT(renderer), "ypad", &ypad, NULL); |
85690c4b |
411 | |
c9b629ae |
412 | process_list->cell_height += ypad; |
413 | #endif |
6871f7d1 |
414 | process_list->cell_height += vertical_separator; |
415 | |
416 | |
a56a1ba4 |
417 | column = gtk_tree_view_column_new_with_attributes ( "Process", |
418 | renderer, |
419 | "text", |
420 | PROCESS_COLUMN, |
421 | NULL); |
422 | gtk_tree_view_column_set_alignment (column, 0.0); |
423 | gtk_tree_view_column_set_fixed_width (column, 45); |
424 | gtk_tree_view_append_column ( |
f5d980bf |
425 | GTK_TREE_VIEW (process_list->process_list_widget), column); |
b9a010a2 |
426 | |
427 | process_list->button = column->button; |
428 | |
a56a1ba4 |
429 | column = gtk_tree_view_column_new_with_attributes ( "PID", |
430 | renderer, |
431 | "text", |
432 | PID_COLUMN, |
433 | NULL); |
434 | gtk_tree_view_append_column ( |
f5d980bf |
435 | GTK_TREE_VIEW (process_list->process_list_widget), column); |
a56a1ba4 |
436 | |
e92eabaf |
437 | column = gtk_tree_view_column_new_with_attributes ( "PPID", |
438 | renderer, |
439 | "text", |
440 | PPID_COLUMN, |
441 | NULL); |
442 | gtk_tree_view_append_column ( |
443 | GTK_TREE_VIEW (process_list->process_list_widget), column); |
a95bc95a |
444 | |
445 | column = gtk_tree_view_column_new_with_attributes ( "CPU", |
446 | renderer, |
447 | "text", |
448 | CPU_COLUMN, |
449 | NULL); |
450 | gtk_tree_view_append_column ( |
451 | GTK_TREE_VIEW (process_list->process_list_widget), column); |
a56a1ba4 |
452 | |
453 | column = gtk_tree_view_column_new_with_attributes ( "Birth sec", |
454 | renderer, |
455 | "text", |
456 | BIRTH_S_COLUMN, |
457 | NULL); |
458 | gtk_tree_view_append_column ( |
f5d980bf |
459 | GTK_TREE_VIEW (process_list->process_list_widget), column); |
a56a1ba4 |
460 | |
461 | //gtk_tree_view_column_set_visible(column, 0); |
462 | // |
463 | column = gtk_tree_view_column_new_with_attributes ( "Birth nsec", |
464 | renderer, |
465 | "text", |
466 | BIRTH_NS_COLUMN, |
467 | NULL); |
468 | gtk_tree_view_append_column ( |
f5d980bf |
469 | GTK_TREE_VIEW (process_list->process_list_widget), column); |
a56a1ba4 |
470 | |
d0cd7f09 |
471 | column = gtk_tree_view_column_new_with_attributes ( "TRACE", |
472 | renderer, |
473 | "text", |
474 | TRACE_COLUMN, |
475 | NULL); |
476 | gtk_tree_view_append_column ( |
477 | GTK_TREE_VIEW (process_list->process_list_widget), column); |
478 | |
479 | |
a56a1ba4 |
480 | //gtk_tree_view_column_set_visible(column, 0); |
481 | |
482 | g_object_set_data_full( |
f5d980bf |
483 | G_OBJECT(process_list->process_list_widget), |
ba90bc77 |
484 | "process_list_Data", |
485 | process_list, |
a56a1ba4 |
486 | (GDestroyNotify)processlist_destroy); |
487 | |
1c736ed5 |
488 | process_list->index_to_pixmap = g_ptr_array_sized_new(ALLOCATE_PROCESSES); |
489 | |
ba90bc77 |
490 | return process_list; |
f0d936c0 |
491 | } |
b9a010a2 |
492 | |
ba90bc77 |
493 | void processlist_destroy(ProcessList *process_list) |
f0d936c0 |
494 | { |
b9a010a2 |
495 | g_debug("processlist_destroy %p", process_list); |
14963be0 |
496 | g_hash_table_destroy(process_list->process_hash); |
497 | process_list->process_hash = NULL; |
1c736ed5 |
498 | g_ptr_array_free(process_list->index_to_pixmap, TRUE); |
f0d936c0 |
499 | |
ba90bc77 |
500 | g_free(process_list); |
b9a010a2 |
501 | g_debug("processlist_destroy end"); |
502 | } |
503 | |
504 | static gboolean remove_hash_item(ProcessInfo *process_info, |
505 | HashedProcessData *hashed_process_data, |
506 | ProcessList *process_list) |
507 | { |
b9a010a2 |
508 | GtkTreeIter iter; |
509 | |
ad96f4a0 |
510 | iter = hashed_process_data->y_iter; |
b9a010a2 |
511 | |
512 | gtk_list_store_remove (process_list->list_store, &iter); |
1c736ed5 |
513 | gdk_pixmap_unref(hashed_process_data->pixmap); |
b9a010a2 |
514 | |
1d1df11d |
515 | if(likely(process_list->current_hash_data != NULL)) { |
516 | if(likely(hashed_process_data == |
517 | process_list->current_hash_data[process_info->cpu])) |
d2d199a6 |
518 | process_list->current_hash_data[process_info->cpu] = NULL; |
519 | } |
b9a010a2 |
520 | return TRUE; /* remove the element from the hash table */ |
f0d936c0 |
521 | } |
522 | |
b9a010a2 |
523 | void processlist_clear(ProcessList *process_list) |
524 | { |
525 | g_info("processlist_clear %p", process_list); |
526 | |
527 | g_hash_table_foreach_remove(process_list->process_hash, |
528 | (GHRFunc)remove_hash_item, |
529 | (gpointer)process_list); |
530 | process_list->number_of_process = 0; |
1c736ed5 |
531 | update_index_to_pixmap(process_list); |
b9a010a2 |
532 | } |
533 | |
534 | |
ba90bc77 |
535 | GtkWidget *processlist_get_widget(ProcessList *process_list) |
f0d936c0 |
536 | { |
f5d980bf |
537 | return process_list->process_list_widget; |
f0d936c0 |
538 | } |
539 | |
540 | |
4c69e0cc |
541 | void destroy_hash_key(gpointer key) |
f0d936c0 |
542 | { |
a56a1ba4 |
543 | g_free(key); |
fa2c4dbe |
544 | } |
545 | |
4c69e0cc |
546 | void destroy_hash_data(gpointer data) |
fa2c4dbe |
547 | { |
a56a1ba4 |
548 | g_free(data); |
fa2c4dbe |
549 | } |
550 | |
f4b88a7d |
551 | |
552 | void processlist_set_name(ProcessList *process_list, |
553 | GQuark name, |
554 | HashedProcessData *hashed_process_data) |
555 | { |
556 | gtk_list_store_set ( process_list->list_store, &hashed_process_data->y_iter, |
557 | PROCESS_COLUMN, g_quark_to_string(name), |
558 | -1); |
559 | } |
560 | |
1fc7847f |
561 | void processlist_set_ppid(ProcessList *process_list, |
562 | guint ppid, |
563 | HashedProcessData *hashed_process_data) |
564 | { |
565 | gtk_list_store_set ( process_list->list_store, &hashed_process_data->y_iter, |
566 | PPID_COLUMN, ppid, |
567 | -1); |
568 | } |
569 | |
570 | |
ba90bc77 |
571 | int processlist_add( ProcessList *process_list, |
1c736ed5 |
572 | Drawing_t *drawing, |
a56a1ba4 |
573 | guint pid, |
a95bc95a |
574 | guint cpu, |
e92eabaf |
575 | guint ppid, |
a56a1ba4 |
576 | LttTime *birth, |
d0cd7f09 |
577 | guint trace_num, |
f4b88a7d |
578 | GQuark name, |
a56a1ba4 |
579 | guint *height, |
4e86ae2e |
580 | ProcessInfo **pm_process_info, |
f5d980bf |
581 | HashedProcessData **pm_hashed_process_data) |
fa2c4dbe |
582 | { |
a56a1ba4 |
583 | ProcessInfo *Process_Info = g_new(ProcessInfo, 1); |
14963be0 |
584 | HashedProcessData *hashed_process_data = g_new(HashedProcessData, 1); |
f5d980bf |
585 | *pm_hashed_process_data = hashed_process_data; |
4e86ae2e |
586 | *pm_process_info = Process_Info; |
a56a1ba4 |
587 | |
588 | Process_Info->pid = pid; |
a95bc95a |
589 | if(pid == 0) |
590 | Process_Info->cpu = cpu; |
591 | else |
592 | Process_Info->cpu = 0; |
e92eabaf |
593 | Process_Info->ppid = ppid; |
a56a1ba4 |
594 | Process_Info->birth = *birth; |
d0cd7f09 |
595 | Process_Info->trace_num = trace_num; |
b9a010a2 |
596 | |
597 | /* When we create it from before state update, we are sure that the |
598 | * last event occured before the beginning of the global area. |
599 | * |
600 | * If it is created after state update, this value (0) will be |
601 | * overriden by the new state before anything is drawn. |
602 | */ |
23093869 |
603 | hashed_process_data->x.over = 0; |
e72908ed |
604 | hashed_process_data->x.over_used = FALSE; |
b2743953 |
605 | hashed_process_data->x.over_marked = FALSE; |
23093869 |
606 | hashed_process_data->x.middle = 0; |
e72908ed |
607 | hashed_process_data->x.middle_used = FALSE; |
b2743953 |
608 | hashed_process_data->x.middle_marked = FALSE; |
23093869 |
609 | hashed_process_data->x.under = 0; |
e72908ed |
610 | hashed_process_data->x.under_used = FALSE; |
b2743953 |
611 | hashed_process_data->x.under_marked = FALSE; |
612 | hashed_process_data->next_good_time = ltt_time_zero; |
1c736ed5 |
613 | |
a56a1ba4 |
614 | /* Add a new row to the model */ |
ad96f4a0 |
615 | gtk_list_store_append ( process_list->list_store, |
616 | &hashed_process_data->y_iter); |
617 | |
618 | gtk_list_store_set ( process_list->list_store, &hashed_process_data->y_iter, |
f4b88a7d |
619 | PROCESS_COLUMN, g_quark_to_string(name), |
a56a1ba4 |
620 | PID_COLUMN, pid, |
e92eabaf |
621 | PPID_COLUMN, ppid, |
40debf7b |
622 | CPU_COLUMN, cpu, |
a56a1ba4 |
623 | BIRTH_S_COLUMN, birth->tv_sec, |
624 | BIRTH_NS_COLUMN, birth->tv_nsec, |
d0cd7f09 |
625 | TRACE_COLUMN, trace_num, |
a56a1ba4 |
626 | -1); |
866fefbd |
627 | //gtk_tree_view_set_model(GTK_TREE_VIEW(process_list->process_list_widget), |
628 | // GTK_TREE_MODEL(process_list->list_store)); |
629 | //gtk_container_resize_children(GTK_CONTAINER(process_list->process_list_widget)); |
630 | |
a95bc95a |
631 | g_hash_table_insert(process_list->process_hash, |
a56a1ba4 |
632 | (gpointer)Process_Info, |
14963be0 |
633 | (gpointer)hashed_process_data); |
a56a1ba4 |
634 | |
ba90bc77 |
635 | process_list->number_of_process++; |
a56a1ba4 |
636 | |
866fefbd |
637 | hashed_process_data->height = process_list->cell_height; |
638 | |
1c736ed5 |
639 | g_assert(hashed_process_data->height != 0); |
640 | |
641 | *height = hashed_process_data->height * process_list->number_of_process; |
642 | |
643 | hashed_process_data->pixmap = |
644 | gdk_pixmap_new(drawing->drawing_area->window, |
645 | drawing->alloc_width, |
646 | hashed_process_data->height, |
647 | -1); |
a56a1ba4 |
648 | |
1c736ed5 |
649 | // Clear the image |
650 | gdk_draw_rectangle (hashed_process_data->pixmap, |
651 | drawing->drawing_area->style->black_gc, |
652 | TRUE, |
653 | 0, 0, |
654 | drawing->alloc_width, |
655 | hashed_process_data->height); |
656 | |
657 | update_index_to_pixmap(process_list); |
658 | |
659 | |
a56a1ba4 |
660 | return 0; |
f0d936c0 |
661 | } |
662 | |
ba90bc77 |
663 | int processlist_remove( ProcessList *process_list, |
a56a1ba4 |
664 | guint pid, |
a95bc95a |
665 | guint cpu, |
d0cd7f09 |
666 | LttTime *birth, |
667 | guint trace_num) |
f0d936c0 |
668 | { |
4e86ae2e |
669 | ProcessInfo process_info; |
14963be0 |
670 | HashedProcessData *hashed_process_data; |
a56a1ba4 |
671 | GtkTreeIter iter; |
672 | |
4e86ae2e |
673 | process_info.pid = pid; |
324cdea4 |
674 | if(pid == 0) |
4e86ae2e |
675 | process_info.cpu = cpu; |
324cdea4 |
676 | else |
4e86ae2e |
677 | process_info.cpu = 0; |
678 | process_info.birth = *birth; |
679 | process_info.trace_num = trace_num; |
a56a1ba4 |
680 | |
681 | |
1d1df11d |
682 | hashed_process_data = |
a56a1ba4 |
683 | (HashedProcessData*)g_hash_table_lookup( |
14963be0 |
684 | process_list->process_hash, |
1d1df11d |
685 | &process_info); |
686 | if(likely(hashed_process_data != NULL)) |
a56a1ba4 |
687 | { |
ad96f4a0 |
688 | iter = hashed_process_data->y_iter; |
a56a1ba4 |
689 | |
f5d980bf |
690 | gtk_list_store_remove (process_list->list_store, &iter); |
e800cf84 |
691 | |
14963be0 |
692 | g_hash_table_remove(process_list->process_hash, |
4e86ae2e |
693 | &process_info); |
694 | |
1d1df11d |
695 | if(likely(process_list->current_hash_data != NULL)) { |
696 | if(likely(hashed_process_data == process_list->current_hash_data[cpu])) { |
0e9000a1 |
697 | process_list->current_hash_data[cpu] = NULL; |
698 | } |
4e86ae2e |
699 | } |
1c736ed5 |
700 | |
701 | gdk_pixmap_unref(hashed_process_data->pixmap); |
702 | |
703 | update_index_to_pixmap(process_list); |
704 | |
ba90bc77 |
705 | process_list->number_of_process--; |
a56a1ba4 |
706 | |
707 | return 0; |
708 | } else { |
709 | return 1; |
710 | } |
fa2c4dbe |
711 | } |
712 | |
713 | |
40debf7b |
714 | #if 0 |
6550d711 |
715 | static inline guint get_cpu_number_from_name(GQuark name) |
a95bc95a |
716 | { |
a95bc95a |
717 | const gchar *string; |
718 | char *begin; |
719 | guint cpu; |
720 | |
721 | string = g_quark_to_string(name); |
722 | |
723 | begin = strrchr(string, '/'); |
724 | begin++; |
725 | |
726 | g_assert(begin != '\0'); |
727 | |
728 | cpu = strtoul(begin, NULL, 10); |
729 | |
730 | return cpu; |
731 | } |
40debf7b |
732 | #endif //0 |