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
);
134 if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace
)==FALSE
135 && !ts
->has_precomputed_states
) {
137 if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"),
139 /* We first remove requests that could have been done for the same
140 * information. Happens when two viewers ask for it before servicing
143 if(!lttvwindowtraces_background_request_find(trace
, "state"))
144 lttvwindowtraces_background_request_queue(
145 main_window_get_widget(control_flow_data
->tab
), trace
, "state");
146 lttvwindowtraces_background_notify_queue(control_flow_data
,
150 background_ready_hook
);
151 control_flow_data
->background_info_waiting
++;
152 } else { /* in progress */
154 lttvwindowtraces_background_notify_current(control_flow_data
,
158 background_ready_hook
);
159 control_flow_data
->background_info_waiting
++;
162 /* Data ready. By its nature, this viewer doesn't need to have
163 * its data ready hook called there, because a background
164 * request is always linked with a redraw.
170 lttv_hooks_destroy(background_ready_hook
);
177 * Event Viewer's constructor hook
179 * This constructor is given as a parameter to the menuitem and toolbar button
180 * registration. It creates the list.
181 * @param tab A pointer to the parent tab.
182 * @return The widget created.
185 h_guicontrolflow(LttvPlugin
*plugin
)
187 LttvPluginTab
*ptab
= LTTV_PLUGIN_TAB(plugin
);
188 Tab
*tab
= ptab
->tab
;
189 g_info("h_guicontrolflow, %p", tab
);
190 ControlFlowData
*control_flow_data
= guicontrolflow(ptab
);
192 control_flow_data
->tab
= tab
;
194 // Unreg done in the GuiControlFlow_Destructor
195 lttvwindow_register_traceset_notify(tab
,
199 lttvwindow_register_time_window_notify(tab
,
200 update_time_window_hook
,
202 lttvwindow_register_current_time_notify(tab
,
203 update_current_time_hook
,
205 lttvwindow_register_redraw_notify(tab
,
208 lttvwindow_register_continue_notify(tab
,
211 request_background_data(control_flow_data
);
214 return guicontrolflow_get_widget(control_flow_data
) ;
218 int event_selected_hook(void *hook_data
, void *call_data
)
220 guint
*event_number
= (guint
*) call_data
;
222 g_debug("DEBUG : event selected by main window : %u", *event_number
);
227 /* Function that selects the color of status&exemode line */
228 static inline PropertiesLine
prepare_s_e_line(LttvProcessState
*process
)
230 PropertiesLine prop_line
;
231 prop_line
.line_width
= STATE_LINE_WIDTH
;
232 prop_line
.style
= GDK_LINE_SOLID
;
233 prop_line
.y
= MIDDLE
;
234 //GdkColormap *colormap = gdk_colormap_get_system();
236 if(process
->state
->s
== LTTV_STATE_RUN
) {
237 if(process
->state
->t
== LTTV_STATE_USER_MODE
)
238 prop_line
.color
= drawing_colors
[COL_RUN_USER_MODE
];
239 else if(process
->state
->t
== LTTV_STATE_SYSCALL
)
240 prop_line
.color
= drawing_colors
[COL_RUN_SYSCALL
];
241 else if(process
->state
->t
== LTTV_STATE_TRAP
)
242 prop_line
.color
= drawing_colors
[COL_RUN_TRAP
];
243 else if(process
->state
->t
== LTTV_STATE_IRQ
)
244 prop_line
.color
= drawing_colors
[COL_RUN_IRQ
];
245 else if(process
->state
->t
== LTTV_STATE_SOFT_IRQ
)
246 prop_line
.color
= drawing_colors
[COL_RUN_SOFT_IRQ
];
247 else if(process
->state
->t
== LTTV_STATE_MAYBE_SYSCALL
)
248 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
249 else if(process
->state
->t
== LTTV_STATE_MAYBE_USER_MODE
)
250 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
251 else if(process
->state
->t
== LTTV_STATE_MAYBE_TRAP
)
252 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
253 else if(process
->state
->t
== LTTV_STATE_MODE_UNKNOWN
)
254 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
256 g_assert(FALSE
); /* RUNNING MODE UNKNOWN */
257 } else if(process
->state
->s
== LTTV_STATE_WAIT
) {
258 /* We don't show if we wait while in user mode, trap, irq or syscall */
259 prop_line
.color
= drawing_colors
[COL_WAIT
];
260 } else if(process
->state
->s
== LTTV_STATE_WAIT_CPU
) {
261 /* We don't show if we wait for CPU while in user mode, trap, irq
263 prop_line
.color
= drawing_colors
[COL_WAIT_CPU
];
264 } else if(process
->state
->s
== LTTV_STATE_ZOMBIE
) {
265 prop_line
.color
= drawing_colors
[COL_ZOMBIE
];
266 } else if(process
->state
->s
== LTTV_STATE_WAIT_FORK
) {
267 prop_line
.color
= drawing_colors
[COL_WAIT_FORK
];
268 } else if(process
->state
->s
== LTTV_STATE_EXIT
) {
269 prop_line
.color
= drawing_colors
[COL_EXIT
];
270 } else if(process
->state
->s
== LTTV_STATE_UNNAMED
) {
271 prop_line
.color
= drawing_colors
[COL_UNNAMED
];
272 } else if(process
->state
->s
== LTTV_STATE_DEAD
) {
273 prop_line
.color
= drawing_colors
[COL_DEAD
];
275 g_critical("unknown state : %s", g_quark_to_string(process
->state
->s
));
276 g_assert(FALSE
); /* UNKNOWN STATE */
283 HashedProcessData
*get_hashed_process_data(ControlFlowData
*control_flow_data
,
284 LttvProcessState
*process
,
288 HashedProcessData
*hashed_process_data
= NULL
;
289 ProcessList
*process_list
= control_flow_data
->process_list
;
290 LttTime birth
= process
->creation_time
;
293 hashed_process_data
= processlist_get_process_data(process_list
,
298 if(hashed_process_data
== NULL
)
300 g_assert(pid
== 0 || pid
!= process
->ppid
);
301 ProcessInfo
*process_info
;
302 Drawing_t
*drawing
= control_flow_data
->drawing
;
303 /* Process not present */
304 processlist_add(process_list
,
316 &hashed_process_data
);
317 gtk_widget_set_size_request(drawing
->drawing_area
,
320 gtk_widget_queue_draw(drawing
->drawing_area
);
322 return hashed_process_data
;
325 void init_drawing_context(DrawContext
*draw_context
,
326 HashedProcessData
*hashed_process_data
,
331 draw_context
->drawable
= hashed_process_data
->pixmap
;
332 draw_context
->gc
= drawing
->gc
;
333 draw_context
->pango_layout
= drawing
->pango_layout
;
334 draw_context
->drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
335 draw_context
->drawinfo
.end
.x
= x
;
337 draw_context
->drawinfo
.y
.over
= 1;
338 draw_context
->drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
339 draw_context
->drawinfo
.y
.under
= hashed_process_data
->height
;
341 draw_context
->drawinfo
.start
.offset
.over
= 0;
342 draw_context
->drawinfo
.start
.offset
.middle
= 0;
343 draw_context
->drawinfo
.start
.offset
.under
= 0;
344 draw_context
->drawinfo
.end
.offset
.over
= 0;
345 draw_context
->drawinfo
.end
.offset
.middle
= 0;
346 draw_context
->drawinfo
.end
.offset
.under
= 0;
350 void draw_state_line(HashedProcessData
*hashed_process_data
,
351 LttvProcessState
*process
,
354 TimeWindow time_window
)
356 DrawContext draw_context
;
357 guint width
= drawing
->width
;
359 init_drawing_context(&draw_context
,
366 PropertiesLine prop_line
= prepare_s_e_line(process
);
367 draw_line((void*)&prop_line
, (void*)&draw_context
);
369 /* become the last x position */
370 hashed_process_data
->x
.middle
= x
;
371 hashed_process_data
->x
.middle_used
= TRUE
;
372 hashed_process_data
->x
.middle_marked
= FALSE
;
374 /* Calculate the next good time */
375 convert_pixels_to_time(width
, x
+1, time_window
,
376 &hashed_process_data
->next_good_time
);
380 void draw_state_items(ControlFlowData
*control_flow_data
,
381 HashedProcessData
*hashed_process_data
,
382 LttvProcessState
*process
,
387 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
390 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
391 TimeWindow time_window
=
392 lttvwindow_get_time_window(control_flow_data
->tab
);
395 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
396 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
399 Drawing_t
*drawing
= control_flow_data
->drawing
;
400 guint width
= drawing
->width
;
402 convert_time_to_pixels(
408 /* Draw collision indicator */
409 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
410 gdk_draw_point(hashed_process_data
->pixmap
,
413 COLLISION_POSITION(hashed_process_data
->height
));
414 hashed_process_data
->x
.middle_marked
= TRUE
;
417 TimeWindow time_window
=
418 lttvwindow_get_time_window(control_flow_data
->tab
);
421 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
422 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
425 Drawing_t
*drawing
= control_flow_data
->drawing
;
426 guint width
= drawing
->width
;
429 convert_time_to_pixels(
436 /* Jump over draw if we are at the same x position */
437 if(unlikely(x
== hashed_process_data
->x
.middle
&&
438 hashed_process_data
->x
.middle_used
))
440 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
441 /* Draw collision indicator */
442 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
443 gdk_draw_point(hashed_process_data
->pixmap
,
446 COLLISION_POSITION(hashed_process_data
->height
));
447 hashed_process_data
->x
.middle_marked
= TRUE
;
452 draw_state_line(hashed_process_data
,
462 /* Before try-wake-up hook. A process is being woken; we need to draw its line up to this point in time
463 in that colour. This is basically like exec-state, but the change applies to a process other than that
464 which is currently running. */
466 int before_trywakeup_hook(void *hook_data
, void *call_data
)
471 event
= (LttvEvent
*) call_data
;
472 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_wakeup") != 0)
475 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
477 LttvTraceState
*ts
= event
->state
;;
480 LttTime evtime
= lttv_event_get_timestamp(event
);
482 LttvFilter
*filter
= control_flow_data
->filter
;
488 woken_pid
= lttv_event_get_long(event
, "tid");
489 woken_cpu
= lttv_event_get_long(event
, "target_cpu");
492 if(!filter
|| !filter
->head
||
493 lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
494 tfc
->t_context
->t
,tfc
,NULL
,NULL
)) {
498 /* First, check if the woken process is in the state computation
499 * process list. If it is there, that means we must add it right now and
500 * draw items from the beginning of the read for it. If it is not
501 * present, it's a new process and it was not present : it will
502 * be added after the state update. TOCHECK: What does that last para mean? */
503 guint trace_num
= 0; /*TODO ybrosseau 2012-08-23: use right number */
504 LttvProcessState
*process
= lttv_state_find_process(ts
, woken_cpu
, woken_pid
);
506 if(process
!= NULL
) {
507 /* Well, the woken process existed : we must get it in the process hash
508 * or add it, and draw its items.
510 /* Add process to process list (if not present) */
512 HashedProcessData
*hashed_process_data
= get_hashed_process_data(control_flow_data
, process
, woken_pid
, trace_num
);
514 /* Now, the process is in the state hash and our own process hash.
515 * We definitely can draw the items related to the ending state.
518 draw_state_items(control_flow_data
,
533 /* before_schedchange_hook
535 * This function basically draw lines and icons. Two types of lines are drawn :
536 * one small (3 pixels?) representing the state of the process and the second
537 * type is thicker (10 pixels?) representing on which CPU a process is running
538 * (and this only in running state).
540 * Extremums of the lines :
541 * x_min : time of the last event context for this process kept in memory.
542 * x_max : time of the current event.
543 * y : middle of the process in the process list. The process is found in the
544 * list, therefore is it's position in pixels.
546 * The choice of lines'color is defined by the context of the last event for this
551 int before_schedchange_hook(void *hook_data
, void *call_data
)
556 LttvProcessState
*process
;
558 //LttvProcessState *old_process = ts->running_process[cpu];
560 guint pid_in
, pid_out
;
563 event
= (LttvEvent
*) call_data
;
564 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_switch") != 0)
567 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
570 /* we are in a schedchange, before the state update. We must draw the
571 * items corresponding to the state before it changes : now is the right
574 cpu
= lttv_traceset_get_cpuid_from_event(event
);
577 pid_out
= lttv_event_get_long(event
, "prev_tid");
578 pid_in
= lttv_event_get_long(event
, "next_tid");
579 state_out
= lttv_event_get_long(event
, "prev_state");
580 guint trace_number
= 0;//TODO fdeslauriers 2012-07-17: // Use trace handle to know trace number
582 process
= lttv_state_find_process(ts
,cpu
,pid_out
);
583 evtime
= lttv_event_get_timestamp(event
);
584 /* For the pid_out */
585 /* First, check if the current process is in the state computation
586 * process list. If it is there, that means we must add it right now and
587 * draw items from the beginning of the read for it. If it is not
588 * present, it's a new process and it was not present : it will
589 * be added after the state update. */
591 /* unknown state, bad current pid */
593 if(process
!= NULL
) {
594 /* Well, the process_out existed : we must get it in the process hash
595 * or add it, and draw its items.
597 /* Add process to process list (if not present) */
599 HashedProcessData
*hashed_process_data
= get_hashed_process_data(control_flow_data
, process
, pid_out
, trace_number
);
601 /* Now, the process is in the state hash and our own process hash.
602 * We definitely can draw the items related to the ending state.
605 draw_state_items(control_flow_data
,
612 /* First, check if the current process is in the state computation
613 * process list. If it is there, that means we must add it right now and
614 * draw items from the beginning of the read for it. If it is not
615 * present, it's a new process and it was not present : it will
616 * be added after the state update. */
617 process
= lttv_state_find_process(ts
,cpu
,pid_in
);
619 if(process
!= NULL
) {
620 /* Well, the process existed : we must get it in the process hash
621 * or add it, and draw its items.
623 /* Add process to process list (if not present) */
625 HashedProcessData
*hashed_process_data
= get_hashed_process_data(control_flow_data
, process
, pid_in
, trace_number
);
627 //We could set the current process and hash here, but will be done
628 //by after schedchange hook
630 /* Now, the process is in the state hash and our own process hash.
631 * We definitely can draw the items related to the ending state.
633 draw_state_items(control_flow_data
,
639 g_warning("Cannot find pid_in in schedchange %u at %u.%u", pid_in
, evtime
.tv_sec
, evtime
.tv_nsec
);
641 tfc
->target_pid
= target_pid_saved
;
642 #endif //babel_cleanup
650 GString
*string
= g_string_new("");;
651 gboolean field_names
= TRUE
, state
= TRUE
;
653 lttv_event_to_string(e
, tfc
->tf
, string
, TRUE
, field_names
, tfs
);
654 g_string_append_printf(string
,"\n");
657 g_string_append_printf(string
, " %s",
658 g_quark_to_string(tfs
->process
->state
->s
));
661 g_info("%s",string
->str
);
663 g_string_free(string
, TRUE
);
665 /* End of text dump */
670 /* after_schedchange_hook
672 * The draw after hook is called by the reading API to have a
673 * particular event drawn on the screen.
674 * @param hook_data ControlFlowData structure of the viewer.
675 * @param call_data Event context.
677 * This function adds items to be drawn in a queue for each process.
680 int after_schedchange_hook(void *hook_data
, void *call_data
)
684 event
= (LttvEvent
*) call_data
;
686 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_switch") != 0)
689 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
692 LttvTraceState
*ts
= event
->state
;
695 LttvFilter
*filter
= control_flow_data
->filter
;
697 LttTime evtime
= lttv_event_get_timestamp(event
);
699 /* Add process to process list (if not present) */
700 LttvProcessState
*process_in
;
701 HashedProcessData
*hashed_process_data_in
= NULL
;
703 ProcessList
*process_list
= control_flow_data
->process_list
;
707 pid_in
= lttv_event_get_long(event
, "next_tid");
711 if(!filter
|| !filter
->head
||
712 lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
713 tfc
->t_context
->t
,tfc
,NULL
,NULL
)) {
717 /* Find process pid_in in the list... */
718 //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in);
719 //process_in = tfs->process;
720 guint cpu
= lttv_traceset_get_cpuid_from_event(event
);
721 guint trace_num
= 0; /* TODO set right trace number */
722 process_in
= ts
->running_process
[cpu
];
723 /* It should exist, because we are after the state update. */
725 g_assert(process_in
!= NULL
);
727 hashed_process_data_in
= get_hashed_process_data(control_flow_data
, process_in
, pid_in
, trace_num
);
729 /* Set the current process */
730 process_list
->current_hash_data
[trace_num
][process_in
->cpu
] =
731 hashed_process_data_in
;
733 if(ltt_time_compare(hashed_process_data_in
->next_good_time
,
736 TimeWindow time_window
=
737 lttvwindow_get_time_window(control_flow_data
->tab
);
740 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
741 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
744 Drawing_t
*drawing
= control_flow_data
->drawing
;
745 guint width
= drawing
->width
;
748 convert_time_to_pixels(
754 if(hashed_process_data_in
->x
.middle
!= new_x
) {
755 hashed_process_data_in
->x
.middle
= new_x
;
756 hashed_process_data_in
->x
.middle_used
= FALSE
;
757 hashed_process_data_in
->x
.middle_marked
= FALSE
;
768 /* before_execmode_hook
770 * This function basically draw lines and icons. Two types of lines are drawn :
771 * one small (3 pixels?) representing the state of the process and the second
772 * type is thicker (10 pixels?) representing on which CPU a process is running
773 * (and this only in running state).
775 * Extremums of the lines :
776 * x_min : time of the last event context for this process kept in memory.
777 * x_max : time of the current event.
778 * y : middle of the process in the process list. The process is found in the
779 * list, therefore is it's position in pixels.
781 * The choice of lines'color is defined by the context of the last event for this
786 int before_execmode_hook(void *hook_data
, void *call_data
)
792 LttvProcessState
*process
;
794 /* we are in a execmode, before the state update. We must draw the
795 * items corresponding to the state before it changes : now is the right
799 event
= (LttvEvent
*) call_data
;
800 if ((strncmp(lttv_traceset_get_name_from_event(event
),"sys_", sizeof("sys_") - 1) == 0)
801 ||(strcmp(lttv_traceset_get_name_from_event(event
),"exit_syscall") == 0)
802 ||(strncmp(lttv_traceset_get_name_from_event(event
),"irq_handler_",sizeof("irq_handler_") -1) == 0)
803 ||(strncmp(lttv_traceset_get_name_from_event(event
),"softirq_", sizeof("softirq_") - 1) == 0)) {
805 LttTime evtime
= lttv_event_get_timestamp(event
);
806 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
808 LttvTraceset
*traceSet
= lttvwindow_get_traceset(control_flow_data
->tab
);
810 cpu
= lttv_traceset_get_cpuid_from_event(event
);
813 guint trace_number
= 0;//TODO fdeslauriers 2012-07-17: // Use trace handle to know trace number
815 //TODO ybrosseau 2013-04-09 validate that using the running process is the right choice
816 //process = lttv_state_find_process(ts ,cpu ,pid);
817 process
= ts
->running_process
[cpu
];
819 g_assert(process
!= NULL
);
821 guint pid
= process
->pid
;
823 /* Well, the process_out existed : we must get it in the process hash
824 * or add it, and draw its items.
826 /* Add process to process list (if not present) */
827 HashedProcessData
*hashed_process_data
= NULL
;
828 ProcessList
*process_list
= control_flow_data
->process_list
;
829 if(process_list
->current_hash_data
== NULL
){//TODO fdeslauriers 2012-07-17 : should not be necessary
833 if(likely(process_list
->current_hash_data
[trace_number
][cpu
] != NULL
)) {
834 hashed_process_data
= process_list
->current_hash_data
[trace_number
][cpu
];
836 hashed_process_data
= get_hashed_process_data(control_flow_data
,
837 process
, pid
, trace_number
);
839 /* Set the current process */
840 process_list
->current_hash_data
[trace_number
][process
->cpu
] =
844 /* Now, the process is in the state hash and our own process hash.
845 * We definitely can draw the items related to the ending state.
848 draw_state_items(control_flow_data
,
858 /* before_process_exit_hook
860 * Draw lines for process event.
862 * @param hook_data ControlFlowData structure of the viewer.
863 * @param call_data Event context.
865 * This function adds items to be drawn in a queue for each process.
870 int before_process_exit_hook(void *hook_data
, void *call_data
)
875 event
= (LttvEvent
*) call_data
;
876 if (strcmp(lttv_traceset_get_name_from_event(event
),
877 "sched_process_exit") != 0)
881 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
882 LttvTraceState
*ts
= event
->state
;
885 LttvFilter
*filter
= control_flow_data
->filter
;
886 if(filter
!= NULL
&& filter
->head
!= NULL
)
887 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
888 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
892 LttTime evtime
= lttv_event_get_timestamp(event
);
894 /* Add process to process list (if not present) */
895 //LttvProcessState *process = tfs->process;
896 guint cpu
= lttv_traceset_get_cpuid_from_event(event
);
897 guint trace_num
= 0; /* TODO set right trace number */
899 LttvProcessState
*process
= ts
->running_process
[cpu
];
900 guint pid
= process
->pid
;
901 HashedProcessData
*hashed_process_data
= NULL
;
903 ProcessList
*process_list
= control_flow_data
->process_list
;
905 g_assert(process
!= NULL
);
907 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
)) {
908 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
910 hashed_process_data
= get_hashed_process_data(control_flow_data
,
911 process
, pid
, trace_num
);
914 /* Now, the process is in the state hash and our own process hash.
915 * We definitely can draw the items related to the ending state.
918 draw_state_items(control_flow_data
,
929 /* before_process_release_hook
931 * Draw lines for process event.
933 * @param hook_data ControlFlowData structure of the viewer.
934 * @param call_data Event context.
936 * This function adds items to be drawn in a queue for each process.
941 int before_process_release_hook(void *hook_data
, void *call_data
)
946 event
= (LttvEvent
*) call_data
;
948 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_process_free") != 0)
951 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
954 LttvTraceState
*ts
= event
->state
;
957 LttvFilter
*filter
= control_flow_data
->filter
;
958 if(filter
!= NULL
&& filter
->head
!= NULL
)
959 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
960 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
963 LttTime evtime
= lttv_event_get_timestamp(event
);
966 guint trace_num
= 0; /* TODO set right trace number */
970 pid
= lttv_event_get_long(event
, "tid");
973 /* Add process to process list (if not present) */
974 /* Don't care about the process if it's not in the state hash already :
975 * that means a process that has never done anything in the trace and
976 * unknown suddently gets destroyed : no state meaningful to show. */
977 LttvProcessState
*process
= lttv_state_find_process(ts
, ANY_CPU
, pid
);
979 if(process
!= NULL
) {
981 HashedProcessData
*hashed_process_data
= NULL
;
983 ProcessList
*process_list
= control_flow_data
->process_list
;
985 birth
= process
->creation_time
;
987 /* Cannot use current process : this event happens on another process,
988 * action done by the parent. */
989 hashed_process_data
= processlist_get_process_data(process_list
,
994 if(unlikely(hashed_process_data
== NULL
))
996 * Process already been scheduled out EXIT_DEAD, not in the process list
997 * anymore. Just return.
1001 /* Now, the process is in the state hash and our own process hash.
1002 * We definitely can draw the items related to the ending state.
1005 draw_state_items(control_flow_data
,
1006 hashed_process_data
,
1017 /* after_process_fork_hook
1019 * Create the processlist entry for the child process. Put the last
1020 * position in x at the current time value.
1022 * @param hook_data ControlFlowData structure of the viewer.
1023 * @param call_data Event context.
1025 * This function adds items to be drawn in a queue for each process.
1028 int after_process_fork_hook(void *hook_data
, void *call_data
)
1032 event
= (LttvEvent
*) call_data
;
1034 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_process_fork") != 0)
1037 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1040 LttvTraceState
*ts
= event
->state
;
1042 #ifdef BABEL_CLEANUP
1043 LttvFilter
*filter
= control_flow_data
->filter
;
1044 if(filter
!= NULL
&& filter
->head
!= NULL
)
1045 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1046 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1050 LttTime evtime
= lttv_event_get_timestamp(event
);
1054 child_pid
= lttv_event_get_long(event
, "child_tid");
1057 /* Add process to process list (if not present) */
1058 LttvProcessState
*process_child
;
1059 HashedProcessData
*hashed_process_data_child
= NULL
;
1061 ProcessList
*process_list
= control_flow_data
->process_list
;
1063 /* Find child in the list... */
1064 process_child
= lttv_state_find_process(ts
, ANY_CPU
, child_pid
);
1065 /* It should exist, because we are after the state update. */
1066 g_assert(process_child
!= NULL
);
1068 guint trace_num
= 0; /* TODO put right */
1070 /* Cannot use current process, because this action is done by the parent
1072 hashed_process_data_child
= get_hashed_process_data(control_flow_data
,
1073 process_child
, child_pid
, trace_num
);
1076 processlist_set_ppid(process_list
, process_child
->ppid
,
1077 hashed_process_data_child
);
1078 processlist_set_tgid(process_list
, process_child
->tgid
,
1079 hashed_process_data_child
);
1083 if(likely(ltt_time_compare(hashed_process_data_child
->next_good_time
,
1086 TimeWindow time_window
=
1087 lttvwindow_get_time_window(control_flow_data
->tab
);
1090 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1091 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1093 #endif //EXTRA_CHECK
1094 Drawing_t
*drawing
= control_flow_data
->drawing
;
1095 guint width
= drawing
->width
;
1097 convert_time_to_pixels(
1103 if(likely(hashed_process_data_child
->x
.over
!= new_x
)) {
1104 hashed_process_data_child
->x
.over
= new_x
;
1105 hashed_process_data_child
->x
.over_used
= FALSE
;
1106 hashed_process_data_child
->x
.over_marked
= FALSE
;
1108 if(likely(hashed_process_data_child
->x
.middle
!= new_x
)) {
1109 hashed_process_data_child
->x
.middle
= new_x
;
1110 hashed_process_data_child
->x
.middle_used
= FALSE
;
1111 hashed_process_data_child
->x
.middle_marked
= FALSE
;
1113 if(likely(hashed_process_data_child
->x
.under
!= new_x
)) {
1114 hashed_process_data_child
->x
.under
= new_x
;
1115 hashed_process_data_child
->x
.under_used
= FALSE
;
1116 hashed_process_data_child
->x
.under_marked
= FALSE
;
1124 /* after_process_exit_hook
1126 * Create the processlist entry for the child process. Put the last
1127 * position in x at the current time value.
1129 * @param hook_data ControlFlowData structure of the viewer.
1130 * @param call_data Event context.
1132 * This function adds items to be drawn in a queue for each process.
1135 int after_process_exit_hook(void *hook_data
, void *call_data
)
1140 event
= (LttvEvent
*) call_data
;
1142 if (strcmp(lttv_traceset_get_name_from_event(event
),"sched_process_exit") != 0)
1145 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1147 LttvTraceState
*ts
= event
->state
;
1149 #ifdef BABEL_CLEANUP
1150 LttvFilter
*filter
= control_flow_data
->filter
;
1151 if(filter
!= NULL
&& filter
->head
!= NULL
)
1152 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1153 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1157 LttTime evtime
= lttv_event_get_timestamp(event
);
1159 /* Add process to process list (if not present) */
1160 //LttvProcessState *process = tfs->process;
1161 guint cpu
= lttv_traceset_get_cpuid_from_event(event
);
1162 guint trace_num
= 0; /* TODO set right trace number */
1163 LttvProcessState
*process
= ts
->running_process
[cpu
];
1165 /* It should exist, because we are after the state update. */
1166 g_assert(process
!= NULL
);
1168 guint pid
= process
->pid
;
1170 //guint pl_height = 0;
1171 HashedProcessData
*hashed_process_data
= NULL
;
1173 ProcessList
*process_list
= control_flow_data
->process_list
;
1175 //birth = process->creation_time;
1177 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
) ){
1178 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
1180 hashed_process_data
= get_hashed_process_data(control_flow_data
,
1181 process
, pid
, trace_num
);
1184 /* Set the current process */
1185 process_list
->current_hash_data
[trace_num
][process
->cpu
] =
1186 hashed_process_data
;
1189 if(unlikely(ltt_time_compare(hashed_process_data
->next_good_time
,
1192 TimeWindow time_window
=
1193 lttvwindow_get_time_window(control_flow_data
->tab
);
1196 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1197 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1199 #endif //EXTRA_CHECK
1200 Drawing_t
*drawing
= control_flow_data
->drawing
;
1201 guint width
= drawing
->width
;
1203 convert_time_to_pixels(
1208 if(unlikely(hashed_process_data
->x
.middle
!= new_x
)) {
1209 hashed_process_data
->x
.middle
= new_x
;
1210 hashed_process_data
->x
.middle_used
= FALSE
;
1211 hashed_process_data
->x
.middle_marked
= FALSE
;
1219 /* Get the filename of the process to print */
1220 int after_fs_exec_hook(void *hook_data
, void *call_data
)
1222 #ifdef BABEL_CLEANUP
1223 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
1224 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
1225 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1227 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
1229 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
1231 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
1234 e
= ltt_tracefile_get_event(tfc
->tf
);
1236 LttvFilter
*filter
= control_flow_data
->filter
;
1237 if(filter
!= NULL
&& filter
->head
!= NULL
)
1238 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1239 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1242 guint cpu
= tfs
->cpu
;
1243 guint trace_num
= ts
->parent
.index
;
1244 LttvProcessState
*process
= ts
->running_process
[cpu
];
1245 g_assert(process
!= NULL
);
1247 guint pid
= process
->pid
;
1249 /* Well, the process_out existed : we must get it in the process hash
1250 * or add it, and draw its items.
1252 /* Add process to process list (if not present) */
1253 guint pl_height
= 0;
1254 HashedProcessData
*hashed_process_data
= NULL
;
1255 ProcessList
*process_list
= control_flow_data
->process_list
;
1256 LttTime birth
= process
->creation_time
;
1258 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
)) {
1259 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
1261 hashed_process_data
= get_hashed_process_data(control_flow_data
,
1262 process
, pid
, trace_num
);
1263 /* Set the current process */
1264 process_list
->current_hash_data
[trace_num
][process
->cpu
] =
1265 hashed_process_data
;
1268 processlist_set_name(process_list
, process
->name
, hashed_process_data
);
1270 #endif //babel_cleanup
1275 /* after_event_enum_process_hook
1277 * Create the processlist entry for the child process. Put the last
1278 * position in x at the current time value.
1280 * @param hook_data ControlFlowData structure of the viewer.
1281 * @param call_data Event context.
1283 * This function adds items to be drawn in a queue for each process.
1286 int after_event_enum_process_hook(void *hook_data
, void *call_data
)
1290 event
= (LttvEvent
*) call_data
;
1292 if (strcmp(lttv_traceset_get_name_from_event(event
),"lttng_statedump_process_state") != 0)
1295 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1298 LttvTraceState
*ts
= event
->state
;
1300 guint first_cpu
, nb_cpus
, cpu
;
1302 #ifdef BABEL_CLEANUP
1303 LttvFilter
*filter
= control_flow_data
->filter
;
1304 if(filter
!= NULL
&& filter
->head
!= NULL
)
1305 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1306 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1309 /* Add process to process list (if not present) */
1310 LttvProcessState
*process_in
;
1311 HashedProcessData
*hashed_process_data_in
= NULL
;
1313 ProcessList
*process_list
= control_flow_data
->process_list
;
1314 guint trace_num
= 0; /* TODO put right trace number */
1318 pid_in
= lttv_event_get_long(event
, "tid");
1323 nb_cpus
= lttv_trace_get_num_cpu(ts
->trace
);
1325 first_cpu
= ANY_CPU
;
1326 nb_cpus
= ANY_CPU
+1;
1329 for(cpu
= first_cpu
; cpu
< nb_cpus
; cpu
++) {
1330 /* Find process pid_in in the list... */
1331 process_in
= lttv_state_find_process(ts
, cpu
, pid_in
);
1332 //process_in = tfs->process;
1333 //guint cpu = tfs->cpu;
1334 //guint trace_num = ts->parent.index;
1335 //process_in = ts->running_process[cpu];
1336 /* It should exist, because we are after the state update. */
1338 //g_assert(process_in != NULL);
1339 #endif //EXTRA_CHECK
1341 hashed_process_data_in
= get_hashed_process_data(control_flow_data
,
1342 process_in
, pid_in
, trace_num
);
1344 processlist_set_name(process_list
, process_in
->name
,
1345 hashed_process_data_in
);
1346 processlist_set_ppid(process_list
, process_in
->ppid
,
1347 hashed_process_data_in
);
1348 processlist_set_tgid(process_list
, process_in
->tgid
,
1349 hashed_process_data_in
);
1356 gint
update_time_window_hook(void *hook_data
, void *call_data
)
1358 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1360 Drawing_t
*drawing
= control_flow_data
->drawing
;
1361 ProcessList
*process_list
= control_flow_data
->process_list
;
1363 const TimeWindowNotifyData
*time_window_nofify_data
=
1364 ((const TimeWindowNotifyData
*)call_data
);
1366 TimeWindow
*old_time_window
=
1367 time_window_nofify_data
->old_time_window
;
1368 TimeWindow
*new_time_window
=
1369 time_window_nofify_data
->new_time_window
;
1371 /* Update the ruler */
1372 drawing_update_ruler(control_flow_data
->drawing
,
1376 /* Two cases : zoom in/out or scrolling */
1378 /* In order to make sure we can reuse the old drawing, the scale must
1379 * be the same and the new time interval being partly located in the
1380 * currently shown time interval. (reuse is only for scrolling)
1383 g_info("Old time window HOOK : %lu, %lu to %lu, %lu",
1384 old_time_window
->start_time
.tv_sec
,
1385 old_time_window
->start_time
.tv_nsec
,
1386 old_time_window
->time_width
.tv_sec
,
1387 old_time_window
->time_width
.tv_nsec
);
1389 g_info("New time window HOOK : %lu, %lu to %lu, %lu",
1390 new_time_window
->start_time
.tv_sec
,
1391 new_time_window
->start_time
.tv_nsec
,
1392 new_time_window
->time_width
.tv_sec
,
1393 new_time_window
->time_width
.tv_nsec
);
1395 if( new_time_window
->time_width
.tv_sec
== old_time_window
->time_width
.tv_sec
1396 && new_time_window
->time_width
.tv_nsec
== old_time_window
->time_width
.tv_nsec
)
1398 /* Same scale (scrolling) */
1399 g_info("scrolling");
1400 LttTime
*ns
= &new_time_window
->start_time
;
1401 LttTime
*os
= &old_time_window
->start_time
;
1402 LttTime old_end
= old_time_window
->end_time
;
1403 LttTime new_end
= new_time_window
->end_time
;
1405 //if(ns<os+w && os+w<ns+w)
1406 //if(ns<old_end && os<ns)
1407 if(ltt_time_compare(*ns
, old_end
) == -1
1408 && ltt_time_compare(*os
, *ns
) == -1)
1410 g_info("scrolling near right");
1411 /* Scroll right, keep right part of the screen */
1413 guint width
= control_flow_data
->drawing
->width
;
1414 convert_time_to_pixels(
1420 /* Copy old data to new location */
1421 copy_pixmap_region(process_list
,
1423 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1427 control_flow_data
->drawing
->width
-x
+SAFETY
, -1);
1429 if(drawing
->damage_begin
== drawing
->damage_end
)
1430 drawing
->damage_begin
= control_flow_data
->drawing
->width
-x
;
1432 drawing
->damage_begin
= 0;
1434 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1436 /* Clear the data request background, but not SAFETY */
1437 rectangle_pixmap(process_list
,
1438 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1440 drawing
->damage_begin
+SAFETY
, 0,
1441 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1443 gtk_widget_queue_draw(drawing
->drawing_area
);
1444 //gtk_widget_queue_draw_area (drawing->drawing_area,
1446 // control_flow_data->drawing->width,
1447 // control_flow_data->drawing->height);
1449 /* Get new data for the rest. */
1450 drawing_data_request(control_flow_data
->drawing
,
1451 drawing
->damage_begin
, 0,
1452 drawing
->damage_end
- drawing
->damage_begin
,
1453 control_flow_data
->drawing
->height
);
1456 //if(ns<os && os<ns+w)
1457 //if(ns<os && os<new_end)
1458 if(ltt_time_compare(*ns
,*os
) == -1
1459 && ltt_time_compare(*os
,new_end
) == -1)
1461 g_info("scrolling near left");
1462 /* Scroll left, keep left part of the screen */
1464 guint width
= control_flow_data
->drawing
->width
;
1465 convert_time_to_pixels(
1471 /* Copy old data to new location */
1472 copy_pixmap_region (process_list
,
1474 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1480 if(drawing
->damage_begin
== drawing
->damage_end
)
1481 drawing
->damage_end
= x
;
1483 drawing
->damage_end
=
1484 control_flow_data
->drawing
->width
;
1486 drawing
->damage_begin
= 0;
1488 rectangle_pixmap (process_list
,
1489 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1491 drawing
->damage_begin
, 0,
1492 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1495 gtk_widget_queue_draw(drawing
->drawing_area
);
1496 //gtk_widget_queue_draw_area (drawing->drawing_area,
1498 // control_flow_data->drawing->width,
1499 // control_flow_data->drawing->height);
1502 /* Get new data for the rest. */
1503 drawing_data_request(control_flow_data
->drawing
,
1504 drawing
->damage_begin
, 0,
1505 drawing
->damage_end
- drawing
->damage_begin
,
1506 control_flow_data
->drawing
->height
);
1509 if(ltt_time_compare(*ns
,*os
) == 0)
1511 g_info("not scrolling");
1513 g_info("scrolling far");
1514 /* Cannot reuse any part of the screen : far jump */
1517 rectangle_pixmap (process_list
,
1518 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1521 control_flow_data
->drawing
->width
+SAFETY
, // do not overlap
1524 //gtk_widget_queue_draw_area (drawing->drawing_area,
1526 // control_flow_data->drawing->width,
1527 // control_flow_data->drawing->height);
1528 gtk_widget_queue_draw(drawing
->drawing_area
);
1530 drawing
->damage_begin
= 0;
1531 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1533 drawing_data_request(control_flow_data
->drawing
,
1535 control_flow_data
->drawing
->width
,
1536 control_flow_data
->drawing
->height
);
1542 /* Different scale (zoom) */
1545 rectangle_pixmap (process_list
,
1546 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1549 control_flow_data
->drawing
->width
+SAFETY
, // do not overlap
1552 //gtk_widget_queue_draw_area (drawing->drawing_area,
1554 // control_flow_data->drawing->width,
1555 // control_flow_data->drawing->height);
1556 gtk_widget_queue_draw(drawing
->drawing_area
);
1558 drawing
->damage_begin
= 0;
1559 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1561 drawing_data_request(control_flow_data
->drawing
,
1563 control_flow_data
->drawing
->width
,
1564 control_flow_data
->drawing
->height
);
1567 /* Update directly when scrolling */
1568 gdk_window_process_updates(control_flow_data
->drawing
->drawing_area
->window
,
1574 gint
traceset_notify(void *hook_data
, void *call_data
)
1576 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1577 Drawing_t
*drawing
= control_flow_data
->drawing
;
1579 if(unlikely(drawing
->gc
== NULL
)) {
1582 if(drawing
->dotted_gc
== NULL
) {
1586 drawing_clear(control_flow_data
->drawing
);
1587 processlist_clear(control_flow_data
->process_list
);
1588 gtk_widget_set_size_request(
1589 control_flow_data
->drawing
->drawing_area
,
1590 -1, processlist_get_height(control_flow_data
->process_list
));
1591 redraw_notify(control_flow_data
, NULL
);
1593 request_background_data(control_flow_data
);
1598 gint
redraw_notify(void *hook_data
, void *call_data
)
1600 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1601 Drawing_t
*drawing
= control_flow_data
->drawing
;
1602 GtkWidget
*widget
= drawing
->drawing_area
;
1604 drawing
->damage_begin
= 0;
1605 drawing
->damage_end
= drawing
->width
;
1607 /* fun feature, to be separated someday... */
1608 drawing_clear(control_flow_data
->drawing
);
1609 processlist_clear(control_flow_data
->process_list
);
1610 gtk_widget_set_size_request(
1611 control_flow_data
->drawing
->drawing_area
,
1612 -1, processlist_get_height(control_flow_data
->process_list
));
1614 rectangle_pixmap (control_flow_data
->process_list
,
1615 widget
->style
->black_gc
,
1618 drawing
->alloc_width
,
1621 gtk_widget_queue_draw(drawing
->drawing_area
);
1623 if(drawing
->damage_begin
< drawing
->damage_end
)
1625 drawing_data_request(drawing
,
1626 drawing
->damage_begin
,
1628 drawing
->damage_end
-drawing
->damage_begin
,
1632 //gtk_widget_queue_draw_area(drawing->drawing_area,
1635 // drawing->height);
1641 gint
continue_notify(void *hook_data
, void *call_data
)
1643 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1644 Drawing_t
*drawing
= control_flow_data
->drawing
;
1646 //g_assert(widget->allocation.width == drawing->damage_end);
1648 if(drawing
->damage_begin
< drawing
->damage_end
)
1650 drawing_data_request(drawing
,
1651 drawing
->damage_begin
,
1653 drawing
->damage_end
-drawing
->damage_begin
,
1661 gint
update_current_time_hook(void *hook_data
, void *call_data
)
1664 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
1666 LttTime current_time
= *((LttTime
*)call_data
);
1668 TimeWindow time_window
=
1669 lttvwindow_get_time_window(control_flow_data
->tab
);
1671 LttTime time_begin
= time_window
.start_time
;
1672 LttTime width
= time_window
.time_width
;
1675 guint64 time_ll
= ltt_time_to_uint64(width
);
1676 time_ll
= time_ll
>> 1; /* divide by two */
1677 half_width
= ltt_time_from_uint64(time_ll
);
1679 LttTime time_end
= ltt_time_add(time_begin
, width
);
1681 LttvTraceset
* ts
= lttvwindow_get_traceset(control_flow_data
->tab
);
1683 TimeInterval time_span
= lttv_traceset_get_time_span_real(ts
);
1684 LttTime trace_start
= time_span
.start_time
;
1685 LttTime trace_end
= time_span
.end_time
;
1687 g_info("New current time HOOK : %lu, %lu", current_time
.tv_sec
,
1688 current_time
.tv_nsec
);
1692 /* If current time is inside time interval, just move the highlight
1695 /* Else, we have to change the time interval. We have to tell it
1696 * to the main window. */
1697 /* The time interval change will take care of placing the current
1698 * time at the center of the visible area, or nearest possible if we are
1699 * at one end of the trace. */
1702 if(ltt_time_compare(current_time
, time_begin
) < 0)
1704 TimeWindow new_time_window
;
1706 if(ltt_time_compare(current_time
,
1707 ltt_time_add(trace_start
,half_width
)) < 0)
1708 time_begin
= trace_start
;
1710 time_begin
= ltt_time_sub(current_time
,half_width
);
1712 new_time_window
.start_time
= time_begin
;
1713 new_time_window
.time_width
= width
;
1714 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1715 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1717 lttvwindow_report_time_window(control_flow_data
->tab
, new_time_window
);
1719 else if(ltt_time_compare(current_time
, time_end
) > 0)
1721 TimeWindow new_time_window
;
1723 if(ltt_time_compare(current_time
, ltt_time_sub(trace_end
, half_width
)) > 0)
1724 time_begin
= ltt_time_sub(trace_end
,width
);
1726 time_begin
= ltt_time_sub(current_time
,half_width
);
1728 new_time_window
.start_time
= time_begin
;
1729 new_time_window
.time_width
= width
;
1730 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1731 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1733 lttvwindow_report_time_window(control_flow_data
->tab
, new_time_window
);
1736 gtk_widget_queue_draw(control_flow_data
->drawing
->drawing_area
);
1738 /* Update directly when scrolling */
1739 gdk_window_process_updates(control_flow_data
->drawing
->drawing_area
->window
,
1746 typedef struct _ClosureData
{
1747 EventsRequest
*events_request
;
1753 void draw_closure(gpointer key
, gpointer value
, gpointer user_data
)
1756 ProcessInfo
*process_info
= (ProcessInfo
*)key
;
1757 HashedProcessData
*hashed_process_data
= (HashedProcessData
*)value
;
1758 ClosureData
*closure_data
= (ClosureData
*)user_data
;
1760 EventsRequest
*events_request
= closure_data
->events_request
;
1761 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1762 LttvTraceset
*ts
= lttvwindow_get_traceset(control_flow_data
->tab
);
1765 LttTime evtime
= closure_data
->end_time
;
1767 gboolean dodraw
= TRUE
;
1770 /* For the process */
1771 /* First, check if the current process is in the state computation
1772 * process list. If it is there, that means we must add it right now and
1773 * draw items from the beginning of the read for it. If it is not
1774 * present, it's a new process and it was not present : it will
1775 * be added after the state update. */
1777 g_assert(lttv_traceset_number(tsc
->ts
) > 0);
1778 #endif //EXTRA_CHECK
1779 //TODO Fdeslauriers 2012-07-17: adapt for multiple traces
1780 LttvTrace
*trace
= lttv_traceset_get(ts
,0);
1781 LttvTraceState
*trace_state
= trace
->state
;
1784 //FIXME : optimize data structures.
1785 LttvTracefileState
*tfs
;
1786 LttvTracefileContext
*tfc
;
1788 for(i
=0;i
<tc
->tracefiles
->len
;i
++) {
1789 tfc
= g_array_index(tc
->tracefiles
, LttvTracefileContext
*, i
);
1790 if(ltt_tracefile_name(tfc
->tf
) == LTT_NAME_CPU
1791 && tfs
->cpu
== process_info
->cpu
)
1795 g_assert(i
<tc
->tracefiles
->len
);
1796 tfs
= LTTV_TRACEFILE_STATE(tfc
);
1798 // LttvTracefileState *tfs =ts
1799 // (LttvTracefileState*)tsc->traces[process_info->trace_num]->
1800 // tracefiles[process_info->cpu];
1802 LttvProcessState
*process
;
1803 process
= lttv_state_find_process(trace_state
, process_info
->cpu
,
1806 if(unlikely(process
!= NULL
)) {
1807 #ifdef BABEL_CLEANUP
1808 LttvFilter
*filter
= control_flow_data
->filter
;
1809 if(filter
!= NULL
&& filter
->head
!= NULL
)
1810 if(!lttv_filter_tree_parse(filter
->head
,NULL
,NULL
,
1811 tc
->t
,NULL
,process
,tc
))
1813 #endif //babel_cleanup
1814 /* Only draw for processes that are currently in the trace states */
1817 /* Should be alike when background info is ready */
1818 if(control_flow_data
->background_info_waiting
==0)
1819 g_assert(ltt_time_compare(process
->creation_time
,
1820 process_info
->birth
) == 0);
1821 #endif //EXTRA_CHECK
1823 /* Now, the process is in the state hash and our own process hash.
1824 * We definitely can draw the items related to the ending state.
1827 if(unlikely(ltt_time_compare(hashed_process_data
->next_good_time
,
1830 TimeWindow time_window
=
1831 lttvwindow_get_time_window(control_flow_data
->tab
);
1834 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1835 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1837 #endif //EXTRA_CHECK
1838 Drawing_t
*drawing
= control_flow_data
->drawing
;
1839 guint width
= drawing
->width
;
1841 guint x
= closure_data
->x_end
;
1843 DrawContext draw_context
;
1845 init_drawing_context(&draw_context
,
1846 hashed_process_data
,
1851 /* Jump over draw if we are at the same x position */
1852 if(x
== hashed_process_data
->x
.over
)
1856 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.over
;
1858 PropertiesLine prop_line
= prepare_execmode_line(process
);
1859 draw_line((void*)&prop_line
, (void*)&draw_context
);
1861 hashed_process_data
->x
.over
= x
;
1865 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1866 hashed_process_data
->x
.middle_used
)) {
1867 #if 0 /* do not mark closure : not missing information */
1868 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
1869 /* Draw collision indicator */
1870 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1871 gdk_draw_point(drawing
->pixmap
,
1875 hashed_process_data
->x
.middle_marked
= TRUE
;
1880 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1883 PropertiesLine prop_line
= prepare_s_e_line(process
);
1884 draw_line((void*)&prop_line
, (void*)&draw_context
);
1887 /* become the last x position */
1888 if(likely(x
!= hashed_process_data
->x
.middle
)) {
1889 hashed_process_data
->x
.middle
= x
;
1890 /* but don't use the pixel */
1891 hashed_process_data
->x
.middle_used
= FALSE
;
1893 /* Calculate the next good time */
1894 convert_pixels_to_time(width
, x
+1, time_window
,
1895 &hashed_process_data
->next_good_time
);
1904 int before_chunk(void *hook_data
, void *call_data
)
1907 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1908 LttvTraceset
*ts
= (LttvTraceset
*)call_data
;
1910 /* Desactivate sort */
1911 gtk_tree_sortable_set_sort_column_id(
1912 GTK_TREE_SORTABLE(cfd
->process_list
->list_store
),
1914 GTK_SORT_ASCENDING
);
1916 drawing_chunk_begin(events_request
, ts
);
1921 int before_request(void *hook_data
, void *call_data
)
1924 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1926 drawing_data_request_begin(events_request
);
1933 void draw_closing_lines(ControlFlowData
*control_flow_data
,
1934 EventsRequest
* events_request
)
1936 ProcessList
*process_list
= control_flow_data
->process_list
;
1939 ClosureData closure_data
;
1940 closure_data
.events_request
= events_request
;
1941 closure_data
.end_time
= events_request
->end_time
;
1943 TimeWindow time_window
=
1944 lttvwindow_get_time_window(control_flow_data
->tab
);
1945 guint width
= control_flow_data
->drawing
->width
;
1946 convert_time_to_pixels(
1948 events_request
->end_time
,
1950 &closure_data
.x_end
);
1953 /* Draw last items */
1954 g_hash_table_foreach(process_list
->process_hash
, draw_closure
,
1955 (void*)&closure_data
);
1958 /* Request expose */
1959 drawing_request_expose(events_request
, events_request
->end_time
);
1963 * after request is necessary in addition of after chunk in order to draw
1964 * lines until the end of the screen. after chunk just draws lines until
1971 int after_request(void *hook_data
, void *call_data
)
1974 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1975 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1977 draw_closing_lines(control_flow_data
, events_request
);
1987 int after_chunk(void *hook_data
, void *call_data
)
1990 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1991 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1992 LttvTraceset
*ts
= (LttvTraceset
*)call_data
;
1995 ProcessList
*process_list
= control_flow_data
->process_list
;
1997 guint nb_trace
= lttv_traceset_number(ts
);
1999 /* Only execute when called for the first trace's events request */
2000 if(!process_list
->current_hash_data
)
2003 for(i
= 0 ; i
< nb_trace
; i
++) {
2004 g_free(process_list
->current_hash_data
[i
]);
2006 g_free(process_list
->current_hash_data
);
2007 process_list
->current_hash_data
= NULL
;
2009 draw_closing_lines(control_flow_data
, events_request
);
2014 /* after_statedump_end
2016 * @param hook_data ControlFlowData structure of the viewer.
2017 * @param call_data Event context.
2019 * This function adds items to be drawn in a queue for each process.
2022 int before_statedump_end(void *hook_data
, void *call_data
)
2026 event
= (LttvEvent
*) call_data
;
2028 if (strcmp(lttv_traceset_get_name_from_event(event
),"lttng_statedump_end") != 0)
2031 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
2034 LttvTraceState
*ts
= event
->state
;
2037 ProcessList
*process_list
= control_flow_data
->process_list
;
2039 #ifdef BABEL_CLEANUP
2040 LttvFilter
*filter
= control_flow_data
->filter
;
2041 if(filter
!= NULL
&& filter
->head
!= NULL
)
2042 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
2043 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
2047 LttTime evtime
= lttv_event_get_timestamp(event
);
2049 ClosureData closure_data
;
2050 //TODO ybrosseau 2013-03-27: Fake and event_request.
2051 // We need to change the API of drawing_request_expose to ask
2052 // For and control flow data only.
2053 EventsRequest events_request
;
2054 events_request
.viewer_data
= control_flow_data
;
2055 closure_data
.events_request
= &events_request
;
2056 closure_data
.end_time
= evtime
;
2058 TimeWindow time_window
=
2059 lttvwindow_get_time_window(control_flow_data
->tab
);
2060 guint width
= control_flow_data
->drawing
->width
;
2061 convert_time_to_pixels(
2065 &closure_data
.x_end
);
2067 /* Draw last items */
2068 g_hash_table_foreach(process_list
->process_hash
, draw_closure
,
2069 (void*)&closure_data
);
2072 /* Reactivate sort */
2073 gtk_tree_sortable_set_sort_column_id(
2074 GTK_TREE_SORTABLE(control_flow_data
->process_list
->list_store
),
2075 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
,
2076 GTK_SORT_ASCENDING
);
2078 update_index_to_pixmap(control_flow_data
->process_list
);
2079 /* Request a full expose : drawing scrambled */
2080 gtk_widget_queue_draw(control_flow_data
->drawing
->drawing_area
);
2082 /* Request expose (updates damages zone also) */
2083 drawing_request_expose(&events_request
, evtime
);