| 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 | |
| 20 | /***************************************************************************** |
| 21 | * Hooks to be called by the main window * |
| 22 | *****************************************************************************/ |
| 23 | |
| 24 | |
| 25 | /* Event hooks are the drawing hooks called during traceset read. They draw the |
| 26 | * icons, text, lines and background color corresponding to the events read. |
| 27 | * |
| 28 | * Two hooks are used for drawing : before_schedchange and after_schedchange hooks. The |
| 29 | * before_schedchange is called before the state update that occurs with an event and |
| 30 | * the after_schedchange hook is called after this state update. |
| 31 | * |
| 32 | * The before_schedchange hooks fulfill the task of drawing the visible objects that |
| 33 | * corresponds to the data accumulated by the after_schedchange hook. |
| 34 | * |
| 35 | * The after_schedchange hook accumulates the data that need to be shown on the screen |
| 36 | * (items) into a queue. Then, the next before_schedchange hook will draw what that |
| 37 | * queue contains. That's the Right Way (TM) of drawing items on the screen, |
| 38 | * because we need to draw the background first (and then add icons, text, ... |
| 39 | * over it), but we only know the length of a background region once the state |
| 40 | * corresponding to it is over, which happens to be at the next before_schedchange |
| 41 | * hook. |
| 42 | * |
| 43 | * We also have a hook called at the end of a chunk to draw the information left |
| 44 | * undrawn in each process queue. We use the current time as end of |
| 45 | * line/background. |
| 46 | */ |
| 47 | |
| 48 | #ifdef HAVE_CONFIG_H |
| 49 | #include <config.h> |
| 50 | #endif |
| 51 | |
| 52 | //#define PANGO_ENABLE_BACKEND |
| 53 | #include <gtk/gtk.h> |
| 54 | #include <gdk/gdk.h> |
| 55 | #include <glib.h> |
| 56 | #include <assert.h> |
| 57 | #include <string.h> |
| 58 | #include <stdio.h> |
| 59 | |
| 60 | //#include <pango/pango.h> |
| 61 | |
| 62 | #include <ltt/event.h> |
| 63 | #include <ltt/time.h> |
| 64 | #include <ltt/type.h> |
| 65 | #include <ltt/trace.h> |
| 66 | |
| 67 | #include <lttv/lttv.h> |
| 68 | #include <lttv/hook.h> |
| 69 | #include <lttv/state.h> |
| 70 | #include <lttvwindow/lttvwindow.h> |
| 71 | #include <lttvwindow/lttvwindowtraces.h> |
| 72 | #include <lttvwindow/support.h> |
| 73 | |
| 74 | |
| 75 | #include "eventhooks.h" |
| 76 | #include "cfv.h" |
| 77 | #include "processlist.h" |
| 78 | #include "drawing.h" |
| 79 | |
| 80 | |
| 81 | #define MAX_PATH_LEN 256 |
| 82 | |
| 83 | extern GSList *g_legend_list; |
| 84 | |
| 85 | |
| 86 | /* Action to do when background computation completed. |
| 87 | * |
| 88 | * Wait for all the awaited computations to be over. |
| 89 | */ |
| 90 | |
| 91 | static gint background_ready(void *hook_data, void *call_data) |
| 92 | { |
| 93 | ControlFlowData *control_flow_data = (ControlFlowData *)hook_data; |
| 94 | LttvTrace *trace = (LttvTrace*)call_data; |
| 95 | |
| 96 | control_flow_data->background_info_waiting--; |
| 97 | |
| 98 | if(control_flow_data->background_info_waiting == 0) { |
| 99 | g_message("control flow viewer : background computation data ready."); |
| 100 | |
| 101 | drawing_clear(control_flow_data->drawing); |
| 102 | processlist_clear(control_flow_data->process_list); |
| 103 | gtk_widget_set_size_request( |
| 104 | control_flow_data->drawing->drawing_area, |
| 105 | -1, processlist_get_height(control_flow_data->process_list)); |
| 106 | redraw_notify(control_flow_data, NULL); |
| 107 | } |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | |
| 113 | /* Request background computation. Verify if it is in progress or ready first. |
| 114 | * Only for each trace in the tab's traceset. |
| 115 | */ |
| 116 | static void request_background_data(ControlFlowData *control_flow_data) |
| 117 | { |
| 118 | LttvTracesetContext * tsc = |
| 119 | lttvwindow_get_traceset_context(control_flow_data->tab); |
| 120 | gint num_traces = lttv_traceset_number(tsc->ts); |
| 121 | gint i; |
| 122 | LttvTrace *trace; |
| 123 | |
| 124 | LttvHooks *background_ready_hook = |
| 125 | lttv_hooks_new(); |
| 126 | lttv_hooks_add(background_ready_hook, background_ready, control_flow_data, |
| 127 | LTTV_PRIO_DEFAULT); |
| 128 | control_flow_data->background_info_waiting = 0; |
| 129 | |
| 130 | for(i=0;i<num_traces;i++) { |
| 131 | trace = lttv_traceset_get(tsc->ts, i); |
| 132 | |
| 133 | if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace)==FALSE) { |
| 134 | |
| 135 | if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"), |
| 136 | trace) == FALSE) { |
| 137 | /* We first remove requests that could have been done for the same |
| 138 | * information. Happens when two viewers ask for it before servicing |
| 139 | * starts. |
| 140 | */ |
| 141 | if(!lttvwindowtraces_background_request_find(trace, "state")) |
| 142 | lttvwindowtraces_background_request_queue( |
| 143 | main_window_get_widget(control_flow_data->tab), trace, "state"); |
| 144 | lttvwindowtraces_background_notify_queue(control_flow_data, |
| 145 | trace, |
| 146 | ltt_time_infinite, |
| 147 | NULL, |
| 148 | background_ready_hook); |
| 149 | control_flow_data->background_info_waiting++; |
| 150 | } else { /* in progress */ |
| 151 | |
| 152 | lttvwindowtraces_background_notify_current(control_flow_data, |
| 153 | trace, |
| 154 | ltt_time_infinite, |
| 155 | NULL, |
| 156 | background_ready_hook); |
| 157 | control_flow_data->background_info_waiting++; |
| 158 | } |
| 159 | } else { |
| 160 | /* Data ready. Be its nature, this viewer doesn't need to have |
| 161 | * its data ready hook called there, because a background |
| 162 | * request is always linked with a redraw. |
| 163 | */ |
| 164 | } |
| 165 | |
| 166 | } |
| 167 | |
| 168 | lttv_hooks_destroy(background_ready_hook); |
| 169 | } |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | /** |
| 175 | * Event Viewer's constructor hook |
| 176 | * |
| 177 | * This constructor is given as a parameter to the menuitem and toolbar button |
| 178 | * registration. It creates the list. |
| 179 | * @param tab A pointer to the parent tab. |
| 180 | * @return The widget created. |
| 181 | */ |
| 182 | GtkWidget * |
| 183 | h_guicontrolflow(Tab *tab) |
| 184 | { |
| 185 | g_info("h_guicontrolflow, %p", tab); |
| 186 | ControlFlowData *control_flow_data = guicontrolflow(tab) ; |
| 187 | |
| 188 | control_flow_data->tab = tab; |
| 189 | |
| 190 | // Unreg done in the GuiControlFlow_Destructor |
| 191 | lttvwindow_register_traceset_notify(tab, |
| 192 | traceset_notify, |
| 193 | control_flow_data); |
| 194 | |
| 195 | lttvwindow_register_time_window_notify(tab, |
| 196 | update_time_window_hook, |
| 197 | control_flow_data); |
| 198 | lttvwindow_register_current_time_notify(tab, |
| 199 | update_current_time_hook, |
| 200 | control_flow_data); |
| 201 | lttvwindow_register_redraw_notify(tab, |
| 202 | redraw_notify, |
| 203 | control_flow_data); |
| 204 | lttvwindow_register_continue_notify(tab, |
| 205 | continue_notify, |
| 206 | control_flow_data); |
| 207 | request_background_data(control_flow_data); |
| 208 | |
| 209 | |
| 210 | return guicontrolflow_get_widget(control_flow_data) ; |
| 211 | |
| 212 | } |
| 213 | |
| 214 | void legend_destructor(GtkWindow *legend) |
| 215 | { |
| 216 | g_legend_list = g_slist_remove(g_legend_list, legend); |
| 217 | } |
| 218 | |
| 219 | /* Create a popup legend */ |
| 220 | GtkWidget * |
| 221 | h_legend(Tab *tab) |
| 222 | { |
| 223 | g_info("h_legend, %p", tab); |
| 224 | |
| 225 | GtkWindow *legend = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
| 226 | |
| 227 | g_legend_list = g_slist_append( |
| 228 | g_legend_list, |
| 229 | legend); |
| 230 | |
| 231 | g_object_set_data_full( |
| 232 | G_OBJECT(legend), |
| 233 | "legend", |
| 234 | legend, |
| 235 | (GDestroyNotify)legend_destructor); |
| 236 | |
| 237 | gtk_window_set_title(legend, "Control Flow View Legend"); |
| 238 | |
| 239 | GtkWidget *pixmap = create_pixmap(GTK_WIDGET(legend), "lttv-color-list.png"); |
| 240 | |
| 241 | // GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixmap( |
| 242 | // GDK_PIXMAP(pixmap), NULL)); |
| 243 | |
| 244 | gtk_container_add(GTK_CONTAINER(legend), GTK_WIDGET(pixmap)); |
| 245 | |
| 246 | gtk_widget_show(GTK_WIDGET(pixmap)); |
| 247 | gtk_widget_show(GTK_WIDGET(legend)); |
| 248 | |
| 249 | |
| 250 | return NULL; /* This is a popup window */ |
| 251 | } |
| 252 | |
| 253 | |
| 254 | int event_selected_hook(void *hook_data, void *call_data) |
| 255 | { |
| 256 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
| 257 | guint *event_number = (guint*) call_data; |
| 258 | |
| 259 | g_debug("DEBUG : event selected by main window : %u", *event_number); |
| 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | /* Function that selects the color of status&exemode line */ |
| 265 | static inline PropertiesLine prepare_s_e_line(LttvProcessState *process) |
| 266 | { |
| 267 | PropertiesLine prop_line; |
| 268 | prop_line.line_width = 2; |
| 269 | prop_line.style = GDK_LINE_SOLID; |
| 270 | prop_line.y = MIDDLE; |
| 271 | //GdkColormap *colormap = gdk_colormap_get_system(); |
| 272 | |
| 273 | if(process->state->s == LTTV_STATE_RUN) { |
| 274 | if(process->state->t == LTTV_STATE_USER_MODE) |
| 275 | prop_line.color = drawing_colors[COL_RUN_USER_MODE]; |
| 276 | else if(process->state->t == LTTV_STATE_SYSCALL) |
| 277 | prop_line.color = drawing_colors[COL_RUN_SYSCALL]; |
| 278 | else if(process->state->t == LTTV_STATE_TRAP) |
| 279 | prop_line.color = drawing_colors[COL_RUN_TRAP]; |
| 280 | else if(process->state->t == LTTV_STATE_IRQ) |
| 281 | prop_line.color = drawing_colors[COL_RUN_IRQ]; |
| 282 | else if(process->state->t == LTTV_STATE_SOFT_IRQ) |
| 283 | prop_line.color = drawing_colors[COL_RUN_SOFT_IRQ]; |
| 284 | else if(process->state->t == LTTV_STATE_MODE_UNKNOWN) |
| 285 | prop_line.color = drawing_colors[COL_MODE_UNKNOWN]; |
| 286 | else |
| 287 | g_assert(FALSE); /* RUNNING MODE UNKNOWN */ |
| 288 | } else if(process->state->s == LTTV_STATE_WAIT) { |
| 289 | /* We don't show if we wait while in user mode, trap, irq or syscall */ |
| 290 | prop_line.color = drawing_colors[COL_WAIT]; |
| 291 | } else if(process->state->s == LTTV_STATE_WAIT_CPU) { |
| 292 | /* We don't show if we wait for CPU while in user mode, trap, irq |
| 293 | * or syscall */ |
| 294 | prop_line.color = drawing_colors[COL_WAIT_CPU]; |
| 295 | } else if(process->state->s == LTTV_STATE_ZOMBIE) { |
| 296 | prop_line.color = drawing_colors[COL_ZOMBIE]; |
| 297 | } else if(process->state->s == LTTV_STATE_WAIT_FORK) { |
| 298 | prop_line.color = drawing_colors[COL_WAIT_FORK]; |
| 299 | } else if(process->state->s == LTTV_STATE_EXIT) { |
| 300 | prop_line.color = drawing_colors[COL_EXIT]; |
| 301 | } else if(process->state->s == LTTV_STATE_UNNAMED) { |
| 302 | prop_line.color = drawing_colors[COL_UNNAMED]; |
| 303 | } else { |
| 304 | g_critical("unknown state : %s", g_quark_to_string(process->state->s)); |
| 305 | g_assert(FALSE); /* UNKNOWN STATE */ |
| 306 | } |
| 307 | |
| 308 | return prop_line; |
| 309 | |
| 310 | } |
| 311 | |
| 312 | |
| 313 | /* before_schedchange_hook |
| 314 | * |
| 315 | * This function basically draw lines and icons. Two types of lines are drawn : |
| 316 | * one small (3 pixels?) representing the state of the process and the second |
| 317 | * type is thicker (10 pixels?) representing on which CPU a process is running |
| 318 | * (and this only in running state). |
| 319 | * |
| 320 | * Extremums of the lines : |
| 321 | * x_min : time of the last event context for this process kept in memory. |
| 322 | * x_max : time of the current event. |
| 323 | * y : middle of the process in the process list. The process is found in the |
| 324 | * list, therefore is it's position in pixels. |
| 325 | * |
| 326 | * The choice of lines'color is defined by the context of the last event for this |
| 327 | * process. |
| 328 | */ |
| 329 | |
| 330 | |
| 331 | int before_schedchange_hook(void *hook_data, void *call_data) |
| 332 | { |
| 333 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 334 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 335 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 336 | |
| 337 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 338 | |
| 339 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 340 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
| 341 | |
| 342 | LttEvent *e; |
| 343 | e = ltt_tracefile_get_event(tfc->tf); |
| 344 | |
| 345 | LttTime evtime = ltt_event_time(e); |
| 346 | |
| 347 | /* we are in a schedchange, before the state update. We must draw the |
| 348 | * items corresponding to the state before it changes : now is the right |
| 349 | * time to do it. |
| 350 | */ |
| 351 | |
| 352 | guint pid_out; |
| 353 | guint pid_in; |
| 354 | { |
| 355 | pid_out = ltt_event_get_long_unsigned(e, thf->f1); |
| 356 | pid_in = ltt_event_get_long_unsigned(e, thf->f2); |
| 357 | } |
| 358 | |
| 359 | { |
| 360 | /* For the pid_out */ |
| 361 | /* First, check if the current process is in the state computation |
| 362 | * process list. If it is there, that means we must add it right now and |
| 363 | * draw items from the beginning of the read for it. If it is not |
| 364 | * present, it's a new process and it was not present : it will |
| 365 | * be added after the state update. */ |
| 366 | guint cpu = tfs->cpu; |
| 367 | LttvProcessState *process = ts->running_process[cpu]; |
| 368 | /* unknown state, bad current pid */ |
| 369 | if(process->pid != pid_out) |
| 370 | process = lttv_state_find_process(ts, |
| 371 | tfs->cpu, pid_out); |
| 372 | |
| 373 | if(process != NULL) { |
| 374 | /* Well, the process_out existed : we must get it in the process hash |
| 375 | * or add it, and draw its items. |
| 376 | */ |
| 377 | /* Add process to process list (if not present) */ |
| 378 | guint pl_height = 0; |
| 379 | HashedProcessData *hashed_process_data = NULL; |
| 380 | ProcessList *process_list = control_flow_data->process_list; |
| 381 | LttTime birth = process->creation_time; |
| 382 | |
| 383 | hashed_process_data = processlist_get_process_data(process_list, |
| 384 | pid_out, |
| 385 | process->cpu, |
| 386 | &birth, |
| 387 | tfc->t_context->index); |
| 388 | if(hashed_process_data == NULL) |
| 389 | { |
| 390 | g_assert(pid_out == 0 || pid_out != process->ppid); |
| 391 | /* Process not present */ |
| 392 | ProcessInfo *process_info; |
| 393 | Drawing_t *drawing = control_flow_data->drawing; |
| 394 | processlist_add(process_list, |
| 395 | drawing, |
| 396 | pid_out, |
| 397 | process->cpu, |
| 398 | process->ppid, |
| 399 | &birth, |
| 400 | tfc->t_context->index, |
| 401 | process->name, |
| 402 | &pl_height, |
| 403 | &process_info, |
| 404 | &hashed_process_data); |
| 405 | gtk_widget_set_size_request(drawing->drawing_area, |
| 406 | -1, |
| 407 | pl_height); |
| 408 | gtk_widget_queue_draw(drawing->drawing_area); |
| 409 | |
| 410 | } |
| 411 | |
| 412 | /* Now, the process is in the state hash and our own process hash. |
| 413 | * We definitely can draw the items related to the ending state. |
| 414 | */ |
| 415 | |
| 416 | if(ltt_time_compare(hashed_process_data->next_good_time, |
| 417 | evtime) > 0) |
| 418 | { |
| 419 | if(hashed_process_data->x.middle_marked == FALSE) { |
| 420 | |
| 421 | TimeWindow time_window = |
| 422 | lttvwindow_get_time_window(control_flow_data->tab); |
| 423 | #ifdef EXTRA_CHECK |
| 424 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 425 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 426 | return; |
| 427 | #endif //EXTRA_CHECK |
| 428 | Drawing_t *drawing = control_flow_data->drawing; |
| 429 | guint width = drawing->width; |
| 430 | guint x; |
| 431 | convert_time_to_pixels( |
| 432 | time_window, |
| 433 | evtime, |
| 434 | width, |
| 435 | &x); |
| 436 | |
| 437 | /* Draw collision indicator */ |
| 438 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 439 | gdk_draw_point(hashed_process_data->pixmap, |
| 440 | drawing->gc, |
| 441 | x, |
| 442 | (hashed_process_data->height/2)-3); |
| 443 | hashed_process_data->x.middle_marked = TRUE; |
| 444 | } |
| 445 | } else { |
| 446 | TimeWindow time_window = |
| 447 | lttvwindow_get_time_window(control_flow_data->tab); |
| 448 | #ifdef EXTRA_CHECK |
| 449 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 450 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 451 | return; |
| 452 | #endif //EXTRA_CHECK |
| 453 | Drawing_t *drawing = control_flow_data->drawing; |
| 454 | guint width = drawing->width; |
| 455 | guint x; |
| 456 | convert_time_to_pixels( |
| 457 | time_window, |
| 458 | evtime, |
| 459 | width, |
| 460 | &x); |
| 461 | |
| 462 | |
| 463 | /* Jump over draw if we are at the same x position */ |
| 464 | if(x == hashed_process_data->x.middle && |
| 465 | hashed_process_data->x.middle_used) |
| 466 | { |
| 467 | if(hashed_process_data->x.middle_marked == FALSE) { |
| 468 | /* Draw collision indicator */ |
| 469 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 470 | gdk_draw_point(hashed_process_data->pixmap, |
| 471 | drawing->gc, |
| 472 | x, |
| 473 | (hashed_process_data->height/2)-3); |
| 474 | hashed_process_data->x.middle_marked = TRUE; |
| 475 | } |
| 476 | /* jump */ |
| 477 | } else { |
| 478 | DrawContext draw_context; |
| 479 | |
| 480 | /* Now create the drawing context that will be used to draw |
| 481 | * items related to the last state. */ |
| 482 | draw_context.drawable = hashed_process_data->pixmap; |
| 483 | draw_context.gc = drawing->gc; |
| 484 | draw_context.pango_layout = drawing->pango_layout; |
| 485 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
| 486 | draw_context.drawinfo.end.x = x; |
| 487 | |
| 488 | draw_context.drawinfo.y.over = 1; |
| 489 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
| 490 | draw_context.drawinfo.y.under = hashed_process_data->height; |
| 491 | |
| 492 | draw_context.drawinfo.start.offset.over = 0; |
| 493 | draw_context.drawinfo.start.offset.middle = 0; |
| 494 | draw_context.drawinfo.start.offset.under = 0; |
| 495 | draw_context.drawinfo.end.offset.over = 0; |
| 496 | draw_context.drawinfo.end.offset.middle = 0; |
| 497 | draw_context.drawinfo.end.offset.under = 0; |
| 498 | |
| 499 | { |
| 500 | /* Draw the line */ |
| 501 | PropertiesLine prop_line = prepare_s_e_line(process); |
| 502 | draw_line((void*)&prop_line, (void*)&draw_context); |
| 503 | |
| 504 | } |
| 505 | /* become the last x position */ |
| 506 | hashed_process_data->x.middle = x; |
| 507 | hashed_process_data->x.middle_used = TRUE; |
| 508 | hashed_process_data->x.middle_marked = FALSE; |
| 509 | |
| 510 | /* Calculate the next good time */ |
| 511 | convert_pixels_to_time(width, x+1, time_window, |
| 512 | &hashed_process_data->next_good_time); |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | { |
| 519 | /* For the pid_in */ |
| 520 | /* First, check if the current process is in the state computation |
| 521 | * process list. If it is there, that means we must add it right now and |
| 522 | * draw items from the beginning of the read for it. If it is not |
| 523 | * present, it's a new process and it was not present : it will |
| 524 | * be added after the state update. */ |
| 525 | LttvProcessState *process; |
| 526 | process = lttv_state_find_process(ts, |
| 527 | tfs->cpu, pid_in); |
| 528 | |
| 529 | if(process != NULL) { |
| 530 | /* Well, the process existed : we must get it in the process hash |
| 531 | * or add it, and draw its items. |
| 532 | */ |
| 533 | /* Add process to process list (if not present) */ |
| 534 | guint pl_height = 0; |
| 535 | HashedProcessData *hashed_process_data = NULL; |
| 536 | ProcessList *process_list = control_flow_data->process_list; |
| 537 | LttTime birth = process->creation_time; |
| 538 | |
| 539 | hashed_process_data = processlist_get_process_data(process_list, |
| 540 | pid_in, |
| 541 | tfs->cpu, |
| 542 | &birth, |
| 543 | tfc->t_context->index); |
| 544 | if(hashed_process_data == NULL) |
| 545 | { |
| 546 | g_assert(pid_in == 0 || pid_in != process->ppid); |
| 547 | /* Process not present */ |
| 548 | ProcessInfo *process_info; |
| 549 | Drawing_t *drawing = control_flow_data->drawing; |
| 550 | processlist_add(process_list, |
| 551 | drawing, |
| 552 | pid_in, |
| 553 | tfs->cpu, |
| 554 | process->ppid, |
| 555 | &birth, |
| 556 | tfc->t_context->index, |
| 557 | process->name, |
| 558 | &pl_height, |
| 559 | &process_info, |
| 560 | &hashed_process_data); |
| 561 | gtk_widget_set_size_request(drawing->drawing_area, |
| 562 | -1, |
| 563 | pl_height); |
| 564 | gtk_widget_queue_draw(drawing->drawing_area); |
| 565 | |
| 566 | } |
| 567 | //We could set the current process and hash here, but will be done |
| 568 | //by after schedchange hook |
| 569 | |
| 570 | /* Now, the process is in the state hash and our own process hash. |
| 571 | * We definitely can draw the items related to the ending state. |
| 572 | */ |
| 573 | |
| 574 | if(ltt_time_compare(hashed_process_data->next_good_time, |
| 575 | evtime) > 0) |
| 576 | { |
| 577 | if(hashed_process_data->x.middle_marked == FALSE) { |
| 578 | |
| 579 | TimeWindow time_window = |
| 580 | lttvwindow_get_time_window(control_flow_data->tab); |
| 581 | #ifdef EXTRA_CHECK |
| 582 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 583 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 584 | return; |
| 585 | #endif //EXTRA_CHECK |
| 586 | Drawing_t *drawing = control_flow_data->drawing; |
| 587 | guint width = drawing->width; |
| 588 | guint x; |
| 589 | convert_time_to_pixels( |
| 590 | time_window, |
| 591 | evtime, |
| 592 | width, |
| 593 | &x); |
| 594 | |
| 595 | /* Draw collision indicator */ |
| 596 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 597 | gdk_draw_point(hashed_process_data->pixmap, |
| 598 | drawing->gc, |
| 599 | x, |
| 600 | (hashed_process_data->height/2)-3); |
| 601 | hashed_process_data->x.middle_marked = TRUE; |
| 602 | } |
| 603 | } else { |
| 604 | TimeWindow time_window = |
| 605 | lttvwindow_get_time_window(control_flow_data->tab); |
| 606 | #ifdef EXTRA_CHECK |
| 607 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 608 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 609 | return; |
| 610 | #endif //EXTRA_CHECK |
| 611 | Drawing_t *drawing = control_flow_data->drawing; |
| 612 | guint width = drawing->width; |
| 613 | guint x; |
| 614 | |
| 615 | convert_time_to_pixels( |
| 616 | time_window, |
| 617 | evtime, |
| 618 | width, |
| 619 | &x); |
| 620 | |
| 621 | |
| 622 | /* Jump over draw if we are at the same x position */ |
| 623 | if(x == hashed_process_data->x.middle && |
| 624 | hashed_process_data->x.middle_used) |
| 625 | { |
| 626 | if(hashed_process_data->x.middle_marked == FALSE) { |
| 627 | /* Draw collision indicator */ |
| 628 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 629 | gdk_draw_point(hashed_process_data->pixmap, |
| 630 | drawing->gc, |
| 631 | x, |
| 632 | (hashed_process_data->height/2)-3); |
| 633 | hashed_process_data->x.middle_marked = TRUE; |
| 634 | } |
| 635 | /* jump */ |
| 636 | } else { |
| 637 | DrawContext draw_context; |
| 638 | |
| 639 | /* Now create the drawing context that will be used to draw |
| 640 | * items related to the last state. */ |
| 641 | draw_context.drawable = hashed_process_data->pixmap; |
| 642 | draw_context.gc = drawing->gc; |
| 643 | draw_context.pango_layout = drawing->pango_layout; |
| 644 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
| 645 | draw_context.drawinfo.end.x = x; |
| 646 | |
| 647 | draw_context.drawinfo.y.over = 1; |
| 648 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
| 649 | draw_context.drawinfo.y.under = hashed_process_data->height; |
| 650 | |
| 651 | draw_context.drawinfo.start.offset.over = 0; |
| 652 | draw_context.drawinfo.start.offset.middle = 0; |
| 653 | draw_context.drawinfo.start.offset.under = 0; |
| 654 | draw_context.drawinfo.end.offset.over = 0; |
| 655 | draw_context.drawinfo.end.offset.middle = 0; |
| 656 | draw_context.drawinfo.end.offset.under = 0; |
| 657 | |
| 658 | { |
| 659 | /* Draw the line */ |
| 660 | PropertiesLine prop_line = prepare_s_e_line(process); |
| 661 | draw_line((void*)&prop_line, (void*)&draw_context); |
| 662 | } |
| 663 | |
| 664 | |
| 665 | /* become the last x position */ |
| 666 | hashed_process_data->x.middle = x; |
| 667 | hashed_process_data->x.middle_used = TRUE; |
| 668 | hashed_process_data->x.middle_marked = FALSE; |
| 669 | |
| 670 | /* Calculate the next good time */ |
| 671 | convert_pixels_to_time(width, x+1, time_window, |
| 672 | &hashed_process_data->next_good_time); |
| 673 | } |
| 674 | } |
| 675 | } else |
| 676 | g_warning("Cannot find pin_in in schedchange %u", pid_in); |
| 677 | } |
| 678 | return 0; |
| 679 | |
| 680 | |
| 681 | |
| 682 | |
| 683 | /* Text dump */ |
| 684 | #ifdef DONTSHOW |
| 685 | GString *string = g_string_new("");; |
| 686 | gboolean field_names = TRUE, state = TRUE; |
| 687 | |
| 688 | lttv_event_to_string(e, tfc->tf, string, TRUE, field_names, tfs); |
| 689 | g_string_append_printf(string,"\n"); |
| 690 | |
| 691 | if(state) { |
| 692 | g_string_append_printf(string, " %s", |
| 693 | g_quark_to_string(tfs->process->state->s)); |
| 694 | } |
| 695 | |
| 696 | g_info("%s",string->str); |
| 697 | |
| 698 | g_string_free(string, TRUE); |
| 699 | |
| 700 | /* End of text dump */ |
| 701 | #endif //DONTSHOW |
| 702 | |
| 703 | } |
| 704 | |
| 705 | /* after_schedchange_hook |
| 706 | * |
| 707 | * The draw after hook is called by the reading API to have a |
| 708 | * particular event drawn on the screen. |
| 709 | * @param hook_data ControlFlowData structure of the viewer. |
| 710 | * @param call_data Event context. |
| 711 | * |
| 712 | * This function adds items to be drawn in a queue for each process. |
| 713 | * |
| 714 | */ |
| 715 | int after_schedchange_hook(void *hook_data, void *call_data) |
| 716 | { |
| 717 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 718 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 719 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 720 | |
| 721 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 722 | |
| 723 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 724 | |
| 725 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
| 726 | |
| 727 | LttEvent *e; |
| 728 | e = ltt_tracefile_get_event(tfc->tf); |
| 729 | |
| 730 | LttTime evtime = ltt_event_time(e); |
| 731 | |
| 732 | /* Add process to process list (if not present) */ |
| 733 | LttvProcessState *process_in; |
| 734 | LttTime birth; |
| 735 | guint pl_height = 0; |
| 736 | HashedProcessData *hashed_process_data_in = NULL; |
| 737 | |
| 738 | ProcessList *process_list = control_flow_data->process_list; |
| 739 | |
| 740 | guint pid_in; |
| 741 | { |
| 742 | guint pid_out; |
| 743 | pid_out = ltt_event_get_long_unsigned(e, thf->f1); |
| 744 | pid_in = ltt_event_get_long_unsigned(e, thf->f2); |
| 745 | } |
| 746 | |
| 747 | |
| 748 | /* Find process pid_in in the list... */ |
| 749 | //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in); |
| 750 | //process_in = tfs->process; |
| 751 | guint cpu = tfs->cpu; |
| 752 | process_in = ts->running_process[cpu]; |
| 753 | /* It should exist, because we are after the state update. */ |
| 754 | #ifdef EXTRA_CHECK |
| 755 | g_assert(process_in != NULL); |
| 756 | #endif //EXTRA_CHECK |
| 757 | birth = process_in->creation_time; |
| 758 | |
| 759 | hashed_process_data_in = processlist_get_process_data(process_list, |
| 760 | pid_in, |
| 761 | process_in->cpu, |
| 762 | &birth, |
| 763 | tfc->t_context->index); |
| 764 | if(hashed_process_data_in == NULL) |
| 765 | { |
| 766 | g_assert(pid_in == 0 || pid_in != process_in->ppid); |
| 767 | ProcessInfo *process_info; |
| 768 | Drawing_t *drawing = control_flow_data->drawing; |
| 769 | /* Process not present */ |
| 770 | processlist_add(process_list, |
| 771 | drawing, |
| 772 | pid_in, |
| 773 | process_in->cpu, |
| 774 | process_in->ppid, |
| 775 | &birth, |
| 776 | tfc->t_context->index, |
| 777 | process_in->name, |
| 778 | &pl_height, |
| 779 | &process_info, |
| 780 | &hashed_process_data_in); |
| 781 | gtk_widget_set_size_request(drawing->drawing_area, |
| 782 | -1, |
| 783 | pl_height); |
| 784 | gtk_widget_queue_draw(drawing->drawing_area); |
| 785 | } |
| 786 | /* Set the current process */ |
| 787 | process_list->current_hash_data[process_in->cpu] = |
| 788 | hashed_process_data_in; |
| 789 | |
| 790 | if(ltt_time_compare(hashed_process_data_in->next_good_time, |
| 791 | evtime) <= 0) |
| 792 | { |
| 793 | TimeWindow time_window = |
| 794 | lttvwindow_get_time_window(control_flow_data->tab); |
| 795 | |
| 796 | #ifdef EXTRA_CHECK |
| 797 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 798 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 799 | return; |
| 800 | #endif //EXTRA_CHECK |
| 801 | Drawing_t *drawing = control_flow_data->drawing; |
| 802 | guint width = drawing->width; |
| 803 | guint new_x; |
| 804 | |
| 805 | convert_time_to_pixels( |
| 806 | time_window, |
| 807 | evtime, |
| 808 | width, |
| 809 | &new_x); |
| 810 | |
| 811 | if(hashed_process_data_in->x.middle != new_x) { |
| 812 | hashed_process_data_in->x.middle = new_x; |
| 813 | hashed_process_data_in->x.middle_used = FALSE; |
| 814 | hashed_process_data_in->x.middle_marked = FALSE; |
| 815 | } |
| 816 | } |
| 817 | return 0; |
| 818 | } |
| 819 | |
| 820 | |
| 821 | |
| 822 | |
| 823 | /* before_execmode_hook |
| 824 | * |
| 825 | * This function basically draw lines and icons. Two types of lines are drawn : |
| 826 | * one small (3 pixels?) representing the state of the process and the second |
| 827 | * type is thicker (10 pixels?) representing on which CPU a process is running |
| 828 | * (and this only in running state). |
| 829 | * |
| 830 | * Extremums of the lines : |
| 831 | * x_min : time of the last event context for this process kept in memory. |
| 832 | * x_max : time of the current event. |
| 833 | * y : middle of the process in the process list. The process is found in the |
| 834 | * list, therefore is it's position in pixels. |
| 835 | * |
| 836 | * The choice of lines'color is defined by the context of the last event for this |
| 837 | * process. |
| 838 | */ |
| 839 | |
| 840 | |
| 841 | int before_execmode_hook(void *hook_data, void *call_data) |
| 842 | { |
| 843 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 844 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 845 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 846 | |
| 847 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 848 | |
| 849 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 850 | |
| 851 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
| 852 | |
| 853 | LttEvent *e; |
| 854 | e = ltt_tracefile_get_event(tfc->tf); |
| 855 | |
| 856 | LttTime evtime = ltt_event_time(e); |
| 857 | |
| 858 | /* we are in a execmode, before the state update. We must draw the |
| 859 | * items corresponding to the state before it changes : now is the right |
| 860 | * time to do it. |
| 861 | */ |
| 862 | /* For the pid */ |
| 863 | //LttvProcessState *process = tfs->process; |
| 864 | guint cpu = tfs->cpu; |
| 865 | LttvProcessState *process = ts->running_process[cpu]; |
| 866 | g_assert(process != NULL); |
| 867 | |
| 868 | guint pid = process->pid; |
| 869 | |
| 870 | /* Well, the process_out existed : we must get it in the process hash |
| 871 | * or add it, and draw its items. |
| 872 | */ |
| 873 | /* Add process to process list (if not present) */ |
| 874 | guint pl_height = 0; |
| 875 | HashedProcessData *hashed_process_data = NULL; |
| 876 | ProcessList *process_list = control_flow_data->process_list; |
| 877 | LttTime birth = process->creation_time; |
| 878 | |
| 879 | if(likely(process_list->current_hash_data[cpu] != NULL)) { |
| 880 | hashed_process_data = process_list->current_hash_data[cpu]; |
| 881 | } else { |
| 882 | hashed_process_data = processlist_get_process_data(process_list, |
| 883 | pid, |
| 884 | process->cpu, |
| 885 | &birth, |
| 886 | tfc->t_context->index); |
| 887 | if(unlikely(hashed_process_data == NULL)) |
| 888 | { |
| 889 | g_assert(pid == 0 || pid != process->ppid); |
| 890 | ProcessInfo *process_info; |
| 891 | /* Process not present */ |
| 892 | Drawing_t *drawing = control_flow_data->drawing; |
| 893 | processlist_add(process_list, |
| 894 | drawing, |
| 895 | pid, |
| 896 | process->cpu, |
| 897 | process->ppid, |
| 898 | &birth, |
| 899 | tfc->t_context->index, |
| 900 | process->name, |
| 901 | &pl_height, |
| 902 | &process_info, |
| 903 | &hashed_process_data); |
| 904 | gtk_widget_set_size_request(drawing->drawing_area, |
| 905 | -1, |
| 906 | pl_height); |
| 907 | gtk_widget_queue_draw(drawing->drawing_area); |
| 908 | } |
| 909 | /* Set the current process */ |
| 910 | process_list->current_hash_data[process->cpu] = |
| 911 | hashed_process_data; |
| 912 | } |
| 913 | |
| 914 | /* Now, the process is in the state hash and our own process hash. |
| 915 | * We definitely can draw the items related to the ending state. |
| 916 | */ |
| 917 | |
| 918 | if(likely(ltt_time_compare(hashed_process_data->next_good_time, |
| 919 | evtime) > 0)) |
| 920 | { |
| 921 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
| 922 | TimeWindow time_window = |
| 923 | lttvwindow_get_time_window(control_flow_data->tab); |
| 924 | |
| 925 | #ifdef EXTRA_CHECK |
| 926 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 927 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 928 | return; |
| 929 | #endif //EXTRA_CHECK |
| 930 | Drawing_t *drawing = control_flow_data->drawing; |
| 931 | guint width = drawing->width; |
| 932 | guint x; |
| 933 | convert_time_to_pixels( |
| 934 | time_window, |
| 935 | evtime, |
| 936 | width, |
| 937 | &x); |
| 938 | |
| 939 | /* Draw collision indicator */ |
| 940 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 941 | gdk_draw_point(hashed_process_data->pixmap, |
| 942 | drawing->gc, |
| 943 | x, |
| 944 | (hashed_process_data->height/2)-3); |
| 945 | hashed_process_data->x.middle_marked = TRUE; |
| 946 | } |
| 947 | } else { |
| 948 | TimeWindow time_window = |
| 949 | lttvwindow_get_time_window(control_flow_data->tab); |
| 950 | |
| 951 | #ifdef EXTRA_CHECK |
| 952 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 953 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 954 | return; |
| 955 | #endif //EXTRA_CHECK |
| 956 | Drawing_t *drawing = control_flow_data->drawing; |
| 957 | guint width = drawing->width; |
| 958 | guint x; |
| 959 | |
| 960 | convert_time_to_pixels( |
| 961 | time_window, |
| 962 | evtime, |
| 963 | width, |
| 964 | &x); |
| 965 | |
| 966 | |
| 967 | /* Jump over draw if we are at the same x position */ |
| 968 | if(unlikely(x == hashed_process_data->x.middle && |
| 969 | hashed_process_data->x.middle_used)) |
| 970 | { |
| 971 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
| 972 | /* Draw collision indicator */ |
| 973 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 974 | gdk_draw_point(hashed_process_data->pixmap, |
| 975 | drawing->gc, |
| 976 | x, |
| 977 | (hashed_process_data->height/2)-3); |
| 978 | hashed_process_data->x.middle_marked = TRUE; |
| 979 | } |
| 980 | /* jump */ |
| 981 | } else { |
| 982 | |
| 983 | DrawContext draw_context; |
| 984 | /* Now create the drawing context that will be used to draw |
| 985 | * items related to the last state. */ |
| 986 | draw_context.drawable = hashed_process_data->pixmap; |
| 987 | draw_context.gc = drawing->gc; |
| 988 | draw_context.pango_layout = drawing->pango_layout; |
| 989 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
| 990 | draw_context.drawinfo.end.x = x; |
| 991 | |
| 992 | draw_context.drawinfo.y.over = 1; |
| 993 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
| 994 | draw_context.drawinfo.y.under = hashed_process_data->height; |
| 995 | |
| 996 | draw_context.drawinfo.start.offset.over = 0; |
| 997 | draw_context.drawinfo.start.offset.middle = 0; |
| 998 | draw_context.drawinfo.start.offset.under = 0; |
| 999 | draw_context.drawinfo.end.offset.over = 0; |
| 1000 | draw_context.drawinfo.end.offset.middle = 0; |
| 1001 | draw_context.drawinfo.end.offset.under = 0; |
| 1002 | |
| 1003 | { |
| 1004 | /* Draw the line */ |
| 1005 | PropertiesLine prop_line = prepare_s_e_line(process); |
| 1006 | draw_line((void*)&prop_line, (void*)&draw_context); |
| 1007 | |
| 1008 | } |
| 1009 | /* become the last x position */ |
| 1010 | hashed_process_data->x.middle = x; |
| 1011 | hashed_process_data->x.middle_used = TRUE; |
| 1012 | hashed_process_data->x.middle_marked = FALSE; |
| 1013 | |
| 1014 | /* Calculate the next good time */ |
| 1015 | convert_pixels_to_time(width, x+1, time_window, |
| 1016 | &hashed_process_data->next_good_time); |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | return 0; |
| 1021 | } |
| 1022 | |
| 1023 | /* before_process_exit_hook |
| 1024 | * |
| 1025 | * Draw lines for process event. |
| 1026 | * |
| 1027 | * @param hook_data ControlFlowData structure of the viewer. |
| 1028 | * @param call_data Event context. |
| 1029 | * |
| 1030 | * This function adds items to be drawn in a queue for each process. |
| 1031 | * |
| 1032 | */ |
| 1033 | |
| 1034 | |
| 1035 | int before_process_exit_hook(void *hook_data, void *call_data) |
| 1036 | { |
| 1037 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 1038 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 1039 | |
| 1040 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 1041 | |
| 1042 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 1043 | |
| 1044 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 1045 | |
| 1046 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
| 1047 | |
| 1048 | LttEvent *e; |
| 1049 | e = ltt_tracefile_get_event(tfc->tf); |
| 1050 | |
| 1051 | LttTime evtime = ltt_event_time(e); |
| 1052 | |
| 1053 | /* Add process to process list (if not present) */ |
| 1054 | //LttvProcessState *process = tfs->process; |
| 1055 | guint cpu = tfs->cpu; |
| 1056 | LttvProcessState *process = ts->running_process[cpu]; |
| 1057 | guint pid = process->pid; |
| 1058 | LttTime birth; |
| 1059 | guint pl_height = 0; |
| 1060 | HashedProcessData *hashed_process_data = NULL; |
| 1061 | |
| 1062 | ProcessList *process_list = control_flow_data->process_list; |
| 1063 | |
| 1064 | g_assert(process != NULL); |
| 1065 | |
| 1066 | birth = process->creation_time; |
| 1067 | |
| 1068 | if(likely(process_list->current_hash_data[cpu] != NULL)) { |
| 1069 | hashed_process_data = process_list->current_hash_data[cpu]; |
| 1070 | } else { |
| 1071 | hashed_process_data = processlist_get_process_data(process_list, |
| 1072 | pid, |
| 1073 | process->cpu, |
| 1074 | &birth, |
| 1075 | tfc->t_context->index); |
| 1076 | if(unlikely(hashed_process_data == NULL)) |
| 1077 | { |
| 1078 | g_assert(pid == 0 || pid != process->ppid); |
| 1079 | /* Process not present */ |
| 1080 | Drawing_t *drawing = control_flow_data->drawing; |
| 1081 | ProcessInfo *process_info; |
| 1082 | processlist_add(process_list, |
| 1083 | drawing, |
| 1084 | pid, |
| 1085 | process->cpu, |
| 1086 | process->ppid, |
| 1087 | &birth, |
| 1088 | tfc->t_context->index, |
| 1089 | process->name, |
| 1090 | &pl_height, |
| 1091 | &process_info, |
| 1092 | &hashed_process_data); |
| 1093 | gtk_widget_set_size_request(drawing->drawing_area, |
| 1094 | -1, |
| 1095 | pl_height); |
| 1096 | gtk_widget_queue_draw(drawing->drawing_area); |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | /* Now, the process is in the state hash and our own process hash. |
| 1101 | * We definitely can draw the items related to the ending state. |
| 1102 | */ |
| 1103 | |
| 1104 | if(likely(ltt_time_compare(hashed_process_data->next_good_time, |
| 1105 | evtime) > 0)) |
| 1106 | { |
| 1107 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
| 1108 | TimeWindow time_window = |
| 1109 | lttvwindow_get_time_window(control_flow_data->tab); |
| 1110 | |
| 1111 | #ifdef EXTRA_CHECK |
| 1112 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 1113 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 1114 | return; |
| 1115 | #endif //EXTRA_CHECK |
| 1116 | Drawing_t *drawing = control_flow_data->drawing; |
| 1117 | guint width = drawing->width; |
| 1118 | guint x; |
| 1119 | convert_time_to_pixels( |
| 1120 | time_window, |
| 1121 | evtime, |
| 1122 | width, |
| 1123 | &x); |
| 1124 | |
| 1125 | /* Draw collision indicator */ |
| 1126 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 1127 | gdk_draw_point(hashed_process_data->pixmap, |
| 1128 | drawing->gc, |
| 1129 | x, |
| 1130 | (hashed_process_data->height/2)-3); |
| 1131 | hashed_process_data->x.middle_marked = TRUE; |
| 1132 | } |
| 1133 | } else { |
| 1134 | TimeWindow time_window = |
| 1135 | lttvwindow_get_time_window(control_flow_data->tab); |
| 1136 | |
| 1137 | #ifdef EXTRA_CHECK |
| 1138 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 1139 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 1140 | return; |
| 1141 | #endif //EXTRA_CHECK |
| 1142 | Drawing_t *drawing = control_flow_data->drawing; |
| 1143 | guint width = drawing->width; |
| 1144 | guint x; |
| 1145 | |
| 1146 | convert_time_to_pixels( |
| 1147 | time_window, |
| 1148 | evtime, |
| 1149 | width, |
| 1150 | &x); |
| 1151 | |
| 1152 | |
| 1153 | /* Jump over draw if we are at the same x position */ |
| 1154 | if(unlikely(x == hashed_process_data->x.middle && |
| 1155 | hashed_process_data->x.middle_used)) |
| 1156 | { |
| 1157 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
| 1158 | /* Draw collision indicator */ |
| 1159 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 1160 | gdk_draw_point(hashed_process_data->pixmap, |
| 1161 | drawing->gc, |
| 1162 | x, |
| 1163 | (hashed_process_data->height/2)-3); |
| 1164 | hashed_process_data->x.middle_marked = TRUE; |
| 1165 | } |
| 1166 | /* jump */ |
| 1167 | } else { |
| 1168 | DrawContext draw_context; |
| 1169 | |
| 1170 | /* Now create the drawing context that will be used to draw |
| 1171 | * items related to the last state. */ |
| 1172 | draw_context.drawable = hashed_process_data->pixmap; |
| 1173 | draw_context.gc = drawing->gc; |
| 1174 | draw_context.pango_layout = drawing->pango_layout; |
| 1175 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
| 1176 | draw_context.drawinfo.end.x = x; |
| 1177 | |
| 1178 | draw_context.drawinfo.y.over = 1; |
| 1179 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
| 1180 | draw_context.drawinfo.y.under = hashed_process_data->height; |
| 1181 | |
| 1182 | draw_context.drawinfo.start.offset.over = 0; |
| 1183 | draw_context.drawinfo.start.offset.middle = 0; |
| 1184 | draw_context.drawinfo.start.offset.under = 0; |
| 1185 | draw_context.drawinfo.end.offset.over = 0; |
| 1186 | draw_context.drawinfo.end.offset.middle = 0; |
| 1187 | draw_context.drawinfo.end.offset.under = 0; |
| 1188 | |
| 1189 | { |
| 1190 | /* Draw the line */ |
| 1191 | PropertiesLine prop_line = prepare_s_e_line(process); |
| 1192 | draw_line((void*)&prop_line, (void*)&draw_context); |
| 1193 | |
| 1194 | } |
| 1195 | /* become the last x position */ |
| 1196 | hashed_process_data->x.middle = x; |
| 1197 | hashed_process_data->x.middle_used = TRUE; |
| 1198 | hashed_process_data->x.middle_marked = FALSE; |
| 1199 | |
| 1200 | /* Calculate the next good time */ |
| 1201 | convert_pixels_to_time(width, x+1, time_window, |
| 1202 | &hashed_process_data->next_good_time); |
| 1203 | } |
| 1204 | } |
| 1205 | |
| 1206 | return 0; |
| 1207 | |
| 1208 | } |
| 1209 | |
| 1210 | |
| 1211 | |
| 1212 | /* before_process_release_hook |
| 1213 | * |
| 1214 | * Draw lines for process event. |
| 1215 | * |
| 1216 | * @param hook_data ControlFlowData structure of the viewer. |
| 1217 | * @param call_data Event context. |
| 1218 | * |
| 1219 | * This function adds items to be drawn in a queue for each process. |
| 1220 | * |
| 1221 | */ |
| 1222 | |
| 1223 | |
| 1224 | int before_process_release_hook(void *hook_data, void *call_data) |
| 1225 | { |
| 1226 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 1227 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 1228 | |
| 1229 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 1230 | |
| 1231 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 1232 | |
| 1233 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 1234 | |
| 1235 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
| 1236 | |
| 1237 | LttEvent *e; |
| 1238 | e = ltt_tracefile_get_event(tfc->tf); |
| 1239 | |
| 1240 | LttTime evtime = ltt_event_time(e); |
| 1241 | |
| 1242 | |
| 1243 | guint pid; |
| 1244 | { |
| 1245 | pid = ltt_event_get_long_unsigned(e, thf->f1); |
| 1246 | } |
| 1247 | |
| 1248 | /* Add process to process list (if not present) */ |
| 1249 | /* Don't care about the process if it's not in the state hash already : |
| 1250 | * that means a process that has never done anything in the trace and |
| 1251 | * unknown suddently gets destroyed : no state meaningful to show. */ |
| 1252 | LttvProcessState *process = lttv_state_find_process(ts, ANY_CPU, pid); |
| 1253 | |
| 1254 | if(process != NULL) { |
| 1255 | LttTime birth; |
| 1256 | guint pl_height = 0; |
| 1257 | HashedProcessData *hashed_process_data = NULL; |
| 1258 | |
| 1259 | ProcessList *process_list = control_flow_data->process_list; |
| 1260 | |
| 1261 | birth = process->creation_time; |
| 1262 | |
| 1263 | /* Cannot use current process : this event happens on another process, |
| 1264 | * action done by the parent. */ |
| 1265 | hashed_process_data = processlist_get_process_data(process_list, |
| 1266 | pid, |
| 1267 | process->cpu, |
| 1268 | &birth, |
| 1269 | tfc->t_context->index); |
| 1270 | if(unlikely(hashed_process_data == NULL)) |
| 1271 | { |
| 1272 | g_assert(pid == 0 || pid != process->ppid); |
| 1273 | /* Process not present */ |
| 1274 | Drawing_t *drawing = control_flow_data->drawing; |
| 1275 | ProcessInfo *process_info; |
| 1276 | processlist_add(process_list, |
| 1277 | drawing, |
| 1278 | pid, |
| 1279 | process->cpu, |
| 1280 | process->ppid, |
| 1281 | &birth, |
| 1282 | tfc->t_context->index, |
| 1283 | process->name, |
| 1284 | &pl_height, |
| 1285 | &process_info, |
| 1286 | &hashed_process_data); |
| 1287 | gtk_widget_set_size_request(drawing->drawing_area, |
| 1288 | -1, |
| 1289 | pl_height); |
| 1290 | gtk_widget_queue_draw(drawing->drawing_area); |
| 1291 | } |
| 1292 | |
| 1293 | /* Now, the process is in the state hash and our own process hash. |
| 1294 | * We definitely can draw the items related to the ending state. |
| 1295 | */ |
| 1296 | |
| 1297 | if(likely(ltt_time_compare(hashed_process_data->next_good_time, |
| 1298 | evtime) > 0)) |
| 1299 | { |
| 1300 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
| 1301 | TimeWindow time_window = |
| 1302 | lttvwindow_get_time_window(control_flow_data->tab); |
| 1303 | |
| 1304 | #ifdef EXTRA_CHECK |
| 1305 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 1306 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 1307 | return; |
| 1308 | #endif //EXTRA_CHECK |
| 1309 | Drawing_t *drawing = control_flow_data->drawing; |
| 1310 | guint width = drawing->width; |
| 1311 | guint x; |
| 1312 | convert_time_to_pixels( |
| 1313 | time_window, |
| 1314 | evtime, |
| 1315 | width, |
| 1316 | &x); |
| 1317 | |
| 1318 | /* Draw collision indicator */ |
| 1319 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 1320 | gdk_draw_point(hashed_process_data->pixmap, |
| 1321 | drawing->gc, |
| 1322 | x, |
| 1323 | (hashed_process_data->height/2)-3); |
| 1324 | hashed_process_data->x.middle_marked = TRUE; |
| 1325 | } |
| 1326 | } else { |
| 1327 | TimeWindow time_window = |
| 1328 | lttvwindow_get_time_window(control_flow_data->tab); |
| 1329 | |
| 1330 | #ifdef EXTRA_CHECK |
| 1331 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 1332 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 1333 | return; |
| 1334 | #endif //EXTRA_CHECK |
| 1335 | Drawing_t *drawing = control_flow_data->drawing; |
| 1336 | guint width = drawing->width; |
| 1337 | guint x; |
| 1338 | |
| 1339 | convert_time_to_pixels( |
| 1340 | time_window, |
| 1341 | evtime, |
| 1342 | width, |
| 1343 | &x); |
| 1344 | |
| 1345 | |
| 1346 | /* Jump over draw if we are at the same x position */ |
| 1347 | if(unlikely(x == hashed_process_data->x.middle && |
| 1348 | hashed_process_data->x.middle_used)) |
| 1349 | { |
| 1350 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
| 1351 | /* Draw collision indicator */ |
| 1352 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 1353 | gdk_draw_point(hashed_process_data->pixmap, |
| 1354 | drawing->gc, |
| 1355 | x, |
| 1356 | (hashed_process_data->height/2)-3); |
| 1357 | hashed_process_data->x.middle_marked = TRUE; |
| 1358 | } |
| 1359 | /* jump */ |
| 1360 | } else { |
| 1361 | DrawContext draw_context; |
| 1362 | |
| 1363 | /* Now create the drawing context that will be used to draw |
| 1364 | * items related to the last state. */ |
| 1365 | draw_context.drawable = hashed_process_data->pixmap; |
| 1366 | draw_context.gc = drawing->gc; |
| 1367 | draw_context.pango_layout = drawing->pango_layout; |
| 1368 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
| 1369 | draw_context.drawinfo.end.x = x; |
| 1370 | |
| 1371 | draw_context.drawinfo.y.over = 1; |
| 1372 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
| 1373 | draw_context.drawinfo.y.under = hashed_process_data->height; |
| 1374 | |
| 1375 | draw_context.drawinfo.start.offset.over = 0; |
| 1376 | draw_context.drawinfo.start.offset.middle = 0; |
| 1377 | draw_context.drawinfo.start.offset.under = 0; |
| 1378 | draw_context.drawinfo.end.offset.over = 0; |
| 1379 | draw_context.drawinfo.end.offset.middle = 0; |
| 1380 | draw_context.drawinfo.end.offset.under = 0; |
| 1381 | |
| 1382 | { |
| 1383 | /* Draw the line */ |
| 1384 | PropertiesLine prop_line = prepare_s_e_line(process); |
| 1385 | draw_line((void*)&prop_line, (void*)&draw_context); |
| 1386 | |
| 1387 | } |
| 1388 | /* become the last x position */ |
| 1389 | hashed_process_data->x.middle = x; |
| 1390 | hashed_process_data->x.middle_used = TRUE; |
| 1391 | hashed_process_data->x.middle_marked = FALSE; |
| 1392 | |
| 1393 | /* Calculate the next good time */ |
| 1394 | convert_pixels_to_time(width, x+1, time_window, |
| 1395 | &hashed_process_data->next_good_time); |
| 1396 | } |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | return 0; |
| 1401 | } |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | |
| 1406 | |
| 1407 | /* after_process_fork_hook |
| 1408 | * |
| 1409 | * Create the processlist entry for the child process. Put the last |
| 1410 | * position in x at the current time value. |
| 1411 | * |
| 1412 | * @param hook_data ControlFlowData structure of the viewer. |
| 1413 | * @param call_data Event context. |
| 1414 | * |
| 1415 | * This function adds items to be drawn in a queue for each process. |
| 1416 | * |
| 1417 | */ |
| 1418 | int after_process_fork_hook(void *hook_data, void *call_data) |
| 1419 | { |
| 1420 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 1421 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 1422 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 1423 | |
| 1424 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 1425 | |
| 1426 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 1427 | |
| 1428 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
| 1429 | |
| 1430 | LttEvent *e; |
| 1431 | e = ltt_tracefile_get_event(tfc->tf); |
| 1432 | |
| 1433 | LttTime evtime = ltt_event_time(e); |
| 1434 | |
| 1435 | guint child_pid; |
| 1436 | { |
| 1437 | child_pid = ltt_event_get_long_unsigned(e, thf->f2); |
| 1438 | } |
| 1439 | |
| 1440 | /* Add process to process list (if not present) */ |
| 1441 | LttvProcessState *process_child; |
| 1442 | LttTime birth; |
| 1443 | guint pl_height = 0; |
| 1444 | HashedProcessData *hashed_process_data_child = NULL; |
| 1445 | |
| 1446 | ProcessList *process_list = control_flow_data->process_list; |
| 1447 | |
| 1448 | /* Find child in the list... */ |
| 1449 | process_child = lttv_state_find_process(ts, ANY_CPU, child_pid); |
| 1450 | /* It should exist, because we are after the state update. */ |
| 1451 | g_assert(process_child != NULL); |
| 1452 | |
| 1453 | birth = process_child->creation_time; |
| 1454 | |
| 1455 | /* Cannot use current process, because this action is done by the parent |
| 1456 | * on its child. */ |
| 1457 | hashed_process_data_child = processlist_get_process_data(process_list, |
| 1458 | child_pid, |
| 1459 | process_child->cpu, |
| 1460 | &birth, |
| 1461 | tfc->t_context->index); |
| 1462 | if(likely(hashed_process_data_child == NULL)) |
| 1463 | { |
| 1464 | g_assert(child_pid == 0 || child_pid != process_child->ppid); |
| 1465 | /* Process not present */ |
| 1466 | Drawing_t *drawing = control_flow_data->drawing; |
| 1467 | ProcessInfo *process_info; |
| 1468 | processlist_add(process_list, |
| 1469 | drawing, |
| 1470 | child_pid, |
| 1471 | process_child->cpu, |
| 1472 | process_child->ppid, |
| 1473 | &birth, |
| 1474 | tfc->t_context->index, |
| 1475 | process_child->name, |
| 1476 | &pl_height, |
| 1477 | &process_info, |
| 1478 | &hashed_process_data_child); |
| 1479 | gtk_widget_set_size_request(drawing->drawing_area, |
| 1480 | -1, |
| 1481 | pl_height); |
| 1482 | gtk_widget_queue_draw(drawing->drawing_area); |
| 1483 | } |
| 1484 | |
| 1485 | |
| 1486 | if(likely(ltt_time_compare(hashed_process_data_child->next_good_time, |
| 1487 | evtime) <= 0)) |
| 1488 | { |
| 1489 | TimeWindow time_window = |
| 1490 | lttvwindow_get_time_window(control_flow_data->tab); |
| 1491 | |
| 1492 | #ifdef EXTRA_CHECK |
| 1493 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 1494 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 1495 | return; |
| 1496 | #endif //EXTRA_CHECK |
| 1497 | Drawing_t *drawing = control_flow_data->drawing; |
| 1498 | guint width = drawing->width; |
| 1499 | guint new_x; |
| 1500 | convert_time_to_pixels( |
| 1501 | time_window, |
| 1502 | evtime, |
| 1503 | width, |
| 1504 | &new_x); |
| 1505 | |
| 1506 | if(likely(hashed_process_data_child->x.over != new_x)) { |
| 1507 | hashed_process_data_child->x.over = new_x; |
| 1508 | hashed_process_data_child->x.over_used = FALSE; |
| 1509 | hashed_process_data_child->x.over_marked = FALSE; |
| 1510 | } |
| 1511 | if(likely(hashed_process_data_child->x.middle != new_x)) { |
| 1512 | hashed_process_data_child->x.middle = new_x; |
| 1513 | hashed_process_data_child->x.middle_used = FALSE; |
| 1514 | hashed_process_data_child->x.middle_marked = FALSE; |
| 1515 | } |
| 1516 | if(likely(hashed_process_data_child->x.under != new_x)) { |
| 1517 | hashed_process_data_child->x.under = new_x; |
| 1518 | hashed_process_data_child->x.under_used = FALSE; |
| 1519 | hashed_process_data_child->x.under_marked = FALSE; |
| 1520 | } |
| 1521 | } |
| 1522 | return 0; |
| 1523 | } |
| 1524 | |
| 1525 | |
| 1526 | |
| 1527 | /* after_process_exit_hook |
| 1528 | * |
| 1529 | * Create the processlist entry for the child process. Put the last |
| 1530 | * position in x at the current time value. |
| 1531 | * |
| 1532 | * @param hook_data ControlFlowData structure of the viewer. |
| 1533 | * @param call_data Event context. |
| 1534 | * |
| 1535 | * This function adds items to be drawn in a queue for each process. |
| 1536 | * |
| 1537 | */ |
| 1538 | int after_process_exit_hook(void *hook_data, void *call_data) |
| 1539 | { |
| 1540 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 1541 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 1542 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 1543 | |
| 1544 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 1545 | |
| 1546 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 1547 | |
| 1548 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
| 1549 | |
| 1550 | LttEvent *e; |
| 1551 | e = ltt_tracefile_get_event(tfc->tf); |
| 1552 | |
| 1553 | LttTime evtime = ltt_event_time(e); |
| 1554 | |
| 1555 | /* Add process to process list (if not present) */ |
| 1556 | //LttvProcessState *process = tfs->process; |
| 1557 | guint cpu = tfs->cpu; |
| 1558 | LttvProcessState *process = ts->running_process[cpu]; |
| 1559 | |
| 1560 | /* It should exist, because we are after the state update. */ |
| 1561 | g_assert(process != NULL); |
| 1562 | |
| 1563 | guint pid = process->pid; |
| 1564 | LttTime birth; |
| 1565 | guint pl_height = 0; |
| 1566 | HashedProcessData *hashed_process_data = NULL; |
| 1567 | |
| 1568 | ProcessList *process_list = control_flow_data->process_list; |
| 1569 | |
| 1570 | birth = process->creation_time; |
| 1571 | |
| 1572 | if(likely(process_list->current_hash_data[cpu] != NULL) ){ |
| 1573 | hashed_process_data = process_list->current_hash_data[cpu]; |
| 1574 | } else { |
| 1575 | hashed_process_data = processlist_get_process_data(process_list, |
| 1576 | pid, |
| 1577 | process->cpu, |
| 1578 | &birth, |
| 1579 | tfc->t_context->index); |
| 1580 | if(unlikely(hashed_process_data == NULL)) |
| 1581 | { |
| 1582 | g_assert(pid == 0 || pid != process->ppid); |
| 1583 | /* Process not present */ |
| 1584 | Drawing_t *drawing = control_flow_data->drawing; |
| 1585 | ProcessInfo *process_info; |
| 1586 | processlist_add(process_list, |
| 1587 | drawing, |
| 1588 | pid, |
| 1589 | process->cpu, |
| 1590 | process->ppid, |
| 1591 | &birth, |
| 1592 | tfc->t_context->index, |
| 1593 | process->name, |
| 1594 | &pl_height, |
| 1595 | &process_info, |
| 1596 | &hashed_process_data); |
| 1597 | gtk_widget_set_size_request(drawing->drawing_area, |
| 1598 | -1, |
| 1599 | pl_height); |
| 1600 | gtk_widget_queue_draw(drawing->drawing_area); |
| 1601 | } |
| 1602 | |
| 1603 | /* Set the current process */ |
| 1604 | process_list->current_hash_data[process->cpu] = |
| 1605 | hashed_process_data; |
| 1606 | } |
| 1607 | |
| 1608 | if(unlikely(ltt_time_compare(hashed_process_data->next_good_time, |
| 1609 | evtime) <= 0)) |
| 1610 | { |
| 1611 | TimeWindow time_window = |
| 1612 | lttvwindow_get_time_window(control_flow_data->tab); |
| 1613 | |
| 1614 | #ifdef EXTRA_CHECK |
| 1615 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 1616 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 1617 | return; |
| 1618 | #endif //EXTRA_CHECK |
| 1619 | Drawing_t *drawing = control_flow_data->drawing; |
| 1620 | guint width = drawing->width; |
| 1621 | guint new_x; |
| 1622 | convert_time_to_pixels( |
| 1623 | time_window, |
| 1624 | evtime, |
| 1625 | width, |
| 1626 | &new_x); |
| 1627 | if(unlikely(hashed_process_data->x.middle != new_x)) { |
| 1628 | hashed_process_data->x.middle = new_x; |
| 1629 | hashed_process_data->x.middle_used = FALSE; |
| 1630 | hashed_process_data->x.middle_marked = FALSE; |
| 1631 | } |
| 1632 | } |
| 1633 | |
| 1634 | return 0; |
| 1635 | } |
| 1636 | |
| 1637 | |
| 1638 | /* Get the filename of the process to print */ |
| 1639 | int after_fs_exec_hook(void *hook_data, void *call_data) |
| 1640 | { |
| 1641 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 1642 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 1643 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 1644 | |
| 1645 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 1646 | |
| 1647 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 1648 | |
| 1649 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
| 1650 | |
| 1651 | guint cpu = tfs->cpu; |
| 1652 | LttvProcessState *process = ts->running_process[cpu]; |
| 1653 | g_assert(process != NULL); |
| 1654 | |
| 1655 | guint pid = process->pid; |
| 1656 | |
| 1657 | /* Well, the process_out existed : we must get it in the process hash |
| 1658 | * or add it, and draw its items. |
| 1659 | */ |
| 1660 | /* Add process to process list (if not present) */ |
| 1661 | guint pl_height = 0; |
| 1662 | HashedProcessData *hashed_process_data = NULL; |
| 1663 | ProcessList *process_list = control_flow_data->process_list; |
| 1664 | LttTime birth = process->creation_time; |
| 1665 | |
| 1666 | if(likely(process_list->current_hash_data[cpu] != NULL)) { |
| 1667 | hashed_process_data = process_list->current_hash_data[cpu]; |
| 1668 | } else { |
| 1669 | hashed_process_data = processlist_get_process_data(process_list, |
| 1670 | pid, |
| 1671 | process->cpu, |
| 1672 | &birth, |
| 1673 | tfc->t_context->index); |
| 1674 | if(unlikely(hashed_process_data == NULL)) |
| 1675 | { |
| 1676 | g_assert(pid == 0 || pid != process->ppid); |
| 1677 | ProcessInfo *process_info; |
| 1678 | /* Process not present */ |
| 1679 | Drawing_t *drawing = control_flow_data->drawing; |
| 1680 | processlist_add(process_list, |
| 1681 | drawing, |
| 1682 | pid, |
| 1683 | process->cpu, |
| 1684 | process->ppid, |
| 1685 | &birth, |
| 1686 | tfc->t_context->index, |
| 1687 | process->name, |
| 1688 | &pl_height, |
| 1689 | &process_info, |
| 1690 | &hashed_process_data); |
| 1691 | gtk_widget_set_size_request(drawing->drawing_area, |
| 1692 | -1, |
| 1693 | pl_height); |
| 1694 | gtk_widget_queue_draw(drawing->drawing_area); |
| 1695 | } |
| 1696 | /* Set the current process */ |
| 1697 | process_list->current_hash_data[process->cpu] = |
| 1698 | hashed_process_data; |
| 1699 | } |
| 1700 | |
| 1701 | processlist_set_name(process_list, process->name, hashed_process_data); |
| 1702 | |
| 1703 | return 0; |
| 1704 | |
| 1705 | } |
| 1706 | |
| 1707 | /* after_event_enum_process_hook |
| 1708 | * |
| 1709 | * Create the processlist entry for the child process. Put the last |
| 1710 | * position in x at the current time value. |
| 1711 | * |
| 1712 | * @param hook_data ControlFlowData structure of the viewer. |
| 1713 | * @param call_data Event context. |
| 1714 | * |
| 1715 | * This function adds items to be drawn in a queue for each process. |
| 1716 | * |
| 1717 | */ |
| 1718 | int after_event_enum_process_hook(void *hook_data, void *call_data) |
| 1719 | { |
| 1720 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 1721 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 1722 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 1723 | |
| 1724 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 1725 | |
| 1726 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 1727 | |
| 1728 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
| 1729 | |
| 1730 | LttEvent *e; |
| 1731 | e = ltt_tracefile_get_event(tfc->tf); |
| 1732 | |
| 1733 | LttTime evtime = ltt_event_time(e); |
| 1734 | |
| 1735 | /* Add process to process list (if not present) */ |
| 1736 | LttvProcessState *process_in; |
| 1737 | LttTime birth; |
| 1738 | guint pl_height = 0; |
| 1739 | HashedProcessData *hashed_process_data_in = NULL; |
| 1740 | |
| 1741 | ProcessList *process_list = control_flow_data->process_list; |
| 1742 | |
| 1743 | guint pid_in; |
| 1744 | { |
| 1745 | pid_in = ltt_event_get_long_unsigned(e, thf->f1); |
| 1746 | } |
| 1747 | |
| 1748 | |
| 1749 | /* Find process pid_in in the list... */ |
| 1750 | process_in = lttv_state_find_process(ts, ANY_CPU, pid_in); |
| 1751 | //process_in = tfs->process; |
| 1752 | //guint cpu = tfs->cpu; |
| 1753 | //process_in = ts->running_process[cpu]; |
| 1754 | /* It should exist, because we are after the state update. */ |
| 1755 | #ifdef EXTRA_CHECK |
| 1756 | //g_assert(process_in != NULL); |
| 1757 | #endif //EXTRA_CHECK |
| 1758 | birth = process_in->creation_time; |
| 1759 | |
| 1760 | hashed_process_data_in = processlist_get_process_data(process_list, |
| 1761 | pid_in, |
| 1762 | process_in->cpu, |
| 1763 | &birth, |
| 1764 | tfc->t_context->index); |
| 1765 | if(hashed_process_data_in == NULL) |
| 1766 | { |
| 1767 | if(pid_in != 0 && pid_in == process_in->ppid) |
| 1768 | g_critical("TEST %u , %u", pid_in, process_in->ppid); |
| 1769 | g_assert(pid_in == 0 || pid_in != process_in->ppid); |
| 1770 | ProcessInfo *process_info; |
| 1771 | Drawing_t *drawing = control_flow_data->drawing; |
| 1772 | /* Process not present */ |
| 1773 | processlist_add(process_list, |
| 1774 | drawing, |
| 1775 | pid_in, |
| 1776 | process_in->cpu, |
| 1777 | process_in->ppid, |
| 1778 | &birth, |
| 1779 | tfc->t_context->index, |
| 1780 | process_in->name, |
| 1781 | &pl_height, |
| 1782 | &process_info, |
| 1783 | &hashed_process_data_in); |
| 1784 | gtk_widget_set_size_request(drawing->drawing_area, |
| 1785 | -1, |
| 1786 | pl_height); |
| 1787 | gtk_widget_queue_draw(drawing->drawing_area); |
| 1788 | } else { |
| 1789 | processlist_set_name(process_list, process_in->name, |
| 1790 | hashed_process_data_in); |
| 1791 | processlist_set_ppid(process_list, process_in->ppid, |
| 1792 | hashed_process_data_in); |
| 1793 | } |
| 1794 | return 0; |
| 1795 | } |
| 1796 | |
| 1797 | |
| 1798 | gint update_time_window_hook(void *hook_data, void *call_data) |
| 1799 | { |
| 1800 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
| 1801 | Drawing_t *drawing = control_flow_data->drawing; |
| 1802 | ProcessList *process_list = control_flow_data->process_list; |
| 1803 | |
| 1804 | const TimeWindowNotifyData *time_window_nofify_data = |
| 1805 | ((const TimeWindowNotifyData *)call_data); |
| 1806 | |
| 1807 | TimeWindow *old_time_window = |
| 1808 | time_window_nofify_data->old_time_window; |
| 1809 | TimeWindow *new_time_window = |
| 1810 | time_window_nofify_data->new_time_window; |
| 1811 | |
| 1812 | /* Update the ruler */ |
| 1813 | drawing_update_ruler(control_flow_data->drawing, |
| 1814 | new_time_window); |
| 1815 | |
| 1816 | |
| 1817 | /* Two cases : zoom in/out or scrolling */ |
| 1818 | |
| 1819 | /* In order to make sure we can reuse the old drawing, the scale must |
| 1820 | * be the same and the new time interval being partly located in the |
| 1821 | * currently shown time interval. (reuse is only for scrolling) |
| 1822 | */ |
| 1823 | |
| 1824 | g_info("Old time window HOOK : %lu, %lu to %lu, %lu", |
| 1825 | old_time_window->start_time.tv_sec, |
| 1826 | old_time_window->start_time.tv_nsec, |
| 1827 | old_time_window->time_width.tv_sec, |
| 1828 | old_time_window->time_width.tv_nsec); |
| 1829 | |
| 1830 | g_info("New time window HOOK : %lu, %lu to %lu, %lu", |
| 1831 | new_time_window->start_time.tv_sec, |
| 1832 | new_time_window->start_time.tv_nsec, |
| 1833 | new_time_window->time_width.tv_sec, |
| 1834 | new_time_window->time_width.tv_nsec); |
| 1835 | |
| 1836 | if( new_time_window->time_width.tv_sec == old_time_window->time_width.tv_sec |
| 1837 | && new_time_window->time_width.tv_nsec == old_time_window->time_width.tv_nsec) |
| 1838 | { |
| 1839 | /* Same scale (scrolling) */ |
| 1840 | g_info("scrolling"); |
| 1841 | LttTime *ns = &new_time_window->start_time; |
| 1842 | LttTime *nw = &new_time_window->time_width; |
| 1843 | LttTime *os = &old_time_window->start_time; |
| 1844 | LttTime *ow = &old_time_window->time_width; |
| 1845 | LttTime old_end = old_time_window->end_time; |
| 1846 | LttTime new_end = new_time_window->end_time; |
| 1847 | //if(ns<os+w<ns+w) |
| 1848 | //if(ns<os+w && os+w<ns+w) |
| 1849 | //if(ns<old_end && os<ns) |
| 1850 | if(ltt_time_compare(*ns, old_end) == -1 |
| 1851 | && ltt_time_compare(*os, *ns) == -1) |
| 1852 | { |
| 1853 | g_info("scrolling near right"); |
| 1854 | /* Scroll right, keep right part of the screen */ |
| 1855 | guint x = 0; |
| 1856 | guint width = control_flow_data->drawing->width; |
| 1857 | convert_time_to_pixels( |
| 1858 | *old_time_window, |
| 1859 | *ns, |
| 1860 | width, |
| 1861 | &x); |
| 1862 | |
| 1863 | /* Copy old data to new location */ |
| 1864 | copy_pixmap_region(process_list, |
| 1865 | NULL, |
| 1866 | control_flow_data->drawing->drawing_area->style->black_gc, |
| 1867 | NULL, |
| 1868 | x, 0, |
| 1869 | 0, 0, |
| 1870 | control_flow_data->drawing->width-x+SAFETY, -1); |
| 1871 | |
| 1872 | if(drawing->damage_begin == drawing->damage_end) |
| 1873 | drawing->damage_begin = control_flow_data->drawing->width-x; |
| 1874 | else |
| 1875 | drawing->damage_begin = 0; |
| 1876 | |
| 1877 | drawing->damage_end = control_flow_data->drawing->width; |
| 1878 | |
| 1879 | /* Clear the data request background, but not SAFETY */ |
| 1880 | rectangle_pixmap(process_list, |
| 1881 | control_flow_data->drawing->drawing_area->style->black_gc, |
| 1882 | TRUE, |
| 1883 | drawing->damage_begin+SAFETY, 0, |
| 1884 | drawing->damage_end - drawing->damage_begin, // do not overlap |
| 1885 | -1); |
| 1886 | gtk_widget_queue_draw(drawing->drawing_area); |
| 1887 | //gtk_widget_queue_draw_area (drawing->drawing_area, |
| 1888 | // 0,0, |
| 1889 | // control_flow_data->drawing->width, |
| 1890 | // control_flow_data->drawing->height); |
| 1891 | |
| 1892 | /* Get new data for the rest. */ |
| 1893 | drawing_data_request(control_flow_data->drawing, |
| 1894 | drawing->damage_begin, 0, |
| 1895 | drawing->damage_end - drawing->damage_begin, |
| 1896 | control_flow_data->drawing->height); |
| 1897 | } else { |
| 1898 | //if(ns<os<ns+w) |
| 1899 | //if(ns<os && os<ns+w) |
| 1900 | //if(ns<os && os<new_end) |
| 1901 | if(ltt_time_compare(*ns,*os) == -1 |
| 1902 | && ltt_time_compare(*os,new_end) == -1) |
| 1903 | { |
| 1904 | g_info("scrolling near left"); |
| 1905 | /* Scroll left, keep left part of the screen */ |
| 1906 | guint x = 0; |
| 1907 | guint width = control_flow_data->drawing->width; |
| 1908 | convert_time_to_pixels( |
| 1909 | *new_time_window, |
| 1910 | *os, |
| 1911 | width, |
| 1912 | &x); |
| 1913 | |
| 1914 | /* Copy old data to new location */ |
| 1915 | copy_pixmap_region (process_list, |
| 1916 | NULL, |
| 1917 | control_flow_data->drawing->drawing_area->style->black_gc, |
| 1918 | NULL, |
| 1919 | 0, 0, |
| 1920 | x, 0, |
| 1921 | -1, -1); |
| 1922 | |
| 1923 | if(drawing->damage_begin == drawing->damage_end) |
| 1924 | drawing->damage_end = x; |
| 1925 | else |
| 1926 | drawing->damage_end = |
| 1927 | control_flow_data->drawing->width; |
| 1928 | |
| 1929 | drawing->damage_begin = 0; |
| 1930 | |
| 1931 | rectangle_pixmap (process_list, |
| 1932 | control_flow_data->drawing->drawing_area->style->black_gc, |
| 1933 | TRUE, |
| 1934 | drawing->damage_begin, 0, |
| 1935 | drawing->damage_end - drawing->damage_begin, // do not overlap |
| 1936 | -1); |
| 1937 | |
| 1938 | gtk_widget_queue_draw(drawing->drawing_area); |
| 1939 | //gtk_widget_queue_draw_area (drawing->drawing_area, |
| 1940 | // 0,0, |
| 1941 | // control_flow_data->drawing->width, |
| 1942 | // control_flow_data->drawing->height); |
| 1943 | |
| 1944 | |
| 1945 | /* Get new data for the rest. */ |
| 1946 | drawing_data_request(control_flow_data->drawing, |
| 1947 | drawing->damage_begin, 0, |
| 1948 | drawing->damage_end - drawing->damage_begin, |
| 1949 | control_flow_data->drawing->height); |
| 1950 | |
| 1951 | } else { |
| 1952 | if(ltt_time_compare(*ns,*os) == 0) |
| 1953 | { |
| 1954 | g_info("not scrolling"); |
| 1955 | } else { |
| 1956 | g_info("scrolling far"); |
| 1957 | /* Cannot reuse any part of the screen : far jump */ |
| 1958 | |
| 1959 | |
| 1960 | rectangle_pixmap (process_list, |
| 1961 | control_flow_data->drawing->drawing_area->style->black_gc, |
| 1962 | TRUE, |
| 1963 | 0, 0, |
| 1964 | control_flow_data->drawing->width+SAFETY, // do not overlap |
| 1965 | -1); |
| 1966 | |
| 1967 | //gtk_widget_queue_draw_area (drawing->drawing_area, |
| 1968 | // 0,0, |
| 1969 | // control_flow_data->drawing->width, |
| 1970 | // control_flow_data->drawing->height); |
| 1971 | gtk_widget_queue_draw(drawing->drawing_area); |
| 1972 | |
| 1973 | drawing->damage_begin = 0; |
| 1974 | drawing->damage_end = control_flow_data->drawing->width; |
| 1975 | |
| 1976 | drawing_data_request(control_flow_data->drawing, |
| 1977 | 0, 0, |
| 1978 | control_flow_data->drawing->width, |
| 1979 | control_flow_data->drawing->height); |
| 1980 | |
| 1981 | } |
| 1982 | } |
| 1983 | } |
| 1984 | } else { |
| 1985 | /* Different scale (zoom) */ |
| 1986 | g_info("zoom"); |
| 1987 | |
| 1988 | rectangle_pixmap (process_list, |
| 1989 | control_flow_data->drawing->drawing_area->style->black_gc, |
| 1990 | TRUE, |
| 1991 | 0, 0, |
| 1992 | control_flow_data->drawing->width+SAFETY, // do not overlap |
| 1993 | -1); |
| 1994 | |
| 1995 | //gtk_widget_queue_draw_area (drawing->drawing_area, |
| 1996 | // 0,0, |
| 1997 | // control_flow_data->drawing->width, |
| 1998 | // control_flow_data->drawing->height); |
| 1999 | gtk_widget_queue_draw(drawing->drawing_area); |
| 2000 | |
| 2001 | drawing->damage_begin = 0; |
| 2002 | drawing->damage_end = control_flow_data->drawing->width; |
| 2003 | |
| 2004 | drawing_data_request(control_flow_data->drawing, |
| 2005 | 0, 0, |
| 2006 | control_flow_data->drawing->width, |
| 2007 | control_flow_data->drawing->height); |
| 2008 | } |
| 2009 | |
| 2010 | /* Update directly when scrolling */ |
| 2011 | gdk_window_process_updates(control_flow_data->drawing->drawing_area->window, |
| 2012 | TRUE); |
| 2013 | |
| 2014 | return 0; |
| 2015 | } |
| 2016 | |
| 2017 | gint traceset_notify(void *hook_data, void *call_data) |
| 2018 | { |
| 2019 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
| 2020 | Drawing_t *drawing = control_flow_data->drawing; |
| 2021 | |
| 2022 | if(unlikely(drawing->gc == NULL)) { |
| 2023 | return FALSE; |
| 2024 | } |
| 2025 | if(drawing->dotted_gc == NULL) { |
| 2026 | return FALSE; |
| 2027 | } |
| 2028 | |
| 2029 | drawing_clear(control_flow_data->drawing); |
| 2030 | processlist_clear(control_flow_data->process_list); |
| 2031 | gtk_widget_set_size_request( |
| 2032 | control_flow_data->drawing->drawing_area, |
| 2033 | -1, processlist_get_height(control_flow_data->process_list)); |
| 2034 | redraw_notify(control_flow_data, NULL); |
| 2035 | |
| 2036 | request_background_data(control_flow_data); |
| 2037 | |
| 2038 | return FALSE; |
| 2039 | } |
| 2040 | |
| 2041 | gint redraw_notify(void *hook_data, void *call_data) |
| 2042 | { |
| 2043 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
| 2044 | Drawing_t *drawing = control_flow_data->drawing; |
| 2045 | GtkWidget *widget = drawing->drawing_area; |
| 2046 | |
| 2047 | drawing->damage_begin = 0; |
| 2048 | drawing->damage_end = drawing->width; |
| 2049 | |
| 2050 | /* fun feature, to be separated someday... */ |
| 2051 | drawing_clear(control_flow_data->drawing); |
| 2052 | processlist_clear(control_flow_data->process_list); |
| 2053 | gtk_widget_set_size_request( |
| 2054 | control_flow_data->drawing->drawing_area, |
| 2055 | -1, processlist_get_height(control_flow_data->process_list)); |
| 2056 | // Clear the images |
| 2057 | rectangle_pixmap (control_flow_data->process_list, |
| 2058 | widget->style->black_gc, |
| 2059 | TRUE, |
| 2060 | 0, 0, |
| 2061 | drawing->alloc_width, |
| 2062 | -1); |
| 2063 | |
| 2064 | gtk_widget_queue_draw(drawing->drawing_area); |
| 2065 | |
| 2066 | if(drawing->damage_begin < drawing->damage_end) |
| 2067 | { |
| 2068 | drawing_data_request(drawing, |
| 2069 | drawing->damage_begin, |
| 2070 | 0, |
| 2071 | drawing->damage_end-drawing->damage_begin, |
| 2072 | drawing->height); |
| 2073 | } |
| 2074 | |
| 2075 | //gtk_widget_queue_draw_area(drawing->drawing_area, |
| 2076 | // 0,0, |
| 2077 | // drawing->width, |
| 2078 | // drawing->height); |
| 2079 | return FALSE; |
| 2080 | |
| 2081 | } |
| 2082 | |
| 2083 | |
| 2084 | gint continue_notify(void *hook_data, void *call_data) |
| 2085 | { |
| 2086 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
| 2087 | Drawing_t *drawing = control_flow_data->drawing; |
| 2088 | |
| 2089 | //g_assert(widget->allocation.width == drawing->damage_end); |
| 2090 | |
| 2091 | if(drawing->damage_begin < drawing->damage_end) |
| 2092 | { |
| 2093 | drawing_data_request(drawing, |
| 2094 | drawing->damage_begin, |
| 2095 | 0, |
| 2096 | drawing->damage_end-drawing->damage_begin, |
| 2097 | drawing->height); |
| 2098 | } |
| 2099 | |
| 2100 | return FALSE; |
| 2101 | } |
| 2102 | |
| 2103 | |
| 2104 | gint update_current_time_hook(void *hook_data, void *call_data) |
| 2105 | { |
| 2106 | ControlFlowData *control_flow_data = (ControlFlowData*)hook_data; |
| 2107 | Drawing_t *drawing = control_flow_data->drawing; |
| 2108 | |
| 2109 | LttTime current_time = *((LttTime*)call_data); |
| 2110 | |
| 2111 | TimeWindow time_window = |
| 2112 | lttvwindow_get_time_window(control_flow_data->tab); |
| 2113 | |
| 2114 | LttTime time_begin = time_window.start_time; |
| 2115 | LttTime width = time_window.time_width; |
| 2116 | LttTime half_width; |
| 2117 | { |
| 2118 | guint64 time_ll = ltt_time_to_uint64(width); |
| 2119 | time_ll = time_ll >> 1; /* divide by two */ |
| 2120 | half_width = ltt_time_from_uint64(time_ll); |
| 2121 | } |
| 2122 | LttTime time_end = ltt_time_add(time_begin, width); |
| 2123 | |
| 2124 | LttvTracesetContext * tsc = |
| 2125 | lttvwindow_get_traceset_context(control_flow_data->tab); |
| 2126 | |
| 2127 | LttTime trace_start = tsc->time_span.start_time; |
| 2128 | LttTime trace_end = tsc->time_span.end_time; |
| 2129 | |
| 2130 | g_info("New current time HOOK : %lu, %lu", current_time.tv_sec, |
| 2131 | current_time.tv_nsec); |
| 2132 | |
| 2133 | |
| 2134 | |
| 2135 | /* If current time is inside time interval, just move the highlight |
| 2136 | * bar */ |
| 2137 | |
| 2138 | /* Else, we have to change the time interval. We have to tell it |
| 2139 | * to the main window. */ |
| 2140 | /* The time interval change will take care of placing the current |
| 2141 | * time at the center of the visible area, or nearest possible if we are |
| 2142 | * at one end of the trace. */ |
| 2143 | |
| 2144 | |
| 2145 | if(ltt_time_compare(current_time, time_begin) < 0) |
| 2146 | { |
| 2147 | TimeWindow new_time_window; |
| 2148 | |
| 2149 | if(ltt_time_compare(current_time, |
| 2150 | ltt_time_add(trace_start,half_width)) < 0) |
| 2151 | time_begin = trace_start; |
| 2152 | else |
| 2153 | time_begin = ltt_time_sub(current_time,half_width); |
| 2154 | |
| 2155 | new_time_window.start_time = time_begin; |
| 2156 | new_time_window.time_width = width; |
| 2157 | new_time_window.time_width_double = ltt_time_to_double(width); |
| 2158 | new_time_window.end_time = ltt_time_add(time_begin, width); |
| 2159 | |
| 2160 | lttvwindow_report_time_window(control_flow_data->tab, new_time_window); |
| 2161 | } |
| 2162 | else if(ltt_time_compare(current_time, time_end) > 0) |
| 2163 | { |
| 2164 | TimeWindow new_time_window; |
| 2165 | |
| 2166 | if(ltt_time_compare(current_time, ltt_time_sub(trace_end, half_width)) > 0) |
| 2167 | time_begin = ltt_time_sub(trace_end,width); |
| 2168 | else |
| 2169 | time_begin = ltt_time_sub(current_time,half_width); |
| 2170 | |
| 2171 | new_time_window.start_time = time_begin; |
| 2172 | new_time_window.time_width = width; |
| 2173 | new_time_window.time_width_double = ltt_time_to_double(width); |
| 2174 | new_time_window.end_time = ltt_time_add(time_begin, width); |
| 2175 | |
| 2176 | lttvwindow_report_time_window(control_flow_data->tab, new_time_window); |
| 2177 | |
| 2178 | } |
| 2179 | gtk_widget_queue_draw(control_flow_data->drawing->drawing_area); |
| 2180 | |
| 2181 | /* Update directly when scrolling */ |
| 2182 | gdk_window_process_updates(control_flow_data->drawing->drawing_area->window, |
| 2183 | TRUE); |
| 2184 | |
| 2185 | return 0; |
| 2186 | } |
| 2187 | |
| 2188 | typedef struct _ClosureData { |
| 2189 | EventsRequest *events_request; |
| 2190 | LttvTracesetState *tss; |
| 2191 | LttTime end_time; |
| 2192 | guint x_end; |
| 2193 | } ClosureData; |
| 2194 | |
| 2195 | |
| 2196 | void draw_closure(gpointer key, gpointer value, gpointer user_data) |
| 2197 | { |
| 2198 | ProcessInfo *process_info = (ProcessInfo*)key; |
| 2199 | HashedProcessData *hashed_process_data = (HashedProcessData*)value; |
| 2200 | ClosureData *closure_data = (ClosureData*)user_data; |
| 2201 | |
| 2202 | EventsRequest *events_request = closure_data->events_request; |
| 2203 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 2204 | |
| 2205 | LttvTracesetState *tss = closure_data->tss; |
| 2206 | LttvTracesetContext *tsc = (LttvTracesetContext*)tss; |
| 2207 | |
| 2208 | LttTime evtime = closure_data->end_time; |
| 2209 | |
| 2210 | { |
| 2211 | /* For the process */ |
| 2212 | /* First, check if the current process is in the state computation |
| 2213 | * process list. If it is there, that means we must add it right now and |
| 2214 | * draw items from the beginning of the read for it. If it is not |
| 2215 | * present, it's a new process and it was not present : it will |
| 2216 | * be added after the state update. */ |
| 2217 | #ifdef EXTRA_CHECK |
| 2218 | g_assert(lttv_traceset_number(tsc->ts) > 0); |
| 2219 | #endif //EXTRA_CHECK |
| 2220 | LttvTraceContext *tc = tsc->traces[process_info->trace_num]; |
| 2221 | LttvTraceState *ts = (LttvTraceState*)tc; |
| 2222 | |
| 2223 | #if 0 |
| 2224 | //FIXME : optimize data structures. |
| 2225 | LttvTracefileState *tfs; |
| 2226 | LttvTracefileContext *tfc; |
| 2227 | guint i; |
| 2228 | for(i=0;i<tc->tracefiles->len;i++) { |
| 2229 | tfc = g_array_index(tc->tracefiles, LttvTracefileContext*, i); |
| 2230 | if(ltt_tracefile_name(tfc->tf) == LTT_NAME_CPU |
| 2231 | && tfs->cpu == process_info->cpu) |
| 2232 | break; |
| 2233 | |
| 2234 | } |
| 2235 | g_assert(i<tc->tracefiles->len); |
| 2236 | tfs = LTTV_TRACEFILE_STATE(tfc); |
| 2237 | #endif //0 |
| 2238 | // LttvTracefileState *tfs = |
| 2239 | // (LttvTracefileState*)tsc->traces[process_info->trace_num]-> |
| 2240 | // tracefiles[process_info->cpu]; |
| 2241 | |
| 2242 | LttvProcessState *process; |
| 2243 | process = lttv_state_find_process(ts, process_info->cpu, |
| 2244 | process_info->pid); |
| 2245 | |
| 2246 | if(unlikely(process != NULL)) { |
| 2247 | |
| 2248 | /* Only draw for processes that are currently in the trace states */ |
| 2249 | |
| 2250 | ProcessList *process_list = control_flow_data->process_list; |
| 2251 | #ifdef EXTRA_CHECK |
| 2252 | /* Should be alike when background info is ready */ |
| 2253 | if(control_flow_data->background_info_waiting==0) |
| 2254 | g_assert(ltt_time_compare(process->creation_time, |
| 2255 | process_info->birth) == 0); |
| 2256 | #endif //EXTRA_CHECK |
| 2257 | |
| 2258 | /* Now, the process is in the state hash and our own process hash. |
| 2259 | * We definitely can draw the items related to the ending state. |
| 2260 | */ |
| 2261 | |
| 2262 | if(unlikely(ltt_time_compare(hashed_process_data->next_good_time, |
| 2263 | evtime) <= 0)) |
| 2264 | { |
| 2265 | TimeWindow time_window = |
| 2266 | lttvwindow_get_time_window(control_flow_data->tab); |
| 2267 | |
| 2268 | #ifdef EXTRA_CHECK |
| 2269 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 2270 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 2271 | return; |
| 2272 | #endif //EXTRA_CHECK |
| 2273 | Drawing_t *drawing = control_flow_data->drawing; |
| 2274 | guint width = drawing->width; |
| 2275 | |
| 2276 | guint x = closure_data->x_end; |
| 2277 | |
| 2278 | DrawContext draw_context; |
| 2279 | |
| 2280 | /* Now create the drawing context that will be used to draw |
| 2281 | * items related to the last state. */ |
| 2282 | draw_context.drawable = hashed_process_data->pixmap; |
| 2283 | draw_context.gc = drawing->gc; |
| 2284 | draw_context.pango_layout = drawing->pango_layout; |
| 2285 | draw_context.drawinfo.end.x = x; |
| 2286 | |
| 2287 | draw_context.drawinfo.y.over = 1; |
| 2288 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
| 2289 | draw_context.drawinfo.y.under = hashed_process_data->height; |
| 2290 | |
| 2291 | draw_context.drawinfo.start.offset.over = 0; |
| 2292 | draw_context.drawinfo.start.offset.middle = 0; |
| 2293 | draw_context.drawinfo.start.offset.under = 0; |
| 2294 | draw_context.drawinfo.end.offset.over = 0; |
| 2295 | draw_context.drawinfo.end.offset.middle = 0; |
| 2296 | draw_context.drawinfo.end.offset.under = 0; |
| 2297 | #if 0 |
| 2298 | /* Jump over draw if we are at the same x position */ |
| 2299 | if(x == hashed_process_data->x.over) |
| 2300 | { |
| 2301 | /* jump */ |
| 2302 | } else { |
| 2303 | draw_context.drawinfo.start.x = hashed_process_data->x.over; |
| 2304 | /* Draw the line */ |
| 2305 | PropertiesLine prop_line = prepare_execmode_line(process); |
| 2306 | draw_line((void*)&prop_line, (void*)&draw_context); |
| 2307 | |
| 2308 | hashed_process_data->x.over = x; |
| 2309 | } |
| 2310 | #endif //0 |
| 2311 | |
| 2312 | if(unlikely(x == hashed_process_data->x.middle && |
| 2313 | hashed_process_data->x.middle_used)) { |
| 2314 | #if 0 /* do not mark closure : not missing information */ |
| 2315 | if(hashed_process_data->x.middle_marked == FALSE) { |
| 2316 | /* Draw collision indicator */ |
| 2317 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 2318 | gdk_draw_point(drawing->pixmap, |
| 2319 | drawing->gc, |
| 2320 | x, |
| 2321 | y+(height/2)-3); |
| 2322 | hashed_process_data->x.middle_marked = TRUE; |
| 2323 | } |
| 2324 | #endif //0 |
| 2325 | /* Jump */ |
| 2326 | } else { |
| 2327 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
| 2328 | /* Draw the line */ |
| 2329 | PropertiesLine prop_line = prepare_s_e_line(process); |
| 2330 | draw_line((void*)&prop_line, (void*)&draw_context); |
| 2331 | |
| 2332 | /* become the last x position */ |
| 2333 | if(likely(x != hashed_process_data->x.middle)) { |
| 2334 | hashed_process_data->x.middle = x; |
| 2335 | /* but don't use the pixel */ |
| 2336 | hashed_process_data->x.middle_used = FALSE; |
| 2337 | |
| 2338 | /* Calculate the next good time */ |
| 2339 | convert_pixels_to_time(width, x+1, time_window, |
| 2340 | &hashed_process_data->next_good_time); |
| 2341 | } |
| 2342 | } |
| 2343 | } |
| 2344 | } |
| 2345 | } |
| 2346 | return; |
| 2347 | } |
| 2348 | |
| 2349 | int before_chunk(void *hook_data, void *call_data) |
| 2350 | { |
| 2351 | EventsRequest *events_request = (EventsRequest*)hook_data; |
| 2352 | LttvTracesetState *tss = (LttvTracesetState*)call_data; |
| 2353 | ControlFlowData *cfd = (ControlFlowData*)events_request->viewer_data; |
| 2354 | #if 0 |
| 2355 | /* Desactivate sort */ |
| 2356 | gtk_tree_sortable_set_sort_column_id( |
| 2357 | GTK_TREE_SORTABLE(cfd->process_list->list_store), |
| 2358 | TRACE_COLUMN, |
| 2359 | GTK_SORT_ASCENDING); |
| 2360 | #endif //0 |
| 2361 | drawing_chunk_begin(events_request, tss); |
| 2362 | |
| 2363 | return 0; |
| 2364 | } |
| 2365 | |
| 2366 | int before_request(void *hook_data, void *call_data) |
| 2367 | { |
| 2368 | EventsRequest *events_request = (EventsRequest*)hook_data; |
| 2369 | LttvTracesetState *tss = (LttvTracesetState*)call_data; |
| 2370 | |
| 2371 | drawing_data_request_begin(events_request, tss); |
| 2372 | |
| 2373 | return 0; |
| 2374 | } |
| 2375 | |
| 2376 | |
| 2377 | /* |
| 2378 | * after request is necessary in addition of after chunk in order to draw |
| 2379 | * lines until the end of the screen. after chunk just draws lines until |
| 2380 | * the last event. |
| 2381 | * |
| 2382 | * for each process |
| 2383 | * draw closing line |
| 2384 | * expose |
| 2385 | */ |
| 2386 | int after_request(void *hook_data, void *call_data) |
| 2387 | { |
| 2388 | EventsRequest *events_request = (EventsRequest*)hook_data; |
| 2389 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 2390 | LttvTracesetState *tss = (LttvTracesetState*)call_data; |
| 2391 | |
| 2392 | ProcessList *process_list = control_flow_data->process_list; |
| 2393 | LttTime end_time = events_request->end_time; |
| 2394 | |
| 2395 | ClosureData closure_data; |
| 2396 | closure_data.events_request = (EventsRequest*)hook_data; |
| 2397 | closure_data.tss = tss; |
| 2398 | closure_data.end_time = end_time; |
| 2399 | |
| 2400 | TimeWindow time_window = |
| 2401 | lttvwindow_get_time_window(control_flow_data->tab); |
| 2402 | guint width = control_flow_data->drawing->width; |
| 2403 | convert_time_to_pixels( |
| 2404 | time_window, |
| 2405 | end_time, |
| 2406 | width, |
| 2407 | &closure_data.x_end); |
| 2408 | |
| 2409 | |
| 2410 | /* Draw last items */ |
| 2411 | g_hash_table_foreach(process_list->process_hash, draw_closure, |
| 2412 | (void*)&closure_data); |
| 2413 | |
| 2414 | |
| 2415 | /* Request expose */ |
| 2416 | drawing_request_expose(events_request, tss, end_time); |
| 2417 | return 0; |
| 2418 | } |
| 2419 | |
| 2420 | /* |
| 2421 | * for each process |
| 2422 | * draw closing line |
| 2423 | * expose |
| 2424 | */ |
| 2425 | int after_chunk(void *hook_data, void *call_data) |
| 2426 | { |
| 2427 | EventsRequest *events_request = (EventsRequest*)hook_data; |
| 2428 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 2429 | LttvTracesetState *tss = (LttvTracesetState*)call_data; |
| 2430 | LttvTracesetContext *tsc = (LttvTracesetContext*)call_data; |
| 2431 | LttvTracefileContext *tfc = lttv_traceset_context_get_current_tfc(tsc); |
| 2432 | LttTime end_time; |
| 2433 | |
| 2434 | ProcessList *process_list = control_flow_data->process_list; |
| 2435 | |
| 2436 | g_free(process_list->current_hash_data); |
| 2437 | process_list->current_hash_data = NULL; |
| 2438 | |
| 2439 | if(tfc != NULL) |
| 2440 | end_time = LTT_TIME_MIN(tfc->timestamp, events_request->end_time); |
| 2441 | else /* end of traceset, or position now out of request : end */ |
| 2442 | end_time = events_request->end_time; |
| 2443 | |
| 2444 | ClosureData closure_data; |
| 2445 | closure_data.events_request = (EventsRequest*)hook_data; |
| 2446 | closure_data.tss = tss; |
| 2447 | closure_data.end_time = end_time; |
| 2448 | |
| 2449 | TimeWindow time_window = |
| 2450 | lttvwindow_get_time_window(control_flow_data->tab); |
| 2451 | guint width = control_flow_data->drawing->width; |
| 2452 | convert_time_to_pixels( |
| 2453 | time_window, |
| 2454 | end_time, |
| 2455 | width, |
| 2456 | &closure_data.x_end); |
| 2457 | |
| 2458 | /* Draw last items */ |
| 2459 | g_hash_table_foreach(process_list->process_hash, draw_closure, |
| 2460 | (void*)&closure_data); |
| 2461 | #if 0 |
| 2462 | /* Reactivate sort */ |
| 2463 | gtk_tree_sortable_set_sort_column_id( |
| 2464 | GTK_TREE_SORTABLE(control_flow_data->process_list->list_store), |
| 2465 | GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, |
| 2466 | GTK_SORT_ASCENDING); |
| 2467 | |
| 2468 | update_index_to_pixmap(control_flow_data->process_list); |
| 2469 | /* Request a full expose : drawing scrambled */ |
| 2470 | gtk_widget_queue_draw(control_flow_data->drawing->drawing_area); |
| 2471 | #endif //0 |
| 2472 | /* Request expose (updates damages zone also) */ |
| 2473 | drawing_request_expose(events_request, tss, end_time); |
| 2474 | |
| 2475 | return 0; |
| 2476 | } |
| 2477 | |