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