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