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