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 <lttv/lttv.h>
63 #include <lttv/hook.h>
64 #include <lttv/state.h>
65 #include <lttvwindow/lttvwindow.h>
66 #include <lttvwindow/lttvwindowtraces.h>
67 #include <lttvwindow/support.h>
70 #include "eventhooks.h"
72 #include "processlist.h"
76 #define MAX_PATH_LEN 256
77 #define STATE_LINE_WIDTH 8
78 #define COLLISION_POSITION(height) (((height - STATE_LINE_WIDTH)/2) -3)
80 extern GSList
*g_legend_list
;
83 /* Action to do when background computation completed.
85 * Wait for all the awaited computations to be over.
88 static gint
background_ready(void *hook_data
, void *call_data
)
90 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
92 control_flow_data
->background_info_waiting
--;
94 if(control_flow_data
->background_info_waiting
== 0) {
95 g_message("control flow viewer : background computation data ready.");
97 drawing_clear(control_flow_data
->drawing
);
98 processlist_clear(control_flow_data
->process_list
);
99 gtk_widget_set_size_request(
100 control_flow_data
->drawing
->drawing_area
,
101 -1, processlist_get_height(control_flow_data
->process_list
));
102 redraw_notify(control_flow_data
, NULL
);
109 /* Request background computation. Verify if it is in progress or ready first.
110 * Only for each trace in the tab's traceset.
113 static void request_background_data(ControlFlowData
*control_flow_data
)
116 LttvTraceset
*ts
= lttvwindow_get_traceset(control_flow_data
->tab
);
117 gint num_traces
= lttv_traceset_number(ts
);
121 LttvHooks
*background_ready_hook
= lttv_hooks_new();
122 lttv_hooks_add(background_ready_hook
, background_ready
, control_flow_data
,
124 control_flow_data
->background_info_waiting
= 0;
126 for(i
=0;i
<num_traces
;i
++) {
127 trace
= lttv_traceset_get(ts
, i
);
129 if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace
)==FALSE
130 && !ts
->has_precomputed_states
) {
132 if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"),
134 /* We first remove requests that could have been done for the same
135 * information. Happens when two viewers ask for it before servicing
138 if(!lttvwindowtraces_background_request_find(trace
, "state"))
139 lttvwindowtraces_background_request_queue(
140 main_window_get_widget(control_flow_data
->tab
), trace
, "state");
141 lttvwindowtraces_background_notify_queue(control_flow_data
,
145 background_ready_hook
);
146 control_flow_data
->background_info_waiting
++;
147 } else { /* in progress */
149 lttvwindowtraces_background_notify_current(control_flow_data
,
153 background_ready_hook
);
154 control_flow_data
->background_info_waiting
++;
157 /* Data ready. By its nature, this viewer doesn't need to have
158 * its data ready hook called there, because a background
159 * request is always linked with a redraw.
165 lttv_hooks_destroy(background_ready_hook
);
172 * Event Viewer's constructor hook
174 * This constructor is given as a parameter to the menuitem and toolbar button
175 * registration. It creates the list.
176 * @param tab A pointer to the parent tab.
177 * @return The widget created.
180 h_guicontrolflow(LttvPlugin
*plugin
)
182 LttvPluginTab
*ptab
= LTTV_PLUGIN_TAB(plugin
);
183 Tab
*tab
= ptab
->tab
;
184 g_info("h_guicontrolflow, %p", tab
);
185 ControlFlowData
*control_flow_data
= guicontrolflow(ptab
);
187 control_flow_data
->tab
= tab
;
189 // Unreg done in the GuiControlFlow_Destructor
190 lttvwindow_register_traceset_notify(tab
,
194 lttvwindow_register_time_window_notify(tab
,
195 update_time_window_hook
,
197 lttvwindow_register_current_time_notify(tab
,
198 update_current_time_hook
,
200 lttvwindow_register_redraw_notify(tab
,
203 lttvwindow_register_continue_notify(tab
,
206 request_background_data(control_flow_data
);
209 return guicontrolflow_get_widget(control_flow_data
) ;
213 int event_selected_hook(void *hook_data
, void *call_data
)
215 guint
*event_number
= (guint
*) call_data
;
217 g_debug("DEBUG : event selected by main window : %u", *event_number
);
222 /* Function that selects the color of status&exemode line */
223 static inline PropertiesLine
prepare_s_e_line(LttvProcessState
*process
)
225 PropertiesLine prop_line
;
226 prop_line
.line_width
= STATE_LINE_WIDTH
;
227 prop_line
.style
= GDK_LINE_SOLID
;
228 prop_line
.y
= MIDDLE
;
229 //GdkColormap *colormap = gdk_colormap_get_system();
231 if(process
->state
->s
== LTTV_STATE_RUN
) {
232 if(process
->state
->t
== LTTV_STATE_USER_MODE
)
233 prop_line
.color
= drawing_colors
[COL_RUN_USER_MODE
];
234 else if(process
->state
->t
== LTTV_STATE_SYSCALL
)
235 prop_line
.color
= drawing_colors
[COL_RUN_SYSCALL
];
236 else if(process
->state
->t
== LTTV_STATE_TRAP
)
237 prop_line
.color
= drawing_colors
[COL_RUN_TRAP
];
238 else if(process
->state
->t
== LTTV_STATE_IRQ
)
239 prop_line
.color
= drawing_colors
[COL_RUN_IRQ
];
240 else if(process
->state
->t
== LTTV_STATE_SOFT_IRQ
)
241 prop_line
.color
= drawing_colors
[COL_RUN_SOFT_IRQ
];
242 else if(process
->state
->t
== LTTV_STATE_MAYBE_SYSCALL
)
243 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
244 else if(process
->state
->t
== LTTV_STATE_MAYBE_USER_MODE
)
245 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
246 else if(process
->state
->t
== LTTV_STATE_MAYBE_TRAP
)
247 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
248 else if(process
->state
->t
== LTTV_STATE_MODE_UNKNOWN
)
249 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
251 g_assert(FALSE
); /* RUNNING MODE UNKNOWN */
252 } else if(process
->state
->s
== LTTV_STATE_WAIT
) {
253 /* We don't show if we wait while in user mode, trap, irq or syscall */
254 prop_line
.color
= drawing_colors
[COL_WAIT
];
255 } else if(process
->state
->s
== LTTV_STATE_WAIT_CPU
) {
256 /* We don't show if we wait for CPU while in user mode, trap, irq
258 prop_line
.color
= drawing_colors
[COL_WAIT_CPU
];
259 } else if(process
->state
->s
== LTTV_STATE_ZOMBIE
) {
260 prop_line
.color
= drawing_colors
[COL_ZOMBIE
];
261 } else if(process
->state
->s
== LTTV_STATE_WAIT_FORK
) {
262 prop_line
.color
= drawing_colors
[COL_WAIT_FORK
];
263 } else if(process
->state
->s
== LTTV_STATE_EXIT
) {
264 prop_line
.color
= drawing_colors
[COL_EXIT
];
265 } else if(process
->state
->s
== LTTV_STATE_UNNAMED
) {
266 prop_line
.color
= drawing_colors
[COL_UNNAMED
];
267 } else if(process
->state
->s
== LTTV_STATE_DEAD
) {
268 prop_line
.color
= drawing_colors
[COL_DEAD
];
270 g_critical("unknown state : %s", g_quark_to_string(process
->state
->s
));
271 g_assert(FALSE
); /* UNKNOWN STATE */
278 HashedProcessData
*get_hashed_process_data(ControlFlowData
*control_flow_data
,
279 LttvProcessState
*process
,
283 HashedProcessData
*hashed_process_data
= NULL
;
284 ProcessList
*process_list
= control_flow_data
->process_list
;
285 LttTime birth
= process
->creation_time
;
288 hashed_process_data
= processlist_get_process_data(process_list
,
293 if(hashed_process_data
== NULL
)
295 g_assert(pid
== 0 || pid
!= process
->ppid
);
296 ProcessInfo
*process_info
;
297 Drawing_t
*drawing
= control_flow_data
->drawing
;
298 /* Process not present */
299 processlist_add(process_list
,
310 &hashed_process_data
);
311 gtk_widget_set_size_request(drawing
->drawing_area
,
314 gtk_widget_queue_draw(drawing
->drawing_area
);
316 return hashed_process_data
;
319 void init_drawing_context(DrawContext
*draw_context
,
320 HashedProcessData
*hashed_process_data
,
325 draw_context
->drawable
= hashed_process_data
->pixmap
;
326 draw_context
->gc
= drawing
->gc
;
327 draw_context
->pango_layout
= drawing
->pango_layout
;
328 draw_context
->drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
329 draw_context
->drawinfo
.end
.x
= x
;
331 draw_context
->drawinfo
.y
.over
= 1;
332 draw_context
->drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
333 draw_context
->drawinfo
.y
.under
= hashed_process_data
->height
;
335 draw_context
->drawinfo
.start
.offset
.over
= 0;
336 draw_context
->drawinfo
.start
.offset
.middle
= 0;
337 draw_context
->drawinfo
.start
.offset
.under
= 0;
338 draw_context
->drawinfo
.end
.offset
.over
= 0;
339 draw_context
->drawinfo
.end
.offset
.middle
= 0;
340 draw_context
->drawinfo
.end
.offset
.under
= 0;
344 void draw_state_line(HashedProcessData
*hashed_process_data
,
345 LttvProcessState
*process
,
348 TimeWindow time_window
)
350 DrawContext draw_context
;
351 guint width
= drawing
->width
;
353 init_drawing_context(&draw_context
,
360 PropertiesLine prop_line
= prepare_s_e_line(process
);
361 draw_line((void*)&prop_line
, (void*)&draw_context
);
363 /* become the last x position */
364 hashed_process_data
->x
.middle
= x
;
365 hashed_process_data
->x
.middle_used
= TRUE
;
366 hashed_process_data
->x
.middle_marked
= FALSE
;
368 /* Calculate the next good time */
369 convert_pixels_to_time(width
, x
+1, time_window
,
370 &hashed_process_data
->next_good_time
);
374 void draw_state_items(ControlFlowData
*control_flow_data
,
375 HashedProcessData
*hashed_process_data
,
376 LttvProcessState
*process
,
381 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
384 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
385 TimeWindow time_window
=
386 lttvwindow_get_time_window(control_flow_data
->tab
);
389 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
390 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
393 Drawing_t
*drawing
= control_flow_data
->drawing
;
394 guint width
= drawing
->width
;
396 convert_time_to_pixels(
402 /* Draw collision indicator */
403 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
404 gdk_draw_point(hashed_process_data
->pixmap
,
407 COLLISION_POSITION(hashed_process_data
->height
));
408 hashed_process_data
->x
.middle_marked
= TRUE
;
411 TimeWindow time_window
=
412 lttvwindow_get_time_window(control_flow_data
->tab
);
415 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
416 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
419 Drawing_t
*drawing
= control_flow_data
->drawing
;
420 guint width
= drawing
->width
;
423 convert_time_to_pixels(
430 /* Jump over draw if we are at the same x position */
431 if(unlikely(x
== hashed_process_data
->x
.middle
&&
432 hashed_process_data
->x
.middle_used
))
434 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
435 /* Draw collision indicator */
436 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
437 gdk_draw_point(hashed_process_data
->pixmap
,
440 COLLISION_POSITION(hashed_process_data
->height
));
441 hashed_process_data
->x
.middle_marked
= TRUE
;
446 draw_state_line(hashed_process_data
,
456 /* Before try-wake-up hook. A process is being woken; we need to draw its line up to this point in time
457 in that colour. This is basically like exec-state, but the change applies to a process other than that
458 which is currently running. */
460 int before_trywakeup_hook(void *hook_data
, void *call_data
)
465 event
= (LttvEvent
*) call_data
;
466 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_wakeup") != 0)
469 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
471 LttvTraceState
*ts
= event
->state
;;
474 LttTime evtime
= lttv_event_get_timestamp(event
);
476 LttvFilter
*filter
= control_flow_data
->filter
;
482 woken_pid
= lttv_event_get_long(event
, "tid");
483 woken_cpu
= lttv_event_get_long(event
, "target_cpu");
486 if(!filter
|| !filter
->head
||
487 lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
488 tfc
->t_context
->t
,tfc
,NULL
,NULL
)) {
492 /* First, check if the woken process is in the state computation
493 * process list. If it is there, that means we must add it right now and
494 * draw items from the beginning of the read for it. If it is not
495 * present, it's a new process and it was not present : it will
496 * be added after the state update. TOCHECK: What does that last para mean? */
497 guint trace_num
= lttv_traceset_get_trace_index_from_event(event
);
498 LttvProcessState
*process
= lttv_state_find_process(ts
, woken_cpu
, woken_pid
);
500 if(process
!= NULL
) {
501 /* Well, the woken process existed : we must get it in the process hash
502 * or add it, and draw its items.
504 /* Add process to process list (if not present) */
506 HashedProcessData
*hashed_process_data
= get_hashed_process_data(control_flow_data
, process
, woken_pid
, trace_num
);
508 /* Now, the process is in the state hash and our own process hash.
509 * We definitely can draw the items related to the ending state.
512 draw_state_items(control_flow_data
,
527 /* before_schedchange_hook
529 * This function basically draw lines and icons. Two types of lines are drawn :
530 * one small (3 pixels?) representing the state of the process and the second
531 * type is thicker (10 pixels?) representing on which CPU a process is running
532 * (and this only in running state).
534 * Extremums of the lines :
535 * x_min : time of the last event context for this process kept in memory.
536 * x_max : time of the current event.
537 * y : middle of the process in the process list. The process is found in the
538 * list, therefore is it's position in pixels.
540 * The choice of lines'color is defined by the context of the last event for this
545 int before_schedchange_hook(void *hook_data
, void *call_data
)
550 LttvProcessState
*process
;
552 //LttvProcessState *old_process = ts->running_process[cpu];
554 guint pid_in
, pid_out
;
556 event
= (LttvEvent
*) call_data
;
557 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_switch") != 0)
560 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
563 /* we are in a schedchange, before the state update. We must draw the
564 * items corresponding to the state before it changes : now is the right
567 cpu
= lttv_traceset_get_cpuid_from_event(event
);
570 pid_out
= lttv_event_get_long(event
, "prev_tid");
571 pid_in
= lttv_event_get_long(event
, "next_tid");
572 guint trace_number
= lttv_traceset_get_trace_index_from_event(event
);
574 process
= lttv_state_find_process(ts
,cpu
,pid_out
);
575 evtime
= lttv_event_get_timestamp(event
);
576 /* For the pid_out */
577 /* First, check if the current process is in the state computation
578 * process list. If it is there, that means we must add it right now and
579 * draw items from the beginning of the read for it. If it is not
580 * present, it's a new process and it was not present : it will
581 * be added after the state update. */
583 /* unknown state, bad current pid */
585 if(process
!= NULL
) {
586 /* Well, the process_out existed : we must get it in the process hash
587 * or add it, and draw its items.
589 /* Add process to process list (if not present) */
591 HashedProcessData
*hashed_process_data
= get_hashed_process_data(control_flow_data
, process
, pid_out
, trace_number
);
593 /* Now, the process is in the state hash and our own process hash.
594 * We definitely can draw the items related to the ending state.
597 draw_state_items(control_flow_data
,
604 /* First, check if the current process is in the state computation
605 * process list. If it is there, that means we must add it right now and
606 * draw items from the beginning of the read for it. If it is not
607 * present, it's a new process and it was not present : it will
608 * be added after the state update. */
609 process
= lttv_state_find_process(ts
,cpu
,pid_in
);
611 if(process
!= NULL
) {
612 /* Well, the process existed : we must get it in the process hash
613 * or add it, and draw its items.
615 /* Add process to process list (if not present) */
617 HashedProcessData
*hashed_process_data
= get_hashed_process_data(control_flow_data
, process
, pid_in
, trace_number
);
619 //We could set the current process and hash here, but will be done
620 //by after schedchange hook
622 /* Now, the process is in the state hash and our own process hash.
623 * We definitely can draw the items related to the ending state.
625 draw_state_items(control_flow_data
,
631 g_warning("Cannot find pid_in in schedchange %u at %lu.%lu", pid_in
, evtime
.tv_sec
, evtime
.tv_nsec
);
633 tfc
->target_pid
= target_pid_saved
;
634 #endif //babel_cleanup
642 GString
*string
= g_string_new("");;
643 gboolean field_names
= TRUE
, state
= TRUE
;
645 lttv_event_to_string(e
, tfc
->tf
, string
, TRUE
, field_names
, tfs
);
646 g_string_append_printf(string
,"\n");
649 g_string_append_printf(string
, " %s",
650 g_quark_to_string(tfs
->process
->state
->s
));
653 g_info("%s",string
->str
);
655 g_string_free(string
, TRUE
);
657 /* End of text dump */
662 /* after_schedchange_hook
664 * The draw after hook is called by the reading API to have a
665 * particular event drawn on the screen.
666 * @param hook_data ControlFlowData structure of the viewer.
667 * @param call_data Event context.
669 * This function adds items to be drawn in a queue for each process.
672 int after_schedchange_hook(void *hook_data
, void *call_data
)
676 event
= (LttvEvent
*) call_data
;
678 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_switch") != 0)
681 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
684 LttvTraceState
*ts
= event
->state
;
687 LttvFilter
*filter
= control_flow_data
->filter
;
689 LttTime evtime
= lttv_event_get_timestamp(event
);
691 /* Add process to process list (if not present) */
692 LttvProcessState
*process_in
;
693 HashedProcessData
*hashed_process_data_in
= NULL
;
695 ProcessList
*process_list
= control_flow_data
->process_list
;
699 pid_in
= lttv_event_get_long(event
, "next_tid");
703 if(!filter
|| !filter
->head
||
704 lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
705 tfc
->t_context
->t
,tfc
,NULL
,NULL
)) {
709 /* Find process pid_in in the list... */
710 //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in);
711 //process_in = tfs->process;
712 guint cpu
= lttv_traceset_get_cpuid_from_event(event
);
713 guint trace_num
= lttv_traceset_get_trace_index_from_event(event
);
714 process_in
= ts
->running_process
[cpu
];
715 /* It should exist, because we are after the state update. */
717 g_assert(process_in
!= NULL
);
719 hashed_process_data_in
= get_hashed_process_data(control_flow_data
, process_in
, pid_in
, trace_num
);
721 /* Set the current process */
722 process_list
->current_hash_data
[trace_num
][process_in
->cpu
] =
723 hashed_process_data_in
;
725 if(ltt_time_compare(hashed_process_data_in
->next_good_time
,
728 TimeWindow time_window
=
729 lttvwindow_get_time_window(control_flow_data
->tab
);
732 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
733 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
736 Drawing_t
*drawing
= control_flow_data
->drawing
;
737 guint width
= drawing
->width
;
740 convert_time_to_pixels(
746 if(hashed_process_data_in
->x
.middle
!= new_x
) {
747 hashed_process_data_in
->x
.middle
= new_x
;
748 hashed_process_data_in
->x
.middle_used
= FALSE
;
749 hashed_process_data_in
->x
.middle_marked
= FALSE
;
760 /* before_execmode_hook
762 * This function basically draw lines and icons. Two types of lines are drawn :
763 * one small (3 pixels?) representing the state of the process and the second
764 * type is thicker (10 pixels?) representing on which CPU a process is running
765 * (and this only in running state).
767 * Extremums of the lines :
768 * x_min : time of the last event context for this process kept in memory.
769 * x_max : time of the current event.
770 * y : middle of the process in the process list. The process is found in the
771 * list, therefore is it's position in pixels.
773 * The choice of lines'color is defined by the context of the last event for this
778 int before_execmode_hook(void *hook_data
, void *call_data
)
783 LttvProcessState
*process
;
785 /* we are in a execmode, before the state update. We must draw the
786 * items corresponding to the state before it changes : now is the right
790 event
= (LttvEvent
*) call_data
;
791 if ((strncmp(lttv_traceset_get_name_from_event(event
),"sys_", sizeof("sys_") - 1) == 0)
792 ||(strcmp(lttv_traceset_get_name_from_event(event
),"exit_syscall") == 0)
793 ||(strncmp(lttv_traceset_get_name_from_event(event
),"irq_handler_",sizeof("irq_handler_") -1) == 0)
794 ||(strncmp(lttv_traceset_get_name_from_event(event
),"softirq_", sizeof("softirq_") - 1) == 0)) {
796 LttTime evtime
= lttv_event_get_timestamp(event
);
797 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
800 cpu
= lttv_traceset_get_cpuid_from_event(event
);
803 guint trace_number
= lttv_traceset_get_trace_index_from_event(event
);
805 //TODO ybrosseau 2013-04-09 validate that using the running process is the right choice
806 //process = lttv_state_find_process(ts ,cpu ,pid);
807 process
= ts
->running_process
[cpu
];
809 g_assert(process
!= NULL
);
811 guint pid
= process
->pid
;
813 /* Well, the process_out existed : we must get it in the process hash
814 * or add it, and draw its items.
816 /* Add process to process list (if not present) */
817 HashedProcessData
*hashed_process_data
= NULL
;
818 ProcessList
*process_list
= control_flow_data
->process_list
;
819 if(process_list
->current_hash_data
== NULL
){//TODO fdeslauriers 2012-07-17 : should not be necessary
823 if(likely(process_list
->current_hash_data
[trace_number
][cpu
] != NULL
)) {
824 hashed_process_data
= process_list
->current_hash_data
[trace_number
][cpu
];
826 hashed_process_data
= get_hashed_process_data(control_flow_data
,
827 process
, pid
, trace_number
);
829 /* Set the current process */
830 process_list
->current_hash_data
[trace_number
][process
->cpu
] =
834 /* Now, the process is in the state hash and our own process hash.
835 * We definitely can draw the items related to the ending state.
838 draw_state_items(control_flow_data
,
848 /* before_process_exit_hook
850 * Draw lines for process event.
852 * @param hook_data ControlFlowData structure of the viewer.
853 * @param call_data Event context.
855 * This function adds items to be drawn in a queue for each process.
860 int before_process_exit_hook(void *hook_data
, void *call_data
)
865 event
= (LttvEvent
*) call_data
;
866 if (strcmp(lttv_traceset_get_name_from_event(event
),
867 "sched_process_exit") != 0)
871 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
872 LttvTraceState
*ts
= event
->state
;
875 LttvFilter
*filter
= control_flow_data
->filter
;
876 if(filter
!= NULL
&& filter
->head
!= NULL
)
877 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
878 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
882 LttTime evtime
= lttv_event_get_timestamp(event
);
884 /* Add process to process list (if not present) */
885 //LttvProcessState *process = tfs->process;
886 guint cpu
= lttv_traceset_get_cpuid_from_event(event
);
887 guint trace_num
= lttv_traceset_get_trace_index_from_event(event
);
889 LttvProcessState
*process
= ts
->running_process
[cpu
];
890 guint pid
= process
->pid
;
891 HashedProcessData
*hashed_process_data
= NULL
;
893 ProcessList
*process_list
= control_flow_data
->process_list
;
895 g_assert(process
!= NULL
);
897 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
)) {
898 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
900 hashed_process_data
= get_hashed_process_data(control_flow_data
,
901 process
, pid
, trace_num
);
904 /* Now, the process is in the state hash and our own process hash.
905 * We definitely can draw the items related to the ending state.
908 draw_state_items(control_flow_data
,
919 /* before_process_release_hook
921 * Draw lines for process event.
923 * @param hook_data ControlFlowData structure of the viewer.
924 * @param call_data Event context.
926 * This function adds items to be drawn in a queue for each process.
931 int before_process_release_hook(void *hook_data
, void *call_data
)
936 event
= (LttvEvent
*) call_data
;
938 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_process_free") != 0)
941 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
944 LttvTraceState
*ts
= event
->state
;
947 LttvFilter
*filter
= control_flow_data
->filter
;
948 if(filter
!= NULL
&& filter
->head
!= NULL
)
949 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
950 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
953 LttTime evtime
= lttv_event_get_timestamp(event
);
956 guint trace_num
= lttv_traceset_get_trace_index_from_event(event
);
960 pid
= lttv_event_get_long(event
, "tid");
963 /* Add process to process list (if not present) */
964 /* Don't care about the process if it's not in the state hash already :
965 * that means a process that has never done anything in the trace and
966 * unknown suddently gets destroyed : no state meaningful to show. */
967 LttvProcessState
*process
= lttv_state_find_process(ts
, ANY_CPU
, pid
);
969 if(process
!= NULL
) {
971 HashedProcessData
*hashed_process_data
= NULL
;
973 ProcessList
*process_list
= control_flow_data
->process_list
;
975 birth
= process
->creation_time
;
977 /* Cannot use current process : this event happens on another process,
978 * action done by the parent. */
979 hashed_process_data
= processlist_get_process_data(process_list
,
984 if(unlikely(hashed_process_data
== NULL
))
986 * Process already been scheduled out EXIT_DEAD, not in the process list
987 * anymore. Just return.
991 /* Now, the process is in the state hash and our own process hash.
992 * We definitely can draw the items related to the ending state.
995 draw_state_items(control_flow_data
,
1007 /* after_process_fork_hook
1009 * Create the processlist entry for the child process. Put the last
1010 * position in x at the current time value.
1012 * @param hook_data ControlFlowData structure of the viewer.
1013 * @param call_data Event context.
1015 * This function adds items to be drawn in a queue for each process.
1018 int after_process_fork_hook(void *hook_data
, void *call_data
)
1022 event
= (LttvEvent
*) call_data
;
1024 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_process_fork") != 0)
1027 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1030 LttvTraceState
*ts
= event
->state
;
1032 #ifdef BABEL_CLEANUP
1033 LttvFilter
*filter
= control_flow_data
->filter
;
1034 if(filter
!= NULL
&& filter
->head
!= NULL
)
1035 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1036 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1040 LttTime evtime
= lttv_event_get_timestamp(event
);
1044 child_pid
= lttv_event_get_long(event
, "child_tid");
1047 /* Add process to process list (if not present) */
1048 LttvProcessState
*process_child
;
1049 HashedProcessData
*hashed_process_data_child
= NULL
;
1051 ProcessList
*process_list
= control_flow_data
->process_list
;
1053 /* Find child in the list... */
1054 process_child
= lttv_state_find_process(ts
, ANY_CPU
, child_pid
);
1055 /* It should exist, because we are after the state update. */
1056 g_assert(process_child
!= NULL
);
1058 guint trace_num
= lttv_traceset_get_trace_index_from_event(event
);
1060 /* Cannot use current process, because this action is done by the parent
1062 hashed_process_data_child
= get_hashed_process_data(control_flow_data
,
1063 process_child
, child_pid
, trace_num
);
1066 processlist_set_ppid(process_list
, process_child
->ppid
,
1067 hashed_process_data_child
);
1068 processlist_set_tgid(process_list
, process_child
->tgid
,
1069 hashed_process_data_child
);
1073 if(likely(ltt_time_compare(hashed_process_data_child
->next_good_time
,
1076 TimeWindow time_window
=
1077 lttvwindow_get_time_window(control_flow_data
->tab
);
1080 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1081 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1083 #endif //EXTRA_CHECK
1084 Drawing_t
*drawing
= control_flow_data
->drawing
;
1085 guint width
= drawing
->width
;
1087 convert_time_to_pixels(
1093 if(likely(hashed_process_data_child
->x
.over
!= new_x
)) {
1094 hashed_process_data_child
->x
.over
= new_x
;
1095 hashed_process_data_child
->x
.over_used
= FALSE
;
1096 hashed_process_data_child
->x
.over_marked
= FALSE
;
1098 if(likely(hashed_process_data_child
->x
.middle
!= new_x
)) {
1099 hashed_process_data_child
->x
.middle
= new_x
;
1100 hashed_process_data_child
->x
.middle_used
= FALSE
;
1101 hashed_process_data_child
->x
.middle_marked
= FALSE
;
1103 if(likely(hashed_process_data_child
->x
.under
!= new_x
)) {
1104 hashed_process_data_child
->x
.under
= new_x
;
1105 hashed_process_data_child
->x
.under_used
= FALSE
;
1106 hashed_process_data_child
->x
.under_marked
= FALSE
;
1114 /* after_process_exit_hook
1116 * Create the processlist entry for the child process. Put the last
1117 * position in x at the current time value.
1119 * @param hook_data ControlFlowData structure of the viewer.
1120 * @param call_data Event context.
1122 * This function adds items to be drawn in a queue for each process.
1125 int after_process_exit_hook(void *hook_data
, void *call_data
)
1130 event
= (LttvEvent
*) call_data
;
1132 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_process_exit") != 0)
1135 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1137 LttvTraceState
*ts
= event
->state
;
1139 #ifdef BABEL_CLEANUP
1140 LttvFilter
*filter
= control_flow_data
->filter
;
1141 if(filter
!= NULL
&& filter
->head
!= NULL
)
1142 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1143 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1147 LttTime evtime
= lttv_event_get_timestamp(event
);
1149 /* Add process to process list (if not present) */
1150 //LttvProcessState *process = tfs->process;
1151 guint cpu
= lttv_traceset_get_cpuid_from_event(event
);
1152 guint trace_num
= lttv_traceset_get_trace_index_from_event(event
);
1153 LttvProcessState
*process
= ts
->running_process
[cpu
];
1155 /* It should exist, because we are after the state update. */
1156 g_assert(process
!= NULL
);
1158 guint pid
= process
->pid
;
1160 //guint pl_height = 0;
1161 HashedProcessData
*hashed_process_data
= NULL
;
1163 ProcessList
*process_list
= control_flow_data
->process_list
;
1165 //birth = process->creation_time;
1167 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
) ){
1168 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
1170 hashed_process_data
= get_hashed_process_data(control_flow_data
,
1171 process
, pid
, trace_num
);
1174 /* Set the current process */
1175 process_list
->current_hash_data
[trace_num
][process
->cpu
] =
1176 hashed_process_data
;
1179 if(unlikely(ltt_time_compare(hashed_process_data
->next_good_time
,
1182 TimeWindow time_window
=
1183 lttvwindow_get_time_window(control_flow_data
->tab
);
1186 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1187 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1189 #endif //EXTRA_CHECK
1190 Drawing_t
*drawing
= control_flow_data
->drawing
;
1191 guint width
= drawing
->width
;
1193 convert_time_to_pixels(
1198 if(unlikely(hashed_process_data
->x
.middle
!= new_x
)) {
1199 hashed_process_data
->x
.middle
= new_x
;
1200 hashed_process_data
->x
.middle_used
= FALSE
;
1201 hashed_process_data
->x
.middle_marked
= FALSE
;
1209 /* Get the filename of the process to print */
1210 int after_fs_exec_hook(void *hook_data
, void *call_data
)
1212 #ifdef BABEL_CLEANUP
1213 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
1214 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
1215 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1217 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
1219 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
1221 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
1224 e
= ltt_tracefile_get_event(tfc
->tf
);
1226 LttvFilter
*filter
= control_flow_data
->filter
;
1227 if(filter
!= NULL
&& filter
->head
!= NULL
)
1228 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1229 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1232 guint cpu
= tfs
->cpu
;
1233 guint trace_num
= ts
->parent
.index
;
1234 LttvProcessState
*process
= ts
->running_process
[cpu
];
1235 g_assert(process
!= NULL
);
1237 guint pid
= process
->pid
;
1239 /* Well, the process_out existed : we must get it in the process hash
1240 * or add it, and draw its items.
1242 /* Add process to process list (if not present) */
1243 guint pl_height
= 0;
1244 HashedProcessData
*hashed_process_data
= NULL
;
1245 ProcessList
*process_list
= control_flow_data
->process_list
;
1246 LttTime birth
= process
->creation_time
;
1248 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
)) {
1249 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
1251 hashed_process_data
= get_hashed_process_data(control_flow_data
,
1252 process
, pid
, trace_num
);
1253 /* Set the current process */
1254 process_list
->current_hash_data
[trace_num
][process
->cpu
] =
1255 hashed_process_data
;
1258 processlist_set_name(process_list
, process
->name
, hashed_process_data
);
1260 #endif //babel_cleanup
1265 /* after_event_enum_process_hook
1267 * Create the processlist entry for the child process. Put the last
1268 * position in x at the current time value.
1270 * @param hook_data ControlFlowData structure of the viewer.
1271 * @param call_data Event context.
1273 * This function adds items to be drawn in a queue for each process.
1276 int after_event_enum_process_hook(void *hook_data
, void *call_data
)
1280 event
= (LttvEvent
*) call_data
;
1282 if (strcmp(lttv_traceset_get_name_from_event(event
),"lttng_statedump_process_state") != 0)
1285 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1288 LttvTraceState
*ts
= event
->state
;
1290 guint first_cpu
, nb_cpus
, cpu
;
1292 #ifdef BABEL_CLEANUP
1293 LttvFilter
*filter
= control_flow_data
->filter
;
1294 if(filter
!= NULL
&& filter
->head
!= NULL
)
1295 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1296 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1299 /* Add process to process list (if not present) */
1300 LttvProcessState
*process_in
;
1301 HashedProcessData
*hashed_process_data_in
= NULL
;
1303 ProcessList
*process_list
= control_flow_data
->process_list
;
1304 guint trace_num
= lttv_traceset_get_trace_index_from_event(event
);
1308 pid_in
= lttv_event_get_long(event
, "tid");
1313 nb_cpus
= lttv_trace_get_num_cpu(ts
->trace
);
1315 first_cpu
= ANY_CPU
;
1316 nb_cpus
= ANY_CPU
+1;
1319 for(cpu
= first_cpu
; cpu
< nb_cpus
; cpu
++) {
1320 /* Find process pid_in in the list... */
1321 process_in
= lttv_state_find_process(ts
, cpu
, pid_in
);
1322 //process_in = tfs->process;
1323 //guint cpu = tfs->cpu;
1324 //guint trace_num = ts->parent.index;
1325 //process_in = ts->running_process[cpu];
1326 /* It should exist, because we are after the state update. */
1328 //g_assert(process_in != NULL);
1329 #endif //EXTRA_CHECK
1331 hashed_process_data_in
= get_hashed_process_data(control_flow_data
,
1332 process_in
, pid_in
, trace_num
);
1334 processlist_set_name(process_list
, process_in
->name
,
1335 hashed_process_data_in
);
1336 processlist_set_ppid(process_list
, process_in
->ppid
,
1337 hashed_process_data_in
);
1338 processlist_set_tgid(process_list
, process_in
->tgid
,
1339 hashed_process_data_in
);
1346 gint
update_time_window_hook(void *hook_data
, void *call_data
)
1348 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1350 Drawing_t
*drawing
= control_flow_data
->drawing
;
1351 ProcessList
*process_list
= control_flow_data
->process_list
;
1353 const TimeWindowNotifyData
*time_window_nofify_data
=
1354 ((const TimeWindowNotifyData
*)call_data
);
1356 TimeWindow
*old_time_window
=
1357 time_window_nofify_data
->old_time_window
;
1358 TimeWindow
*new_time_window
=
1359 time_window_nofify_data
->new_time_window
;
1361 /* Update the ruler */
1362 drawing_update_ruler(control_flow_data
->drawing
,
1366 /* Two cases : zoom in/out or scrolling */
1368 /* In order to make sure we can reuse the old drawing, the scale must
1369 * be the same and the new time interval being partly located in the
1370 * currently shown time interval. (reuse is only for scrolling)
1373 g_info("Old time window HOOK : %lu, %lu to %lu, %lu",
1374 old_time_window
->start_time
.tv_sec
,
1375 old_time_window
->start_time
.tv_nsec
,
1376 old_time_window
->time_width
.tv_sec
,
1377 old_time_window
->time_width
.tv_nsec
);
1379 g_info("New time window HOOK : %lu, %lu to %lu, %lu",
1380 new_time_window
->start_time
.tv_sec
,
1381 new_time_window
->start_time
.tv_nsec
,
1382 new_time_window
->time_width
.tv_sec
,
1383 new_time_window
->time_width
.tv_nsec
);
1385 if( new_time_window
->time_width
.tv_sec
== old_time_window
->time_width
.tv_sec
1386 && new_time_window
->time_width
.tv_nsec
== old_time_window
->time_width
.tv_nsec
)
1388 /* Same scale (scrolling) */
1389 g_info("scrolling");
1390 LttTime
*ns
= &new_time_window
->start_time
;
1391 LttTime
*os
= &old_time_window
->start_time
;
1392 LttTime old_end
= old_time_window
->end_time
;
1393 LttTime new_end
= new_time_window
->end_time
;
1395 //if(ns<os+w && os+w<ns+w)
1396 //if(ns<old_end && os<ns)
1397 if(ltt_time_compare(*ns
, old_end
) == -1
1398 && ltt_time_compare(*os
, *ns
) == -1)
1400 g_info("scrolling near right");
1401 /* Scroll right, keep right part of the screen */
1403 guint width
= control_flow_data
->drawing
->width
;
1404 convert_time_to_pixels(
1410 /* Copy old data to new location */
1411 copy_pixmap_region(process_list
,
1413 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1417 control_flow_data
->drawing
->width
-x
+SAFETY
, -1);
1419 if(drawing
->damage_begin
== drawing
->damage_end
)
1420 drawing
->damage_begin
= control_flow_data
->drawing
->width
-x
;
1422 drawing
->damage_begin
= 0;
1424 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1426 /* Clear the data request background, but not SAFETY */
1427 rectangle_pixmap(process_list
,
1428 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1430 drawing
->damage_begin
+SAFETY
, 0,
1431 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1433 gtk_widget_queue_draw(drawing
->drawing_area
);
1434 //gtk_widget_queue_draw_area (drawing->drawing_area,
1436 // control_flow_data->drawing->width,
1437 // control_flow_data->drawing->height);
1439 /* Get new data for the rest. */
1440 drawing_data_request(control_flow_data
->drawing
,
1441 drawing
->damage_begin
, 0,
1442 drawing
->damage_end
- drawing
->damage_begin
,
1443 control_flow_data
->drawing
->height
);
1446 //if(ns<os && os<ns+w)
1447 //if(ns<os && os<new_end)
1448 if(ltt_time_compare(*ns
,*os
) == -1
1449 && ltt_time_compare(*os
,new_end
) == -1)
1451 g_info("scrolling near left");
1452 /* Scroll left, keep left part of the screen */
1454 guint width
= control_flow_data
->drawing
->width
;
1455 convert_time_to_pixels(
1461 /* Copy old data to new location */
1462 copy_pixmap_region (process_list
,
1464 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1470 if(drawing
->damage_begin
== drawing
->damage_end
)
1471 drawing
->damage_end
= x
;
1473 drawing
->damage_end
=
1474 control_flow_data
->drawing
->width
;
1476 drawing
->damage_begin
= 0;
1478 rectangle_pixmap (process_list
,
1479 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1481 drawing
->damage_begin
, 0,
1482 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1485 gtk_widget_queue_draw(drawing
->drawing_area
);
1486 //gtk_widget_queue_draw_area (drawing->drawing_area,
1488 // control_flow_data->drawing->width,
1489 // control_flow_data->drawing->height);
1492 /* Get new data for the rest. */
1493 drawing_data_request(control_flow_data
->drawing
,
1494 drawing
->damage_begin
, 0,
1495 drawing
->damage_end
- drawing
->damage_begin
,
1496 control_flow_data
->drawing
->height
);
1499 if(ltt_time_compare(*ns
,*os
) == 0)
1501 g_info("not scrolling");
1503 g_info("scrolling far");
1504 /* Cannot reuse any part of the screen : far jump */
1507 rectangle_pixmap (process_list
,
1508 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1511 control_flow_data
->drawing
->width
+SAFETY
, // do not overlap
1514 //gtk_widget_queue_draw_area (drawing->drawing_area,
1516 // control_flow_data->drawing->width,
1517 // control_flow_data->drawing->height);
1518 gtk_widget_queue_draw(drawing
->drawing_area
);
1520 drawing
->damage_begin
= 0;
1521 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1523 drawing_data_request(control_flow_data
->drawing
,
1525 control_flow_data
->drawing
->width
,
1526 control_flow_data
->drawing
->height
);
1532 /* Different scale (zoom) */
1535 rectangle_pixmap (process_list
,
1536 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1539 control_flow_data
->drawing
->width
+SAFETY
, // do not overlap
1542 //gtk_widget_queue_draw_area (drawing->drawing_area,
1544 // control_flow_data->drawing->width,
1545 // control_flow_data->drawing->height);
1546 gtk_widget_queue_draw(drawing
->drawing_area
);
1548 drawing
->damage_begin
= 0;
1549 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1551 drawing_data_request(control_flow_data
->drawing
,
1553 control_flow_data
->drawing
->width
,
1554 control_flow_data
->drawing
->height
);
1557 /* Update directly when scrolling */
1558 gdk_window_process_updates(control_flow_data
->drawing
->drawing_area
->window
,
1564 gint
traceset_notify(void *hook_data
, void *call_data
)
1566 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1567 Drawing_t
*drawing
= control_flow_data
->drawing
;
1569 if(unlikely(drawing
->gc
== NULL
)) {
1572 if(drawing
->dotted_gc
== NULL
) {
1576 drawing_clear(control_flow_data
->drawing
);
1577 processlist_clear(control_flow_data
->process_list
);
1578 gtk_widget_set_size_request(
1579 control_flow_data
->drawing
->drawing_area
,
1580 -1, processlist_get_height(control_flow_data
->process_list
));
1581 redraw_notify(control_flow_data
, NULL
);
1583 request_background_data(control_flow_data
);
1588 gint
redraw_notify(void *hook_data
, void *call_data
)
1590 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1591 Drawing_t
*drawing
= control_flow_data
->drawing
;
1592 GtkWidget
*widget
= drawing
->drawing_area
;
1594 drawing
->damage_begin
= 0;
1595 drawing
->damage_end
= drawing
->width
;
1597 /* fun feature, to be separated someday... */
1598 drawing_clear(control_flow_data
->drawing
);
1599 processlist_clear(control_flow_data
->process_list
);
1600 gtk_widget_set_size_request(
1601 control_flow_data
->drawing
->drawing_area
,
1602 -1, processlist_get_height(control_flow_data
->process_list
));
1604 rectangle_pixmap (control_flow_data
->process_list
,
1605 widget
->style
->black_gc
,
1608 drawing
->alloc_width
,
1611 gtk_widget_queue_draw(drawing
->drawing_area
);
1613 if(drawing
->damage_begin
< drawing
->damage_end
)
1615 drawing_data_request(drawing
,
1616 drawing
->damage_begin
,
1618 drawing
->damage_end
-drawing
->damage_begin
,
1622 //gtk_widget_queue_draw_area(drawing->drawing_area,
1625 // drawing->height);
1631 gint
continue_notify(void *hook_data
, void *call_data
)
1633 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1634 Drawing_t
*drawing
= control_flow_data
->drawing
;
1636 //g_assert(widget->allocation.width == drawing->damage_end);
1638 if(drawing
->damage_begin
< drawing
->damage_end
)
1640 drawing_data_request(drawing
,
1641 drawing
->damage_begin
,
1643 drawing
->damage_end
-drawing
->damage_begin
,
1651 gint
update_current_time_hook(void *hook_data
, void *call_data
)
1654 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
1656 LttTime current_time
= *((LttTime
*)call_data
);
1658 TimeWindow time_window
=
1659 lttvwindow_get_time_window(control_flow_data
->tab
);
1661 LttTime time_begin
= time_window
.start_time
;
1662 LttTime width
= time_window
.time_width
;
1665 guint64 time_ll
= ltt_time_to_uint64(width
);
1666 time_ll
= time_ll
>> 1; /* divide by two */
1667 half_width
= ltt_time_from_uint64(time_ll
);
1669 LttTime time_end
= ltt_time_add(time_begin
, width
);
1671 LttvTraceset
* ts
= lttvwindow_get_traceset(control_flow_data
->tab
);
1673 TimeInterval time_span
= lttv_traceset_get_time_span_real(ts
);
1674 LttTime trace_start
= time_span
.start_time
;
1675 LttTime trace_end
= time_span
.end_time
;
1677 g_info("New current time HOOK : %lu, %lu", current_time
.tv_sec
,
1678 current_time
.tv_nsec
);
1682 /* If current time is inside time interval, just move the highlight
1685 /* Else, we have to change the time interval. We have to tell it
1686 * to the main window. */
1687 /* The time interval change will take care of placing the current
1688 * time at the center of the visible area, or nearest possible if we are
1689 * at one end of the trace. */
1692 if(ltt_time_compare(current_time
, time_begin
) < 0)
1694 TimeWindow new_time_window
;
1696 if(ltt_time_compare(current_time
,
1697 ltt_time_add(trace_start
,half_width
)) < 0)
1698 time_begin
= trace_start
;
1700 time_begin
= ltt_time_sub(current_time
,half_width
);
1702 new_time_window
.start_time
= time_begin
;
1703 new_time_window
.time_width
= width
;
1704 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1705 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1707 lttvwindow_report_time_window(control_flow_data
->tab
, new_time_window
);
1709 else if(ltt_time_compare(current_time
, time_end
) > 0)
1711 TimeWindow new_time_window
;
1713 if(ltt_time_compare(current_time
, ltt_time_sub(trace_end
, half_width
)) > 0)
1714 time_begin
= ltt_time_sub(trace_end
,width
);
1716 time_begin
= ltt_time_sub(current_time
,half_width
);
1718 new_time_window
.start_time
= time_begin
;
1719 new_time_window
.time_width
= width
;
1720 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1721 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1723 lttvwindow_report_time_window(control_flow_data
->tab
, new_time_window
);
1726 gtk_widget_queue_draw(control_flow_data
->drawing
->drawing_area
);
1728 /* Update directly when scrolling */
1729 gdk_window_process_updates(control_flow_data
->drawing
->drawing_area
->window
,
1736 typedef struct _ClosureData
{
1737 EventsRequest
*events_request
;
1743 void draw_closure(gpointer key
, gpointer value
, gpointer user_data
)
1746 ProcessInfo
*process_info
= (ProcessInfo
*)key
;
1747 HashedProcessData
*hashed_process_data
= (HashedProcessData
*)value
;
1748 ClosureData
*closure_data
= (ClosureData
*)user_data
;
1750 EventsRequest
*events_request
= closure_data
->events_request
;
1751 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1752 LttvTraceset
*ts
= lttvwindow_get_traceset(control_flow_data
->tab
);
1755 LttTime evtime
= closure_data
->end_time
;
1757 gboolean dodraw
= TRUE
;
1760 /* For the process */
1761 /* First, check if the current process is in the state computation
1762 * process list. If it is there, that means we must add it right now and
1763 * draw items from the beginning of the read for it. If it is not
1764 * present, it's a new process and it was not present : it will
1765 * be added after the state update. */
1767 g_assert(lttv_traceset_number(tsc
->ts
) > 0);
1768 #endif //EXTRA_CHECK
1770 LttvTrace
*trace
= lttv_traceset_get(ts
, process_info
->trace_num
);
1771 LttvTraceState
*trace_state
= trace
->state
;
1774 //FIXME : optimize data structures.
1775 LttvTracefileState
*tfs
;
1776 LttvTracefileContext
*tfc
;
1778 for(i
=0;i
<tc
->tracefiles
->len
;i
++) {
1779 tfc
= g_array_index(tc
->tracefiles
, LttvTracefileContext
*, i
);
1780 if(ltt_tracefile_name(tfc
->tf
) == LTT_NAME_CPU
1781 && tfs
->cpu
== process_info
->cpu
)
1785 g_assert(i
<tc
->tracefiles
->len
);
1786 tfs
= LTTV_TRACEFILE_STATE(tfc
);
1788 // LttvTracefileState *tfs =ts
1789 // (LttvTracefileState*)tsc->traces[process_info->trace_num]->
1790 // tracefiles[process_info->cpu];
1792 LttvProcessState
*process
;
1793 process
= lttv_state_find_process(trace_state
, process_info
->cpu
,
1796 if(unlikely(process
!= NULL
)) {
1797 #ifdef BABEL_CLEANUP
1798 LttvFilter
*filter
= control_flow_data
->filter
;
1799 if(filter
!= NULL
&& filter
->head
!= NULL
)
1800 if(!lttv_filter_tree_parse(filter
->head
,NULL
,NULL
,
1801 tc
->t
,NULL
,process
,tc
))
1803 #endif //babel_cleanup
1804 /* Only draw for processes that are currently in the trace states */
1807 /* Should be alike when background info is ready */
1808 if(control_flow_data
->background_info_waiting
==0)
1809 g_assert(ltt_time_compare(process
->creation_time
,
1810 process_info
->birth
) == 0);
1811 #endif //EXTRA_CHECK
1813 /* Now, the process is in the state hash and our own process hash.
1814 * We definitely can draw the items related to the ending state.
1817 if(unlikely(ltt_time_compare(hashed_process_data
->next_good_time
,
1820 TimeWindow time_window
=
1821 lttvwindow_get_time_window(control_flow_data
->tab
);
1824 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1825 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1827 #endif //EXTRA_CHECK
1828 Drawing_t
*drawing
= control_flow_data
->drawing
;
1829 guint width
= drawing
->width
;
1831 guint x
= closure_data
->x_end
;
1833 DrawContext draw_context
;
1835 init_drawing_context(&draw_context
,
1836 hashed_process_data
,
1841 /* Jump over draw if we are at the same x position */
1842 if(x
== hashed_process_data
->x
.over
)
1846 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.over
;
1848 PropertiesLine prop_line
= prepare_execmode_line(process
);
1849 draw_line((void*)&prop_line
, (void*)&draw_context
);
1851 hashed_process_data
->x
.over
= x
;
1855 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1856 hashed_process_data
->x
.middle_used
)) {
1857 #if 0 /* do not mark closure : not missing information */
1858 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
1859 /* Draw collision indicator */
1860 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1861 gdk_draw_point(drawing
->pixmap
,
1865 hashed_process_data
->x
.middle_marked
= TRUE
;
1870 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1873 PropertiesLine prop_line
= prepare_s_e_line(process
);
1874 draw_line((void*)&prop_line
, (void*)&draw_context
);
1877 /* become the last x position */
1878 if(likely(x
!= hashed_process_data
->x
.middle
)) {
1879 hashed_process_data
->x
.middle
= x
;
1880 /* but don't use the pixel */
1881 hashed_process_data
->x
.middle_used
= FALSE
;
1883 /* Calculate the next good time */
1884 convert_pixels_to_time(width
, x
+1, time_window
,
1885 &hashed_process_data
->next_good_time
);
1894 int before_chunk(void *hook_data
, void *call_data
)
1897 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1898 LttvTraceset
*ts
= (LttvTraceset
*)call_data
;
1900 /* Desactivate sort */
1901 gtk_tree_sortable_set_sort_column_id(
1902 GTK_TREE_SORTABLE(cfd
->process_list
->list_store
),
1904 GTK_SORT_ASCENDING
);
1906 drawing_chunk_begin(events_request
, ts
);
1911 int before_request(void *hook_data
, void *call_data
)
1914 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1916 drawing_data_request_begin(events_request
);
1923 void draw_closing_lines(ControlFlowData
*control_flow_data
,
1924 EventsRequest
* events_request
)
1926 ProcessList
*process_list
= control_flow_data
->process_list
;
1929 ClosureData closure_data
;
1930 closure_data
.events_request
= events_request
;
1931 closure_data
.end_time
= events_request
->end_time
;
1933 TimeWindow time_window
=
1934 lttvwindow_get_time_window(control_flow_data
->tab
);
1935 guint width
= control_flow_data
->drawing
->width
;
1936 convert_time_to_pixels(
1938 events_request
->end_time
,
1940 &closure_data
.x_end
);
1943 /* Draw last items */
1944 g_hash_table_foreach(process_list
->process_hash
, draw_closure
,
1945 (void*)&closure_data
);
1948 /* Request expose */
1949 drawing_request_expose(events_request
, events_request
->end_time
);
1953 * after request is necessary in addition of after chunk in order to draw
1954 * lines until the end of the screen. after chunk just draws lines until
1961 int after_request(void *hook_data
, void *call_data
)
1964 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1965 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1967 draw_closing_lines(control_flow_data
, events_request
);
1977 int after_chunk(void *hook_data
, void *call_data
)
1980 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1981 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1982 LttvTraceset
*ts
= (LttvTraceset
*)call_data
;
1985 ProcessList
*process_list
= control_flow_data
->process_list
;
1987 guint nb_trace
= lttv_traceset_number(ts
);
1989 /* Only execute when called for the first trace's events request */
1990 if(!process_list
->current_hash_data
)
1993 for(i
= 0 ; i
< nb_trace
; i
++) {
1994 g_free(process_list
->current_hash_data
[i
]);
1996 g_free(process_list
->current_hash_data
);
1997 process_list
->current_hash_data
= NULL
;
1999 draw_closing_lines(control_flow_data
, events_request
);
2004 /* after_statedump_end
2006 * @param hook_data ControlFlowData structure of the viewer.
2007 * @param call_data Event context.
2009 * This function adds items to be drawn in a queue for each process.
2012 int before_statedump_end(void *hook_data
, void *call_data
)
2016 event
= (LttvEvent
*) call_data
;
2018 if (strcmp(lttv_traceset_get_name_from_event(event
),"lttng_statedump_end") != 0)
2021 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
2023 ProcessList
*process_list
= control_flow_data
->process_list
;
2025 #ifdef BABEL_CLEANUP
2026 LttvFilter
*filter
= control_flow_data
->filter
;
2027 if(filter
!= NULL
&& filter
->head
!= NULL
)
2028 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
2029 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
2033 LttTime evtime
= lttv_event_get_timestamp(event
);
2035 ClosureData closure_data
;
2036 //TODO ybrosseau 2013-03-27: Fake and event_request.
2037 // We need to change the API of drawing_request_expose to ask
2038 // For and control flow data only.
2039 EventsRequest events_request
;
2040 events_request
.viewer_data
= control_flow_data
;
2041 closure_data
.events_request
= &events_request
;
2042 closure_data
.end_time
= evtime
;
2044 TimeWindow time_window
=
2045 lttvwindow_get_time_window(control_flow_data
->tab
);
2046 guint width
= control_flow_data
->drawing
->width
;
2047 convert_time_to_pixels(
2051 &closure_data
.x_end
);
2053 /* Draw last items */
2054 g_hash_table_foreach(process_list
->process_hash
, draw_closure
,
2055 (void*)&closure_data
);
2058 /* Reactivate sort */
2059 gtk_tree_sortable_set_sort_column_id(
2060 GTK_TREE_SORTABLE(control_flow_data
->process_list
->list_store
),
2061 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
,
2062 GTK_SORT_ASCENDING
);
2064 update_index_to_pixmap(control_flow_data
->process_list
);
2065 /* Request a full expose : drawing scrambled */
2066 gtk_widget_queue_draw(control_flow_data
->drawing
->drawing_area
);
2068 /* Request expose (updates damages zone also) */
2069 drawing_request_expose(&events_request
, evtime
);