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