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