| 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 | |
| 73 | |
| 74 | #include "eventhooks.h" |
| 75 | #include "cfv.h" |
| 76 | #include "processlist.h" |
| 77 | #include "drawing.h" |
| 78 | |
| 79 | |
| 80 | #define MAX_PATH_LEN 256 |
| 81 | |
| 82 | #if 0 |
| 83 | typedef struct _ProcessAddClosure { |
| 84 | ControlFlowData *cfd; |
| 85 | guint trace_num; |
| 86 | } ProcessAddClosure; |
| 87 | |
| 88 | static void process_add(gpointer key, |
| 89 | gpointer value, |
| 90 | gpointer user_data) |
| 91 | { |
| 92 | LttvProcessState *process = (LttvProcessState*)value; |
| 93 | ProcessAddClosure *closure = (ProcessAddClosure*)user_data; |
| 94 | ControlFlowData *control_flow_data = closure->cfd; |
| 95 | guint trace_num = closure->trace_num; |
| 96 | |
| 97 | /* Add process to process list (if not present) */ |
| 98 | guint pid; |
| 99 | LttTime birth; |
| 100 | guint y = 0, height = 0, pl_height = 0; |
| 101 | |
| 102 | ProcessList *process_list = control_flow_data->process_list; |
| 103 | |
| 104 | pid = process->pid; |
| 105 | birth = process->creation_time; |
| 106 | const gchar *name = g_quark_to_string(process->name); |
| 107 | HashedProcessData *hashed_process_data = NULL; |
| 108 | |
| 109 | if(processlist_get_process_pixels(process_list, |
| 110 | pid, |
| 111 | &birth, |
| 112 | trace_num, |
| 113 | &y, |
| 114 | &height, |
| 115 | &hashed_process_data) == 1) |
| 116 | { |
| 117 | /* Process not present */ |
| 118 | processlist_add(process_list, |
| 119 | pid, |
| 120 | &birth, |
| 121 | trace_num, |
| 122 | name, |
| 123 | &pl_height, |
| 124 | &hashed_process_data); |
| 125 | processlist_get_process_pixels(process_list, |
| 126 | pid, |
| 127 | &birth, |
| 128 | trace_num, |
| 129 | &y, |
| 130 | &height, |
| 131 | &hashed_process_data); |
| 132 | drawing_insert_square( control_flow_data->drawing, y, height); |
| 133 | } |
| 134 | } |
| 135 | #endif //0 |
| 136 | |
| 137 | |
| 138 | /* Action to do when background computation completed. |
| 139 | * |
| 140 | * Wait for all the awaited computations to be over. |
| 141 | */ |
| 142 | |
| 143 | gint background_ready(void *hook_data, void *call_data) |
| 144 | { |
| 145 | ControlFlowData *control_flow_data = (ControlFlowData *)hook_data; |
| 146 | LttvTrace *trace = (LttvTrace*)call_data; |
| 147 | |
| 148 | control_flow_data->background_info_waiting--; |
| 149 | |
| 150 | if(control_flow_data->background_info_waiting == 0) { |
| 151 | g_debug("control flow viewer : background computation data ready."); |
| 152 | |
| 153 | drawing_clear(control_flow_data->drawing); |
| 154 | processlist_clear(control_flow_data->process_list); |
| 155 | gtk_widget_set_size_request( |
| 156 | control_flow_data->drawing->drawing_area, |
| 157 | -1, processlist_get_height(control_flow_data->process_list)); |
| 158 | redraw_notify(control_flow_data, NULL); |
| 159 | } |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | |
| 165 | /* Request background computation. Verify if it is in progress or ready first. |
| 166 | * Only for each trace in the tab's traceset. |
| 167 | */ |
| 168 | void request_background_data(ControlFlowData *control_flow_data) |
| 169 | { |
| 170 | LttvTracesetContext * tsc = |
| 171 | lttvwindow_get_traceset_context(control_flow_data->tab); |
| 172 | gint num_traces = lttv_traceset_number(tsc->ts); |
| 173 | gint i; |
| 174 | LttvTrace *trace; |
| 175 | |
| 176 | LttvHooks *background_ready_hook = |
| 177 | lttv_hooks_new(); |
| 178 | lttv_hooks_add(background_ready_hook, background_ready, control_flow_data, |
| 179 | LTTV_PRIO_DEFAULT); |
| 180 | control_flow_data->background_info_waiting = 0; |
| 181 | |
| 182 | for(i=0;i<num_traces;i++) { |
| 183 | trace = lttv_traceset_get(tsc->ts, i); |
| 184 | |
| 185 | if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace)==FALSE) { |
| 186 | |
| 187 | if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"), |
| 188 | trace) == FALSE) { |
| 189 | /* We first remove requests that could have been done for the same |
| 190 | * information. Happens when two viewers ask for it before servicing |
| 191 | * starts. |
| 192 | */ |
| 193 | lttvwindowtraces_background_request_remove(trace, "state"); |
| 194 | lttvwindowtraces_background_request_queue(trace, |
| 195 | "state"); |
| 196 | lttvwindowtraces_background_notify_queue(control_flow_data, |
| 197 | trace, |
| 198 | ltt_time_infinite, |
| 199 | NULL, |
| 200 | background_ready_hook); |
| 201 | control_flow_data->background_info_waiting++; |
| 202 | } else { /* in progress */ |
| 203 | |
| 204 | lttvwindowtraces_background_notify_current(control_flow_data, |
| 205 | trace, |
| 206 | ltt_time_infinite, |
| 207 | NULL, |
| 208 | background_ready_hook); |
| 209 | control_flow_data->background_info_waiting++; |
| 210 | } |
| 211 | } else { |
| 212 | /* Data ready. Be its nature, this viewer doesn't need to have |
| 213 | * its data ready hook called htere, because a background |
| 214 | * request is always linked with a redraw. |
| 215 | */ |
| 216 | } |
| 217 | |
| 218 | } |
| 219 | |
| 220 | lttv_hooks_destroy(background_ready_hook); |
| 221 | } |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | /** |
| 227 | * Event Viewer's constructor hook |
| 228 | * |
| 229 | * This constructor is given as a parameter to the menuitem and toolbar button |
| 230 | * registration. It creates the list. |
| 231 | * @param tab A pointer to the parent tab. |
| 232 | * @return The widget created. |
| 233 | */ |
| 234 | GtkWidget * |
| 235 | h_guicontrolflow(Tab *tab) |
| 236 | { |
| 237 | g_info("h_guicontrolflow, %p", tab); |
| 238 | ControlFlowData *control_flow_data = guicontrolflow() ; |
| 239 | |
| 240 | control_flow_data->tab = tab; |
| 241 | |
| 242 | // Unreg done in the GuiControlFlow_Destructor |
| 243 | lttvwindow_register_traceset_notify(tab, |
| 244 | traceset_notify, |
| 245 | control_flow_data); |
| 246 | |
| 247 | lttvwindow_register_time_window_notify(tab, |
| 248 | update_time_window_hook, |
| 249 | control_flow_data); |
| 250 | lttvwindow_register_current_time_notify(tab, |
| 251 | update_current_time_hook, |
| 252 | control_flow_data); |
| 253 | lttvwindow_register_redraw_notify(tab, |
| 254 | redraw_notify, |
| 255 | control_flow_data); |
| 256 | lttvwindow_register_continue_notify(tab, |
| 257 | continue_notify, |
| 258 | control_flow_data); |
| 259 | request_background_data(control_flow_data); |
| 260 | |
| 261 | |
| 262 | return guicontrolflow_get_widget(control_flow_data) ; |
| 263 | |
| 264 | } |
| 265 | |
| 266 | int event_selected_hook(void *hook_data, void *call_data) |
| 267 | { |
| 268 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
| 269 | guint *event_number = (guint*) call_data; |
| 270 | |
| 271 | g_debug("DEBUG : event selected by main window : %u", *event_number); |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | /* Function that selects the color of status&exemode line */ |
| 277 | static inline PropertiesLine prepare_s_e_line(LttvProcessState *process) |
| 278 | { |
| 279 | PropertiesLine prop_line; |
| 280 | prop_line.line_width = 2; |
| 281 | prop_line.style = GDK_LINE_SOLID; |
| 282 | prop_line.y = MIDDLE; |
| 283 | //GdkColormap *colormap = gdk_colormap_get_system(); |
| 284 | |
| 285 | if(process->state->s == LTTV_STATE_RUN) { |
| 286 | if(process->state->t == LTTV_STATE_USER_MODE) |
| 287 | prop_line.color = drawing_colors[COL_RUN_USER_MODE]; |
| 288 | else if(process->state->t == LTTV_STATE_SYSCALL) |
| 289 | prop_line.color = drawing_colors[COL_RUN_SYSCALL]; |
| 290 | else if(process->state->t == LTTV_STATE_TRAP) |
| 291 | prop_line.color = drawing_colors[COL_RUN_TRAP]; |
| 292 | else if(process->state->t == LTTV_STATE_IRQ) |
| 293 | prop_line.color = drawing_colors[COL_RUN_IRQ]; |
| 294 | else if(process->state->t == LTTV_STATE_MODE_UNKNOWN) |
| 295 | prop_line.color = drawing_colors[COL_MODE_UNKNOWN]; |
| 296 | else |
| 297 | g_assert(FALSE); /* RUNNING MODE UNKNOWN */ |
| 298 | } else if(process->state->s == LTTV_STATE_WAIT) { |
| 299 | /* We don't show if we wait while in user mode, trap, irq or syscall */ |
| 300 | prop_line.color = drawing_colors[COL_WAIT]; |
| 301 | } else if(process->state->s == LTTV_STATE_WAIT_CPU) { |
| 302 | /* We don't show if we wait for CPU while in user mode, trap, irq |
| 303 | * or syscall */ |
| 304 | prop_line.color = drawing_colors[COL_WAIT_CPU]; |
| 305 | } else if(process->state->s == LTTV_STATE_ZOMBIE) { |
| 306 | prop_line.color = drawing_colors[COL_ZOMBIE]; |
| 307 | } else if(process->state->s == LTTV_STATE_WAIT_FORK) { |
| 308 | prop_line.color = drawing_colors[COL_WAIT_FORK]; |
| 309 | } else if(process->state->s == LTTV_STATE_EXIT) { |
| 310 | prop_line.color = drawing_colors[COL_EXIT]; |
| 311 | } else if(process->state->s == LTTV_STATE_UNNAMED) { |
| 312 | prop_line.color = drawing_colors[COL_UNNAMED]; |
| 313 | } else |
| 314 | g_assert(FALSE); /* UNKNOWN STATE */ |
| 315 | |
| 316 | return prop_line; |
| 317 | |
| 318 | } |
| 319 | |
| 320 | #if 0 |
| 321 | static inline PropertiesLine prepare_status_line(LttvProcessState *process) |
| 322 | { |
| 323 | PropertiesLine prop_line; |
| 324 | prop_line.line_width = 2; |
| 325 | prop_line.style = GDK_LINE_SOLID; |
| 326 | prop_line.y = MIDDLE; |
| 327 | //GdkColormap *colormap = gdk_colormap_get_system(); |
| 328 | |
| 329 | g_debug("prepare_status_line for state : %s", |
| 330 | g_quark_to_string(process->state->s)); |
| 331 | |
| 332 | /* color of line : status of the process */ |
| 333 | if(process->state->s == LTTV_STATE_UNNAMED) |
| 334 | prop_line.color = drawing_colors[COL_WHITE]; |
| 335 | else if(process->state->s == LTTV_STATE_WAIT_FORK) |
| 336 | prop_line.color = drawing_colors[COL_WAIT_FORK]; |
| 337 | else if(process->state->s == LTTV_STATE_WAIT_CPU) |
| 338 | prop_line.color = drawing_colors[COL_WAIT_CPU]; |
| 339 | else if(process->state->s == LTTV_STATE_EXIT) |
| 340 | prop_line.color = drawing_colors[COL_EXIT]; |
| 341 | else if(process->state->s == LTTV_STATE_ZOMBIE) |
| 342 | prop_line.color = drawing_colors[COL_ZOMBIE]; |
| 343 | else if(process->state->s == LTTV_STATE_WAIT) |
| 344 | prop_line.color = drawing_colors[COL_WAIT]; |
| 345 | else if(process->state->s == LTTV_STATE_RUN) |
| 346 | prop_line.color = drawing_colors[COL_RUN]; |
| 347 | else |
| 348 | prop_line.color = drawing_colors[COL_WHITE]; |
| 349 | |
| 350 | //gdk_colormap_alloc_color(colormap, |
| 351 | // prop_line.color, |
| 352 | // FALSE, |
| 353 | // TRUE); |
| 354 | |
| 355 | return prop_line; |
| 356 | |
| 357 | } |
| 358 | #endif //0 |
| 359 | |
| 360 | |
| 361 | /* before_schedchange_hook |
| 362 | * |
| 363 | * This function basically draw lines and icons. Two types of lines are drawn : |
| 364 | * one small (3 pixels?) representing the state of the process and the second |
| 365 | * type is thicker (10 pixels?) representing on which CPU a process is running |
| 366 | * (and this only in running state). |
| 367 | * |
| 368 | * Extremums of the lines : |
| 369 | * x_min : time of the last event context for this process kept in memory. |
| 370 | * x_max : time of the current event. |
| 371 | * y : middle of the process in the process list. The process is found in the |
| 372 | * list, therefore is it's position in pixels. |
| 373 | * |
| 374 | * The choice of lines'color is defined by the context of the last event for this |
| 375 | * process. |
| 376 | */ |
| 377 | |
| 378 | |
| 379 | int before_schedchange_hook(void *hook_data, void *call_data) |
| 380 | { |
| 381 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 382 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 383 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 384 | |
| 385 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 386 | |
| 387 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 388 | |
| 389 | LttEvent *e; |
| 390 | e = ltt_tracefile_get_event(tfc->tf); |
| 391 | |
| 392 | LttTime evtime = ltt_event_time(e); |
| 393 | |
| 394 | /* we are in a schedchange, before the state update. We must draw the |
| 395 | * items corresponding to the state before it changes : now is the right |
| 396 | * time to do it. |
| 397 | */ |
| 398 | |
| 399 | guint pid_out; |
| 400 | guint pid_in; |
| 401 | { |
| 402 | pid_out = ltt_event_get_long_unsigned(e, thf->f1); |
| 403 | pid_in = ltt_event_get_long_unsigned(e, thf->f2); |
| 404 | } |
| 405 | |
| 406 | { |
| 407 | /* For the pid_out */ |
| 408 | /* First, check if the current process is in the state computation |
| 409 | * process list. If it is there, that means we must add it right now and |
| 410 | * draw items from the beginning of the read for it. If it is not |
| 411 | * present, it's a new process and it was not present : it will |
| 412 | * be added after the state update. */ |
| 413 | LttvProcessState *process; |
| 414 | /* unknown state, bad current pid */ |
| 415 | if(tfs->process->pid != pid_out) |
| 416 | process = lttv_state_find_process(tfs, pid_out); |
| 417 | else |
| 418 | process = tfs->process; |
| 419 | |
| 420 | if(process != NULL) { |
| 421 | /* Well, the process_out existed : we must get it in the process hash |
| 422 | * or add it, and draw its items. |
| 423 | */ |
| 424 | /* Add process to process list (if not present) */ |
| 425 | guint pl_height = 0; |
| 426 | HashedProcessData *hashed_process_data = NULL; |
| 427 | ProcessList *process_list = control_flow_data->process_list; |
| 428 | LttTime birth = process->creation_time; |
| 429 | |
| 430 | hashed_process_data = processlist_get_process_data(process_list, |
| 431 | pid_out, |
| 432 | process->last_cpu_index, |
| 433 | &birth, |
| 434 | tfc->t_context->index); |
| 435 | if(hashed_process_data == NULL) |
| 436 | { |
| 437 | g_assert(pid_out == 0 || pid_out != process->ppid); |
| 438 | const gchar *name = g_quark_to_string(process->name); |
| 439 | /* Process not present */ |
| 440 | ProcessInfo *process_info; |
| 441 | Drawing_t *drawing = control_flow_data->drawing; |
| 442 | processlist_add(process_list, |
| 443 | drawing, |
| 444 | pid_out, |
| 445 | process->last_cpu_index, |
| 446 | process->ppid, |
| 447 | &birth, |
| 448 | tfc->t_context->index, |
| 449 | name, |
| 450 | &pl_height, |
| 451 | &process_info, |
| 452 | &hashed_process_data); |
| 453 | gtk_widget_set_size_request(drawing->drawing_area, |
| 454 | -1, |
| 455 | pl_height); |
| 456 | gtk_widget_queue_draw(drawing->drawing_area); |
| 457 | |
| 458 | } |
| 459 | |
| 460 | /* Now, the process is in the state hash and our own process hash. |
| 461 | * We definitely can draw the items related to the ending state. |
| 462 | */ |
| 463 | |
| 464 | if(ltt_time_compare(hashed_process_data->next_good_time, |
| 465 | evtime) > 0) |
| 466 | { |
| 467 | if(hashed_process_data->x.middle_marked == FALSE) { |
| 468 | |
| 469 | TimeWindow time_window = |
| 470 | lttvwindow_get_time_window(control_flow_data->tab); |
| 471 | #ifdef EXTRA_CHECK |
| 472 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 473 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 474 | return; |
| 475 | #endif //EXTRA_CHECK |
| 476 | Drawing_t *drawing = control_flow_data->drawing; |
| 477 | guint width = drawing->width; |
| 478 | guint x; |
| 479 | convert_time_to_pixels( |
| 480 | time_window, |
| 481 | evtime, |
| 482 | width, |
| 483 | &x); |
| 484 | |
| 485 | /* Draw collision indicator */ |
| 486 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 487 | gdk_draw_point(hashed_process_data->pixmap, |
| 488 | drawing->gc, |
| 489 | x, |
| 490 | (hashed_process_data->height/2)-3); |
| 491 | hashed_process_data->x.middle_marked = TRUE; |
| 492 | } |
| 493 | } else { |
| 494 | TimeWindow time_window = |
| 495 | lttvwindow_get_time_window(control_flow_data->tab); |
| 496 | #ifdef EXTRA_CHECK |
| 497 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 498 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 499 | return; |
| 500 | #endif //EXTRA_CHECK |
| 501 | Drawing_t *drawing = control_flow_data->drawing; |
| 502 | guint width = drawing->width; |
| 503 | guint x; |
| 504 | convert_time_to_pixels( |
| 505 | time_window, |
| 506 | evtime, |
| 507 | width, |
| 508 | &x); |
| 509 | |
| 510 | |
| 511 | /* Jump over draw if we are at the same x position */ |
| 512 | if(x == hashed_process_data->x.middle && |
| 513 | hashed_process_data->x.middle_used) |
| 514 | { |
| 515 | if(hashed_process_data->x.middle_marked == FALSE) { |
| 516 | /* Draw collision indicator */ |
| 517 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 518 | gdk_draw_point(hashed_process_data->pixmap, |
| 519 | drawing->gc, |
| 520 | x, |
| 521 | (hashed_process_data->height/2)-3); |
| 522 | hashed_process_data->x.middle_marked = TRUE; |
| 523 | } |
| 524 | /* jump */ |
| 525 | } else { |
| 526 | DrawContext draw_context; |
| 527 | |
| 528 | /* Now create the drawing context that will be used to draw |
| 529 | * items related to the last state. */ |
| 530 | draw_context.drawable = hashed_process_data->pixmap; |
| 531 | draw_context.gc = drawing->gc; |
| 532 | draw_context.pango_layout = drawing->pango_layout; |
| 533 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
| 534 | draw_context.drawinfo.end.x = x; |
| 535 | |
| 536 | draw_context.drawinfo.y.over = 1; |
| 537 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
| 538 | draw_context.drawinfo.y.under = hashed_process_data->height; |
| 539 | |
| 540 | draw_context.drawinfo.start.offset.over = 0; |
| 541 | draw_context.drawinfo.start.offset.middle = 0; |
| 542 | draw_context.drawinfo.start.offset.under = 0; |
| 543 | draw_context.drawinfo.end.offset.over = 0; |
| 544 | draw_context.drawinfo.end.offset.middle = 0; |
| 545 | draw_context.drawinfo.end.offset.under = 0; |
| 546 | |
| 547 | { |
| 548 | /* Draw the line */ |
| 549 | PropertiesLine prop_line = prepare_s_e_line(process); |
| 550 | draw_line((void*)&prop_line, (void*)&draw_context); |
| 551 | |
| 552 | } |
| 553 | /* become the last x position */ |
| 554 | hashed_process_data->x.middle = x; |
| 555 | hashed_process_data->x.middle_used = TRUE; |
| 556 | hashed_process_data->x.middle_marked = FALSE; |
| 557 | |
| 558 | /* Calculate the next good time */ |
| 559 | convert_pixels_to_time(width, x+1, time_window, |
| 560 | &hashed_process_data->next_good_time); |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | { |
| 567 | /* For the pid_in */ |
| 568 | /* First, check if the current process is in the state computation |
| 569 | * process list. If it is there, that means we must add it right now and |
| 570 | * draw items from the beginning of the read for it. If it is not |
| 571 | * present, it's a new process and it was not present : it will |
| 572 | * be added after the state update. */ |
| 573 | LttvProcessState *process; |
| 574 | process = lttv_state_find_process(tfs, pid_in); |
| 575 | |
| 576 | if(process != NULL) { |
| 577 | /* Well, the process_out existed : we must get it in the process hash |
| 578 | * or add it, and draw its items. |
| 579 | */ |
| 580 | /* Add process to process list (if not present) */ |
| 581 | guint pl_height = 0; |
| 582 | HashedProcessData *hashed_process_data = NULL; |
| 583 | ProcessList *process_list = control_flow_data->process_list; |
| 584 | LttTime birth = process->creation_time; |
| 585 | |
| 586 | hashed_process_data = processlist_get_process_data(process_list, |
| 587 | pid_in, |
| 588 | process->last_cpu_index, |
| 589 | &birth, |
| 590 | tfc->t_context->index); |
| 591 | if(hashed_process_data == NULL) |
| 592 | { |
| 593 | g_assert(pid_in == 0 || pid_in != process->ppid); |
| 594 | const gchar *name = g_quark_to_string(process->name); |
| 595 | /* Process not present */ |
| 596 | ProcessInfo *process_info; |
| 597 | Drawing_t *drawing = control_flow_data->drawing; |
| 598 | processlist_add(process_list, |
| 599 | drawing, |
| 600 | pid_in, |
| 601 | process->last_cpu_index, |
| 602 | process->ppid, |
| 603 | &birth, |
| 604 | tfc->t_context->index, |
| 605 | name, |
| 606 | &pl_height, |
| 607 | &process_info, |
| 608 | &hashed_process_data); |
| 609 | gtk_widget_set_size_request(drawing->drawing_area, |
| 610 | -1, |
| 611 | pl_height); |
| 612 | gtk_widget_queue_draw(drawing->drawing_area); |
| 613 | |
| 614 | } |
| 615 | //We could set the current process and hash here, but will be done |
| 616 | //by after schedchange hook |
| 617 | |
| 618 | /* Now, the process is in the state hash and our own process hash. |
| 619 | * We definitely can draw the items related to the ending state. |
| 620 | */ |
| 621 | |
| 622 | if(ltt_time_compare(hashed_process_data->next_good_time, |
| 623 | evtime) > 0) |
| 624 | { |
| 625 | if(hashed_process_data->x.middle_marked == FALSE) { |
| 626 | |
| 627 | TimeWindow time_window = |
| 628 | lttvwindow_get_time_window(control_flow_data->tab); |
| 629 | #ifdef EXTRA_CHECK |
| 630 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 631 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 632 | return; |
| 633 | #endif //EXTRA_CHECK |
| 634 | Drawing_t *drawing = control_flow_data->drawing; |
| 635 | guint width = drawing->width; |
| 636 | guint x; |
| 637 | convert_time_to_pixels( |
| 638 | time_window, |
| 639 | evtime, |
| 640 | width, |
| 641 | &x); |
| 642 | |
| 643 | /* Draw collision indicator */ |
| 644 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 645 | gdk_draw_point(hashed_process_data->pixmap, |
| 646 | drawing->gc, |
| 647 | x, |
| 648 | (hashed_process_data->height/2)-3); |
| 649 | hashed_process_data->x.middle_marked = TRUE; |
| 650 | } |
| 651 | } else { |
| 652 | TimeWindow time_window = |
| 653 | lttvwindow_get_time_window(control_flow_data->tab); |
| 654 | #ifdef EXTRA_CHECK |
| 655 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 656 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 657 | return; |
| 658 | #endif //EXTRA_CHECK |
| 659 | Drawing_t *drawing = control_flow_data->drawing; |
| 660 | guint width = drawing->width; |
| 661 | guint x; |
| 662 | |
| 663 | convert_time_to_pixels( |
| 664 | time_window, |
| 665 | evtime, |
| 666 | width, |
| 667 | &x); |
| 668 | |
| 669 | |
| 670 | /* Jump over draw if we are at the same x position */ |
| 671 | if(x == hashed_process_data->x.middle && |
| 672 | hashed_process_data->x.middle_used) |
| 673 | { |
| 674 | if(hashed_process_data->x.middle_marked == FALSE) { |
| 675 | /* Draw collision indicator */ |
| 676 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 677 | gdk_draw_point(hashed_process_data->pixmap, |
| 678 | drawing->gc, |
| 679 | x, |
| 680 | (hashed_process_data->height/2)-3); |
| 681 | hashed_process_data->x.middle_marked = TRUE; |
| 682 | } |
| 683 | /* jump */ |
| 684 | } else { |
| 685 | DrawContext draw_context; |
| 686 | |
| 687 | /* Now create the drawing context that will be used to draw |
| 688 | * items related to the last state. */ |
| 689 | draw_context.drawable = hashed_process_data->pixmap; |
| 690 | draw_context.gc = drawing->gc; |
| 691 | draw_context.pango_layout = drawing->pango_layout; |
| 692 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
| 693 | draw_context.drawinfo.end.x = x; |
| 694 | |
| 695 | draw_context.drawinfo.y.over = 1; |
| 696 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
| 697 | draw_context.drawinfo.y.under = hashed_process_data->height; |
| 698 | |
| 699 | draw_context.drawinfo.start.offset.over = 0; |
| 700 | draw_context.drawinfo.start.offset.middle = 0; |
| 701 | draw_context.drawinfo.start.offset.under = 0; |
| 702 | draw_context.drawinfo.end.offset.over = 0; |
| 703 | draw_context.drawinfo.end.offset.middle = 0; |
| 704 | draw_context.drawinfo.end.offset.under = 0; |
| 705 | |
| 706 | { |
| 707 | /* Draw the line */ |
| 708 | PropertiesLine prop_line = prepare_s_e_line(process); |
| 709 | draw_line((void*)&prop_line, (void*)&draw_context); |
| 710 | } |
| 711 | |
| 712 | |
| 713 | /* become the last x position */ |
| 714 | hashed_process_data->x.middle = x; |
| 715 | hashed_process_data->x.middle_used = TRUE; |
| 716 | hashed_process_data->x.middle_marked = FALSE; |
| 717 | |
| 718 | /* Calculate the next good time */ |
| 719 | convert_pixels_to_time(width, x+1, time_window, |
| 720 | &hashed_process_data->next_good_time); |
| 721 | } |
| 722 | } |
| 723 | } |
| 724 | } |
| 725 | return 0; |
| 726 | |
| 727 | |
| 728 | #if 0 |
| 729 | EventsRequest *events_request = (EventsRequest*)hook_data; |
| 730 | ControlFlowData *control_flow_data = |
| 731 | (ControlFlowData*)events_request->viewer_data; |
| 732 | Tab *tab = control_flow_data->tab; |
| 733 | |
| 734 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 735 | |
| 736 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 737 | LttvTraceState *ts =(LttvTraceState *)LTTV_TRACEFILE_CONTEXT(tfs)->t_context; |
| 738 | |
| 739 | LttEvent *e; |
| 740 | e = tfc->e; |
| 741 | |
| 742 | LttTime evtime = ltt_event_time(e); |
| 743 | TimeWindow time_window = |
| 744 | lttvwindow_get_time_window(tab); |
| 745 | |
| 746 | LttTime time_window.end_time = time_window.time_window.end_time; |
| 747 | |
| 748 | //if(time < time_beg || time > time_end) return; |
| 749 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 750 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 751 | return; |
| 752 | |
| 753 | if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0) |
| 754 | { |
| 755 | g_debug("schedchange!"); |
| 756 | |
| 757 | /* Add process to process list (if not present) and get drawing "y" from |
| 758 | * process position */ |
| 759 | guint pid_out, pid_in; |
| 760 | LttvProcessState *process_out, *process_in; |
| 761 | LttTime birth; |
| 762 | guint y_in = 0, y_out = 0, height = 0, pl_height = 0; |
| 763 | |
| 764 | ProcessList *process_list = control_flow_data->process_list; |
| 765 | |
| 766 | |
| 767 | LttField *f = ltt_event_field(e); |
| 768 | LttField *element; |
| 769 | element = ltt_field_member(f,0); |
| 770 | pid_out = ltt_event_get_long_unsigned(e,element); |
| 771 | element = ltt_field_member(f,1); |
| 772 | pid_in = ltt_event_get_long_unsigned(e,element); |
| 773 | g_debug("out : %u in : %u", pid_out, pid_in); |
| 774 | |
| 775 | |
| 776 | /* Find process pid_out in the list... */ |
| 777 | process_out = lttv_state_find_process(tfs, pid_out); |
| 778 | if(process_out == NULL) return 0; |
| 779 | g_debug("out : %s",g_quark_to_string(process_out->state->s)); |
| 780 | |
| 781 | birth = process_out->creation_time; |
| 782 | const gchar *name = g_quark_to_string(process_out->name); |
| 783 | HashedProcessData *hashed_process_data_out = NULL; |
| 784 | |
| 785 | if(processlist_get_process_pixels(process_list, |
| 786 | pid_out, |
| 787 | &birth, |
| 788 | tfc->t_context->index, |
| 789 | &y_out, |
| 790 | &height, |
| 791 | &hashed_process_data_out) == 1) |
| 792 | { |
| 793 | /* Process not present */ |
| 794 | processlist_add(process_list, |
| 795 | pid_out, |
| 796 | &birth, |
| 797 | tfc->t_context->index, |
| 798 | name, |
| 799 | &pl_height, |
| 800 | &hashed_process_data_out); |
| 801 | g_assert(processlist_get_process_pixels(process_list, |
| 802 | pid_out, |
| 803 | &birth, |
| 804 | tfc->t_context->index, |
| 805 | &y_out, |
| 806 | &height, |
| 807 | &hashed_process_data_out)==0); |
| 808 | drawing_insert_square( control_flow_data->drawing, y_out, height); |
| 809 | } |
| 810 | //g_free(name); |
| 811 | |
| 812 | /* Find process pid_in in the list... */ |
| 813 | process_in = lttv_state_find_process(tfs, pid_in); |
| 814 | if(process_in == NULL) return 0; |
| 815 | g_debug("in : %s",g_quark_to_string(process_in->state->s)); |
| 816 | |
| 817 | birth = process_in->creation_time; |
| 818 | name = g_quark_to_string(process_in->name); |
| 819 | HashedProcessData *hashed_process_data_in = NULL; |
| 820 | |
| 821 | if(processlist_get_process_pixels(process_list, |
| 822 | pid_in, |
| 823 | &birth, |
| 824 | tfc->t_context->index, |
| 825 | &y_in, |
| 826 | &height, |
| 827 | &hashed_process_data_in) == 1) |
| 828 | { |
| 829 | /* Process not present */ |
| 830 | processlist_add(process_list, |
| 831 | pid_in, |
| 832 | &birth, |
| 833 | tfc->t_context->index, |
| 834 | name, |
| 835 | &pl_height, |
| 836 | &hashed_process_data_in); |
| 837 | processlist_get_process_pixels(process_list, |
| 838 | pid_in, |
| 839 | &birth, |
| 840 | tfc->t_context->index, |
| 841 | &y_in, |
| 842 | &height, |
| 843 | &hashed_process_data_in); |
| 844 | |
| 845 | drawing_insert_square( control_flow_data->drawing, y_in, height); |
| 846 | } |
| 847 | //g_free(name); |
| 848 | |
| 849 | |
| 850 | /* Find pixels corresponding to time of the event. If the time does |
| 851 | * not fit in the window, show a warning, not supposed to happend. */ |
| 852 | guint x = 0; |
| 853 | guint width = control_flow_data->drawing->width; |
| 854 | |
| 855 | LttTime time = ltt_event_time(e); |
| 856 | |
| 857 | LttTime window_end = time_window.time_window.end_time; |
| 858 | |
| 859 | convert_time_to_pixels( |
| 860 | time_window, |
| 861 | time, |
| 862 | width, |
| 863 | &x); |
| 864 | //assert(x <= width); |
| 865 | // |
| 866 | /* draw what represents the event for outgoing process. */ |
| 867 | |
| 868 | DrawContext *draw_context_out = hashed_process_data_out->draw_context; |
| 869 | draw_context_out->current->modify_over->x = x; |
| 870 | draw_context_out->current->modify_under->x = x; |
| 871 | draw_context_out->current->modify_over->y = y_out; |
| 872 | draw_context_out->current->modify_under->y = y_out+(height/2)+2; |
| 873 | draw_context_out->drawable = control_flow_data->drawing->pixmap; |
| 874 | draw_context_out->pango_layout = control_flow_data->drawing->pango_layout; |
| 875 | GtkWidget *widget = control_flow_data->drawing->drawing_area; |
| 876 | //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)]; |
| 877 | //draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap); |
| 878 | //gdk_gc_copy(draw_context_out->gc, widget->style->black_gc); |
| 879 | //draw_context_out->gc = widget->style->black_gc; |
| 880 | |
| 881 | //draw_arc((void*)&prop_arc, (void*)draw_context_out); |
| 882 | //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap); |
| 883 | |
| 884 | /* Draw the line/background of the out process */ |
| 885 | if(draw_context_out->previous->middle->x == -1) |
| 886 | { |
| 887 | draw_context_out->previous->over->x = |
| 888 | control_flow_data->drawing->damage_begin; |
| 889 | draw_context_out->previous->middle->x = |
| 890 | control_flow_data->drawing->damage_begin; |
| 891 | draw_context_out->previous->under->x = |
| 892 | control_flow_data->drawing->damage_begin; |
| 893 | g_debug("out middle x_beg : %u",control_flow_data->drawing->damage_begin); |
| 894 | } |
| 895 | |
| 896 | draw_context_out->current->middle->x = x; |
| 897 | draw_context_out->current->over->x = x; |
| 898 | draw_context_out->current->under->x = x; |
| 899 | draw_context_out->current->middle->y = y_out + height/2; |
| 900 | draw_context_out->current->over->y = y_out; |
| 901 | draw_context_out->current->under->y = y_out + height; |
| 902 | draw_context_out->previous->middle->y = y_out + height/2; |
| 903 | draw_context_out->previous->over->y = y_out; |
| 904 | draw_context_out->previous->under->y = y_out + height; |
| 905 | |
| 906 | draw_context_out->drawable = control_flow_data->drawing->pixmap; |
| 907 | draw_context_out->pango_layout = control_flow_data->drawing->pango_layout; |
| 908 | |
| 909 | if(process_out->state->s == LTTV_STATE_RUN) |
| 910 | { |
| 911 | //draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap); |
| 912 | //gdk_gc_copy(draw_context_out->gc, widget->style->black_gc); |
| 913 | draw_context_out->gc = control_flow_data->drawing->gc; |
| 914 | |
| 915 | PropertiesBG prop_bg; |
| 916 | prop_bg.color = g_new(GdkColor,1); |
| 917 | |
| 918 | switch(ltt_tracefile_num(tfc->tf)) { |
| 919 | case 0: |
| 920 | prop_bg.color->red = 0x1515; |
| 921 | prop_bg.color->green = 0x1515; |
| 922 | prop_bg.color->blue = 0x8c8c; |
| 923 | break; |
| 924 | case 1: |
| 925 | prop_bg.color->red = 0x4e4e; |
| 926 | prop_bg.color->green = 0xa9a9; |
| 927 | prop_bg.color->blue = 0xa4a4; |
| 928 | break; |
| 929 | case 2: |
| 930 | prop_bg.color->red = 0x7a7a; |
| 931 | prop_bg.color->green = 0x4a4a; |
| 932 | prop_bg.color->blue = 0x8b8b; |
| 933 | break; |
| 934 | case 3: |
| 935 | prop_bg.color->red = 0x8080; |
| 936 | prop_bg.color->green = 0x7777; |
| 937 | prop_bg.color->blue = 0x4747; |
| 938 | break; |
| 939 | default: |
| 940 | prop_bg.color->red = 0xe7e7; |
| 941 | prop_bg.color->green = 0xe7e7; |
| 942 | prop_bg.color->blue = 0xe7e7; |
| 943 | } |
| 944 | |
| 945 | g_debug("calling from draw_event"); |
| 946 | draw_bg((void*)&prop_bg, (void*)draw_context_out); |
| 947 | g_free(prop_bg.color); |
| 948 | //gdk_gc_unref(draw_context_out->gc); |
| 949 | } |
| 950 | |
| 951 | draw_context_out->gc = widget->style->black_gc; |
| 952 | |
| 953 | GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 }; |
| 954 | GdkColor colorbg_out = { 0, 0x0000, 0x0000, 0x0000 }; |
| 955 | PropertiesText prop_text_out; |
| 956 | prop_text_out.foreground = &colorfg_out; |
| 957 | prop_text_out.background = &colorbg_out; |
| 958 | prop_text_out.size = 6; |
| 959 | prop_text_out.position = OVER; |
| 960 | |
| 961 | /* color of text : status of the process */ |
| 962 | if(process_out->state->s == LTTV_STATE_UNNAMED) |
| 963 | { |
| 964 | prop_text_out.foreground->red = 0xffff; |
| 965 | prop_text_out.foreground->green = 0xffff; |
| 966 | prop_text_out.foreground->blue = 0xffff; |
| 967 | } |
| 968 | else if(process_out->state->s == LTTV_STATE_WAIT_FORK) |
| 969 | { |
| 970 | prop_text_out.foreground->red = 0x0fff; |
| 971 | prop_text_out.foreground->green = 0xffff; |
| 972 | prop_text_out.foreground->blue = 0xfff0; |
| 973 | } |
| 974 | else if(process_out->state->s == LTTV_STATE_WAIT_CPU) |
| 975 | { |
| 976 | prop_text_out.foreground->red = 0xffff; |
| 977 | prop_text_out.foreground->green = 0xffff; |
| 978 | prop_text_out.foreground->blue = 0x0000; |
| 979 | } |
| 980 | else if(process_out->state->s == LTTV_STATE_ZOMBIE) |
| 981 | { |
| 982 | prop_text_out.foreground->red = 0xffff; |
| 983 | prop_text_out.foreground->green = 0x0000; |
| 984 | prop_text_out.foreground->blue = 0xffff; |
| 985 | } |
| 986 | else if(process_out->state->s == LTTV_STATE_WAIT) |
| 987 | { |
| 988 | prop_text_out.foreground->red = 0xffff; |
| 989 | prop_text_out.foreground->green = 0x0000; |
| 990 | prop_text_out.foreground->blue = 0x0000; |
| 991 | } |
| 992 | else if(process_out->state->s == LTTV_STATE_RUN) |
| 993 | { |
| 994 | prop_text_out.foreground->red = 0x0000; |
| 995 | prop_text_out.foreground->green = 0xffff; |
| 996 | prop_text_out.foreground->blue = 0x0000; |
| 997 | } |
| 998 | else |
| 999 | { |
| 1000 | prop_text_out.foreground->red = 0xffff; |
| 1001 | prop_text_out.foreground->green = 0xffff; |
| 1002 | prop_text_out.foreground->blue = 0xffff; |
| 1003 | } |
| 1004 | |
| 1005 | |
| 1006 | /* Print status of the process : U, WF, WC, E, W, R */ |
| 1007 | if(process_out->state->s == LTTV_STATE_UNNAMED) |
| 1008 | prop_text_out.text = "U->"; |
| 1009 | else if(process_out->state->s == LTTV_STATE_WAIT_FORK) |
| 1010 | prop_text_out.text = "WF->"; |
| 1011 | else if(process_out->state->s == LTTV_STATE_WAIT_CPU) |
| 1012 | prop_text_out.text = "WC->"; |
| 1013 | else if(process_out->state->s == LTTV_STATE_ZOMBIE) |
| 1014 | prop_text_out.text = "E->"; |
| 1015 | else if(process_out->state->s == LTTV_STATE_WAIT) |
| 1016 | prop_text_out.text = "W->"; |
| 1017 | else if(process_out->state->s == LTTV_STATE_RUN) |
| 1018 | prop_text_out.text = "R->"; |
| 1019 | else |
| 1020 | prop_text_out.text = "U"; |
| 1021 | |
| 1022 | draw_text((void*)&prop_text_out, (void*)draw_context_out); |
| 1023 | //gdk_gc_unref(draw_context_out->gc); |
| 1024 | |
| 1025 | //draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap); |
| 1026 | //gdk_gc_copy(draw_context_out->gc, widget->style->black_gc); |
| 1027 | draw_context_out->gc = control_flow_data->drawing->gc; |
| 1028 | |
| 1029 | PropertiesLine prop_line_out; |
| 1030 | prop_line_out.color = g_new(GdkColor,1); |
| 1031 | prop_line_out.line_width = 2; |
| 1032 | prop_line_out.style = GDK_LINE_SOLID; |
| 1033 | prop_line_out.position = MIDDLE; |
| 1034 | |
| 1035 | g_debug("out state : %s", g_quark_to_string(process_out->state->s)); |
| 1036 | |
| 1037 | /* color of line : status of the process */ |
| 1038 | if(process_out->state->s == LTTV_STATE_UNNAMED) |
| 1039 | { |
| 1040 | prop_line_out.color->red = 0xffff; |
| 1041 | prop_line_out.color->green = 0xffff; |
| 1042 | prop_line_out.color->blue = 0xffff; |
| 1043 | } |
| 1044 | else if(process_out->state->s == LTTV_STATE_WAIT_FORK) |
| 1045 | { |
| 1046 | prop_line_out.color->red = 0x0fff; |
| 1047 | prop_line_out.color->green = 0xffff; |
| 1048 | prop_line_out.color->blue = 0xfff0; |
| 1049 | } |
| 1050 | else if(process_out->state->s == LTTV_STATE_WAIT_CPU) |
| 1051 | { |
| 1052 | prop_line_out.color->red = 0xffff; |
| 1053 | prop_line_out.color->green = 0xffff; |
| 1054 | prop_line_out.color->blue = 0x0000; |
| 1055 | } |
| 1056 | else if(process_out->state->s == LTTV_STATE_ZOMBIE) |
| 1057 | { |
| 1058 | prop_line_out.color->red = 0xffff; |
| 1059 | prop_line_out.color->green = 0x0000; |
| 1060 | prop_line_out.color->blue = 0xffff; |
| 1061 | } |
| 1062 | else if(process_out->state->s == LTTV_STATE_WAIT) |
| 1063 | { |
| 1064 | prop_line_out.color->red = 0xffff; |
| 1065 | prop_line_out.color->green = 0x0000; |
| 1066 | prop_line_out.color->blue = 0x0000; |
| 1067 | } |
| 1068 | else if(process_out->state->s == LTTV_STATE_RUN) |
| 1069 | { |
| 1070 | prop_line_out.color->red = 0x0000; |
| 1071 | prop_line_out.color->green = 0xffff; |
| 1072 | prop_line_out.color->blue = 0x0000; |
| 1073 | } |
| 1074 | else |
| 1075 | { |
| 1076 | prop_line_out.color->red = 0xffff; |
| 1077 | prop_line_out.color->green = 0xffff; |
| 1078 | prop_line_out.color->blue = 0xffff; |
| 1079 | } |
| 1080 | |
| 1081 | draw_line((void*)&prop_line_out, (void*)draw_context_out); |
| 1082 | g_free(prop_line_out.color); |
| 1083 | //gdk_gc_unref(draw_context_out->gc); |
| 1084 | /* Note : finishing line will have to be added when trace read over. */ |
| 1085 | |
| 1086 | /* Finally, update the drawing context of the pid_in. */ |
| 1087 | |
| 1088 | DrawContext *draw_context_in = hashed_process_data_in->draw_context; |
| 1089 | draw_context_in->current->modify_over->x = x; |
| 1090 | draw_context_in->current->modify_under->x = x; |
| 1091 | draw_context_in->current->modify_over->y = y_in; |
| 1092 | draw_context_in->current->modify_under->y = y_in+(height/2)+2; |
| 1093 | draw_context_in->drawable = control_flow_data->drawing->pixmap; |
| 1094 | draw_context_in->pango_layout = control_flow_data->drawing->pango_layout; |
| 1095 | widget = control_flow_data->drawing->drawing_area; |
| 1096 | //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)]; |
| 1097 | //draw_context_in->gc = widget->style->black_gc; |
| 1098 | //draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap); |
| 1099 | //gdk_gc_copy(draw_context_in->gc, widget->style->black_gc); |
| 1100 | |
| 1101 | //draw_arc((void*)&prop_arc, (void*)draw_context_in); |
| 1102 | //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap); |
| 1103 | |
| 1104 | /* Draw the line/bg of the in process */ |
| 1105 | if(draw_context_in->previous->middle->x == -1) |
| 1106 | { |
| 1107 | draw_context_in->previous->over->x = |
| 1108 | control_flow_data->drawing->damage_begin; |
| 1109 | draw_context_in->previous->middle->x = |
| 1110 | control_flow_data->drawing->damage_begin; |
| 1111 | draw_context_in->previous->under->x = |
| 1112 | control_flow_data->drawing->damage_begin; |
| 1113 | |
| 1114 | g_debug("in middle x_beg : %u",control_flow_data->drawing->damage_begin); |
| 1115 | |
| 1116 | } |
| 1117 | |
| 1118 | draw_context_in->current->middle->x = x; |
| 1119 | draw_context_in->current->over->x = x; |
| 1120 | draw_context_in->current->under->x = x; |
| 1121 | draw_context_in->current->middle->y = y_in + height/2; |
| 1122 | draw_context_in->current->over->y = y_in; |
| 1123 | draw_context_in->current->under->y = y_in + height; |
| 1124 | draw_context_in->previous->middle->y = y_in + height/2; |
| 1125 | draw_context_in->previous->over->y = y_in; |
| 1126 | draw_context_in->previous->under->y = y_in + height; |
| 1127 | |
| 1128 | draw_context_in->drawable = control_flow_data->drawing->pixmap; |
| 1129 | draw_context_in->pango_layout = control_flow_data->drawing->pango_layout; |
| 1130 | |
| 1131 | |
| 1132 | if(process_in->state->s == LTTV_STATE_RUN) |
| 1133 | { |
| 1134 | //draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap); |
| 1135 | //gdk_gc_copy(draw_context_in->gc, widget->style->black_gc); |
| 1136 | draw_context_in->gc = control_flow_data->drawing->gc; |
| 1137 | |
| 1138 | PropertiesBG prop_bg; |
| 1139 | prop_bg.color = g_new(GdkColor,1); |
| 1140 | |
| 1141 | switcht(ltt_tracefile_num(tfc->tf)) { |
| 1142 | case 0: |
| 1143 | prop_bg.color->red = 0x1515; |
| 1144 | prop_bg.color->green = 0x1515; |
| 1145 | prop_bg.color->blue = 0x8c8c; |
| 1146 | break; |
| 1147 | case 1: |
| 1148 | prop_bg.color->red = 0x4e4e; |
| 1149 | prop_bg.color->green = 0xa9a9; |
| 1150 | prop_bg.color->blue = 0xa4a4; |
| 1151 | break; |
| 1152 | case 2: |
| 1153 | prop_bg.color->red = 0x7a7a; |
| 1154 | prop_bg.color->green = 0x4a4a; |
| 1155 | prop_bg.color->blue = 0x8b8b; |
| 1156 | break; |
| 1157 | case 3: |
| 1158 | prop_bg.color->red = 0x8080; |
| 1159 | prop_bg.color->green = 0x7777; |
| 1160 | prop_bg.color->blue = 0x4747; |
| 1161 | break; |
| 1162 | default: |
| 1163 | prop_bg.color->red = 0xe7e7; |
| 1164 | prop_bg.color->green = 0xe7e7; |
| 1165 | prop_bg.color->blue = 0xe7e7; |
| 1166 | } |
| 1167 | |
| 1168 | |
| 1169 | draw_bg((void*)&prop_bg, (void*)draw_context_in); |
| 1170 | g_free(prop_bg.color); |
| 1171 | //gdk_gc_unref(draw_context_in->gc); |
| 1172 | } |
| 1173 | |
| 1174 | draw_context_in->gc = widget->style->black_gc; |
| 1175 | |
| 1176 | GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 }; |
| 1177 | GdkColor colorbg_in = { 0, 0x0000, 0x0000, 0x0000 }; |
| 1178 | PropertiesText prop_text_in; |
| 1179 | prop_text_in.foreground = &colorfg_in; |
| 1180 | prop_text_in.background = &colorbg_in; |
| 1181 | prop_text_in.size = 6; |
| 1182 | prop_text_in.position = OVER; |
| 1183 | |
| 1184 | g_debug("in state : %s", g_quark_to_string(process_in->state->s)); |
| 1185 | /* foreground of text : status of the process */ |
| 1186 | if(process_in->state->s == LTTV_STATE_UNNAMED) |
| 1187 | { |
| 1188 | prop_text_in.foreground->red = 0xffff; |
| 1189 | prop_text_in.foreground->green = 0xffff; |
| 1190 | prop_text_in.foreground->blue = 0xffff; |
| 1191 | } |
| 1192 | else if(process_in->state->s == LTTV_STATE_WAIT_FORK) |
| 1193 | { |
| 1194 | prop_text_in.foreground->red = 0x0fff; |
| 1195 | prop_text_in.foreground->green = 0xffff; |
| 1196 | prop_text_in.foreground->blue = 0xfff0; |
| 1197 | } |
| 1198 | else if(process_in->state->s == LTTV_STATE_WAIT_CPU) |
| 1199 | { |
| 1200 | prop_text_in.foreground->red = 0xffff; |
| 1201 | prop_text_in.foreground->green = 0xffff; |
| 1202 | prop_text_in.foreground->blue = 0x0000; |
| 1203 | } |
| 1204 | else if(process_in->state->s == LTTV_STATE_ZOMBIE) |
| 1205 | { |
| 1206 | prop_text_in.foreground->red = 0xffff; |
| 1207 | prop_text_in.foreground->green = 0x0000; |
| 1208 | prop_text_in.foreground->blue = 0xffff; |
| 1209 | } |
| 1210 | else if(process_in->state->s == LTTV_STATE_WAIT) |
| 1211 | { |
| 1212 | prop_text_in.foreground->red = 0xffff; |
| 1213 | prop_text_in.foreground->green = 0x0000; |
| 1214 | prop_text_in.foreground->blue = 0x0000; |
| 1215 | } |
| 1216 | else if(process_in->state->s == LTTV_STATE_RUN) |
| 1217 | { |
| 1218 | prop_text_in.foreground->red = 0x0000; |
| 1219 | prop_text_in.foreground->green = 0xffff; |
| 1220 | prop_text_in.foreground->blue = 0x0000; |
| 1221 | } |
| 1222 | else |
| 1223 | { |
| 1224 | prop_text_in.foreground->red = 0xffff; |
| 1225 | prop_text_in.foreground->green = 0xffff; |
| 1226 | prop_text_in.foreground->blue = 0xffff; |
| 1227 | } |
| 1228 | |
| 1229 | |
| 1230 | |
| 1231 | /* Print status of the process : U, WF, WC, E, W, R */ |
| 1232 | if(process_in->state->s == LTTV_STATE_UNNAMED) |
| 1233 | prop_text_in.text = "U->"; |
| 1234 | else if(process_in->state->s == LTTV_STATE_WAIT_FORK) |
| 1235 | prop_text_in.text = "WF->"; |
| 1236 | else if(process_in->state->s == LTTV_STATE_WAIT_CPU) |
| 1237 | prop_text_in.text = "WC->"; |
| 1238 | else if(process_in->state->s == LTTV_STATE_ZOMBIE) |
| 1239 | prop_text_in.text = "E->"; |
| 1240 | else if(process_in->state->s == LTTV_STATE_WAIT) |
| 1241 | prop_text_in.text = "W->"; |
| 1242 | else if(process_in->state->s == LTTV_STATE_RUN) |
| 1243 | prop_text_in.text = "R->"; |
| 1244 | else |
| 1245 | prop_text_in.text = "U"; |
| 1246 | |
| 1247 | draw_text((void*)&prop_text_in, (void*)draw_context_in); |
| 1248 | //gdk_gc_unref(draw_context_in->gc); |
| 1249 | |
| 1250 | //draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap); |
| 1251 | //gdk_gc_copy(draw_context_in->gc, widget->style->black_gc); |
| 1252 | draw_context_in->gc = control_flow_data->drawing->gc; |
| 1253 | |
| 1254 | PropertiesLine prop_line_in; |
| 1255 | prop_line_in.color = g_new(GdkColor,1); |
| 1256 | prop_line_in.line_width = 2; |
| 1257 | prop_line_in.style = GDK_LINE_SOLID; |
| 1258 | prop_line_in.position = MIDDLE; |
| 1259 | |
| 1260 | /* color of line : status of the process */ |
| 1261 | if(process_in->state->s == LTTV_STATE_UNNAMED) |
| 1262 | { |
| 1263 | prop_line_in.color->red = 0xffff; |
| 1264 | prop_line_in.color->green = 0xffff; |
| 1265 | prop_line_in.color->blue = 0xffff; |
| 1266 | } |
| 1267 | else if(process_in->state->s == LTTV_STATE_WAIT_FORK) |
| 1268 | { |
| 1269 | prop_line_in.color->red = 0x0fff; |
| 1270 | prop_line_in.color->green = 0xffff; |
| 1271 | prop_line_in.color->blue = 0xfff0; |
| 1272 | } |
| 1273 | else if(process_in->state->s == LTTV_STATE_WAIT_CPU) |
| 1274 | { |
| 1275 | prop_line_in.color->red = 0xffff; |
| 1276 | prop_line_in.color->green = 0xffff; |
| 1277 | prop_line_in.color->blue = 0x0000; |
| 1278 | } |
| 1279 | else if(process_in->state->s == LTTV_STATE_ZOMBIE) |
| 1280 | { |
| 1281 | prop_line_in.color->red = 0xffff; |
| 1282 | prop_line_in.color->green = 0x0000; |
| 1283 | prop_line_in.color->blue = 0xffff; |
| 1284 | } |
| 1285 | else if(process_in->state->s == LTTV_STATE_WAIT) |
| 1286 | { |
| 1287 | prop_line_in.color->red = 0xffff; |
| 1288 | prop_line_in.color->green = 0x0000; |
| 1289 | prop_line_in.color->blue = 0x0000; |
| 1290 | } |
| 1291 | else if(process_in->state->s == LTTV_STATE_RUN) |
| 1292 | { |
| 1293 | prop_line_in.color->red = 0x0000; |
| 1294 | prop_line_in.color->green = 0xffff; |
| 1295 | prop_line_in.color->blue = 0x0000; |
| 1296 | } |
| 1297 | else |
| 1298 | { |
| 1299 | prop_line_in.color->red = 0xffff; |
| 1300 | prop_line_in.color->green = 0xffff; |
| 1301 | prop_line_in.color->blue = 0xffff; |
| 1302 | } |
| 1303 | |
| 1304 | draw_line((void*)&prop_line_in, (void*)draw_context_in); |
| 1305 | g_free(prop_line_in.color); |
| 1306 | //gdk_gc_unref(draw_context_in->gc); |
| 1307 | } |
| 1308 | |
| 1309 | return 0; |
| 1310 | #endif //0 |
| 1311 | |
| 1312 | |
| 1313 | |
| 1314 | /* Text dump */ |
| 1315 | #ifdef DONTSHOW |
| 1316 | GString *string = g_string_new("");; |
| 1317 | gboolean field_names = TRUE, state = TRUE; |
| 1318 | |
| 1319 | lttv_event_to_string(e, tfc->tf, string, TRUE, field_names, tfs); |
| 1320 | g_string_append_printf(string,"\n"); |
| 1321 | |
| 1322 | if(state) { |
| 1323 | g_string_append_printf(string, " %s", |
| 1324 | g_quark_to_string(tfs->process->state->s)); |
| 1325 | } |
| 1326 | |
| 1327 | g_info("%s",string->str); |
| 1328 | |
| 1329 | g_string_free(string, TRUE); |
| 1330 | |
| 1331 | /* End of text dump */ |
| 1332 | #endif //DONTSHOW |
| 1333 | |
| 1334 | } |
| 1335 | |
| 1336 | /* after_schedchange_hook |
| 1337 | * |
| 1338 | * The draw after hook is called by the reading API to have a |
| 1339 | * particular event drawn on the screen. |
| 1340 | * @param hook_data ControlFlowData structure of the viewer. |
| 1341 | * @param call_data Event context. |
| 1342 | * |
| 1343 | * This function adds items to be drawn in a queue for each process. |
| 1344 | * |
| 1345 | */ |
| 1346 | int after_schedchange_hook(void *hook_data, void *call_data) |
| 1347 | { |
| 1348 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 1349 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 1350 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 1351 | |
| 1352 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 1353 | |
| 1354 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 1355 | |
| 1356 | LttEvent *e; |
| 1357 | e = ltt_tracefile_get_event(tfc->tf); |
| 1358 | |
| 1359 | LttTime evtime = ltt_event_time(e); |
| 1360 | |
| 1361 | /* Add process to process list (if not present) */ |
| 1362 | LttvProcessState *process_in; |
| 1363 | LttTime birth; |
| 1364 | guint pl_height = 0; |
| 1365 | HashedProcessData *hashed_process_data_in = NULL; |
| 1366 | |
| 1367 | ProcessList *process_list = control_flow_data->process_list; |
| 1368 | |
| 1369 | guint pid_in; |
| 1370 | { |
| 1371 | guint pid_out; |
| 1372 | pid_out = ltt_event_get_long_unsigned(e, thf->f1); |
| 1373 | pid_in = ltt_event_get_long_unsigned(e, thf->f2); |
| 1374 | } |
| 1375 | |
| 1376 | |
| 1377 | /* Find process pid_in in the list... */ |
| 1378 | //process_in = lttv_state_find_process(tfs, pid_in); |
| 1379 | process_in = tfs->process; |
| 1380 | /* It should exist, because we are after the state update. */ |
| 1381 | #ifdef EXTRA_CHECK |
| 1382 | g_assert(process_in != NULL); |
| 1383 | #endif //EXTRA_CHECK |
| 1384 | birth = process_in->creation_time; |
| 1385 | |
| 1386 | hashed_process_data_in = processlist_get_process_data(process_list, |
| 1387 | pid_in, |
| 1388 | process_in->last_cpu_index, |
| 1389 | &birth, |
| 1390 | tfc->t_context->index); |
| 1391 | if(hashed_process_data_in == NULL) |
| 1392 | { |
| 1393 | g_assert(pid_in == 0 || pid_in != process_in->ppid); |
| 1394 | const gchar *name = g_quark_to_string(process_in->name); |
| 1395 | ProcessInfo *process_info; |
| 1396 | Drawing_t *drawing = control_flow_data->drawing; |
| 1397 | /* Process not present */ |
| 1398 | processlist_add(process_list, |
| 1399 | drawing, |
| 1400 | pid_in, |
| 1401 | process_in->last_cpu_index, |
| 1402 | process_in->ppid, |
| 1403 | &birth, |
| 1404 | tfc->t_context->index, |
| 1405 | name, |
| 1406 | &pl_height, |
| 1407 | &process_info, |
| 1408 | &hashed_process_data_in); |
| 1409 | gtk_widget_set_size_request(drawing->drawing_area, |
| 1410 | -1, |
| 1411 | pl_height); |
| 1412 | gtk_widget_queue_draw(drawing->drawing_area); |
| 1413 | } |
| 1414 | /* Set the current process */ |
| 1415 | process_list->current_hash_data[process_in->last_cpu_index] = |
| 1416 | hashed_process_data_in; |
| 1417 | |
| 1418 | if(ltt_time_compare(hashed_process_data_in->next_good_time, |
| 1419 | evtime) <= 0) |
| 1420 | { |
| 1421 | TimeWindow time_window = |
| 1422 | lttvwindow_get_time_window(control_flow_data->tab); |
| 1423 | |
| 1424 | #ifdef EXTRA_CHECK |
| 1425 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 1426 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 1427 | return; |
| 1428 | #endif //EXTRA_CHECK |
| 1429 | Drawing_t *drawing = control_flow_data->drawing; |
| 1430 | guint width = drawing->width; |
| 1431 | guint new_x; |
| 1432 | |
| 1433 | convert_time_to_pixels( |
| 1434 | time_window, |
| 1435 | evtime, |
| 1436 | width, |
| 1437 | &new_x); |
| 1438 | |
| 1439 | if(hashed_process_data_in->x.middle != new_x) { |
| 1440 | hashed_process_data_in->x.middle = new_x; |
| 1441 | hashed_process_data_in->x.middle_used = FALSE; |
| 1442 | hashed_process_data_in->x.middle_marked = FALSE; |
| 1443 | } |
| 1444 | } |
| 1445 | return 0; |
| 1446 | |
| 1447 | |
| 1448 | |
| 1449 | |
| 1450 | |
| 1451 | #if 0 |
| 1452 | EventsRequest *events_request = (EventsRequest*)hook_data; |
| 1453 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 1454 | |
| 1455 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 1456 | |
| 1457 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 1458 | LttvTraceState *ts =(LttvTraceState *)LTTV_TRACEFILE_CONTEXT(tfs)->t_context; |
| 1459 | |
| 1460 | |
| 1461 | LttEvent *e; |
| 1462 | e = tfc->e; |
| 1463 | |
| 1464 | LttTime evtime = ltt_event_time(e); |
| 1465 | TimeWindow time_window = |
| 1466 | lttvwindow_get_time_window(control_flow_data->tab); |
| 1467 | |
| 1468 | LttTime time_window.end_time = time_window.time_window.end_time; |
| 1469 | |
| 1470 | //if(time < time_beg || time > time_end) return; |
| 1471 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 1472 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 1473 | return; |
| 1474 | |
| 1475 | |
| 1476 | if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0) |
| 1477 | { |
| 1478 | g_debug("schedchange!"); |
| 1479 | |
| 1480 | /* Add process to process list (if not present) and get drawing "y" from |
| 1481 | * process position */ |
| 1482 | guint pid_out, pid_in; |
| 1483 | LttvProcessState *process_out, *process_in; |
| 1484 | LttTime birth; |
| 1485 | guint y_in = 0, y_out = 0, height = 0, pl_height = 0; |
| 1486 | |
| 1487 | ProcessList *process_list = control_flow_data->process_list; |
| 1488 | |
| 1489 | |
| 1490 | LttField *f = ltt_event_field(e); |
| 1491 | LttField *element; |
| 1492 | element = ltt_field_member(f,0); |
| 1493 | pid_out = ltt_event_get_long_unsigned(e,element); |
| 1494 | element = ltt_field_member(f,1); |
| 1495 | pid_in = ltt_event_get_long_unsigned(e,element); |
| 1496 | //g_debug("out : %u in : %u", pid_out, pid_in); |
| 1497 | |
| 1498 | |
| 1499 | /* Find process pid_out in the list... */ |
| 1500 | process_out = lttv_state_find_process(tfs, pid_out); |
| 1501 | if(process_out == NULL) return 0; |
| 1502 | //g_debug("out : %s",g_quark_to_string(process_out->state->s)); |
| 1503 | |
| 1504 | birth = process_out->creation_time; |
| 1505 | gchar *name = strdup(g_quark_to_string(process_out->name)); |
| 1506 | HashedProcessData *hashed_process_data_out = NULL; |
| 1507 | |
| 1508 | if(processlist_get_process_pixels(process_list, |
| 1509 | pid_out, |
| 1510 | &birth, |
| 1511 | tfc->t_context->index, |
| 1512 | &y_out, |
| 1513 | &height, |
| 1514 | &hashed_process_data_out) == 1) |
| 1515 | { |
| 1516 | /* Process not present */ |
| 1517 | processlist_add(process_list, |
| 1518 | pid_out, |
| 1519 | &birth, |
| 1520 | tfc->t_context->index, |
| 1521 | name, |
| 1522 | &pl_height, |
| 1523 | &hashed_process_data_out); |
| 1524 | processlist_get_process_pixels(process_list, |
| 1525 | pid_out, |
| 1526 | &birth, |
| 1527 | tfc->t_context->index, |
| 1528 | &y_out, |
| 1529 | &height, |
| 1530 | &hashed_process_data_out); |
| 1531 | drawing_insert_square( control_flow_data->drawing, y_out, height); |
| 1532 | } |
| 1533 | |
| 1534 | g_free(name); |
| 1535 | |
| 1536 | /* Find process pid_in in the list... */ |
| 1537 | process_in = lttv_state_find_process(tfs, pid_in); |
| 1538 | if(process_in == NULL) return 0; |
| 1539 | //g_debug("in : %s",g_quark_to_string(process_in->state->s)); |
| 1540 | |
| 1541 | birth = process_in->creation_time; |
| 1542 | name = strdup(g_quark_to_string(process_in->name)); |
| 1543 | HashedProcessData *hashed_process_data_in = NULL; |
| 1544 | |
| 1545 | if(processlist_get_process_pixels(process_list, |
| 1546 | pid_in, |
| 1547 | &birth, |
| 1548 | tfc->t_context->index, |
| 1549 | &y_in, |
| 1550 | &height, |
| 1551 | &hashed_process_data_in) == 1) |
| 1552 | { |
| 1553 | /* Process not present */ |
| 1554 | processlist_add(process_list, |
| 1555 | pid_in, |
| 1556 | &birth, |
| 1557 | tfc->t_context->index, |
| 1558 | name, |
| 1559 | &pl_height, |
| 1560 | &hashed_process_data_in); |
| 1561 | processlist_get_process_pixels(process_list, |
| 1562 | pid_in, |
| 1563 | &birth, |
| 1564 | tfc->t_context->index, |
| 1565 | &y_in, |
| 1566 | &height, |
| 1567 | &hashed_process_data_in); |
| 1568 | |
| 1569 | drawing_insert_square( control_flow_data->drawing, y_in, height); |
| 1570 | } |
| 1571 | g_free(name); |
| 1572 | |
| 1573 | |
| 1574 | /* Find pixels corresponding to time of the event. If the time does |
| 1575 | * not fit in the window, show a warning, not supposed to happend. */ |
| 1576 | //guint x = 0; |
| 1577 | //guint width = control_flow_data->drawing->drawing_area->allocation.width; |
| 1578 | |
| 1579 | //LttTime time = ltt_event_time(e); |
| 1580 | |
| 1581 | //LttTime window_end = time_window->time_window.end_time; |
| 1582 | |
| 1583 | |
| 1584 | //convert_time_to_pixels( |
| 1585 | // *time_window, |
| 1586 | // time, |
| 1587 | // width, |
| 1588 | // &x); |
| 1589 | |
| 1590 | //assert(x <= width); |
| 1591 | |
| 1592 | /* draw what represents the event for outgoing process. */ |
| 1593 | |
| 1594 | DrawContext *draw_context_out = hashed_process_data_out->draw_context; |
| 1595 | //draw_context_out->current->modify_over->x = x; |
| 1596 | draw_context_out->current->modify_over->y = y_out; |
| 1597 | draw_context_out->current->modify_under->y = y_out+(height/2)+2; |
| 1598 | draw_context_out->drawable = control_flow_data->drawing->pixmap; |
| 1599 | draw_context_out->pango_layout = control_flow_data->drawing->pango_layout; |
| 1600 | GtkWidget *widget = control_flow_data->drawing->drawing_area; |
| 1601 | //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)]; |
| 1602 | |
| 1603 | //draw_arc((void*)&prop_arc, (void*)draw_context_out); |
| 1604 | //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap); |
| 1605 | |
| 1606 | /*if(process_out->state->s == LTTV_STATE_RUN) |
| 1607 | { |
| 1608 | draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap); |
| 1609 | gdk_gc_copy(draw_context_out->gc, widget->style->black_gc); |
| 1610 | PropertiesBG prop_bg; |
| 1611 | prop_bg.color = g_new(GdkColor,1); |
| 1612 | |
| 1613 | prop_bg.color->red = 0xffff; |
| 1614 | prop_bg.color->green = 0xffff; |
| 1615 | prop_bg.color->blue = 0xffff; |
| 1616 | |
| 1617 | draw_bg((void*)&prop_bg, (void*)draw_context_out); |
| 1618 | g_free(prop_bg.color); |
| 1619 | gdk_gc_unref(draw_context_out->gc); |
| 1620 | }*/ |
| 1621 | |
| 1622 | draw_context_out->gc = widget->style->black_gc; |
| 1623 | |
| 1624 | GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 }; |
| 1625 | GdkColor colorbg_out = { 0, 0x0000, 0x0000, 0x0000 }; |
| 1626 | PropertiesText prop_text_out; |
| 1627 | prop_text_out.foreground = &colorfg_out; |
| 1628 | prop_text_out.background = &colorbg_out; |
| 1629 | prop_text_out.size = 6; |
| 1630 | prop_text_out.position = OVER; |
| 1631 | |
| 1632 | /* color of text : status of the process */ |
| 1633 | if(process_out->state->s == LTTV_STATE_UNNAMED) |
| 1634 | { |
| 1635 | prop_text_out.foreground->red = 0xffff; |
| 1636 | prop_text_out.foreground->green = 0xffff; |
| 1637 | prop_text_out.foreground->blue = 0xffff; |
| 1638 | } |
| 1639 | else if(process_out->state->s == LTTV_STATE_WAIT_FORK) |
| 1640 | { |
| 1641 | prop_text_out.foreground->red = 0x0fff; |
| 1642 | prop_text_out.foreground->green = 0xffff; |
| 1643 | prop_text_out.foreground->blue = 0xfff0; |
| 1644 | } |
| 1645 | else if(process_out->state->s == LTTV_STATE_WAIT_CPU) |
| 1646 | { |
| 1647 | prop_text_out.foreground->red = 0xffff; |
| 1648 | prop_text_out.foreground->green = 0xffff; |
| 1649 | prop_text_out.foreground->blue = 0x0000; |
| 1650 | } |
| 1651 | else if(process_out->state->s == LTTV_STATE_ZOMBIE) |
| 1652 | { |
| 1653 | prop_text_out.foreground->red = 0xffff; |
| 1654 | prop_text_out.foreground->green = 0x0000; |
| 1655 | prop_text_out.foreground->blue = 0xffff; |
| 1656 | } |
| 1657 | else if(process_out->state->s == LTTV_STATE_WAIT) |
| 1658 | { |
| 1659 | prop_text_out.foreground->red = 0xffff; |
| 1660 | prop_text_out.foreground->green = 0x0000; |
| 1661 | prop_text_out.foreground->blue = 0x0000; |
| 1662 | } |
| 1663 | else if(process_out->state->s == LTTV_STATE_RUN) |
| 1664 | { |
| 1665 | prop_text_out.foreground->red = 0x0000; |
| 1666 | prop_text_out.foreground->green = 0xffff; |
| 1667 | prop_text_out.foreground->blue = 0x0000; |
| 1668 | } |
| 1669 | else |
| 1670 | { |
| 1671 | prop_text_out.foreground->red = 0xffff; |
| 1672 | prop_text_out.foreground->green = 0xffff; |
| 1673 | prop_text_out.foreground->blue = 0xffff; |
| 1674 | } |
| 1675 | |
| 1676 | /* Print status of the process : U, WF, WC, E, W, R */ |
| 1677 | if(process_out->state->s == LTTV_STATE_UNNAMED) |
| 1678 | prop_text_out.text = "U"; |
| 1679 | else if(process_out->state->s == LTTV_STATE_WAIT_FORK) |
| 1680 | prop_text_out.text = "WF"; |
| 1681 | else if(process_out->state->s == LTTV_STATE_WAIT_CPU) |
| 1682 | prop_text_out.text = "WC"; |
| 1683 | else if(process_out->state->s == LTTV_STATE_ZOMBIE) |
| 1684 | prop_text_out.text = "E"; |
| 1685 | else if(process_out->state->s == LTTV_STATE_WAIT) |
| 1686 | prop_text_out.text = "W"; |
| 1687 | else if(process_out->state->s == LTTV_STATE_RUN) |
| 1688 | prop_text_out.text = "R"; |
| 1689 | else |
| 1690 | prop_text_out.text = "U"; |
| 1691 | |
| 1692 | draw_text((void*)&prop_text_out, (void*)draw_context_out); |
| 1693 | |
| 1694 | //gdk_gc_unref(draw_context_out->gc); |
| 1695 | |
| 1696 | draw_context_out->current->middle->y = y_out+height/2; |
| 1697 | draw_context_out->current->over->y = y_out; |
| 1698 | draw_context_out->current->under->y = y_out+height; |
| 1699 | draw_context_out->current->status = process_out->state->s; |
| 1700 | |
| 1701 | /* for pid_out : remove previous, Prev = current, new current (default) */ |
| 1702 | g_free(draw_context_out->previous->modify_under); |
| 1703 | g_free(draw_context_out->previous->modify_middle); |
| 1704 | g_free(draw_context_out->previous->modify_over); |
| 1705 | g_free(draw_context_out->previous->under); |
| 1706 | g_free(draw_context_out->previous->middle); |
| 1707 | g_free(draw_context_out->previous->over); |
| 1708 | g_free(draw_context_out->previous); |
| 1709 | |
| 1710 | draw_context_out->previous = draw_context_out->current; |
| 1711 | |
| 1712 | draw_context_out->current = g_new(DrawInfo,1); |
| 1713 | draw_context_out->current->over = g_new(ItemInfo,1); |
| 1714 | draw_context_out->current->over->x = -1; |
| 1715 | draw_context_out->current->over->y = -1; |
| 1716 | draw_context_out->current->middle = g_new(ItemInfo,1); |
| 1717 | draw_context_out->current->middle->x = -1; |
| 1718 | draw_context_out->current->middle->y = -1; |
| 1719 | draw_context_out->current->under = g_new(ItemInfo,1); |
| 1720 | draw_context_out->current->under->x = -1; |
| 1721 | draw_context_out->current->under->y = -1; |
| 1722 | draw_context_out->current->modify_over = g_new(ItemInfo,1); |
| 1723 | draw_context_out->current->modify_over->x = -1; |
| 1724 | draw_context_out->current->modify_over->y = -1; |
| 1725 | draw_context_out->current->modify_middle = g_new(ItemInfo,1); |
| 1726 | draw_context_out->current->modify_middle->x = -1; |
| 1727 | draw_context_out->current->modify_middle->y = -1; |
| 1728 | draw_context_out->current->modify_under = g_new(ItemInfo,1); |
| 1729 | draw_context_out->current->modify_under->x = -1; |
| 1730 | draw_context_out->current->modify_under->y = -1; |
| 1731 | draw_context_out->current->status = LTTV_STATE_UNNAMED; |
| 1732 | |
| 1733 | /* Finally, update the drawing context of the pid_in. */ |
| 1734 | |
| 1735 | DrawContext *draw_context_in = hashed_process_data_in->draw_context; |
| 1736 | //draw_context_in->current->modify_over->x = x; |
| 1737 | draw_context_in->current->modify_over->y = y_in; |
| 1738 | draw_context_in->current->modify_under->y = y_in+(height/2)+2; |
| 1739 | draw_context_in->drawable = control_flow_data->drawing->pixmap; |
| 1740 | draw_context_in->pango_layout = control_flow_data->drawing->pango_layout; |
| 1741 | widget = control_flow_data->drawing->drawing_area; |
| 1742 | //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)]; |
| 1743 | |
| 1744 | //draw_arc((void*)&prop_arc, (void*)draw_context_in); |
| 1745 | //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap); |
| 1746 | |
| 1747 | /*if(process_in->state->s == LTTV_STATE_RUN) |
| 1748 | { |
| 1749 | draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap); |
| 1750 | gdk_gc_copy(draw_context_in->gc, widget->style->black_gc); |
| 1751 | PropertiesBG prop_bg; |
| 1752 | prop_bg.color = g_new(GdkColor,1); |
| 1753 | |
| 1754 | prop_bg.color->red = 0xffff; |
| 1755 | prop_bg.color->green = 0xffff; |
| 1756 | prop_bg.color->blue = 0xffff; |
| 1757 | |
| 1758 | draw_bg((void*)&prop_bg, (void*)draw_context_in); |
| 1759 | g_free(prop_bg.color); |
| 1760 | gdk_gc_unref(draw_context_in->gc); |
| 1761 | }*/ |
| 1762 | |
| 1763 | draw_context_in->gc = widget->style->black_gc; |
| 1764 | |
| 1765 | GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 }; |
| 1766 | GdkColor colorbg_in = { 0, 0x0000, 0x0000, 0x0000 }; |
| 1767 | PropertiesText prop_text_in; |
| 1768 | prop_text_in.foreground = &colorfg_in; |
| 1769 | prop_text_in.background = &colorbg_in; |
| 1770 | prop_text_in.size = 6; |
| 1771 | prop_text_in.position = OVER; |
| 1772 | |
| 1773 | /* foreground of text : status of the process */ |
| 1774 | if(process_in->state->s == LTTV_STATE_UNNAMED) |
| 1775 | { |
| 1776 | prop_text_in.foreground->red = 0xffff; |
| 1777 | prop_text_in.foreground->green = 0xffff; |
| 1778 | prop_text_in.foreground->blue = 0xffff; |
| 1779 | } |
| 1780 | else if(process_in->state->s == LTTV_STATE_WAIT_FORK) |
| 1781 | { |
| 1782 | prop_text_in.foreground->red = 0x0fff; |
| 1783 | prop_text_in.foreground->green = 0xffff; |
| 1784 | prop_text_in.foreground->blue = 0xfff0; |
| 1785 | } |
| 1786 | else if(process_in->state->s == LTTV_STATE_WAIT_CPU) |
| 1787 | { |
| 1788 | prop_text_in.foreground->red = 0xffff; |
| 1789 | prop_text_in.foreground->green = 0xffff; |
| 1790 | prop_text_in.foreground->blue = 0x0000; |
| 1791 | } |
| 1792 | else if(process_in->state->s == LTTV_STATE_ZOMBIE) |
| 1793 | { |
| 1794 | prop_text_in.foreground->red = 0xffff; |
| 1795 | prop_text_in.foreground->green = 0x0000; |
| 1796 | prop_text_in.foreground->blue = 0xffff; |
| 1797 | } |
| 1798 | else if(process_in->state->s == LTTV_STATE_WAIT) |
| 1799 | { |
| 1800 | prop_text_in.foreground->red = 0xffff; |
| 1801 | prop_text_in.foreground->green = 0x0000; |
| 1802 | prop_text_in.foreground->blue = 0x0000; |
| 1803 | } |
| 1804 | else if(process_in->state->s == LTTV_STATE_RUN) |
| 1805 | { |
| 1806 | prop_text_in.foreground->red = 0x0000; |
| 1807 | prop_text_in.foreground->green = 0xffff; |
| 1808 | prop_text_in.foreground->blue = 0x0000; |
| 1809 | } |
| 1810 | else |
| 1811 | { |
| 1812 | prop_text_in.foreground->red = 0xffff; |
| 1813 | prop_text_in.foreground->green = 0xffff; |
| 1814 | prop_text_in.foreground->blue = 0xffff; |
| 1815 | } |
| 1816 | |
| 1817 | |
| 1818 | /* Print status of the process : U, WF, WC, E, W, R */ |
| 1819 | if(process_in->state->s == LTTV_STATE_UNNAMED) |
| 1820 | prop_text_in.text = "U"; |
| 1821 | else if(process_in->state->s == LTTV_STATE_WAIT_FORK) |
| 1822 | prop_text_in.text = "WF"; |
| 1823 | else if(process_in->state->s == LTTV_STATE_WAIT_CPU) |
| 1824 | prop_text_in.text = "WC"; |
| 1825 | else if(process_in->state->s == LTTV_STATE_ZOMBIE) |
| 1826 | prop_text_in.text = "E"; |
| 1827 | else if(process_in->state->s == LTTV_STATE_WAIT) |
| 1828 | prop_text_in.text = "W"; |
| 1829 | else if(process_in->state->s == LTTV_STATE_RUN) |
| 1830 | prop_text_in.text = "R"; |
| 1831 | else |
| 1832 | prop_text_in.text = "U"; |
| 1833 | |
| 1834 | draw_text((void*)&prop_text_in, (void*)draw_context_in); |
| 1835 | |
| 1836 | |
| 1837 | if(process_in->state->s == LTTV_STATE_RUN) |
| 1838 | { |
| 1839 | gchar tmp[255]; |
| 1840 | prop_text_in.foreground = &colorfg_in; |
| 1841 | prop_text_in.background = &colorbg_in; |
| 1842 | prop_text_in.foreground->red = 0xffff; |
| 1843 | prop_text_in.foreground->green = 0xffff; |
| 1844 | prop_text_in.foreground->blue = 0xffff; |
| 1845 | prop_text_in.size = 6; |
| 1846 | prop_text_in.position = UNDER; |
| 1847 | |
| 1848 | prop_text_in.text = g_new(gchar, 260); |
| 1849 | strcpy(prop_text_in.text, "CPU "); |
| 1850 | snprintf(tmp, 255, "%u", ltt_tracefile_num(tfc->tf)); |
| 1851 | strcat(prop_text_in.text, tmp); |
| 1852 | |
| 1853 | draw_text((void*)&prop_text_in, (void*)draw_context_in); |
| 1854 | g_free(prop_text_in.text); |
| 1855 | } |
| 1856 | |
| 1857 | |
| 1858 | draw_context_in->current->middle->y = y_in+height/2; |
| 1859 | draw_context_in->current->over->y = y_in; |
| 1860 | draw_context_in->current->under->y = y_in+height; |
| 1861 | draw_context_in->current->status = process_in->state->s; |
| 1862 | |
| 1863 | /* for pid_in : remove previous, Prev = current, new current (default) */ |
| 1864 | g_free(draw_context_in->previous->modify_under); |
| 1865 | g_free(draw_context_in->previous->modify_middle); |
| 1866 | g_free(draw_context_in->previous->modify_over); |
| 1867 | g_free(draw_context_in->previous->under); |
| 1868 | g_free(draw_context_in->previous->middle); |
| 1869 | g_free(draw_context_in->previous->over); |
| 1870 | g_free(draw_context_in->previous); |
| 1871 | |
| 1872 | draw_context_in->previous = draw_context_in->current; |
| 1873 | |
| 1874 | draw_context_in->current = g_new(DrawInfo,1); |
| 1875 | draw_context_in->current->over = g_new(ItemInfo,1); |
| 1876 | draw_context_in->current->over->x = -1; |
| 1877 | draw_context_in->current->over->y = -1; |
| 1878 | draw_context_in->current->middle = g_new(ItemInfo,1); |
| 1879 | draw_context_in->current->middle->x = -1; |
| 1880 | draw_context_in->current->middle->y = -1; |
| 1881 | draw_context_in->current->under = g_new(ItemInfo,1); |
| 1882 | draw_context_in->current->under->x = -1; |
| 1883 | draw_context_in->current->under->y = -1; |
| 1884 | draw_context_in->current->modify_over = g_new(ItemInfo,1); |
| 1885 | draw_context_in->current->modify_over->x = -1; |
| 1886 | draw_context_in->current->modify_over->y = -1; |
| 1887 | draw_context_in->current->modify_middle = g_new(ItemInfo,1); |
| 1888 | draw_context_in->current->modify_middle->x = -1; |
| 1889 | draw_context_in->current->modify_middle->y = -1; |
| 1890 | draw_context_in->current->modify_under = g_new(ItemInfo,1); |
| 1891 | draw_context_in->current->modify_under->x = -1; |
| 1892 | draw_context_in->current->modify_under->y = -1; |
| 1893 | draw_context_in->current->status = LTTV_STATE_UNNAMED; |
| 1894 | |
| 1895 | } |
| 1896 | |
| 1897 | return 0; |
| 1898 | #endif //0 |
| 1899 | } |
| 1900 | |
| 1901 | #if 0 |
| 1902 | static inline PropertiesLine prepare_execmode_line(LttvProcessState *process) |
| 1903 | { |
| 1904 | PropertiesLine prop_line; |
| 1905 | prop_line.line_width = 1; |
| 1906 | prop_line.style = GDK_LINE_SOLID; |
| 1907 | prop_line.y = OVER; |
| 1908 | //GdkColormap *colormap = gdk_colormap_get_system(); |
| 1909 | |
| 1910 | /* color of line : execution mode of the process */ |
| 1911 | if(process->state->t == LTTV_STATE_USER_MODE) |
| 1912 | prop_line.color = drawing_colors[COL_USER_MODE]; |
| 1913 | else if(process->state->t == LTTV_STATE_SYSCALL) |
| 1914 | prop_line.color = drawing_colors[COL_SYSCALL]; |
| 1915 | else if(process->state->t == LTTV_STATE_TRAP) |
| 1916 | prop_line.color = drawing_colors[COL_TRAP]; |
| 1917 | else if(process->state->t == LTTV_STATE_IRQ) |
| 1918 | prop_line.color = drawing_colors[COL_IRQ]; |
| 1919 | else if(process->state->t == LTTV_STATE_MODE_UNKNOWN) |
| 1920 | prop_line.color = drawing_colors[COL_MODE_UNKNOWN]; |
| 1921 | else |
| 1922 | prop_line.color = drawing_colors[COL_WHITE]; |
| 1923 | |
| 1924 | //gdk_colormap_alloc_color(colormap, |
| 1925 | // prop_line.color, |
| 1926 | // FALSE, |
| 1927 | // TRUE); |
| 1928 | |
| 1929 | return prop_line; |
| 1930 | |
| 1931 | } |
| 1932 | #endif //0 |
| 1933 | |
| 1934 | |
| 1935 | /* before_execmode_hook |
| 1936 | * |
| 1937 | * This function basically draw lines and icons. Two types of lines are drawn : |
| 1938 | * one small (3 pixels?) representing the state of the process and the second |
| 1939 | * type is thicker (10 pixels?) representing on which CPU a process is running |
| 1940 | * (and this only in running state). |
| 1941 | * |
| 1942 | * Extremums of the lines : |
| 1943 | * x_min : time of the last event context for this process kept in memory. |
| 1944 | * x_max : time of the current event. |
| 1945 | * y : middle of the process in the process list. The process is found in the |
| 1946 | * list, therefore is it's position in pixels. |
| 1947 | * |
| 1948 | * The choice of lines'color is defined by the context of the last event for this |
| 1949 | * process. |
| 1950 | */ |
| 1951 | |
| 1952 | |
| 1953 | int before_execmode_hook(void *hook_data, void *call_data) |
| 1954 | { |
| 1955 | return 0; //DISABLED |
| 1956 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 1957 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 1958 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 1959 | |
| 1960 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 1961 | |
| 1962 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 1963 | |
| 1964 | LttEvent *e; |
| 1965 | e = ltt_tracefile_get_event(tfc->tf); |
| 1966 | |
| 1967 | LttTime evtime = ltt_event_time(e); |
| 1968 | |
| 1969 | /* we are in a execmode, before the state update. We must draw the |
| 1970 | * items corresponding to the state before it changes : now is the right |
| 1971 | * time to do it. |
| 1972 | */ |
| 1973 | /* For the pid */ |
| 1974 | LttvProcessState *process = tfs->process; |
| 1975 | g_assert(process != NULL); |
| 1976 | |
| 1977 | guint pid = process->pid; |
| 1978 | |
| 1979 | /* Well, the process_out existed : we must get it in the process hash |
| 1980 | * or add it, and draw its items. |
| 1981 | */ |
| 1982 | /* Add process to process list (if not present) */ |
| 1983 | guint pl_height = 0; |
| 1984 | HashedProcessData *hashed_process_data = NULL; |
| 1985 | ProcessList *process_list = control_flow_data->process_list; |
| 1986 | LttTime birth = process->creation_time; |
| 1987 | |
| 1988 | if(likely(process_list->current_hash_data[ltt_tracefile_num(tfc->tf)] != NULL)) { |
| 1989 | hashed_process_data = process_list->current_hash_data[ltt_tracefile_num(tfc->tf)]; |
| 1990 | } else { |
| 1991 | hashed_process_data = processlist_get_process_data(process_list, |
| 1992 | pid, |
| 1993 | process->last_cpu_index, |
| 1994 | &birth, |
| 1995 | tfc->t_context->index); |
| 1996 | if(unlikely(hashed_process_data == NULL)) |
| 1997 | { |
| 1998 | g_assert(pid == 0 || pid != process->ppid); |
| 1999 | ProcessInfo *process_info; |
| 2000 | /* Process not present */ |
| 2001 | Drawing_t *drawing = control_flow_data->drawing; |
| 2002 | const gchar *name = g_quark_to_string(process->name); |
| 2003 | processlist_add(process_list, |
| 2004 | drawing, |
| 2005 | pid, |
| 2006 | process->last_cpu_index, |
| 2007 | process->ppid, |
| 2008 | &birth, |
| 2009 | tfc->t_context->index, |
| 2010 | name, |
| 2011 | &pl_height, |
| 2012 | &process_info, |
| 2013 | &hashed_process_data); |
| 2014 | gtk_widget_set_size_request(drawing->drawing_area, |
| 2015 | -1, |
| 2016 | pl_height); |
| 2017 | gtk_widget_queue_draw(drawing->drawing_area); |
| 2018 | } |
| 2019 | /* Set the current process */ |
| 2020 | process_list->current_hash_data[process->last_cpu_index] = |
| 2021 | hashed_process_data; |
| 2022 | } |
| 2023 | |
| 2024 | /* Now, the process is in the state hash and our own process hash. |
| 2025 | * We definitely can draw the items related to the ending state. |
| 2026 | */ |
| 2027 | |
| 2028 | if(likely(ltt_time_compare(hashed_process_data->next_good_time, |
| 2029 | evtime) > 0)) |
| 2030 | { |
| 2031 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
| 2032 | TimeWindow time_window = |
| 2033 | lttvwindow_get_time_window(control_flow_data->tab); |
| 2034 | |
| 2035 | #ifdef EXTRA_CHECK |
| 2036 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 2037 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 2038 | return; |
| 2039 | #endif //EXTRA_CHECK |
| 2040 | Drawing_t *drawing = control_flow_data->drawing; |
| 2041 | guint width = drawing->width; |
| 2042 | guint x; |
| 2043 | convert_time_to_pixels( |
| 2044 | time_window, |
| 2045 | evtime, |
| 2046 | width, |
| 2047 | &x); |
| 2048 | |
| 2049 | /* Draw collision indicator */ |
| 2050 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 2051 | gdk_draw_point(hashed_process_data->pixmap, |
| 2052 | drawing->gc, |
| 2053 | x, |
| 2054 | (hashed_process_data->height/2)-3); |
| 2055 | hashed_process_data->x.middle_marked = TRUE; |
| 2056 | } |
| 2057 | } else { |
| 2058 | TimeWindow time_window = |
| 2059 | lttvwindow_get_time_window(control_flow_data->tab); |
| 2060 | |
| 2061 | #ifdef EXTRA_CHECK |
| 2062 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 2063 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 2064 | return; |
| 2065 | #endif //EXTRA_CHECK |
| 2066 | Drawing_t *drawing = control_flow_data->drawing; |
| 2067 | guint width = drawing->width; |
| 2068 | guint x; |
| 2069 | |
| 2070 | convert_time_to_pixels( |
| 2071 | time_window, |
| 2072 | evtime, |
| 2073 | width, |
| 2074 | &x); |
| 2075 | |
| 2076 | |
| 2077 | /* Jump over draw if we are at the same x position */ |
| 2078 | if(unlikely(x == hashed_process_data->x.middle && |
| 2079 | hashed_process_data->x.middle_used)) |
| 2080 | { |
| 2081 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
| 2082 | /* Draw collision indicator */ |
| 2083 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 2084 | gdk_draw_point(hashed_process_data->pixmap, |
| 2085 | drawing->gc, |
| 2086 | x, |
| 2087 | (hashed_process_data->height/2)-3); |
| 2088 | hashed_process_data->x.middle_marked = TRUE; |
| 2089 | } |
| 2090 | /* jump */ |
| 2091 | } else { |
| 2092 | |
| 2093 | DrawContext draw_context; |
| 2094 | /* Now create the drawing context that will be used to draw |
| 2095 | * items related to the last state. */ |
| 2096 | draw_context.drawable = hashed_process_data->pixmap; |
| 2097 | draw_context.gc = drawing->gc; |
| 2098 | draw_context.pango_layout = drawing->pango_layout; |
| 2099 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
| 2100 | draw_context.drawinfo.end.x = x; |
| 2101 | |
| 2102 | draw_context.drawinfo.y.over = 1; |
| 2103 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
| 2104 | draw_context.drawinfo.y.under = hashed_process_data->height; |
| 2105 | |
| 2106 | draw_context.drawinfo.start.offset.over = 0; |
| 2107 | draw_context.drawinfo.start.offset.middle = 0; |
| 2108 | draw_context.drawinfo.start.offset.under = 0; |
| 2109 | draw_context.drawinfo.end.offset.over = 0; |
| 2110 | draw_context.drawinfo.end.offset.middle = 0; |
| 2111 | draw_context.drawinfo.end.offset.under = 0; |
| 2112 | |
| 2113 | { |
| 2114 | /* Draw the line */ |
| 2115 | PropertiesLine prop_line = prepare_s_e_line(process); |
| 2116 | draw_line((void*)&prop_line, (void*)&draw_context); |
| 2117 | |
| 2118 | } |
| 2119 | /* become the last x position */ |
| 2120 | hashed_process_data->x.middle = x; |
| 2121 | hashed_process_data->x.middle_used = TRUE; |
| 2122 | hashed_process_data->x.middle_marked = FALSE; |
| 2123 | |
| 2124 | /* Calculate the next good time */ |
| 2125 | convert_pixels_to_time(width, x+1, time_window, |
| 2126 | &hashed_process_data->next_good_time); |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | return 0; |
| 2131 | } |
| 2132 | |
| 2133 | /* after_execmode_hook |
| 2134 | * |
| 2135 | * The draw after hook is called by the reading API to have a |
| 2136 | * particular event drawn on the screen. |
| 2137 | * @param hook_data ControlFlowData structure of the viewer. |
| 2138 | * @param call_data Event context. |
| 2139 | * |
| 2140 | * This function adds items to be drawn in a queue for each process. |
| 2141 | * |
| 2142 | */ |
| 2143 | int after_execmode_hook(void *hook_data, void *call_data) |
| 2144 | { |
| 2145 | /**************** DOES NOTHING!! *************/ |
| 2146 | /* hook desactivated in drawing.c */ |
| 2147 | return 0; |
| 2148 | |
| 2149 | |
| 2150 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 2151 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 2152 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 2153 | |
| 2154 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 2155 | |
| 2156 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 2157 | |
| 2158 | LttEvent *e; |
| 2159 | e = ltt_tracefile_get_event(tfc->tf); |
| 2160 | |
| 2161 | LttTime evtime = ltt_event_time(e); |
| 2162 | |
| 2163 | /* Add process to process list (if not present) */ |
| 2164 | LttvProcessState *process; |
| 2165 | LttTime birth; |
| 2166 | guint pl_height = 0; |
| 2167 | HashedProcessData *hashed_process_data = NULL; |
| 2168 | |
| 2169 | ProcessList *process_list = control_flow_data->process_list; |
| 2170 | |
| 2171 | /* Find process pid_in in the list... */ |
| 2172 | process = tfs->process; |
| 2173 | /* It should exist, because we are after the state update. */ |
| 2174 | g_assert(process != NULL); |
| 2175 | |
| 2176 | guint pid = process->pid; |
| 2177 | |
| 2178 | birth = process->creation_time; |
| 2179 | |
| 2180 | if(likely(process_list->current_hash_data[ltt_tracefile_num(tfc->tf)] != NULL)) { |
| 2181 | hashed_process_data = process_list->current_hash_data[ltt_tracefile_num(tfc->tf)]; |
| 2182 | } else { |
| 2183 | hashed_process_data = processlist_get_process_data(process_list, |
| 2184 | pid, |
| 2185 | process->last_cpu_index, |
| 2186 | &birth, |
| 2187 | tfc->t_context->index); |
| 2188 | if(unlikely(hashed_process_data == NULL)) |
| 2189 | { |
| 2190 | g_assert(pid == 0 || pid != process->ppid); |
| 2191 | /* Process not present */ |
| 2192 | Drawing_t *drawing = control_flow_data->drawing; |
| 2193 | const gchar *name = g_quark_to_string(process->name); |
| 2194 | ProcessInfo *process_info; |
| 2195 | processlist_add(process_list, |
| 2196 | drawing, |
| 2197 | pid, |
| 2198 | process->last_cpu_index, |
| 2199 | process->ppid, |
| 2200 | &birth, |
| 2201 | tfc->t_context->index, |
| 2202 | name, |
| 2203 | &pl_height, |
| 2204 | &process_info, |
| 2205 | &hashed_process_data); |
| 2206 | gtk_widget_set_size_request(drawing->drawing_area, |
| 2207 | -1, |
| 2208 | pl_height); |
| 2209 | gtk_widget_queue_draw(drawing->drawing_area); |
| 2210 | } |
| 2211 | /* Set the current process */ |
| 2212 | process_list->current_hash_data[process->last_cpu_index] = |
| 2213 | hashed_process_data; |
| 2214 | } |
| 2215 | |
| 2216 | if(unlikely(ltt_time_compare(hashed_process_data->next_good_time, |
| 2217 | evtime) <= 0)) |
| 2218 | { |
| 2219 | TimeWindow time_window = |
| 2220 | lttvwindow_get_time_window(control_flow_data->tab); |
| 2221 | |
| 2222 | #ifdef EXTRA_CHECK |
| 2223 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 2224 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 2225 | return; |
| 2226 | #endif //EXTRA_CHECK |
| 2227 | Drawing_t *drawing = control_flow_data->drawing; |
| 2228 | guint width = drawing->width; |
| 2229 | guint new_x; |
| 2230 | |
| 2231 | convert_time_to_pixels( |
| 2232 | time_window, |
| 2233 | evtime, |
| 2234 | width, |
| 2235 | &new_x); |
| 2236 | |
| 2237 | if(hashed_process_data->x.middle != new_x) { |
| 2238 | hashed_process_data->x.middle = new_x; |
| 2239 | hashed_process_data->x.middle_used = FALSE; |
| 2240 | hashed_process_data->x.middle_marked = FALSE; |
| 2241 | } |
| 2242 | } |
| 2243 | return 0; |
| 2244 | } |
| 2245 | |
| 2246 | |
| 2247 | |
| 2248 | |
| 2249 | /* before_process_exit_hook |
| 2250 | * |
| 2251 | * Draw lines for process event. |
| 2252 | * |
| 2253 | * @param hook_data ControlFlowData structure of the viewer. |
| 2254 | * @param call_data Event context. |
| 2255 | * |
| 2256 | * This function adds items to be drawn in a queue for each process. |
| 2257 | * |
| 2258 | */ |
| 2259 | |
| 2260 | |
| 2261 | int before_process_exit_hook(void *hook_data, void *call_data) |
| 2262 | { |
| 2263 | return 0; //DISABLED |
| 2264 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 2265 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 2266 | |
| 2267 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 2268 | |
| 2269 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 2270 | |
| 2271 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 2272 | |
| 2273 | LttEvent *e; |
| 2274 | e = ltt_tracefile_get_event(tfc->tf); |
| 2275 | |
| 2276 | LttTime evtime = ltt_event_time(e); |
| 2277 | |
| 2278 | /* Add process to process list (if not present) */ |
| 2279 | LttvProcessState *process = tfs->process; |
| 2280 | guint pid = process->pid; |
| 2281 | LttTime birth; |
| 2282 | guint pl_height = 0; |
| 2283 | HashedProcessData *hashed_process_data = NULL; |
| 2284 | |
| 2285 | ProcessList *process_list = control_flow_data->process_list; |
| 2286 | |
| 2287 | g_assert(process != NULL); |
| 2288 | |
| 2289 | birth = process->creation_time; |
| 2290 | |
| 2291 | if(likely(process_list->current_hash_data[ltt_tracefile_num(tfc->tf)] != NULL)) { |
| 2292 | hashed_process_data = process_list->current_hash_data[ltt_tracefile_num(tfc->tf)]; |
| 2293 | } else { |
| 2294 | hashed_process_data = processlist_get_process_data(process_list, |
| 2295 | pid, |
| 2296 | process->last_cpu_index, |
| 2297 | &birth, |
| 2298 | tfc->t_context->index); |
| 2299 | if(unlikely(hashed_process_data == NULL)) |
| 2300 | { |
| 2301 | g_assert(pid == 0 || pid != process->ppid); |
| 2302 | /* Process not present */ |
| 2303 | Drawing_t *drawing = control_flow_data->drawing; |
| 2304 | const gchar *name = g_quark_to_string(process->name); |
| 2305 | ProcessInfo *process_info; |
| 2306 | processlist_add(process_list, |
| 2307 | drawing, |
| 2308 | pid, |
| 2309 | process->last_cpu_index, |
| 2310 | process->ppid, |
| 2311 | &birth, |
| 2312 | tfc->t_context->index, |
| 2313 | name, |
| 2314 | &pl_height, |
| 2315 | &process_info, |
| 2316 | &hashed_process_data); |
| 2317 | gtk_widget_set_size_request(drawing->drawing_area, |
| 2318 | -1, |
| 2319 | pl_height); |
| 2320 | gtk_widget_queue_draw(drawing->drawing_area); |
| 2321 | } |
| 2322 | } |
| 2323 | |
| 2324 | /* Now, the process is in the state hash and our own process hash. |
| 2325 | * We definitely can draw the items related to the ending state. |
| 2326 | */ |
| 2327 | |
| 2328 | if(likely(ltt_time_compare(hashed_process_data->next_good_time, |
| 2329 | evtime) > 0)) |
| 2330 | { |
| 2331 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
| 2332 | TimeWindow time_window = |
| 2333 | lttvwindow_get_time_window(control_flow_data->tab); |
| 2334 | |
| 2335 | #ifdef EXTRA_CHECK |
| 2336 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 2337 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 2338 | return; |
| 2339 | #endif //EXTRA_CHECK |
| 2340 | Drawing_t *drawing = control_flow_data->drawing; |
| 2341 | guint width = drawing->width; |
| 2342 | guint x; |
| 2343 | convert_time_to_pixels( |
| 2344 | time_window, |
| 2345 | evtime, |
| 2346 | width, |
| 2347 | &x); |
| 2348 | |
| 2349 | /* Draw collision indicator */ |
| 2350 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 2351 | gdk_draw_point(hashed_process_data->pixmap, |
| 2352 | drawing->gc, |
| 2353 | x, |
| 2354 | (hashed_process_data->height/2)-3); |
| 2355 | hashed_process_data->x.middle_marked = TRUE; |
| 2356 | } |
| 2357 | } else { |
| 2358 | TimeWindow time_window = |
| 2359 | lttvwindow_get_time_window(control_flow_data->tab); |
| 2360 | |
| 2361 | #ifdef EXTRA_CHECK |
| 2362 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 2363 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 2364 | return; |
| 2365 | #endif //EXTRA_CHECK |
| 2366 | Drawing_t *drawing = control_flow_data->drawing; |
| 2367 | guint width = drawing->width; |
| 2368 | guint x; |
| 2369 | |
| 2370 | convert_time_to_pixels( |
| 2371 | time_window, |
| 2372 | evtime, |
| 2373 | width, |
| 2374 | &x); |
| 2375 | |
| 2376 | |
| 2377 | /* Jump over draw if we are at the same x position */ |
| 2378 | if(unlikely(x == hashed_process_data->x.middle && |
| 2379 | hashed_process_data->x.middle_used)) |
| 2380 | { |
| 2381 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
| 2382 | /* Draw collision indicator */ |
| 2383 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 2384 | gdk_draw_point(hashed_process_data->pixmap, |
| 2385 | drawing->gc, |
| 2386 | x, |
| 2387 | (hashed_process_data->height/2)-3); |
| 2388 | hashed_process_data->x.middle_marked = TRUE; |
| 2389 | } |
| 2390 | /* jump */ |
| 2391 | } else { |
| 2392 | DrawContext draw_context; |
| 2393 | |
| 2394 | /* Now create the drawing context that will be used to draw |
| 2395 | * items related to the last state. */ |
| 2396 | draw_context.drawable = hashed_process_data->pixmap; |
| 2397 | draw_context.gc = drawing->gc; |
| 2398 | draw_context.pango_layout = drawing->pango_layout; |
| 2399 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
| 2400 | draw_context.drawinfo.end.x = x; |
| 2401 | |
| 2402 | draw_context.drawinfo.y.over = 1; |
| 2403 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
| 2404 | draw_context.drawinfo.y.under = hashed_process_data->height; |
| 2405 | |
| 2406 | draw_context.drawinfo.start.offset.over = 0; |
| 2407 | draw_context.drawinfo.start.offset.middle = 0; |
| 2408 | draw_context.drawinfo.start.offset.under = 0; |
| 2409 | draw_context.drawinfo.end.offset.over = 0; |
| 2410 | draw_context.drawinfo.end.offset.middle = 0; |
| 2411 | draw_context.drawinfo.end.offset.under = 0; |
| 2412 | |
| 2413 | { |
| 2414 | /* Draw the line */ |
| 2415 | PropertiesLine prop_line = prepare_s_e_line(process); |
| 2416 | draw_line((void*)&prop_line, (void*)&draw_context); |
| 2417 | |
| 2418 | } |
| 2419 | /* become the last x position */ |
| 2420 | hashed_process_data->x.middle = x; |
| 2421 | hashed_process_data->x.middle_used = TRUE; |
| 2422 | hashed_process_data->x.middle_marked = FALSE; |
| 2423 | |
| 2424 | /* Calculate the next good time */ |
| 2425 | convert_pixels_to_time(width, x+1, time_window, |
| 2426 | &hashed_process_data->next_good_time); |
| 2427 | } |
| 2428 | } |
| 2429 | |
| 2430 | return 0; |
| 2431 | |
| 2432 | } |
| 2433 | |
| 2434 | |
| 2435 | |
| 2436 | /* before_process_release_hook |
| 2437 | * |
| 2438 | * Draw lines for process event. |
| 2439 | * |
| 2440 | * @param hook_data ControlFlowData structure of the viewer. |
| 2441 | * @param call_data Event context. |
| 2442 | * |
| 2443 | * This function adds items to be drawn in a queue for each process. |
| 2444 | * |
| 2445 | */ |
| 2446 | |
| 2447 | |
| 2448 | int before_process_release_hook(void *hook_data, void *call_data) |
| 2449 | { |
| 2450 | return 0; //DISABLED |
| 2451 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 2452 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 2453 | |
| 2454 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 2455 | |
| 2456 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 2457 | |
| 2458 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 2459 | |
| 2460 | LttEvent *e; |
| 2461 | e = ltt_tracefile_get_event(tfc->tf); |
| 2462 | |
| 2463 | LttTime evtime = ltt_event_time(e); |
| 2464 | |
| 2465 | |
| 2466 | guint pid; |
| 2467 | { |
| 2468 | pid = ltt_event_get_long_unsigned(e, thf->f1); |
| 2469 | } |
| 2470 | |
| 2471 | /* Add process to process list (if not present) */ |
| 2472 | /* Don't care about the process if it's not in the state hash already : |
| 2473 | * that means a process that has never done anything in the trace and |
| 2474 | * unknown suddently gets destroyed : no state meaningful to show. */ |
| 2475 | LttvProcessState *process = lttv_state_find_process(tfs, pid); |
| 2476 | |
| 2477 | if(process != NULL) { |
| 2478 | LttTime birth; |
| 2479 | guint pl_height = 0; |
| 2480 | HashedProcessData *hashed_process_data = NULL; |
| 2481 | |
| 2482 | ProcessList *process_list = control_flow_data->process_list; |
| 2483 | |
| 2484 | birth = process->creation_time; |
| 2485 | |
| 2486 | /* Cannot use current process : this event happens on another process, |
| 2487 | * action done by the parent. */ |
| 2488 | hashed_process_data = processlist_get_process_data(process_list, |
| 2489 | pid, |
| 2490 | process->last_cpu_index, |
| 2491 | &birth, |
| 2492 | tfc->t_context->index); |
| 2493 | if(unlikely(hashed_process_data == NULL)) |
| 2494 | { |
| 2495 | g_assert(pid == 0 || pid != process->ppid); |
| 2496 | /* Process not present */ |
| 2497 | Drawing_t *drawing = control_flow_data->drawing; |
| 2498 | const gchar *name = g_quark_to_string(process->name); |
| 2499 | ProcessInfo *process_info; |
| 2500 | processlist_add(process_list, |
| 2501 | drawing, |
| 2502 | pid, |
| 2503 | process->last_cpu_index, |
| 2504 | process->ppid, |
| 2505 | &birth, |
| 2506 | tfc->t_context->index, |
| 2507 | name, |
| 2508 | &pl_height, |
| 2509 | &process_info, |
| 2510 | &hashed_process_data); |
| 2511 | gtk_widget_set_size_request(drawing->drawing_area, |
| 2512 | -1, |
| 2513 | pl_height); |
| 2514 | gtk_widget_queue_draw(drawing->drawing_area); |
| 2515 | } |
| 2516 | |
| 2517 | /* Now, the process is in the state hash and our own process hash. |
| 2518 | * We definitely can draw the items related to the ending state. |
| 2519 | */ |
| 2520 | |
| 2521 | if(likely(ltt_time_compare(hashed_process_data->next_good_time, |
| 2522 | evtime) > 0)) |
| 2523 | { |
| 2524 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
| 2525 | TimeWindow time_window = |
| 2526 | lttvwindow_get_time_window(control_flow_data->tab); |
| 2527 | |
| 2528 | #ifdef EXTRA_CHECK |
| 2529 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 2530 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 2531 | return; |
| 2532 | #endif //EXTRA_CHECK |
| 2533 | Drawing_t *drawing = control_flow_data->drawing; |
| 2534 | guint width = drawing->width; |
| 2535 | guint x; |
| 2536 | convert_time_to_pixels( |
| 2537 | time_window, |
| 2538 | evtime, |
| 2539 | width, |
| 2540 | &x); |
| 2541 | |
| 2542 | /* Draw collision indicator */ |
| 2543 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 2544 | gdk_draw_point(hashed_process_data->pixmap, |
| 2545 | drawing->gc, |
| 2546 | x, |
| 2547 | (hashed_process_data->height/2)-3); |
| 2548 | hashed_process_data->x.middle_marked = TRUE; |
| 2549 | } |
| 2550 | } else { |
| 2551 | TimeWindow time_window = |
| 2552 | lttvwindow_get_time_window(control_flow_data->tab); |
| 2553 | |
| 2554 | #ifdef EXTRA_CHECK |
| 2555 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 2556 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 2557 | return; |
| 2558 | #endif //EXTRA_CHECK |
| 2559 | Drawing_t *drawing = control_flow_data->drawing; |
| 2560 | guint width = drawing->width; |
| 2561 | guint x; |
| 2562 | |
| 2563 | convert_time_to_pixels( |
| 2564 | time_window, |
| 2565 | evtime, |
| 2566 | width, |
| 2567 | &x); |
| 2568 | |
| 2569 | |
| 2570 | /* Jump over draw if we are at the same x position */ |
| 2571 | if(unlikely(x == hashed_process_data->x.middle && |
| 2572 | hashed_process_data->x.middle_used)) |
| 2573 | { |
| 2574 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
| 2575 | /* Draw collision indicator */ |
| 2576 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 2577 | gdk_draw_point(hashed_process_data->pixmap, |
| 2578 | drawing->gc, |
| 2579 | x, |
| 2580 | (hashed_process_data->height/2)-3); |
| 2581 | hashed_process_data->x.middle_marked = TRUE; |
| 2582 | } |
| 2583 | /* jump */ |
| 2584 | } else { |
| 2585 | DrawContext draw_context; |
| 2586 | |
| 2587 | /* Now create the drawing context that will be used to draw |
| 2588 | * items related to the last state. */ |
| 2589 | draw_context.drawable = hashed_process_data->pixmap; |
| 2590 | draw_context.gc = drawing->gc; |
| 2591 | draw_context.pango_layout = drawing->pango_layout; |
| 2592 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
| 2593 | draw_context.drawinfo.end.x = x; |
| 2594 | |
| 2595 | draw_context.drawinfo.y.over = 1; |
| 2596 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
| 2597 | draw_context.drawinfo.y.under = hashed_process_data->height; |
| 2598 | |
| 2599 | draw_context.drawinfo.start.offset.over = 0; |
| 2600 | draw_context.drawinfo.start.offset.middle = 0; |
| 2601 | draw_context.drawinfo.start.offset.under = 0; |
| 2602 | draw_context.drawinfo.end.offset.over = 0; |
| 2603 | draw_context.drawinfo.end.offset.middle = 0; |
| 2604 | draw_context.drawinfo.end.offset.under = 0; |
| 2605 | |
| 2606 | { |
| 2607 | /* Draw the line */ |
| 2608 | PropertiesLine prop_line = prepare_s_e_line(process); |
| 2609 | draw_line((void*)&prop_line, (void*)&draw_context); |
| 2610 | |
| 2611 | } |
| 2612 | /* become the last x position */ |
| 2613 | hashed_process_data->x.middle = x; |
| 2614 | hashed_process_data->x.middle_used = TRUE; |
| 2615 | hashed_process_data->x.middle_marked = FALSE; |
| 2616 | |
| 2617 | /* Calculate the next good time */ |
| 2618 | convert_pixels_to_time(width, x+1, time_window, |
| 2619 | &hashed_process_data->next_good_time); |
| 2620 | } |
| 2621 | } |
| 2622 | } |
| 2623 | |
| 2624 | return 0; |
| 2625 | } |
| 2626 | |
| 2627 | |
| 2628 | |
| 2629 | |
| 2630 | |
| 2631 | |
| 2632 | |
| 2633 | |
| 2634 | #if 0 |
| 2635 | /* before_process_hook |
| 2636 | * |
| 2637 | * Draw lines for process event. |
| 2638 | * |
| 2639 | * @param hook_data ControlFlowData structure of the viewer. |
| 2640 | * @param call_data Event context. |
| 2641 | * |
| 2642 | * This function adds items to be drawn in a queue for each process. |
| 2643 | * |
| 2644 | */ |
| 2645 | int before_process_hook(void *hook_data, void *call_data) |
| 2646 | { |
| 2647 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 2648 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 2649 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 2650 | |
| 2651 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 2652 | |
| 2653 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 2654 | |
| 2655 | LttEvent *e; |
| 2656 | e = ltt_tracefile_get_event(tfc->tf); |
| 2657 | |
| 2658 | LttTime evtime = ltt_event_time(e); |
| 2659 | |
| 2660 | guint sub_id; |
| 2661 | { |
| 2662 | LttField *f = ltt_event_field(e); |
| 2663 | LttField *element; |
| 2664 | element = ltt_field_member(f,0); |
| 2665 | sub_id = ltt_event_get_long_unsigned(e,element); |
| 2666 | } |
| 2667 | |
| 2668 | if(sub_id == 3) { /* exit */ |
| 2669 | |
| 2670 | /* Add process to process list (if not present) */ |
| 2671 | LttvProcessState *process = tfs->process; |
| 2672 | guint pid = process->pid; |
| 2673 | LttTime birth; |
| 2674 | guint pl_height = 0; |
| 2675 | HashedProcessData *hashed_process_data = NULL; |
| 2676 | |
| 2677 | ProcessList *process_list = control_flow_data->process_list; |
| 2678 | |
| 2679 | g_assert(process != NULL); |
| 2680 | |
| 2681 | birth = process->creation_time; |
| 2682 | |
| 2683 | if(likely(process_list->current_hash_data[tfc->index] != NULL)) { |
| 2684 | hashed_process_data = process_list->current_hash_data[tfc->index]; |
| 2685 | } else { |
| 2686 | hashed_process_data = processlist_get_process_data(process_list, |
| 2687 | pid, |
| 2688 | process->last_cpu_index, |
| 2689 | &birth, |
| 2690 | tfc->t_context->index); |
| 2691 | if(unlikely(hashed_process_data == NULL)) |
| 2692 | { |
| 2693 | g_assert(pid == 0 || pid != process->ppid); |
| 2694 | /* Process not present */ |
| 2695 | Drawing_t *drawing = control_flow_data->drawing; |
| 2696 | const gchar *name = g_quark_to_string(process->name); |
| 2697 | ProcessInfo *process_info; |
| 2698 | processlist_add(process_list, |
| 2699 | drawing, |
| 2700 | pid, |
| 2701 | process->last_cpu_index, |
| 2702 | process->ppid, |
| 2703 | &birth, |
| 2704 | tfc->t_context->index, |
| 2705 | name, |
| 2706 | &pl_height, |
| 2707 | &process_info, |
| 2708 | &hashed_process_data); |
| 2709 | gtk_widget_set_size_request(drawing->drawing_area, |
| 2710 | -1, |
| 2711 | pl_height); |
| 2712 | gtk_widget_queue_draw(drawing->drawing_area); |
| 2713 | } |
| 2714 | } |
| 2715 | |
| 2716 | /* Now, the process is in the state hash and our own process hash. |
| 2717 | * We definitely can draw the items related to the ending state. |
| 2718 | */ |
| 2719 | |
| 2720 | if(likely(ltt_time_compare(hashed_process_data->next_good_time, |
| 2721 | evtime) > 0)) |
| 2722 | { |
| 2723 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
| 2724 | TimeWindow time_window = |
| 2725 | lttvwindow_get_time_window(control_flow_data->tab); |
| 2726 | |
| 2727 | #ifdef EXTRA_CHECK |
| 2728 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 2729 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 2730 | return; |
| 2731 | #endif //EXTRA_CHECK |
| 2732 | Drawing_t *drawing = control_flow_data->drawing; |
| 2733 | guint width = drawing->width; |
| 2734 | guint x; |
| 2735 | convert_time_to_pixels( |
| 2736 | time_window, |
| 2737 | evtime, |
| 2738 | width, |
| 2739 | &x); |
| 2740 | |
| 2741 | /* Draw collision indicator */ |
| 2742 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 2743 | gdk_draw_point(hashed_process_data->pixmap, |
| 2744 | drawing->gc, |
| 2745 | x, |
| 2746 | (hashed_process_data->height/2)-3); |
| 2747 | hashed_process_data->x.middle_marked = TRUE; |
| 2748 | } |
| 2749 | } else { |
| 2750 | TimeWindow time_window = |
| 2751 | lttvwindow_get_time_window(control_flow_data->tab); |
| 2752 | |
| 2753 | #ifdef EXTRA_CHECK |
| 2754 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 2755 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 2756 | return; |
| 2757 | #endif //EXTRA_CHECK |
| 2758 | Drawing_t *drawing = control_flow_data->drawing; |
| 2759 | guint width = drawing->width; |
| 2760 | guint x; |
| 2761 | |
| 2762 | convert_time_to_pixels( |
| 2763 | time_window, |
| 2764 | evtime, |
| 2765 | width, |
| 2766 | &x); |
| 2767 | |
| 2768 | |
| 2769 | /* Jump over draw if we are at the same x position */ |
| 2770 | if(unlikely(x == hashed_process_data->x.middle && |
| 2771 | hashed_process_data->x.middle_used)) |
| 2772 | { |
| 2773 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
| 2774 | /* Draw collision indicator */ |
| 2775 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 2776 | gdk_draw_point(hashed_process_data->pixmap, |
| 2777 | drawing->gc, |
| 2778 | x, |
| 2779 | (hashed_process_data->height/2)-3); |
| 2780 | hashed_process_data->x.middle_marked = TRUE; |
| 2781 | } |
| 2782 | /* jump */ |
| 2783 | } else { |
| 2784 | DrawContext draw_context; |
| 2785 | |
| 2786 | /* Now create the drawing context that will be used to draw |
| 2787 | * items related to the last state. */ |
| 2788 | draw_context.drawable = hashed_process_data->pixmap; |
| 2789 | draw_context.gc = drawing->gc; |
| 2790 | draw_context.pango_layout = drawing->pango_layout; |
| 2791 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
| 2792 | draw_context.drawinfo.end.x = x; |
| 2793 | |
| 2794 | draw_context.drawinfo.y.over = 1; |
| 2795 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
| 2796 | draw_context.drawinfo.y.under = hashed_process_data->height; |
| 2797 | |
| 2798 | draw_context.drawinfo.start.offset.over = 0; |
| 2799 | draw_context.drawinfo.start.offset.middle = 0; |
| 2800 | draw_context.drawinfo.start.offset.under = 0; |
| 2801 | draw_context.drawinfo.end.offset.over = 0; |
| 2802 | draw_context.drawinfo.end.offset.middle = 0; |
| 2803 | draw_context.drawinfo.end.offset.under = 0; |
| 2804 | |
| 2805 | { |
| 2806 | /* Draw the line */ |
| 2807 | PropertiesLine prop_line = prepare_s_e_line(process); |
| 2808 | draw_line((void*)&prop_line, (void*)&draw_context); |
| 2809 | |
| 2810 | } |
| 2811 | /* become the last x position */ |
| 2812 | hashed_process_data->x.middle = x; |
| 2813 | hashed_process_data->x.middle_used = TRUE; |
| 2814 | hashed_process_data->x.middle_marked = FALSE; |
| 2815 | |
| 2816 | /* Calculate the next good time */ |
| 2817 | convert_pixels_to_time(width, x+1, time_window, |
| 2818 | &hashed_process_data->next_good_time); |
| 2819 | } |
| 2820 | } |
| 2821 | |
| 2822 | } else if(sub_id == 7) /* release */ { |
| 2823 | |
| 2824 | guint pid; |
| 2825 | { |
| 2826 | LttField *f = ltt_event_field(e); |
| 2827 | LttField *element; |
| 2828 | element = ltt_field_member(f,1); |
| 2829 | pid = ltt_event_get_long_unsigned(e,element); |
| 2830 | } |
| 2831 | |
| 2832 | /* Add process to process list (if not present) */ |
| 2833 | /* Don't care about the process if it's not in the state hash already : |
| 2834 | * that means a process that has never done anything in the trace and |
| 2835 | * unknown suddently gets destroyed : no state meaningful to show. */ |
| 2836 | LttvProcessState *process = lttv_state_find_process(tfs, pid); |
| 2837 | |
| 2838 | if(process != NULL) { |
| 2839 | LttTime birth; |
| 2840 | guint pl_height = 0; |
| 2841 | HashedProcessData *hashed_process_data = NULL; |
| 2842 | |
| 2843 | ProcessList *process_list = control_flow_data->process_list; |
| 2844 | |
| 2845 | birth = process->creation_time; |
| 2846 | |
| 2847 | /* Cannot use current process : this event happens on another process, |
| 2848 | * action done by the parent. */ |
| 2849 | hashed_process_data = processlist_get_process_data(process_list, |
| 2850 | pid, |
| 2851 | process->last_cpu_index, |
| 2852 | &birth, |
| 2853 | tfc->t_context->index); |
| 2854 | if(unlikely(hashed_process_data == NULL)) |
| 2855 | { |
| 2856 | g_assert(pid == 0 || pid != process->ppid); |
| 2857 | /* Process not present */ |
| 2858 | Drawing_t *drawing = control_flow_data->drawing; |
| 2859 | const gchar *name = g_quark_to_string(process->name); |
| 2860 | ProcessInfo *process_info; |
| 2861 | processlist_add(process_list, |
| 2862 | drawing, |
| 2863 | pid, |
| 2864 | process->last_cpu_index, |
| 2865 | process->ppid, |
| 2866 | &birth, |
| 2867 | tfc->t_context->index, |
| 2868 | name, |
| 2869 | &pl_height, |
| 2870 | &process_info, |
| 2871 | &hashed_process_data); |
| 2872 | gtk_widget_set_size_request(drawing->drawing_area, |
| 2873 | -1, |
| 2874 | pl_height); |
| 2875 | gtk_widget_queue_draw(drawing->drawing_area); |
| 2876 | } |
| 2877 | |
| 2878 | /* Now, the process is in the state hash and our own process hash. |
| 2879 | * We definitely can draw the items related to the ending state. |
| 2880 | */ |
| 2881 | |
| 2882 | if(likely(ltt_time_compare(hashed_process_data->next_good_time, |
| 2883 | evtime) > 0)) |
| 2884 | { |
| 2885 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
| 2886 | TimeWindow time_window = |
| 2887 | lttvwindow_get_time_window(control_flow_data->tab); |
| 2888 | |
| 2889 | #ifdef EXTRA_CHECK |
| 2890 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 2891 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 2892 | return; |
| 2893 | #endif //EXTRA_CHECK |
| 2894 | Drawing_t *drawing = control_flow_data->drawing; |
| 2895 | guint width = drawing->width; |
| 2896 | guint x; |
| 2897 | convert_time_to_pixels( |
| 2898 | time_window, |
| 2899 | evtime, |
| 2900 | width, |
| 2901 | &x); |
| 2902 | |
| 2903 | /* Draw collision indicator */ |
| 2904 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 2905 | gdk_draw_point(hashed_process_data->pixmap, |
| 2906 | drawing->gc, |
| 2907 | x, |
| 2908 | (hashed_process_data->height/2)-3); |
| 2909 | hashed_process_data->x.middle_marked = TRUE; |
| 2910 | } |
| 2911 | } else { |
| 2912 | TimeWindow time_window = |
| 2913 | lttvwindow_get_time_window(control_flow_data->tab); |
| 2914 | |
| 2915 | #ifdef EXTRA_CHECK |
| 2916 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 2917 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 2918 | return; |
| 2919 | #endif //EXTRA_CHECK |
| 2920 | Drawing_t *drawing = control_flow_data->drawing; |
| 2921 | guint width = drawing->width; |
| 2922 | guint x; |
| 2923 | |
| 2924 | convert_time_to_pixels( |
| 2925 | time_window, |
| 2926 | evtime, |
| 2927 | width, |
| 2928 | &x); |
| 2929 | |
| 2930 | |
| 2931 | /* Jump over draw if we are at the same x position */ |
| 2932 | if(unlikely(x == hashed_process_data->x.middle && |
| 2933 | hashed_process_data->x.middle_used)) |
| 2934 | { |
| 2935 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
| 2936 | /* Draw collision indicator */ |
| 2937 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 2938 | gdk_draw_point(hashed_process_data->pixmap, |
| 2939 | drawing->gc, |
| 2940 | x, |
| 2941 | (hashed_process_data->height/2)-3); |
| 2942 | hashed_process_data->x.middle_marked = TRUE; |
| 2943 | } |
| 2944 | /* jump */ |
| 2945 | } else { |
| 2946 | DrawContext draw_context; |
| 2947 | |
| 2948 | /* Now create the drawing context that will be used to draw |
| 2949 | * items related to the last state. */ |
| 2950 | draw_context.drawable = hashed_process_data->pixmap; |
| 2951 | draw_context.gc = drawing->gc; |
| 2952 | draw_context.pango_layout = drawing->pango_layout; |
| 2953 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
| 2954 | draw_context.drawinfo.end.x = x; |
| 2955 | |
| 2956 | draw_context.drawinfo.y.over = 1; |
| 2957 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
| 2958 | draw_context.drawinfo.y.under = hashed_process_data->height; |
| 2959 | |
| 2960 | draw_context.drawinfo.start.offset.over = 0; |
| 2961 | draw_context.drawinfo.start.offset.middle = 0; |
| 2962 | draw_context.drawinfo.start.offset.under = 0; |
| 2963 | draw_context.drawinfo.end.offset.over = 0; |
| 2964 | draw_context.drawinfo.end.offset.middle = 0; |
| 2965 | draw_context.drawinfo.end.offset.under = 0; |
| 2966 | |
| 2967 | { |
| 2968 | /* Draw the line */ |
| 2969 | PropertiesLine prop_line = prepare_s_e_line(process); |
| 2970 | draw_line((void*)&prop_line, (void*)&draw_context); |
| 2971 | |
| 2972 | } |
| 2973 | /* become the last x position */ |
| 2974 | hashed_process_data->x.middle = x; |
| 2975 | hashed_process_data->x.middle_used = TRUE; |
| 2976 | hashed_process_data->x.middle_marked = FALSE; |
| 2977 | |
| 2978 | /* Calculate the next good time */ |
| 2979 | convert_pixels_to_time(width, x+1, time_window, |
| 2980 | &hashed_process_data->next_good_time); |
| 2981 | } |
| 2982 | } |
| 2983 | } |
| 2984 | |
| 2985 | } |
| 2986 | return 0; |
| 2987 | |
| 2988 | } |
| 2989 | |
| 2990 | #endif //0 |
| 2991 | |
| 2992 | |
| 2993 | |
| 2994 | /* after_process_fork_hook |
| 2995 | * |
| 2996 | * Create the processlist entry for the child process. Put the last |
| 2997 | * position in x at the current time value. |
| 2998 | * |
| 2999 | * @param hook_data ControlFlowData structure of the viewer. |
| 3000 | * @param call_data Event context. |
| 3001 | * |
| 3002 | * This function adds items to be drawn in a queue for each process. |
| 3003 | * |
| 3004 | */ |
| 3005 | int after_process_fork_hook(void *hook_data, void *call_data) |
| 3006 | { |
| 3007 | return 0; //DISABLED |
| 3008 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 3009 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 3010 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 3011 | |
| 3012 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 3013 | |
| 3014 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 3015 | |
| 3016 | LttEvent *e; |
| 3017 | e = ltt_tracefile_get_event(tfc->tf); |
| 3018 | |
| 3019 | LttTime evtime = ltt_event_time(e); |
| 3020 | |
| 3021 | guint child_pid; |
| 3022 | { |
| 3023 | child_pid = ltt_event_get_long_unsigned(e, thf->f2); |
| 3024 | } |
| 3025 | |
| 3026 | /* Add process to process list (if not present) */ |
| 3027 | LttvProcessState *process_child; |
| 3028 | LttTime birth; |
| 3029 | guint pl_height = 0; |
| 3030 | HashedProcessData *hashed_process_data_child = NULL; |
| 3031 | |
| 3032 | ProcessList *process_list = control_flow_data->process_list; |
| 3033 | |
| 3034 | /* Find child in the list... */ |
| 3035 | process_child = lttv_state_find_process(tfs, child_pid); |
| 3036 | /* It should exist, because we are after the state update. */ |
| 3037 | g_assert(process_child != NULL); |
| 3038 | |
| 3039 | birth = process_child->creation_time; |
| 3040 | |
| 3041 | /* Cannot use current process, because this action is done by the parent |
| 3042 | * on its child. */ |
| 3043 | hashed_process_data_child = processlist_get_process_data(process_list, |
| 3044 | child_pid, |
| 3045 | process_child->last_cpu_index, |
| 3046 | &birth, |
| 3047 | tfc->t_context->index); |
| 3048 | if(likely(hashed_process_data_child == NULL)) |
| 3049 | { |
| 3050 | g_assert(child_pid == 0 || child_pid != process_child->ppid); |
| 3051 | /* Process not present */ |
| 3052 | Drawing_t *drawing = control_flow_data->drawing; |
| 3053 | const gchar *name = g_quark_to_string(process_child->name); |
| 3054 | ProcessInfo *process_info; |
| 3055 | processlist_add(process_list, |
| 3056 | drawing, |
| 3057 | child_pid, |
| 3058 | process_child->last_cpu_index, |
| 3059 | process_child->ppid, |
| 3060 | &birth, |
| 3061 | tfc->t_context->index, |
| 3062 | name, |
| 3063 | &pl_height, |
| 3064 | &process_info, |
| 3065 | &hashed_process_data_child); |
| 3066 | gtk_widget_set_size_request(drawing->drawing_area, |
| 3067 | -1, |
| 3068 | pl_height); |
| 3069 | gtk_widget_queue_draw(drawing->drawing_area); |
| 3070 | } |
| 3071 | |
| 3072 | |
| 3073 | if(likely(ltt_time_compare(hashed_process_data_child->next_good_time, |
| 3074 | evtime) <= 0)) |
| 3075 | { |
| 3076 | TimeWindow time_window = |
| 3077 | lttvwindow_get_time_window(control_flow_data->tab); |
| 3078 | |
| 3079 | #ifdef EXTRA_CHECK |
| 3080 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 3081 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 3082 | return; |
| 3083 | #endif //EXTRA_CHECK |
| 3084 | Drawing_t *drawing = control_flow_data->drawing; |
| 3085 | guint width = drawing->width; |
| 3086 | guint new_x; |
| 3087 | convert_time_to_pixels( |
| 3088 | time_window, |
| 3089 | evtime, |
| 3090 | width, |
| 3091 | &new_x); |
| 3092 | |
| 3093 | if(likely(hashed_process_data_child->x.over != new_x)) { |
| 3094 | hashed_process_data_child->x.over = new_x; |
| 3095 | hashed_process_data_child->x.over_used = FALSE; |
| 3096 | hashed_process_data_child->x.over_marked = FALSE; |
| 3097 | } |
| 3098 | if(likely(hashed_process_data_child->x.middle != new_x)) { |
| 3099 | hashed_process_data_child->x.middle = new_x; |
| 3100 | hashed_process_data_child->x.middle_used = FALSE; |
| 3101 | hashed_process_data_child->x.middle_marked = FALSE; |
| 3102 | } |
| 3103 | if(likely(hashed_process_data_child->x.under != new_x)) { |
| 3104 | hashed_process_data_child->x.under = new_x; |
| 3105 | hashed_process_data_child->x.under_used = FALSE; |
| 3106 | hashed_process_data_child->x.under_marked = FALSE; |
| 3107 | } |
| 3108 | } |
| 3109 | return 0; |
| 3110 | } |
| 3111 | |
| 3112 | |
| 3113 | |
| 3114 | /* after_process_exit_hook |
| 3115 | * |
| 3116 | * Create the processlist entry for the child process. Put the last |
| 3117 | * position in x at the current time value. |
| 3118 | * |
| 3119 | * @param hook_data ControlFlowData structure of the viewer. |
| 3120 | * @param call_data Event context. |
| 3121 | * |
| 3122 | * This function adds items to be drawn in a queue for each process. |
| 3123 | * |
| 3124 | */ |
| 3125 | int after_process_exit_hook(void *hook_data, void *call_data) |
| 3126 | { |
| 3127 | return 0; //DISABLED |
| 3128 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 3129 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 3130 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 3131 | |
| 3132 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 3133 | |
| 3134 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 3135 | |
| 3136 | LttEvent *e; |
| 3137 | e = ltt_tracefile_get_event(tfc->tf); |
| 3138 | |
| 3139 | LttTime evtime = ltt_event_time(e); |
| 3140 | |
| 3141 | /* Add process to process list (if not present) */ |
| 3142 | LttvProcessState *process = tfs->process; |
| 3143 | guint pid = process->pid; |
| 3144 | LttTime birth; |
| 3145 | guint pl_height = 0; |
| 3146 | HashedProcessData *hashed_process_data = NULL; |
| 3147 | |
| 3148 | ProcessList *process_list = control_flow_data->process_list; |
| 3149 | |
| 3150 | /* It should exist, because we are after the state update. */ |
| 3151 | g_assert(process != NULL); |
| 3152 | |
| 3153 | birth = process->creation_time; |
| 3154 | |
| 3155 | if(likely(process_list->current_hash_data[ltt_tracefile_num(tfc->tf)] != NULL) ){ |
| 3156 | hashed_process_data = process_list->current_hash_data[ltt_tracefile_num(tfc->tf)]; |
| 3157 | } else { |
| 3158 | hashed_process_data = processlist_get_process_data(process_list, |
| 3159 | pid, |
| 3160 | process->last_cpu_index, |
| 3161 | &birth, |
| 3162 | tfc->t_context->index); |
| 3163 | if(unlikely(hashed_process_data == NULL)) |
| 3164 | { |
| 3165 | g_assert(pid == 0 || pid != process->ppid); |
| 3166 | /* Process not present */ |
| 3167 | Drawing_t *drawing = control_flow_data->drawing; |
| 3168 | const gchar *name = g_quark_to_string(process->name); |
| 3169 | ProcessInfo *process_info; |
| 3170 | processlist_add(process_list, |
| 3171 | drawing, |
| 3172 | pid, |
| 3173 | process->last_cpu_index, |
| 3174 | process->ppid, |
| 3175 | &birth, |
| 3176 | tfc->t_context->index, |
| 3177 | name, |
| 3178 | &pl_height, |
| 3179 | &process_info, |
| 3180 | &hashed_process_data); |
| 3181 | gtk_widget_set_size_request(drawing->drawing_area, |
| 3182 | -1, |
| 3183 | pl_height); |
| 3184 | gtk_widget_queue_draw(drawing->drawing_area); |
| 3185 | } |
| 3186 | |
| 3187 | /* Set the current process */ |
| 3188 | process_list->current_hash_data[process->last_cpu_index] = |
| 3189 | hashed_process_data; |
| 3190 | } |
| 3191 | |
| 3192 | if(unlikely(ltt_time_compare(hashed_process_data->next_good_time, |
| 3193 | evtime) <= 0)) |
| 3194 | { |
| 3195 | TimeWindow time_window = |
| 3196 | lttvwindow_get_time_window(control_flow_data->tab); |
| 3197 | |
| 3198 | #ifdef EXTRA_CHECK |
| 3199 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 3200 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 3201 | return; |
| 3202 | #endif //EXTRA_CHECK |
| 3203 | Drawing_t *drawing = control_flow_data->drawing; |
| 3204 | guint width = drawing->width; |
| 3205 | guint new_x; |
| 3206 | convert_time_to_pixels( |
| 3207 | time_window, |
| 3208 | evtime, |
| 3209 | width, |
| 3210 | &new_x); |
| 3211 | if(unlikely(hashed_process_data->x.middle != new_x)) { |
| 3212 | hashed_process_data->x.middle = new_x; |
| 3213 | hashed_process_data->x.middle_used = FALSE; |
| 3214 | hashed_process_data->x.middle_marked = FALSE; |
| 3215 | } |
| 3216 | } |
| 3217 | |
| 3218 | return 0; |
| 3219 | } |
| 3220 | |
| 3221 | |
| 3222 | #if 0 |
| 3223 | |
| 3224 | /* after_process_hook |
| 3225 | * |
| 3226 | * Create the processlist entry for the child process. Put the last |
| 3227 | * position in x at the current time value. |
| 3228 | * |
| 3229 | * @param hook_data ControlFlowData structure of the viewer. |
| 3230 | * @param call_data Event context. |
| 3231 | * |
| 3232 | * This function adds items to be drawn in a queue for each process. |
| 3233 | * |
| 3234 | */ |
| 3235 | int after_process_hook(void *hook_data, void *call_data) |
| 3236 | { |
| 3237 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
| 3238 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
| 3239 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 3240 | |
| 3241 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 3242 | |
| 3243 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 3244 | |
| 3245 | LttEvent *e; |
| 3246 | e = ltt_tracefile_get_event(tfc->tf); |
| 3247 | |
| 3248 | LttTime evtime = ltt_event_time(e); |
| 3249 | |
| 3250 | guint sub_id; |
| 3251 | guint param1; |
| 3252 | { |
| 3253 | LttField *f = ltt_event_field(e); |
| 3254 | LttField *element; |
| 3255 | element = ltt_field_member(f,0); |
| 3256 | sub_id = ltt_event_get_long_unsigned(e,element); |
| 3257 | element = ltt_field_member(f,1); |
| 3258 | param1 = ltt_event_get_long_unsigned(e,element); |
| 3259 | } |
| 3260 | |
| 3261 | if(sub_id == 2) { /* fork */ |
| 3262 | |
| 3263 | guint child_pid = param1; |
| 3264 | /* Add process to process list (if not present) */ |
| 3265 | LttvProcessState *process_child; |
| 3266 | LttTime birth; |
| 3267 | guint pl_height = 0; |
| 3268 | HashedProcessData *hashed_process_data_child = NULL; |
| 3269 | |
| 3270 | ProcessList *process_list = control_flow_data->process_list; |
| 3271 | |
| 3272 | /* Find child in the list... */ |
| 3273 | process_child = lttv_state_find_process(tfs, child_pid); |
| 3274 | /* It should exist, because we are after the state update. */ |
| 3275 | g_assert(process_child != NULL); |
| 3276 | |
| 3277 | birth = process_child->creation_time; |
| 3278 | |
| 3279 | /* Cannot use current process, because this action is done by the parent |
| 3280 | * on its child. */ |
| 3281 | hashed_process_data_child = processlist_get_process_data(process_list, |
| 3282 | child_pid, |
| 3283 | process_child->last_cpu_index, |
| 3284 | &birth, |
| 3285 | tfc->t_context->index); |
| 3286 | if(likely(hashed_process_data_child == NULL)) |
| 3287 | { |
| 3288 | g_assert(child_pid == 0 || child_pid != process_child->ppid); |
| 3289 | /* Process not present */ |
| 3290 | Drawing_t *drawing = control_flow_data->drawing; |
| 3291 | const gchar *name = g_quark_to_string(process_child->name); |
| 3292 | ProcessInfo *process_info; |
| 3293 | processlist_add(process_list, |
| 3294 | drawing, |
| 3295 | child_pid, |
| 3296 | process_child->last_cpu_index, |
| 3297 | process_child->ppid, |
| 3298 | &birth, |
| 3299 | tfc->t_context->index, |
| 3300 | name, |
| 3301 | &pl_height, |
| 3302 | &process_info, |
| 3303 | &hashed_process_data_child); |
| 3304 | gtk_widget_set_size_request(drawing->drawing_area, |
| 3305 | -1, |
| 3306 | pl_height); |
| 3307 | gtk_widget_queue_draw(drawing->drawing_area); |
| 3308 | } |
| 3309 | |
| 3310 | |
| 3311 | if(likely(ltt_time_compare(hashed_process_data_child->next_good_time, |
| 3312 | evtime) <= 0)) |
| 3313 | { |
| 3314 | TimeWindow time_window = |
| 3315 | lttvwindow_get_time_window(control_flow_data->tab); |
| 3316 | |
| 3317 | #ifdef EXTRA_CHECK |
| 3318 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 3319 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 3320 | return; |
| 3321 | #endif //EXTRA_CHECK |
| 3322 | Drawing_t *drawing = control_flow_data->drawing; |
| 3323 | guint width = drawing->width; |
| 3324 | guint new_x; |
| 3325 | convert_time_to_pixels( |
| 3326 | time_window, |
| 3327 | evtime, |
| 3328 | width, |
| 3329 | &new_x); |
| 3330 | |
| 3331 | if(likely(hashed_process_data_child->x.over != new_x)) { |
| 3332 | hashed_process_data_child->x.over = new_x; |
| 3333 | hashed_process_data_child->x.over_used = FALSE; |
| 3334 | hashed_process_data_child->x.over_marked = FALSE; |
| 3335 | } |
| 3336 | if(likely(hashed_process_data_child->x.middle != new_x)) { |
| 3337 | hashed_process_data_child->x.middle = new_x; |
| 3338 | hashed_process_data_child->x.middle_used = FALSE; |
| 3339 | hashed_process_data_child->x.middle_marked = FALSE; |
| 3340 | } |
| 3341 | if(likely(hashed_process_data_child->x.under != new_x)) { |
| 3342 | hashed_process_data_child->x.under = new_x; |
| 3343 | hashed_process_data_child->x.under_used = FALSE; |
| 3344 | hashed_process_data_child->x.under_marked = FALSE; |
| 3345 | } |
| 3346 | } |
| 3347 | |
| 3348 | } else if(sub_id == 3) { /* exit */ |
| 3349 | |
| 3350 | /* Add process to process list (if not present) */ |
| 3351 | LttvProcessState *process = tfs->process; |
| 3352 | guint pid = process->pid; |
| 3353 | LttTime birth; |
| 3354 | guint pl_height = 0; |
| 3355 | HashedProcessData *hashed_process_data = NULL; |
| 3356 | |
| 3357 | ProcessList *process_list = control_flow_data->process_list; |
| 3358 | |
| 3359 | /* It should exist, because we are after the state update. */ |
| 3360 | g_assert(process != NULL); |
| 3361 | |
| 3362 | birth = process->creation_time; |
| 3363 | |
| 3364 | if(likely(process_list->current_hash_data[ltt_tracefile_num(tfc->tf)] != NULL) ){ |
| 3365 | hashed_process_data = process_list->current_hash_data[ltt_tracefile_num(tfc->tf)]; |
| 3366 | } else { |
| 3367 | hashed_process_data = processlist_get_process_data(process_list, |
| 3368 | pid, |
| 3369 | process->last_cpu_index, |
| 3370 | &birth, |
| 3371 | tfc->t_context->index); |
| 3372 | if(unlikely(hashed_process_data == NULL)) |
| 3373 | { |
| 3374 | g_assert(pid == 0 || pid != process->ppid); |
| 3375 | /* Process not present */ |
| 3376 | Drawing_t *drawing = control_flow_data->drawing; |
| 3377 | const gchar *name = g_quark_to_string(process->name); |
| 3378 | ProcessInfo *process_info; |
| 3379 | processlist_add(process_list, |
| 3380 | drawing, |
| 3381 | pid, |
| 3382 | process->last_cpu_index, |
| 3383 | process->ppid, |
| 3384 | &birth, |
| 3385 | tfc->t_context->index, |
| 3386 | name, |
| 3387 | &pl_height, |
| 3388 | &process_info, |
| 3389 | &hashed_process_data); |
| 3390 | gtk_widget_set_size_request(drawing->drawing_area, |
| 3391 | -1, |
| 3392 | pl_height); |
| 3393 | gtk_widget_queue_draw(drawing->drawing_area); |
| 3394 | } |
| 3395 | |
| 3396 | /* Set the current process */ |
| 3397 | process_list->current_hash_data[process->last_cpu_index] = |
| 3398 | hashed_process_data; |
| 3399 | } |
| 3400 | |
| 3401 | if(unlikely(ltt_time_compare(hashed_process_data->next_good_time, |
| 3402 | evtime) <= 0)) |
| 3403 | { |
| 3404 | TimeWindow time_window = |
| 3405 | lttvwindow_get_time_window(control_flow_data->tab); |
| 3406 | |
| 3407 | #ifdef EXTRA_CHECK |
| 3408 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 3409 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 3410 | return; |
| 3411 | #endif //EXTRA_CHECK |
| 3412 | Drawing_t *drawing = control_flow_data->drawing; |
| 3413 | guint width = drawing->width; |
| 3414 | guint new_x; |
| 3415 | convert_time_to_pixels( |
| 3416 | time_window, |
| 3417 | evtime, |
| 3418 | width, |
| 3419 | &new_x); |
| 3420 | if(unlikely(hashed_process_data->x.middle != new_x)) { |
| 3421 | hashed_process_data->x.middle = new_x; |
| 3422 | hashed_process_data->x.middle_used = FALSE; |
| 3423 | hashed_process_data->x.middle_marked = FALSE; |
| 3424 | } |
| 3425 | } |
| 3426 | |
| 3427 | } |
| 3428 | return 0; |
| 3429 | |
| 3430 | } |
| 3431 | #endif //0 |
| 3432 | |
| 3433 | gint update_time_window_hook(void *hook_data, void *call_data) |
| 3434 | { |
| 3435 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
| 3436 | Drawing_t *drawing = control_flow_data->drawing; |
| 3437 | ProcessList *process_list = control_flow_data->process_list; |
| 3438 | |
| 3439 | const TimeWindowNotifyData *time_window_nofify_data = |
| 3440 | ((const TimeWindowNotifyData *)call_data); |
| 3441 | |
| 3442 | TimeWindow *old_time_window = |
| 3443 | time_window_nofify_data->old_time_window; |
| 3444 | TimeWindow *new_time_window = |
| 3445 | time_window_nofify_data->new_time_window; |
| 3446 | |
| 3447 | /* Update the ruler */ |
| 3448 | drawing_update_ruler(control_flow_data->drawing, |
| 3449 | new_time_window); |
| 3450 | |
| 3451 | |
| 3452 | /* Two cases : zoom in/out or scrolling */ |
| 3453 | |
| 3454 | /* In order to make sure we can reuse the old drawing, the scale must |
| 3455 | * be the same and the new time interval being partly located in the |
| 3456 | * currently shown time interval. (reuse is only for scrolling) |
| 3457 | */ |
| 3458 | |
| 3459 | g_info("Old time window HOOK : %lu, %lu to %lu, %lu", |
| 3460 | old_time_window->start_time.tv_sec, |
| 3461 | old_time_window->start_time.tv_nsec, |
| 3462 | old_time_window->time_width.tv_sec, |
| 3463 | old_time_window->time_width.tv_nsec); |
| 3464 | |
| 3465 | g_info("New time window HOOK : %lu, %lu to %lu, %lu", |
| 3466 | new_time_window->start_time.tv_sec, |
| 3467 | new_time_window->start_time.tv_nsec, |
| 3468 | new_time_window->time_width.tv_sec, |
| 3469 | new_time_window->time_width.tv_nsec); |
| 3470 | |
| 3471 | if( new_time_window->time_width.tv_sec == old_time_window->time_width.tv_sec |
| 3472 | && new_time_window->time_width.tv_nsec == old_time_window->time_width.tv_nsec) |
| 3473 | { |
| 3474 | /* Same scale (scrolling) */ |
| 3475 | g_info("scrolling"); |
| 3476 | LttTime *ns = &new_time_window->start_time; |
| 3477 | LttTime *nw = &new_time_window->time_width; |
| 3478 | LttTime *os = &old_time_window->start_time; |
| 3479 | LttTime *ow = &old_time_window->time_width; |
| 3480 | LttTime old_end = old_time_window->end_time; |
| 3481 | LttTime new_end = new_time_window->end_time; |
| 3482 | //if(ns<os+w<ns+w) |
| 3483 | //if(ns<os+w && os+w<ns+w) |
| 3484 | //if(ns<old_end && os<ns) |
| 3485 | if(ltt_time_compare(*ns, old_end) == -1 |
| 3486 | && ltt_time_compare(*os, *ns) == -1) |
| 3487 | { |
| 3488 | g_info("scrolling near right"); |
| 3489 | /* Scroll right, keep right part of the screen */ |
| 3490 | guint x = 0; |
| 3491 | guint width = control_flow_data->drawing->width; |
| 3492 | convert_time_to_pixels( |
| 3493 | *old_time_window, |
| 3494 | *ns, |
| 3495 | width, |
| 3496 | &x); |
| 3497 | |
| 3498 | /* Copy old data to new location */ |
| 3499 | copy_pixmap_region(process_list, |
| 3500 | NULL, |
| 3501 | control_flow_data->drawing->drawing_area->style->black_gc, |
| 3502 | NULL, |
| 3503 | x, 0, |
| 3504 | 0, 0, |
| 3505 | control_flow_data->drawing->width-x+SAFETY, -1); |
| 3506 | |
| 3507 | if(drawing->damage_begin == drawing->damage_end) |
| 3508 | drawing->damage_begin = control_flow_data->drawing->width-x; |
| 3509 | else |
| 3510 | drawing->damage_begin = 0; |
| 3511 | |
| 3512 | drawing->damage_end = control_flow_data->drawing->width; |
| 3513 | |
| 3514 | /* Clear the data request background, but not SAFETY */ |
| 3515 | rectangle_pixmap(process_list, |
| 3516 | control_flow_data->drawing->drawing_area->style->black_gc, |
| 3517 | TRUE, |
| 3518 | drawing->damage_begin+SAFETY, 0, |
| 3519 | drawing->damage_end - drawing->damage_begin, // do not overlap |
| 3520 | -1); |
| 3521 | gtk_widget_queue_draw(drawing->drawing_area); |
| 3522 | //gtk_widget_queue_draw_area (drawing->drawing_area, |
| 3523 | // 0,0, |
| 3524 | // control_flow_data->drawing->width, |
| 3525 | // control_flow_data->drawing->height); |
| 3526 | |
| 3527 | /* Get new data for the rest. */ |
| 3528 | drawing_data_request(control_flow_data->drawing, |
| 3529 | drawing->damage_begin, 0, |
| 3530 | drawing->damage_end - drawing->damage_begin, |
| 3531 | control_flow_data->drawing->height); |
| 3532 | } else { |
| 3533 | //if(ns<os<ns+w) |
| 3534 | //if(ns<os && os<ns+w) |
| 3535 | //if(ns<os && os<new_end) |
| 3536 | if(ltt_time_compare(*ns,*os) == -1 |
| 3537 | && ltt_time_compare(*os,new_end) == -1) |
| 3538 | { |
| 3539 | g_info("scrolling near left"); |
| 3540 | /* Scroll left, keep left part of the screen */ |
| 3541 | guint x = 0; |
| 3542 | guint width = control_flow_data->drawing->width; |
| 3543 | convert_time_to_pixels( |
| 3544 | *new_time_window, |
| 3545 | *os, |
| 3546 | width, |
| 3547 | &x); |
| 3548 | |
| 3549 | /* Copy old data to new location */ |
| 3550 | copy_pixmap_region (process_list, |
| 3551 | NULL, |
| 3552 | control_flow_data->drawing->drawing_area->style->black_gc, |
| 3553 | NULL, |
| 3554 | 0, 0, |
| 3555 | x, 0, |
| 3556 | -1, -1); |
| 3557 | |
| 3558 | if(drawing->damage_begin == drawing->damage_end) |
| 3559 | drawing->damage_end = x; |
| 3560 | else |
| 3561 | drawing->damage_end = |
| 3562 | control_flow_data->drawing->width; |
| 3563 | |
| 3564 | drawing->damage_begin = 0; |
| 3565 | |
| 3566 | rectangle_pixmap (process_list, |
| 3567 | control_flow_data->drawing->drawing_area->style->black_gc, |
| 3568 | TRUE, |
| 3569 | drawing->damage_begin, 0, |
| 3570 | drawing->damage_end - drawing->damage_begin, // do not overlap |
| 3571 | -1); |
| 3572 | |
| 3573 | gtk_widget_queue_draw(drawing->drawing_area); |
| 3574 | //gtk_widget_queue_draw_area (drawing->drawing_area, |
| 3575 | // 0,0, |
| 3576 | // control_flow_data->drawing->width, |
| 3577 | // control_flow_data->drawing->height); |
| 3578 | |
| 3579 | |
| 3580 | /* Get new data for the rest. */ |
| 3581 | drawing_data_request(control_flow_data->drawing, |
| 3582 | drawing->damage_begin, 0, |
| 3583 | drawing->damage_end - drawing->damage_begin, |
| 3584 | control_flow_data->drawing->height); |
| 3585 | |
| 3586 | } else { |
| 3587 | if(ltt_time_compare(*ns,*os) == 0) |
| 3588 | { |
| 3589 | g_info("not scrolling"); |
| 3590 | } else { |
| 3591 | g_info("scrolling far"); |
| 3592 | /* Cannot reuse any part of the screen : far jump */ |
| 3593 | |
| 3594 | |
| 3595 | rectangle_pixmap (process_list, |
| 3596 | control_flow_data->drawing->drawing_area->style->black_gc, |
| 3597 | TRUE, |
| 3598 | 0, 0, |
| 3599 | control_flow_data->drawing->width+SAFETY, // do not overlap |
| 3600 | -1); |
| 3601 | |
| 3602 | //gtk_widget_queue_draw_area (drawing->drawing_area, |
| 3603 | // 0,0, |
| 3604 | // control_flow_data->drawing->width, |
| 3605 | // control_flow_data->drawing->height); |
| 3606 | gtk_widget_queue_draw(drawing->drawing_area); |
| 3607 | |
| 3608 | drawing->damage_begin = 0; |
| 3609 | drawing->damage_end = control_flow_data->drawing->width; |
| 3610 | |
| 3611 | drawing_data_request(control_flow_data->drawing, |
| 3612 | 0, 0, |
| 3613 | control_flow_data->drawing->width, |
| 3614 | control_flow_data->drawing->height); |
| 3615 | |
| 3616 | } |
| 3617 | } |
| 3618 | } |
| 3619 | } else { |
| 3620 | /* Different scale (zoom) */ |
| 3621 | g_info("zoom"); |
| 3622 | |
| 3623 | rectangle_pixmap (process_list, |
| 3624 | control_flow_data->drawing->drawing_area->style->black_gc, |
| 3625 | TRUE, |
| 3626 | 0, 0, |
| 3627 | control_flow_data->drawing->width+SAFETY, // do not overlap |
| 3628 | -1); |
| 3629 | |
| 3630 | //gtk_widget_queue_draw_area (drawing->drawing_area, |
| 3631 | // 0,0, |
| 3632 | // control_flow_data->drawing->width, |
| 3633 | // control_flow_data->drawing->height); |
| 3634 | gtk_widget_queue_draw(drawing->drawing_area); |
| 3635 | |
| 3636 | drawing->damage_begin = 0; |
| 3637 | drawing->damage_end = control_flow_data->drawing->width; |
| 3638 | |
| 3639 | drawing_data_request(control_flow_data->drawing, |
| 3640 | 0, 0, |
| 3641 | control_flow_data->drawing->width, |
| 3642 | control_flow_data->drawing->height); |
| 3643 | } |
| 3644 | |
| 3645 | |
| 3646 | |
| 3647 | return 0; |
| 3648 | } |
| 3649 | |
| 3650 | gint traceset_notify(void *hook_data, void *call_data) |
| 3651 | { |
| 3652 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
| 3653 | Drawing_t *drawing = control_flow_data->drawing; |
| 3654 | |
| 3655 | |
| 3656 | drawing_clear(control_flow_data->drawing); |
| 3657 | processlist_clear(control_flow_data->process_list); |
| 3658 | gtk_widget_set_size_request( |
| 3659 | control_flow_data->drawing->drawing_area, |
| 3660 | -1, processlist_get_height(control_flow_data->process_list)); |
| 3661 | redraw_notify(control_flow_data, NULL); |
| 3662 | |
| 3663 | request_background_data(control_flow_data); |
| 3664 | |
| 3665 | return FALSE; |
| 3666 | } |
| 3667 | |
| 3668 | gint redraw_notify(void *hook_data, void *call_data) |
| 3669 | { |
| 3670 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
| 3671 | Drawing_t *drawing = control_flow_data->drawing; |
| 3672 | GtkWidget *widget = drawing->drawing_area; |
| 3673 | |
| 3674 | drawing->damage_begin = 0; |
| 3675 | drawing->damage_end = drawing->width; |
| 3676 | |
| 3677 | /* fun feature, to be separated someday... */ |
| 3678 | drawing_clear(control_flow_data->drawing); |
| 3679 | processlist_clear(control_flow_data->process_list); |
| 3680 | gtk_widget_set_size_request( |
| 3681 | control_flow_data->drawing->drawing_area, |
| 3682 | -1, processlist_get_height(control_flow_data->process_list)); |
| 3683 | // Clear the images |
| 3684 | rectangle_pixmap (control_flow_data->process_list, |
| 3685 | widget->style->black_gc, |
| 3686 | TRUE, |
| 3687 | 0, 0, |
| 3688 | drawing->alloc_width, |
| 3689 | -1); |
| 3690 | |
| 3691 | gtk_widget_queue_draw(drawing->drawing_area); |
| 3692 | |
| 3693 | if(drawing->damage_begin < drawing->damage_end) |
| 3694 | { |
| 3695 | drawing_data_request(drawing, |
| 3696 | drawing->damage_begin, |
| 3697 | 0, |
| 3698 | drawing->damage_end-drawing->damage_begin, |
| 3699 | drawing->height); |
| 3700 | } |
| 3701 | |
| 3702 | //gtk_widget_queue_draw_area(drawing->drawing_area, |
| 3703 | // 0,0, |
| 3704 | // drawing->width, |
| 3705 | // drawing->height); |
| 3706 | return FALSE; |
| 3707 | |
| 3708 | } |
| 3709 | |
| 3710 | |
| 3711 | gint continue_notify(void *hook_data, void *call_data) |
| 3712 | { |
| 3713 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
| 3714 | Drawing_t *drawing = control_flow_data->drawing; |
| 3715 | |
| 3716 | //g_assert(widget->allocation.width == drawing->damage_end); |
| 3717 | |
| 3718 | if(drawing->damage_begin < drawing->damage_end) |
| 3719 | { |
| 3720 | drawing_data_request(drawing, |
| 3721 | drawing->damage_begin, |
| 3722 | 0, |
| 3723 | drawing->damage_end-drawing->damage_begin, |
| 3724 | drawing->height); |
| 3725 | } |
| 3726 | |
| 3727 | return FALSE; |
| 3728 | } |
| 3729 | |
| 3730 | |
| 3731 | gint update_current_time_hook(void *hook_data, void *call_data) |
| 3732 | { |
| 3733 | ControlFlowData *control_flow_data = (ControlFlowData*)hook_data; |
| 3734 | Drawing_t *drawing = control_flow_data->drawing; |
| 3735 | |
| 3736 | LttTime current_time = *((LttTime*)call_data); |
| 3737 | |
| 3738 | TimeWindow time_window = |
| 3739 | lttvwindow_get_time_window(control_flow_data->tab); |
| 3740 | |
| 3741 | LttTime time_begin = time_window.start_time; |
| 3742 | LttTime width = time_window.time_width; |
| 3743 | LttTime half_width; |
| 3744 | { |
| 3745 | guint64 time_ll = ltt_time_to_uint64(width); |
| 3746 | time_ll = time_ll >> 1; /* divide by two */ |
| 3747 | half_width = ltt_time_from_uint64(time_ll); |
| 3748 | } |
| 3749 | LttTime time_end = ltt_time_add(time_begin, width); |
| 3750 | |
| 3751 | LttvTracesetContext * tsc = |
| 3752 | lttvwindow_get_traceset_context(control_flow_data->tab); |
| 3753 | |
| 3754 | LttTime trace_start = tsc->time_span.start_time; |
| 3755 | LttTime trace_end = tsc->time_span.end_time; |
| 3756 | |
| 3757 | g_info("New current time HOOK : %lu, %lu", current_time.tv_sec, |
| 3758 | current_time.tv_nsec); |
| 3759 | |
| 3760 | |
| 3761 | |
| 3762 | /* If current time is inside time interval, just move the highlight |
| 3763 | * bar */ |
| 3764 | |
| 3765 | /* Else, we have to change the time interval. We have to tell it |
| 3766 | * to the main window. */ |
| 3767 | /* The time interval change will take care of placing the current |
| 3768 | * time at the center of the visible area, or nearest possible if we are |
| 3769 | * at one end of the trace. */ |
| 3770 | |
| 3771 | |
| 3772 | if(ltt_time_compare(current_time, time_begin) < 0) |
| 3773 | { |
| 3774 | TimeWindow new_time_window; |
| 3775 | |
| 3776 | if(ltt_time_compare(current_time, |
| 3777 | ltt_time_add(trace_start,half_width)) < 0) |
| 3778 | time_begin = trace_start; |
| 3779 | else |
| 3780 | time_begin = ltt_time_sub(current_time,half_width); |
| 3781 | |
| 3782 | new_time_window.start_time = time_begin; |
| 3783 | new_time_window.time_width = width; |
| 3784 | new_time_window.time_width_double = ltt_time_to_double(width); |
| 3785 | new_time_window.end_time = ltt_time_add(time_begin, width); |
| 3786 | |
| 3787 | lttvwindow_report_time_window(control_flow_data->tab, new_time_window); |
| 3788 | } |
| 3789 | else if(ltt_time_compare(current_time, time_end) > 0) |
| 3790 | { |
| 3791 | TimeWindow new_time_window; |
| 3792 | |
| 3793 | if(ltt_time_compare(current_time, ltt_time_sub(trace_end, half_width)) > 0) |
| 3794 | time_begin = ltt_time_sub(trace_end,width); |
| 3795 | else |
| 3796 | time_begin = ltt_time_sub(current_time,half_width); |
| 3797 | |
| 3798 | new_time_window.start_time = time_begin; |
| 3799 | new_time_window.time_width = width; |
| 3800 | new_time_window.time_width_double = ltt_time_to_double(width); |
| 3801 | new_time_window.end_time = ltt_time_add(time_begin, width); |
| 3802 | |
| 3803 | lttvwindow_report_time_window(control_flow_data->tab, new_time_window); |
| 3804 | |
| 3805 | } |
| 3806 | gtk_widget_queue_draw(control_flow_data->drawing->drawing_area); |
| 3807 | |
| 3808 | |
| 3809 | return 0; |
| 3810 | } |
| 3811 | |
| 3812 | typedef struct _ClosureData { |
| 3813 | EventsRequest *events_request; |
| 3814 | LttvTracesetState *tss; |
| 3815 | LttTime end_time; |
| 3816 | guint x_end; |
| 3817 | } ClosureData; |
| 3818 | |
| 3819 | |
| 3820 | void draw_closure(gpointer key, gpointer value, gpointer user_data) |
| 3821 | { |
| 3822 | ProcessInfo *process_info = (ProcessInfo*)key; |
| 3823 | HashedProcessData *hashed_process_data = (HashedProcessData*)value; |
| 3824 | ClosureData *closure_data = (ClosureData*)user_data; |
| 3825 | |
| 3826 | EventsRequest *events_request = closure_data->events_request; |
| 3827 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 3828 | |
| 3829 | LttvTracesetState *tss = closure_data->tss; |
| 3830 | LttvTracesetContext *tsc = (LttvTracesetContext*)tss; |
| 3831 | |
| 3832 | LttTime evtime = closure_data->end_time; |
| 3833 | |
| 3834 | { |
| 3835 | /* For the process */ |
| 3836 | /* First, check if the current process is in the state computation |
| 3837 | * process list. If it is there, that means we must add it right now and |
| 3838 | * draw items from the beginning of the read for it. If it is not |
| 3839 | * present, it's a new process and it was not present : it will |
| 3840 | * be added after the state update. */ |
| 3841 | #ifdef EXTRA_CHECK |
| 3842 | g_assert(lttv_traceset_number(tsc->ts) > 0); |
| 3843 | #endif //EXTRA_CHECK |
| 3844 | LttvTraceContext *tc = tsc->traces[process_info->trace_num]; |
| 3845 | |
| 3846 | //FIXME : optimize data structures. |
| 3847 | LttvTracefileState *tfs; |
| 3848 | LttvTracefileContext *tfc; |
| 3849 | guint i; |
| 3850 | for(i=0;i<tc->tracefiles->len;i++) { |
| 3851 | tfc = g_array_index(tc->tracefiles, LttvTracefileContext*, i); |
| 3852 | if(ltt_tracefile_name(tfc->tf) == LTT_NAME_CPU |
| 3853 | && ltt_tracefile_num(tfc->tf) == process_info->cpu) |
| 3854 | break; |
| 3855 | |
| 3856 | } |
| 3857 | g_assert(i<tc->tracefiles->len); |
| 3858 | tfs = LTTV_TRACEFILE_STATE(tfc); |
| 3859 | |
| 3860 | // LttvTracefileState *tfs = |
| 3861 | // (LttvTracefileState*)tsc->traces[process_info->trace_num]-> |
| 3862 | // tracefiles[process_info->cpu]; |
| 3863 | |
| 3864 | LttvProcessState *process; |
| 3865 | process = lttv_state_find_process(tfs, |
| 3866 | process_info->pid); |
| 3867 | |
| 3868 | if(unlikely(process != NULL)) { |
| 3869 | |
| 3870 | /* Only draw for processes that are currently in the trace states */ |
| 3871 | |
| 3872 | ProcessList *process_list = control_flow_data->process_list; |
| 3873 | #ifdef EXTRA_CHECK |
| 3874 | /* Should be alike when background info is ready */ |
| 3875 | if(control_flow_data->background_info_waiting==0) |
| 3876 | g_assert(ltt_time_compare(process->creation_time, |
| 3877 | process_info->birth) == 0); |
| 3878 | #endif //EXTRA_CHECK |
| 3879 | |
| 3880 | /* Now, the process is in the state hash and our own process hash. |
| 3881 | * We definitely can draw the items related to the ending state. |
| 3882 | */ |
| 3883 | |
| 3884 | if(unlikely(ltt_time_compare(hashed_process_data->next_good_time, |
| 3885 | evtime) <= 0)) |
| 3886 | { |
| 3887 | TimeWindow time_window = |
| 3888 | lttvwindow_get_time_window(control_flow_data->tab); |
| 3889 | |
| 3890 | #ifdef EXTRA_CHECK |
| 3891 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
| 3892 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
| 3893 | return; |
| 3894 | #endif //EXTRA_CHECK |
| 3895 | Drawing_t *drawing = control_flow_data->drawing; |
| 3896 | guint width = drawing->width; |
| 3897 | |
| 3898 | guint x = closure_data->x_end; |
| 3899 | |
| 3900 | DrawContext draw_context; |
| 3901 | |
| 3902 | /* Now create the drawing context that will be used to draw |
| 3903 | * items related to the last state. */ |
| 3904 | draw_context.drawable = hashed_process_data->pixmap; |
| 3905 | draw_context.gc = drawing->gc; |
| 3906 | draw_context.pango_layout = drawing->pango_layout; |
| 3907 | draw_context.drawinfo.end.x = x; |
| 3908 | |
| 3909 | draw_context.drawinfo.y.over = 1; |
| 3910 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
| 3911 | draw_context.drawinfo.y.under = hashed_process_data->height; |
| 3912 | |
| 3913 | draw_context.drawinfo.start.offset.over = 0; |
| 3914 | draw_context.drawinfo.start.offset.middle = 0; |
| 3915 | draw_context.drawinfo.start.offset.under = 0; |
| 3916 | draw_context.drawinfo.end.offset.over = 0; |
| 3917 | draw_context.drawinfo.end.offset.middle = 0; |
| 3918 | draw_context.drawinfo.end.offset.under = 0; |
| 3919 | #if 0 |
| 3920 | /* Jump over draw if we are at the same x position */ |
| 3921 | if(x == hashed_process_data->x.over) |
| 3922 | { |
| 3923 | /* jump */ |
| 3924 | } else { |
| 3925 | draw_context.drawinfo.start.x = hashed_process_data->x.over; |
| 3926 | /* Draw the line */ |
| 3927 | PropertiesLine prop_line = prepare_execmode_line(process); |
| 3928 | draw_line((void*)&prop_line, (void*)&draw_context); |
| 3929 | |
| 3930 | hashed_process_data->x.over = x; |
| 3931 | } |
| 3932 | #endif //0 |
| 3933 | |
| 3934 | if(unlikely(x == hashed_process_data->x.middle && |
| 3935 | hashed_process_data->x.middle_used)) { |
| 3936 | #if 0 /* do not mark closure : not missing information */ |
| 3937 | if(hashed_process_data->x.middle_marked == FALSE) { |
| 3938 | /* Draw collision indicator */ |
| 3939 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
| 3940 | gdk_draw_point(drawing->pixmap, |
| 3941 | drawing->gc, |
| 3942 | x, |
| 3943 | y+(height/2)-3); |
| 3944 | hashed_process_data->x.middle_marked = TRUE; |
| 3945 | } |
| 3946 | #endif //0 |
| 3947 | /* Jump */ |
| 3948 | } else { |
| 3949 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
| 3950 | /* Draw the line */ |
| 3951 | PropertiesLine prop_line = prepare_s_e_line(process); |
| 3952 | draw_line((void*)&prop_line, (void*)&draw_context); |
| 3953 | |
| 3954 | /* become the last x position */ |
| 3955 | if(likely(x != hashed_process_data->x.middle)) { |
| 3956 | hashed_process_data->x.middle = x; |
| 3957 | /* but don't use the pixel */ |
| 3958 | hashed_process_data->x.middle_used = FALSE; |
| 3959 | |
| 3960 | /* Calculate the next good time */ |
| 3961 | convert_pixels_to_time(width, x+1, time_window, |
| 3962 | &hashed_process_data->next_good_time); |
| 3963 | } |
| 3964 | } |
| 3965 | } |
| 3966 | } |
| 3967 | } |
| 3968 | return; |
| 3969 | } |
| 3970 | |
| 3971 | int before_chunk(void *hook_data, void *call_data) |
| 3972 | { |
| 3973 | EventsRequest *events_request = (EventsRequest*)hook_data; |
| 3974 | LttvTracesetState *tss = (LttvTracesetState*)call_data; |
| 3975 | ControlFlowData *cfd = (ControlFlowData*)events_request->viewer_data; |
| 3976 | #if 0 |
| 3977 | /* Desactivate sort */ |
| 3978 | gtk_tree_sortable_set_sort_column_id( |
| 3979 | GTK_TREE_SORTABLE(cfd->process_list->list_store), |
| 3980 | TRACE_COLUMN, |
| 3981 | GTK_SORT_ASCENDING); |
| 3982 | #endif //0 |
| 3983 | drawing_chunk_begin(events_request, tss); |
| 3984 | |
| 3985 | return 0; |
| 3986 | } |
| 3987 | |
| 3988 | int before_request(void *hook_data, void *call_data) |
| 3989 | { |
| 3990 | EventsRequest *events_request = (EventsRequest*)hook_data; |
| 3991 | LttvTracesetState *tss = (LttvTracesetState*)call_data; |
| 3992 | |
| 3993 | drawing_data_request_begin(events_request, tss); |
| 3994 | |
| 3995 | return 0; |
| 3996 | } |
| 3997 | |
| 3998 | |
| 3999 | /* |
| 4000 | * after request is necessary in addition of after chunk in order to draw |
| 4001 | * lines until the end of the screen. after chunk just draws lines until |
| 4002 | * the last event. |
| 4003 | * |
| 4004 | * for each process |
| 4005 | * draw closing line |
| 4006 | * expose |
| 4007 | */ |
| 4008 | int after_request(void *hook_data, void *call_data) |
| 4009 | { |
| 4010 | EventsRequest *events_request = (EventsRequest*)hook_data; |
| 4011 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 4012 | LttvTracesetState *tss = (LttvTracesetState*)call_data; |
| 4013 | |
| 4014 | ProcessList *process_list = control_flow_data->process_list; |
| 4015 | LttTime end_time = events_request->end_time; |
| 4016 | |
| 4017 | ClosureData closure_data; |
| 4018 | closure_data.events_request = (EventsRequest*)hook_data; |
| 4019 | closure_data.tss = tss; |
| 4020 | closure_data.end_time = end_time; |
| 4021 | |
| 4022 | TimeWindow time_window = |
| 4023 | lttvwindow_get_time_window(control_flow_data->tab); |
| 4024 | guint width = control_flow_data->drawing->width; |
| 4025 | convert_time_to_pixels( |
| 4026 | time_window, |
| 4027 | end_time, |
| 4028 | width, |
| 4029 | &closure_data.x_end); |
| 4030 | |
| 4031 | |
| 4032 | /* Draw last items */ |
| 4033 | g_hash_table_foreach(process_list->process_hash, draw_closure, |
| 4034 | (void*)&closure_data); |
| 4035 | |
| 4036 | |
| 4037 | /* Request expose */ |
| 4038 | drawing_request_expose(events_request, tss, end_time); |
| 4039 | return 0; |
| 4040 | } |
| 4041 | |
| 4042 | /* |
| 4043 | * for each process |
| 4044 | * draw closing line |
| 4045 | * expose |
| 4046 | */ |
| 4047 | int after_chunk(void *hook_data, void *call_data) |
| 4048 | { |
| 4049 | EventsRequest *events_request = (EventsRequest*)hook_data; |
| 4050 | ControlFlowData *control_flow_data = events_request->viewer_data; |
| 4051 | LttvTracesetState *tss = (LttvTracesetState*)call_data; |
| 4052 | LttvTracesetContext *tsc = (LttvTracesetContext*)call_data; |
| 4053 | LttvTracefileContext *tfc = lttv_traceset_context_get_current_tfc(tsc); |
| 4054 | LttTime end_time; |
| 4055 | |
| 4056 | ProcessList *process_list = control_flow_data->process_list; |
| 4057 | |
| 4058 | g_free(process_list->current_hash_data); |
| 4059 | process_list->current_hash_data = NULL; |
| 4060 | |
| 4061 | if(tfc != NULL) |
| 4062 | end_time = LTT_TIME_MIN(tfc->timestamp, events_request->end_time); |
| 4063 | else /* end of traceset, or position now out of request : end */ |
| 4064 | end_time = events_request->end_time; |
| 4065 | |
| 4066 | ClosureData closure_data; |
| 4067 | closure_data.events_request = (EventsRequest*)hook_data; |
| 4068 | closure_data.tss = tss; |
| 4069 | closure_data.end_time = end_time; |
| 4070 | |
| 4071 | TimeWindow time_window = |
| 4072 | lttvwindow_get_time_window(control_flow_data->tab); |
| 4073 | guint width = control_flow_data->drawing->width; |
| 4074 | convert_time_to_pixels( |
| 4075 | time_window, |
| 4076 | end_time, |
| 4077 | width, |
| 4078 | &closure_data.x_end); |
| 4079 | |
| 4080 | /* Draw last items */ |
| 4081 | g_hash_table_foreach(process_list->process_hash, draw_closure, |
| 4082 | (void*)&closure_data); |
| 4083 | #if 0 |
| 4084 | /* Reactivate sort */ |
| 4085 | gtk_tree_sortable_set_sort_column_id( |
| 4086 | GTK_TREE_SORTABLE(control_flow_data->process_list->list_store), |
| 4087 | GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, |
| 4088 | GTK_SORT_ASCENDING); |
| 4089 | |
| 4090 | update_index_to_pixmap(control_flow_data->process_list); |
| 4091 | /* Request a full expose : drawing scrambled */ |
| 4092 | gtk_widget_queue_draw(control_flow_data->drawing->drawing_area); |
| 4093 | #endif //0 |
| 4094 | /* Request expose (updates damages zone also) */ |
| 4095 | drawing_request_expose(events_request, tss, end_time); |
| 4096 | |
| 4097 | return 0; |
| 4098 | } |
| 4099 | |