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