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