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
);
831 // TODO: fix this, it's ugly and slow:
835 str
= g_strdup_printf("IRQ %llu [%s]", irq
, (char*)g_quark_to_string(ts
->irq_names
[irq
]));
836 name
= g_quark_from_string(str
);
839 gtk_tree_store_set(resourceview_data
->process_list
->list_store
, &hashed_process_data
->y_iter
, NAME_COLUMN
, g_quark_to_string(name
), -1);
841 /* Now, the process is in the state hash and our own process hash.
842 * We definitely can draw the items related to the ending state.
845 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
848 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
849 TimeWindow time_window
=
850 lttvwindow_get_time_window(resourceview_data
->tab
);
853 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
854 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
857 Drawing_t
*drawing
= resourceview_data
->drawing
;
858 guint width
= drawing
->width
;
860 convert_time_to_pixels(
866 /* Draw collision indicator */
867 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
868 gdk_draw_point(hashed_process_data
->pixmap
,
871 COLLISION_POSITION(hashed_process_data
->height
));
872 hashed_process_data
->x
.middle_marked
= TRUE
;
876 TimeWindow time_window
=
877 lttvwindow_get_time_window(resourceview_data
->tab
);
880 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
881 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
884 Drawing_t
*drawing
= resourceview_data
->drawing
;
885 guint width
= drawing
->width
;
888 convert_time_to_pixels(
895 /* Jump over draw if we are at the same x position */
896 if(unlikely(x
== hashed_process_data
->x
.middle
&&
897 hashed_process_data
->x
.middle_used
))
899 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
900 /* Draw collision indicator */
901 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
902 gdk_draw_point(hashed_process_data
->pixmap
,
905 COLLISION_POSITION(hashed_process_data
->height
));
906 hashed_process_data
->x
.middle_marked
= TRUE
;
912 DrawContext draw_context
;
913 /* Now create the drawing context that will be used to draw
914 * items related to the last state. */
915 draw_context
.drawable
= hashed_process_data
->pixmap
;
916 draw_context
.gc
= drawing
->gc
;
917 draw_context
.pango_layout
= drawing
->pango_layout
;
918 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
919 draw_context
.drawinfo
.end
.x
= x
;
921 draw_context
.drawinfo
.y
.over
= 1;
922 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
923 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
925 draw_context
.drawinfo
.start
.offset
.over
= 0;
926 draw_context
.drawinfo
.start
.offset
.middle
= 0;
927 draw_context
.drawinfo
.start
.offset
.under
= 0;
928 draw_context
.drawinfo
.end
.offset
.over
= 0;
929 draw_context
.drawinfo
.end
.offset
.middle
= 0;
930 draw_context
.drawinfo
.end
.offset
.under
= 0;
934 PropertiesLine prop_line
;
935 prop_line
.line_width
= STATE_LINE_WIDTH
;
936 prop_line
.style
= GDK_LINE_SOLID
;
937 prop_line
.y
= MIDDLE
;
938 irq_set_line_color(&prop_line
, &ts
->irq_states
[irq
]);
939 draw_line((void*)&prop_line
, (void*)&draw_context
);
941 /* become the last x position */
942 hashed_process_data
->x
.middle
= x
;
943 hashed_process_data
->x
.middle_used
= TRUE
;
944 hashed_process_data
->x
.middle_marked
= FALSE
;
946 /* Calculate the next good time */
947 convert_pixels_to_time(width
, x
+1, time_window
,
948 &hashed_process_data
->next_good_time
);
955 int before_bdev_event_hook(void *hook_data
, void *call_data
)
957 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
958 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
959 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
961 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
963 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
964 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
967 e
= ltt_tracefile_get_event(tfc
->tf
);
969 LttTime evtime
= ltt_event_time(e
);
971 /* we are in a execmode, before the state update. We must draw the
972 * items corresponding to the state before it changes : now is the right
977 guint cpu
= tfs
->cpu
;
978 guint8 major
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
979 guint8 minor
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
980 guint oper
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 2));
981 gint devcode_gint
= MKDEV(major
,minor
);
983 guint trace_num
= ts
->parent
.index
;
985 LttvBdevState
*bdev
= g_hash_table_lookup(ts
->bdev_states
, &devcode_gint
);
986 /* the result of the lookup might be NULL. that's ok, the rest of the function
987 should understand it was not found and that its state is unknown */
989 /* Well, the process_out existed : we must get it in the process hash
990 * or add it, and draw its items.
992 /* Add process to process list (if not present) */
994 HashedResourceData
*hashed_process_data
= NULL
;
995 ProcessList
*process_list
= resourceview_data
->process_list
;
996 // LttTime birth = process->creation_time;
998 // if(likely(process_list->current_hash_data[trace_num][cpu] != NULL)) {
999 // hashed_process_data = process_list->current_hash_data[trace_num][cpu];
1001 hashed_process_data
= resourcelist_obtain_bdev(resourceview_data
, trace_num
, devcode_gint
);
1002 ////hashed_process_data = processlist_get_process_data(process_list, resourceq, trace_num);
1003 // hashed_process_data = processlist_get_process_data(process_list,
1009 /* Set the current process */
1010 // process_list->current_hash_data[trace_num][process->cpu] =
1011 // hashed_process_data;
1014 /* Now, the process is in the state hash and our own process hash.
1015 * We definitely can draw the items related to the ending state.
1018 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
1021 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1022 TimeWindow time_window
=
1023 lttvwindow_get_time_window(resourceview_data
->tab
);
1026 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1027 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1029 #endif //EXTRA_CHECK
1030 Drawing_t
*drawing
= resourceview_data
->drawing
;
1031 guint width
= drawing
->width
;
1033 convert_time_to_pixels(
1039 /* Draw collision indicator */
1040 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1041 gdk_draw_point(hashed_process_data
->pixmap
,
1044 COLLISION_POSITION(hashed_process_data
->height
));
1045 hashed_process_data
->x
.middle_marked
= TRUE
;
1049 TimeWindow time_window
=
1050 lttvwindow_get_time_window(resourceview_data
->tab
);
1053 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1054 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1056 #endif //EXTRA_CHECK
1057 Drawing_t
*drawing
= resourceview_data
->drawing
;
1058 guint width
= drawing
->width
;
1061 convert_time_to_pixels(
1068 /* Jump over draw if we are at the same x position */
1069 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1070 hashed_process_data
->x
.middle_used
))
1072 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1073 /* Draw collision indicator */
1074 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1075 gdk_draw_point(hashed_process_data
->pixmap
,
1078 COLLISION_POSITION(hashed_process_data
->height
));
1079 hashed_process_data
->x
.middle_marked
= TRUE
;
1085 DrawContext draw_context
;
1086 /* Now create the drawing context that will be used to draw
1087 * items related to the last state. */
1088 draw_context
.drawable
= hashed_process_data
->pixmap
;
1089 draw_context
.gc
= drawing
->gc
;
1090 draw_context
.pango_layout
= drawing
->pango_layout
;
1091 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1092 draw_context
.drawinfo
.end
.x
= x
;
1094 draw_context
.drawinfo
.y
.over
= 1;
1095 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
1096 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
1098 draw_context
.drawinfo
.start
.offset
.over
= 0;
1099 draw_context
.drawinfo
.start
.offset
.middle
= 0;
1100 draw_context
.drawinfo
.start
.offset
.under
= 0;
1101 draw_context
.drawinfo
.end
.offset
.over
= 0;
1102 draw_context
.drawinfo
.end
.offset
.middle
= 0;
1103 draw_context
.drawinfo
.end
.offset
.under
= 0;
1107 PropertiesLine prop_line
;
1108 prop_line
.line_width
= STATE_LINE_WIDTH
;
1109 prop_line
.style
= GDK_LINE_SOLID
;
1110 prop_line
.y
= MIDDLE
;
1111 bdev_set_line_color(&prop_line
, bdev
);
1112 draw_line((void*)&prop_line
, (void*)&draw_context
);
1114 /* become the last x position */
1115 hashed_process_data
->x
.middle
= x
;
1116 hashed_process_data
->x
.middle_used
= TRUE
;
1117 hashed_process_data
->x
.middle_marked
= FALSE
;
1119 /* Calculate the next good time */
1120 convert_pixels_to_time(width
, x
+1, time_window
,
1121 &hashed_process_data
->next_good_time
);
1128 gint
update_time_window_hook(void *hook_data
, void *call_data
)
1130 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
1131 Drawing_t
*drawing
= resourceview_data
->drawing
;
1132 ProcessList
*process_list
= resourceview_data
->process_list
;
1134 const TimeWindowNotifyData
*time_window_nofify_data
=
1135 ((const TimeWindowNotifyData
*)call_data
);
1137 TimeWindow
*old_time_window
=
1138 time_window_nofify_data
->old_time_window
;
1139 TimeWindow
*new_time_window
=
1140 time_window_nofify_data
->new_time_window
;
1142 /* Update the ruler */
1143 drawing_update_ruler(resourceview_data
->drawing
,
1147 /* Two cases : zoom in/out or scrolling */
1149 /* In order to make sure we can reuse the old drawing, the scale must
1150 * be the same and the new time interval being partly located in the
1151 * currently shown time interval. (reuse is only for scrolling)
1154 g_info("Old time window HOOK : %lu, %lu to %lu, %lu",
1155 old_time_window
->start_time
.tv_sec
,
1156 old_time_window
->start_time
.tv_nsec
,
1157 old_time_window
->time_width
.tv_sec
,
1158 old_time_window
->time_width
.tv_nsec
);
1160 g_info("New time window HOOK : %lu, %lu to %lu, %lu",
1161 new_time_window
->start_time
.tv_sec
,
1162 new_time_window
->start_time
.tv_nsec
,
1163 new_time_window
->time_width
.tv_sec
,
1164 new_time_window
->time_width
.tv_nsec
);
1166 if( new_time_window
->time_width
.tv_sec
== old_time_window
->time_width
.tv_sec
1167 && new_time_window
->time_width
.tv_nsec
== old_time_window
->time_width
.tv_nsec
)
1169 /* Same scale (scrolling) */
1170 g_info("scrolling");
1171 LttTime
*ns
= &new_time_window
->start_time
;
1172 LttTime
*nw
= &new_time_window
->time_width
;
1173 LttTime
*os
= &old_time_window
->start_time
;
1174 LttTime
*ow
= &old_time_window
->time_width
;
1175 LttTime old_end
= old_time_window
->end_time
;
1176 LttTime new_end
= new_time_window
->end_time
;
1178 //if(ns<os+w && os+w<ns+w)
1179 //if(ns<old_end && os<ns)
1180 if(ltt_time_compare(*ns
, old_end
) == -1
1181 && ltt_time_compare(*os
, *ns
) == -1)
1183 g_info("scrolling near right");
1184 /* Scroll right, keep right part of the screen */
1186 guint width
= resourceview_data
->drawing
->width
;
1187 convert_time_to_pixels(
1193 /* Copy old data to new location */
1194 copy_pixmap_region(process_list
,
1196 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1200 resourceview_data
->drawing
->width
-x
+SAFETY
, -1);
1202 if(drawing
->damage_begin
== drawing
->damage_end
)
1203 drawing
->damage_begin
= resourceview_data
->drawing
->width
-x
;
1205 drawing
->damage_begin
= 0;
1207 drawing
->damage_end
= resourceview_data
->drawing
->width
;
1209 /* Clear the data request background, but not SAFETY */
1210 rectangle_pixmap(process_list
,
1211 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1213 drawing
->damage_begin
+SAFETY
, 0,
1214 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1216 gtk_widget_queue_draw(drawing
->drawing_area
);
1218 /* Get new data for the rest. */
1219 drawing_data_request(resourceview_data
->drawing
,
1220 drawing
->damage_begin
, 0,
1221 drawing
->damage_end
- drawing
->damage_begin
,
1222 resourceview_data
->drawing
->height
);
1224 if(ltt_time_compare(*ns
,*os
) == -1
1225 && ltt_time_compare(*os
,new_end
) == -1)
1227 g_info("scrolling near left");
1228 /* Scroll left, keep left part of the screen */
1230 guint width
= resourceview_data
->drawing
->width
;
1231 convert_time_to_pixels(
1237 /* Copy old data to new location */
1238 copy_pixmap_region (process_list
,
1240 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1246 if(drawing
->damage_begin
== drawing
->damage_end
)
1247 drawing
->damage_end
= x
;
1249 drawing
->damage_end
=
1250 resourceview_data
->drawing
->width
;
1252 drawing
->damage_begin
= 0;
1254 rectangle_pixmap (process_list
,
1255 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1257 drawing
->damage_begin
, 0,
1258 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1261 gtk_widget_queue_draw(drawing
->drawing_area
);
1263 /* Get new data for the rest. */
1264 drawing_data_request(resourceview_data
->drawing
,
1265 drawing
->damage_begin
, 0,
1266 drawing
->damage_end
- drawing
->damage_begin
,
1267 resourceview_data
->drawing
->height
);
1270 if(ltt_time_compare(*ns
,*os
) == 0)
1272 g_info("not scrolling");
1274 g_info("scrolling far");
1275 /* Cannot reuse any part of the screen : far jump */
1278 rectangle_pixmap (process_list
,
1279 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1282 resourceview_data
->drawing
->width
+SAFETY
, // do not overlap
1285 gtk_widget_queue_draw(drawing
->drawing_area
);
1287 drawing
->damage_begin
= 0;
1288 drawing
->damage_end
= resourceview_data
->drawing
->width
;
1290 drawing_data_request(resourceview_data
->drawing
,
1292 resourceview_data
->drawing
->width
,
1293 resourceview_data
->drawing
->height
);
1299 /* Different scale (zoom) */
1302 rectangle_pixmap (process_list
,
1303 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1306 resourceview_data
->drawing
->width
+SAFETY
, // do not overlap
1309 gtk_widget_queue_draw(drawing
->drawing_area
);
1311 drawing
->damage_begin
= 0;
1312 drawing
->damage_end
= resourceview_data
->drawing
->width
;
1314 drawing_data_request(resourceview_data
->drawing
,
1316 resourceview_data
->drawing
->width
,
1317 resourceview_data
->drawing
->height
);
1320 /* Update directly when scrolling */
1321 gdk_window_process_updates(resourceview_data
->drawing
->drawing_area
->window
,
1327 gint
traceset_notify(void *hook_data
, void *call_data
)
1329 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
1330 Drawing_t
*drawing
= resourceview_data
->drawing
;
1332 if(unlikely(drawing
->gc
== NULL
)) {
1335 if(drawing
->dotted_gc
== NULL
) {
1339 drawing_clear(resourceview_data
->drawing
);
1340 processlist_clear(resourceview_data
->process_list
);
1341 gtk_widget_set_size_request(
1342 resourceview_data
->drawing
->drawing_area
,
1343 -1, processlist_get_height(resourceview_data
->process_list
));
1344 redraw_notify(resourceview_data
, NULL
);
1346 request_background_data(resourceview_data
);
1351 gint
redraw_notify(void *hook_data
, void *call_data
)
1353 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
1354 Drawing_t
*drawing
= resourceview_data
->drawing
;
1355 GtkWidget
*widget
= drawing
->drawing_area
;
1357 drawing
->damage_begin
= 0;
1358 drawing
->damage_end
= drawing
->width
;
1360 /* fun feature, to be separated someday... */
1361 drawing_clear(resourceview_data
->drawing
);
1362 processlist_clear(resourceview_data
->process_list
);
1363 gtk_widget_set_size_request(
1364 resourceview_data
->drawing
->drawing_area
,
1365 -1, processlist_get_height(resourceview_data
->process_list
));
1367 rectangle_pixmap (resourceview_data
->process_list
,
1368 widget
->style
->black_gc
,
1371 drawing
->alloc_width
,
1374 gtk_widget_queue_draw(drawing
->drawing_area
);
1376 if(drawing
->damage_begin
< drawing
->damage_end
)
1378 drawing_data_request(drawing
,
1379 drawing
->damage_begin
,
1381 drawing
->damage_end
-drawing
->damage_begin
,
1390 gint
continue_notify(void *hook_data
, void *call_data
)
1392 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
1393 Drawing_t
*drawing
= resourceview_data
->drawing
;
1395 if(drawing
->damage_begin
< drawing
->damage_end
)
1397 drawing_data_request(drawing
,
1398 drawing
->damage_begin
,
1400 drawing
->damage_end
-drawing
->damage_begin
,
1408 gint
update_current_time_hook(void *hook_data
, void *call_data
)
1410 ControlFlowData
*resourceview_data
= (ControlFlowData
*)hook_data
;
1411 Drawing_t
*drawing
= resourceview_data
->drawing
;
1413 LttTime current_time
= *((LttTime
*)call_data
);
1415 TimeWindow time_window
=
1416 lttvwindow_get_time_window(resourceview_data
->tab
);
1418 LttTime time_begin
= time_window
.start_time
;
1419 LttTime width
= time_window
.time_width
;
1422 guint64 time_ll
= ltt_time_to_uint64(width
);
1423 time_ll
= time_ll
>> 1; /* divide by two */
1424 half_width
= ltt_time_from_uint64(time_ll
);
1426 LttTime time_end
= ltt_time_add(time_begin
, width
);
1428 LttvTracesetContext
* tsc
=
1429 lttvwindow_get_traceset_context(resourceview_data
->tab
);
1431 LttTime trace_start
= tsc
->time_span
.start_time
;
1432 LttTime trace_end
= tsc
->time_span
.end_time
;
1434 g_info("New current time HOOK : %lu, %lu", current_time
.tv_sec
,
1435 current_time
.tv_nsec
);
1437 /* If current time is inside time interval, just move the highlight
1440 /* Else, we have to change the time interval. We have to tell it
1441 * to the main window. */
1442 /* The time interval change will take care of placing the current
1443 * time at the center of the visible area, or nearest possible if we are
1444 * at one end of the trace. */
1447 if(ltt_time_compare(current_time
, time_begin
) < 0)
1449 TimeWindow new_time_window
;
1451 if(ltt_time_compare(current_time
,
1452 ltt_time_add(trace_start
,half_width
)) < 0)
1453 time_begin
= trace_start
;
1455 time_begin
= ltt_time_sub(current_time
,half_width
);
1457 new_time_window
.start_time
= time_begin
;
1458 new_time_window
.time_width
= width
;
1459 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1460 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1462 lttvwindow_report_time_window(resourceview_data
->tab
, new_time_window
);
1464 else if(ltt_time_compare(current_time
, time_end
) > 0)
1466 TimeWindow new_time_window
;
1468 if(ltt_time_compare(current_time
, ltt_time_sub(trace_end
, half_width
)) > 0)
1469 time_begin
= ltt_time_sub(trace_end
,width
);
1471 time_begin
= ltt_time_sub(current_time
,half_width
);
1473 new_time_window
.start_time
= time_begin
;
1474 new_time_window
.time_width
= width
;
1475 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1476 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1478 lttvwindow_report_time_window(resourceview_data
->tab
, new_time_window
);
1481 gtk_widget_queue_draw(resourceview_data
->drawing
->drawing_area
);
1483 /* Update directly when scrolling */
1484 gdk_window_process_updates(resourceview_data
->drawing
->drawing_area
->window
,
1490 typedef struct _ClosureData
{
1491 EventsRequest
*events_request
;
1492 LttvTracesetState
*tss
;
1497 /* Draw line until end of the screen */
1499 void draw_closure(gpointer key
, gpointer value
, gpointer user_data
)
1501 ResourceUniqueNumeric
*process_info
= (ResourceUniqueNumeric
*)key
;
1502 HashedResourceData
*hashed_process_data
= (HashedResourceData
*)value
;
1503 ClosureData
*closure_data
= (ClosureData
*)user_data
;
1505 EventsRequest
*events_request
= closure_data
->events_request
;
1506 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1508 LttvTracesetState
*tss
= closure_data
->tss
;
1509 LttvTracesetContext
*tsc
= (LttvTracesetContext
*)tss
;
1511 LttTime evtime
= closure_data
->end_time
;
1513 gboolean dodraw
= TRUE
;
1515 if(hashed_process_data
->type
== RV_RESOURCE_MACHINE
)
1519 /* For the process */
1520 /* First, check if the current process is in the state computation
1521 * process list. If it is there, that means we must add it right now and
1522 * draw items from the beginning of the read for it. If it is not
1523 * present, it's a new process and it was not present : it will
1524 * be added after the state update. */
1526 g_assert(lttv_traceset_number(tsc
->ts
) > 0);
1527 #endif //EXTRA_CHECK
1528 LttvTraceContext
*tc
= tsc
->traces
[process_info
->trace_num
];
1529 LttvTraceState
*ts
= (LttvTraceState
*)tc
;
1531 /* Only draw for processes that are currently in the trace states */
1533 ProcessList
*process_list
= resourceview_data
->process_list
;
1535 /* Should be alike when background info is ready */
1536 if(resourceview_data
->background_info_waiting
==0)
1537 g_assert(ltt_time_compare(process
->creation_time
,
1538 process_info
->birth
) == 0);
1539 #endif //EXTRA_CHECK
1541 /* Now, the process is in the state hash and our own process hash.
1542 * We definitely can draw the items related to the ending state.
1545 if(unlikely(ltt_time_compare(hashed_process_data
->next_good_time
,
1548 TimeWindow time_window
=
1549 lttvwindow_get_time_window(resourceview_data
->tab
);
1552 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1553 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1555 #endif //EXTRA_CHECK
1556 Drawing_t
*drawing
= resourceview_data
->drawing
;
1557 guint width
= drawing
->width
;
1559 guint x
= closure_data
->x_end
;
1561 DrawContext draw_context
;
1563 /* Now create the drawing context that will be used to draw
1564 * items related to the last state. */
1565 draw_context
.drawable
= hashed_process_data
->pixmap
;
1566 draw_context
.gc
= drawing
->gc
;
1567 draw_context
.pango_layout
= drawing
->pango_layout
;
1568 draw_context
.drawinfo
.end
.x
= x
;
1570 draw_context
.drawinfo
.y
.over
= 1;
1571 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
1572 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
1574 draw_context
.drawinfo
.start
.offset
.over
= 0;
1575 draw_context
.drawinfo
.start
.offset
.middle
= 0;
1576 draw_context
.drawinfo
.start
.offset
.under
= 0;
1577 draw_context
.drawinfo
.end
.offset
.over
= 0;
1578 draw_context
.drawinfo
.end
.offset
.middle
= 0;
1579 draw_context
.drawinfo
.end
.offset
.under
= 0;
1581 /* Jump over draw if we are at the same x position */
1582 if(x
== hashed_process_data
->x
.over
)
1586 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.over
;
1588 PropertiesLine prop_line
= prepare_execmode_line(process
);
1589 draw_line((void*)&prop_line
, (void*)&draw_context
);
1591 hashed_process_data
->x
.over
= x
;
1595 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1596 hashed_process_data
->x
.middle_used
)) {
1597 #if 0 /* do not mark closure : not missing information */
1598 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
1599 /* Draw collision indicator */
1600 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1601 gdk_draw_point(drawing
->pixmap
,
1605 hashed_process_data
->x
.middle_marked
= TRUE
;
1610 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1613 PropertiesLine prop_line
;
1614 prop_line
.line_width
= STATE_LINE_WIDTH
;
1615 prop_line
.style
= GDK_LINE_SOLID
;
1616 prop_line
.y
= MIDDLE
;
1617 if(hashed_process_data
->type
== RV_RESOURCE_CPU
)
1618 cpu_set_line_color(&prop_line
, &ts
->cpu_states
[process_info
->id
]);
1619 else if(hashed_process_data
->type
== RV_RESOURCE_IRQ
)
1620 irq_set_line_color(&prop_line
, &ts
->irq_states
[process_info
->id
]);
1621 else if(hashed_process_data
->type
== RV_RESOURCE_BDEV
) {
1622 gint devcode_gint
= process_info
->id
;
1623 LttvBdevState
*bdev
= g_hash_table_lookup(ts
->bdev_states
, &devcode_gint
);
1624 // the lookup may return null; bdev_set_line_color must act appropriately
1625 bdev_set_line_color(&prop_line
, bdev
);
1628 draw_line((void*)&prop_line
, (void*)&draw_context
);
1631 /* become the last x position */
1632 if(likely(x
!= hashed_process_data
->x
.middle
)) {
1633 hashed_process_data
->x
.middle
= x
;
1634 /* but don't use the pixel */
1635 hashed_process_data
->x
.middle_used
= FALSE
;
1637 /* Calculate the next good time */
1638 convert_pixels_to_time(width
, x
+1, time_window
,
1639 &hashed_process_data
->next_good_time
);
1646 int before_chunk(void *hook_data
, void *call_data
)
1648 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1649 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1650 ControlFlowData
*cfd
= (ControlFlowData
*)events_request
->viewer_data
;
1652 /* Deactivate sort */
1653 gtk_tree_sortable_set_sort_column_id(
1654 GTK_TREE_SORTABLE(cfd
->process_list
->list_store
),
1656 GTK_SORT_ASCENDING
);
1658 drawing_chunk_begin(events_request
, tss
);
1663 int before_request(void *hook_data
, void *call_data
)
1665 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1666 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1668 drawing_data_request_begin(events_request
, tss
);
1675 * after request is necessary in addition of after chunk in order to draw
1676 * lines until the end of the screen. after chunk just draws lines until
1683 int after_request(void *hook_data
, void *call_data
)
1686 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1687 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1688 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1690 ProcessList
*process_list
= resourceview_data
->process_list
;
1691 LttTime end_time
= events_request
->end_time
;
1693 ClosureData closure_data
;
1694 closure_data
.events_request
= (EventsRequest
*)hook_data
;
1695 closure_data
.tss
= tss
;
1696 closure_data
.end_time
= end_time
;
1698 TimeWindow time_window
=
1699 lttvwindow_get_time_window(resourceview_data
->tab
);
1700 guint width
= resourceview_data
->drawing
->width
;
1701 convert_time_to_pixels(
1705 &closure_data
.x_end
);
1708 /* Draw last items */
1709 for(i
=0; i
<RV_RESOURCE_COUNT
; i
++) {
1710 g_hash_table_foreach(resourcelist_get_resource_hash_table(resourceview_data
, i
), draw_closure
,
1711 (void*)&closure_data
);
1714 /* Request expose */
1715 drawing_request_expose(events_request
, tss
, end_time
);
1724 int after_chunk(void *hook_data
, void *call_data
)
1726 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1727 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1728 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1729 LttvTracesetContext
*tsc
= (LttvTracesetContext
*)call_data
;
1730 LttvTracefileContext
*tfc
= lttv_traceset_context_get_current_tfc(tsc
);
1733 ProcessList
*process_list
= resourceview_data
->process_list
;
1735 LttvTraceset
*traceset
= tsc
->ts
;
1736 guint nb_trace
= lttv_traceset_number(traceset
);
1738 /* Only execute when called for the first trace's events request */
1739 if(!process_list
->current_hash_data
) return;
1741 for(i
= 0 ; i
< nb_trace
; i
++) {
1742 g_free(process_list
->current_hash_data
[i
]);
1744 g_free(process_list
->current_hash_data
);
1745 process_list
->current_hash_data
= NULL
;
1748 end_time
= LTT_TIME_MIN(tfc
->timestamp
, events_request
->end_time
);
1749 else /* end of traceset, or position now out of request : end */
1750 end_time
= events_request
->end_time
;
1752 ClosureData closure_data
;
1753 closure_data
.events_request
= (EventsRequest
*)hook_data
;
1754 closure_data
.tss
= tss
;
1755 closure_data
.end_time
= end_time
;
1757 TimeWindow time_window
=
1758 lttvwindow_get_time_window(resourceview_data
->tab
);
1759 guint width
= resourceview_data
->drawing
->width
;
1760 convert_time_to_pixels(
1764 &closure_data
.x_end
);
1766 /* Draw last items */
1767 for(i
=0; i
<RV_RESOURCE_COUNT
; i
++) {
1768 g_hash_table_foreach(resourcelist_get_resource_hash_table(resourceview_data
, i
), draw_closure
,
1769 (void*)&closure_data
);
1772 /* Reactivate sort */
1773 gtk_tree_sortable_set_sort_column_id(
1774 GTK_TREE_SORTABLE(resourceview_data
->process_list
->list_store
),
1775 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
,
1776 GTK_SORT_ASCENDING
);
1778 update_index_to_pixmap(resourceview_data
->process_list
);
1779 /* Request a full expose : drawing scrambled */
1780 gtk_widget_queue_draw(resourceview_data
->drawing
->drawing_area
);
1782 /* Request expose (updates damages zone also) */
1783 drawing_request_expose(events_request
, tss
, end_time
);
1788 /* after_statedump_end
1790 * @param hook_data ControlFlowData structure of the viewer.
1791 * @param call_data Event context.
1793 * This function adds items to be drawn in a queue for each process.
1796 int before_statedump_end(void *hook_data
, void *call_data
)
1800 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
1801 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
1802 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1804 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
1806 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
1808 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
1810 LttvTracesetState
*tss
= (LttvTracesetState
*)tfc
->t_context
->ts_context
;
1811 ProcessList
*process_list
= resourceview_data
->process_list
;
1814 e
= ltt_tracefile_get_event(tfc
->tf
);
1816 LttvFilter
*filter
= resourceview_data
->filter
;
1817 if(filter
!= NULL
&& filter
->head
!= NULL
)
1818 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1819 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
1822 LttTime evtime
= ltt_event_time(e
);
1824 ClosureData closure_data
;
1825 closure_data
.events_request
= events_request
;
1826 closure_data
.tss
= tss
;
1827 closure_data
.end_time
= evtime
;
1829 TimeWindow time_window
=
1830 lttvwindow_get_time_window(resourceview_data
->tab
);
1831 guint width
= resourceview_data
->drawing
->width
;
1832 convert_time_to_pixels(
1836 &closure_data
.x_end
);
1838 /* Draw last items */
1840 for(i
=0; i
<RV_RESOURCE_COUNT
; i
++) {
1841 g_hash_table_foreach(resourcelist_get_resource_hash_table(resourceview_data
, i
), draw_closure
,
1842 (void*)&closure_data
);
1845 /* Reactivate sort */
1846 gtk_tree_sortable_set_sort_column_id(
1847 GTK_TREE_SORTABLE(resourceview_data
->process_list
->list_store
),
1848 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
,
1849 GTK_SORT_ASCENDING
);
1851 update_index_to_pixmap(resourceview_data
->process_list
);
1852 /* Request a full expose : drawing scrambled */
1853 gtk_widget_queue_draw(resourceview_data
->drawing
->drawing_area
);
1855 /* Request expose (updates damages zone also) */
1856 drawing_request_expose(events_request
, tss
, evtime
);