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
);
120 LttvTraceState
*tstate
;
122 LttvHooks
*background_ready_hook
= lttv_hooks_new();
123 lttv_hooks_add(background_ready_hook
, background_ready
, control_flow_data
,
125 control_flow_data
->background_info_waiting
= 0;
127 for(i
=0;i
<num_traces
;i
++) {
128 trace
= lttv_traceset_get(ts
, i
);
130 if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace
)==FALSE
131 && !ts
->has_precomputed_states
) {
133 if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"),
135 /* We first remove requests that could have been done for the same
136 * information. Happens when two viewers ask for it before servicing
139 if(!lttvwindowtraces_background_request_find(trace
, "state"))
140 lttvwindowtraces_background_request_queue(
141 main_window_get_widget(control_flow_data
->tab
), trace
, "state");
142 lttvwindowtraces_background_notify_queue(control_flow_data
,
146 background_ready_hook
);
147 control_flow_data
->background_info_waiting
++;
148 } else { /* in progress */
150 lttvwindowtraces_background_notify_current(control_flow_data
,
154 background_ready_hook
);
155 control_flow_data
->background_info_waiting
++;
158 /* Data ready. By its nature, this viewer doesn't need to have
159 * its data ready hook called there, because a background
160 * request is always linked with a redraw.
166 lttv_hooks_destroy(background_ready_hook
);
173 * Event Viewer's constructor hook
175 * This constructor is given as a parameter to the menuitem and toolbar button
176 * registration. It creates the list.
177 * @param tab A pointer to the parent tab.
178 * @return The widget created.
181 h_guicontrolflow(LttvPlugin
*plugin
)
183 LttvPluginTab
*ptab
= LTTV_PLUGIN_TAB(plugin
);
184 Tab
*tab
= ptab
->tab
;
185 g_info("h_guicontrolflow, %p", tab
);
186 ControlFlowData
*control_flow_data
= guicontrolflow(ptab
);
188 control_flow_data
->tab
= tab
;
190 // Unreg done in the GuiControlFlow_Destructor
191 lttvwindow_register_traceset_notify(tab
,
195 lttvwindow_register_time_window_notify(tab
,
196 update_time_window_hook
,
198 lttvwindow_register_current_time_notify(tab
,
199 update_current_time_hook
,
201 lttvwindow_register_redraw_notify(tab
,
204 lttvwindow_register_continue_notify(tab
,
207 request_background_data(control_flow_data
);
210 return guicontrolflow_get_widget(control_flow_data
) ;
214 int event_selected_hook(void *hook_data
, void *call_data
)
216 guint
*event_number
= (guint
*) call_data
;
218 g_debug("DEBUG : event selected by main window : %u", *event_number
);
223 /* Function that selects the color of status&exemode line */
224 static inline PropertiesLine
prepare_s_e_line(LttvProcessState
*process
)
226 PropertiesLine prop_line
;
227 prop_line
.line_width
= STATE_LINE_WIDTH
;
228 prop_line
.style
= GDK_LINE_SOLID
;
229 prop_line
.y
= MIDDLE
;
230 //GdkColormap *colormap = gdk_colormap_get_system();
232 if(process
->state
->s
== LTTV_STATE_RUN
) {
233 if(process
->state
->t
== LTTV_STATE_USER_MODE
)
234 prop_line
.color
= drawing_colors
[COL_RUN_USER_MODE
];
235 else if(process
->state
->t
== LTTV_STATE_SYSCALL
)
236 prop_line
.color
= drawing_colors
[COL_RUN_SYSCALL
];
237 else if(process
->state
->t
== LTTV_STATE_TRAP
)
238 prop_line
.color
= drawing_colors
[COL_RUN_TRAP
];
239 else if(process
->state
->t
== LTTV_STATE_IRQ
)
240 prop_line
.color
= drawing_colors
[COL_RUN_IRQ
];
241 else if(process
->state
->t
== LTTV_STATE_SOFT_IRQ
)
242 prop_line
.color
= drawing_colors
[COL_RUN_SOFT_IRQ
];
243 else if(process
->state
->t
== LTTV_STATE_MAYBE_SYSCALL
)
244 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
245 else if(process
->state
->t
== LTTV_STATE_MAYBE_USER_MODE
)
246 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
247 else if(process
->state
->t
== LTTV_STATE_MAYBE_TRAP
)
248 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
249 else if(process
->state
->t
== LTTV_STATE_MODE_UNKNOWN
)
250 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
252 g_assert(FALSE
); /* RUNNING MODE UNKNOWN */
253 } else if(process
->state
->s
== LTTV_STATE_WAIT
) {
254 /* We don't show if we wait while in user mode, trap, irq or syscall */
255 prop_line
.color
= drawing_colors
[COL_WAIT
];
256 } else if(process
->state
->s
== LTTV_STATE_WAIT_CPU
) {
257 /* We don't show if we wait for CPU while in user mode, trap, irq
259 prop_line
.color
= drawing_colors
[COL_WAIT_CPU
];
260 } else if(process
->state
->s
== LTTV_STATE_ZOMBIE
) {
261 prop_line
.color
= drawing_colors
[COL_ZOMBIE
];
262 } else if(process
->state
->s
== LTTV_STATE_WAIT_FORK
) {
263 prop_line
.color
= drawing_colors
[COL_WAIT_FORK
];
264 } else if(process
->state
->s
== LTTV_STATE_EXIT
) {
265 prop_line
.color
= drawing_colors
[COL_EXIT
];
266 } else if(process
->state
->s
== LTTV_STATE_UNNAMED
) {
267 prop_line
.color
= drawing_colors
[COL_UNNAMED
];
268 } else if(process
->state
->s
== LTTV_STATE_DEAD
) {
269 prop_line
.color
= drawing_colors
[COL_DEAD
];
271 g_critical("unknown state : %s", g_quark_to_string(process
->state
->s
));
272 g_assert(FALSE
); /* UNKNOWN STATE */
279 HashedProcessData
*get_hashed_process_data(ControlFlowData
*control_flow_data
,
280 LttvProcessState
*process
,
284 HashedProcessData
*hashed_process_data
= NULL
;
285 ProcessList
*process_list
= control_flow_data
->process_list
;
286 LttTime birth
= process
->creation_time
;
289 hashed_process_data
= processlist_get_process_data(process_list
,
294 if(hashed_process_data
== NULL
)
296 g_assert(pid
== 0 || pid
!= process
->ppid
);
297 ProcessInfo
*process_info
;
298 Drawing_t
*drawing
= control_flow_data
->drawing
;
299 /* Process not present */
300 processlist_add(process_list
,
311 &hashed_process_data
);
312 gtk_widget_set_size_request(drawing
->drawing_area
,
315 gtk_widget_queue_draw(drawing
->drawing_area
);
317 return hashed_process_data
;
320 void init_drawing_context(DrawContext
*draw_context
,
321 HashedProcessData
*hashed_process_data
,
326 draw_context
->drawable
= hashed_process_data
->pixmap
;
327 draw_context
->gc
= drawing
->gc
;
328 draw_context
->pango_layout
= drawing
->pango_layout
;
329 draw_context
->drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
330 draw_context
->drawinfo
.end
.x
= x
;
332 draw_context
->drawinfo
.y
.over
= 1;
333 draw_context
->drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
334 draw_context
->drawinfo
.y
.under
= hashed_process_data
->height
;
336 draw_context
->drawinfo
.start
.offset
.over
= 0;
337 draw_context
->drawinfo
.start
.offset
.middle
= 0;
338 draw_context
->drawinfo
.start
.offset
.under
= 0;
339 draw_context
->drawinfo
.end
.offset
.over
= 0;
340 draw_context
->drawinfo
.end
.offset
.middle
= 0;
341 draw_context
->drawinfo
.end
.offset
.under
= 0;
345 void draw_state_line(HashedProcessData
*hashed_process_data
,
346 LttvProcessState
*process
,
349 TimeWindow time_window
)
351 DrawContext draw_context
;
352 guint width
= drawing
->width
;
354 init_drawing_context(&draw_context
,
361 PropertiesLine prop_line
= prepare_s_e_line(process
);
362 draw_line((void*)&prop_line
, (void*)&draw_context
);
364 /* become the last x position */
365 hashed_process_data
->x
.middle
= x
;
366 hashed_process_data
->x
.middle_used
= TRUE
;
367 hashed_process_data
->x
.middle_marked
= FALSE
;
369 /* Calculate the next good time */
370 convert_pixels_to_time(width
, x
+1, time_window
,
371 &hashed_process_data
->next_good_time
);
375 void draw_state_items(ControlFlowData
*control_flow_data
,
376 HashedProcessData
*hashed_process_data
,
377 LttvProcessState
*process
,
382 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
385 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
386 TimeWindow time_window
=
387 lttvwindow_get_time_window(control_flow_data
->tab
);
390 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
391 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
394 Drawing_t
*drawing
= control_flow_data
->drawing
;
395 guint width
= drawing
->width
;
397 convert_time_to_pixels(
403 /* Draw collision indicator */
404 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
405 gdk_draw_point(hashed_process_data
->pixmap
,
408 COLLISION_POSITION(hashed_process_data
->height
));
409 hashed_process_data
->x
.middle_marked
= TRUE
;
412 TimeWindow time_window
=
413 lttvwindow_get_time_window(control_flow_data
->tab
);
416 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
417 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
420 Drawing_t
*drawing
= control_flow_data
->drawing
;
421 guint width
= drawing
->width
;
424 convert_time_to_pixels(
431 /* Jump over draw if we are at the same x position */
432 if(unlikely(x
== hashed_process_data
->x
.middle
&&
433 hashed_process_data
->x
.middle_used
))
435 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
436 /* Draw collision indicator */
437 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
438 gdk_draw_point(hashed_process_data
->pixmap
,
441 COLLISION_POSITION(hashed_process_data
->height
));
442 hashed_process_data
->x
.middle_marked
= TRUE
;
447 draw_state_line(hashed_process_data
,
457 /* Before try-wake-up hook. A process is being woken; we need to draw its line up to this point in time
458 in that colour. This is basically like exec-state, but the change applies to a process other than that
459 which is currently running. */
461 int before_trywakeup_hook(void *hook_data
, void *call_data
)
466 event
= (LttvEvent
*) call_data
;
467 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_wakeup") != 0)
470 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
472 LttvTraceState
*ts
= event
->state
;;
475 LttTime evtime
= lttv_event_get_timestamp(event
);
477 LttvFilter
*filter
= control_flow_data
->filter
;
483 woken_pid
= lttv_event_get_long(event
, "tid");
484 woken_cpu
= lttv_event_get_long(event
, "target_cpu");
487 if(!filter
|| !filter
->head
||
488 lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
489 tfc
->t_context
->t
,tfc
,NULL
,NULL
)) {
493 /* First, check if the woken process is in the state computation
494 * process list. If it is there, that means we must add it right now and
495 * draw items from the beginning of the read for it. If it is not
496 * present, it's a new process and it was not present : it will
497 * be added after the state update. TOCHECK: What does that last para mean? */
498 guint trace_num
= lttv_traceset_get_trace_index_from_event(event
);
499 LttvProcessState
*process
= lttv_state_find_process(ts
, woken_cpu
, woken_pid
);
501 if(process
!= NULL
) {
502 /* Well, the woken process existed : we must get it in the process hash
503 * or add it, and draw its items.
505 /* Add process to process list (if not present) */
507 HashedProcessData
*hashed_process_data
= get_hashed_process_data(control_flow_data
, process
, woken_pid
, trace_num
);
509 /* Now, the process is in the state hash and our own process hash.
510 * We definitely can draw the items related to the ending state.
513 draw_state_items(control_flow_data
,
528 /* before_schedchange_hook
530 * This function basically draw lines and icons. Two types of lines are drawn :
531 * one small (3 pixels?) representing the state of the process and the second
532 * type is thicker (10 pixels?) representing on which CPU a process is running
533 * (and this only in running state).
535 * Extremums of the lines :
536 * x_min : time of the last event context for this process kept in memory.
537 * x_max : time of the current event.
538 * y : middle of the process in the process list. The process is found in the
539 * list, therefore is it's position in pixels.
541 * The choice of lines'color is defined by the context of the last event for this
546 int before_schedchange_hook(void *hook_data
, void *call_data
)
551 LttvProcessState
*process
;
553 //LttvProcessState *old_process = ts->running_process[cpu];
555 guint pid_in
, pid_out
;
558 event
= (LttvEvent
*) call_data
;
559 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_switch") != 0)
562 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
565 /* we are in a schedchange, before the state update. We must draw the
566 * items corresponding to the state before it changes : now is the right
569 cpu
= lttv_traceset_get_cpuid_from_event(event
);
572 pid_out
= lttv_event_get_long(event
, "prev_tid");
573 pid_in
= lttv_event_get_long(event
, "next_tid");
574 state_out
= lttv_event_get_long(event
, "prev_state");
575 guint trace_number
= lttv_traceset_get_trace_index_from_event(event
);
577 process
= lttv_state_find_process(ts
,cpu
,pid_out
);
578 evtime
= lttv_event_get_timestamp(event
);
579 /* For the pid_out */
580 /* First, check if the current process is in the state computation
581 * process list. If it is there, that means we must add it right now and
582 * draw items from the beginning of the read for it. If it is not
583 * present, it's a new process and it was not present : it will
584 * be added after the state update. */
586 /* unknown state, bad current pid */
588 if(process
!= NULL
) {
589 /* Well, the process_out existed : we must get it in the process hash
590 * or add it, and draw its items.
592 /* Add process to process list (if not present) */
594 HashedProcessData
*hashed_process_data
= get_hashed_process_data(control_flow_data
, process
, pid_out
, trace_number
);
596 /* Now, the process is in the state hash and our own process hash.
597 * We definitely can draw the items related to the ending state.
600 draw_state_items(control_flow_data
,
607 /* First, check if the current process is in the state computation
608 * process list. If it is there, that means we must add it right now and
609 * draw items from the beginning of the read for it. If it is not
610 * present, it's a new process and it was not present : it will
611 * be added after the state update. */
612 process
= lttv_state_find_process(ts
,cpu
,pid_in
);
614 if(process
!= NULL
) {
615 /* Well, the process existed : we must get it in the process hash
616 * or add it, and draw its items.
618 /* Add process to process list (if not present) */
620 HashedProcessData
*hashed_process_data
= get_hashed_process_data(control_flow_data
, process
, pid_in
, trace_number
);
622 //We could set the current process and hash here, but will be done
623 //by after schedchange hook
625 /* Now, the process is in the state hash and our own process hash.
626 * We definitely can draw the items related to the ending state.
628 draw_state_items(control_flow_data
,
634 g_warning("Cannot find pid_in in schedchange %u at %u.%u", pid_in
, evtime
.tv_sec
, evtime
.tv_nsec
);
636 tfc
->target_pid
= target_pid_saved
;
637 #endif //babel_cleanup
645 GString
*string
= g_string_new("");;
646 gboolean field_names
= TRUE
, state
= TRUE
;
648 lttv_event_to_string(e
, tfc
->tf
, string
, TRUE
, field_names
, tfs
);
649 g_string_append_printf(string
,"\n");
652 g_string_append_printf(string
, " %s",
653 g_quark_to_string(tfs
->process
->state
->s
));
656 g_info("%s",string
->str
);
658 g_string_free(string
, TRUE
);
660 /* End of text dump */
665 /* after_schedchange_hook
667 * The draw after hook is called by the reading API to have a
668 * particular event drawn on the screen.
669 * @param hook_data ControlFlowData structure of the viewer.
670 * @param call_data Event context.
672 * This function adds items to be drawn in a queue for each process.
675 int after_schedchange_hook(void *hook_data
, void *call_data
)
679 event
= (LttvEvent
*) call_data
;
681 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_switch") != 0)
684 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
687 LttvTraceState
*ts
= event
->state
;
690 LttvFilter
*filter
= control_flow_data
->filter
;
692 LttTime evtime
= lttv_event_get_timestamp(event
);
694 /* Add process to process list (if not present) */
695 LttvProcessState
*process_in
;
696 HashedProcessData
*hashed_process_data_in
= NULL
;
698 ProcessList
*process_list
= control_flow_data
->process_list
;
702 pid_in
= lttv_event_get_long(event
, "next_tid");
706 if(!filter
|| !filter
->head
||
707 lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
708 tfc
->t_context
->t
,tfc
,NULL
,NULL
)) {
712 /* Find process pid_in in the list... */
713 //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in);
714 //process_in = tfs->process;
715 guint cpu
= lttv_traceset_get_cpuid_from_event(event
);
716 guint trace_num
= lttv_traceset_get_trace_index_from_event(event
);
717 process_in
= ts
->running_process
[cpu
];
718 /* It should exist, because we are after the state update. */
720 g_assert(process_in
!= NULL
);
722 hashed_process_data_in
= get_hashed_process_data(control_flow_data
, process_in
, pid_in
, trace_num
);
724 /* Set the current process */
725 process_list
->current_hash_data
[trace_num
][process_in
->cpu
] =
726 hashed_process_data_in
;
728 if(ltt_time_compare(hashed_process_data_in
->next_good_time
,
731 TimeWindow time_window
=
732 lttvwindow_get_time_window(control_flow_data
->tab
);
735 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
736 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
739 Drawing_t
*drawing
= control_flow_data
->drawing
;
740 guint width
= drawing
->width
;
743 convert_time_to_pixels(
749 if(hashed_process_data_in
->x
.middle
!= new_x
) {
750 hashed_process_data_in
->x
.middle
= new_x
;
751 hashed_process_data_in
->x
.middle_used
= FALSE
;
752 hashed_process_data_in
->x
.middle_marked
= FALSE
;
763 /* before_execmode_hook
765 * This function basically draw lines and icons. Two types of lines are drawn :
766 * one small (3 pixels?) representing the state of the process and the second
767 * type is thicker (10 pixels?) representing on which CPU a process is running
768 * (and this only in running state).
770 * Extremums of the lines :
771 * x_min : time of the last event context for this process kept in memory.
772 * x_max : time of the current event.
773 * y : middle of the process in the process list. The process is found in the
774 * list, therefore is it's position in pixels.
776 * The choice of lines'color is defined by the context of the last event for this
781 int before_execmode_hook(void *hook_data
, void *call_data
)
787 LttvProcessState
*process
;
789 /* we are in a execmode, before the state update. We must draw the
790 * items corresponding to the state before it changes : now is the right
794 event
= (LttvEvent
*) call_data
;
795 if ((strncmp(lttv_traceset_get_name_from_event(event
),"sys_", sizeof("sys_") - 1) == 0)
796 ||(strcmp(lttv_traceset_get_name_from_event(event
),"exit_syscall") == 0)
797 ||(strncmp(lttv_traceset_get_name_from_event(event
),"irq_handler_",sizeof("irq_handler_") -1) == 0)
798 ||(strncmp(lttv_traceset_get_name_from_event(event
),"softirq_", sizeof("softirq_") - 1) == 0)) {
800 LttTime evtime
= lttv_event_get_timestamp(event
);
801 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
803 LttvTraceset
*traceSet
= lttvwindow_get_traceset(control_flow_data
->tab
);
805 cpu
= lttv_traceset_get_cpuid_from_event(event
);
808 guint trace_number
= lttv_traceset_get_trace_index_from_event(event
);
810 //TODO ybrosseau 2013-04-09 validate that using the running process is the right choice
811 //process = lttv_state_find_process(ts ,cpu ,pid);
812 process
= ts
->running_process
[cpu
];
814 g_assert(process
!= NULL
);
816 guint pid
= process
->pid
;
818 /* Well, the process_out existed : we must get it in the process hash
819 * or add it, and draw its items.
821 /* Add process to process list (if not present) */
822 HashedProcessData
*hashed_process_data
= NULL
;
823 ProcessList
*process_list
= control_flow_data
->process_list
;
824 if(process_list
->current_hash_data
== NULL
){//TODO fdeslauriers 2012-07-17 : should not be necessary
828 if(likely(process_list
->current_hash_data
[trace_number
][cpu
] != NULL
)) {
829 hashed_process_data
= process_list
->current_hash_data
[trace_number
][cpu
];
831 hashed_process_data
= get_hashed_process_data(control_flow_data
,
832 process
, pid
, trace_number
);
834 /* Set the current process */
835 process_list
->current_hash_data
[trace_number
][process
->cpu
] =
839 /* Now, the process is in the state hash and our own process hash.
840 * We definitely can draw the items related to the ending state.
843 draw_state_items(control_flow_data
,
853 /* before_process_exit_hook
855 * Draw lines for process event.
857 * @param hook_data ControlFlowData structure of the viewer.
858 * @param call_data Event context.
860 * This function adds items to be drawn in a queue for each process.
865 int before_process_exit_hook(void *hook_data
, void *call_data
)
870 event
= (LttvEvent
*) call_data
;
871 if (strcmp(lttv_traceset_get_name_from_event(event
),
872 "sched_process_exit") != 0)
876 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
877 LttvTraceState
*ts
= event
->state
;
880 LttvFilter
*filter
= control_flow_data
->filter
;
881 if(filter
!= NULL
&& filter
->head
!= NULL
)
882 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
883 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
887 LttTime evtime
= lttv_event_get_timestamp(event
);
889 /* Add process to process list (if not present) */
890 //LttvProcessState *process = tfs->process;
891 guint cpu
= lttv_traceset_get_cpuid_from_event(event
);
892 guint trace_num
= lttv_traceset_get_trace_index_from_event(event
);
894 LttvProcessState
*process
= ts
->running_process
[cpu
];
895 guint pid
= process
->pid
;
896 HashedProcessData
*hashed_process_data
= NULL
;
898 ProcessList
*process_list
= control_flow_data
->process_list
;
900 g_assert(process
!= NULL
);
902 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
)) {
903 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
905 hashed_process_data
= get_hashed_process_data(control_flow_data
,
906 process
, pid
, trace_num
);
909 /* Now, the process is in the state hash and our own process hash.
910 * We definitely can draw the items related to the ending state.
913 draw_state_items(control_flow_data
,
924 /* before_process_release_hook
926 * Draw lines for process event.
928 * @param hook_data ControlFlowData structure of the viewer.
929 * @param call_data Event context.
931 * This function adds items to be drawn in a queue for each process.
936 int before_process_release_hook(void *hook_data
, void *call_data
)
941 event
= (LttvEvent
*) call_data
;
943 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_process_free") != 0)
946 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
949 LttvTraceState
*ts
= event
->state
;
952 LttvFilter
*filter
= control_flow_data
->filter
;
953 if(filter
!= NULL
&& filter
->head
!= NULL
)
954 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
955 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
958 LttTime evtime
= lttv_event_get_timestamp(event
);
961 guint trace_num
= lttv_traceset_get_trace_index_from_event(event
);
965 pid
= lttv_event_get_long(event
, "tid");
968 /* Add process to process list (if not present) */
969 /* Don't care about the process if it's not in the state hash already :
970 * that means a process that has never done anything in the trace and
971 * unknown suddently gets destroyed : no state meaningful to show. */
972 LttvProcessState
*process
= lttv_state_find_process(ts
, ANY_CPU
, pid
);
974 if(process
!= NULL
) {
976 HashedProcessData
*hashed_process_data
= NULL
;
978 ProcessList
*process_list
= control_flow_data
->process_list
;
980 birth
= process
->creation_time
;
982 /* Cannot use current process : this event happens on another process,
983 * action done by the parent. */
984 hashed_process_data
= processlist_get_process_data(process_list
,
989 if(unlikely(hashed_process_data
== NULL
))
991 * Process already been scheduled out EXIT_DEAD, not in the process list
992 * anymore. Just return.
996 /* Now, the process is in the state hash and our own process hash.
997 * We definitely can draw the items related to the ending state.
1000 draw_state_items(control_flow_data
,
1001 hashed_process_data
,
1012 /* after_process_fork_hook
1014 * Create the processlist entry for the child process. Put the last
1015 * position in x at the current time value.
1017 * @param hook_data ControlFlowData structure of the viewer.
1018 * @param call_data Event context.
1020 * This function adds items to be drawn in a queue for each process.
1023 int after_process_fork_hook(void *hook_data
, void *call_data
)
1027 event
= (LttvEvent
*) call_data
;
1029 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_process_fork") != 0)
1032 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1035 LttvTraceState
*ts
= event
->state
;
1037 #ifdef BABEL_CLEANUP
1038 LttvFilter
*filter
= control_flow_data
->filter
;
1039 if(filter
!= NULL
&& filter
->head
!= NULL
)
1040 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1041 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1045 LttTime evtime
= lttv_event_get_timestamp(event
);
1049 child_pid
= lttv_event_get_long(event
, "child_tid");
1052 /* Add process to process list (if not present) */
1053 LttvProcessState
*process_child
;
1054 HashedProcessData
*hashed_process_data_child
= NULL
;
1056 ProcessList
*process_list
= control_flow_data
->process_list
;
1058 /* Find child in the list... */
1059 process_child
= lttv_state_find_process(ts
, ANY_CPU
, child_pid
);
1060 /* It should exist, because we are after the state update. */
1061 g_assert(process_child
!= NULL
);
1063 guint trace_num
= lttv_traceset_get_trace_index_from_event(event
);
1065 /* Cannot use current process, because this action is done by the parent
1067 hashed_process_data_child
= get_hashed_process_data(control_flow_data
,
1068 process_child
, child_pid
, trace_num
);
1071 processlist_set_ppid(process_list
, process_child
->ppid
,
1072 hashed_process_data_child
);
1073 processlist_set_tgid(process_list
, process_child
->tgid
,
1074 hashed_process_data_child
);
1078 if(likely(ltt_time_compare(hashed_process_data_child
->next_good_time
,
1081 TimeWindow time_window
=
1082 lttvwindow_get_time_window(control_flow_data
->tab
);
1085 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1086 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1088 #endif //EXTRA_CHECK
1089 Drawing_t
*drawing
= control_flow_data
->drawing
;
1090 guint width
= drawing
->width
;
1092 convert_time_to_pixels(
1098 if(likely(hashed_process_data_child
->x
.over
!= new_x
)) {
1099 hashed_process_data_child
->x
.over
= new_x
;
1100 hashed_process_data_child
->x
.over_used
= FALSE
;
1101 hashed_process_data_child
->x
.over_marked
= FALSE
;
1103 if(likely(hashed_process_data_child
->x
.middle
!= new_x
)) {
1104 hashed_process_data_child
->x
.middle
= new_x
;
1105 hashed_process_data_child
->x
.middle_used
= FALSE
;
1106 hashed_process_data_child
->x
.middle_marked
= FALSE
;
1108 if(likely(hashed_process_data_child
->x
.under
!= new_x
)) {
1109 hashed_process_data_child
->x
.under
= new_x
;
1110 hashed_process_data_child
->x
.under_used
= FALSE
;
1111 hashed_process_data_child
->x
.under_marked
= FALSE
;
1119 /* after_process_exit_hook
1121 * Create the processlist entry for the child process. Put the last
1122 * position in x at the current time value.
1124 * @param hook_data ControlFlowData structure of the viewer.
1125 * @param call_data Event context.
1127 * This function adds items to be drawn in a queue for each process.
1130 int after_process_exit_hook(void *hook_data
, void *call_data
)
1135 event
= (LttvEvent
*) call_data
;
1137 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_process_exit") != 0)
1140 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1142 LttvTraceState
*ts
= event
->state
;
1144 #ifdef BABEL_CLEANUP
1145 LttvFilter
*filter
= control_flow_data
->filter
;
1146 if(filter
!= NULL
&& filter
->head
!= NULL
)
1147 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1148 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1152 LttTime evtime
= lttv_event_get_timestamp(event
);
1154 /* Add process to process list (if not present) */
1155 //LttvProcessState *process = tfs->process;
1156 guint cpu
= lttv_traceset_get_cpuid_from_event(event
);
1157 guint trace_num
= lttv_traceset_get_trace_index_from_event(event
);
1158 LttvProcessState
*process
= ts
->running_process
[cpu
];
1160 /* It should exist, because we are after the state update. */
1161 g_assert(process
!= NULL
);
1163 guint pid
= process
->pid
;
1165 //guint pl_height = 0;
1166 HashedProcessData
*hashed_process_data
= NULL
;
1168 ProcessList
*process_list
= control_flow_data
->process_list
;
1170 //birth = process->creation_time;
1172 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
) ){
1173 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
1175 hashed_process_data
= get_hashed_process_data(control_flow_data
,
1176 process
, pid
, trace_num
);
1179 /* Set the current process */
1180 process_list
->current_hash_data
[trace_num
][process
->cpu
] =
1181 hashed_process_data
;
1184 if(unlikely(ltt_time_compare(hashed_process_data
->next_good_time
,
1187 TimeWindow time_window
=
1188 lttvwindow_get_time_window(control_flow_data
->tab
);
1191 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1192 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1194 #endif //EXTRA_CHECK
1195 Drawing_t
*drawing
= control_flow_data
->drawing
;
1196 guint width
= drawing
->width
;
1198 convert_time_to_pixels(
1203 if(unlikely(hashed_process_data
->x
.middle
!= new_x
)) {
1204 hashed_process_data
->x
.middle
= new_x
;
1205 hashed_process_data
->x
.middle_used
= FALSE
;
1206 hashed_process_data
->x
.middle_marked
= FALSE
;
1214 /* Get the filename of the process to print */
1215 int after_fs_exec_hook(void *hook_data
, void *call_data
)
1217 #ifdef BABEL_CLEANUP
1218 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
1219 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
1220 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1222 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
1224 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
1226 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
1229 e
= ltt_tracefile_get_event(tfc
->tf
);
1231 LttvFilter
*filter
= control_flow_data
->filter
;
1232 if(filter
!= NULL
&& filter
->head
!= NULL
)
1233 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1234 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1237 guint cpu
= tfs
->cpu
;
1238 guint trace_num
= ts
->parent
.index
;
1239 LttvProcessState
*process
= ts
->running_process
[cpu
];
1240 g_assert(process
!= NULL
);
1242 guint pid
= process
->pid
;
1244 /* Well, the process_out existed : we must get it in the process hash
1245 * or add it, and draw its items.
1247 /* Add process to process list (if not present) */
1248 guint pl_height
= 0;
1249 HashedProcessData
*hashed_process_data
= NULL
;
1250 ProcessList
*process_list
= control_flow_data
->process_list
;
1251 LttTime birth
= process
->creation_time
;
1253 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
)) {
1254 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
1256 hashed_process_data
= get_hashed_process_data(control_flow_data
,
1257 process
, pid
, trace_num
);
1258 /* Set the current process */
1259 process_list
->current_hash_data
[trace_num
][process
->cpu
] =
1260 hashed_process_data
;
1263 processlist_set_name(process_list
, process
->name
, hashed_process_data
);
1265 #endif //babel_cleanup
1270 /* after_event_enum_process_hook
1272 * Create the processlist entry for the child process. Put the last
1273 * position in x at the current time value.
1275 * @param hook_data ControlFlowData structure of the viewer.
1276 * @param call_data Event context.
1278 * This function adds items to be drawn in a queue for each process.
1281 int after_event_enum_process_hook(void *hook_data
, void *call_data
)
1285 event
= (LttvEvent
*) call_data
;
1287 if (strcmp(lttv_traceset_get_name_from_event(event
),"lttng_statedump_process_state") != 0)
1290 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1293 LttvTraceState
*ts
= event
->state
;
1295 guint first_cpu
, nb_cpus
, cpu
;
1297 #ifdef BABEL_CLEANUP
1298 LttvFilter
*filter
= control_flow_data
->filter
;
1299 if(filter
!= NULL
&& filter
->head
!= NULL
)
1300 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1301 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1304 /* Add process to process list (if not present) */
1305 LttvProcessState
*process_in
;
1306 HashedProcessData
*hashed_process_data_in
= NULL
;
1308 ProcessList
*process_list
= control_flow_data
->process_list
;
1309 guint trace_num
= lttv_traceset_get_trace_index_from_event(event
);
1313 pid_in
= lttv_event_get_long(event
, "tid");
1318 nb_cpus
= lttv_trace_get_num_cpu(ts
->trace
);
1320 first_cpu
= ANY_CPU
;
1321 nb_cpus
= ANY_CPU
+1;
1324 for(cpu
= first_cpu
; cpu
< nb_cpus
; cpu
++) {
1325 /* Find process pid_in in the list... */
1326 process_in
= lttv_state_find_process(ts
, cpu
, pid_in
);
1327 //process_in = tfs->process;
1328 //guint cpu = tfs->cpu;
1329 //guint trace_num = ts->parent.index;
1330 //process_in = ts->running_process[cpu];
1331 /* It should exist, because we are after the state update. */
1333 //g_assert(process_in != NULL);
1334 #endif //EXTRA_CHECK
1336 hashed_process_data_in
= get_hashed_process_data(control_flow_data
,
1337 process_in
, pid_in
, trace_num
);
1339 processlist_set_name(process_list
, process_in
->name
,
1340 hashed_process_data_in
);
1341 processlist_set_ppid(process_list
, process_in
->ppid
,
1342 hashed_process_data_in
);
1343 processlist_set_tgid(process_list
, process_in
->tgid
,
1344 hashed_process_data_in
);
1351 gint
update_time_window_hook(void *hook_data
, void *call_data
)
1353 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1355 Drawing_t
*drawing
= control_flow_data
->drawing
;
1356 ProcessList
*process_list
= control_flow_data
->process_list
;
1358 const TimeWindowNotifyData
*time_window_nofify_data
=
1359 ((const TimeWindowNotifyData
*)call_data
);
1361 TimeWindow
*old_time_window
=
1362 time_window_nofify_data
->old_time_window
;
1363 TimeWindow
*new_time_window
=
1364 time_window_nofify_data
->new_time_window
;
1366 /* Update the ruler */
1367 drawing_update_ruler(control_flow_data
->drawing
,
1371 /* Two cases : zoom in/out or scrolling */
1373 /* In order to make sure we can reuse the old drawing, the scale must
1374 * be the same and the new time interval being partly located in the
1375 * currently shown time interval. (reuse is only for scrolling)
1378 g_info("Old time window HOOK : %lu, %lu to %lu, %lu",
1379 old_time_window
->start_time
.tv_sec
,
1380 old_time_window
->start_time
.tv_nsec
,
1381 old_time_window
->time_width
.tv_sec
,
1382 old_time_window
->time_width
.tv_nsec
);
1384 g_info("New time window HOOK : %lu, %lu to %lu, %lu",
1385 new_time_window
->start_time
.tv_sec
,
1386 new_time_window
->start_time
.tv_nsec
,
1387 new_time_window
->time_width
.tv_sec
,
1388 new_time_window
->time_width
.tv_nsec
);
1390 if( new_time_window
->time_width
.tv_sec
== old_time_window
->time_width
.tv_sec
1391 && new_time_window
->time_width
.tv_nsec
== old_time_window
->time_width
.tv_nsec
)
1393 /* Same scale (scrolling) */
1394 g_info("scrolling");
1395 LttTime
*ns
= &new_time_window
->start_time
;
1396 LttTime
*os
= &old_time_window
->start_time
;
1397 LttTime old_end
= old_time_window
->end_time
;
1398 LttTime new_end
= new_time_window
->end_time
;
1400 //if(ns<os+w && os+w<ns+w)
1401 //if(ns<old_end && os<ns)
1402 if(ltt_time_compare(*ns
, old_end
) == -1
1403 && ltt_time_compare(*os
, *ns
) == -1)
1405 g_info("scrolling near right");
1406 /* Scroll right, keep right part of the screen */
1408 guint width
= control_flow_data
->drawing
->width
;
1409 convert_time_to_pixels(
1415 /* Copy old data to new location */
1416 copy_pixmap_region(process_list
,
1418 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1422 control_flow_data
->drawing
->width
-x
+SAFETY
, -1);
1424 if(drawing
->damage_begin
== drawing
->damage_end
)
1425 drawing
->damage_begin
= control_flow_data
->drawing
->width
-x
;
1427 drawing
->damage_begin
= 0;
1429 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1431 /* Clear the data request background, but not SAFETY */
1432 rectangle_pixmap(process_list
,
1433 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1435 drawing
->damage_begin
+SAFETY
, 0,
1436 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1438 gtk_widget_queue_draw(drawing
->drawing_area
);
1439 //gtk_widget_queue_draw_area (drawing->drawing_area,
1441 // control_flow_data->drawing->width,
1442 // control_flow_data->drawing->height);
1444 /* Get new data for the rest. */
1445 drawing_data_request(control_flow_data
->drawing
,
1446 drawing
->damage_begin
, 0,
1447 drawing
->damage_end
- drawing
->damage_begin
,
1448 control_flow_data
->drawing
->height
);
1451 //if(ns<os && os<ns+w)
1452 //if(ns<os && os<new_end)
1453 if(ltt_time_compare(*ns
,*os
) == -1
1454 && ltt_time_compare(*os
,new_end
) == -1)
1456 g_info("scrolling near left");
1457 /* Scroll left, keep left part of the screen */
1459 guint width
= control_flow_data
->drawing
->width
;
1460 convert_time_to_pixels(
1466 /* Copy old data to new location */
1467 copy_pixmap_region (process_list
,
1469 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1475 if(drawing
->damage_begin
== drawing
->damage_end
)
1476 drawing
->damage_end
= x
;
1478 drawing
->damage_end
=
1479 control_flow_data
->drawing
->width
;
1481 drawing
->damage_begin
= 0;
1483 rectangle_pixmap (process_list
,
1484 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1486 drawing
->damage_begin
, 0,
1487 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1490 gtk_widget_queue_draw(drawing
->drawing_area
);
1491 //gtk_widget_queue_draw_area (drawing->drawing_area,
1493 // control_flow_data->drawing->width,
1494 // control_flow_data->drawing->height);
1497 /* Get new data for the rest. */
1498 drawing_data_request(control_flow_data
->drawing
,
1499 drawing
->damage_begin
, 0,
1500 drawing
->damage_end
- drawing
->damage_begin
,
1501 control_flow_data
->drawing
->height
);
1504 if(ltt_time_compare(*ns
,*os
) == 0)
1506 g_info("not scrolling");
1508 g_info("scrolling far");
1509 /* Cannot reuse any part of the screen : far jump */
1512 rectangle_pixmap (process_list
,
1513 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1516 control_flow_data
->drawing
->width
+SAFETY
, // do not overlap
1519 //gtk_widget_queue_draw_area (drawing->drawing_area,
1521 // control_flow_data->drawing->width,
1522 // control_flow_data->drawing->height);
1523 gtk_widget_queue_draw(drawing
->drawing_area
);
1525 drawing
->damage_begin
= 0;
1526 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1528 drawing_data_request(control_flow_data
->drawing
,
1530 control_flow_data
->drawing
->width
,
1531 control_flow_data
->drawing
->height
);
1537 /* Different scale (zoom) */
1540 rectangle_pixmap (process_list
,
1541 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1544 control_flow_data
->drawing
->width
+SAFETY
, // do not overlap
1547 //gtk_widget_queue_draw_area (drawing->drawing_area,
1549 // control_flow_data->drawing->width,
1550 // control_flow_data->drawing->height);
1551 gtk_widget_queue_draw(drawing
->drawing_area
);
1553 drawing
->damage_begin
= 0;
1554 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1556 drawing_data_request(control_flow_data
->drawing
,
1558 control_flow_data
->drawing
->width
,
1559 control_flow_data
->drawing
->height
);
1562 /* Update directly when scrolling */
1563 gdk_window_process_updates(control_flow_data
->drawing
->drawing_area
->window
,
1569 gint
traceset_notify(void *hook_data
, void *call_data
)
1571 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1572 Drawing_t
*drawing
= control_flow_data
->drawing
;
1574 if(unlikely(drawing
->gc
== NULL
)) {
1577 if(drawing
->dotted_gc
== NULL
) {
1581 drawing_clear(control_flow_data
->drawing
);
1582 processlist_clear(control_flow_data
->process_list
);
1583 gtk_widget_set_size_request(
1584 control_flow_data
->drawing
->drawing_area
,
1585 -1, processlist_get_height(control_flow_data
->process_list
));
1586 redraw_notify(control_flow_data
, NULL
);
1588 request_background_data(control_flow_data
);
1593 gint
redraw_notify(void *hook_data
, void *call_data
)
1595 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1596 Drawing_t
*drawing
= control_flow_data
->drawing
;
1597 GtkWidget
*widget
= drawing
->drawing_area
;
1599 drawing
->damage_begin
= 0;
1600 drawing
->damage_end
= drawing
->width
;
1602 /* fun feature, to be separated someday... */
1603 drawing_clear(control_flow_data
->drawing
);
1604 processlist_clear(control_flow_data
->process_list
);
1605 gtk_widget_set_size_request(
1606 control_flow_data
->drawing
->drawing_area
,
1607 -1, processlist_get_height(control_flow_data
->process_list
));
1609 rectangle_pixmap (control_flow_data
->process_list
,
1610 widget
->style
->black_gc
,
1613 drawing
->alloc_width
,
1616 gtk_widget_queue_draw(drawing
->drawing_area
);
1618 if(drawing
->damage_begin
< drawing
->damage_end
)
1620 drawing_data_request(drawing
,
1621 drawing
->damage_begin
,
1623 drawing
->damage_end
-drawing
->damage_begin
,
1627 //gtk_widget_queue_draw_area(drawing->drawing_area,
1630 // drawing->height);
1636 gint
continue_notify(void *hook_data
, void *call_data
)
1638 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1639 Drawing_t
*drawing
= control_flow_data
->drawing
;
1641 //g_assert(widget->allocation.width == drawing->damage_end);
1643 if(drawing
->damage_begin
< drawing
->damage_end
)
1645 drawing_data_request(drawing
,
1646 drawing
->damage_begin
,
1648 drawing
->damage_end
-drawing
->damage_begin
,
1656 gint
update_current_time_hook(void *hook_data
, void *call_data
)
1659 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
1661 LttTime current_time
= *((LttTime
*)call_data
);
1663 TimeWindow time_window
=
1664 lttvwindow_get_time_window(control_flow_data
->tab
);
1666 LttTime time_begin
= time_window
.start_time
;
1667 LttTime width
= time_window
.time_width
;
1670 guint64 time_ll
= ltt_time_to_uint64(width
);
1671 time_ll
= time_ll
>> 1; /* divide by two */
1672 half_width
= ltt_time_from_uint64(time_ll
);
1674 LttTime time_end
= ltt_time_add(time_begin
, width
);
1676 LttvTraceset
* ts
= lttvwindow_get_traceset(control_flow_data
->tab
);
1678 TimeInterval time_span
= lttv_traceset_get_time_span_real(ts
);
1679 LttTime trace_start
= time_span
.start_time
;
1680 LttTime trace_end
= time_span
.end_time
;
1682 g_info("New current time HOOK : %lu, %lu", current_time
.tv_sec
,
1683 current_time
.tv_nsec
);
1687 /* If current time is inside time interval, just move the highlight
1690 /* Else, we have to change the time interval. We have to tell it
1691 * to the main window. */
1692 /* The time interval change will take care of placing the current
1693 * time at the center of the visible area, or nearest possible if we are
1694 * at one end of the trace. */
1697 if(ltt_time_compare(current_time
, time_begin
) < 0)
1699 TimeWindow new_time_window
;
1701 if(ltt_time_compare(current_time
,
1702 ltt_time_add(trace_start
,half_width
)) < 0)
1703 time_begin
= trace_start
;
1705 time_begin
= ltt_time_sub(current_time
,half_width
);
1707 new_time_window
.start_time
= time_begin
;
1708 new_time_window
.time_width
= width
;
1709 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1710 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1712 lttvwindow_report_time_window(control_flow_data
->tab
, new_time_window
);
1714 else if(ltt_time_compare(current_time
, time_end
) > 0)
1716 TimeWindow new_time_window
;
1718 if(ltt_time_compare(current_time
, ltt_time_sub(trace_end
, half_width
)) > 0)
1719 time_begin
= ltt_time_sub(trace_end
,width
);
1721 time_begin
= ltt_time_sub(current_time
,half_width
);
1723 new_time_window
.start_time
= time_begin
;
1724 new_time_window
.time_width
= width
;
1725 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1726 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1728 lttvwindow_report_time_window(control_flow_data
->tab
, new_time_window
);
1731 gtk_widget_queue_draw(control_flow_data
->drawing
->drawing_area
);
1733 /* Update directly when scrolling */
1734 gdk_window_process_updates(control_flow_data
->drawing
->drawing_area
->window
,
1741 typedef struct _ClosureData
{
1742 EventsRequest
*events_request
;
1748 void draw_closure(gpointer key
, gpointer value
, gpointer user_data
)
1751 ProcessInfo
*process_info
= (ProcessInfo
*)key
;
1752 HashedProcessData
*hashed_process_data
= (HashedProcessData
*)value
;
1753 ClosureData
*closure_data
= (ClosureData
*)user_data
;
1755 EventsRequest
*events_request
= closure_data
->events_request
;
1756 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1757 LttvTraceset
*ts
= lttvwindow_get_traceset(control_flow_data
->tab
);
1760 LttTime evtime
= closure_data
->end_time
;
1762 gboolean dodraw
= TRUE
;
1765 /* For the process */
1766 /* First, check if the current process is in the state computation
1767 * process list. If it is there, that means we must add it right now and
1768 * draw items from the beginning of the read for it. If it is not
1769 * present, it's a new process and it was not present : it will
1770 * be added after the state update. */
1772 g_assert(lttv_traceset_number(tsc
->ts
) > 0);
1773 #endif //EXTRA_CHECK
1775 LttvTrace
*trace
= lttv_traceset_get(ts
, process_info
->trace_num
);
1776 LttvTraceState
*trace_state
= trace
->state
;
1779 //FIXME : optimize data structures.
1780 LttvTracefileState
*tfs
;
1781 LttvTracefileContext
*tfc
;
1783 for(i
=0;i
<tc
->tracefiles
->len
;i
++) {
1784 tfc
= g_array_index(tc
->tracefiles
, LttvTracefileContext
*, i
);
1785 if(ltt_tracefile_name(tfc
->tf
) == LTT_NAME_CPU
1786 && tfs
->cpu
== process_info
->cpu
)
1790 g_assert(i
<tc
->tracefiles
->len
);
1791 tfs
= LTTV_TRACEFILE_STATE(tfc
);
1793 // LttvTracefileState *tfs =ts
1794 // (LttvTracefileState*)tsc->traces[process_info->trace_num]->
1795 // tracefiles[process_info->cpu];
1797 LttvProcessState
*process
;
1798 process
= lttv_state_find_process(trace_state
, process_info
->cpu
,
1801 if(unlikely(process
!= NULL
)) {
1802 #ifdef BABEL_CLEANUP
1803 LttvFilter
*filter
= control_flow_data
->filter
;
1804 if(filter
!= NULL
&& filter
->head
!= NULL
)
1805 if(!lttv_filter_tree_parse(filter
->head
,NULL
,NULL
,
1806 tc
->t
,NULL
,process
,tc
))
1808 #endif //babel_cleanup
1809 /* Only draw for processes that are currently in the trace states */
1812 /* Should be alike when background info is ready */
1813 if(control_flow_data
->background_info_waiting
==0)
1814 g_assert(ltt_time_compare(process
->creation_time
,
1815 process_info
->birth
) == 0);
1816 #endif //EXTRA_CHECK
1818 /* Now, the process is in the state hash and our own process hash.
1819 * We definitely can draw the items related to the ending state.
1822 if(unlikely(ltt_time_compare(hashed_process_data
->next_good_time
,
1825 TimeWindow time_window
=
1826 lttvwindow_get_time_window(control_flow_data
->tab
);
1829 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1830 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1832 #endif //EXTRA_CHECK
1833 Drawing_t
*drawing
= control_flow_data
->drawing
;
1834 guint width
= drawing
->width
;
1836 guint x
= closure_data
->x_end
;
1838 DrawContext draw_context
;
1840 init_drawing_context(&draw_context
,
1841 hashed_process_data
,
1846 /* Jump over draw if we are at the same x position */
1847 if(x
== hashed_process_data
->x
.over
)
1851 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.over
;
1853 PropertiesLine prop_line
= prepare_execmode_line(process
);
1854 draw_line((void*)&prop_line
, (void*)&draw_context
);
1856 hashed_process_data
->x
.over
= x
;
1860 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1861 hashed_process_data
->x
.middle_used
)) {
1862 #if 0 /* do not mark closure : not missing information */
1863 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
1864 /* Draw collision indicator */
1865 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1866 gdk_draw_point(drawing
->pixmap
,
1870 hashed_process_data
->x
.middle_marked
= TRUE
;
1875 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1878 PropertiesLine prop_line
= prepare_s_e_line(process
);
1879 draw_line((void*)&prop_line
, (void*)&draw_context
);
1882 /* become the last x position */
1883 if(likely(x
!= hashed_process_data
->x
.middle
)) {
1884 hashed_process_data
->x
.middle
= x
;
1885 /* but don't use the pixel */
1886 hashed_process_data
->x
.middle_used
= FALSE
;
1888 /* Calculate the next good time */
1889 convert_pixels_to_time(width
, x
+1, time_window
,
1890 &hashed_process_data
->next_good_time
);
1899 int before_chunk(void *hook_data
, void *call_data
)
1902 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1903 LttvTraceset
*ts
= (LttvTraceset
*)call_data
;
1905 /* Desactivate sort */
1906 gtk_tree_sortable_set_sort_column_id(
1907 GTK_TREE_SORTABLE(cfd
->process_list
->list_store
),
1909 GTK_SORT_ASCENDING
);
1911 drawing_chunk_begin(events_request
, ts
);
1916 int before_request(void *hook_data
, void *call_data
)
1919 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1921 drawing_data_request_begin(events_request
);
1928 void draw_closing_lines(ControlFlowData
*control_flow_data
,
1929 EventsRequest
* events_request
)
1931 ProcessList
*process_list
= control_flow_data
->process_list
;
1934 ClosureData closure_data
;
1935 closure_data
.events_request
= events_request
;
1936 closure_data
.end_time
= events_request
->end_time
;
1938 TimeWindow time_window
=
1939 lttvwindow_get_time_window(control_flow_data
->tab
);
1940 guint width
= control_flow_data
->drawing
->width
;
1941 convert_time_to_pixels(
1943 events_request
->end_time
,
1945 &closure_data
.x_end
);
1948 /* Draw last items */
1949 g_hash_table_foreach(process_list
->process_hash
, draw_closure
,
1950 (void*)&closure_data
);
1953 /* Request expose */
1954 drawing_request_expose(events_request
, events_request
->end_time
);
1958 * after request is necessary in addition of after chunk in order to draw
1959 * lines until the end of the screen. after chunk just draws lines until
1966 int after_request(void *hook_data
, void *call_data
)
1969 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1970 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1972 draw_closing_lines(control_flow_data
, events_request
);
1982 int after_chunk(void *hook_data
, void *call_data
)
1985 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1986 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1987 LttvTraceset
*ts
= (LttvTraceset
*)call_data
;
1990 ProcessList
*process_list
= control_flow_data
->process_list
;
1992 guint nb_trace
= lttv_traceset_number(ts
);
1994 /* Only execute when called for the first trace's events request */
1995 if(!process_list
->current_hash_data
)
1998 for(i
= 0 ; i
< nb_trace
; i
++) {
1999 g_free(process_list
->current_hash_data
[i
]);
2001 g_free(process_list
->current_hash_data
);
2002 process_list
->current_hash_data
= NULL
;
2004 draw_closing_lines(control_flow_data
, events_request
);
2009 /* after_statedump_end
2011 * @param hook_data ControlFlowData structure of the viewer.
2012 * @param call_data Event context.
2014 * This function adds items to be drawn in a queue for each process.
2017 int before_statedump_end(void *hook_data
, void *call_data
)
2021 event
= (LttvEvent
*) call_data
;
2023 if (strcmp(lttv_traceset_get_name_from_event(event
),"lttng_statedump_end") != 0)
2026 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
2029 LttvTraceState
*ts
= event
->state
;
2032 ProcessList
*process_list
= control_flow_data
->process_list
;
2034 #ifdef BABEL_CLEANUP
2035 LttvFilter
*filter
= control_flow_data
->filter
;
2036 if(filter
!= NULL
&& filter
->head
!= NULL
)
2037 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
2038 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
2042 LttTime evtime
= lttv_event_get_timestamp(event
);
2044 ClosureData closure_data
;
2045 //TODO ybrosseau 2013-03-27: Fake and event_request.
2046 // We need to change the API of drawing_request_expose to ask
2047 // For and control flow data only.
2048 EventsRequest events_request
;
2049 events_request
.viewer_data
= control_flow_data
;
2050 closure_data
.events_request
= &events_request
;
2051 closure_data
.end_time
= evtime
;
2053 TimeWindow time_window
=
2054 lttvwindow_get_time_window(control_flow_data
->tab
);
2055 guint width
= control_flow_data
->drawing
->width
;
2056 convert_time_to_pixels(
2060 &closure_data
.x_end
);
2062 /* Draw last items */
2063 g_hash_table_foreach(process_list
->process_hash
, draw_closure
,
2064 (void*)&closure_data
);
2067 /* Reactivate sort */
2068 gtk_tree_sortable_set_sort_column_id(
2069 GTK_TREE_SORTABLE(control_flow_data
->process_list
->list_store
),
2070 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
,
2071 GTK_SORT_ASCENDING
);
2073 update_index_to_pixmap(control_flow_data
->process_list
);
2074 /* Request a full expose : drawing scrambled */
2075 gtk_widget_queue_draw(control_flow_data
->drawing
->drawing_area
);
2077 /* Request expose (updates damages zone also) */
2078 drawing_request_expose(&events_request
, evtime
);