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