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>
64 #include <ltt/trace.h>
66 #include <lttv/lttv.h>
67 #include <lttv/hook.h>
68 #include <lttv/state.h>
69 #include <lttvwindow/lttvwindow.h>
70 #include <lttvwindow/lttvwindowtraces.h>
71 #include <lttvwindow/support.h>
74 #include "eventhooks.h"
76 #include "processlist.h"
80 #define MAX_PATH_LEN 256
81 #define STATE_LINE_WIDTH 8
82 #define COLLISION_POSITION(height) (((height - STATE_LINE_WIDTH)/2) -3)
84 extern GSList
*g_legend_list
;
87 /* Action to do when background computation completed.
89 * Wait for all the awaited computations to be over.
92 static gint
background_ready(void *hook_data
, void *call_data
)
94 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
96 control_flow_data
->background_info_waiting
--;
98 if(control_flow_data
->background_info_waiting
== 0) {
99 g_message("control flow viewer : background computation data ready.");
101 drawing_clear(control_flow_data
->drawing
);
102 processlist_clear(control_flow_data
->process_list
);
103 gtk_widget_set_size_request(
104 control_flow_data
->drawing
->drawing_area
,
105 -1, processlist_get_height(control_flow_data
->process_list
));
106 redraw_notify(control_flow_data
, NULL
);
113 /* Request background computation. Verify if it is in progress or ready first.
114 * Only for each trace in the tab's traceset.
117 static void request_background_data(ControlFlowData
*control_flow_data
)
120 LttvTraceset
*ts
= lttvwindow_get_traceset(control_flow_data
->tab
);
121 gint num_traces
= lttv_traceset_number(ts
);
124 LttvTraceState
*tstate
;
126 LttvHooks
*background_ready_hook
= lttv_hooks_new();
127 lttv_hooks_add(background_ready_hook
, background_ready
, control_flow_data
,
129 control_flow_data
->background_info_waiting
= 0;
131 for(i
=0;i
<num_traces
;i
++) {
132 trace
= lttv_traceset_get(ts
, i
);
133 tstate
= trace
->state
;
135 if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace
)==FALSE
136 && !ts
->has_precomputed_states
) {
138 if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"),
140 /* We first remove requests that could have been done for the same
141 * information. Happens when two viewers ask for it before servicing
144 if(!lttvwindowtraces_background_request_find(trace
, "state"))
145 lttvwindowtraces_background_request_queue(
146 main_window_get_widget(control_flow_data
->tab
), trace
, "state");
147 lttvwindowtraces_background_notify_queue(control_flow_data
,
151 background_ready_hook
);
152 control_flow_data
->background_info_waiting
++;
153 } else { /* in progress */
155 lttvwindowtraces_background_notify_current(control_flow_data
,
159 background_ready_hook
);
160 control_flow_data
->background_info_waiting
++;
163 /* Data ready. By its nature, this viewer doesn't need to have
164 * its data ready hook called there, because a background
165 * request is always linked with a redraw.
171 lttv_hooks_destroy(background_ready_hook
);
178 * Event Viewer's constructor hook
180 * This constructor is given as a parameter to the menuitem and toolbar button
181 * registration. It creates the list.
182 * @param tab A pointer to the parent tab.
183 * @return The widget created.
186 h_guicontrolflow(LttvPlugin
*plugin
)
188 LttvPluginTab
*ptab
= LTTV_PLUGIN_TAB(plugin
);
189 Tab
*tab
= ptab
->tab
;
190 g_info("h_guicontrolflow, %p", tab
);
191 ControlFlowData
*control_flow_data
= guicontrolflow(ptab
);
193 control_flow_data
->tab
= tab
;
195 // Unreg done in the GuiControlFlow_Destructor
196 lttvwindow_register_traceset_notify(tab
,
200 lttvwindow_register_time_window_notify(tab
,
201 update_time_window_hook
,
203 lttvwindow_register_current_time_notify(tab
,
204 update_current_time_hook
,
206 lttvwindow_register_redraw_notify(tab
,
209 lttvwindow_register_continue_notify(tab
,
212 request_background_data(control_flow_data
);
215 return guicontrolflow_get_widget(control_flow_data
) ;
219 int event_selected_hook(void *hook_data
, void *call_data
)
221 guint
*event_number
= (guint
*) call_data
;
223 g_debug("DEBUG : event selected by main window : %u", *event_number
);
228 /* Function that selects the color of status&exemode line */
229 static inline PropertiesLine
prepare_s_e_line(LttvProcessState
*process
)
231 PropertiesLine prop_line
;
232 prop_line
.line_width
= STATE_LINE_WIDTH
;
233 prop_line
.style
= GDK_LINE_SOLID
;
234 prop_line
.y
= MIDDLE
;
235 //GdkColormap *colormap = gdk_colormap_get_system();
237 if(process
->state
->s
== LTTV_STATE_RUN
) {
238 if(process
->state
->t
== LTTV_STATE_USER_MODE
)
239 prop_line
.color
= drawing_colors
[COL_RUN_USER_MODE
];
240 else if(process
->state
->t
== LTTV_STATE_SYSCALL
)
241 prop_line
.color
= drawing_colors
[COL_RUN_SYSCALL
];
242 else if(process
->state
->t
== LTTV_STATE_TRAP
)
243 prop_line
.color
= drawing_colors
[COL_RUN_TRAP
];
244 else if(process
->state
->t
== LTTV_STATE_IRQ
)
245 prop_line
.color
= drawing_colors
[COL_RUN_IRQ
];
246 else if(process
->state
->t
== LTTV_STATE_SOFT_IRQ
)
247 prop_line
.color
= drawing_colors
[COL_RUN_SOFT_IRQ
];
248 else if(process
->state
->t
== LTTV_STATE_MAYBE_SYSCALL
)
249 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
250 else if(process
->state
->t
== LTTV_STATE_MAYBE_USER_MODE
)
251 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
252 else if(process
->state
->t
== LTTV_STATE_MAYBE_TRAP
)
253 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
254 else if(process
->state
->t
== LTTV_STATE_MODE_UNKNOWN
)
255 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
257 g_assert(FALSE
); /* RUNNING MODE UNKNOWN */
258 } else if(process
->state
->s
== LTTV_STATE_WAIT
) {
259 /* We don't show if we wait while in user mode, trap, irq or syscall */
260 prop_line
.color
= drawing_colors
[COL_WAIT
];
261 } else if(process
->state
->s
== LTTV_STATE_WAIT_CPU
) {
262 /* We don't show if we wait for CPU while in user mode, trap, irq
264 prop_line
.color
= drawing_colors
[COL_WAIT_CPU
];
265 } else if(process
->state
->s
== LTTV_STATE_ZOMBIE
) {
266 prop_line
.color
= drawing_colors
[COL_ZOMBIE
];
267 } else if(process
->state
->s
== LTTV_STATE_WAIT_FORK
) {
268 prop_line
.color
= drawing_colors
[COL_WAIT_FORK
];
269 } else if(process
->state
->s
== LTTV_STATE_EXIT
) {
270 prop_line
.color
= drawing_colors
[COL_EXIT
];
271 } else if(process
->state
->s
== LTTV_STATE_UNNAMED
) {
272 prop_line
.color
= drawing_colors
[COL_UNNAMED
];
273 } else if(process
->state
->s
== LTTV_STATE_DEAD
) {
274 prop_line
.color
= drawing_colors
[COL_DEAD
];
276 g_critical("unknown state : %s", g_quark_to_string(process
->state
->s
));
277 g_assert(FALSE
); /* UNKNOWN STATE */
284 HashedProcessData
*get_hashed_process_data(ControlFlowData
*control_flow_data
,
285 LttvProcessState
*process
,
289 HashedProcessData
*hashed_process_data
= NULL
;
290 ProcessList
*process_list
= control_flow_data
->process_list
;
291 LttTime birth
= process
->creation_time
;
294 hashed_process_data
= processlist_get_process_data(process_list
,
299 if(hashed_process_data
== NULL
)
301 g_assert(pid
== 0 || pid
!= process
->ppid
);
302 ProcessInfo
*process_info
;
303 Drawing_t
*drawing
= control_flow_data
->drawing
;
304 /* Process not present */
305 processlist_add(process_list
,
317 &hashed_process_data
);
318 gtk_widget_set_size_request(drawing
->drawing_area
,
321 gtk_widget_queue_draw(drawing
->drawing_area
);
323 return hashed_process_data
;
326 void init_drawing_context(DrawContext
*draw_context
,
327 HashedProcessData
*hashed_process_data
,
332 draw_context
->drawable
= hashed_process_data
->pixmap
;
333 draw_context
->gc
= drawing
->gc
;
334 draw_context
->pango_layout
= drawing
->pango_layout
;
335 draw_context
->drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
336 draw_context
->drawinfo
.end
.x
= x
;
338 draw_context
->drawinfo
.y
.over
= 1;
339 draw_context
->drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
340 draw_context
->drawinfo
.y
.under
= hashed_process_data
->height
;
342 draw_context
->drawinfo
.start
.offset
.over
= 0;
343 draw_context
->drawinfo
.start
.offset
.middle
= 0;
344 draw_context
->drawinfo
.start
.offset
.under
= 0;
345 draw_context
->drawinfo
.end
.offset
.over
= 0;
346 draw_context
->drawinfo
.end
.offset
.middle
= 0;
347 draw_context
->drawinfo
.end
.offset
.under
= 0;
351 void draw_state_line(HashedProcessData
*hashed_process_data
,
352 LttvProcessState
*process
,
355 TimeWindow time_window
)
357 DrawContext draw_context
;
358 guint width
= drawing
->width
;
360 init_drawing_context(&draw_context
,
367 PropertiesLine prop_line
= prepare_s_e_line(process
);
368 draw_line((void*)&prop_line
, (void*)&draw_context
);
370 /* become the last x position */
371 hashed_process_data
->x
.middle
= x
;
372 hashed_process_data
->x
.middle_used
= TRUE
;
373 hashed_process_data
->x
.middle_marked
= FALSE
;
375 /* Calculate the next good time */
376 convert_pixels_to_time(width
, x
+1, time_window
,
377 &hashed_process_data
->next_good_time
);
381 void draw_state_items(ControlFlowData
*control_flow_data
,
382 HashedProcessData
*hashed_process_data
,
383 LttvProcessState
*process
,
388 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
391 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
392 TimeWindow time_window
=
393 lttvwindow_get_time_window(control_flow_data
->tab
);
396 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
397 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
400 Drawing_t
*drawing
= control_flow_data
->drawing
;
401 guint width
= drawing
->width
;
403 convert_time_to_pixels(
409 /* Draw collision indicator */
410 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
411 gdk_draw_point(hashed_process_data
->pixmap
,
414 COLLISION_POSITION(hashed_process_data
->height
));
415 hashed_process_data
->x
.middle_marked
= TRUE
;
418 TimeWindow time_window
=
419 lttvwindow_get_time_window(control_flow_data
->tab
);
422 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
423 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
426 Drawing_t
*drawing
= control_flow_data
->drawing
;
427 guint width
= drawing
->width
;
430 convert_time_to_pixels(
437 /* Jump over draw if we are at the same x position */
438 if(unlikely(x
== hashed_process_data
->x
.middle
&&
439 hashed_process_data
->x
.middle_used
))
441 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
442 /* Draw collision indicator */
443 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
444 gdk_draw_point(hashed_process_data
->pixmap
,
447 COLLISION_POSITION(hashed_process_data
->height
));
448 hashed_process_data
->x
.middle_marked
= TRUE
;
453 draw_state_line(hashed_process_data
,
463 /* Before try-wake-up hook. A process is being woken; we need to draw its line up to this point in time
464 in that colour. This is basically like exec-state, but the change applies to a process other than that
465 which is currently running. */
467 int before_trywakeup_hook(void *hook_data
, void *call_data
)
472 event
= (LttvEvent
*) call_data
;
473 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_wakeup") != 0)
476 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
478 LttvTraceState
*ts
= event
->state
;;
481 LttTime evtime
= lttv_event_get_timestamp(event
);
483 LttvFilter
*filter
= control_flow_data
->filter
;
489 woken_pid
= lttv_event_get_long(event
, "tid");
490 woken_cpu
= lttv_event_get_long(event
, "target_cpu");
493 if(!filter
|| !filter
->head
||
494 lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
495 tfc
->t_context
->t
,tfc
,NULL
,NULL
)) {
499 /* First, check if the woken process is in the state computation
500 * process list. If it is there, that means we must add it right now and
501 * draw items from the beginning of the read for it. If it is not
502 * present, it's a new process and it was not present : it will
503 * be added after the state update. TOCHECK: What does that last para mean? */
504 guint trace_num
= 0; /*TODO ybrosseau 2012-08-23: use right number */
505 LttvProcessState
*process
= lttv_state_find_process(ts
, woken_cpu
, woken_pid
);
507 if(process
!= NULL
) {
508 /* Well, the woken process existed : we must get it in the process hash
509 * or add it, and draw its items.
511 /* Add process to process list (if not present) */
513 HashedProcessData
*hashed_process_data
= get_hashed_process_data(control_flow_data
, process
, woken_pid
, trace_num
);
515 /* Now, the process is in the state hash and our own process hash.
516 * We definitely can draw the items related to the ending state.
519 draw_state_items(control_flow_data
,
534 /* before_schedchange_hook
536 * This function basically draw lines and icons. Two types of lines are drawn :
537 * one small (3 pixels?) representing the state of the process and the second
538 * type is thicker (10 pixels?) representing on which CPU a process is running
539 * (and this only in running state).
541 * Extremums of the lines :
542 * x_min : time of the last event context for this process kept in memory.
543 * x_max : time of the current event.
544 * y : middle of the process in the process list. The process is found in the
545 * list, therefore is it's position in pixels.
547 * The choice of lines'color is defined by the context of the last event for this
552 int before_schedchange_hook(void *hook_data
, void *call_data
)
557 LttvProcessState
*process
;
559 //LttvProcessState *old_process = ts->running_process[cpu];
561 guint pid_in
, pid_out
;
564 event
= (LttvEvent
*) call_data
;
565 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_switch") != 0)
568 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
571 /* we are in a schedchange, before the state update. We must draw the
572 * items corresponding to the state before it changes : now is the right
575 cpu
= lttv_traceset_get_cpuid_from_event(event
);
578 pid_out
= lttv_event_get_long(event
, "prev_tid");
579 pid_in
= lttv_event_get_long(event
, "next_tid");
580 state_out
= lttv_event_get_long(event
, "prev_state");
581 guint trace_number
= 0;//TODO fdeslauriers 2012-07-17: // Use trace handle to know trace number
583 process
= lttv_state_find_process(ts
,cpu
,pid_out
);
584 evtime
= lttv_event_get_timestamp(event
);
585 /* For the pid_out */
586 /* First, check if the current process is in the state computation
587 * process list. If it is there, that means we must add it right now and
588 * draw items from the beginning of the read for it. If it is not
589 * present, it's a new process and it was not present : it will
590 * be added after the state update. */
592 /* unknown state, bad current pid */
594 if(process
!= NULL
) {
595 /* Well, the process_out existed : we must get it in the process hash
596 * or add it, and draw its items.
598 /* Add process to process list (if not present) */
600 HashedProcessData
*hashed_process_data
= get_hashed_process_data(control_flow_data
, process
, pid_out
, trace_number
);
602 /* Now, the process is in the state hash and our own process hash.
603 * We definitely can draw the items related to the ending state.
606 draw_state_items(control_flow_data
,
613 /* First, check if the current process is in the state computation
614 * process list. If it is there, that means we must add it right now and
615 * draw items from the beginning of the read for it. If it is not
616 * present, it's a new process and it was not present : it will
617 * be added after the state update. */
618 process
= lttv_state_find_process(ts
,cpu
,pid_in
);
620 if(process
!= NULL
) {
621 /* Well, the process existed : we must get it in the process hash
622 * or add it, and draw its items.
624 /* Add process to process list (if not present) */
626 HashedProcessData
*hashed_process_data
= get_hashed_process_data(control_flow_data
, process
, pid_in
, trace_number
);
628 //We could set the current process and hash here, but will be done
629 //by after schedchange hook
631 /* Now, the process is in the state hash and our own process hash.
632 * We definitely can draw the items related to the ending state.
634 draw_state_items(control_flow_data
,
640 g_warning("Cannot find pin_in in schedchange %u", pid_in
);
642 tfc
->target_pid
= target_pid_saved
;
643 #endif //babel_cleanup
651 GString
*string
= g_string_new("");;
652 gboolean field_names
= TRUE
, state
= TRUE
;
654 lttv_event_to_string(e
, tfc
->tf
, string
, TRUE
, field_names
, tfs
);
655 g_string_append_printf(string
,"\n");
658 g_string_append_printf(string
, " %s",
659 g_quark_to_string(tfs
->process
->state
->s
));
662 g_info("%s",string
->str
);
664 g_string_free(string
, TRUE
);
666 /* End of text dump */
671 /* after_schedchange_hook
673 * The draw after hook is called by the reading API to have a
674 * particular event drawn on the screen.
675 * @param hook_data ControlFlowData structure of the viewer.
676 * @param call_data Event context.
678 * This function adds items to be drawn in a queue for each process.
681 int after_schedchange_hook(void *hook_data
, void *call_data
)
685 event
= (LttvEvent
*) call_data
;
687 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_switch") != 0)
690 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
693 LttvTraceState
*ts
= event
->state
;
696 LttvFilter
*filter
= control_flow_data
->filter
;
698 LttTime evtime
= lttv_event_get_timestamp(event
);
700 /* Add process to process list (if not present) */
701 LttvProcessState
*process_in
;
702 HashedProcessData
*hashed_process_data_in
= NULL
;
704 ProcessList
*process_list
= control_flow_data
->process_list
;
708 pid_in
= lttv_event_get_long(event
, "next_tid");
712 if(!filter
|| !filter
->head
||
713 lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
714 tfc
->t_context
->t
,tfc
,NULL
,NULL
)) {
718 /* Find process pid_in in the list... */
719 //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in);
720 //process_in = tfs->process;
721 guint cpu
= lttv_traceset_get_cpuid_from_event(event
);
722 guint trace_num
= 0; /* TODO set right trace number */
723 process_in
= ts
->running_process
[cpu
];
724 /* It should exist, because we are after the state update. */
726 g_assert(process_in
!= NULL
);
728 hashed_process_data_in
= get_hashed_process_data(control_flow_data
, process_in
, pid_in
, trace_num
);
730 /* Set the current process */
731 process_list
->current_hash_data
[trace_num
][process_in
->cpu
] =
732 hashed_process_data_in
;
734 if(ltt_time_compare(hashed_process_data_in
->next_good_time
,
737 TimeWindow time_window
=
738 lttvwindow_get_time_window(control_flow_data
->tab
);
741 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
742 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
745 Drawing_t
*drawing
= control_flow_data
->drawing
;
746 guint width
= drawing
->width
;
749 convert_time_to_pixels(
755 if(hashed_process_data_in
->x
.middle
!= new_x
) {
756 hashed_process_data_in
->x
.middle
= new_x
;
757 hashed_process_data_in
->x
.middle_used
= FALSE
;
758 hashed_process_data_in
->x
.middle_marked
= FALSE
;
769 /* before_execmode_hook
771 * This function basically draw lines and icons. Two types of lines are drawn :
772 * one small (3 pixels?) representing the state of the process and the second
773 * type is thicker (10 pixels?) representing on which CPU a process is running
774 * (and this only in running state).
776 * Extremums of the lines :
777 * x_min : time of the last event context for this process kept in memory.
778 * x_max : time of the current event.
779 * y : middle of the process in the process list. The process is found in the
780 * list, therefore is it's position in pixels.
782 * The choice of lines'color is defined by the context of the last event for this
787 int before_execmode_hook(void *hook_data
, void *call_data
)
793 LttvProcessState
*process
;
795 /* we are in a execmode, before the state update. We must draw the
796 * items corresponding to the state before it changes : now is the right
800 event
= (LttvEvent
*) call_data
;
801 if ((strncmp(lttv_traceset_get_name_from_event(event
),"sys_", sizeof("sys_") - 1) == 0)
802 ||(strcmp(lttv_traceset_get_name_from_event(event
),"exit_syscall") == 0)
803 ||(strncmp(lttv_traceset_get_name_from_event(event
),"irq_handler_",sizeof("irq_handler_")) == 0)
804 ||(strncmp(lttv_traceset_get_name_from_event(event
),"softirq_", sizeof("softirq_")) == 0)) {
806 LttTime evtime
= lttv_event_get_timestamp(event
);
807 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
809 LttvTraceset
*traceSet
= lttvwindow_get_traceset(control_flow_data
->tab
);
811 cpu
= lttv_traceset_get_cpuid_from_event(event
);
814 guint trace_number
= 0;//TODO fdeslauriers 2012-07-17: // Use trace handle to know trace number
815 process
= lttv_state_find_process(ts
,cpu
,pid
);
816 g_assert(process
!= NULL
);
818 guint pid
= process
->pid
;
820 /* Well, the process_out existed : we must get it in the process hash
821 * or add it, and draw its items.
823 /* Add process to process list (if not present) */
824 HashedProcessData
*hashed_process_data
= NULL
;
825 ProcessList
*process_list
= control_flow_data
->process_list
;
826 if(process_list
->current_hash_data
== NULL
){//TODO fdeslauriers 2012-07-17 : should not be necessary
830 if(likely(process_list
->current_hash_data
[trace_number
][cpu
] != NULL
)) {
831 hashed_process_data
= process_list
->current_hash_data
[trace_number
][cpu
];
833 hashed_process_data
= get_hashed_process_data(control_flow_data
,
834 process
, pid
, trace_number
);
836 /* Set the current process */
837 process_list
->current_hash_data
[trace_number
][process
->cpu
] =
841 /* Now, the process is in the state hash and our own process hash.
842 * We definitely can draw the items related to the ending state.
845 draw_state_items(control_flow_data
,
855 /* before_process_exit_hook
857 * Draw lines for process event.
859 * @param hook_data ControlFlowData structure of the viewer.
860 * @param call_data Event context.
862 * This function adds items to be drawn in a queue for each process.
867 int before_process_exit_hook(void *hook_data
, void *call_data
)
872 event
= (LttvEvent
*) call_data
;
873 if (strcmp(lttv_traceset_get_name_from_event(event
),
874 "sched_process_exit") != 0)
878 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
879 LttvTraceState
*ts
= event
->state
;
882 LttvFilter
*filter
= control_flow_data
->filter
;
883 if(filter
!= NULL
&& filter
->head
!= NULL
)
884 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
885 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
889 LttTime evtime
= lttv_event_get_timestamp(event
);
891 /* Add process to process list (if not present) */
892 //LttvProcessState *process = tfs->process;
893 guint cpu
= lttv_traceset_get_cpuid_from_event(event
);
894 guint trace_num
= 0; /* TODO set right trace number */
896 LttvProcessState
*process
= ts
->running_process
[cpu
];
897 guint pid
= process
->pid
;
898 HashedProcessData
*hashed_process_data
= NULL
;
900 ProcessList
*process_list
= control_flow_data
->process_list
;
902 g_assert(process
!= NULL
);
904 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
)) {
905 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
907 hashed_process_data
= get_hashed_process_data(control_flow_data
,
908 process
, pid
, trace_num
);
911 /* Now, the process is in the state hash and our own process hash.
912 * We definitely can draw the items related to the ending state.
915 draw_state_items(control_flow_data
,
926 /* before_process_release_hook
928 * Draw lines for process event.
930 * @param hook_data ControlFlowData structure of the viewer.
931 * @param call_data Event context.
933 * This function adds items to be drawn in a queue for each process.
938 int before_process_release_hook(void *hook_data
, void *call_data
)
943 event
= (LttvEvent
*) call_data
;
945 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_process_free") != 0)
948 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
951 LttvTraceState
*ts
= event
->state
;
954 LttvFilter
*filter
= control_flow_data
->filter
;
955 if(filter
!= NULL
&& filter
->head
!= NULL
)
956 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
957 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
960 LttTime evtime
= lttv_event_get_timestamp(event
);
963 guint trace_num
= 0; /* TODO set right trace number */
967 pid
= lttv_event_get_long(event
, "tid");
970 /* Add process to process list (if not present) */
971 /* Don't care about the process if it's not in the state hash already :
972 * that means a process that has never done anything in the trace and
973 * unknown suddently gets destroyed : no state meaningful to show. */
974 LttvProcessState
*process
= lttv_state_find_process(ts
, ANY_CPU
, pid
);
976 if(process
!= NULL
) {
978 HashedProcessData
*hashed_process_data
= NULL
;
980 ProcessList
*process_list
= control_flow_data
->process_list
;
982 birth
= process
->creation_time
;
984 /* Cannot use current process : this event happens on another process,
985 * action done by the parent. */
986 hashed_process_data
= processlist_get_process_data(process_list
,
991 if(unlikely(hashed_process_data
== NULL
))
993 * Process already been scheduled out EXIT_DEAD, not in the process list
994 * anymore. Just return.
998 /* Now, the process is in the state hash and our own process hash.
999 * We definitely can draw the items related to the ending state.
1002 draw_state_items(control_flow_data
,
1003 hashed_process_data
,
1014 /* after_process_fork_hook
1016 * Create the processlist entry for the child process. Put the last
1017 * position in x at the current time value.
1019 * @param hook_data ControlFlowData structure of the viewer.
1020 * @param call_data Event context.
1022 * This function adds items to be drawn in a queue for each process.
1025 int after_process_fork_hook(void *hook_data
, void *call_data
)
1029 event
= (LttvEvent
*) call_data
;
1031 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_process_fork") != 0)
1034 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1037 LttvTraceState
*ts
= event
->state
;
1039 #ifdef BABEL_CLEANUP
1040 LttvFilter
*filter
= control_flow_data
->filter
;
1041 if(filter
!= NULL
&& filter
->head
!= NULL
)
1042 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1043 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1047 LttTime evtime
= lttv_event_get_timestamp(event
);
1051 child_pid
= lttv_event_get_long(event
, "child_tid");
1054 /* Add process to process list (if not present) */
1055 LttvProcessState
*process_child
;
1056 HashedProcessData
*hashed_process_data_child
= NULL
;
1058 ProcessList
*process_list
= control_flow_data
->process_list
;
1060 /* Find child in the list... */
1061 process_child
= lttv_state_find_process(ts
, ANY_CPU
, child_pid
);
1062 /* It should exist, because we are after the state update. */
1063 g_assert(process_child
!= NULL
);
1065 guint trace_num
= 0; /* TODO put right */
1067 /* Cannot use current process, because this action is done by the parent
1069 hashed_process_data_child
= get_hashed_process_data(control_flow_data
,
1070 process_child
, child_pid
, trace_num
);
1073 processlist_set_ppid(process_list
, process_child
->ppid
,
1074 hashed_process_data_child
);
1075 processlist_set_tgid(process_list
, process_child
->tgid
,
1076 hashed_process_data_child
);
1080 if(likely(ltt_time_compare(hashed_process_data_child
->next_good_time
,
1083 TimeWindow time_window
=
1084 lttvwindow_get_time_window(control_flow_data
->tab
);
1087 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1088 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1090 #endif //EXTRA_CHECK
1091 Drawing_t
*drawing
= control_flow_data
->drawing
;
1092 guint width
= drawing
->width
;
1094 convert_time_to_pixels(
1100 if(likely(hashed_process_data_child
->x
.over
!= new_x
)) {
1101 hashed_process_data_child
->x
.over
= new_x
;
1102 hashed_process_data_child
->x
.over_used
= FALSE
;
1103 hashed_process_data_child
->x
.over_marked
= FALSE
;
1105 if(likely(hashed_process_data_child
->x
.middle
!= new_x
)) {
1106 hashed_process_data_child
->x
.middle
= new_x
;
1107 hashed_process_data_child
->x
.middle_used
= FALSE
;
1108 hashed_process_data_child
->x
.middle_marked
= FALSE
;
1110 if(likely(hashed_process_data_child
->x
.under
!= new_x
)) {
1111 hashed_process_data_child
->x
.under
= new_x
;
1112 hashed_process_data_child
->x
.under_used
= FALSE
;
1113 hashed_process_data_child
->x
.under_marked
= FALSE
;
1121 /* after_process_exit_hook
1123 * Create the processlist entry for the child process. Put the last
1124 * position in x at the current time value.
1126 * @param hook_data ControlFlowData structure of the viewer.
1127 * @param call_data Event context.
1129 * This function adds items to be drawn in a queue for each process.
1132 int after_process_exit_hook(void *hook_data
, void *call_data
)
1137 event
= (LttvEvent
*) call_data
;
1139 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_process_exit") != 0)
1142 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1144 LttvTraceState
*ts
= event
->state
;
1146 #ifdef BABEL_CLEANUP
1147 LttvFilter
*filter
= control_flow_data
->filter
;
1148 if(filter
!= NULL
&& filter
->head
!= NULL
)
1149 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1150 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1154 LttTime evtime
= lttv_event_get_timestamp(event
);
1156 /* Add process to process list (if not present) */
1157 //LttvProcessState *process = tfs->process;
1158 guint cpu
= lttv_traceset_get_cpuid_from_event(event
);
1159 guint trace_num
= 0; /* TODO set right trace number */
1160 LttvProcessState
*process
= ts
->running_process
[cpu
];
1162 /* It should exist, because we are after the state update. */
1163 g_assert(process
!= NULL
);
1165 guint pid
= process
->pid
;
1167 guint pl_height
= 0;
1168 HashedProcessData
*hashed_process_data
= NULL
;
1170 ProcessList
*process_list
= control_flow_data
->process_list
;
1172 birth
= process
->creation_time
;
1174 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
) ){
1175 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
1177 hashed_process_data
= get_hashed_process_data(control_flow_data
,
1178 process
, ppid
, trace_num
);
1181 /* Set the current process */
1182 process_list
->current_hash_data
[trace_num
][process
->cpu
] =
1183 hashed_process_data
;
1186 if(unlikely(ltt_time_compare(hashed_process_data
->next_good_time
,
1189 TimeWindow time_window
=
1190 lttvwindow_get_time_window(control_flow_data
->tab
);
1193 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1194 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1196 #endif //EXTRA_CHECK
1197 Drawing_t
*drawing
= control_flow_data
->drawing
;
1198 guint width
= drawing
->width
;
1200 convert_time_to_pixels(
1205 if(unlikely(hashed_process_data
->x
.middle
!= new_x
)) {
1206 hashed_process_data
->x
.middle
= new_x
;
1207 hashed_process_data
->x
.middle_used
= FALSE
;
1208 hashed_process_data
->x
.middle_marked
= FALSE
;
1216 /* Get the filename of the process to print */
1217 int after_fs_exec_hook(void *hook_data
, void *call_data
)
1219 #ifdef BABEL_CLEANUP
1220 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
1221 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
1222 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1224 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
1226 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
1228 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
1231 e
= ltt_tracefile_get_event(tfc
->tf
);
1233 LttvFilter
*filter
= control_flow_data
->filter
;
1234 if(filter
!= NULL
&& filter
->head
!= NULL
)
1235 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1236 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1239 guint cpu
= tfs
->cpu
;
1240 guint trace_num
= ts
->parent
.index
;
1241 LttvProcessState
*process
= ts
->running_process
[cpu
];
1242 g_assert(process
!= NULL
);
1244 guint pid
= process
->pid
;
1246 /* Well, the process_out existed : we must get it in the process hash
1247 * or add it, and draw its items.
1249 /* Add process to process list (if not present) */
1250 guint pl_height
= 0;
1251 HashedProcessData
*hashed_process_data
= NULL
;
1252 ProcessList
*process_list
= control_flow_data
->process_list
;
1253 LttTime birth
= process
->creation_time
;
1255 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
)) {
1256 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
1258 hashed_process_data
= get_hashed_process_data(control_flow_data
,
1259 process
, pid
, trace_num
);
1260 /* Set the current process */
1261 process_list
->current_hash_data
[trace_num
][process
->cpu
] =
1262 hashed_process_data
;
1265 processlist_set_name(process_list
, process
->name
, hashed_process_data
);
1267 #endif //babel_cleanup
1272 /* after_event_enum_process_hook
1274 * Create the processlist entry for the child process. Put the last
1275 * position in x at the current time value.
1277 * @param hook_data ControlFlowData structure of the viewer.
1278 * @param call_data Event context.
1280 * This function adds items to be drawn in a queue for each process.
1283 int after_event_enum_process_hook(void *hook_data
, void *call_data
)
1287 event
= (LttvEvent
*) call_data
;
1289 if (strcmp(lttv_traceset_get_name_from_event(event
),"lttng_statedump_process_state") != 0)
1292 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1295 LttvTraceState
*ts
= event
->state
;
1297 guint first_cpu
, nb_cpus
, cpu
;
1299 #ifdef BABEL_CLEANUP
1300 LttvFilter
*filter
= control_flow_data
->filter
;
1301 if(filter
!= NULL
&& filter
->head
!= NULL
)
1302 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1303 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1306 /* Add process to process list (if not present) */
1307 LttvProcessState
*process_in
;
1308 HashedProcessData
*hashed_process_data_in
= NULL
;
1310 ProcessList
*process_list
= control_flow_data
->process_list
;
1311 guint trace_num
= 0; /* TODO put right trace number */
1315 pid_in
= lttv_event_get_long(event
, "tid");
1320 nb_cpus
= lttv_trace_get_num_cpu(ts
->trace
);
1322 first_cpu
= ANY_CPU
;
1323 nb_cpus
= ANY_CPU
+1;
1326 for(cpu
= first_cpu
; cpu
< nb_cpus
; cpu
++) {
1327 /* Find process pid_in in the list... */
1328 process_in
= lttv_state_find_process(ts
, cpu
, pid_in
);
1329 //process_in = tfs->process;
1330 //guint cpu = tfs->cpu;
1331 //guint trace_num = ts->parent.index;
1332 //process_in = ts->running_process[cpu];
1333 /* It should exist, because we are after the state update. */
1335 //g_assert(process_in != NULL);
1336 #endif //EXTRA_CHECK
1338 hashed_process_data_in
= get_hashed_process_data(control_flow_data
,
1339 process_in
, pid_in
, trace_num
);
1341 processlist_set_name(process_list
, process_in
->name
,
1342 hashed_process_data_in
);
1343 processlist_set_ppid(process_list
, process_in
->ppid
,
1344 hashed_process_data_in
);
1345 processlist_set_tgid(process_list
, process_in
->tgid
,
1346 hashed_process_data_in
);
1353 gint
update_time_window_hook(void *hook_data
, void *call_data
)
1355 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1357 Drawing_t
*drawing
= control_flow_data
->drawing
;
1358 ProcessList
*process_list
= control_flow_data
->process_list
;
1360 const TimeWindowNotifyData
*time_window_nofify_data
=
1361 ((const TimeWindowNotifyData
*)call_data
);
1363 TimeWindow
*old_time_window
=
1364 time_window_nofify_data
->old_time_window
;
1365 TimeWindow
*new_time_window
=
1366 time_window_nofify_data
->new_time_window
;
1368 /* Update the ruler */
1369 drawing_update_ruler(control_flow_data
->drawing
,
1373 /* Two cases : zoom in/out or scrolling */
1375 /* In order to make sure we can reuse the old drawing, the scale must
1376 * be the same and the new time interval being partly located in the
1377 * currently shown time interval. (reuse is only for scrolling)
1380 g_info("Old time window HOOK : %lu, %lu to %lu, %lu",
1381 old_time_window
->start_time
.tv_sec
,
1382 old_time_window
->start_time
.tv_nsec
,
1383 old_time_window
->time_width
.tv_sec
,
1384 old_time_window
->time_width
.tv_nsec
);
1386 g_info("New time window HOOK : %lu, %lu to %lu, %lu",
1387 new_time_window
->start_time
.tv_sec
,
1388 new_time_window
->start_time
.tv_nsec
,
1389 new_time_window
->time_width
.tv_sec
,
1390 new_time_window
->time_width
.tv_nsec
);
1392 if( new_time_window
->time_width
.tv_sec
== old_time_window
->time_width
.tv_sec
1393 && new_time_window
->time_width
.tv_nsec
== old_time_window
->time_width
.tv_nsec
)
1395 /* Same scale (scrolling) */
1396 g_info("scrolling");
1397 LttTime
*ns
= &new_time_window
->start_time
;
1398 LttTime
*os
= &old_time_window
->start_time
;
1399 LttTime old_end
= old_time_window
->end_time
;
1400 LttTime new_end
= new_time_window
->end_time
;
1402 //if(ns<os+w && os+w<ns+w)
1403 //if(ns<old_end && os<ns)
1404 if(ltt_time_compare(*ns
, old_end
) == -1
1405 && ltt_time_compare(*os
, *ns
) == -1)
1407 g_info("scrolling near right");
1408 /* Scroll right, keep right part of the screen */
1410 guint width
= control_flow_data
->drawing
->width
;
1411 convert_time_to_pixels(
1417 /* Copy old data to new location */
1418 copy_pixmap_region(process_list
,
1420 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1424 control_flow_data
->drawing
->width
-x
+SAFETY
, -1);
1426 if(drawing
->damage_begin
== drawing
->damage_end
)
1427 drawing
->damage_begin
= control_flow_data
->drawing
->width
-x
;
1429 drawing
->damage_begin
= 0;
1431 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1433 /* Clear the data request background, but not SAFETY */
1434 rectangle_pixmap(process_list
,
1435 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1437 drawing
->damage_begin
+SAFETY
, 0,
1438 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1440 gtk_widget_queue_draw(drawing
->drawing_area
);
1441 //gtk_widget_queue_draw_area (drawing->drawing_area,
1443 // control_flow_data->drawing->width,
1444 // control_flow_data->drawing->height);
1446 /* Get new data for the rest. */
1447 drawing_data_request(control_flow_data
->drawing
,
1448 drawing
->damage_begin
, 0,
1449 drawing
->damage_end
- drawing
->damage_begin
,
1450 control_flow_data
->drawing
->height
);
1453 //if(ns<os && os<ns+w)
1454 //if(ns<os && os<new_end)
1455 if(ltt_time_compare(*ns
,*os
) == -1
1456 && ltt_time_compare(*os
,new_end
) == -1)
1458 g_info("scrolling near left");
1459 /* Scroll left, keep left part of the screen */
1461 guint width
= control_flow_data
->drawing
->width
;
1462 convert_time_to_pixels(
1468 /* Copy old data to new location */
1469 copy_pixmap_region (process_list
,
1471 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1477 if(drawing
->damage_begin
== drawing
->damage_end
)
1478 drawing
->damage_end
= x
;
1480 drawing
->damage_end
=
1481 control_flow_data
->drawing
->width
;
1483 drawing
->damage_begin
= 0;
1485 rectangle_pixmap (process_list
,
1486 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1488 drawing
->damage_begin
, 0,
1489 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1492 gtk_widget_queue_draw(drawing
->drawing_area
);
1493 //gtk_widget_queue_draw_area (drawing->drawing_area,
1495 // control_flow_data->drawing->width,
1496 // control_flow_data->drawing->height);
1499 /* Get new data for the rest. */
1500 drawing_data_request(control_flow_data
->drawing
,
1501 drawing
->damage_begin
, 0,
1502 drawing
->damage_end
- drawing
->damage_begin
,
1503 control_flow_data
->drawing
->height
);
1506 if(ltt_time_compare(*ns
,*os
) == 0)
1508 g_info("not scrolling");
1510 g_info("scrolling far");
1511 /* Cannot reuse any part of the screen : far jump */
1514 rectangle_pixmap (process_list
,
1515 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1518 control_flow_data
->drawing
->width
+SAFETY
, // do not overlap
1521 //gtk_widget_queue_draw_area (drawing->drawing_area,
1523 // control_flow_data->drawing->width,
1524 // control_flow_data->drawing->height);
1525 gtk_widget_queue_draw(drawing
->drawing_area
);
1527 drawing
->damage_begin
= 0;
1528 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1530 drawing_data_request(control_flow_data
->drawing
,
1532 control_flow_data
->drawing
->width
,
1533 control_flow_data
->drawing
->height
);
1539 /* Different scale (zoom) */
1542 rectangle_pixmap (process_list
,
1543 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1546 control_flow_data
->drawing
->width
+SAFETY
, // do not overlap
1549 //gtk_widget_queue_draw_area (drawing->drawing_area,
1551 // control_flow_data->drawing->width,
1552 // control_flow_data->drawing->height);
1553 gtk_widget_queue_draw(drawing
->drawing_area
);
1555 drawing
->damage_begin
= 0;
1556 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1558 drawing_data_request(control_flow_data
->drawing
,
1560 control_flow_data
->drawing
->width
,
1561 control_flow_data
->drawing
->height
);
1564 /* Update directly when scrolling */
1565 gdk_window_process_updates(control_flow_data
->drawing
->drawing_area
->window
,
1571 gint
traceset_notify(void *hook_data
, void *call_data
)
1573 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1574 Drawing_t
*drawing
= control_flow_data
->drawing
;
1576 if(unlikely(drawing
->gc
== NULL
)) {
1579 if(drawing
->dotted_gc
== NULL
) {
1583 drawing_clear(control_flow_data
->drawing
);
1584 processlist_clear(control_flow_data
->process_list
);
1585 gtk_widget_set_size_request(
1586 control_flow_data
->drawing
->drawing_area
,
1587 -1, processlist_get_height(control_flow_data
->process_list
));
1588 redraw_notify(control_flow_data
, NULL
);
1590 request_background_data(control_flow_data
);
1595 gint
redraw_notify(void *hook_data
, void *call_data
)
1597 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1598 Drawing_t
*drawing
= control_flow_data
->drawing
;
1599 GtkWidget
*widget
= drawing
->drawing_area
;
1601 drawing
->damage_begin
= 0;
1602 drawing
->damage_end
= drawing
->width
;
1604 /* fun feature, to be separated someday... */
1605 drawing_clear(control_flow_data
->drawing
);
1606 processlist_clear(control_flow_data
->process_list
);
1607 gtk_widget_set_size_request(
1608 control_flow_data
->drawing
->drawing_area
,
1609 -1, processlist_get_height(control_flow_data
->process_list
));
1611 rectangle_pixmap (control_flow_data
->process_list
,
1612 widget
->style
->black_gc
,
1615 drawing
->alloc_width
,
1618 gtk_widget_queue_draw(drawing
->drawing_area
);
1620 if(drawing
->damage_begin
< drawing
->damage_end
)
1622 drawing_data_request(drawing
,
1623 drawing
->damage_begin
,
1625 drawing
->damage_end
-drawing
->damage_begin
,
1629 //gtk_widget_queue_draw_area(drawing->drawing_area,
1632 // drawing->height);
1638 gint
continue_notify(void *hook_data
, void *call_data
)
1640 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1641 Drawing_t
*drawing
= control_flow_data
->drawing
;
1643 //g_assert(widget->allocation.width == drawing->damage_end);
1645 if(drawing
->damage_begin
< drawing
->damage_end
)
1647 drawing_data_request(drawing
,
1648 drawing
->damage_begin
,
1650 drawing
->damage_end
-drawing
->damage_begin
,
1658 gint
update_current_time_hook(void *hook_data
, void *call_data
)
1661 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
1663 LttTime current_time
= *((LttTime
*)call_data
);
1665 TimeWindow time_window
=
1666 lttvwindow_get_time_window(control_flow_data
->tab
);
1668 LttTime time_begin
= time_window
.start_time
;
1669 LttTime width
= time_window
.time_width
;
1672 guint64 time_ll
= ltt_time_to_uint64(width
);
1673 time_ll
= time_ll
>> 1; /* divide by two */
1674 half_width
= ltt_time_from_uint64(time_ll
);
1676 LttTime time_end
= ltt_time_add(time_begin
, width
);
1678 LttvTraceset
* ts
= lttvwindow_get_traceset(control_flow_data
->tab
);
1680 TimeInterval time_span
= lttv_traceset_get_time_span_real(ts
);
1681 LttTime trace_start
= time_span
.start_time
;
1682 LttTime trace_end
= time_span
.end_time
;
1684 g_info("New current time HOOK : %lu, %lu", current_time
.tv_sec
,
1685 current_time
.tv_nsec
);
1689 /* If current time is inside time interval, just move the highlight
1692 /* Else, we have to change the time interval. We have to tell it
1693 * to the main window. */
1694 /* The time interval change will take care of placing the current
1695 * time at the center of the visible area, or nearest possible if we are
1696 * at one end of the trace. */
1699 if(ltt_time_compare(current_time
, time_begin
) < 0)
1701 TimeWindow new_time_window
;
1703 if(ltt_time_compare(current_time
,
1704 ltt_time_add(trace_start
,half_width
)) < 0)
1705 time_begin
= trace_start
;
1707 time_begin
= ltt_time_sub(current_time
,half_width
);
1709 new_time_window
.start_time
= time_begin
;
1710 new_time_window
.time_width
= width
;
1711 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1712 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1714 lttvwindow_report_time_window(control_flow_data
->tab
, new_time_window
);
1716 else if(ltt_time_compare(current_time
, time_end
) > 0)
1718 TimeWindow new_time_window
;
1720 if(ltt_time_compare(current_time
, ltt_time_sub(trace_end
, half_width
)) > 0)
1721 time_begin
= ltt_time_sub(trace_end
,width
);
1723 time_begin
= ltt_time_sub(current_time
,half_width
);
1725 new_time_window
.start_time
= time_begin
;
1726 new_time_window
.time_width
= width
;
1727 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1728 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1730 lttvwindow_report_time_window(control_flow_data
->tab
, new_time_window
);
1733 gtk_widget_queue_draw(control_flow_data
->drawing
->drawing_area
);
1735 /* Update directly when scrolling */
1736 gdk_window_process_updates(control_flow_data
->drawing
->drawing_area
->window
,
1743 typedef struct _ClosureData
{
1744 EventsRequest
*events_request
;
1750 void draw_closure(gpointer key
, gpointer value
, gpointer user_data
)
1753 ProcessInfo
*process_info
= (ProcessInfo
*)key
;
1754 HashedProcessData
*hashed_process_data
= (HashedProcessData
*)value
;
1755 ClosureData
*closure_data
= (ClosureData
*)user_data
;
1757 EventsRequest
*events_request
= closure_data
->events_request
;
1758 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1759 LttvTraceset
*ts
= lttvwindow_get_traceset(control_flow_data
->tab
);
1762 LttTime evtime
= closure_data
->end_time
;
1764 gboolean dodraw
= TRUE
;
1767 /* For the process */
1768 /* First, check if the current process is in the state computation
1769 * process list. If it is there, that means we must add it right now and
1770 * draw items from the beginning of the read for it. If it is not
1771 * present, it's a new process and it was not present : it will
1772 * be added after the state update. */
1774 g_assert(lttv_traceset_number(tsc
->ts
) > 0);
1775 #endif //EXTRA_CHECK
1776 //TODO Fdeslauriers 2012-07-17: adapt for multiple traces
1777 LttvTrace
*trace
= lttv_traceset_get(ts
,0);
1778 LttvTraceState
*trace_state
= trace
->state
;
1781 //FIXME : optimize data structures.
1782 LttvTracefileState
*tfs
;
1783 LttvTracefileContext
*tfc
;
1785 for(i
=0;i
<tc
->tracefiles
->len
;i
++) {
1786 tfc
= g_array_index(tc
->tracefiles
, LttvTracefileContext
*, i
);
1787 if(ltt_tracefile_name(tfc
->tf
) == LTT_NAME_CPU
1788 && tfs
->cpu
== process_info
->cpu
)
1792 g_assert(i
<tc
->tracefiles
->len
);
1793 tfs
= LTTV_TRACEFILE_STATE(tfc
);
1795 // LttvTracefileState *tfs =ts
1796 // (LttvTracefileState*)tsc->traces[process_info->trace_num]->
1797 // tracefiles[process_info->cpu];
1799 LttvProcessState
*process
;
1800 process
= lttv_state_find_process(trace_state
, process_info
->cpu
,
1803 if(unlikely(process
!= NULL
)) {
1804 #ifdef BABEL_CLEANUP
1805 LttvFilter
*filter
= control_flow_data
->filter
;
1806 if(filter
!= NULL
&& filter
->head
!= NULL
)
1807 if(!lttv_filter_tree_parse(filter
->head
,NULL
,NULL
,
1808 tc
->t
,NULL
,process
,tc
))
1810 #endif //babel_cleanup
1811 /* Only draw for processes that are currently in the trace states */
1814 /* Should be alike when background info is ready */
1815 if(control_flow_data
->background_info_waiting
==0)
1816 g_assert(ltt_time_compare(process
->creation_time
,
1817 process_info
->birth
) == 0);
1818 #endif //EXTRA_CHECK
1820 /* Now, the process is in the state hash and our own process hash.
1821 * We definitely can draw the items related to the ending state.
1824 if(unlikely(ltt_time_compare(hashed_process_data
->next_good_time
,
1827 TimeWindow time_window
=
1828 lttvwindow_get_time_window(control_flow_data
->tab
);
1831 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1832 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1834 #endif //EXTRA_CHECK
1835 Drawing_t
*drawing
= control_flow_data
->drawing
;
1836 guint width
= drawing
->width
;
1838 guint x
= closure_data
->x_end
;
1840 DrawContext draw_context
;
1842 init_drawing_context(&draw_context
,
1843 hashed_process_data
,
1848 /* Jump over draw if we are at the same x position */
1849 if(x
== hashed_process_data
->x
.over
)
1853 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.over
;
1855 PropertiesLine prop_line
= prepare_execmode_line(process
);
1856 draw_line((void*)&prop_line
, (void*)&draw_context
);
1858 hashed_process_data
->x
.over
= x
;
1862 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1863 hashed_process_data
->x
.middle_used
)) {
1864 #if 0 /* do not mark closure : not missing information */
1865 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
1866 /* Draw collision indicator */
1867 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1868 gdk_draw_point(drawing
->pixmap
,
1872 hashed_process_data
->x
.middle_marked
= TRUE
;
1877 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1880 PropertiesLine prop_line
= prepare_s_e_line(process
);
1881 draw_line((void*)&prop_line
, (void*)&draw_context
);
1884 /* become the last x position */
1885 if(likely(x
!= hashed_process_data
->x
.middle
)) {
1886 hashed_process_data
->x
.middle
= x
;
1887 /* but don't use the pixel */
1888 hashed_process_data
->x
.middle_used
= FALSE
;
1890 /* Calculate the next good time */
1891 convert_pixels_to_time(width
, x
+1, time_window
,
1892 &hashed_process_data
->next_good_time
);
1901 int before_chunk(void *hook_data
, void *call_data
)
1904 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1905 LttvTraceset
*ts
= (LttvTraceset
*)call_data
;
1907 /* Desactivate sort */
1908 gtk_tree_sortable_set_sort_column_id(
1909 GTK_TREE_SORTABLE(cfd
->process_list
->list_store
),
1911 GTK_SORT_ASCENDING
);
1913 drawing_chunk_begin(events_request
, ts
);
1918 int before_request(void *hook_data
, void *call_data
)
1921 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1923 drawing_data_request_begin(events_request
);
1930 void draw_closing_lines(ControlFlowData
*control_flow_data
,
1931 EventsRequest
* events_request
)
1933 ProcessList
*process_list
= control_flow_data
->process_list
;
1936 ClosureData closure_data
;
1937 closure_data
.events_request
= events_request
;
1938 closure_data
.end_time
= events_request
->end_time
;
1940 TimeWindow time_window
=
1941 lttvwindow_get_time_window(control_flow_data
->tab
);
1942 guint width
= control_flow_data
->drawing
->width
;
1943 convert_time_to_pixels(
1945 events_request
->end_time
,
1947 &closure_data
.x_end
);
1950 /* Draw last items */
1951 g_hash_table_foreach(process_list
->process_hash
, draw_closure
,
1952 (void*)&closure_data
);
1955 /* Request expose */
1956 drawing_request_expose(events_request
, events_request
->end_time
);
1960 * after request is necessary in addition of after chunk in order to draw
1961 * lines until the end of the screen. after chunk just draws lines until
1968 int after_request(void *hook_data
, void *call_data
)
1971 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1972 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1974 draw_closing_lines(control_flow_data
, events_request
);
1984 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 LttvTraceset
*ts
= (LttvTraceset
*)call_data
;
1992 ProcessList
*process_list
= control_flow_data
->process_list
;
1994 guint nb_trace
= lttv_traceset_number(ts
);
1996 /* Only execute when called for the first trace's events request */
1997 if(!process_list
->current_hash_data
)
2000 for(i
= 0 ; i
< nb_trace
; i
++) {
2001 g_free(process_list
->current_hash_data
[i
]);
2003 g_free(process_list
->current_hash_data
);
2004 process_list
->current_hash_data
= NULL
;
2006 draw_closing_lines(control_flow_data
, events_request
);
2011 /* after_statedump_end
2013 * @param hook_data ControlFlowData structure of the viewer.
2014 * @param call_data Event context.
2016 * This function adds items to be drawn in a queue for each process.
2019 int before_statedump_end(void *hook_data
, void *call_data
)
2023 event
= (LttvEvent
*) call_data
;
2025 if (strcmp(lttv_traceset_get_name_from_event(event
),"lttng_statedump_end") != 0)
2028 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
2031 LttvTraceState
*ts
= event
->state
;
2034 ProcessList
*process_list
= control_flow_data
->process_list
;
2036 #ifdef BABEL_CLEANUP
2037 LttvFilter
*filter
= control_flow_data
->filter
;
2038 if(filter
!= NULL
&& filter
->head
!= NULL
)
2039 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
2040 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
2044 LttTime evtime
= lttv_event_get_timestamp(event
);
2045 #ifdef BABEL_CLEANUP
2046 ClosureData closure_data
;
2047 closure_data
.events_request
= events_request
;
2048 closure_data
.tss
= tss
;
2049 closure_data
.end_time
= evtime
;
2051 TimeWindow time_window
=
2052 lttvwindow_get_time_window(control_flow_data
->tab
);
2053 guint width
= control_flow_data
->drawing
->width
;
2054 convert_time_to_pixels(
2058 &closure_data
.x_end
);
2060 /* Draw last items */
2061 g_hash_table_foreach(process_list
->process_hash
, draw_closure
,
2062 (void*)&closure_data
);
2065 /* Reactivate sort */
2066 gtk_tree_sortable_set_sort_column_id(
2067 GTK_TREE_SORTABLE(control_flow_data
->process_list
->list_store
),
2068 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
,
2069 GTK_SORT_ASCENDING
);
2071 update_index_to_pixmap(control_flow_data
->process_list
);
2072 /* Request a full expose : drawing scrambled */
2073 gtk_widget_queue_draw(control_flow_data
->drawing
->drawing_area
);
2075 /* Request expose (updates damages zone also) */
2076 drawing_request_expose(events_request
, tss
, evtime
);