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