1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Mathieu Desnoyers
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 /*****************************************************************************
21 * Hooks to be called by the main window *
22 *****************************************************************************/
25 /* Event hooks are the drawing hooks called during traceset read. They draw the
26 * icons, text, lines and background color corresponding to the events read.
28 * Two hooks are used for drawing : before_schedchange and after_schedchange hooks. The
29 * before_schedchange is called before the state update that occurs with an event and
30 * the after_schedchange hook is called after this state update.
32 * The before_schedchange hooks fulfill the task of drawing the visible objects that
33 * corresponds to the data accumulated by the after_schedchange hook.
35 * The after_schedchange hook accumulates the data that need to be shown on the screen
36 * (items) into a queue. Then, the next before_schedchange hook will draw what that
37 * queue contains. That's the Right Way (TM) of drawing items on the screen,
38 * because we need to draw the background first (and then add icons, text, ...
39 * over it), but we only know the length of a background region once the state
40 * corresponding to it is over, which happens to be at the next before_schedchange
43 * We also have a hook called at the end of a chunk to draw the information left
44 * undrawn in each process queue. We use the current time as end of
52 //#define PANGO_ENABLE_BACKEND
60 //#include <pango/pango.h>
62 #include <ltt/event.h>
65 #include <ltt/trace.h>
67 #include <lttv/lttv.h>
68 #include <lttv/hook.h>
69 #include <lttv/state.h>
70 #include <lttvwindow/lttvwindow.h>
71 #include <lttvwindow/lttvwindowtraces.h>
72 #include <lttvwindow/support.h>
75 #include "eventhooks.h"
77 #include "processlist.h"
81 #define MAX_PATH_LEN 256
82 #define STATE_LINE_WIDTH 4
83 #define COLLISION_POSITION(height) (((height - STATE_LINE_WIDTH)/2) -3)
85 extern GSList
*g_legend_list
;
88 /* Action to do when background computation completed.
90 * Wait for all the awaited computations to be over.
93 static gint
background_ready(void *hook_data
, void *call_data
)
95 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
96 LttvTrace
*trace
= (LttvTrace
*)call_data
;
98 control_flow_data
->background_info_waiting
--;
100 if(control_flow_data
->background_info_waiting
== 0) {
101 g_message("control flow viewer : background computation data ready.");
103 drawing_clear(control_flow_data
->drawing
);
104 processlist_clear(control_flow_data
->process_list
);
105 gtk_widget_set_size_request(
106 control_flow_data
->drawing
->drawing_area
,
107 -1, processlist_get_height(control_flow_data
->process_list
));
108 redraw_notify(control_flow_data
, NULL
);
115 /* Request background computation. Verify if it is in progress or ready first.
116 * Only for each trace in the tab's traceset.
118 static void request_background_data(ControlFlowData
*control_flow_data
)
120 LttvTracesetContext
* tsc
=
121 lttvwindow_get_traceset_context(control_flow_data
->tab
);
122 gint num_traces
= lttv_traceset_number(tsc
->ts
);
125 LttvTraceState
*tstate
;
127 LttvHooks
*background_ready_hook
=
129 lttv_hooks_add(background_ready_hook
, background_ready
, control_flow_data
,
131 control_flow_data
->background_info_waiting
= 0;
133 for(i
=0;i
<num_traces
;i
++) {
134 trace
= lttv_traceset_get(tsc
->ts
, i
);
135 tstate
= LTTV_TRACE_STATE(tsc
->traces
[i
]);
137 if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace
)==FALSE
138 && !tstate
->has_precomputed_states
) {
140 if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"),
142 /* We first remove requests that could have been done for the same
143 * information. Happens when two viewers ask for it before servicing
146 if(!lttvwindowtraces_background_request_find(trace
, "state"))
147 lttvwindowtraces_background_request_queue(
148 main_window_get_widget(control_flow_data
->tab
), trace
, "state");
149 lttvwindowtraces_background_notify_queue(control_flow_data
,
153 background_ready_hook
);
154 control_flow_data
->background_info_waiting
++;
155 } else { /* in progress */
157 lttvwindowtraces_background_notify_current(control_flow_data
,
161 background_ready_hook
);
162 control_flow_data
->background_info_waiting
++;
165 /* Data ready. By its nature, this viewer doesn't need to have
166 * its data ready hook called there, because a background
167 * request is always linked with a redraw.
173 lttv_hooks_destroy(background_ready_hook
);
180 * Event Viewer's constructor hook
182 * This constructor is given as a parameter to the menuitem and toolbar button
183 * registration. It creates the list.
184 * @param tab A pointer to the parent tab.
185 * @return The widget created.
188 h_resourceview(LttvPlugin
*plugin
)
190 LttvPluginTab
*ptab
= LTTV_PLUGIN_TAB(plugin
);
191 Tab
*tab
= ptab
->tab
;
192 g_info("h_guicontrolflow, %p", tab
);
193 ControlFlowData
*control_flow_data
= resourceview(ptab
);
195 control_flow_data
->tab
= tab
;
197 // Unreg done in the GuiControlFlow_Destructor
198 lttvwindow_register_traceset_notify(tab
,
202 lttvwindow_register_time_window_notify(tab
,
203 update_time_window_hook
,
205 lttvwindow_register_current_time_notify(tab
,
206 update_current_time_hook
,
208 lttvwindow_register_redraw_notify(tab
,
211 lttvwindow_register_continue_notify(tab
,
214 request_background_data(control_flow_data
);
217 return guicontrolflow_get_widget(control_flow_data
) ;
221 void legend_destructor(GtkWindow
*legend
)
223 g_legend_list
= g_slist_remove(g_legend_list
, legend
);
226 /* Create a popup legend */
228 h_legend(LttvPlugin
*plugin
)
230 LttvPluginTab
*ptab
= LTTV_PLUGIN_TAB(plugin
);
231 Tab
*tab
= ptab
->tab
;
232 g_info("h_legend, %p", tab
);
234 GtkWindow
*legend
= GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL
));
236 g_legend_list
= g_slist_append(
240 g_object_set_data_full(
244 (GDestroyNotify
)legend_destructor
);
246 gtk_window_set_title(legend
, "Control Flow View Legend");
248 GtkWidget
*pixmap
= create_pixmap(GTK_WIDGET(legend
), "lttv-color-list.png");
250 // GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixmap(
251 // GDK_PIXMAP(pixmap), NULL));
253 gtk_container_add(GTK_CONTAINER(legend
), GTK_WIDGET(pixmap
));
255 gtk_widget_show(GTK_WIDGET(pixmap
));
256 gtk_widget_show(GTK_WIDGET(legend
));
259 return NULL
; /* This is a popup window */
263 int event_selected_hook(void *hook_data
, void *call_data
)
265 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
266 guint
*event_number
= (guint
*) call_data
;
268 g_debug("DEBUG : event selected by main window : %u", *event_number
);
273 /* Function that selects the color of status&exemode line */
274 static inline PropertiesLine
prepare_s_e_line(LttvProcessState
*process
)
276 PropertiesLine prop_line
;
277 prop_line
.line_width
= STATE_LINE_WIDTH
;
278 prop_line
.style
= GDK_LINE_SOLID
;
279 prop_line
.y
= MIDDLE
;
281 if(process
->state
->s
== LTTV_STATE_RUN
) {
282 if(process
->state
->t
== LTTV_STATE_USER_MODE
)
283 prop_line
.color
= drawing_colors
[COL_RUN_USER_MODE
];
284 else if(process
->state
->t
== LTTV_STATE_SYSCALL
)
285 prop_line
.color
= drawing_colors
[COL_RUN_SYSCALL
];
286 else if(process
->state
->t
== LTTV_STATE_TRAP
)
287 prop_line
.color
= drawing_colors
[COL_RUN_TRAP
];
288 else if(process
->state
->t
== LTTV_STATE_IRQ
)
289 prop_line
.color
= drawing_colors
[COL_RUN_IRQ
];
290 else if(process
->state
->t
== LTTV_STATE_SOFT_IRQ
)
291 prop_line
.color
= drawing_colors
[COL_RUN_SOFT_IRQ
];
292 else if(process
->state
->t
== LTTV_STATE_MODE_UNKNOWN
)
293 prop_line
.color
= drawing_colors
[COL_MODE_UNKNOWN
];
295 g_assert(FALSE
); /* RUNNING MODE UNKNOWN */
296 } else if(process
->state
->s
== LTTV_STATE_WAIT
) {
297 /* We don't show if we wait while in user mode, trap, irq or syscall */
298 prop_line
.color
= drawing_colors
[COL_WAIT
];
299 } else if(process
->state
->s
== LTTV_STATE_WAIT_CPU
) {
300 /* We don't show if we wait for CPU while in user mode, trap, irq
302 prop_line
.color
= drawing_colors
[COL_WAIT_CPU
];
303 } else if(process
->state
->s
== LTTV_STATE_ZOMBIE
) {
304 prop_line
.color
= drawing_colors
[COL_ZOMBIE
];
305 } else if(process
->state
->s
== LTTV_STATE_WAIT_FORK
) {
306 prop_line
.color
= drawing_colors
[COL_WAIT_FORK
];
307 } else if(process
->state
->s
== LTTV_STATE_EXIT
) {
308 prop_line
.color
= drawing_colors
[COL_EXIT
];
309 } else if(process
->state
->s
== LTTV_STATE_UNNAMED
) {
310 prop_line
.color
= drawing_colors
[COL_UNNAMED
];
312 g_critical("unknown state : %s", g_quark_to_string(process
->state
->s
));
313 g_assert(FALSE
); /* UNKNOWN STATE */
320 static void cpu_set_line_color(PropertiesLine
*prop_line
, LttvCPUState
*s
)
322 GQuark present_state
= ((GQuark
*)s
->mode_stack
->data
)[s
->mode_stack
->len
-1];
324 if(present_state
== LTTV_CPU_IDLE
) {
325 prop_line
->color
= drawing_colors_cpu
[COL_CPU_IDLE
];
327 else if(present_state
== LTTV_CPU_BUSY
) {
328 prop_line
->color
= drawing_colors_cpu
[COL_CPU_BUSY
];
330 else if(present_state
== LTTV_CPU_IRQ
) {
331 prop_line
->color
= drawing_colors_cpu
[COL_CPU_IRQ
];
333 else if(present_state
== LTTV_CPU_TRAP
) {
334 prop_line
->color
= drawing_colors_cpu
[COL_CPU_TRAP
];
336 prop_line
->color
= drawing_colors_cpu
[COL_CPU_UNKNOWN
];
340 static void irq_set_line_color(PropertiesLine
*prop_line
, LttvIRQState
*s
)
342 GQuark present_state
= ((GQuark
*)s
->mode_stack
->data
)[s
->mode_stack
->len
-1];
344 if(present_state
== LTTV_IRQ_UNKNOWN
) {
345 prop_line
->color
= drawing_colors_irq
[COL_IRQ_UNKNOWN
];
347 else if(present_state
== LTTV_IRQ_IDLE
) {
348 prop_line
->color
= drawing_colors_irq
[COL_IRQ_IDLE
];
350 else if(present_state
== LTTV_IRQ_BUSY
) {
351 prop_line
->color
= drawing_colors_irq
[COL_IRQ_BUSY
];
355 /* before_schedchange_hook
357 * This function basically draw lines and icons. Two types of lines are drawn :
358 * one small (3 pixels?) representing the state of the process and the second
359 * type is thicker (10 pixels?) representing on which CPU a process is running
360 * (and this only in running state).
362 * Extremums of the lines :
363 * x_min : time of the last event context for this process kept in memory.
364 * x_max : time of the current event.
365 * y : middle of the process in the process list. The process is found in the
366 * list, therefore is it's position in pixels.
368 * The choice of lines'color is defined by the context of the last event for this
373 int before_schedchange_hook(void *hook_data
, void *call_data
)
375 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
376 EventsRequest
*events_request
= (EventsRequest
*)thf
->hook_data
;
377 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
379 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
381 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
382 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
385 e
= ltt_tracefile_get_event(tfc
->tf
);
386 gint target_pid_saved
= tfc
->target_pid
;
388 LttTime evtime
= ltt_event_time(e
);
389 LttvFilter
*filter
= control_flow_data
->filter
;
393 /* we are in a schedchange, before the state update. We must draw the
394 * items corresponding to the state before it changes : now is the right
400 pid_out
= ltt_event_get_long_unsigned(e
, thf
->f1
);
401 pid_in
= ltt_event_get_long_unsigned(e
, thf
->f2
);
402 // if(pid_in != 0 && pid_out != 0) {
403 // /* not a transition to/from idle */
407 tfc
->target_pid
= pid_out
;
408 // if(!filter || !filter->head ||
409 // lttv_filter_tree_parse(filter->head,e,tfc->tf,
410 // tfc->t_context->t,tfc,NULL,NULL)) {
411 /* For the pid_out */
412 /* First, check if the current process is in the state computation
413 * process list. If it is there, that means we must add it right now and
414 * draw items from the beginning of the read for it. If it is not
415 * present, it's a new process and it was not present : it will
416 * be added after the state update. */
417 guint cpu
= tfs
->cpu
;
420 cpustr
= g_strdup_printf("CPU%u", cpu
);
421 cpuq
= g_quark_from_string(cpustr
);
425 guint trace_num
= ts
->parent
.index
;
426 // LttvProcessState *process = ts->running_process[cpu];
427 /* unknown state, bad current pid */
428 // if(process->pid != pid_out)
429 // process = lttv_state_find_process(ts,
430 // tfs->cpu, pid_out);
432 // if(process != NULL) {
433 /* Well, the process_out existed : we must get it in the process hash
434 * or add it, and draw its items.
436 /* Add process to process list (if not present) */
438 HashedResourceData
*hashed_process_data
= NULL
;
439 ProcessList
*process_list
= control_flow_data
->process_list
;
440 // LttTime birth = process->creation_time;
442 hashed_process_data
= processlist_get_process_data(process_list
, cpuq
, trace_num
);
443 // hashed_process_data = processlist_get_process_data(process_list,
448 if(hashed_process_data
== NULL
)
450 // g_assert(pid_out == 0 || pid_out != process->ppid);
451 /* Process not present */
452 ResourceInfo
*process_info
;
453 Drawing_t
*drawing
= control_flow_data
->drawing
;
454 resourcelist_add(process_list
,
457 cpuq
, //process->name,
462 &hashed_process_data
);
463 gtk_widget_set_size_request(drawing
->drawing_area
,
466 gtk_widget_queue_draw(drawing
->drawing_area
);
470 /* Now, the process is in the state hash and our own process hash.
471 * We definitely can draw the items related to the ending state.
474 if(ltt_time_compare(hashed_process_data
->next_good_time
,
477 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
479 TimeWindow time_window
=
480 lttvwindow_get_time_window(control_flow_data
->tab
);
482 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
483 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
486 Drawing_t
*drawing
= control_flow_data
->drawing
;
487 guint width
= drawing
->width
;
489 convert_time_to_pixels(
495 /* Draw collision indicator */
496 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
497 gdk_draw_point(hashed_process_data
->pixmap
,
500 COLLISION_POSITION(hashed_process_data
->height
));
501 hashed_process_data
->x
.middle_marked
= TRUE
;
504 TimeWindow time_window
=
505 lttvwindow_get_time_window(control_flow_data
->tab
);
507 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
508 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
511 Drawing_t
*drawing
= control_flow_data
->drawing
;
512 guint width
= drawing
->width
;
514 convert_time_to_pixels(
521 /* Jump over draw if we are at the same x position */
522 if(x
== hashed_process_data
->x
.middle
&&
523 hashed_process_data
->x
.middle_used
)
525 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
526 /* Draw collision indicator */
527 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
528 gdk_draw_point(hashed_process_data
->pixmap
,
531 COLLISION_POSITION(hashed_process_data
->height
));
532 hashed_process_data
->x
.middle_marked
= TRUE
;
536 DrawContext draw_context
;
538 /* Now create the drawing context that will be used to draw
539 * items related to the last state. */
540 draw_context
.drawable
= hashed_process_data
->pixmap
;
541 draw_context
.gc
= drawing
->gc
;
542 draw_context
.pango_layout
= drawing
->pango_layout
;
543 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
544 draw_context
.drawinfo
.end
.x
= x
;
546 draw_context
.drawinfo
.y
.over
= 1;
547 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
548 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
550 draw_context
.drawinfo
.start
.offset
.over
= 0;
551 draw_context
.drawinfo
.start
.offset
.middle
= 0;
552 draw_context
.drawinfo
.start
.offset
.under
= 0;
553 draw_context
.drawinfo
.end
.offset
.over
= 0;
554 draw_context
.drawinfo
.end
.offset
.middle
= 0;
555 draw_context
.drawinfo
.end
.offset
.under
= 0;
559 //PropertiesLine prop_line = prepare_s_e_line(process);
560 PropertiesLine prop_line
;
561 prop_line
.line_width
= STATE_LINE_WIDTH
;
562 prop_line
.style
= GDK_LINE_SOLID
;
563 prop_line
.y
= MIDDLE
;
564 cpu_set_line_color(&prop_line
, tfs
->cpu_state
);
565 draw_line((void*)&prop_line
, (void*)&draw_context
);
568 /* become the last x position */
569 hashed_process_data
->x
.middle
= x
;
570 hashed_process_data
->x
.middle_used
= TRUE
;
571 hashed_process_data
->x
.middle_marked
= FALSE
;
573 /* Calculate the next good time */
574 convert_pixels_to_time(width
, x
+1, time_window
,
575 &hashed_process_data
->next_good_time
);
581 // tfc->target_pid = pid_in;
582 // if(!filter || !filter->head ||
583 // lttv_filter_tree_parse(filter->head,e,tfc->tf,
584 // tfc->t_context->t,tfc,NULL,NULL)) {
585 // /* For the pid_in */
586 // /* First, check if the current process is in the state computation
587 // * process list. If it is there, that means we must add it right now and
588 // * draw items from the beginning of the read for it. If it is not
589 // * present, it's a new process and it was not present : it will
590 // * be added after the state update. */
591 // LttvProcessState *process;
592 // process = lttv_state_find_process(ts,
593 // tfs->cpu, pid_in);
594 // guint trace_num = ts->parent.index;
596 // if(process != NULL) {
597 // /* Well, the process existed : we must get it in the process hash
598 // * or add it, and draw its items.
600 // /* Add process to process list (if not present) */
601 // guint pl_height = 0;
602 // HashedResourceData *hashed_process_data = NULL;
603 // ProcessList *process_list = control_flow_data->process_list;
604 // LttTime birth = process->creation_time;
606 // hashed_process_data = processlist_get_process_data(process_list, cpuq);
607 //// hashed_process_data = processlist_get_process_data(process_list,
612 // if(hashed_process_data == NULL)
614 // g_assert(pid_in == 0 || pid_in != process->ppid);
615 // /* Process not present */
616 // ResourceInfo *process_info;
617 // Drawing_t *drawing = control_flow_data->drawing;
618 // resourcelist_add(process_list,
630 // &hashed_process_data);
631 // gtk_widget_set_size_request(drawing->drawing_area,
634 // gtk_widget_queue_draw(drawing->drawing_area);
637 // //We could set the current process and hash here, but will be done
638 // //by after schedchange hook
640 // /* Now, the process is in the state hash and our own process hash.
641 // * We definitely can draw the items related to the ending state.
644 // if(ltt_time_compare(hashed_process_data->next_good_time,
647 // if(hashed_process_data->x.middle_marked == FALSE) {
649 // TimeWindow time_window =
650 // lttvwindow_get_time_window(control_flow_data->tab);
652 // if(ltt_time_compare(evtime, time_window.start_time) == -1
653 // || ltt_time_compare(evtime, time_window.end_time) == 1)
655 //#endif //EXTRA_CHECK
656 // Drawing_t *drawing = control_flow_data->drawing;
657 // guint width = drawing->width;
659 // convert_time_to_pixels(
665 // /* Draw collision indicator */
666 // gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
667 // gdk_draw_point(hashed_process_data->pixmap,
670 // COLLISION_POSITION(hashed_process_data->height));
671 // hashed_process_data->x.middle_marked = TRUE;
674 // TimeWindow time_window =
675 // lttvwindow_get_time_window(control_flow_data->tab);
677 // if(ltt_time_compare(evtime, time_window.start_time) == -1
678 // || ltt_time_compare(evtime, time_window.end_time) == 1)
680 //#endif //EXTRA_CHECK
681 // Drawing_t *drawing = control_flow_data->drawing;
682 // guint width = drawing->width;
685 // convert_time_to_pixels(
692 // /* Jump over draw if we are at the same x position */
693 // if(x == hashed_process_data->x.middle &&
694 // hashed_process_data->x.middle_used)
696 // if(hashed_process_data->x.middle_marked == FALSE) {
697 // /* Draw collision indicator */
698 // gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
699 // gdk_draw_point(hashed_process_data->pixmap,
702 // COLLISION_POSITION(hashed_process_data->height));
703 // hashed_process_data->x.middle_marked = TRUE;
707 // DrawContext draw_context;
709 // /* Now create the drawing context that will be used to draw
710 // * items related to the last state. */
711 // draw_context.drawable = hashed_process_data->pixmap;
712 // draw_context.gc = drawing->gc;
713 // draw_context.pango_layout = drawing->pango_layout;
714 // draw_context.drawinfo.start.x = hashed_process_data->x.middle;
715 // draw_context.drawinfo.end.x = x;
717 // draw_context.drawinfo.y.over = 1;
718 // draw_context.drawinfo.y.middle = (hashed_process_data->height/2);
719 // draw_context.drawinfo.y.under = hashed_process_data->height;
721 // draw_context.drawinfo.start.offset.over = 0;
722 // draw_context.drawinfo.start.offset.middle = 0;
723 // draw_context.drawinfo.start.offset.under = 0;
724 // draw_context.drawinfo.end.offset.over = 0;
725 // draw_context.drawinfo.end.offset.middle = 0;
726 // draw_context.drawinfo.end.offset.under = 0;
729 // /* Draw the line */
730 // PropertiesLine prop_line = prepare_s_e_line(process);
731 // draw_line((void*)&prop_line, (void*)&draw_context);
735 // /* become the last x position */
736 // hashed_process_data->x.middle = x;
737 // hashed_process_data->x.middle_used = TRUE;
738 // hashed_process_data->x.middle_marked = FALSE;
740 // /* Calculate the next good time */
741 // convert_pixels_to_time(width, x+1, time_window,
742 // &hashed_process_data->next_good_time);
746 // g_warning("Cannot find pin_in in schedchange %u", pid_in);
748 // tfc->target_pid = target_pid_saved;
756 GString
*string
= g_string_new("");;
757 gboolean field_names
= TRUE
, state
= TRUE
;
759 lttv_event_to_string(e
, tfc
->tf
, string
, TRUE
, field_names
, tfs
);
760 g_string_append_printf(string
,"\n");
763 g_string_append_printf(string
, " %s",
764 g_quark_to_string(tfs
->process
->state
->s
));
767 g_info("%s",string
->str
);
769 g_string_free(string
, TRUE
);
771 /* End of text dump */
776 /* after_schedchange_hook
778 * The draw after hook is called by the reading API to have a
779 * particular event drawn on the screen.
780 * @param hook_data ControlFlowData structure of the viewer.
781 * @param call_data Event context.
783 * This function adds items to be drawn in a queue for each process.
786 int after_schedchange_hook(void *hook_data
, void *call_data
)
788 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
789 EventsRequest
*events_request
= (EventsRequest
*)thf
->hook_data
;
790 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
792 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
794 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
796 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
799 e
= ltt_tracefile_get_event(tfc
->tf
);
801 LttvFilter
*filter
= control_flow_data
->filter
;
802 if(filter
!= NULL
&& filter
->head
!= NULL
)
803 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
804 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
807 LttTime evtime
= ltt_event_time(e
);
811 /* Add process to process list (if not present) */
812 LttvProcessState
*process_in
;
815 HashedResourceData
*hashed_process_data_in
= NULL
;
817 ProcessList
*process_list
= control_flow_data
->process_list
;
822 pid_out
= ltt_event_get_long_unsigned(e
, thf
->f1
);
823 pid_in
= ltt_event_get_long_unsigned(e
, thf
->f2
);
827 /* Find process pid_in in the list... */
828 //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in);
829 //process_in = tfs->process;
830 guint cpu
= tfs
->cpu
;
833 cpustr
= g_strdup_printf("CPU%u", cpu
);
834 cpuq
= g_quark_from_string(cpustr
);
837 guint trace_num
= ts
->parent
.index
;
838 process_in
= ts
->running_process
[cpu
];
839 /* It should exist, because we are after the state update. */
841 g_assert(process_in
!= NULL
);
843 birth
= process_in
->creation_time
;
845 hashed_process_data_in
= processlist_get_process_data(process_list
, cpuq
, trace_num
);
846 // hashed_process_data_in = processlist_get_process_data(process_list,
851 if(hashed_process_data_in
== NULL
)
853 g_assert(pid_in
== 0 || pid_in
!= process_in
->ppid
);
854 ResourceInfo
*process_info
;
855 Drawing_t
*drawing
= control_flow_data
->drawing
;
856 /* Process not present */
857 resourcelist_add(process_list
,
865 &hashed_process_data_in
);
866 gtk_widget_set_size_request(drawing
->drawing_area
,
869 gtk_widget_queue_draw(drawing
->drawing_area
);
871 /* Set the current process */
872 process_list
->current_hash_data
[trace_num
][process_in
->cpu
] =
873 hashed_process_data_in
;
875 if(ltt_time_compare(hashed_process_data_in
->next_good_time
,
878 TimeWindow time_window
=
879 lttvwindow_get_time_window(control_flow_data
->tab
);
882 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
883 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
886 Drawing_t
*drawing
= control_flow_data
->drawing
;
887 guint width
= drawing
->width
;
890 convert_time_to_pixels(
896 if(hashed_process_data_in
->x
.middle
!= new_x
) {
897 hashed_process_data_in
->x
.middle
= new_x
;
898 hashed_process_data_in
->x
.middle_used
= FALSE
;
899 hashed_process_data_in
->x
.middle_marked
= FALSE
;
905 /* before_execmode_hook
907 * This function basically draw lines and icons. Two types of lines are drawn :
908 * one small (3 pixels?) representing the state of the process and the second
909 * type is thicker (10 pixels?) representing on which CPU a process is running
910 * (and this only in running state).
912 * Extremums of the lines :
913 * x_min : time of the last event context for this process kept in memory.
914 * x_max : time of the current event.
915 * y : middle of the process in the process list. The process is found in the
916 * list, therefore is it's position in pixels.
918 * The choice of lines'color is defined by the context of the last event for this
922 int before_execmode_hook(void *hook_data
, void *call_data
)
924 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
925 EventsRequest
*events_request
= (EventsRequest
*)thf
->hook_data
;
926 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
928 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
930 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
931 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
934 e
= ltt_tracefile_get_event(tfc
->tf
);
936 LttTime evtime
= ltt_event_time(e
);
940 before_execmode_hook_irq(hook_data
, call_data
);
942 /* we are in a execmode, before the state update. We must draw the
943 * items corresponding to the state before it changes : now is the right
947 //LttvProcessState *process = tfs->process;
948 guint cpu
= tfs
->cpu
;
951 cpustr
= g_strdup_printf("CPU%u", cpu
);
952 cpuq
= g_quark_from_string(cpustr
);
955 guint trace_num
= ts
->parent
.index
;
956 LttvProcessState
*process
= ts
->running_process
[cpu
];
957 g_assert(process
!= NULL
);
959 // guint pid = process->pid;
961 /* Well, the process_out existed : we must get it in the process hash
962 * or add it, and draw its items.
964 /* Add process to process list (if not present) */
966 HashedResourceData
*hashed_process_data
= NULL
;
967 ProcessList
*process_list
= control_flow_data
->process_list
;
968 LttTime birth
= process
->creation_time
;
970 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
)) {
971 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
973 hashed_process_data
= processlist_get_process_data(process_list
, cpuq
, trace_num
);
974 // hashed_process_data = processlist_get_process_data(process_list,
979 if(unlikely(hashed_process_data
== NULL
))
981 //g_assert(pid == 0 || pid != process->ppid);
982 ResourceInfo
*process_info
;
983 /* Process not present */
984 Drawing_t
*drawing
= control_flow_data
->drawing
;
985 resourcelist_add(process_list
,
988 cpuq
, //process->name,
993 &hashed_process_data
);
994 gtk_widget_set_size_request(drawing
->drawing_area
,
997 gtk_widget_queue_draw(drawing
->drawing_area
);
999 /* Set the current process */
1000 process_list
->current_hash_data
[trace_num
][process
->cpu
] =
1001 hashed_process_data
;
1004 /* Now, the process is in the state hash and our own process hash.
1005 * We definitely can draw the items related to the ending state.
1008 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
1011 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1012 TimeWindow time_window
=
1013 lttvwindow_get_time_window(control_flow_data
->tab
);
1016 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1017 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1019 #endif //EXTRA_CHECK
1020 Drawing_t
*drawing
= control_flow_data
->drawing
;
1021 guint width
= drawing
->width
;
1023 convert_time_to_pixels(
1029 /* Draw collision indicator */
1030 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1031 gdk_draw_point(hashed_process_data
->pixmap
,
1034 COLLISION_POSITION(hashed_process_data
->height
));
1035 hashed_process_data
->x
.middle_marked
= TRUE
;
1039 TimeWindow time_window
=
1040 lttvwindow_get_time_window(control_flow_data
->tab
);
1043 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1044 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1046 #endif //EXTRA_CHECK
1047 Drawing_t
*drawing
= control_flow_data
->drawing
;
1048 guint width
= drawing
->width
;
1051 convert_time_to_pixels(
1058 /* Jump over draw if we are at the same x position */
1059 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1060 hashed_process_data
->x
.middle_used
))
1062 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1063 /* Draw collision indicator */
1064 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1065 gdk_draw_point(hashed_process_data
->pixmap
,
1068 COLLISION_POSITION(hashed_process_data
->height
));
1069 hashed_process_data
->x
.middle_marked
= TRUE
;
1075 DrawContext draw_context
;
1076 /* Now create the drawing context that will be used to draw
1077 * items related to the last state. */
1078 draw_context
.drawable
= hashed_process_data
->pixmap
;
1079 draw_context
.gc
= drawing
->gc
;
1080 draw_context
.pango_layout
= drawing
->pango_layout
;
1081 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1082 draw_context
.drawinfo
.end
.x
= x
;
1084 draw_context
.drawinfo
.y
.over
= 1;
1085 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
1086 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
1088 draw_context
.drawinfo
.start
.offset
.over
= 0;
1089 draw_context
.drawinfo
.start
.offset
.middle
= 0;
1090 draw_context
.drawinfo
.start
.offset
.under
= 0;
1091 draw_context
.drawinfo
.end
.offset
.over
= 0;
1092 draw_context
.drawinfo
.end
.offset
.middle
= 0;
1093 draw_context
.drawinfo
.end
.offset
.under
= 0;
1097 PropertiesLine prop_line
;
1098 prop_line
.line_width
= STATE_LINE_WIDTH
;
1099 prop_line
.style
= GDK_LINE_SOLID
;
1100 prop_line
.y
= MIDDLE
;
1101 cpu_set_line_color(&prop_line
, tfs
->cpu_state
);
1102 draw_line((void*)&prop_line
, (void*)&draw_context
);
1104 /* become the last x position */
1105 hashed_process_data
->x
.middle
= x
;
1106 hashed_process_data
->x
.middle_used
= TRUE
;
1107 hashed_process_data
->x
.middle_marked
= FALSE
;
1109 /* Calculate the next good time */
1110 convert_pixels_to_time(width
, x
+1, time_window
,
1111 &hashed_process_data
->next_good_time
);
1118 int before_execmode_hook_irq(void *hook_data
, void *call_data
)
1120 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
1121 EventsRequest
*events_request
= (EventsRequest
*)thf
->hook_data
;
1122 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1124 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
1126 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
1127 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
1130 e
= ltt_tracefile_get_event(tfc
->tf
);
1132 LttTime evtime
= ltt_event_time(e
);
1136 /* we are in a execmode, before the state update. We must draw the
1137 * items corresponding to the state before it changes : now is the right
1143 guint cpu
= tfs
->cpu
;
1145 LttFacility
*ev_facility
= ltt_event_facility(e
);
1146 if(ltt_facility_name(ev_facility
) != LTT_FACILITY_KERNEL
)
1148 guint8 ev_id_entry
= ltt_eventtype_id(ltt_facility_eventtype_get_by_name(ev_facility
, LTT_EVENT_IRQ_ENTRY
));
1149 guint8 ev_id_exit
= ltt_eventtype_id(ltt_facility_eventtype_get_by_name(ev_facility
, LTT_EVENT_IRQ_EXIT
));
1150 if(ltt_facility_name(ev_facility
) == LTT_FACILITY_KERNEL
&&
1151 ev_id_entry
== ltt_event_eventtype_id(e
)) {
1152 irq
= ltt_event_get_long_unsigned(e
, thf
->f1
);
1154 else if(ltt_facility_name(ev_facility
) == LTT_FACILITY_KERNEL
&&
1155 ev_id_exit
== ltt_event_eventtype_id(e
)) {
1156 irq
= ts
->cpu_states
[cpu
].last_irq
;
1164 irqstr
= g_strdup_printf("IRQ %u", irq
);
1165 resourceq
= g_quark_from_string(irqstr
);
1168 guint trace_num
= ts
->parent
.index
;
1170 // guint pid = process->pid;
1172 /* Well, the process_out existed : we must get it in the process hash
1173 * or add it, and draw its items.
1175 /* Add process to process list (if not present) */
1176 guint pl_height
= 0;
1177 HashedResourceData
*hashed_process_data
= NULL
;
1178 ProcessList
*process_list
= control_flow_data
->process_list
;
1179 // LttTime birth = process->creation_time;
1181 // if(likely(process_list->current_hash_data[trace_num][cpu] != NULL)) {
1182 // hashed_process_data = process_list->current_hash_data[trace_num][cpu];
1184 hashed_process_data
= processlist_get_process_data(process_list
, resourceq
, trace_num
);
1185 // hashed_process_data = processlist_get_process_data(process_list,
1190 if(unlikely(hashed_process_data
== NULL
))
1192 //g_assert(pid == 0 || pid != process->ppid);
1193 ResourceInfo
*process_info
;
1194 /* Process not present */
1195 Drawing_t
*drawing
= control_flow_data
->drawing
;
1196 resourcelist_add(process_list
,
1199 resourceq
, //process->name,
1204 &hashed_process_data
);
1205 gtk_widget_set_size_request(drawing
->drawing_area
,
1208 gtk_widget_queue_draw(drawing
->drawing_area
);
1210 /* Set the current process */
1211 // process_list->current_hash_data[trace_num][process->cpu] =
1212 // hashed_process_data;
1215 /* Now, the process is in the state hash and our own process hash.
1216 * We definitely can draw the items related to the ending state.
1219 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
1222 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1223 TimeWindow time_window
=
1224 lttvwindow_get_time_window(control_flow_data
->tab
);
1227 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1228 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1230 #endif //EXTRA_CHECK
1231 Drawing_t
*drawing
= control_flow_data
->drawing
;
1232 guint width
= drawing
->width
;
1234 convert_time_to_pixels(
1240 /* Draw collision indicator */
1241 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1242 gdk_draw_point(hashed_process_data
->pixmap
,
1245 COLLISION_POSITION(hashed_process_data
->height
));
1246 hashed_process_data
->x
.middle_marked
= TRUE
;
1250 TimeWindow time_window
=
1251 lttvwindow_get_time_window(control_flow_data
->tab
);
1254 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1255 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1257 #endif //EXTRA_CHECK
1258 Drawing_t
*drawing
= control_flow_data
->drawing
;
1259 guint width
= drawing
->width
;
1262 convert_time_to_pixels(
1269 /* Jump over draw if we are at the same x position */
1270 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1271 hashed_process_data
->x
.middle_used
))
1273 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1274 /* Draw collision indicator */
1275 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1276 gdk_draw_point(hashed_process_data
->pixmap
,
1279 COLLISION_POSITION(hashed_process_data
->height
));
1280 hashed_process_data
->x
.middle_marked
= TRUE
;
1286 DrawContext draw_context
;
1287 /* Now create the drawing context that will be used to draw
1288 * items related to the last state. */
1289 draw_context
.drawable
= hashed_process_data
->pixmap
;
1290 draw_context
.gc
= drawing
->gc
;
1291 draw_context
.pango_layout
= drawing
->pango_layout
;
1292 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1293 draw_context
.drawinfo
.end
.x
= x
;
1295 draw_context
.drawinfo
.y
.over
= 1;
1296 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
1297 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
1299 draw_context
.drawinfo
.start
.offset
.over
= 0;
1300 draw_context
.drawinfo
.start
.offset
.middle
= 0;
1301 draw_context
.drawinfo
.start
.offset
.under
= 0;
1302 draw_context
.drawinfo
.end
.offset
.over
= 0;
1303 draw_context
.drawinfo
.end
.offset
.middle
= 0;
1304 draw_context
.drawinfo
.end
.offset
.under
= 0;
1308 PropertiesLine prop_line
;
1309 prop_line
.line_width
= STATE_LINE_WIDTH
;
1310 prop_line
.style
= GDK_LINE_SOLID
;
1311 prop_line
.y
= MIDDLE
;
1312 irq_set_line_color(&prop_line
, &ts
->irq_states
[irq
]);
1313 draw_line((void*)&prop_line
, (void*)&draw_context
);
1315 /* become the last x position */
1316 hashed_process_data
->x
.middle
= x
;
1317 hashed_process_data
->x
.middle_used
= TRUE
;
1318 hashed_process_data
->x
.middle_marked
= FALSE
;
1320 /* Calculate the next good time */
1321 convert_pixels_to_time(width
, x
+1, time_window
,
1322 &hashed_process_data
->next_good_time
);
1329 gint
update_time_window_hook(void *hook_data
, void *call_data
)
1331 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1332 Drawing_t
*drawing
= control_flow_data
->drawing
;
1333 ProcessList
*process_list
= control_flow_data
->process_list
;
1335 const TimeWindowNotifyData
*time_window_nofify_data
=
1336 ((const TimeWindowNotifyData
*)call_data
);
1338 TimeWindow
*old_time_window
=
1339 time_window_nofify_data
->old_time_window
;
1340 TimeWindow
*new_time_window
=
1341 time_window_nofify_data
->new_time_window
;
1343 /* Update the ruler */
1344 drawing_update_ruler(control_flow_data
->drawing
,
1348 /* Two cases : zoom in/out or scrolling */
1350 /* In order to make sure we can reuse the old drawing, the scale must
1351 * be the same and the new time interval being partly located in the
1352 * currently shown time interval. (reuse is only for scrolling)
1355 g_info("Old time window HOOK : %lu, %lu to %lu, %lu",
1356 old_time_window
->start_time
.tv_sec
,
1357 old_time_window
->start_time
.tv_nsec
,
1358 old_time_window
->time_width
.tv_sec
,
1359 old_time_window
->time_width
.tv_nsec
);
1361 g_info("New time window HOOK : %lu, %lu to %lu, %lu",
1362 new_time_window
->start_time
.tv_sec
,
1363 new_time_window
->start_time
.tv_nsec
,
1364 new_time_window
->time_width
.tv_sec
,
1365 new_time_window
->time_width
.tv_nsec
);
1367 if( new_time_window
->time_width
.tv_sec
== old_time_window
->time_width
.tv_sec
1368 && new_time_window
->time_width
.tv_nsec
== old_time_window
->time_width
.tv_nsec
)
1370 /* Same scale (scrolling) */
1371 g_info("scrolling");
1372 LttTime
*ns
= &new_time_window
->start_time
;
1373 LttTime
*nw
= &new_time_window
->time_width
;
1374 LttTime
*os
= &old_time_window
->start_time
;
1375 LttTime
*ow
= &old_time_window
->time_width
;
1376 LttTime old_end
= old_time_window
->end_time
;
1377 LttTime new_end
= new_time_window
->end_time
;
1379 //if(ns<os+w && os+w<ns+w)
1380 //if(ns<old_end && os<ns)
1381 if(ltt_time_compare(*ns
, old_end
) == -1
1382 && ltt_time_compare(*os
, *ns
) == -1)
1384 g_info("scrolling near right");
1385 /* Scroll right, keep right part of the screen */
1387 guint width
= control_flow_data
->drawing
->width
;
1388 convert_time_to_pixels(
1394 /* Copy old data to new location */
1395 copy_pixmap_region(process_list
,
1397 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1401 control_flow_data
->drawing
->width
-x
+SAFETY
, -1);
1403 if(drawing
->damage_begin
== drawing
->damage_end
)
1404 drawing
->damage_begin
= control_flow_data
->drawing
->width
-x
;
1406 drawing
->damage_begin
= 0;
1408 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1410 /* Clear the data request background, but not SAFETY */
1411 rectangle_pixmap(process_list
,
1412 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1414 drawing
->damage_begin
+SAFETY
, 0,
1415 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1417 gtk_widget_queue_draw(drawing
->drawing_area
);
1418 //gtk_widget_queue_draw_area (drawing->drawing_area,
1420 // control_flow_data->drawing->width,
1421 // control_flow_data->drawing->height);
1423 /* Get new data for the rest. */
1424 drawing_data_request(control_flow_data
->drawing
,
1425 drawing
->damage_begin
, 0,
1426 drawing
->damage_end
- drawing
->damage_begin
,
1427 control_flow_data
->drawing
->height
);
1430 //if(ns<os && os<ns+w)
1431 //if(ns<os && os<new_end)
1432 if(ltt_time_compare(*ns
,*os
) == -1
1433 && ltt_time_compare(*os
,new_end
) == -1)
1435 g_info("scrolling near left");
1436 /* Scroll left, keep left part of the screen */
1438 guint width
= control_flow_data
->drawing
->width
;
1439 convert_time_to_pixels(
1445 /* Copy old data to new location */
1446 copy_pixmap_region (process_list
,
1448 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1454 if(drawing
->damage_begin
== drawing
->damage_end
)
1455 drawing
->damage_end
= x
;
1457 drawing
->damage_end
=
1458 control_flow_data
->drawing
->width
;
1460 drawing
->damage_begin
= 0;
1462 rectangle_pixmap (process_list
,
1463 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1465 drawing
->damage_begin
, 0,
1466 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1469 gtk_widget_queue_draw(drawing
->drawing_area
);
1470 //gtk_widget_queue_draw_area (drawing->drawing_area,
1472 // control_flow_data->drawing->width,
1473 // control_flow_data->drawing->height);
1476 /* Get new data for the rest. */
1477 drawing_data_request(control_flow_data
->drawing
,
1478 drawing
->damage_begin
, 0,
1479 drawing
->damage_end
- drawing
->damage_begin
,
1480 control_flow_data
->drawing
->height
);
1483 if(ltt_time_compare(*ns
,*os
) == 0)
1485 g_info("not scrolling");
1487 g_info("scrolling far");
1488 /* Cannot reuse any part of the screen : far jump */
1491 rectangle_pixmap (process_list
,
1492 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1495 control_flow_data
->drawing
->width
+SAFETY
, // do not overlap
1498 //gtk_widget_queue_draw_area (drawing->drawing_area,
1500 // control_flow_data->drawing->width,
1501 // control_flow_data->drawing->height);
1502 gtk_widget_queue_draw(drawing
->drawing_area
);
1504 drawing
->damage_begin
= 0;
1505 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1507 drawing_data_request(control_flow_data
->drawing
,
1509 control_flow_data
->drawing
->width
,
1510 control_flow_data
->drawing
->height
);
1516 /* Different scale (zoom) */
1519 rectangle_pixmap (process_list
,
1520 control_flow_data
->drawing
->drawing_area
->style
->black_gc
,
1523 control_flow_data
->drawing
->width
+SAFETY
, // do not overlap
1526 //gtk_widget_queue_draw_area (drawing->drawing_area,
1528 // control_flow_data->drawing->width,
1529 // control_flow_data->drawing->height);
1530 gtk_widget_queue_draw(drawing
->drawing_area
);
1532 drawing
->damage_begin
= 0;
1533 drawing
->damage_end
= control_flow_data
->drawing
->width
;
1535 drawing_data_request(control_flow_data
->drawing
,
1537 control_flow_data
->drawing
->width
,
1538 control_flow_data
->drawing
->height
);
1541 /* Update directly when scrolling */
1542 gdk_window_process_updates(control_flow_data
->drawing
->drawing_area
->window
,
1548 gint
traceset_notify(void *hook_data
, void *call_data
)
1550 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1551 Drawing_t
*drawing
= control_flow_data
->drawing
;
1553 if(unlikely(drawing
->gc
== NULL
)) {
1556 if(drawing
->dotted_gc
== NULL
) {
1560 drawing_clear(control_flow_data
->drawing
);
1561 processlist_clear(control_flow_data
->process_list
);
1562 gtk_widget_set_size_request(
1563 control_flow_data
->drawing
->drawing_area
,
1564 -1, processlist_get_height(control_flow_data
->process_list
));
1565 redraw_notify(control_flow_data
, NULL
);
1567 request_background_data(control_flow_data
);
1572 gint
redraw_notify(void *hook_data
, void *call_data
)
1574 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1575 Drawing_t
*drawing
= control_flow_data
->drawing
;
1576 GtkWidget
*widget
= drawing
->drawing_area
;
1578 drawing
->damage_begin
= 0;
1579 drawing
->damage_end
= drawing
->width
;
1581 /* fun feature, to be separated someday... */
1582 drawing_clear(control_flow_data
->drawing
);
1583 processlist_clear(control_flow_data
->process_list
);
1584 gtk_widget_set_size_request(
1585 control_flow_data
->drawing
->drawing_area
,
1586 -1, processlist_get_height(control_flow_data
->process_list
));
1588 rectangle_pixmap (control_flow_data
->process_list
,
1589 widget
->style
->black_gc
,
1592 drawing
->alloc_width
,
1595 gtk_widget_queue_draw(drawing
->drawing_area
);
1597 if(drawing
->damage_begin
< drawing
->damage_end
)
1599 drawing_data_request(drawing
,
1600 drawing
->damage_begin
,
1602 drawing
->damage_end
-drawing
->damage_begin
,
1606 //gtk_widget_queue_draw_area(drawing->drawing_area,
1609 // drawing->height);
1615 gint
continue_notify(void *hook_data
, void *call_data
)
1617 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
1618 Drawing_t
*drawing
= control_flow_data
->drawing
;
1620 //g_assert(widget->allocation.width == drawing->damage_end);
1622 if(drawing
->damage_begin
< drawing
->damage_end
)
1624 drawing_data_request(drawing
,
1625 drawing
->damage_begin
,
1627 drawing
->damage_end
-drawing
->damage_begin
,
1635 gint
update_current_time_hook(void *hook_data
, void *call_data
)
1637 ControlFlowData
*control_flow_data
= (ControlFlowData
*)hook_data
;
1638 Drawing_t
*drawing
= control_flow_data
->drawing
;
1640 LttTime current_time
= *((LttTime
*)call_data
);
1642 TimeWindow time_window
=
1643 lttvwindow_get_time_window(control_flow_data
->tab
);
1645 LttTime time_begin
= time_window
.start_time
;
1646 LttTime width
= time_window
.time_width
;
1649 guint64 time_ll
= ltt_time_to_uint64(width
);
1650 time_ll
= time_ll
>> 1; /* divide by two */
1651 half_width
= ltt_time_from_uint64(time_ll
);
1653 LttTime time_end
= ltt_time_add(time_begin
, width
);
1655 LttvTracesetContext
* tsc
=
1656 lttvwindow_get_traceset_context(control_flow_data
->tab
);
1658 LttTime trace_start
= tsc
->time_span
.start_time
;
1659 LttTime trace_end
= tsc
->time_span
.end_time
;
1661 g_info("New current time HOOK : %lu, %lu", current_time
.tv_sec
,
1662 current_time
.tv_nsec
);
1666 /* If current time is inside time interval, just move the highlight
1669 /* Else, we have to change the time interval. We have to tell it
1670 * to the main window. */
1671 /* The time interval change will take care of placing the current
1672 * time at the center of the visible area, or nearest possible if we are
1673 * at one end of the trace. */
1676 if(ltt_time_compare(current_time
, time_begin
) < 0)
1678 TimeWindow new_time_window
;
1680 if(ltt_time_compare(current_time
,
1681 ltt_time_add(trace_start
,half_width
)) < 0)
1682 time_begin
= trace_start
;
1684 time_begin
= ltt_time_sub(current_time
,half_width
);
1686 new_time_window
.start_time
= time_begin
;
1687 new_time_window
.time_width
= width
;
1688 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1689 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1691 lttvwindow_report_time_window(control_flow_data
->tab
, new_time_window
);
1693 else if(ltt_time_compare(current_time
, time_end
) > 0)
1695 TimeWindow new_time_window
;
1697 if(ltt_time_compare(current_time
, ltt_time_sub(trace_end
, half_width
)) > 0)
1698 time_begin
= ltt_time_sub(trace_end
,width
);
1700 time_begin
= ltt_time_sub(current_time
,half_width
);
1702 new_time_window
.start_time
= time_begin
;
1703 new_time_window
.time_width
= width
;
1704 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1705 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1707 lttvwindow_report_time_window(control_flow_data
->tab
, new_time_window
);
1710 gtk_widget_queue_draw(control_flow_data
->drawing
->drawing_area
);
1712 /* Update directly when scrolling */
1713 gdk_window_process_updates(control_flow_data
->drawing
->drawing_area
->window
,
1719 typedef struct _ClosureData
{
1720 EventsRequest
*events_request
;
1721 LttvTracesetState
*tss
;
1726 /* Draw line until end of the screen */
1728 void draw_closure(gpointer key
, gpointer value
, gpointer user_data
)
1730 ResourceInfo
*process_info
= (ResourceInfo
*)key
;
1731 HashedResourceData
*hashed_process_data
= (HashedResourceData
*)value
;
1732 ClosureData
*closure_data
= (ClosureData
*)user_data
;
1734 EventsRequest
*events_request
= closure_data
->events_request
;
1735 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1737 LttvTracesetState
*tss
= closure_data
->tss
;
1738 LttvTracesetContext
*tsc
= (LttvTracesetContext
*)tss
;
1740 LttTime evtime
= closure_data
->end_time
;
1742 gboolean dodraw
= TRUE
;
1745 /* For the process */
1746 /* First, check if the current process is in the state computation
1747 * process list. If it is there, that means we must add it right now and
1748 * draw items from the beginning of the read for it. If it is not
1749 * present, it's a new process and it was not present : it will
1750 * be added after the state update. */
1752 g_assert(lttv_traceset_number(tsc
->ts
) > 0);
1753 #endif //EXTRA_CHECK
1754 LttvTraceContext
*tc
= tsc
->traces
[process_info
->trace_num
];
1755 LttvTraceState
*ts
= (LttvTraceState
*)tc
;
1758 //FIXME : optimize data structures.
1759 LttvTracefileState
*tfs
;
1760 LttvTracefileContext
*tfc
;
1762 for(i
=0;i
<tc
->tracefiles
->len
;i
++) {
1763 tfc
= g_array_index(tc
->tracefiles
, LttvTracefileContext
*, i
);
1764 if(ltt_tracefile_name(tfc
->tf
) == LTT_NAME_CPU
1765 && tfs
->cpu
== process_info
->cpu
)
1769 g_assert(i
<tc
->tracefiles
->len
);
1770 tfs
= LTTV_TRACEFILE_STATE(tfc
);
1772 // LttvTracefileState *tfs =
1773 // (LttvTracefileState*)tsc->traces[process_info->trace_num]->
1774 // tracefiles[process_info->cpu];
1776 // LttvProcessState *process;
1777 // process = lttv_state_find_process(ts, process_info->cpu,
1778 // process_info->pid);
1780 // if(unlikely(process != NULL)) {
1782 // LttvFilter *filter = control_flow_data->filter;
1783 // if(filter != NULL && filter->head != NULL)
1784 // if(!lttv_filter_tree_parse(filter->head,NULL,NULL,
1785 // tc->t,NULL,process,tc))
1788 /* Only draw for processes that are currently in the trace states */
1790 ProcessList
*process_list
= control_flow_data
->process_list
;
1792 /* Should be alike when background info is ready */
1793 if(control_flow_data
->background_info_waiting
==0)
1794 g_assert(ltt_time_compare(process
->creation_time
,
1795 process_info
->birth
) == 0);
1796 #endif //EXTRA_CHECK
1798 /* Now, the process is in the state hash and our own process hash.
1799 * We definitely can draw the items related to the ending state.
1802 if(unlikely(ltt_time_compare(hashed_process_data
->next_good_time
,
1805 TimeWindow time_window
=
1806 lttvwindow_get_time_window(control_flow_data
->tab
);
1809 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1810 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1812 #endif //EXTRA_CHECK
1813 Drawing_t
*drawing
= control_flow_data
->drawing
;
1814 guint width
= drawing
->width
;
1816 guint x
= closure_data
->x_end
;
1818 DrawContext draw_context
;
1820 /* Now create the drawing context that will be used to draw
1821 * items related to the last state. */
1822 draw_context
.drawable
= hashed_process_data
->pixmap
;
1823 draw_context
.gc
= drawing
->gc
;
1824 draw_context
.pango_layout
= drawing
->pango_layout
;
1825 draw_context
.drawinfo
.end
.x
= x
;
1827 draw_context
.drawinfo
.y
.over
= 1;
1828 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
1829 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
1831 draw_context
.drawinfo
.start
.offset
.over
= 0;
1832 draw_context
.drawinfo
.start
.offset
.middle
= 0;
1833 draw_context
.drawinfo
.start
.offset
.under
= 0;
1834 draw_context
.drawinfo
.end
.offset
.over
= 0;
1835 draw_context
.drawinfo
.end
.offset
.middle
= 0;
1836 draw_context
.drawinfo
.end
.offset
.under
= 0;
1838 /* Jump over draw if we are at the same x position */
1839 if(x
== hashed_process_data
->x
.over
)
1843 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.over
;
1845 PropertiesLine prop_line
= prepare_execmode_line(process
);
1846 draw_line((void*)&prop_line
, (void*)&draw_context
);
1848 hashed_process_data
->x
.over
= x
;
1852 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1853 hashed_process_data
->x
.middle_used
)) {
1854 #if 0 /* do not mark closure : not missing information */
1855 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
1856 /* Draw collision indicator */
1857 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1858 gdk_draw_point(drawing
->pixmap
,
1862 hashed_process_data
->x
.middle_marked
= TRUE
;
1867 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1870 PropertiesLine prop_line
;
1871 prop_line
.line_width
= STATE_LINE_WIDTH
;
1872 prop_line
.style
= GDK_LINE_SOLID
;
1873 prop_line
.y
= MIDDLE
;
1874 if(process_info
->type
== 0)
1875 cpu_set_line_color(&prop_line
, &ts
->cpu_states
[process_info
->id
]);
1876 else if(process_info
->type
== 1)
1877 irq_set_line_color(&prop_line
, &ts
->irq_states
[process_info
->id
]);
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
)
1901 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1902 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1903 ControlFlowData
*cfd
= (ControlFlowData
*)events_request
->viewer_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
, tss
);
1916 int before_request(void *hook_data
, void *call_data
)
1918 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1919 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1921 drawing_data_request_begin(events_request
, tss
);
1928 * after request is necessary in addition of after chunk in order to draw
1929 * lines until the end of the screen. after chunk just draws lines until
1936 // TODO pmf: reenable this
1937 int after_request(void *hook_data
, void *call_data
)
1939 // EventsRequest *events_request = (EventsRequest*)hook_data;
1940 // ControlFlowData *control_flow_data = events_request->viewer_data;
1941 // LttvTracesetState *tss = (LttvTracesetState*)call_data;
1943 // ProcessList *process_list = control_flow_data->process_list;
1944 // LttTime end_time = events_request->end_time;
1946 // ClosureData closure_data;
1947 // closure_data.events_request = (EventsRequest*)hook_data;
1948 // closure_data.tss = tss;
1949 // closure_data.end_time = end_time;
1951 // TimeWindow time_window =
1952 // lttvwindow_get_time_window(control_flow_data->tab);
1953 // guint width = control_flow_data->drawing->width;
1954 // convert_time_to_pixels(
1958 // &closure_data.x_end);
1961 // /* Draw last items */
1962 // g_hash_table_foreach(process_list->process_hash, draw_closure,
1963 // (void*)&closure_data);
1966 // /* Request expose */
1967 // drawing_request_expose(events_request, tss, end_time);
1976 int after_chunk(void *hook_data
, void *call_data
)
1978 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1979 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
1980 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1981 LttvTracesetContext
*tsc
= (LttvTracesetContext
*)call_data
;
1982 LttvTracefileContext
*tfc
= lttv_traceset_context_get_current_tfc(tsc
);
1985 ProcessList
*process_list
= control_flow_data
->process_list
;
1987 LttvTraceset
*traceset
= tsc
->ts
;
1988 guint nb_trace
= lttv_traceset_number(traceset
);
1990 /* Only execute when called for the first trace's events request */
1991 if(!process_list
->current_hash_data
) return;
1993 for(i
= 0 ; i
< nb_trace
; i
++) {
1994 g_free(process_list
->current_hash_data
[i
]);
1996 g_free(process_list
->current_hash_data
);
1997 process_list
->current_hash_data
= NULL
;
2000 end_time
= LTT_TIME_MIN(tfc
->timestamp
, events_request
->end_time
);
2001 else /* end of traceset, or position now out of request : end */
2002 end_time
= events_request
->end_time
;
2004 ClosureData closure_data
;
2005 closure_data
.events_request
= (EventsRequest
*)hook_data
;
2006 closure_data
.tss
= tss
;
2007 closure_data
.end_time
= end_time
;
2009 TimeWindow time_window
=
2010 lttvwindow_get_time_window(control_flow_data
->tab
);
2011 guint width
= control_flow_data
->drawing
->width
;
2012 convert_time_to_pixels(
2016 &closure_data
.x_end
);
2018 /* Draw last items */
2019 g_hash_table_foreach(process_list
->process_hash
, draw_closure
,
2020 (void*)&closure_data
);
2022 /* Reactivate sort */
2023 gtk_tree_sortable_set_sort_column_id(
2024 GTK_TREE_SORTABLE(control_flow_data
->process_list
->list_store
),
2025 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
,
2026 GTK_SORT_ASCENDING
);
2028 update_index_to_pixmap(control_flow_data
->process_list
);
2029 /* Request a full expose : drawing scrambled */
2030 gtk_widget_queue_draw(control_flow_data
->drawing
->drawing_area
);
2032 /* Request expose (updates damages zone also) */
2033 drawing_request_expose(events_request
, tss
, end_time
);
2038 /* after_statedump_end
2040 * @param hook_data ControlFlowData structure of the viewer.
2041 * @param call_data Event context.
2043 * This function adds items to be drawn in a queue for each process.
2046 int before_statedump_end(void *hook_data
, void *call_data
)
2048 LttvTraceHookByFacility
*thf
= (LttvTraceHookByFacility
*)hook_data
;
2049 EventsRequest
*events_request
= (EventsRequest
*)thf
->hook_data
;
2050 ControlFlowData
*control_flow_data
= events_request
->viewer_data
;
2052 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
2054 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
2056 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
2058 LttvTracesetState
*tss
= (LttvTracesetState
*)tfc
->t_context
->ts_context
;
2059 ProcessList
*process_list
= control_flow_data
->process_list
;
2062 e
= ltt_tracefile_get_event(tfc
->tf
);
2064 LttvFilter
*filter
= control_flow_data
->filter
;
2065 if(filter
!= NULL
&& filter
->head
!= NULL
)
2066 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
2067 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
2070 LttTime evtime
= ltt_event_time(e
);
2072 ClosureData closure_data
;
2073 closure_data
.events_request
= events_request
;
2074 closure_data
.tss
= tss
;
2075 closure_data
.end_time
= evtime
;
2077 TimeWindow time_window
=
2078 lttvwindow_get_time_window(control_flow_data
->tab
);
2079 guint width
= control_flow_data
->drawing
->width
;
2080 convert_time_to_pixels(
2084 &closure_data
.x_end
);
2086 /* Draw last items */
2087 g_hash_table_foreach(process_list
->process_hash
, draw_closure
,
2088 (void*)&closure_data
);
2090 /* Reactivate sort */
2091 gtk_tree_sortable_set_sort_column_id(
2092 GTK_TREE_SORTABLE(control_flow_data
->process_list
->list_store
),
2093 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
,
2094 GTK_SORT_ASCENDING
);
2096 update_index_to_pixmap(control_flow_data
->process_list
);
2097 /* Request a full expose : drawing scrambled */
2098 gtk_widget_queue_draw(control_flow_data
->drawing
->drawing_area
);
2100 /* Request expose (updates damages zone also) */
2101 drawing_request_expose(events_request
, tss
, evtime
);