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 4
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
*resourceview_data
= (ControlFlowData
*)hook_data
;
95 LttvTrace
*trace
= (LttvTrace
*)call_data
;
97 resourceview_data
->background_info_waiting
--;
99 if(resourceview_data
->background_info_waiting
== 0) {
100 g_message("control flow viewer : background computation data ready.");
102 drawing_clear(resourceview_data
->drawing
);
103 processlist_clear(resourceview_data
->process_list
);
104 gtk_widget_set_size_request(
105 resourceview_data
->drawing
->drawing_area
,
106 -1, processlist_get_height(resourceview_data
->process_list
));
107 redraw_notify(resourceview_data
, NULL
);
114 /* Request background computation. Verify if it is in progress or ready first.
115 * Only for each trace in the tab's traceset.
117 static void request_background_data(ControlFlowData
*resourceview_data
)
119 LttvTracesetContext
* tsc
=
120 lttvwindow_get_traceset_context(resourceview_data
->tab
);
121 gint num_traces
= lttv_traceset_number(tsc
->ts
);
124 LttvTraceState
*tstate
;
126 LttvHooks
*background_ready_hook
=
128 lttv_hooks_add(background_ready_hook
, background_ready
, resourceview_data
,
130 resourceview_data
->background_info_waiting
= 0;
132 for(i
=0;i
<num_traces
;i
++) {
133 trace
= lttv_traceset_get(tsc
->ts
, i
);
134 tstate
= LTTV_TRACE_STATE(tsc
->traces
[i
]);
136 if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace
)==FALSE
137 && !tstate
->has_precomputed_states
) {
139 if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"),
141 /* We first remove requests that could have been done for the same
142 * information. Happens when two viewers ask for it before servicing
145 if(!lttvwindowtraces_background_request_find(trace
, "state"))
146 lttvwindowtraces_background_request_queue(
147 main_window_get_widget(resourceview_data
->tab
), trace
, "state");
148 lttvwindowtraces_background_notify_queue(resourceview_data
,
152 background_ready_hook
);
153 resourceview_data
->background_info_waiting
++;
154 } else { /* in progress */
156 lttvwindowtraces_background_notify_current(resourceview_data
,
160 background_ready_hook
);
161 resourceview_data
->background_info_waiting
++;
164 /* Data ready. By its nature, this viewer doesn't need to have
165 * its data ready hook called there, because a background
166 * request is always linked with a redraw.
171 lttv_hooks_destroy(background_ready_hook
);
176 * Event Viewer's constructor hook
178 * This constructor is given as a parameter to the menuitem and toolbar button
179 * registration. It creates the list.
180 * @param tab A pointer to the parent tab.
181 * @return The widget created.
184 h_resourceview(LttvPlugin
*plugin
)
186 LttvPluginTab
*ptab
= LTTV_PLUGIN_TAB(plugin
);
187 Tab
*tab
= ptab
->tab
;
188 g_info("h_guicontrolflow, %p", tab
);
189 ControlFlowData
*resourceview_data
= resourceview(ptab
);
191 resourceview_data
->tab
= tab
;
193 // Unreg done in the GuiControlFlow_Destructor
194 lttvwindow_register_traceset_notify(tab
,
198 lttvwindow_register_time_window_notify(tab
,
199 update_time_window_hook
,
201 lttvwindow_register_current_time_notify(tab
,
202 update_current_time_hook
,
204 lttvwindow_register_redraw_notify(tab
,
207 lttvwindow_register_continue_notify(tab
,
210 request_background_data(resourceview_data
);
213 return guicontrolflow_get_widget(resourceview_data
) ;
217 void legend_destructor(GtkWindow
*legend
)
219 g_legend_list
= g_slist_remove(g_legend_list
, legend
);
222 /* Create a popup legend */
224 h_legend(LttvPlugin
*plugin
)
226 LttvPluginTab
*ptab
= LTTV_PLUGIN_TAB(plugin
);
227 Tab
*tab
= ptab
->tab
;
228 g_info("h_legend, %p", tab
);
230 GtkWindow
*legend
= GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL
));
232 g_legend_list
= g_slist_append(
236 g_object_set_data_full(
240 (GDestroyNotify
)legend_destructor
);
242 gtk_window_set_title(legend
, "Control Flow View Legend");
244 GtkWidget
*pixmap
= create_pixmap(GTK_WIDGET(legend
), "lttv-color-list.png");
246 gtk_container_add(GTK_CONTAINER(legend
), GTK_WIDGET(pixmap
));
248 gtk_widget_show(GTK_WIDGET(pixmap
));
249 gtk_widget_show(GTK_WIDGET(legend
));
252 return NULL
; /* This is a popup window */
256 int event_selected_hook(void *hook_data
, void *call_data
)
258 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
259 guint
*event_number
= (guint
*) call_data
;
261 g_debug("DEBUG : event selected by main window : %u", *event_number
);
266 static void cpu_set_line_color(PropertiesLine
*prop_line
, LttvCPUState
*s
)
268 GQuark present_state
;
270 if(s
->mode_stack
->len
== 0)
271 present_state
= LTTV_CPU_UNKNOWN
;
273 present_state
= ((GQuark
*)s
->mode_stack
->data
)[s
->mode_stack
->len
-1];
275 if(present_state
== LTTV_CPU_IDLE
) {
276 prop_line
->color
= drawing_colors_cpu
[COL_CPU_IDLE
];
278 else if(present_state
== LTTV_CPU_BUSY
) {
279 prop_line
->color
= drawing_colors_cpu
[COL_CPU_BUSY
];
281 else if(present_state
== LTTV_CPU_IRQ
) {
282 prop_line
->color
= drawing_colors_cpu
[COL_CPU_IRQ
];
284 else if(present_state
== LTTV_CPU_TRAP
) {
285 prop_line
->color
= drawing_colors_cpu
[COL_CPU_TRAP
];
287 prop_line
->color
= drawing_colors_cpu
[COL_CPU_UNKNOWN
];
291 static void irq_set_line_color(PropertiesLine
*prop_line
, LttvIRQState
*s
)
293 GQuark present_state
;
294 if(s
->mode_stack
->len
== 0)
295 present_state
= LTTV_IRQ_UNKNOWN
;
297 present_state
= ((GQuark
*)s
->mode_stack
->data
)[s
->mode_stack
->len
-1];
299 if(present_state
== LTTV_IRQ_IDLE
) {
300 prop_line
->color
= drawing_colors_irq
[COL_IRQ_IDLE
];
302 else if(present_state
== LTTV_IRQ_BUSY
) {
303 prop_line
->color
= drawing_colors_irq
[COL_IRQ_BUSY
];
306 prop_line
->color
= drawing_colors_irq
[COL_IRQ_UNKNOWN
];
310 static void bdev_set_line_color(PropertiesLine
*prop_line
, LttvBdevState
*s
)
312 GQuark present_state
;
313 if(s
== 0 || s
->mode_stack
->len
== 0)
314 present_state
= LTTV_BDEV_UNKNOWN
;
316 present_state
= ((GQuark
*)s
->mode_stack
->data
)[s
->mode_stack
->len
-1];
318 if(present_state
== LTTV_BDEV_IDLE
) {
319 prop_line
->color
= drawing_colors_bdev
[COL_BDEV_IDLE
];
321 else if(present_state
== LTTV_BDEV_BUSY_READING
) {
322 prop_line
->color
= drawing_colors_bdev
[COL_BDEV_BUSY_READING
];
324 else if(present_state
== LTTV_BDEV_BUSY_WRITING
) {
325 prop_line
->color
= drawing_colors_bdev
[COL_BDEV_BUSY_WRITING
];
328 prop_line
->color
= drawing_colors_bdev
[COL_BDEV_UNKNOWN
];
332 /* before_schedchange_hook
334 * This function basically draw lines and icons. Two types of lines are drawn :
335 * one small (3 pixels?) representing the state of the process and the second
336 * type is thicker (10 pixels?) representing on which CPU a process is running
337 * (and this only in running state).
339 * Extremums of the lines :
340 * x_min : time of the last event context for this process kept in memory.
341 * x_max : time of the current event.
342 * y : middle of the process in the process list. The process is found in the
343 * list, therefore is it's position in pixels.
345 * The choice of lines'color is defined by the context of the last event for this
350 int before_schedchange_hook(void *hook_data
, void *call_data
)
352 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
353 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
354 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
356 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
358 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
359 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
362 e
= ltt_tracefile_get_event(tfc
->tf
);
363 gint target_pid_saved
= tfc
->target_pid
;
365 LttTime evtime
= ltt_event_time(e
);
366 LttvFilter
*filter
= resourceview_data
->filter
;
368 /* we are in a schedchange, before the state update. We must draw the
369 * items corresponding to the state before it changes : now is the right
375 pid_out
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
376 pid_in
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
377 // TODO: can't we reenable this? pmf
378 // if(pid_in != 0 && pid_out != 0) {
379 // /* not a transition to/from idle */
383 tfc
->target_pid
= pid_out
;
385 guint cpu
= tfs
->cpu
;
387 guint trace_num
= ts
->parent
.index
;
388 /* Add process to process list (if not present) */
390 HashedResourceData
*hashed_process_data
= NULL
;
391 ProcessList
*process_list
= resourceview_data
->process_list
;
393 hashed_process_data
= resourcelist_obtain_cpu(resourceview_data
, trace_num
, cpu
);
395 /* Now, the process is in the state hash and our own process hash.
396 * We definitely can draw the items related to the ending state.
399 if(ltt_time_compare(hashed_process_data
->next_good_time
,
402 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
404 TimeWindow time_window
=
405 lttvwindow_get_time_window(resourceview_data
->tab
);
407 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
408 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
411 Drawing_t
*drawing
= resourceview_data
->drawing
;
412 guint width
= drawing
->width
;
414 convert_time_to_pixels(
420 /* Draw collision indicator */
421 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
422 gdk_draw_point(hashed_process_data
->pixmap
,
425 COLLISION_POSITION(hashed_process_data
->height
));
426 hashed_process_data
->x
.middle_marked
= TRUE
;
429 TimeWindow time_window
=
430 lttvwindow_get_time_window(resourceview_data
->tab
);
432 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
433 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
436 Drawing_t
*drawing
= resourceview_data
->drawing
;
437 guint width
= drawing
->width
;
439 convert_time_to_pixels(
445 /* Jump over draw if we are at the same x position */
446 if(x
== hashed_process_data
->x
.middle
&&
447 hashed_process_data
->x
.middle_used
)
449 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
450 /* Draw collision indicator */
451 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
452 gdk_draw_point(hashed_process_data
->pixmap
,
455 COLLISION_POSITION(hashed_process_data
->height
));
456 hashed_process_data
->x
.middle_marked
= TRUE
;
460 DrawContext draw_context
;
462 /* Now create the drawing context that will be used to draw
463 * items related to the last state. */
464 draw_context
.drawable
= hashed_process_data
->pixmap
;
465 draw_context
.gc
= drawing
->gc
;
466 draw_context
.pango_layout
= drawing
->pango_layout
;
467 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
468 draw_context
.drawinfo
.end
.x
= x
;
470 draw_context
.drawinfo
.y
.over
= 1;
471 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
472 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
474 draw_context
.drawinfo
.start
.offset
.over
= 0;
475 draw_context
.drawinfo
.start
.offset
.middle
= 0;
476 draw_context
.drawinfo
.start
.offset
.under
= 0;
477 draw_context
.drawinfo
.end
.offset
.over
= 0;
478 draw_context
.drawinfo
.end
.offset
.middle
= 0;
479 draw_context
.drawinfo
.end
.offset
.under
= 0;
483 //PropertiesLine prop_line = prepare_s_e_line(process);
484 PropertiesLine prop_line
;
485 prop_line
.line_width
= STATE_LINE_WIDTH
;
486 prop_line
.style
= GDK_LINE_SOLID
;
487 prop_line
.y
= MIDDLE
;
488 cpu_set_line_color(&prop_line
, tfs
->cpu_state
);
489 draw_line((void*)&prop_line
, (void*)&draw_context
);
492 /* become the last x position */
493 hashed_process_data
->x
.middle
= x
;
494 hashed_process_data
->x
.middle_used
= TRUE
;
495 hashed_process_data
->x
.middle_marked
= FALSE
;
497 /* Calculate the next good time */
498 convert_pixels_to_time(width
, x
+1, time_window
,
499 &hashed_process_data
->next_good_time
);
506 /* after_schedchange_hook
508 * The draw after hook is called by the reading API to have a
509 * particular event drawn on the screen.
510 * @param hook_data ControlFlowData structure of the viewer.
511 * @param call_data Event context.
513 * This function adds items to be drawn in a queue for each process.
516 int after_schedchange_hook(void *hook_data
, void *call_data
)
518 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
519 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
520 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
521 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
522 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
523 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
526 e
= ltt_tracefile_get_event(tfc
->tf
);
528 LttvFilter
*filter
= resourceview_data
->filter
;
529 if(filter
!= NULL
&& filter
->head
!= NULL
)
530 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
531 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
534 LttTime evtime
= ltt_event_time(e
);
536 /* Add process to process list (if not present) */
537 LttvProcessState
*process_in
;
540 HashedResourceData
*hashed_process_data_in
= NULL
;
542 ProcessList
*process_list
= resourceview_data
->process_list
;
547 pid_out
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
548 pid_in
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
552 /* Find process pid_in in the list... */
553 //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in);
554 //process_in = tfs->process;
555 guint cpu
= tfs
->cpu
;
556 guint trace_num
= ts
->parent
.index
;
557 process_in
= ts
->running_process
[cpu
];
558 /* It should exist, because we are after the state update. */
560 g_assert(process_in
!= NULL
);
562 birth
= process_in
->creation_time
;
564 //hashed_process_data_in = processlist_get_process_data(process_list, cpuq, trace_num);
565 hashed_process_data_in
= resourcelist_obtain_cpu(resourceview_data
, trace_num
, cpu
);
567 /* Set the current process */
568 process_list
->current_hash_data
[trace_num
][process_in
->cpu
] =
569 hashed_process_data_in
;
571 if(ltt_time_compare(hashed_process_data_in
->next_good_time
,
574 TimeWindow time_window
=
575 lttvwindow_get_time_window(resourceview_data
->tab
);
578 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
579 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
582 Drawing_t
*drawing
= resourceview_data
->drawing
;
583 guint width
= drawing
->width
;
586 convert_time_to_pixels(
592 if(hashed_process_data_in
->x
.middle
!= new_x
) {
593 hashed_process_data_in
->x
.middle
= new_x
;
594 hashed_process_data_in
->x
.middle_used
= FALSE
;
595 hashed_process_data_in
->x
.middle_marked
= FALSE
;
601 /* before_execmode_hook
603 * This function basically draw lines and icons. Two types of lines are drawn :
604 * one small (3 pixels?) representing the state of the process and the second
605 * type is thicker (10 pixels?) representing on which CPU a process is running
606 * (and this only in running state).
608 * Extremums of the lines :
609 * x_min : time of the last event context for this process kept in memory.
610 * x_max : time of the current event.
611 * y : middle of the process in the process list. The process is found in the
612 * list, therefore is it's position in pixels.
614 * The choice of lines'color is defined by the context of the last event for this
618 int before_execmode_hook(void *hook_data
, void *call_data
)
620 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
621 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
622 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
624 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
626 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
627 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
630 e
= ltt_tracefile_get_event(tfc
->tf
);
632 LttTime evtime
= ltt_event_time(e
);
634 before_execmode_hook_irq(hook_data
, call_data
);
636 /* we are in a execmode, before the state update. We must draw the
637 * items corresponding to the state before it changes : now is the right
641 guint cpu
= tfs
->cpu
;
643 guint trace_num
= ts
->parent
.index
;
644 LttvProcessState
*process
= ts
->running_process
[cpu
];
645 g_assert(process
!= NULL
);
647 /* Well, the process_out existed : we must get it in the process hash
648 * or add it, and draw its items.
650 /* Add process to process list (if not present) */
652 HashedResourceData
*hashed_process_data
= NULL
;
653 ProcessList
*process_list
= resourceview_data
->process_list
;
655 LttTime birth
= process
->creation_time
;
657 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
)) {
658 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
660 hashed_process_data
= resourcelist_obtain_cpu(resourceview_data
, trace_num
, cpu
);
662 /* Set the current process */
663 process_list
->current_hash_data
[trace_num
][process
->cpu
] =
667 /* Now, the process is in the state hash and our own process hash.
668 * We definitely can draw the items related to the ending state.
671 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
674 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
675 TimeWindow time_window
=
676 lttvwindow_get_time_window(resourceview_data
->tab
);
679 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
680 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
683 Drawing_t
*drawing
= resourceview_data
->drawing
;
684 guint width
= drawing
->width
;
686 convert_time_to_pixels(
692 /* Draw collision indicator */
693 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
694 gdk_draw_point(hashed_process_data
->pixmap
,
697 COLLISION_POSITION(hashed_process_data
->height
));
698 hashed_process_data
->x
.middle_marked
= TRUE
;
702 TimeWindow time_window
=
703 lttvwindow_get_time_window(resourceview_data
->tab
);
706 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
707 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
710 Drawing_t
*drawing
= resourceview_data
->drawing
;
711 guint width
= drawing
->width
;
714 convert_time_to_pixels(
721 /* Jump over draw if we are at the same x position */
722 if(unlikely(x
== hashed_process_data
->x
.middle
&&
723 hashed_process_data
->x
.middle_used
))
725 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
726 /* Draw collision indicator */
727 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
728 gdk_draw_point(hashed_process_data
->pixmap
,
731 COLLISION_POSITION(hashed_process_data
->height
));
732 hashed_process_data
->x
.middle_marked
= TRUE
;
738 DrawContext draw_context
;
739 /* Now create the drawing context that will be used to draw
740 * items related to the last state. */
741 draw_context
.drawable
= hashed_process_data
->pixmap
;
742 draw_context
.gc
= drawing
->gc
;
743 draw_context
.pango_layout
= drawing
->pango_layout
;
744 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
745 draw_context
.drawinfo
.end
.x
= x
;
747 draw_context
.drawinfo
.y
.over
= 1;
748 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
749 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
751 draw_context
.drawinfo
.start
.offset
.over
= 0;
752 draw_context
.drawinfo
.start
.offset
.middle
= 0;
753 draw_context
.drawinfo
.start
.offset
.under
= 0;
754 draw_context
.drawinfo
.end
.offset
.over
= 0;
755 draw_context
.drawinfo
.end
.offset
.middle
= 0;
756 draw_context
.drawinfo
.end
.offset
.under
= 0;
760 PropertiesLine prop_line
;
761 prop_line
.line_width
= STATE_LINE_WIDTH
;
762 prop_line
.style
= GDK_LINE_SOLID
;
763 prop_line
.y
= MIDDLE
;
764 cpu_set_line_color(&prop_line
, tfs
->cpu_state
);
765 draw_line((void*)&prop_line
, (void*)&draw_context
);
767 /* become the last x position */
768 hashed_process_data
->x
.middle
= x
;
769 hashed_process_data
->x
.middle_used
= TRUE
;
770 hashed_process_data
->x
.middle_marked
= FALSE
;
772 /* Calculate the next good time */
773 convert_pixels_to_time(width
, x
+1, time_window
,
774 &hashed_process_data
->next_good_time
);
781 int before_execmode_hook_irq(void *hook_data
, void *call_data
)
783 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
784 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
785 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
787 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
789 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
790 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
793 e
= ltt_tracefile_get_event(tfc
->tf
);
795 LttTime evtime
= ltt_event_time(e
);
797 LttTrace
*trace
= tfc
->t_context
->t
;
799 /* we are in a execmode, before the state update. We must draw the
800 * items corresponding to the state before it changes : now is the right
806 guint cpu
= tfs
->cpu
;
808 guint16 ev_id_entry
= marker_get_id_from_info(trace
, marker_get_info_from_name(trace
, lttv_merge_facility_event_name(LTT_FACILITY_KERNEL
, LTT_EVENT_IRQ_ENTRY
)));
809 guint16 ev_id_exit
= marker_get_id_from_info(trace
, marker_get_info_from_name(trace
, lttv_merge_facility_event_name(LTT_FACILITY_KERNEL
, LTT_EVENT_IRQ_EXIT
)));
810 if(ev_id_entry
== e
->event_id
) {
811 irq
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
813 else if(ev_id_exit
== e
->event_id
) {
814 irq
= ts
->cpu_states
[cpu
].last_irq
;
820 guint trace_num
= ts
->parent
.index
;
822 /* Well, the process_out existed : we must get it in the process hash
823 * or add it, and draw its items.
825 /* Add process to process list (if not present) */
827 HashedResourceData
*hashed_process_data
= NULL
;
828 ProcessList
*process_list
= resourceview_data
->process_list
;
830 hashed_process_data
= resourcelist_obtain_irq(resourceview_data
, trace_num
, irq
);
832 /* Now, the process is in the state hash and our own process hash.
833 * We definitely can draw the items related to the ending state.
836 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
839 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
840 TimeWindow time_window
=
841 lttvwindow_get_time_window(resourceview_data
->tab
);
844 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
845 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
848 Drawing_t
*drawing
= resourceview_data
->drawing
;
849 guint width
= drawing
->width
;
851 convert_time_to_pixels(
857 /* Draw collision indicator */
858 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
859 gdk_draw_point(hashed_process_data
->pixmap
,
862 COLLISION_POSITION(hashed_process_data
->height
));
863 hashed_process_data
->x
.middle_marked
= TRUE
;
867 TimeWindow time_window
=
868 lttvwindow_get_time_window(resourceview_data
->tab
);
871 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
872 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
875 Drawing_t
*drawing
= resourceview_data
->drawing
;
876 guint width
= drawing
->width
;
879 convert_time_to_pixels(
886 /* Jump over draw if we are at the same x position */
887 if(unlikely(x
== hashed_process_data
->x
.middle
&&
888 hashed_process_data
->x
.middle_used
))
890 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
891 /* Draw collision indicator */
892 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
893 gdk_draw_point(hashed_process_data
->pixmap
,
896 COLLISION_POSITION(hashed_process_data
->height
));
897 hashed_process_data
->x
.middle_marked
= TRUE
;
903 DrawContext draw_context
;
904 /* Now create the drawing context that will be used to draw
905 * items related to the last state. */
906 draw_context
.drawable
= hashed_process_data
->pixmap
;
907 draw_context
.gc
= drawing
->gc
;
908 draw_context
.pango_layout
= drawing
->pango_layout
;
909 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
910 draw_context
.drawinfo
.end
.x
= x
;
912 draw_context
.drawinfo
.y
.over
= 1;
913 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
914 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
916 draw_context
.drawinfo
.start
.offset
.over
= 0;
917 draw_context
.drawinfo
.start
.offset
.middle
= 0;
918 draw_context
.drawinfo
.start
.offset
.under
= 0;
919 draw_context
.drawinfo
.end
.offset
.over
= 0;
920 draw_context
.drawinfo
.end
.offset
.middle
= 0;
921 draw_context
.drawinfo
.end
.offset
.under
= 0;
925 PropertiesLine prop_line
;
926 prop_line
.line_width
= STATE_LINE_WIDTH
;
927 prop_line
.style
= GDK_LINE_SOLID
;
928 prop_line
.y
= MIDDLE
;
929 irq_set_line_color(&prop_line
, &ts
->irq_states
[irq
]);
930 draw_line((void*)&prop_line
, (void*)&draw_context
);
932 /* become the last x position */
933 hashed_process_data
->x
.middle
= x
;
934 hashed_process_data
->x
.middle_used
= TRUE
;
935 hashed_process_data
->x
.middle_marked
= FALSE
;
937 /* Calculate the next good time */
938 convert_pixels_to_time(width
, x
+1, time_window
,
939 &hashed_process_data
->next_good_time
);
946 int before_bdev_event_hook(void *hook_data
, void *call_data
)
948 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
949 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
950 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
952 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
954 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
955 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
958 e
= ltt_tracefile_get_event(tfc
->tf
);
960 LttTime evtime
= ltt_event_time(e
);
962 /* we are in a execmode, before the state update. We must draw the
963 * items corresponding to the state before it changes : now is the right
968 guint cpu
= tfs
->cpu
;
969 guint8 major
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
970 guint8 minor
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
971 guint oper
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 2));
972 gint devcode_gint
= MKDEV(major
,minor
);
974 guint trace_num
= ts
->parent
.index
;
976 LttvBdevState
*bdev
= g_hash_table_lookup(ts
->bdev_states
, &devcode_gint
);
977 /* the result of the lookup might be NULL. that's ok, the rest of the function
978 should understand it was not found and that its state is unknown */
980 /* Well, the process_out existed : we must get it in the process hash
981 * or add it, and draw its items.
983 /* Add process to process list (if not present) */
985 HashedResourceData
*hashed_process_data
= NULL
;
986 ProcessList
*process_list
= resourceview_data
->process_list
;
987 // LttTime birth = process->creation_time;
989 // if(likely(process_list->current_hash_data[trace_num][cpu] != NULL)) {
990 // hashed_process_data = process_list->current_hash_data[trace_num][cpu];
992 hashed_process_data
= resourcelist_obtain_bdev(resourceview_data
, trace_num
, devcode_gint
);
993 ////hashed_process_data = processlist_get_process_data(process_list, resourceq, trace_num);
994 // hashed_process_data = processlist_get_process_data(process_list,
1000 /* Set the current process */
1001 // process_list->current_hash_data[trace_num][process->cpu] =
1002 // hashed_process_data;
1005 /* Now, the process is in the state hash and our own process hash.
1006 * We definitely can draw the items related to the ending state.
1009 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
1012 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1013 TimeWindow time_window
=
1014 lttvwindow_get_time_window(resourceview_data
->tab
);
1017 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1018 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1020 #endif //EXTRA_CHECK
1021 Drawing_t
*drawing
= resourceview_data
->drawing
;
1022 guint width
= drawing
->width
;
1024 convert_time_to_pixels(
1030 /* Draw collision indicator */
1031 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1032 gdk_draw_point(hashed_process_data
->pixmap
,
1035 COLLISION_POSITION(hashed_process_data
->height
));
1036 hashed_process_data
->x
.middle_marked
= TRUE
;
1040 TimeWindow time_window
=
1041 lttvwindow_get_time_window(resourceview_data
->tab
);
1044 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1045 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1047 #endif //EXTRA_CHECK
1048 Drawing_t
*drawing
= resourceview_data
->drawing
;
1049 guint width
= drawing
->width
;
1052 convert_time_to_pixels(
1059 /* Jump over draw if we are at the same x position */
1060 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1061 hashed_process_data
->x
.middle_used
))
1063 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1064 /* Draw collision indicator */
1065 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1066 gdk_draw_point(hashed_process_data
->pixmap
,
1069 COLLISION_POSITION(hashed_process_data
->height
));
1070 hashed_process_data
->x
.middle_marked
= TRUE
;
1076 DrawContext draw_context
;
1077 /* Now create the drawing context that will be used to draw
1078 * items related to the last state. */
1079 draw_context
.drawable
= hashed_process_data
->pixmap
;
1080 draw_context
.gc
= drawing
->gc
;
1081 draw_context
.pango_layout
= drawing
->pango_layout
;
1082 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1083 draw_context
.drawinfo
.end
.x
= x
;
1085 draw_context
.drawinfo
.y
.over
= 1;
1086 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
1087 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
1089 draw_context
.drawinfo
.start
.offset
.over
= 0;
1090 draw_context
.drawinfo
.start
.offset
.middle
= 0;
1091 draw_context
.drawinfo
.start
.offset
.under
= 0;
1092 draw_context
.drawinfo
.end
.offset
.over
= 0;
1093 draw_context
.drawinfo
.end
.offset
.middle
= 0;
1094 draw_context
.drawinfo
.end
.offset
.under
= 0;
1098 PropertiesLine prop_line
;
1099 prop_line
.line_width
= STATE_LINE_WIDTH
;
1100 prop_line
.style
= GDK_LINE_SOLID
;
1101 prop_line
.y
= MIDDLE
;
1102 bdev_set_line_color(&prop_line
, bdev
);
1103 draw_line((void*)&prop_line
, (void*)&draw_context
);
1105 /* become the last x position */
1106 hashed_process_data
->x
.middle
= x
;
1107 hashed_process_data
->x
.middle_used
= TRUE
;
1108 hashed_process_data
->x
.middle_marked
= FALSE
;
1110 /* Calculate the next good time */
1111 convert_pixels_to_time(width
, x
+1, time_window
,
1112 &hashed_process_data
->next_good_time
);
1119 gint
update_time_window_hook(void *hook_data
, void *call_data
)
1121 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
1122 Drawing_t
*drawing
= resourceview_data
->drawing
;
1123 ProcessList
*process_list
= resourceview_data
->process_list
;
1125 const TimeWindowNotifyData
*time_window_nofify_data
=
1126 ((const TimeWindowNotifyData
*)call_data
);
1128 TimeWindow
*old_time_window
=
1129 time_window_nofify_data
->old_time_window
;
1130 TimeWindow
*new_time_window
=
1131 time_window_nofify_data
->new_time_window
;
1133 /* Update the ruler */
1134 drawing_update_ruler(resourceview_data
->drawing
,
1138 /* Two cases : zoom in/out or scrolling */
1140 /* In order to make sure we can reuse the old drawing, the scale must
1141 * be the same and the new time interval being partly located in the
1142 * currently shown time interval. (reuse is only for scrolling)
1145 g_info("Old time window HOOK : %lu, %lu to %lu, %lu",
1146 old_time_window
->start_time
.tv_sec
,
1147 old_time_window
->start_time
.tv_nsec
,
1148 old_time_window
->time_width
.tv_sec
,
1149 old_time_window
->time_width
.tv_nsec
);
1151 g_info("New time window HOOK : %lu, %lu to %lu, %lu",
1152 new_time_window
->start_time
.tv_sec
,
1153 new_time_window
->start_time
.tv_nsec
,
1154 new_time_window
->time_width
.tv_sec
,
1155 new_time_window
->time_width
.tv_nsec
);
1157 if( new_time_window
->time_width
.tv_sec
== old_time_window
->time_width
.tv_sec
1158 && new_time_window
->time_width
.tv_nsec
== old_time_window
->time_width
.tv_nsec
)
1160 /* Same scale (scrolling) */
1161 g_info("scrolling");
1162 LttTime
*ns
= &new_time_window
->start_time
;
1163 LttTime
*nw
= &new_time_window
->time_width
;
1164 LttTime
*os
= &old_time_window
->start_time
;
1165 LttTime
*ow
= &old_time_window
->time_width
;
1166 LttTime old_end
= old_time_window
->end_time
;
1167 LttTime new_end
= new_time_window
->end_time
;
1169 //if(ns<os+w && os+w<ns+w)
1170 //if(ns<old_end && os<ns)
1171 if(ltt_time_compare(*ns
, old_end
) == -1
1172 && ltt_time_compare(*os
, *ns
) == -1)
1174 g_info("scrolling near right");
1175 /* Scroll right, keep right part of the screen */
1177 guint width
= resourceview_data
->drawing
->width
;
1178 convert_time_to_pixels(
1184 /* Copy old data to new location */
1185 copy_pixmap_region(process_list
,
1187 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1191 resourceview_data
->drawing
->width
-x
+SAFETY
, -1);
1193 if(drawing
->damage_begin
== drawing
->damage_end
)
1194 drawing
->damage_begin
= resourceview_data
->drawing
->width
-x
;
1196 drawing
->damage_begin
= 0;
1198 drawing
->damage_end
= resourceview_data
->drawing
->width
;
1200 /* Clear the data request background, but not SAFETY */
1201 rectangle_pixmap(process_list
,
1202 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1204 drawing
->damage_begin
+SAFETY
, 0,
1205 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1207 gtk_widget_queue_draw(drawing
->drawing_area
);
1209 /* Get new data for the rest. */
1210 drawing_data_request(resourceview_data
->drawing
,
1211 drawing
->damage_begin
, 0,
1212 drawing
->damage_end
- drawing
->damage_begin
,
1213 resourceview_data
->drawing
->height
);
1215 if(ltt_time_compare(*ns
,*os
) == -1
1216 && ltt_time_compare(*os
,new_end
) == -1)
1218 g_info("scrolling near left");
1219 /* Scroll left, keep left part of the screen */
1221 guint width
= resourceview_data
->drawing
->width
;
1222 convert_time_to_pixels(
1228 /* Copy old data to new location */
1229 copy_pixmap_region (process_list
,
1231 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1237 if(drawing
->damage_begin
== drawing
->damage_end
)
1238 drawing
->damage_end
= x
;
1240 drawing
->damage_end
=
1241 resourceview_data
->drawing
->width
;
1243 drawing
->damage_begin
= 0;
1245 rectangle_pixmap (process_list
,
1246 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1248 drawing
->damage_begin
, 0,
1249 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1252 gtk_widget_queue_draw(drawing
->drawing_area
);
1254 /* Get new data for the rest. */
1255 drawing_data_request(resourceview_data
->drawing
,
1256 drawing
->damage_begin
, 0,
1257 drawing
->damage_end
- drawing
->damage_begin
,
1258 resourceview_data
->drawing
->height
);
1261 if(ltt_time_compare(*ns
,*os
) == 0)
1263 g_info("not scrolling");
1265 g_info("scrolling far");
1266 /* Cannot reuse any part of the screen : far jump */
1269 rectangle_pixmap (process_list
,
1270 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1273 resourceview_data
->drawing
->width
+SAFETY
, // do not overlap
1276 gtk_widget_queue_draw(drawing
->drawing_area
);
1278 drawing
->damage_begin
= 0;
1279 drawing
->damage_end
= resourceview_data
->drawing
->width
;
1281 drawing_data_request(resourceview_data
->drawing
,
1283 resourceview_data
->drawing
->width
,
1284 resourceview_data
->drawing
->height
);
1290 /* Different scale (zoom) */
1293 rectangle_pixmap (process_list
,
1294 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1297 resourceview_data
->drawing
->width
+SAFETY
, // do not overlap
1300 gtk_widget_queue_draw(drawing
->drawing_area
);
1302 drawing
->damage_begin
= 0;
1303 drawing
->damage_end
= resourceview_data
->drawing
->width
;
1305 drawing_data_request(resourceview_data
->drawing
,
1307 resourceview_data
->drawing
->width
,
1308 resourceview_data
->drawing
->height
);
1311 /* Update directly when scrolling */
1312 gdk_window_process_updates(resourceview_data
->drawing
->drawing_area
->window
,
1318 gint
traceset_notify(void *hook_data
, void *call_data
)
1320 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
1321 Drawing_t
*drawing
= resourceview_data
->drawing
;
1323 if(unlikely(drawing
->gc
== NULL
)) {
1326 if(drawing
->dotted_gc
== NULL
) {
1330 drawing_clear(resourceview_data
->drawing
);
1331 processlist_clear(resourceview_data
->process_list
);
1332 gtk_widget_set_size_request(
1333 resourceview_data
->drawing
->drawing_area
,
1334 -1, processlist_get_height(resourceview_data
->process_list
));
1335 redraw_notify(resourceview_data
, NULL
);
1337 request_background_data(resourceview_data
);
1342 gint
redraw_notify(void *hook_data
, void *call_data
)
1344 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
1345 Drawing_t
*drawing
= resourceview_data
->drawing
;
1346 GtkWidget
*widget
= drawing
->drawing_area
;
1348 drawing
->damage_begin
= 0;
1349 drawing
->damage_end
= drawing
->width
;
1351 /* fun feature, to be separated someday... */
1352 drawing_clear(resourceview_data
->drawing
);
1353 processlist_clear(resourceview_data
->process_list
);
1354 gtk_widget_set_size_request(
1355 resourceview_data
->drawing
->drawing_area
,
1356 -1, processlist_get_height(resourceview_data
->process_list
));
1358 rectangle_pixmap (resourceview_data
->process_list
,
1359 widget
->style
->black_gc
,
1362 drawing
->alloc_width
,
1365 gtk_widget_queue_draw(drawing
->drawing_area
);
1367 if(drawing
->damage_begin
< drawing
->damage_end
)
1369 drawing_data_request(drawing
,
1370 drawing
->damage_begin
,
1372 drawing
->damage_end
-drawing
->damage_begin
,
1381 gint
continue_notify(void *hook_data
, void *call_data
)
1383 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
1384 Drawing_t
*drawing
= resourceview_data
->drawing
;
1386 if(drawing
->damage_begin
< drawing
->damage_end
)
1388 drawing_data_request(drawing
,
1389 drawing
->damage_begin
,
1391 drawing
->damage_end
-drawing
->damage_begin
,
1399 gint
update_current_time_hook(void *hook_data
, void *call_data
)
1401 ControlFlowData
*resourceview_data
= (ControlFlowData
*)hook_data
;
1402 Drawing_t
*drawing
= resourceview_data
->drawing
;
1404 LttTime current_time
= *((LttTime
*)call_data
);
1406 TimeWindow time_window
=
1407 lttvwindow_get_time_window(resourceview_data
->tab
);
1409 LttTime time_begin
= time_window
.start_time
;
1410 LttTime width
= time_window
.time_width
;
1413 guint64 time_ll
= ltt_time_to_uint64(width
);
1414 time_ll
= time_ll
>> 1; /* divide by two */
1415 half_width
= ltt_time_from_uint64(time_ll
);
1417 LttTime time_end
= ltt_time_add(time_begin
, width
);
1419 LttvTracesetContext
* tsc
=
1420 lttvwindow_get_traceset_context(resourceview_data
->tab
);
1422 LttTime trace_start
= tsc
->time_span
.start_time
;
1423 LttTime trace_end
= tsc
->time_span
.end_time
;
1425 g_info("New current time HOOK : %lu, %lu", current_time
.tv_sec
,
1426 current_time
.tv_nsec
);
1428 /* If current time is inside time interval, just move the highlight
1431 /* Else, we have to change the time interval. We have to tell it
1432 * to the main window. */
1433 /* The time interval change will take care of placing the current
1434 * time at the center of the visible area, or nearest possible if we are
1435 * at one end of the trace. */
1438 if(ltt_time_compare(current_time
, time_begin
) < 0)
1440 TimeWindow new_time_window
;
1442 if(ltt_time_compare(current_time
,
1443 ltt_time_add(trace_start
,half_width
)) < 0)
1444 time_begin
= trace_start
;
1446 time_begin
= ltt_time_sub(current_time
,half_width
);
1448 new_time_window
.start_time
= time_begin
;
1449 new_time_window
.time_width
= width
;
1450 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1451 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1453 lttvwindow_report_time_window(resourceview_data
->tab
, new_time_window
);
1455 else if(ltt_time_compare(current_time
, time_end
) > 0)
1457 TimeWindow new_time_window
;
1459 if(ltt_time_compare(current_time
, ltt_time_sub(trace_end
, half_width
)) > 0)
1460 time_begin
= ltt_time_sub(trace_end
,width
);
1462 time_begin
= ltt_time_sub(current_time
,half_width
);
1464 new_time_window
.start_time
= time_begin
;
1465 new_time_window
.time_width
= width
;
1466 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1467 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1469 lttvwindow_report_time_window(resourceview_data
->tab
, new_time_window
);
1472 gtk_widget_queue_draw(resourceview_data
->drawing
->drawing_area
);
1474 /* Update directly when scrolling */
1475 gdk_window_process_updates(resourceview_data
->drawing
->drawing_area
->window
,
1481 typedef struct _ClosureData
{
1482 EventsRequest
*events_request
;
1483 LttvTracesetState
*tss
;
1488 /* Draw line until end of the screen */
1490 void draw_closure(gpointer key
, gpointer value
, gpointer user_data
)
1492 ResourceUniqueNumeric
*process_info
= (ResourceUniqueNumeric
*)key
;
1493 HashedResourceData
*hashed_process_data
= (HashedResourceData
*)value
;
1494 ClosureData
*closure_data
= (ClosureData
*)user_data
;
1496 EventsRequest
*events_request
= closure_data
->events_request
;
1497 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1499 LttvTracesetState
*tss
= closure_data
->tss
;
1500 LttvTracesetContext
*tsc
= (LttvTracesetContext
*)tss
;
1502 LttTime evtime
= closure_data
->end_time
;
1504 gboolean dodraw
= TRUE
;
1506 if(hashed_process_data
->type
== RV_RESOURCE_MACHINE
)
1510 /* For the process */
1511 /* First, check if the current process is in the state computation
1512 * process list. If it is there, that means we must add it right now and
1513 * draw items from the beginning of the read for it. If it is not
1514 * present, it's a new process and it was not present : it will
1515 * be added after the state update. */
1517 g_assert(lttv_traceset_number(tsc
->ts
) > 0);
1518 #endif //EXTRA_CHECK
1519 LttvTraceContext
*tc
= tsc
->traces
[process_info
->trace_num
];
1520 LttvTraceState
*ts
= (LttvTraceState
*)tc
;
1522 /* Only draw for processes that are currently in the trace states */
1524 ProcessList
*process_list
= resourceview_data
->process_list
;
1526 /* Should be alike when background info is ready */
1527 if(resourceview_data
->background_info_waiting
==0)
1528 g_assert(ltt_time_compare(process
->creation_time
,
1529 process_info
->birth
) == 0);
1530 #endif //EXTRA_CHECK
1532 /* Now, the process is in the state hash and our own process hash.
1533 * We definitely can draw the items related to the ending state.
1536 if(unlikely(ltt_time_compare(hashed_process_data
->next_good_time
,
1539 TimeWindow time_window
=
1540 lttvwindow_get_time_window(resourceview_data
->tab
);
1543 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1544 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1546 #endif //EXTRA_CHECK
1547 Drawing_t
*drawing
= resourceview_data
->drawing
;
1548 guint width
= drawing
->width
;
1550 guint x
= closure_data
->x_end
;
1552 DrawContext draw_context
;
1554 /* Now create the drawing context that will be used to draw
1555 * items related to the last state. */
1556 draw_context
.drawable
= hashed_process_data
->pixmap
;
1557 draw_context
.gc
= drawing
->gc
;
1558 draw_context
.pango_layout
= drawing
->pango_layout
;
1559 draw_context
.drawinfo
.end
.x
= x
;
1561 draw_context
.drawinfo
.y
.over
= 1;
1562 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
1563 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
1565 draw_context
.drawinfo
.start
.offset
.over
= 0;
1566 draw_context
.drawinfo
.start
.offset
.middle
= 0;
1567 draw_context
.drawinfo
.start
.offset
.under
= 0;
1568 draw_context
.drawinfo
.end
.offset
.over
= 0;
1569 draw_context
.drawinfo
.end
.offset
.middle
= 0;
1570 draw_context
.drawinfo
.end
.offset
.under
= 0;
1572 /* Jump over draw if we are at the same x position */
1573 if(x
== hashed_process_data
->x
.over
)
1577 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.over
;
1579 PropertiesLine prop_line
= prepare_execmode_line(process
);
1580 draw_line((void*)&prop_line
, (void*)&draw_context
);
1582 hashed_process_data
->x
.over
= x
;
1586 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1587 hashed_process_data
->x
.middle_used
)) {
1588 #if 0 /* do not mark closure : not missing information */
1589 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
1590 /* Draw collision indicator */
1591 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1592 gdk_draw_point(drawing
->pixmap
,
1596 hashed_process_data
->x
.middle_marked
= TRUE
;
1601 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1604 PropertiesLine prop_line
;
1605 prop_line
.line_width
= STATE_LINE_WIDTH
;
1606 prop_line
.style
= GDK_LINE_SOLID
;
1607 prop_line
.y
= MIDDLE
;
1608 if(hashed_process_data
->type
== RV_RESOURCE_CPU
)
1609 cpu_set_line_color(&prop_line
, &ts
->cpu_states
[process_info
->id
]);
1610 else if(hashed_process_data
->type
== RV_RESOURCE_IRQ
)
1611 irq_set_line_color(&prop_line
, &ts
->irq_states
[process_info
->id
]);
1612 else if(hashed_process_data
->type
== RV_RESOURCE_BDEV
) {
1613 gint devcode_gint
= process_info
->id
;
1614 LttvBdevState
*bdev
= g_hash_table_lookup(ts
->bdev_states
, &devcode_gint
);
1615 // the lookup may return null; bdev_set_line_color must act appropriately
1616 bdev_set_line_color(&prop_line
, bdev
);
1619 draw_line((void*)&prop_line
, (void*)&draw_context
);
1622 /* become the last x position */
1623 if(likely(x
!= hashed_process_data
->x
.middle
)) {
1624 hashed_process_data
->x
.middle
= x
;
1625 /* but don't use the pixel */
1626 hashed_process_data
->x
.middle_used
= FALSE
;
1628 /* Calculate the next good time */
1629 convert_pixels_to_time(width
, x
+1, time_window
,
1630 &hashed_process_data
->next_good_time
);
1637 int before_chunk(void *hook_data
, void *call_data
)
1639 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1640 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1641 ControlFlowData
*cfd
= (ControlFlowData
*)events_request
->viewer_data
;
1643 /* Deactivate sort */
1644 gtk_tree_sortable_set_sort_column_id(
1645 GTK_TREE_SORTABLE(cfd
->process_list
->list_store
),
1647 GTK_SORT_ASCENDING
);
1649 drawing_chunk_begin(events_request
, tss
);
1654 int before_request(void *hook_data
, void *call_data
)
1656 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1657 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1659 drawing_data_request_begin(events_request
, tss
);
1666 * after request is necessary in addition of after chunk in order to draw
1667 * lines until the end of the screen. after chunk just draws lines until
1674 int after_request(void *hook_data
, void *call_data
)
1677 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1678 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1679 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1681 ProcessList
*process_list
= resourceview_data
->process_list
;
1682 LttTime end_time
= events_request
->end_time
;
1684 ClosureData closure_data
;
1685 closure_data
.events_request
= (EventsRequest
*)hook_data
;
1686 closure_data
.tss
= tss
;
1687 closure_data
.end_time
= end_time
;
1689 TimeWindow time_window
=
1690 lttvwindow_get_time_window(resourceview_data
->tab
);
1691 guint width
= resourceview_data
->drawing
->width
;
1692 convert_time_to_pixels(
1696 &closure_data
.x_end
);
1699 /* Draw last items */
1700 for(i
=0; i
<RV_RESOURCE_COUNT
; i
++) {
1701 g_hash_table_foreach(resourcelist_get_resource_hash_table(resourceview_data
, i
), draw_closure
,
1702 (void*)&closure_data
);
1705 /* Request expose */
1706 drawing_request_expose(events_request
, tss
, end_time
);
1715 int after_chunk(void *hook_data
, void *call_data
)
1717 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1718 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1719 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1720 LttvTracesetContext
*tsc
= (LttvTracesetContext
*)call_data
;
1721 LttvTracefileContext
*tfc
= lttv_traceset_context_get_current_tfc(tsc
);
1724 ProcessList
*process_list
= resourceview_data
->process_list
;
1726 LttvTraceset
*traceset
= tsc
->ts
;
1727 guint nb_trace
= lttv_traceset_number(traceset
);
1729 /* Only execute when called for the first trace's events request */
1730 if(!process_list
->current_hash_data
) return;
1732 for(i
= 0 ; i
< nb_trace
; i
++) {
1733 g_free(process_list
->current_hash_data
[i
]);
1735 g_free(process_list
->current_hash_data
);
1736 process_list
->current_hash_data
= NULL
;
1739 end_time
= LTT_TIME_MIN(tfc
->timestamp
, events_request
->end_time
);
1740 else /* end of traceset, or position now out of request : end */
1741 end_time
= events_request
->end_time
;
1743 ClosureData closure_data
;
1744 closure_data
.events_request
= (EventsRequest
*)hook_data
;
1745 closure_data
.tss
= tss
;
1746 closure_data
.end_time
= end_time
;
1748 TimeWindow time_window
=
1749 lttvwindow_get_time_window(resourceview_data
->tab
);
1750 guint width
= resourceview_data
->drawing
->width
;
1751 convert_time_to_pixels(
1755 &closure_data
.x_end
);
1757 /* Draw last items */
1758 for(i
=0; i
<RV_RESOURCE_COUNT
; i
++) {
1759 g_hash_table_foreach(resourcelist_get_resource_hash_table(resourceview_data
, i
), draw_closure
,
1760 (void*)&closure_data
);
1763 /* Reactivate sort */
1764 gtk_tree_sortable_set_sort_column_id(
1765 GTK_TREE_SORTABLE(resourceview_data
->process_list
->list_store
),
1766 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
,
1767 GTK_SORT_ASCENDING
);
1769 update_index_to_pixmap(resourceview_data
->process_list
);
1770 /* Request a full expose : drawing scrambled */
1771 gtk_widget_queue_draw(resourceview_data
->drawing
->drawing_area
);
1773 /* Request expose (updates damages zone also) */
1774 drawing_request_expose(events_request
, tss
, end_time
);
1779 /* after_statedump_end
1781 * @param hook_data ControlFlowData structure of the viewer.
1782 * @param call_data Event context.
1784 * This function adds items to be drawn in a queue for each process.
1787 int before_statedump_end(void *hook_data
, void *call_data
)
1791 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
1792 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
1793 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1795 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
1797 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
1799 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
1801 LttvTracesetState
*tss
= (LttvTracesetState
*)tfc
->t_context
->ts_context
;
1802 ProcessList
*process_list
= resourceview_data
->process_list
;
1805 e
= ltt_tracefile_get_event(tfc
->tf
);
1807 LttvFilter
*filter
= resourceview_data
->filter
;
1808 if(filter
!= NULL
&& filter
->head
!= NULL
)
1809 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1810 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1813 LttTime evtime
= ltt_event_time(e
);
1815 ClosureData closure_data
;
1816 closure_data
.events_request
= events_request
;
1817 closure_data
.tss
= tss
;
1818 closure_data
.end_time
= evtime
;
1820 TimeWindow time_window
=
1821 lttvwindow_get_time_window(resourceview_data
->tab
);
1822 guint width
= resourceview_data
->drawing
->width
;
1823 convert_time_to_pixels(
1827 &closure_data
.x_end
);
1829 /* Draw last items */
1831 for(i
=0; i
<RV_RESOURCE_COUNT
; i
++) {
1832 g_hash_table_foreach(resourcelist_get_resource_hash_table(resourceview_data
, i
), draw_closure
,
1833 (void*)&closure_data
);
1836 /* Reactivate sort */
1837 gtk_tree_sortable_set_sort_column_id(
1838 GTK_TREE_SORTABLE(resourceview_data
->process_list
->list_store
),
1839 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
,
1840 GTK_SORT_ASCENDING
);
1842 update_index_to_pixmap(resourceview_data
->process_list
);
1843 /* Request a full expose : drawing scrambled */
1844 gtk_widget_queue_draw(resourceview_data
->drawing
->drawing_area
);
1846 /* Request expose (updates damages zone also) */
1847 drawing_request_expose(events_request
, tss
, evtime
);