1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Mathieu Desnoyers
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;
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.
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,
20 /*****************************************************************************
21 * Hooks to be called by the main window *
22 *****************************************************************************/
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.
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.
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.
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
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
52 //#define PANGO_ENABLE_BACKEND
60 //#include <pango/pango.h>
62 #include <ltt/event.h>
65 #include <ltt/trace.h>
67 #include <lttv/lttv.h>
68 #include <lttv/hook.h>
69 #include <lttv/state.h>
70 #include <lttvwindow/lttvwindow.h>
71 #include <lttvwindow/lttvwindowtraces.h>
72 #include <lttvwindow/support.h>
75 #include "eventhooks.h"
77 #include "processlist.h"
81 #define MAX_PATH_LEN 256
82 #define STATE_LINE_WIDTH 4
83 #define COLLISION_POSITION(height) (((height - STATE_LINE_WIDTH)/2) -3)
85 extern GSList
*g_legend_list
;
88 /* Action to do when background computation completed.
90 * Wait for all the awaited computations to be over.
93 static gint
background_ready(void *hook_data
, void *call_data
)
95 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
96 LttvTrace
*trace
= (LttvTrace
*)call_data
;
98 control_flow_data
->background_info_waiting
--;
100 if(control_flow_data
->background_info_waiting
== 0) {
101 g_message("control flow viewer : background computation data ready.");
103 drawing_clear(control_flow_data
->drawing
);
104 processlist_clear(control_flow_data
->process_list
);
105 gtk_widget_set_size_request(
106 control_flow_data
->drawing
->drawing_area
,
107 -1, processlist_get_height(control_flow_data
->process_list
));
108 redraw_notify(control_flow_data
, NULL
);
115 /* Request background computation. Verify if it is in progress or ready first.
116 * Only for each trace in the tab's traceset.
118 static void request_background_data(ControlFlowData
*control_flow_data
)
120 LttvTracesetContext
* tsc
=
121 lttvwindow_get_traceset_context(control_flow_data
->tab
);
122 gint num_traces
= lttv_traceset_number(tsc
->ts
);
125 LttvTraceState
*tstate
;
127 LttvHooks
*background_ready_hook
=
129 lttv_hooks_add(background_ready_hook
, background_ready
, control_flow_data
,
131 control_flow_data
->background_info_waiting
= 0;
133 for(i
=0;i
<num_traces
;i
++) {
134 trace
= lttv_traceset_get(tsc
->ts
, i
);
135 tstate
= LTTV_TRACE_STATE(tsc
->traces
[i
]);
137 if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace
)==FALSE
138 && !tstate
->has_precomputed_states
) {
140 if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"),
142 /* We first remove requests that could have been done for the same
143 * information. Happens when two viewers ask for it before servicing
146 if(!lttvwindowtraces_background_request_find(trace
, "state"))
147 lttvwindowtraces_background_request_queue(
148 main_window_get_widget(control_flow_data
->tab
), trace
, "state");
149 lttvwindowtraces_background_notify_queue(control_flow_data
,
153 background_ready_hook
);
154 control_flow_data
->background_info_waiting
++;
155 } else { /* in progress */
157 lttvwindowtraces_background_notify_current(control_flow_data
,
161 background_ready_hook
);
162 control_flow_data
->background_info_waiting
++;
165 /* Data ready. By its nature, this viewer doesn't need to have
166 * its data ready hook called there, because a background
167 * request is always linked with a redraw.
173 lttv_hooks_destroy(background_ready_hook
);
180 * Event Viewer's constructor hook
182 * This constructor is given as a parameter to the menuitem and toolbar button
183 * registration. It creates the list.
184 * @param tab A pointer to the parent tab.
185 * @return The widget created.
188 h_resourceview(LttvPlugin
*plugin
)
190 LttvPluginTab
*ptab
= LTTV_PLUGIN_TAB(plugin
);
191 Tab
*tab
= ptab
->tab
;
192 g_info("h_guicontrolflow, %p", tab
);
193 ControlFlowData
*control_flow_data
= resourceview(ptab
);
195 control_flow_data
->tab
= tab
;
197 // Unreg done in the GuiControlFlow_Destructor
198 lttvwindow_register_traceset_notify(tab
,
202 lttvwindow_register_time_window_notify(tab
,
203 update_time_window_hook
,
205 lttvwindow_register_current_time_notify(tab
,
206 update_current_time_hook
,
208 lttvwindow_register_redraw_notify(tab
,
211 lttvwindow_register_continue_notify(tab
,
214 request_background_data(control_flow_data
);
217 return guicontrolflow_get_widget(control_flow_data
) ;
221 void legend_destructor(GtkWindow
*legend
)
223 g_legend_list
= g_slist_remove(g_legend_list
, legend
);
226 /* Create a popup legend */
228 h_legend(LttvPlugin
*plugin
)
230 LttvPluginTab
*ptab
= LTTV_PLUGIN_TAB(plugin
);
231 Tab
*tab
= ptab
->tab
;
232 g_info("h_legend, %p", tab
);
234 GtkWindow
*legend
= GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL
));
236 g_legend_list
= g_slist_append(
240 g_object_set_data_full(
244 (GDestroyNotify
)legend_destructor
);
246 gtk_window_set_title(legend
, "Control Flow View Legend");
248 GtkWidget
*pixmap
= create_pixmap(GTK_WIDGET(legend
), "lttv-color-list.png");
250 // GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixmap(
251 // GDK_PIXMAP(pixmap), NULL));
253 gtk_container_add(GTK_CONTAINER(legend
), GTK_WIDGET(pixmap
));
255 gtk_widget_show(GTK_WIDGET(pixmap
));
256 gtk_widget_show(GTK_WIDGET(legend
));
259 return NULL
; /* This is a popup window */
263 int event_selected_hook(void *hook_data
, void *call_data
)
265 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
266 guint
*event_number
= (guint
*) call_data
;
268 g_debug("DEBUG : event selected by main window : %u", *event_number
);
273 /* Function that selects the color of status&exemode line */
274 static inline PropertiesLine
prepare_s_e_line(LttvProcessState
*process
)
276 PropertiesLine prop_line
;
277 prop_line
.line_width
= STATE_LINE_WIDTH
;
278 prop_line
.style
= GDK_LINE_SOLID
;
279 prop_line
.y
= MIDDLE
;
281 if(process
->state
->s
== LTTV_STATE_RUN
) {
282 if(process
->state
->t
== LTTV_STATE_USER_MODE
)
283 prop_line
.color
= drawing_colors
[COL_RUN_USER_MODE
];
284 else if(process
->state
->t
== LTTV_STATE_SYSCALL
)
285 prop_line
.color
= drawing_colors
[COL_RUN_SYSCALL
];
286 else if(process
->state
->t
== LTTV_STATE_TRAP
)
287 prop_line
.color
= drawing_colors
[COL_RUN_TRAP
];
288 else if(process
->state
->t
== LTTV_STATE_IRQ
)
289 prop_line
.color
= drawing_colors
[COL_RUN_IRQ
];
290 else if(process
->state
->t
== LTTV_STATE_SOFT_IRQ
)
291 prop_line
.color
= drawing_colors
[COL_RUN_SOFT_IRQ
];
292 else if(process
->state
->t
== LTTV_STATE_MODE_UNKNOWN
)
293 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
295 g_assert(FALSE
); /* RUNNING MODE UNKNOWN */
296 } else if(process
->state
->s
== LTTV_STATE_WAIT
) {
297 /* We don't show if we wait while in user mode, trap, irq or syscall */
298 prop_line
.color
= drawing_colors
[COL_WAIT
];
299 } else if(process
->state
->s
== LTTV_STATE_WAIT_CPU
) {
300 /* We don't show if we wait for CPU while in user mode, trap, irq
302 prop_line
.color
= drawing_colors
[COL_WAIT_CPU
];
303 } else if(process
->state
->s
== LTTV_STATE_ZOMBIE
) {
304 prop_line
.color
= drawing_colors
[COL_ZOMBIE
];
305 } else if(process
->state
->s
== LTTV_STATE_WAIT_FORK
) {
306 prop_line
.color
= drawing_colors
[COL_WAIT_FORK
];
307 } else if(process
->state
->s
== LTTV_STATE_EXIT
) {
308 prop_line
.color
= drawing_colors
[COL_EXIT
];
309 } else if(process
->state
->s
== LTTV_STATE_UNNAMED
) {
310 prop_line
.color
= drawing_colors
[COL_UNNAMED
];
312 g_critical("unknown state : %s", g_quark_to_string(process
->state
->s
));
313 g_assert(FALSE
); /* UNKNOWN STATE */
320 static void cpu_set_line_color(PropertiesLine
*prop_line
, LttvCPUState
*s
)
322 GQuark present_state
= ((GQuark
*)s
->mode_stack
->data
)[s
->mode_stack
->len
-1];
324 if(present_state
== LTTV_CPU_UNKNOWN
) {
325 prop_line
->color
= drawing_colors_cpu
[COL_CPU_UNKNOWN
];
327 else if(present_state
== LTTV_CPU_IDLE
) {
328 prop_line
->color
= drawing_colors_cpu
[COL_CPU_IDLE
];
330 else if(present_state
== LTTV_CPU_BUSY
) {
331 prop_line
->color
= drawing_colors_cpu
[COL_CPU_BUSY
];
333 else if(present_state
== LTTV_CPU_IRQ
) {
334 prop_line
->color
= drawing_colors_cpu
[COL_CPU_IRQ
];
336 else if(present_state
== LTTV_CPU_TRAP
) {
337 prop_line
->color
= drawing_colors_cpu
[COL_CPU_TRAP
];
341 static void irq_set_line_color(PropertiesLine
*prop_line
, LttvIRQState
*s
)
343 GQuark present_state
= ((GQuark
*)s
->mode_stack
->data
)[s
->mode_stack
->len
-1];
345 if(present_state
== LTTV_IRQ_UNKNOWN
) {
346 prop_line
->color
= drawing_colors_irq
[COL_IRQ_UNKNOWN
];
348 else if(present_state
== LTTV_IRQ_IDLE
) {
349 prop_line
->color
= drawing_colors_irq
[COL_IRQ_IDLE
];
351 else if(present_state
== LTTV_IRQ_BUSY
) {
352 prop_line
->color
= drawing_colors_irq
[COL_IRQ_BUSY
];
356 /* before_schedchange_hook
358 * This function basically draw lines and icons. Two types of lines are drawn :
359 * one small (3 pixels?) representing the state of the process and the second
360 * type is thicker (10 pixels?) representing on which CPU a process is running
361 * (and this only in running state).
363 * Extremums of the lines :
364 * x_min : time of the last event context for this process kept in memory.
365 * x_max : time of the current event.
366 * y : middle of the process in the process list. The process is found in the
367 * list, therefore is it's position in pixels.
369 * The choice of lines'color is defined by the context of the last event for this
374 int before_schedchange_hook(void *hook_data
, void *call_data
)
376 before_schedchange_hook_cpu(hook_data
, call_data
);
377 // before_schedchange_hook_irq(hook_data, call_data);
382 int before_schedchange_hook_cpu(void *hook_data
, void *call_data
)
384 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
385 EventsRequest
*events_request
= (EventsRequest
*)thf
->hook_data
;
386 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
388 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
390 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
391 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
394 e
= ltt_tracefile_get_event(tfc
->tf
);
395 gint target_pid_saved
= tfc
->target_pid
;
397 LttTime evtime
= ltt_event_time(e
);
398 LttvFilter
*filter
= control_flow_data
->filter
;
402 /* we are in a schedchange, before the state update. We must draw the
403 * items corresponding to the state before it changes : now is the right
409 pid_out
= ltt_event_get_long_unsigned(e
, thf
->f1
);
410 pid_in
= ltt_event_get_long_unsigned(e
, thf
->f2
);
411 // if(pid_in != 0 && pid_out != 0) {
412 // /* not a transition to/from idle */
416 tfc
->target_pid
= pid_out
;
417 // if(!filter || !filter->head ||
418 // lttv_filter_tree_parse(filter->head,e,tfc->tf,
419 // tfc->t_context->t,tfc,NULL,NULL)) {
420 /* For the pid_out */
421 /* First, check if the current process is in the state computation
422 * process list. If it is there, that means we must add it right now and
423 * draw items from the beginning of the read for it. If it is not
424 * present, it's a new process and it was not present : it will
425 * be added after the state update. */
426 guint cpu
= tfs
->cpu
;
429 cpustr
= g_strdup_printf("CPU%u", cpu
);
430 cpuq
= g_quark_from_string(cpustr
);
434 guint trace_num
= ts
->parent
.index
;
435 // LttvProcessState *process = ts->running_process[cpu];
436 /* unknown state, bad current pid */
437 // if(process->pid != pid_out)
438 // process = lttv_state_find_process(ts,
439 // tfs->cpu, pid_out);
441 // if(process != NULL) {
442 /* Well, the process_out existed : we must get it in the process hash
443 * or add it, and draw its items.
445 /* Add process to process list (if not present) */
447 HashedResourceData
*hashed_process_data
= NULL
;
448 ProcessList
*process_list
= control_flow_data
->process_list
;
449 // LttTime birth = process->creation_time;
451 hashed_process_data
= processlist_get_process_data(process_list
, cpuq
, trace_num
);
452 // hashed_process_data = processlist_get_process_data(process_list,
457 if(hashed_process_data
== NULL
)
459 // g_assert(pid_out == 0 || pid_out != process->ppid);
460 /* Process not present */
461 ResourceInfo
*process_info
;
462 Drawing_t
*drawing
= control_flow_data
->drawing
;
463 resourcelist_add(process_list
,
466 cpuq
, //process->name,
471 &hashed_process_data
);
472 gtk_widget_set_size_request(drawing
->drawing_area
,
475 gtk_widget_queue_draw(drawing
->drawing_area
);
479 /* Now, the process is in the state hash and our own process hash.
480 * We definitely can draw the items related to the ending state.
483 if(ltt_time_compare(hashed_process_data
->next_good_time
,
486 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
488 TimeWindow time_window
=
489 lttvwindow_get_time_window(control_flow_data
->tab
);
491 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
492 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
495 Drawing_t
*drawing
= control_flow_data
->drawing
;
496 guint width
= drawing
->width
;
498 convert_time_to_pixels(
504 /* Draw collision indicator */
505 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
506 gdk_draw_point(hashed_process_data
->pixmap
,
509 COLLISION_POSITION(hashed_process_data
->height
));
510 hashed_process_data
->x
.middle_marked
= TRUE
;
513 TimeWindow time_window
=
514 lttvwindow_get_time_window(control_flow_data
->tab
);
516 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
517 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
520 Drawing_t
*drawing
= control_flow_data
->drawing
;
521 guint width
= drawing
->width
;
523 convert_time_to_pixels(
530 /* Jump over draw if we are at the same x position */
531 if(x
== hashed_process_data
->x
.middle
&&
532 hashed_process_data
->x
.middle_used
)
534 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
535 /* Draw collision indicator */
536 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
537 gdk_draw_point(hashed_process_data
->pixmap
,
540 COLLISION_POSITION(hashed_process_data
->height
));
541 hashed_process_data
->x
.middle_marked
= TRUE
;
545 DrawContext draw_context
;
547 /* Now create the drawing context that will be used to draw
548 * items related to the last state. */
549 draw_context
.drawable
= hashed_process_data
->pixmap
;
550 draw_context
.gc
= drawing
->gc
;
551 draw_context
.pango_layout
= drawing
->pango_layout
;
552 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
553 draw_context
.drawinfo
.end
.x
= x
;
555 draw_context
.drawinfo
.y
.over
= 1;
556 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
557 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
559 draw_context
.drawinfo
.start
.offset
.over
= 0;
560 draw_context
.drawinfo
.start
.offset
.middle
= 0;
561 draw_context
.drawinfo
.start
.offset
.under
= 0;
562 draw_context
.drawinfo
.end
.offset
.over
= 0;
563 draw_context
.drawinfo
.end
.offset
.middle
= 0;
564 draw_context
.drawinfo
.end
.offset
.under
= 0;
568 //PropertiesLine prop_line = prepare_s_e_line(process);
569 PropertiesLine prop_line
;
570 prop_line
.line_width
= STATE_LINE_WIDTH
;
571 prop_line
.style
= GDK_LINE_SOLID
;
572 prop_line
.y
= MIDDLE
;
573 cpu_set_line_color(&prop_line
, tfs
->cpu_state
);
574 draw_line((void*)&prop_line
, (void*)&draw_context
);
577 /* become the last x position */
578 hashed_process_data
->x
.middle
= x
;
579 hashed_process_data
->x
.middle_used
= TRUE
;
580 hashed_process_data
->x
.middle_marked
= FALSE
;
582 /* Calculate the next good time */
583 convert_pixels_to_time(width
, x
+1, time_window
,
584 &hashed_process_data
->next_good_time
);
590 // tfc->target_pid = pid_in;
591 // if(!filter || !filter->head ||
592 // lttv_filter_tree_parse(filter->head,e,tfc->tf,
593 // tfc->t_context->t,tfc,NULL,NULL)) {
594 // /* For the pid_in */
595 // /* First, check if the current process is in the state computation
596 // * process list. If it is there, that means we must add it right now and
597 // * draw items from the beginning of the read for it. If it is not
598 // * present, it's a new process and it was not present : it will
599 // * be added after the state update. */
600 // LttvProcessState *process;
601 // process = lttv_state_find_process(ts,
602 // tfs->cpu, pid_in);
603 // guint trace_num = ts->parent.index;
605 // if(process != NULL) {
606 // /* Well, the process existed : we must get it in the process hash
607 // * or add it, and draw its items.
609 // /* Add process to process list (if not present) */
610 // guint pl_height = 0;
611 // HashedResourceData *hashed_process_data = NULL;
612 // ProcessList *process_list = control_flow_data->process_list;
613 // LttTime birth = process->creation_time;
615 // hashed_process_data = processlist_get_process_data(process_list, cpuq);
616 //// hashed_process_data = processlist_get_process_data(process_list,
621 // if(hashed_process_data == NULL)
623 // g_assert(pid_in == 0 || pid_in != process->ppid);
624 // /* Process not present */
625 // ResourceInfo *process_info;
626 // Drawing_t *drawing = control_flow_data->drawing;
627 // resourcelist_add(process_list,
639 // &hashed_process_data);
640 // gtk_widget_set_size_request(drawing->drawing_area,
643 // gtk_widget_queue_draw(drawing->drawing_area);
646 // //We could set the current process and hash here, but will be done
647 // //by after schedchange hook
649 // /* Now, the process is in the state hash and our own process hash.
650 // * We definitely can draw the items related to the ending state.
653 // if(ltt_time_compare(hashed_process_data->next_good_time,
656 // if(hashed_process_data->x.middle_marked == FALSE) {
658 // TimeWindow time_window =
659 // lttvwindow_get_time_window(control_flow_data->tab);
661 // if(ltt_time_compare(evtime, time_window.start_time) == -1
662 // || ltt_time_compare(evtime, time_window.end_time) == 1)
664 //#endif //EXTRA_CHECK
665 // Drawing_t *drawing = control_flow_data->drawing;
666 // guint width = drawing->width;
668 // convert_time_to_pixels(
674 // /* Draw collision indicator */
675 // gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
676 // gdk_draw_point(hashed_process_data->pixmap,
679 // COLLISION_POSITION(hashed_process_data->height));
680 // hashed_process_data->x.middle_marked = TRUE;
683 // TimeWindow time_window =
684 // lttvwindow_get_time_window(control_flow_data->tab);
686 // if(ltt_time_compare(evtime, time_window.start_time) == -1
687 // || ltt_time_compare(evtime, time_window.end_time) == 1)
689 //#endif //EXTRA_CHECK
690 // Drawing_t *drawing = control_flow_data->drawing;
691 // guint width = drawing->width;
694 // convert_time_to_pixels(
701 // /* Jump over draw if we are at the same x position */
702 // if(x == hashed_process_data->x.middle &&
703 // hashed_process_data->x.middle_used)
705 // if(hashed_process_data->x.middle_marked == FALSE) {
706 // /* Draw collision indicator */
707 // gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
708 // gdk_draw_point(hashed_process_data->pixmap,
711 // COLLISION_POSITION(hashed_process_data->height));
712 // hashed_process_data->x.middle_marked = TRUE;
716 // DrawContext draw_context;
718 // /* Now create the drawing context that will be used to draw
719 // * items related to the last state. */
720 // draw_context.drawable = hashed_process_data->pixmap;
721 // draw_context.gc = drawing->gc;
722 // draw_context.pango_layout = drawing->pango_layout;
723 // draw_context.drawinfo.start.x = hashed_process_data->x.middle;
724 // draw_context.drawinfo.end.x = x;
726 // draw_context.drawinfo.y.over = 1;
727 // draw_context.drawinfo.y.middle = (hashed_process_data->height/2);
728 // draw_context.drawinfo.y.under = hashed_process_data->height;
730 // draw_context.drawinfo.start.offset.over = 0;
731 // draw_context.drawinfo.start.offset.middle = 0;
732 // draw_context.drawinfo.start.offset.under = 0;
733 // draw_context.drawinfo.end.offset.over = 0;
734 // draw_context.drawinfo.end.offset.middle = 0;
735 // draw_context.drawinfo.end.offset.under = 0;
738 // /* Draw the line */
739 // PropertiesLine prop_line = prepare_s_e_line(process);
740 // draw_line((void*)&prop_line, (void*)&draw_context);
744 // /* become the last x position */
745 // hashed_process_data->x.middle = x;
746 // hashed_process_data->x.middle_used = TRUE;
747 // hashed_process_data->x.middle_marked = FALSE;
749 // /* Calculate the next good time */
750 // convert_pixels_to_time(width, x+1, time_window,
751 // &hashed_process_data->next_good_time);
755 // g_warning("Cannot find pin_in in schedchange %u", pid_in);
757 // tfc->target_pid = target_pid_saved;
765 GString
*string
= g_string_new("");;
766 gboolean field_names
= TRUE
, state
= TRUE
;
768 lttv_event_to_string(e
, tfc
->tf
, string
, TRUE
, field_names
, tfs
);
769 g_string_append_printf(string
,"\n");
772 g_string_append_printf(string
, " %s",
773 g_quark_to_string(tfs
->process
->state
->s
));
776 g_info("%s",string
->str
);
778 g_string_free(string
, TRUE
);
780 /* End of text dump */
785 /* after_schedchange_hook
787 * The draw after hook is called by the reading API to have a
788 * particular event drawn on the screen.
789 * @param hook_data ControlFlowData structure of the viewer.
790 * @param call_data Event context.
792 * This function adds items to be drawn in a queue for each process.
795 int after_schedchange_hook(void *hook_data
, void *call_data
)
797 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
798 EventsRequest
*events_request
= (EventsRequest
*)thf
->hook_data
;
799 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
801 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
803 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
805 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
808 e
= ltt_tracefile_get_event(tfc
->tf
);
810 LttvFilter
*filter
= control_flow_data
->filter
;
811 if(filter
!= NULL
&& filter
->head
!= NULL
)
812 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
813 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
816 LttTime evtime
= ltt_event_time(e
);
820 /* Add process to process list (if not present) */
821 LttvProcessState
*process_in
;
824 HashedResourceData
*hashed_process_data_in
= NULL
;
826 ProcessList
*process_list
= control_flow_data
->process_list
;
831 pid_out
= ltt_event_get_long_unsigned(e
, thf
->f1
);
832 pid_in
= ltt_event_get_long_unsigned(e
, thf
->f2
);
836 /* Find process pid_in in the list... */
837 //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in);
838 //process_in = tfs->process;
839 guint cpu
= tfs
->cpu
;
842 cpustr
= g_strdup_printf("CPU%u", cpu
);
843 cpuq
= g_quark_from_string(cpustr
);
846 guint trace_num
= ts
->parent
.index
;
847 process_in
= ts
->running_process
[cpu
];
848 /* It should exist, because we are after the state update. */
850 g_assert(process_in
!= NULL
);
852 birth
= process_in
->creation_time
;
854 hashed_process_data_in
= processlist_get_process_data(process_list
, cpuq
, trace_num
);
855 // hashed_process_data_in = processlist_get_process_data(process_list,
860 if(hashed_process_data_in
== NULL
)
862 g_assert(pid_in
== 0 || pid_in
!= process_in
->ppid
);
863 ResourceInfo
*process_info
;
864 Drawing_t
*drawing
= control_flow_data
->drawing
;
865 /* Process not present */
866 resourcelist_add(process_list
,
874 &hashed_process_data_in
);
875 gtk_widget_set_size_request(drawing
->drawing_area
,
878 gtk_widget_queue_draw(drawing
->drawing_area
);
880 /* Set the current process */
881 process_list
->current_hash_data
[trace_num
][process_in
->cpu
] =
882 hashed_process_data_in
;
884 if(ltt_time_compare(hashed_process_data_in
->next_good_time
,
887 TimeWindow time_window
=
888 lttvwindow_get_time_window(control_flow_data
->tab
);
891 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
892 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
895 Drawing_t
*drawing
= control_flow_data
->drawing
;
896 guint width
= drawing
->width
;
899 convert_time_to_pixels(
905 if(hashed_process_data_in
->x
.middle
!= new_x
) {
906 hashed_process_data_in
->x
.middle
= new_x
;
907 hashed_process_data_in
->x
.middle_used
= FALSE
;
908 hashed_process_data_in
->x
.middle_marked
= FALSE
;
914 /* before_execmode_hook
916 * This function basically draw lines and icons. Two types of lines are drawn :
917 * one small (3 pixels?) representing the state of the process and the second
918 * type is thicker (10 pixels?) representing on which CPU a process is running
919 * (and this only in running state).
921 * Extremums of the lines :
922 * x_min : time of the last event context for this process kept in memory.
923 * x_max : time of the current event.
924 * y : middle of the process in the process list. The process is found in the
925 * list, therefore is it's position in pixels.
927 * The choice of lines'color is defined by the context of the last event for this
931 int before_execmode_hook(void *hook_data
, void *call_data
)
933 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
934 EventsRequest
*events_request
= (EventsRequest
*)thf
->hook_data
;
935 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
937 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
939 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
940 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
943 e
= ltt_tracefile_get_event(tfc
->tf
);
945 LttTime evtime
= ltt_event_time(e
);
949 before_execmode_hook_irq(hook_data
, call_data
);
951 /* we are in a execmode, before the state update. We must draw the
952 * items corresponding to the state before it changes : now is the right
956 //LttvProcessState *process = tfs->process;
957 guint cpu
= tfs
->cpu
;
960 cpustr
= g_strdup_printf("CPU%u", cpu
);
961 cpuq
= g_quark_from_string(cpustr
);
964 guint trace_num
= ts
->parent
.index
;
965 LttvProcessState
*process
= ts
->running_process
[cpu
];
966 g_assert(process
!= NULL
);
968 // guint pid = process->pid;
970 /* Well, the process_out existed : we must get it in the process hash
971 * or add it, and draw its items.
973 /* Add process to process list (if not present) */
975 HashedResourceData
*hashed_process_data
= NULL
;
976 ProcessList
*process_list
= control_flow_data
->process_list
;
977 LttTime birth
= process
->creation_time
;
979 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
)) {
980 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
982 hashed_process_data
= processlist_get_process_data(process_list
, cpuq
, trace_num
);
983 // hashed_process_data = processlist_get_process_data(process_list,
988 if(unlikely(hashed_process_data
== NULL
))
990 //g_assert(pid == 0 || pid != process->ppid);
991 ResourceInfo
*process_info
;
992 /* Process not present */
993 Drawing_t
*drawing
= control_flow_data
->drawing
;
994 resourcelist_add(process_list
,
997 cpuq
, //process->name,
1002 &hashed_process_data
);
1003 gtk_widget_set_size_request(drawing
->drawing_area
,
1006 gtk_widget_queue_draw(drawing
->drawing_area
);
1008 /* Set the current process */
1009 process_list
->current_hash_data
[trace_num
][process
->cpu
] =
1010 hashed_process_data
;
1013 /* Now, the process is in the state hash and our own process hash.
1014 * We definitely can draw the items related to the ending state.
1017 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
1020 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1021 TimeWindow time_window
=
1022 lttvwindow_get_time_window(control_flow_data
->tab
);
1025 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1026 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1028 #endif //EXTRA_CHECK
1029 Drawing_t
*drawing
= control_flow_data
->drawing
;
1030 guint width
= drawing
->width
;
1032 convert_time_to_pixels(
1038 /* Draw collision indicator */
1039 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1040 gdk_draw_point(hashed_process_data
->pixmap
,
1043 COLLISION_POSITION(hashed_process_data
->height
));
1044 hashed_process_data
->x
.middle_marked
= TRUE
;
1048 TimeWindow time_window
=
1049 lttvwindow_get_time_window(control_flow_data
->tab
);
1052 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1053 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1055 #endif //EXTRA_CHECK
1056 Drawing_t
*drawing
= control_flow_data
->drawing
;
1057 guint width
= drawing
->width
;
1060 convert_time_to_pixels(
1067 /* Jump over draw if we are at the same x position */
1068 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1069 hashed_process_data
->x
.middle_used
))
1071 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1072 /* Draw collision indicator */
1073 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1074 gdk_draw_point(hashed_process_data
->pixmap
,
1077 COLLISION_POSITION(hashed_process_data
->height
));
1078 hashed_process_data
->x
.middle_marked
= TRUE
;
1084 DrawContext draw_context
;
1085 /* Now create the drawing context that will be used to draw
1086 * items related to the last state. */
1087 draw_context
.drawable
= hashed_process_data
->pixmap
;
1088 draw_context
.gc
= drawing
->gc
;
1089 draw_context
.pango_layout
= drawing
->pango_layout
;
1090 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1091 draw_context
.drawinfo
.end
.x
= x
;
1093 draw_context
.drawinfo
.y
.over
= 1;
1094 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
1095 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
1097 draw_context
.drawinfo
.start
.offset
.over
= 0;
1098 draw_context
.drawinfo
.start
.offset
.middle
= 0;
1099 draw_context
.drawinfo
.start
.offset
.under
= 0;
1100 draw_context
.drawinfo
.end
.offset
.over
= 0;
1101 draw_context
.drawinfo
.end
.offset
.middle
= 0;
1102 draw_context
.drawinfo
.end
.offset
.under
= 0;
1106 PropertiesLine prop_line
;
1107 prop_line
.line_width
= STATE_LINE_WIDTH
;
1108 prop_line
.style
= GDK_LINE_SOLID
;
1109 prop_line
.y
= MIDDLE
;
1110 cpu_set_line_color(&prop_line
, tfs
->cpu_state
);
1111 draw_line((void*)&prop_line
, (void*)&draw_context
);
1113 /* become the last x position */
1114 hashed_process_data
->x
.middle
= x
;
1115 hashed_process_data
->x
.middle_used
= TRUE
;
1116 hashed_process_data
->x
.middle_marked
= FALSE
;
1118 /* Calculate the next good time */
1119 convert_pixels_to_time(width
, x
+1, time_window
,
1120 &hashed_process_data
->next_good_time
);
1127 int before_execmode_hook_irq(void *hook_data
, void *call_data
)
1129 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
1130 EventsRequest
*events_request
= (EventsRequest
*)thf
->hook_data
;
1131 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1133 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
1135 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
1136 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
1139 e
= ltt_tracefile_get_event(tfc
->tf
);
1141 LttTime evtime
= ltt_event_time(e
);
1145 /* we are in a execmode, before the state update. We must draw the
1146 * items corresponding to the state before it changes : now is the right
1152 guint cpu
= tfs
->cpu
;
1154 LttFacility
*ev_facility
= ltt_event_facility(e
);
1155 if(ltt_facility_name(ev_facility
) != LTT_FACILITY_KERNEL
)
1157 guint8 ev_id_entry
= ltt_eventtype_id(ltt_facility_eventtype_get_by_name(ev_facility
, LTT_EVENT_IRQ_ENTRY
));
1158 guint8 ev_id_exit
= ltt_eventtype_id(ltt_facility_eventtype_get_by_name(ev_facility
, LTT_EVENT_IRQ_EXIT
));
1159 if(ltt_facility_name(ev_facility
) == LTT_FACILITY_KERNEL
&&
1160 ev_id_entry
== ltt_event_eventtype_id(e
)) {
1161 irq
= ltt_event_get_long_unsigned(e
, thf
->f1
);
1163 else if(ltt_facility_name(ev_facility
) == LTT_FACILITY_KERNEL
&&
1164 ev_id_exit
== ltt_event_eventtype_id(e
)) {
1165 irq
= ts
->cpu_states
[cpu
].last_irq
;
1173 irqstr
= g_strdup_printf("IRQ %u", irq
);
1174 resourceq
= g_quark_from_string(irqstr
);
1177 guint trace_num
= ts
->parent
.index
;
1179 // guint pid = process->pid;
1181 /* Well, the process_out existed : we must get it in the process hash
1182 * or add it, and draw its items.
1184 /* Add process to process list (if not present) */
1185 guint pl_height
= 0;
1186 HashedResourceData
*hashed_process_data
= NULL
;
1187 ProcessList
*process_list
= control_flow_data
->process_list
;
1188 // LttTime birth = process->creation_time;
1190 // if(likely(process_list->current_hash_data[trace_num][cpu] != NULL)) {
1191 // hashed_process_data = process_list->current_hash_data[trace_num][cpu];
1193 hashed_process_data
= processlist_get_process_data(process_list
, resourceq
, trace_num
);
1194 // hashed_process_data = processlist_get_process_data(process_list,
1199 if(unlikely(hashed_process_data
== NULL
))
1201 //g_assert(pid == 0 || pid != process->ppid);
1202 ResourceInfo
*process_info
;
1203 /* Process not present */
1204 Drawing_t
*drawing
= control_flow_data
->drawing
;
1205 resourcelist_add(process_list
,
1208 resourceq
, //process->name,
1213 &hashed_process_data
);
1214 gtk_widget_set_size_request(drawing
->drawing_area
,
1217 gtk_widget_queue_draw(drawing
->drawing_area
);
1219 /* Set the current process */
1220 // process_list->current_hash_data[trace_num][process->cpu] =
1221 // hashed_process_data;
1224 /* Now, the process is in the state hash and our own process hash.
1225 * We definitely can draw the items related to the ending state.
1228 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
1231 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1232 TimeWindow time_window
=
1233 lttvwindow_get_time_window(control_flow_data
->tab
);
1236 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1237 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1239 #endif //EXTRA_CHECK
1240 Drawing_t
*drawing
= control_flow_data
->drawing
;
1241 guint width
= drawing
->width
;
1243 convert_time_to_pixels(
1249 /* Draw collision indicator */
1250 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1251 gdk_draw_point(hashed_process_data
->pixmap
,
1254 COLLISION_POSITION(hashed_process_data
->height
));
1255 hashed_process_data
->x
.middle_marked
= TRUE
;
1259 TimeWindow time_window
=
1260 lttvwindow_get_time_window(control_flow_data
->tab
);
1263 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1264 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1266 #endif //EXTRA_CHECK
1267 Drawing_t
*drawing
= control_flow_data
->drawing
;
1268 guint width
= drawing
->width
;
1271 convert_time_to_pixels(
1278 /* Jump over draw if we are at the same x position */
1279 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1280 hashed_process_data
->x
.middle_used
))
1282 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1283 /* Draw collision indicator */
1284 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1285 gdk_draw_point(hashed_process_data
->pixmap
,
1288 COLLISION_POSITION(hashed_process_data
->height
));
1289 hashed_process_data
->x
.middle_marked
= TRUE
;
1295 DrawContext draw_context
;
1296 /* Now create the drawing context that will be used to draw
1297 * items related to the last state. */
1298 draw_context
.drawable
= hashed_process_data
->pixmap
;
1299 draw_context
.gc
= drawing
->gc
;
1300 draw_context
.pango_layout
= drawing
->pango_layout
;
1301 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1302 draw_context
.drawinfo
.end
.x
= x
;
1304 draw_context
.drawinfo
.y
.over
= 1;
1305 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
1306 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
1308 draw_context
.drawinfo
.start
.offset
.over
= 0;
1309 draw_context
.drawinfo
.start
.offset
.middle
= 0;
1310 draw_context
.drawinfo
.start
.offset
.under
= 0;
1311 draw_context
.drawinfo
.end
.offset
.over
= 0;
1312 draw_context
.drawinfo
.end
.offset
.middle
= 0;
1313 draw_context
.drawinfo
.end
.offset
.under
= 0;
1317 PropertiesLine prop_line
;
1318 prop_line
.line_width
= STATE_LINE_WIDTH
;
1319 prop_line
.style
= GDK_LINE_SOLID
;
1320 prop_line
.y
= MIDDLE
;
1321 irq_set_line_color(&prop_line
, &ts
->irq_states
[irq
]);
1322 draw_line((void*)&prop_line
, (void*)&draw_context
);
1324 /* become the last x position */
1325 hashed_process_data
->x
.middle
= x
;
1326 hashed_process_data
->x
.middle_used
= TRUE
;
1327 hashed_process_data
->x
.middle_marked
= FALSE
;
1329 /* Calculate the next good time */
1330 convert_pixels_to_time(width
, x
+1, time_window
,
1331 &hashed_process_data
->next_good_time
);
1338 gint
update_time_window_hook(void *hook_data
, void *call_data
)
1340 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1341 Drawing_t
*drawing
= control_flow_data
->drawing
;
1342 ProcessList
*process_list
= control_flow_data
->process_list
;
1344 const TimeWindowNotifyData
*time_window_nofify_data
=
1345 ((const TimeWindowNotifyData
*)call_data
);
1347 TimeWindow
*old_time_window
=
1348 time_window_nofify_data
->old_time_window
;
1349 TimeWindow
*new_time_window
=
1350 time_window_nofify_data
->new_time_window
;
1352 /* Update the ruler */
1353 drawing_update_ruler(control_flow_data
->drawing
,
1357 /* Two cases : zoom in/out or scrolling */
1359 /* In order to make sure we can reuse the old drawing, the scale must
1360 * be the same and the new time interval being partly located in the
1361 * currently shown time interval. (reuse is only for scrolling)
1364 g_info("Old time window HOOK : %lu, %lu to %lu, %lu",
1365 old_time_window
->start_time
.tv_sec
,
1366 old_time_window
->start_time
.tv_nsec
,
1367 old_time_window
->time_width
.tv_sec
,
1368 old_time_window
->time_width
.tv_nsec
);
1370 g_info("New time window HOOK : %lu, %lu to %lu, %lu",
1371 new_time_window
->start_time
.tv_sec
,
1372 new_time_window
->start_time
.tv_nsec
,
1373 new_time_window
->time_width
.tv_sec
,
1374 new_time_window
->time_width
.tv_nsec
);
1376 if( new_time_window
->time_width
.tv_sec
== old_time_window
->time_width
.tv_sec
1377 && new_time_window
->time_width
.tv_nsec
== old_time_window
->time_width
.tv_nsec
)
1379 /* Same scale (scrolling) */
1380 g_info("scrolling");
1381 LttTime
*ns
= &new_time_window
->start_time
;
1382 LttTime
*nw
= &new_time_window
->time_width
;
1383 LttTime
*os
= &old_time_window
->start_time
;
1384 LttTime
*ow
= &old_time_window
->time_width
;
1385 LttTime old_end
= old_time_window
->end_time
;
1386 LttTime new_end
= new_time_window
->end_time
;
1388 //if(ns<os+w && os+w<ns+w)
1389 //if(ns<old_end && os<ns)
1390 if(ltt_time_compare(*ns
, old_end
) == -1
1391 && ltt_time_compare(*os
, *ns
) == -1)
1393 g_info("scrolling near right");
1394 /* Scroll right, keep right part of the screen */
1396 guint width
= control_flow_data
->drawing
->width
;
1397 convert_time_to_pixels(
1403 /* Copy old data to new location */
1404 copy_pixmap_region(process_list
,
1406 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1410 control_flow_data
->drawing
->width
-x
+SAFETY
, -1);
1412 if(drawing
->damage_begin
== drawing
->damage_end
)
1413 drawing
->damage_begin
= control_flow_data
->drawing
->width
-x
;
1415 drawing
->damage_begin
= 0;
1417 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1419 /* Clear the data request background, but not SAFETY */
1420 rectangle_pixmap(process_list
,
1421 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1423 drawing
->damage_begin
+SAFETY
, 0,
1424 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1426 gtk_widget_queue_draw(drawing
->drawing_area
);
1427 //gtk_widget_queue_draw_area (drawing->drawing_area,
1429 // control_flow_data->drawing->width,
1430 // control_flow_data->drawing->height);
1432 /* Get new data for the rest. */
1433 drawing_data_request(control_flow_data
->drawing
,
1434 drawing
->damage_begin
, 0,
1435 drawing
->damage_end
- drawing
->damage_begin
,
1436 control_flow_data
->drawing
->height
);
1439 //if(ns<os && os<ns+w)
1440 //if(ns<os && os<new_end)
1441 if(ltt_time_compare(*ns
,*os
) == -1
1442 && ltt_time_compare(*os
,new_end
) == -1)
1444 g_info("scrolling near left");
1445 /* Scroll left, keep left part of the screen */
1447 guint width
= control_flow_data
->drawing
->width
;
1448 convert_time_to_pixels(
1454 /* Copy old data to new location */
1455 copy_pixmap_region (process_list
,
1457 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1463 if(drawing
->damage_begin
== drawing
->damage_end
)
1464 drawing
->damage_end
= x
;
1466 drawing
->damage_end
=
1467 control_flow_data
->drawing
->width
;
1469 drawing
->damage_begin
= 0;
1471 rectangle_pixmap (process_list
,
1472 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1474 drawing
->damage_begin
, 0,
1475 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1478 gtk_widget_queue_draw(drawing
->drawing_area
);
1479 //gtk_widget_queue_draw_area (drawing->drawing_area,
1481 // control_flow_data->drawing->width,
1482 // control_flow_data->drawing->height);
1485 /* Get new data for the rest. */
1486 drawing_data_request(control_flow_data
->drawing
,
1487 drawing
->damage_begin
, 0,
1488 drawing
->damage_end
- drawing
->damage_begin
,
1489 control_flow_data
->drawing
->height
);
1492 if(ltt_time_compare(*ns
,*os
) == 0)
1494 g_info("not scrolling");
1496 g_info("scrolling far");
1497 /* Cannot reuse any part of the screen : far jump */
1500 rectangle_pixmap (process_list
,
1501 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1504 control_flow_data
->drawing
->width
+SAFETY
, // do not overlap
1507 //gtk_widget_queue_draw_area (drawing->drawing_area,
1509 // control_flow_data->drawing->width,
1510 // control_flow_data->drawing->height);
1511 gtk_widget_queue_draw(drawing
->drawing_area
);
1513 drawing
->damage_begin
= 0;
1514 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1516 drawing_data_request(control_flow_data
->drawing
,
1518 control_flow_data
->drawing
->width
,
1519 control_flow_data
->drawing
->height
);
1525 /* Different scale (zoom) */
1528 rectangle_pixmap (process_list
,
1529 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1532 control_flow_data
->drawing
->width
+SAFETY
, // do not overlap
1535 //gtk_widget_queue_draw_area (drawing->drawing_area,
1537 // control_flow_data->drawing->width,
1538 // control_flow_data->drawing->height);
1539 gtk_widget_queue_draw(drawing
->drawing_area
);
1541 drawing
->damage_begin
= 0;
1542 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1544 drawing_data_request(control_flow_data
->drawing
,
1546 control_flow_data
->drawing
->width
,
1547 control_flow_data
->drawing
->height
);
1550 /* Update directly when scrolling */
1551 gdk_window_process_updates(control_flow_data
->drawing
->drawing_area
->window
,
1557 gint
traceset_notify(void *hook_data
, void *call_data
)
1559 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1560 Drawing_t
*drawing
= control_flow_data
->drawing
;
1562 if(unlikely(drawing
->gc
== NULL
)) {
1565 if(drawing
->dotted_gc
== NULL
) {
1569 drawing_clear(control_flow_data
->drawing
);
1570 processlist_clear(control_flow_data
->process_list
);
1571 gtk_widget_set_size_request(
1572 control_flow_data
->drawing
->drawing_area
,
1573 -1, processlist_get_height(control_flow_data
->process_list
));
1574 redraw_notify(control_flow_data
, NULL
);
1576 request_background_data(control_flow_data
);
1581 gint
redraw_notify(void *hook_data
, void *call_data
)
1583 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1584 Drawing_t
*drawing
= control_flow_data
->drawing
;
1585 GtkWidget
*widget
= drawing
->drawing_area
;
1587 drawing
->damage_begin
= 0;
1588 drawing
->damage_end
= drawing
->width
;
1590 /* fun feature, to be separated someday... */
1591 drawing_clear(control_flow_data
->drawing
);
1592 processlist_clear(control_flow_data
->process_list
);
1593 gtk_widget_set_size_request(
1594 control_flow_data
->drawing
->drawing_area
,
1595 -1, processlist_get_height(control_flow_data
->process_list
));
1597 rectangle_pixmap (control_flow_data
->process_list
,
1598 widget
->style
->black_gc
,
1601 drawing
->alloc_width
,
1604 gtk_widget_queue_draw(drawing
->drawing_area
);
1606 if(drawing
->damage_begin
< drawing
->damage_end
)
1608 drawing_data_request(drawing
,
1609 drawing
->damage_begin
,
1611 drawing
->damage_end
-drawing
->damage_begin
,
1615 //gtk_widget_queue_draw_area(drawing->drawing_area,
1618 // drawing->height);
1624 gint
continue_notify(void *hook_data
, void *call_data
)
1626 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1627 Drawing_t
*drawing
= control_flow_data
->drawing
;
1629 //g_assert(widget->allocation.width == drawing->damage_end);
1631 if(drawing
->damage_begin
< drawing
->damage_end
)
1633 drawing_data_request(drawing
,
1634 drawing
->damage_begin
,
1636 drawing
->damage_end
-drawing
->damage_begin
,
1644 gint
update_current_time_hook(void *hook_data
, void *call_data
)
1646 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
1647 Drawing_t
*drawing
= control_flow_data
->drawing
;
1649 LttTime current_time
= *((LttTime
*)call_data
);
1651 TimeWindow time_window
=
1652 lttvwindow_get_time_window(control_flow_data
->tab
);
1654 LttTime time_begin
= time_window
.start_time
;
1655 LttTime width
= time_window
.time_width
;
1658 guint64 time_ll
= ltt_time_to_uint64(width
);
1659 time_ll
= time_ll
>> 1; /* divide by two */
1660 half_width
= ltt_time_from_uint64(time_ll
);
1662 LttTime time_end
= ltt_time_add(time_begin
, width
);
1664 LttvTracesetContext
* tsc
=
1665 lttvwindow_get_traceset_context(control_flow_data
->tab
);
1667 LttTime trace_start
= tsc
->time_span
.start_time
;
1668 LttTime trace_end
= tsc
->time_span
.end_time
;
1670 g_info("New current time HOOK : %lu, %lu", current_time
.tv_sec
,
1671 current_time
.tv_nsec
);
1675 /* If current time is inside time interval, just move the highlight
1678 /* Else, we have to change the time interval. We have to tell it
1679 * to the main window. */
1680 /* The time interval change will take care of placing the current
1681 * time at the center of the visible area, or nearest possible if we are
1682 * at one end of the trace. */
1685 if(ltt_time_compare(current_time
, time_begin
) < 0)
1687 TimeWindow new_time_window
;
1689 if(ltt_time_compare(current_time
,
1690 ltt_time_add(trace_start
,half_width
)) < 0)
1691 time_begin
= trace_start
;
1693 time_begin
= ltt_time_sub(current_time
,half_width
);
1695 new_time_window
.start_time
= time_begin
;
1696 new_time_window
.time_width
= width
;
1697 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1698 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1700 lttvwindow_report_time_window(control_flow_data
->tab
, new_time_window
);
1702 else if(ltt_time_compare(current_time
, time_end
) > 0)
1704 TimeWindow new_time_window
;
1706 if(ltt_time_compare(current_time
, ltt_time_sub(trace_end
, half_width
)) > 0)
1707 time_begin
= ltt_time_sub(trace_end
,width
);
1709 time_begin
= ltt_time_sub(current_time
,half_width
);
1711 new_time_window
.start_time
= time_begin
;
1712 new_time_window
.time_width
= width
;
1713 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1714 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1716 lttvwindow_report_time_window(control_flow_data
->tab
, new_time_window
);
1719 gtk_widget_queue_draw(control_flow_data
->drawing
->drawing_area
);
1721 /* Update directly when scrolling */
1722 gdk_window_process_updates(control_flow_data
->drawing
->drawing_area
->window
,
1728 typedef struct _ClosureData
{
1729 EventsRequest
*events_request
;
1730 LttvTracesetState
*tss
;
1735 /* Draw line until end of the screen */
1737 void draw_closure(gpointer key
, gpointer value
, gpointer user_data
)
1739 ResourceInfo
*process_info
= (ResourceInfo
*)key
;
1740 HashedResourceData
*hashed_process_data
= (HashedResourceData
*)value
;
1741 ClosureData
*closure_data
= (ClosureData
*)user_data
;
1743 EventsRequest
*events_request
= closure_data
->events_request
;
1744 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1746 LttvTracesetState
*tss
= closure_data
->tss
;
1747 LttvTracesetContext
*tsc
= (LttvTracesetContext
*)tss
;
1749 LttTime evtime
= closure_data
->end_time
;
1751 gboolean dodraw
= TRUE
;
1754 /* For the process */
1755 /* First, check if the current process is in the state computation
1756 * process list. If it is there, that means we must add it right now and
1757 * draw items from the beginning of the read for it. If it is not
1758 * present, it's a new process and it was not present : it will
1759 * be added after the state update. */
1761 g_assert(lttv_traceset_number(tsc
->ts
) > 0);
1762 #endif //EXTRA_CHECK
1763 LttvTraceContext
*tc
= tsc
->traces
[process_info
->trace_num
];
1764 LttvTraceState
*ts
= (LttvTraceState
*)tc
;
1767 //FIXME : optimize data structures.
1768 LttvTracefileState
*tfs
;
1769 LttvTracefileContext
*tfc
;
1771 for(i
=0;i
<tc
->tracefiles
->len
;i
++) {
1772 tfc
= g_array_index(tc
->tracefiles
, LttvTracefileContext
*, i
);
1773 if(ltt_tracefile_name(tfc
->tf
) == LTT_NAME_CPU
1774 && tfs
->cpu
== process_info
->cpu
)
1778 g_assert(i
<tc
->tracefiles
->len
);
1779 tfs
= LTTV_TRACEFILE_STATE(tfc
);
1781 // LttvTracefileState *tfs =
1782 // (LttvTracefileState*)tsc->traces[process_info->trace_num]->
1783 // tracefiles[process_info->cpu];
1785 // LttvProcessState *process;
1786 // process = lttv_state_find_process(ts, process_info->cpu,
1787 // process_info->pid);
1789 // if(unlikely(process != NULL)) {
1791 // LttvFilter *filter = control_flow_data->filter;
1792 // if(filter != NULL && filter->head != NULL)
1793 // if(!lttv_filter_tree_parse(filter->head,NULL,NULL,
1794 // tc->t,NULL,process,tc))
1797 /* Only draw for processes that are currently in the trace states */
1799 ProcessList
*process_list
= control_flow_data
->process_list
;
1801 /* Should be alike when background info is ready */
1802 if(control_flow_data
->background_info_waiting
==0)
1803 g_assert(ltt_time_compare(process
->creation_time
,
1804 process_info
->birth
) == 0);
1805 #endif //EXTRA_CHECK
1807 /* Now, the process is in the state hash and our own process hash.
1808 * We definitely can draw the items related to the ending state.
1811 if(unlikely(ltt_time_compare(hashed_process_data
->next_good_time
,
1814 TimeWindow time_window
=
1815 lttvwindow_get_time_window(control_flow_data
->tab
);
1818 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1819 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1821 #endif //EXTRA_CHECK
1822 Drawing_t
*drawing
= control_flow_data
->drawing
;
1823 guint width
= drawing
->width
;
1825 guint x
= closure_data
->x_end
;
1827 DrawContext draw_context
;
1829 /* Now create the drawing context that will be used to draw
1830 * items related to the last state. */
1831 draw_context
.drawable
= hashed_process_data
->pixmap
;
1832 draw_context
.gc
= drawing
->gc
;
1833 draw_context
.pango_layout
= drawing
->pango_layout
;
1834 draw_context
.drawinfo
.end
.x
= x
;
1836 draw_context
.drawinfo
.y
.over
= 1;
1837 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
1838 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
1840 draw_context
.drawinfo
.start
.offset
.over
= 0;
1841 draw_context
.drawinfo
.start
.offset
.middle
= 0;
1842 draw_context
.drawinfo
.start
.offset
.under
= 0;
1843 draw_context
.drawinfo
.end
.offset
.over
= 0;
1844 draw_context
.drawinfo
.end
.offset
.middle
= 0;
1845 draw_context
.drawinfo
.end
.offset
.under
= 0;
1847 /* Jump over draw if we are at the same x position */
1848 if(x
== hashed_process_data
->x
.over
)
1852 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.over
;
1854 PropertiesLine prop_line
= prepare_execmode_line(process
);
1855 draw_line((void*)&prop_line
, (void*)&draw_context
);
1857 hashed_process_data
->x
.over
= x
;
1861 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1862 hashed_process_data
->x
.middle_used
)) {
1863 #if 0 /* do not mark closure : not missing information */
1864 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
1865 /* Draw collision indicator */
1866 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1867 gdk_draw_point(drawing
->pixmap
,
1871 hashed_process_data
->x
.middle_marked
= TRUE
;
1876 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1879 PropertiesLine prop_line
;
1880 prop_line
.line_width
= STATE_LINE_WIDTH
;
1881 prop_line
.style
= GDK_LINE_SOLID
;
1882 prop_line
.y
= MIDDLE
;
1883 if(process_info
->type
== 0)
1884 cpu_set_line_color(&prop_line
, &ts
->cpu_states
[process_info
->id
]);
1885 else if(process_info
->type
== 1)
1886 irq_set_line_color(&prop_line
, &ts
->irq_states
[process_info
->id
]);
1888 draw_line((void*)&prop_line
, (void*)&draw_context
);
1891 /* become the last x position */
1892 if(likely(x
!= hashed_process_data
->x
.middle
)) {
1893 hashed_process_data
->x
.middle
= x
;
1894 /* but don't use the pixel */
1895 hashed_process_data
->x
.middle_used
= FALSE
;
1897 /* Calculate the next good time */
1898 convert_pixels_to_time(width
, x
+1, time_window
,
1899 &hashed_process_data
->next_good_time
);
1908 int before_chunk(void *hook_data
, void *call_data
)
1910 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1911 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1912 ControlFlowData
*cfd
= (ControlFlowData
*)events_request
->viewer_data
;
1914 /* Desactivate sort */
1915 gtk_tree_sortable_set_sort_column_id(
1916 GTK_TREE_SORTABLE(cfd
->process_list
->list_store
),
1918 GTK_SORT_ASCENDING
);
1920 drawing_chunk_begin(events_request
, tss
);
1925 int before_request(void *hook_data
, void *call_data
)
1927 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1928 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1930 drawing_data_request_begin(events_request
, tss
);
1937 * after request is necessary in addition of after chunk in order to draw
1938 * lines until the end of the screen. after chunk just draws lines until
1945 // TODO pmf: reenable this
1946 int after_request(void *hook_data
, void *call_data
)
1948 // EventsRequest *events_request = (EventsRequest*)hook_data;
1949 // ControlFlowData *control_flow_data = events_request->viewer_data;
1950 // LttvTracesetState *tss = (LttvTracesetState*)call_data;
1952 // ProcessList *process_list = control_flow_data->process_list;
1953 // LttTime end_time = events_request->end_time;
1955 // ClosureData closure_data;
1956 // closure_data.events_request = (EventsRequest*)hook_data;
1957 // closure_data.tss = tss;
1958 // closure_data.end_time = end_time;
1960 // TimeWindow time_window =
1961 // lttvwindow_get_time_window(control_flow_data->tab);
1962 // guint width = control_flow_data->drawing->width;
1963 // convert_time_to_pixels(
1967 // &closure_data.x_end);
1970 // /* Draw last items */
1971 // g_hash_table_foreach(process_list->process_hash, draw_closure,
1972 // (void*)&closure_data);
1975 // /* Request expose */
1976 // drawing_request_expose(events_request, tss, end_time);
1985 int after_chunk(void *hook_data
, void *call_data
)
1987 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1988 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1989 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1990 LttvTracesetContext
*tsc
= (LttvTracesetContext
*)call_data
;
1991 LttvTracefileContext
*tfc
= lttv_traceset_context_get_current_tfc(tsc
);
1994 ProcessList
*process_list
= control_flow_data
->process_list
;
1996 LttvTraceset
*traceset
= tsc
->ts
;
1997 guint nb_trace
= lttv_traceset_number(traceset
);
1999 /* Only execute when called for the first trace's events request */
2000 if(!process_list
->current_hash_data
) return;
2002 for(i
= 0 ; i
< nb_trace
; i
++) {
2003 g_free(process_list
->current_hash_data
[i
]);
2005 g_free(process_list
->current_hash_data
);
2006 process_list
->current_hash_data
= NULL
;
2009 end_time
= LTT_TIME_MIN(tfc
->timestamp
, events_request
->end_time
);
2010 else /* end of traceset, or position now out of request : end */
2011 end_time
= events_request
->end_time
;
2013 ClosureData closure_data
;
2014 closure_data
.events_request
= (EventsRequest
*)hook_data
;
2015 closure_data
.tss
= tss
;
2016 closure_data
.end_time
= end_time
;
2018 TimeWindow time_window
=
2019 lttvwindow_get_time_window(control_flow_data
->tab
);
2020 guint width
= control_flow_data
->drawing
->width
;
2021 convert_time_to_pixels(
2025 &closure_data
.x_end
);
2027 /* Draw last items */
2028 g_hash_table_foreach(process_list
->process_hash
, draw_closure
,
2029 (void*)&closure_data
);
2031 /* Reactivate sort */
2032 gtk_tree_sortable_set_sort_column_id(
2033 GTK_TREE_SORTABLE(control_flow_data
->process_list
->list_store
),
2034 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
,
2035 GTK_SORT_ASCENDING
);
2037 update_index_to_pixmap(control_flow_data
->process_list
);
2038 /* Request a full expose : drawing scrambled */
2039 gtk_widget_queue_draw(control_flow_data
->drawing
->drawing_area
);
2041 /* Request expose (updates damages zone also) */
2042 drawing_request_expose(events_request
, tss
, end_time
);
2047 /* after_statedump_end
2049 * @param hook_data ControlFlowData structure of the viewer.
2050 * @param call_data Event context.
2052 * This function adds items to be drawn in a queue for each process.
2055 int before_statedump_end(void *hook_data
, void *call_data
)
2057 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
2058 EventsRequest
*events_request
= (EventsRequest
*)thf
->hook_data
;
2059 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
2061 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
2063 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
2065 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
2067 LttvTracesetState
*tss
= (LttvTracesetState
*)tfc
->t_context
->ts_context
;
2068 ProcessList
*process_list
= control_flow_data
->process_list
;
2071 e
= ltt_tracefile_get_event(tfc
->tf
);
2073 LttvFilter
*filter
= control_flow_data
->filter
;
2074 if(filter
!= NULL
&& filter
->head
!= NULL
)
2075 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
2076 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
2079 LttTime evtime
= ltt_event_time(e
);
2081 ClosureData closure_data
;
2082 closure_data
.events_request
= events_request
;
2083 closure_data
.tss
= tss
;
2084 closure_data
.end_time
= evtime
;
2086 TimeWindow time_window
=
2087 lttvwindow_get_time_window(control_flow_data
->tab
);
2088 guint width
= control_flow_data
->drawing
->width
;
2089 convert_time_to_pixels(
2093 &closure_data
.x_end
);
2095 /* Draw last items */
2096 g_hash_table_foreach(process_list
->process_hash
, draw_closure
,
2097 (void*)&closure_data
);
2099 /* Reactivate sort */
2100 gtk_tree_sortable_set_sort_column_id(
2101 GTK_TREE_SORTABLE(control_flow_data
->process_list
->list_store
),
2102 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
,
2103 GTK_SORT_ASCENDING
);
2105 update_index_to_pixmap(control_flow_data
->process_list
);
2106 /* Request a full expose : drawing scrambled */
2107 gtk_widget_queue_draw(control_flow_data
->drawing
->drawing_area
);
2109 /* Request expose (updates damages zone also) */
2110 drawing_request_expose(events_request
, tss
, evtime
);