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 | |
a95bc95a |
35 | static guint get_cpu_number_from_name(GQuark name); |
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 | |
fa2c4dbe |
236 | guint hash_fct(gconstpointer key) |
237 | { |
a56a1ba4 |
238 | return ((ProcessInfo*)key)->pid; |
fa2c4dbe |
239 | } |
240 | |
241 | gboolean equ_fct(gconstpointer a, gconstpointer b) |
242 | { |
a95bc95a |
243 | const ProcessInfo *pa = (const ProcessInfo*)a; |
244 | const ProcessInfo *pb = (const ProcessInfo*)b; |
245 | |
246 | if(pa->pid != pb->pid) |
a56a1ba4 |
247 | return 0; |
a95bc95a |
248 | |
249 | if((pa->pid == 0 && (pa->cpu != pb->cpu))) |
a56a1ba4 |
250 | return 0; |
a56a1ba4 |
251 | |
a95bc95a |
252 | if(pa->birth.tv_sec != pb->birth.tv_sec) |
a56a1ba4 |
253 | return 0; |
a56a1ba4 |
254 | |
a95bc95a |
255 | if(pa->birth.tv_nsec != pb->birth.tv_nsec) |
256 | return 0; |
257 | |
258 | if(pa->trace_num != pb->trace_num) |
d0cd7f09 |
259 | return 0; |
260 | |
a56a1ba4 |
261 | return 1; |
fa2c4dbe |
262 | } |
263 | |
4c69e0cc |
264 | void destroy_hash_key(gpointer key); |
fa2c4dbe |
265 | |
4c69e0cc |
266 | void destroy_hash_data(gpointer data); |
fa2c4dbe |
267 | |
268 | |
269 | |
270 | |
4c69e0cc |
271 | ProcessList *processlist_construct(void) |
f0d936c0 |
272 | { |
a56a1ba4 |
273 | GtkTreeViewColumn *column; |
274 | GtkCellRenderer *renderer; |
275 | |
ba90bc77 |
276 | ProcessList* process_list = g_new(ProcessList,1); |
a56a1ba4 |
277 | |
ba90bc77 |
278 | process_list->number_of_process = 0; |
ad96f4a0 |
279 | process_list->cell_height_cache = -1; |
a56a1ba4 |
280 | |
281 | /* Create the Process list */ |
f5d980bf |
282 | process_list->list_store = gtk_list_store_new ( N_COLUMNS, |
a56a1ba4 |
283 | G_TYPE_STRING, |
284 | G_TYPE_UINT, |
e92eabaf |
285 | G_TYPE_UINT, |
a95bc95a |
286 | G_TYPE_UINT, |
a56a1ba4 |
287 | G_TYPE_ULONG, |
d0cd7f09 |
288 | G_TYPE_ULONG, |
a56a1ba4 |
289 | G_TYPE_ULONG); |
290 | |
291 | |
f5d980bf |
292 | process_list->process_list_widget = |
a56a1ba4 |
293 | gtk_tree_view_new_with_model |
f5d980bf |
294 | (GTK_TREE_MODEL (process_list->list_store)); |
f5d980bf |
295 | g_object_unref (G_OBJECT (process_list->list_store)); |
a56a1ba4 |
296 | |
297 | gtk_tree_sortable_set_sort_func( |
f5d980bf |
298 | GTK_TREE_SORTABLE(process_list->list_store), |
a56a1ba4 |
299 | PID_COLUMN, |
300 | process_sort_func, |
301 | NULL, |
302 | NULL); |
303 | |
304 | gtk_tree_sortable_set_sort_column_id( |
f5d980bf |
305 | GTK_TREE_SORTABLE(process_list->list_store), |
a56a1ba4 |
306 | PID_COLUMN, |
307 | GTK_SORT_ASCENDING); |
308 | |
14963be0 |
309 | process_list->process_hash = g_hash_table_new_full( |
a56a1ba4 |
310 | hash_fct, equ_fct, |
311 | destroy_hash_key, destroy_hash_data |
312 | ); |
313 | |
314 | |
315 | gtk_tree_view_set_headers_visible( |
3cb8b205 |
316 | GTK_TREE_VIEW(process_list->process_list_widget), TRUE); |
a56a1ba4 |
317 | |
318 | /* Create a column, associating the "text" attribute of the |
319 | * cell_renderer to the first column of the model */ |
320 | /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */ |
321 | renderer = gtk_cell_renderer_text_new (); |
322 | column = gtk_tree_view_column_new_with_attributes ( "Process", |
323 | renderer, |
324 | "text", |
325 | PROCESS_COLUMN, |
326 | NULL); |
327 | gtk_tree_view_column_set_alignment (column, 0.0); |
328 | gtk_tree_view_column_set_fixed_width (column, 45); |
329 | gtk_tree_view_append_column ( |
f5d980bf |
330 | GTK_TREE_VIEW (process_list->process_list_widget), column); |
b9a010a2 |
331 | |
332 | process_list->button = column->button; |
333 | |
a56a1ba4 |
334 | column = gtk_tree_view_column_new_with_attributes ( "PID", |
335 | renderer, |
336 | "text", |
337 | PID_COLUMN, |
338 | NULL); |
339 | gtk_tree_view_append_column ( |
f5d980bf |
340 | GTK_TREE_VIEW (process_list->process_list_widget), column); |
a56a1ba4 |
341 | |
e92eabaf |
342 | column = gtk_tree_view_column_new_with_attributes ( "PPID", |
343 | renderer, |
344 | "text", |
345 | PPID_COLUMN, |
346 | NULL); |
347 | gtk_tree_view_append_column ( |
348 | GTK_TREE_VIEW (process_list->process_list_widget), column); |
a95bc95a |
349 | |
350 | column = gtk_tree_view_column_new_with_attributes ( "CPU", |
351 | renderer, |
352 | "text", |
353 | CPU_COLUMN, |
354 | NULL); |
355 | gtk_tree_view_append_column ( |
356 | GTK_TREE_VIEW (process_list->process_list_widget), column); |
a56a1ba4 |
357 | |
358 | column = gtk_tree_view_column_new_with_attributes ( "Birth sec", |
359 | renderer, |
360 | "text", |
361 | BIRTH_S_COLUMN, |
362 | NULL); |
363 | gtk_tree_view_append_column ( |
f5d980bf |
364 | GTK_TREE_VIEW (process_list->process_list_widget), column); |
a56a1ba4 |
365 | |
366 | //gtk_tree_view_column_set_visible(column, 0); |
367 | // |
368 | column = gtk_tree_view_column_new_with_attributes ( "Birth nsec", |
369 | renderer, |
370 | "text", |
371 | BIRTH_NS_COLUMN, |
372 | NULL); |
373 | gtk_tree_view_append_column ( |
f5d980bf |
374 | GTK_TREE_VIEW (process_list->process_list_widget), column); |
a56a1ba4 |
375 | |
d0cd7f09 |
376 | column = gtk_tree_view_column_new_with_attributes ( "TRACE", |
377 | renderer, |
378 | "text", |
379 | TRACE_COLUMN, |
380 | NULL); |
381 | gtk_tree_view_append_column ( |
382 | GTK_TREE_VIEW (process_list->process_list_widget), column); |
383 | |
384 | |
a56a1ba4 |
385 | //gtk_tree_view_column_set_visible(column, 0); |
386 | |
387 | g_object_set_data_full( |
f5d980bf |
388 | G_OBJECT(process_list->process_list_widget), |
ba90bc77 |
389 | "process_list_Data", |
390 | process_list, |
a56a1ba4 |
391 | (GDestroyNotify)processlist_destroy); |
392 | |
ba90bc77 |
393 | return process_list; |
f0d936c0 |
394 | } |
b9a010a2 |
395 | |
ba90bc77 |
396 | void processlist_destroy(ProcessList *process_list) |
f0d936c0 |
397 | { |
b9a010a2 |
398 | g_debug("processlist_destroy %p", process_list); |
14963be0 |
399 | g_hash_table_destroy(process_list->process_hash); |
400 | process_list->process_hash = NULL; |
f0d936c0 |
401 | |
ba90bc77 |
402 | g_free(process_list); |
b9a010a2 |
403 | g_debug("processlist_destroy end"); |
404 | } |
405 | |
406 | static gboolean remove_hash_item(ProcessInfo *process_info, |
407 | HashedProcessData *hashed_process_data, |
408 | ProcessList *process_list) |
409 | { |
b9a010a2 |
410 | GtkTreeIter iter; |
411 | |
ad96f4a0 |
412 | iter = hashed_process_data->y_iter; |
b9a010a2 |
413 | |
414 | gtk_list_store_remove (process_list->list_store, &iter); |
415 | |
b9a010a2 |
416 | return TRUE; /* remove the element from the hash table */ |
f0d936c0 |
417 | } |
418 | |
b9a010a2 |
419 | void processlist_clear(ProcessList *process_list) |
420 | { |
421 | g_info("processlist_clear %p", process_list); |
422 | |
423 | g_hash_table_foreach_remove(process_list->process_hash, |
424 | (GHRFunc)remove_hash_item, |
425 | (gpointer)process_list); |
426 | process_list->number_of_process = 0; |
427 | } |
428 | |
429 | |
ba90bc77 |
430 | GtkWidget *processlist_get_widget(ProcessList *process_list) |
f0d936c0 |
431 | { |
f5d980bf |
432 | return process_list->process_list_widget; |
f0d936c0 |
433 | } |
434 | |
435 | |
436 | |
ad96f4a0 |
437 | __inline gint get_cell_height(ProcessList *process_list, GtkTreeView *tree_view) |
f0d936c0 |
438 | { |
ad96f4a0 |
439 | gint height = process_list->cell_height_cache; |
440 | if(height != -1) return height; |
441 | else { |
442 | GtkTreeViewColumn *Column = gtk_tree_view_get_column(tree_view, 0); |
a56a1ba4 |
443 | |
ad96f4a0 |
444 | gtk_tree_view_column_cell_get_size(Column, NULL, NULL, NULL, NULL, |
445 | &process_list->cell_height_cache); |
446 | } |
447 | |
a56a1ba4 |
448 | |
ad96f4a0 |
449 | return process_list->cell_height_cache; |
f0d936c0 |
450 | } |
451 | |
4c69e0cc |
452 | void destroy_hash_key(gpointer key) |
f0d936c0 |
453 | { |
a56a1ba4 |
454 | g_free(key); |
fa2c4dbe |
455 | } |
456 | |
4c69e0cc |
457 | void destroy_hash_data(gpointer data) |
fa2c4dbe |
458 | { |
a56a1ba4 |
459 | g_free(data); |
fa2c4dbe |
460 | } |
461 | |
ba90bc77 |
462 | int processlist_add( ProcessList *process_list, |
a56a1ba4 |
463 | guint pid, |
a95bc95a |
464 | guint cpu, |
e92eabaf |
465 | guint ppid, |
a56a1ba4 |
466 | LttTime *birth, |
d0cd7f09 |
467 | guint trace_num, |
51705146 |
468 | const gchar *name, |
a56a1ba4 |
469 | guint *height, |
f5d980bf |
470 | HashedProcessData **pm_hashed_process_data) |
fa2c4dbe |
471 | { |
a56a1ba4 |
472 | ProcessInfo *Process_Info = g_new(ProcessInfo, 1); |
14963be0 |
473 | HashedProcessData *hashed_process_data = g_new(HashedProcessData, 1); |
f5d980bf |
474 | *pm_hashed_process_data = hashed_process_data; |
a56a1ba4 |
475 | |
476 | Process_Info->pid = pid; |
a95bc95a |
477 | if(pid == 0) |
478 | Process_Info->cpu = cpu; |
479 | else |
480 | Process_Info->cpu = 0; |
e92eabaf |
481 | Process_Info->ppid = ppid; |
a56a1ba4 |
482 | Process_Info->birth = *birth; |
d0cd7f09 |
483 | Process_Info->trace_num = trace_num; |
b9a010a2 |
484 | |
485 | /* When we create it from before state update, we are sure that the |
486 | * last event occured before the beginning of the global area. |
487 | * |
488 | * If it is created after state update, this value (0) will be |
489 | * overriden by the new state before anything is drawn. |
490 | */ |
23093869 |
491 | hashed_process_data->x.over = 0; |
492 | hashed_process_data->x.middle = 0; |
493 | hashed_process_data->x.under = 0; |
a56a1ba4 |
494 | |
a56a1ba4 |
495 | /* Add a new row to the model */ |
ad96f4a0 |
496 | gtk_list_store_append ( process_list->list_store, |
497 | &hashed_process_data->y_iter); |
498 | |
499 | gtk_list_store_set ( process_list->list_store, &hashed_process_data->y_iter, |
a56a1ba4 |
500 | PROCESS_COLUMN, name, |
501 | PID_COLUMN, pid, |
e92eabaf |
502 | PPID_COLUMN, ppid, |
a95bc95a |
503 | CPU_COLUMN, get_cpu_number_from_name(cpu), |
a56a1ba4 |
504 | BIRTH_S_COLUMN, birth->tv_sec, |
505 | BIRTH_NS_COLUMN, birth->tv_nsec, |
d0cd7f09 |
506 | TRACE_COLUMN, trace_num, |
a56a1ba4 |
507 | -1); |
ad96f4a0 |
508 | #if 0 |
f5d980bf |
509 | hashed_process_data->row_ref = gtk_tree_row_reference_new ( |
510 | GTK_TREE_MODEL(process_list->list_store), |
a56a1ba4 |
511 | gtk_tree_model_get_path( |
f5d980bf |
512 | GTK_TREE_MODEL(process_list->list_store), |
a56a1ba4 |
513 | &iter)); |
ad96f4a0 |
514 | #endif //0 |
a95bc95a |
515 | g_hash_table_insert(process_list->process_hash, |
a56a1ba4 |
516 | (gpointer)Process_Info, |
14963be0 |
517 | (gpointer)hashed_process_data); |
a56a1ba4 |
518 | |
519 | //g_critical ( "iter after : %s", gtk_tree_path_to_string ( |
520 | // gtk_tree_model_get_path ( |
f5d980bf |
521 | // GTK_TREE_MODEL(process_list->list_store), |
a56a1ba4 |
522 | // &iter))); |
ba90bc77 |
523 | process_list->number_of_process++; |
a56a1ba4 |
524 | |
ad96f4a0 |
525 | *height = get_cell_height(process_list, |
526 | GTK_TREE_VIEW(process_list->process_list_widget)) |
ba90bc77 |
527 | * process_list->number_of_process ; |
a56a1ba4 |
528 | |
a56a1ba4 |
529 | return 0; |
f0d936c0 |
530 | } |
531 | |
ba90bc77 |
532 | int processlist_remove( ProcessList *process_list, |
a56a1ba4 |
533 | guint pid, |
a95bc95a |
534 | guint cpu, |
d0cd7f09 |
535 | LttTime *birth, |
536 | guint trace_num) |
f0d936c0 |
537 | { |
a56a1ba4 |
538 | ProcessInfo Process_Info; |
539 | gint *path_indices; |
14963be0 |
540 | HashedProcessData *hashed_process_data; |
a56a1ba4 |
541 | GtkTreeIter iter; |
542 | |
543 | Process_Info.pid = pid; |
a95bc95a |
544 | Process_Info.cpu = cpu; |
a56a1ba4 |
545 | Process_Info.birth = *birth; |
d0cd7f09 |
546 | Process_Info.trace_num = trace_num; |
a56a1ba4 |
547 | |
548 | |
14963be0 |
549 | if(hashed_process_data = |
a56a1ba4 |
550 | (HashedProcessData*)g_hash_table_lookup( |
14963be0 |
551 | process_list->process_hash, |
a56a1ba4 |
552 | &Process_Info)) |
553 | { |
ad96f4a0 |
554 | iter = hashed_process_data->y_iter; |
a56a1ba4 |
555 | |
f5d980bf |
556 | gtk_list_store_remove (process_list->list_store, &iter); |
e800cf84 |
557 | |
14963be0 |
558 | g_hash_table_remove(process_list->process_hash, |
a56a1ba4 |
559 | &Process_Info); |
560 | |
ba90bc77 |
561 | process_list->number_of_process--; |
a56a1ba4 |
562 | |
563 | return 0; |
564 | } else { |
565 | return 1; |
566 | } |
fa2c4dbe |
567 | } |
568 | |
569 | |
ba90bc77 |
570 | guint processlist_get_height(ProcessList *process_list) |
fa2c4dbe |
571 | { |
ad96f4a0 |
572 | return get_cell_height(process_list, |
573 | GTK_TREE_VIEW(process_list->process_list_widget)) |
ba90bc77 |
574 | * process_list->number_of_process ; |
f0d936c0 |
575 | } |
fa2c4dbe |
576 | |
577 | |
ba90bc77 |
578 | gint processlist_get_process_pixels( ProcessList *process_list, |
a95bc95a |
579 | guint pid, guint cpu, LttTime *birth, guint trace_num, |
a56a1ba4 |
580 | guint *y, |
581 | guint *height, |
f5d980bf |
582 | HashedProcessData **pm_hashed_process_data) |
fa2c4dbe |
583 | { |
a56a1ba4 |
584 | ProcessInfo Process_Info; |
585 | gint *path_indices; |
586 | GtkTreePath *tree_path; |
14963be0 |
587 | HashedProcessData *hashed_process_data = NULL; |
a56a1ba4 |
588 | |
589 | Process_Info.pid = pid; |
a95bc95a |
590 | Process_Info.cpu = cpu; |
a56a1ba4 |
591 | Process_Info.birth = *birth; |
d0cd7f09 |
592 | Process_Info.trace_num = trace_num; |
a56a1ba4 |
593 | |
14963be0 |
594 | if(hashed_process_data = |
a56a1ba4 |
595 | (HashedProcessData*)g_hash_table_lookup( |
14963be0 |
596 | process_list->process_hash, |
a56a1ba4 |
597 | &Process_Info)) |
598 | { |
ad96f4a0 |
599 | tree_path = gtk_tree_model_get_path( |
600 | GTK_TREE_MODEL(process_list->list_store), |
601 | &hashed_process_data->y_iter); |
a56a1ba4 |
602 | path_indices = gtk_tree_path_get_indices (tree_path); |
603 | |
ad96f4a0 |
604 | *height = get_cell_height(process_list, |
f5d980bf |
605 | GTK_TREE_VIEW(process_list->process_list_widget)); |
a56a1ba4 |
606 | *y = *height * path_indices[0]; |
f5d980bf |
607 | *pm_hashed_process_data = hashed_process_data; |
51705146 |
608 | gtk_tree_path_free(tree_path); |
609 | |
a56a1ba4 |
610 | return 0; |
611 | } else { |
f5d980bf |
612 | *pm_hashed_process_data = hashed_process_data; |
a56a1ba4 |
613 | return 1; |
614 | } |
fa2c4dbe |
615 | |
fa2c4dbe |
616 | } |
8b90e648 |
617 | |
618 | |
ba90bc77 |
619 | gint processlist_get_pixels_from_data( ProcessList *process_list, |
a56a1ba4 |
620 | ProcessInfo *process_info, |
14963be0 |
621 | HashedProcessData *hashed_process_data, |
a56a1ba4 |
622 | guint *y, |
623 | guint *height) |
8b90e648 |
624 | { |
a56a1ba4 |
625 | gint *path_indices; |
626 | GtkTreePath *tree_path; |
8b90e648 |
627 | |
ad96f4a0 |
628 | tree_path = gtk_tree_model_get_path(GTK_TREE_MODEL(process_list->list_store), |
629 | &hashed_process_data->y_iter); |
a56a1ba4 |
630 | path_indices = gtk_tree_path_get_indices (tree_path); |
8b90e648 |
631 | |
ad96f4a0 |
632 | *height = get_cell_height(process_list, |
f5d980bf |
633 | GTK_TREE_VIEW(process_list->process_list_widget)); |
a56a1ba4 |
634 | *y = *height * path_indices[0]; |
51705146 |
635 | gtk_tree_path_free(tree_path); |
8b90e648 |
636 | |
a56a1ba4 |
637 | return 0; |
8b90e648 |
638 | |
639 | } |
a95bc95a |
640 | |
641 | static guint get_cpu_number_from_name(GQuark name) |
642 | { |
643 | /* remember / */ |
644 | const gchar *string; |
645 | char *begin; |
646 | guint cpu; |
647 | |
648 | string = g_quark_to_string(name); |
649 | |
650 | begin = strrchr(string, '/'); |
651 | begin++; |
652 | |
653 | g_assert(begin != '\0'); |
654 | |
655 | cpu = strtoul(begin, NULL, 10); |
656 | |
657 | return cpu; |
658 | } |
659 | |