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_SOFT_IRQ
) {
285 prop_line
->color
= drawing_colors_cpu
[COL_CPU_SOFT_IRQ
];
287 else if(present_state
== LTTV_CPU_TRAP
) {
288 prop_line
->color
= drawing_colors_cpu
[COL_CPU_TRAP
];
290 prop_line
->color
= drawing_colors_cpu
[COL_CPU_UNKNOWN
];
294 static void irq_set_line_color(PropertiesLine
*prop_line
, LttvIRQState
*s
)
296 GQuark present_state
;
297 if(s
->mode_stack
->len
== 0)
298 present_state
= LTTV_IRQ_UNKNOWN
;
300 present_state
= ((GQuark
*)s
->mode_stack
->data
)[s
->mode_stack
->len
-1];
302 if(present_state
== LTTV_IRQ_IDLE
) {
303 prop_line
->color
= drawing_colors_irq
[COL_IRQ_IDLE
];
305 else if(present_state
== LTTV_IRQ_BUSY
) {
306 prop_line
->color
= drawing_colors_irq
[COL_IRQ_BUSY
];
309 prop_line
->color
= drawing_colors_irq
[COL_IRQ_UNKNOWN
];
313 static void soft_irq_set_line_color(PropertiesLine
*prop_line
, LttvSoftIRQState
*s
)
315 GQuark present_state
;
317 prop_line
->color
= drawing_colors_soft_irq
[COL_SOFT_IRQ_IDLE
];
319 prop_line
->color
= drawing_colors_soft_irq
[COL_SOFT_IRQ_BUSY
];
322 static void bdev_set_line_color(PropertiesLine
*prop_line
, LttvBdevState
*s
)
324 GQuark present_state
;
325 if(s
== 0 || s
->mode_stack
->len
== 0)
326 present_state
= LTTV_BDEV_UNKNOWN
;
328 present_state
= ((GQuark
*)s
->mode_stack
->data
)[s
->mode_stack
->len
-1];
330 if(present_state
== LTTV_BDEV_IDLE
) {
331 prop_line
->color
= drawing_colors_bdev
[COL_BDEV_IDLE
];
333 else if(present_state
== LTTV_BDEV_BUSY_READING
) {
334 prop_line
->color
= drawing_colors_bdev
[COL_BDEV_BUSY_READING
];
336 else if(present_state
== LTTV_BDEV_BUSY_WRITING
) {
337 prop_line
->color
= drawing_colors_bdev
[COL_BDEV_BUSY_WRITING
];
340 prop_line
->color
= drawing_colors_bdev
[COL_BDEV_UNKNOWN
];
344 /* before_schedchange_hook
346 * This function basically draw lines and icons. Two types of lines are drawn :
347 * one small (3 pixels?) representing the state of the process and the second
348 * type is thicker (10 pixels?) representing on which CPU a process is running
349 * (and this only in running state).
351 * Extremums of the lines :
352 * x_min : time of the last event context for this process kept in memory.
353 * x_max : time of the current event.
354 * y : middle of the process in the process list. The process is found in the
355 * list, therefore is it's position in pixels.
357 * The choice of lines'color is defined by the context of the last event for this
362 int before_schedchange_hook(void *hook_data
, void *call_data
)
364 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
365 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
366 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
368 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
370 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
371 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
374 e
= ltt_tracefile_get_event(tfc
->tf
);
375 gint target_pid_saved
= tfc
->target_pid
;
377 LttTime evtime
= ltt_event_time(e
);
378 LttvFilter
*filter
= resourceview_data
->filter
;
380 /* we are in a schedchange, before the state update. We must draw the
381 * items corresponding to the state before it changes : now is the right
387 pid_out
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
388 pid_in
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
389 // TODO: can't we reenable this? pmf
390 // if(pid_in != 0 && pid_out != 0) {
391 // /* not a transition to/from idle */
395 tfc
->target_pid
= pid_out
;
397 guint cpu
= tfs
->cpu
;
399 guint trace_num
= ts
->parent
.index
;
400 /* Add process to process list (if not present) */
402 HashedResourceData
*hashed_process_data
= NULL
;
403 ProcessList
*process_list
= resourceview_data
->process_list
;
405 hashed_process_data
= resourcelist_obtain_cpu(resourceview_data
, trace_num
, cpu
);
407 /* Now, the process is in the state hash and our own process hash.
408 * We definitely can draw the items related to the ending state.
411 if(ltt_time_compare(hashed_process_data
->next_good_time
,
414 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
416 TimeWindow time_window
=
417 lttvwindow_get_time_window(resourceview_data
->tab
);
419 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
420 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
423 Drawing_t
*drawing
= resourceview_data
->drawing
;
424 guint width
= drawing
->width
;
426 convert_time_to_pixels(
432 /* Draw collision indicator */
433 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
434 gdk_draw_point(hashed_process_data
->pixmap
,
437 COLLISION_POSITION(hashed_process_data
->height
));
438 hashed_process_data
->x
.middle_marked
= TRUE
;
441 TimeWindow time_window
=
442 lttvwindow_get_time_window(resourceview_data
->tab
);
444 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
445 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
448 Drawing_t
*drawing
= resourceview_data
->drawing
;
449 guint width
= drawing
->width
;
451 convert_time_to_pixels(
457 /* Jump over draw if we are at the same x position */
458 if(x
== hashed_process_data
->x
.middle
&&
459 hashed_process_data
->x
.middle_used
)
461 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
462 /* Draw collision indicator */
463 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
464 gdk_draw_point(hashed_process_data
->pixmap
,
467 COLLISION_POSITION(hashed_process_data
->height
));
468 hashed_process_data
->x
.middle_marked
= TRUE
;
472 DrawContext draw_context
;
474 /* Now create the drawing context that will be used to draw
475 * items related to the last state. */
476 draw_context
.drawable
= hashed_process_data
->pixmap
;
477 draw_context
.gc
= drawing
->gc
;
478 draw_context
.pango_layout
= drawing
->pango_layout
;
479 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
480 draw_context
.drawinfo
.end
.x
= x
;
482 draw_context
.drawinfo
.y
.over
= 1;
483 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
484 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
486 draw_context
.drawinfo
.start
.offset
.over
= 0;
487 draw_context
.drawinfo
.start
.offset
.middle
= 0;
488 draw_context
.drawinfo
.start
.offset
.under
= 0;
489 draw_context
.drawinfo
.end
.offset
.over
= 0;
490 draw_context
.drawinfo
.end
.offset
.middle
= 0;
491 draw_context
.drawinfo
.end
.offset
.under
= 0;
495 //PropertiesLine prop_line = prepare_s_e_line(process);
496 PropertiesLine prop_line
;
497 prop_line
.line_width
= STATE_LINE_WIDTH
;
498 prop_line
.style
= GDK_LINE_SOLID
;
499 prop_line
.y
= MIDDLE
;
500 cpu_set_line_color(&prop_line
, tfs
->cpu_state
);
501 draw_line((void*)&prop_line
, (void*)&draw_context
);
504 /* become the last x position */
505 hashed_process_data
->x
.middle
= x
;
506 hashed_process_data
->x
.middle_used
= TRUE
;
507 hashed_process_data
->x
.middle_marked
= FALSE
;
509 /* Calculate the next good time */
510 convert_pixels_to_time(width
, x
+1, time_window
,
511 &hashed_process_data
->next_good_time
);
518 /* after_schedchange_hook
520 * The draw after hook is called by the reading API to have a
521 * particular event drawn on the screen.
522 * @param hook_data ControlFlowData structure of the viewer.
523 * @param call_data Event context.
525 * This function adds items to be drawn in a queue for each process.
528 int after_schedchange_hook(void *hook_data
, void *call_data
)
530 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
531 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
532 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
533 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
534 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
535 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
538 e
= ltt_tracefile_get_event(tfc
->tf
);
540 LttvFilter
*filter
= resourceview_data
->filter
;
541 if(filter
!= NULL
&& filter
->head
!= NULL
)
542 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
543 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
546 LttTime evtime
= ltt_event_time(e
);
548 /* Add process to process list (if not present) */
549 LttvProcessState
*process_in
;
552 HashedResourceData
*hashed_process_data_in
= NULL
;
554 ProcessList
*process_list
= resourceview_data
->process_list
;
559 pid_out
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
560 pid_in
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
564 /* Find process pid_in in the list... */
565 //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in);
566 //process_in = tfs->process;
567 guint cpu
= tfs
->cpu
;
568 guint trace_num
= ts
->parent
.index
;
569 process_in
= ts
->running_process
[cpu
];
570 /* It should exist, because we are after the state update. */
572 g_assert(process_in
!= NULL
);
574 birth
= process_in
->creation_time
;
576 //hashed_process_data_in = processlist_get_process_data(process_list, cpuq, trace_num);
577 hashed_process_data_in
= resourcelist_obtain_cpu(resourceview_data
, trace_num
, cpu
);
579 /* Set the current process */
580 process_list
->current_hash_data
[trace_num
][process_in
->cpu
] =
581 hashed_process_data_in
;
583 if(ltt_time_compare(hashed_process_data_in
->next_good_time
,
586 TimeWindow time_window
=
587 lttvwindow_get_time_window(resourceview_data
->tab
);
590 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
591 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
594 Drawing_t
*drawing
= resourceview_data
->drawing
;
595 guint width
= drawing
->width
;
598 convert_time_to_pixels(
604 if(hashed_process_data_in
->x
.middle
!= new_x
) {
605 hashed_process_data_in
->x
.middle
= new_x
;
606 hashed_process_data_in
->x
.middle_used
= FALSE
;
607 hashed_process_data_in
->x
.middle_marked
= FALSE
;
613 /* before_execmode_hook
615 * This function basically draw lines and icons. Two types of lines are drawn :
616 * one small (3 pixels?) representing the state of the process and the second
617 * type is thicker (10 pixels?) representing on which CPU a process is running
618 * (and this only in running state).
620 * Extremums of the lines :
621 * x_min : time of the last event context for this process kept in memory.
622 * x_max : time of the current event.
623 * y : middle of the process in the process list. The process is found in the
624 * list, therefore is it's position in pixels.
626 * The choice of lines'color is defined by the context of the last event for this
630 int before_execmode_hook(void *hook_data
, void *call_data
)
632 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
633 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
634 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
636 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
638 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
639 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
642 e
= ltt_tracefile_get_event(tfc
->tf
);
644 LttTime evtime
= ltt_event_time(e
);
646 before_execmode_hook_irq(hook_data
, call_data
);
647 before_execmode_hook_soft_irq(hook_data
, call_data
);
649 /* we are in a execmode, before the state update. We must draw the
650 * items corresponding to the state before it changes : now is the right
654 guint cpu
= tfs
->cpu
;
656 guint trace_num
= ts
->parent
.index
;
657 LttvProcessState
*process
= ts
->running_process
[cpu
];
658 g_assert(process
!= NULL
);
660 /* Well, the process_out existed : we must get it in the process hash
661 * or add it, and draw its items.
663 /* Add process to process list (if not present) */
665 HashedResourceData
*hashed_process_data
= NULL
;
666 ProcessList
*process_list
= resourceview_data
->process_list
;
668 LttTime birth
= process
->creation_time
;
670 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
)) {
671 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
673 hashed_process_data
= resourcelist_obtain_cpu(resourceview_data
, trace_num
, cpu
);
675 /* Set the current process */
676 process_list
->current_hash_data
[trace_num
][process
->cpu
] =
680 /* Now, the process is in the state hash and our own process hash.
681 * We definitely can draw the items related to the ending state.
684 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
687 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
688 TimeWindow time_window
=
689 lttvwindow_get_time_window(resourceview_data
->tab
);
692 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
693 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
696 Drawing_t
*drawing
= resourceview_data
->drawing
;
697 guint width
= drawing
->width
;
699 convert_time_to_pixels(
705 /* Draw collision indicator */
706 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
707 gdk_draw_point(hashed_process_data
->pixmap
,
710 COLLISION_POSITION(hashed_process_data
->height
));
711 hashed_process_data
->x
.middle_marked
= TRUE
;
715 TimeWindow time_window
=
716 lttvwindow_get_time_window(resourceview_data
->tab
);
719 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
720 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
723 Drawing_t
*drawing
= resourceview_data
->drawing
;
724 guint width
= drawing
->width
;
727 convert_time_to_pixels(
734 /* Jump over draw if we are at the same x position */
735 if(unlikely(x
== hashed_process_data
->x
.middle
&&
736 hashed_process_data
->x
.middle_used
))
738 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
739 /* Draw collision indicator */
740 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
741 gdk_draw_point(hashed_process_data
->pixmap
,
744 COLLISION_POSITION(hashed_process_data
->height
));
745 hashed_process_data
->x
.middle_marked
= TRUE
;
751 DrawContext draw_context
;
752 /* Now create the drawing context that will be used to draw
753 * items related to the last state. */
754 draw_context
.drawable
= hashed_process_data
->pixmap
;
755 draw_context
.gc
= drawing
->gc
;
756 draw_context
.pango_layout
= drawing
->pango_layout
;
757 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
758 draw_context
.drawinfo
.end
.x
= x
;
760 draw_context
.drawinfo
.y
.over
= 1;
761 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
762 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
764 draw_context
.drawinfo
.start
.offset
.over
= 0;
765 draw_context
.drawinfo
.start
.offset
.middle
= 0;
766 draw_context
.drawinfo
.start
.offset
.under
= 0;
767 draw_context
.drawinfo
.end
.offset
.over
= 0;
768 draw_context
.drawinfo
.end
.offset
.middle
= 0;
769 draw_context
.drawinfo
.end
.offset
.under
= 0;
773 PropertiesLine prop_line
;
774 prop_line
.line_width
= STATE_LINE_WIDTH
;
775 prop_line
.style
= GDK_LINE_SOLID
;
776 prop_line
.y
= MIDDLE
;
777 cpu_set_line_color(&prop_line
, tfs
->cpu_state
);
778 draw_line((void*)&prop_line
, (void*)&draw_context
);
780 /* become the last x position */
781 hashed_process_data
->x
.middle
= x
;
782 hashed_process_data
->x
.middle_used
= TRUE
;
783 hashed_process_data
->x
.middle_marked
= FALSE
;
785 /* Calculate the next good time */
786 convert_pixels_to_time(width
, x
+1, time_window
,
787 &hashed_process_data
->next_good_time
);
794 int before_execmode_hook_irq(void *hook_data
, void *call_data
)
796 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
797 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
798 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
800 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
802 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
803 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
806 e
= ltt_tracefile_get_event(tfc
->tf
);
808 LttTime evtime
= ltt_event_time(e
);
810 LttTrace
*trace
= tfc
->t_context
->t
;
812 /* we are in a execmode, before the state update. We must draw the
813 * items corresponding to the state before it changes : now is the right
819 guint cpu
= tfs
->cpu
;
821 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
)));
822 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
)));
823 if(ev_id_entry
== e
->event_id
) {
824 irq
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
826 else if(ev_id_exit
== e
->event_id
) {
827 irq
= ts
->cpu_states
[cpu
].last_irq
;
833 guint trace_num
= ts
->parent
.index
;
835 /* Well, the process_out existed : we must get it in the process hash
836 * or add it, and draw its items.
838 /* Add process to process list (if not present) */
840 HashedResourceData
*hashed_process_data
= NULL
;
841 ProcessList
*process_list
= resourceview_data
->process_list
;
843 hashed_process_data
= resourcelist_obtain_irq(resourceview_data
, trace_num
, irq
);
844 // TODO: fix this, it's ugly and slow:
848 str
= g_strdup_printf("IRQ %llu [%s]", irq
, (char*)g_quark_to_string(ts
->irq_names
[irq
]));
849 name
= g_quark_from_string(str
);
852 gtk_tree_store_set(resourceview_data
->process_list
->list_store
, &hashed_process_data
->y_iter
, NAME_COLUMN
, g_quark_to_string(name
), -1);
854 /* Now, the process is in the state hash and our own process hash.
855 * We definitely can draw the items related to the ending state.
858 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
861 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
862 TimeWindow time_window
=
863 lttvwindow_get_time_window(resourceview_data
->tab
);
866 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
867 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
870 Drawing_t
*drawing
= resourceview_data
->drawing
;
871 guint width
= drawing
->width
;
873 convert_time_to_pixels(
879 /* Draw collision indicator */
880 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
881 gdk_draw_point(hashed_process_data
->pixmap
,
884 COLLISION_POSITION(hashed_process_data
->height
));
885 hashed_process_data
->x
.middle_marked
= TRUE
;
889 TimeWindow time_window
=
890 lttvwindow_get_time_window(resourceview_data
->tab
);
893 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
894 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
897 Drawing_t
*drawing
= resourceview_data
->drawing
;
898 guint width
= drawing
->width
;
901 convert_time_to_pixels(
908 /* Jump over draw if we are at the same x position */
909 if(unlikely(x
== hashed_process_data
->x
.middle
&&
910 hashed_process_data
->x
.middle_used
))
912 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
913 /* Draw collision indicator */
914 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
915 gdk_draw_point(hashed_process_data
->pixmap
,
918 COLLISION_POSITION(hashed_process_data
->height
));
919 hashed_process_data
->x
.middle_marked
= TRUE
;
925 DrawContext draw_context
;
926 /* Now create the drawing context that will be used to draw
927 * items related to the last state. */
928 draw_context
.drawable
= hashed_process_data
->pixmap
;
929 draw_context
.gc
= drawing
->gc
;
930 draw_context
.pango_layout
= drawing
->pango_layout
;
931 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
932 draw_context
.drawinfo
.end
.x
= x
;
934 draw_context
.drawinfo
.y
.over
= 1;
935 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
936 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
938 draw_context
.drawinfo
.start
.offset
.over
= 0;
939 draw_context
.drawinfo
.start
.offset
.middle
= 0;
940 draw_context
.drawinfo
.start
.offset
.under
= 0;
941 draw_context
.drawinfo
.end
.offset
.over
= 0;
942 draw_context
.drawinfo
.end
.offset
.middle
= 0;
943 draw_context
.drawinfo
.end
.offset
.under
= 0;
947 PropertiesLine prop_line
;
948 prop_line
.line_width
= STATE_LINE_WIDTH
;
949 prop_line
.style
= GDK_LINE_SOLID
;
950 prop_line
.y
= MIDDLE
;
951 irq_set_line_color(&prop_line
, &ts
->irq_states
[irq
]);
952 draw_line((void*)&prop_line
, (void*)&draw_context
);
954 /* become the last x position */
955 hashed_process_data
->x
.middle
= x
;
956 hashed_process_data
->x
.middle_used
= TRUE
;
957 hashed_process_data
->x
.middle_marked
= FALSE
;
959 /* Calculate the next good time */
960 convert_pixels_to_time(width
, x
+1, time_window
,
961 &hashed_process_data
->next_good_time
);
968 int before_execmode_hook_soft_irq(void *hook_data
, void *call_data
)
970 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
971 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
972 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
974 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
976 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
977 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
980 e
= ltt_tracefile_get_event(tfc
->tf
);
982 LttTime evtime
= ltt_event_time(e
);
984 LttTrace
*trace
= tfc
->t_context
->t
;
986 /* we are in a execmode, before the state update. We must draw the
987 * items corresponding to the state before it changes : now is the right
993 guint cpu
= tfs
->cpu
;
995 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_SOFT_IRQ_ENTRY
)));
996 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_SOFT_IRQ_EXIT
)));
997 if(ev_id_entry
== e
->event_id
) {
998 softirq
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
1000 else if(ev_id_exit
== e
->event_id
) {
1001 softirq
= ts
->cpu_states
[cpu
].last_soft_irq
;
1007 guint trace_num
= ts
->parent
.index
;
1009 /* Well, the process_out existed : we must get it in the process hash
1010 * or add it, and draw its items.
1012 /* Add process to process list (if not present) */
1013 guint pl_height
= 0;
1014 HashedResourceData
*hashed_process_data
= NULL
;
1015 ProcessList
*process_list
= resourceview_data
->process_list
;
1017 hashed_process_data
= resourcelist_obtain_soft_irq(resourceview_data
, trace_num
, softirq
);
1019 /* Now, the process is in the state hash and our own process hash.
1020 * We definitely can draw the items related to the ending state.
1023 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
1026 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1027 TimeWindow time_window
=
1028 lttvwindow_get_time_window(resourceview_data
->tab
);
1031 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1032 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1034 #endif //EXTRA_CHECK
1035 Drawing_t
*drawing
= resourceview_data
->drawing
;
1036 guint width
= drawing
->width
;
1038 convert_time_to_pixels(
1044 /* Draw collision indicator */
1045 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1046 gdk_draw_point(hashed_process_data
->pixmap
,
1049 COLLISION_POSITION(hashed_process_data
->height
));
1050 hashed_process_data
->x
.middle_marked
= TRUE
;
1054 TimeWindow time_window
=
1055 lttvwindow_get_time_window(resourceview_data
->tab
);
1058 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1059 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1061 #endif //EXTRA_CHECK
1062 Drawing_t
*drawing
= resourceview_data
->drawing
;
1063 guint width
= drawing
->width
;
1066 convert_time_to_pixels(
1073 /* Jump over draw if we are at the same x position */
1074 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1075 hashed_process_data
->x
.middle_used
))
1077 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1078 /* Draw collision indicator */
1079 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1080 gdk_draw_point(hashed_process_data
->pixmap
,
1083 COLLISION_POSITION(hashed_process_data
->height
));
1084 hashed_process_data
->x
.middle_marked
= TRUE
;
1090 DrawContext draw_context
;
1091 /* Now create the drawing context that will be used to draw
1092 * items related to the last state. */
1093 draw_context
.drawable
= hashed_process_data
->pixmap
;
1094 draw_context
.gc
= drawing
->gc
;
1095 draw_context
.pango_layout
= drawing
->pango_layout
;
1096 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1097 draw_context
.drawinfo
.end
.x
= x
;
1099 draw_context
.drawinfo
.y
.over
= 1;
1100 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
1101 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
1103 draw_context
.drawinfo
.start
.offset
.over
= 0;
1104 draw_context
.drawinfo
.start
.offset
.middle
= 0;
1105 draw_context
.drawinfo
.start
.offset
.under
= 0;
1106 draw_context
.drawinfo
.end
.offset
.over
= 0;
1107 draw_context
.drawinfo
.end
.offset
.middle
= 0;
1108 draw_context
.drawinfo
.end
.offset
.under
= 0;
1112 PropertiesLine prop_line
;
1113 prop_line
.line_width
= STATE_LINE_WIDTH
;
1114 prop_line
.style
= GDK_LINE_SOLID
;
1115 prop_line
.y
= MIDDLE
;
1116 soft_irq_set_line_color(&prop_line
, &ts
->soft_irq_states
[softirq
]);
1117 draw_line((void*)&prop_line
, (void*)&draw_context
);
1119 /* become the last x position */
1120 hashed_process_data
->x
.middle
= x
;
1121 hashed_process_data
->x
.middle_used
= TRUE
;
1122 hashed_process_data
->x
.middle_marked
= FALSE
;
1124 /* Calculate the next good time */
1125 convert_pixels_to_time(width
, x
+1, time_window
,
1126 &hashed_process_data
->next_good_time
);
1134 int before_bdev_event_hook(void *hook_data
, void *call_data
)
1136 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
1137 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
1138 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1140 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
1142 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
1143 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
1146 e
= ltt_tracefile_get_event(tfc
->tf
);
1148 LttTime evtime
= ltt_event_time(e
);
1150 /* we are in a execmode, before the state update. We must draw the
1151 * items corresponding to the state before it changes : now is the right
1156 guint cpu
= tfs
->cpu
;
1157 guint8 major
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
1158 guint8 minor
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
1159 guint oper
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 2));
1160 gint devcode_gint
= MKDEV(major
,minor
);
1162 guint trace_num
= ts
->parent
.index
;
1164 LttvBdevState
*bdev
= g_hash_table_lookup(ts
->bdev_states
, &devcode_gint
);
1165 /* the result of the lookup might be NULL. that's ok, the rest of the function
1166 should understand it was not found and that its state is unknown */
1168 /* Well, the process_out existed : we must get it in the process hash
1169 * or add it, and draw its items.
1171 /* Add process to process list (if not present) */
1172 guint pl_height
= 0;
1173 HashedResourceData
*hashed_process_data
= NULL
;
1174 ProcessList
*process_list
= resourceview_data
->process_list
;
1175 // LttTime birth = process->creation_time;
1177 // if(likely(process_list->current_hash_data[trace_num][cpu] != NULL)) {
1178 // hashed_process_data = process_list->current_hash_data[trace_num][cpu];
1180 hashed_process_data
= resourcelist_obtain_bdev(resourceview_data
, trace_num
, devcode_gint
);
1181 ////hashed_process_data = processlist_get_process_data(process_list, resourceq, trace_num);
1182 // hashed_process_data = processlist_get_process_data(process_list,
1188 /* Set the current process */
1189 // process_list->current_hash_data[trace_num][process->cpu] =
1190 // hashed_process_data;
1193 /* Now, the process is in the state hash and our own process hash.
1194 * We definitely can draw the items related to the ending state.
1197 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
1200 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1201 TimeWindow time_window
=
1202 lttvwindow_get_time_window(resourceview_data
->tab
);
1205 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1206 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1208 #endif //EXTRA_CHECK
1209 Drawing_t
*drawing
= resourceview_data
->drawing
;
1210 guint width
= drawing
->width
;
1212 convert_time_to_pixels(
1218 /* Draw collision indicator */
1219 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1220 gdk_draw_point(hashed_process_data
->pixmap
,
1223 COLLISION_POSITION(hashed_process_data
->height
));
1224 hashed_process_data
->x
.middle_marked
= TRUE
;
1228 TimeWindow time_window
=
1229 lttvwindow_get_time_window(resourceview_data
->tab
);
1232 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1233 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1235 #endif //EXTRA_CHECK
1236 Drawing_t
*drawing
= resourceview_data
->drawing
;
1237 guint width
= drawing
->width
;
1240 convert_time_to_pixels(
1247 /* Jump over draw if we are at the same x position */
1248 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1249 hashed_process_data
->x
.middle_used
))
1251 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1252 /* Draw collision indicator */
1253 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1254 gdk_draw_point(hashed_process_data
->pixmap
,
1257 COLLISION_POSITION(hashed_process_data
->height
));
1258 hashed_process_data
->x
.middle_marked
= TRUE
;
1264 DrawContext draw_context
;
1265 /* Now create the drawing context that will be used to draw
1266 * items related to the last state. */
1267 draw_context
.drawable
= hashed_process_data
->pixmap
;
1268 draw_context
.gc
= drawing
->gc
;
1269 draw_context
.pango_layout
= drawing
->pango_layout
;
1270 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1271 draw_context
.drawinfo
.end
.x
= x
;
1273 draw_context
.drawinfo
.y
.over
= 1;
1274 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
1275 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
1277 draw_context
.drawinfo
.start
.offset
.over
= 0;
1278 draw_context
.drawinfo
.start
.offset
.middle
= 0;
1279 draw_context
.drawinfo
.start
.offset
.under
= 0;
1280 draw_context
.drawinfo
.end
.offset
.over
= 0;
1281 draw_context
.drawinfo
.end
.offset
.middle
= 0;
1282 draw_context
.drawinfo
.end
.offset
.under
= 0;
1286 PropertiesLine prop_line
;
1287 prop_line
.line_width
= STATE_LINE_WIDTH
;
1288 prop_line
.style
= GDK_LINE_SOLID
;
1289 prop_line
.y
= MIDDLE
;
1290 bdev_set_line_color(&prop_line
, bdev
);
1291 draw_line((void*)&prop_line
, (void*)&draw_context
);
1293 /* become the last x position */
1294 hashed_process_data
->x
.middle
= x
;
1295 hashed_process_data
->x
.middle_used
= TRUE
;
1296 hashed_process_data
->x
.middle_marked
= FALSE
;
1298 /* Calculate the next good time */
1299 convert_pixels_to_time(width
, x
+1, time_window
,
1300 &hashed_process_data
->next_good_time
);
1307 gint
update_time_window_hook(void *hook_data
, void *call_data
)
1309 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
1310 Drawing_t
*drawing
= resourceview_data
->drawing
;
1311 ProcessList
*process_list
= resourceview_data
->process_list
;
1313 const TimeWindowNotifyData
*time_window_nofify_data
=
1314 ((const TimeWindowNotifyData
*)call_data
);
1316 TimeWindow
*old_time_window
=
1317 time_window_nofify_data
->old_time_window
;
1318 TimeWindow
*new_time_window
=
1319 time_window_nofify_data
->new_time_window
;
1321 /* Update the ruler */
1322 drawing_update_ruler(resourceview_data
->drawing
,
1326 /* Two cases : zoom in/out or scrolling */
1328 /* In order to make sure we can reuse the old drawing, the scale must
1329 * be the same and the new time interval being partly located in the
1330 * currently shown time interval. (reuse is only for scrolling)
1333 g_info("Old time window HOOK : %lu, %lu to %lu, %lu",
1334 old_time_window
->start_time
.tv_sec
,
1335 old_time_window
->start_time
.tv_nsec
,
1336 old_time_window
->time_width
.tv_sec
,
1337 old_time_window
->time_width
.tv_nsec
);
1339 g_info("New time window HOOK : %lu, %lu to %lu, %lu",
1340 new_time_window
->start_time
.tv_sec
,
1341 new_time_window
->start_time
.tv_nsec
,
1342 new_time_window
->time_width
.tv_sec
,
1343 new_time_window
->time_width
.tv_nsec
);
1345 if( new_time_window
->time_width
.tv_sec
== old_time_window
->time_width
.tv_sec
1346 && new_time_window
->time_width
.tv_nsec
== old_time_window
->time_width
.tv_nsec
)
1348 /* Same scale (scrolling) */
1349 g_info("scrolling");
1350 LttTime
*ns
= &new_time_window
->start_time
;
1351 LttTime
*nw
= &new_time_window
->time_width
;
1352 LttTime
*os
= &old_time_window
->start_time
;
1353 LttTime
*ow
= &old_time_window
->time_width
;
1354 LttTime old_end
= old_time_window
->end_time
;
1355 LttTime new_end
= new_time_window
->end_time
;
1357 //if(ns<os+w && os+w<ns+w)
1358 //if(ns<old_end && os<ns)
1359 if(ltt_time_compare(*ns
, old_end
) == -1
1360 && ltt_time_compare(*os
, *ns
) == -1)
1362 g_info("scrolling near right");
1363 /* Scroll right, keep right part of the screen */
1365 guint width
= resourceview_data
->drawing
->width
;
1366 convert_time_to_pixels(
1372 /* Copy old data to new location */
1373 copy_pixmap_region(process_list
,
1375 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1379 resourceview_data
->drawing
->width
-x
+SAFETY
, -1);
1381 if(drawing
->damage_begin
== drawing
->damage_end
)
1382 drawing
->damage_begin
= resourceview_data
->drawing
->width
-x
;
1384 drawing
->damage_begin
= 0;
1386 drawing
->damage_end
= resourceview_data
->drawing
->width
;
1388 /* Clear the data request background, but not SAFETY */
1389 rectangle_pixmap(process_list
,
1390 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1392 drawing
->damage_begin
+SAFETY
, 0,
1393 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1395 gtk_widget_queue_draw(drawing
->drawing_area
);
1397 /* Get new data for the rest. */
1398 drawing_data_request(resourceview_data
->drawing
,
1399 drawing
->damage_begin
, 0,
1400 drawing
->damage_end
- drawing
->damage_begin
,
1401 resourceview_data
->drawing
->height
);
1403 if(ltt_time_compare(*ns
,*os
) == -1
1404 && ltt_time_compare(*os
,new_end
) == -1)
1406 g_info("scrolling near left");
1407 /* Scroll left, keep left part of the screen */
1409 guint width
= resourceview_data
->drawing
->width
;
1410 convert_time_to_pixels(
1416 /* Copy old data to new location */
1417 copy_pixmap_region (process_list
,
1419 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1425 if(drawing
->damage_begin
== drawing
->damage_end
)
1426 drawing
->damage_end
= x
;
1428 drawing
->damage_end
=
1429 resourceview_data
->drawing
->width
;
1431 drawing
->damage_begin
= 0;
1433 rectangle_pixmap (process_list
,
1434 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1436 drawing
->damage_begin
, 0,
1437 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1440 gtk_widget_queue_draw(drawing
->drawing_area
);
1442 /* Get new data for the rest. */
1443 drawing_data_request(resourceview_data
->drawing
,
1444 drawing
->damage_begin
, 0,
1445 drawing
->damage_end
- drawing
->damage_begin
,
1446 resourceview_data
->drawing
->height
);
1449 if(ltt_time_compare(*ns
,*os
) == 0)
1451 g_info("not scrolling");
1453 g_info("scrolling far");
1454 /* Cannot reuse any part of the screen : far jump */
1457 rectangle_pixmap (process_list
,
1458 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1461 resourceview_data
->drawing
->width
+SAFETY
, // do not overlap
1464 gtk_widget_queue_draw(drawing
->drawing_area
);
1466 drawing
->damage_begin
= 0;
1467 drawing
->damage_end
= resourceview_data
->drawing
->width
;
1469 drawing_data_request(resourceview_data
->drawing
,
1471 resourceview_data
->drawing
->width
,
1472 resourceview_data
->drawing
->height
);
1478 /* Different scale (zoom) */
1481 rectangle_pixmap (process_list
,
1482 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1485 resourceview_data
->drawing
->width
+SAFETY
, // do not overlap
1488 gtk_widget_queue_draw(drawing
->drawing_area
);
1490 drawing
->damage_begin
= 0;
1491 drawing
->damage_end
= resourceview_data
->drawing
->width
;
1493 drawing_data_request(resourceview_data
->drawing
,
1495 resourceview_data
->drawing
->width
,
1496 resourceview_data
->drawing
->height
);
1499 /* Update directly when scrolling */
1500 gdk_window_process_updates(resourceview_data
->drawing
->drawing_area
->window
,
1506 gint
traceset_notify(void *hook_data
, void *call_data
)
1508 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
1509 Drawing_t
*drawing
= resourceview_data
->drawing
;
1511 if(unlikely(drawing
->gc
== NULL
)) {
1514 if(drawing
->dotted_gc
== NULL
) {
1518 drawing_clear(resourceview_data
->drawing
);
1519 processlist_clear(resourceview_data
->process_list
);
1520 gtk_widget_set_size_request(
1521 resourceview_data
->drawing
->drawing_area
,
1522 -1, processlist_get_height(resourceview_data
->process_list
));
1523 redraw_notify(resourceview_data
, NULL
);
1525 request_background_data(resourceview_data
);
1530 gint
redraw_notify(void *hook_data
, void *call_data
)
1532 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
1533 Drawing_t
*drawing
= resourceview_data
->drawing
;
1534 GtkWidget
*widget
= drawing
->drawing_area
;
1536 drawing
->damage_begin
= 0;
1537 drawing
->damage_end
= drawing
->width
;
1539 /* fun feature, to be separated someday... */
1540 drawing_clear(resourceview_data
->drawing
);
1541 processlist_clear(resourceview_data
->process_list
);
1542 gtk_widget_set_size_request(
1543 resourceview_data
->drawing
->drawing_area
,
1544 -1, processlist_get_height(resourceview_data
->process_list
));
1546 rectangle_pixmap (resourceview_data
->process_list
,
1547 widget
->style
->black_gc
,
1550 drawing
->alloc_width
,
1553 gtk_widget_queue_draw(drawing
->drawing_area
);
1555 if(drawing
->damage_begin
< drawing
->damage_end
)
1557 drawing_data_request(drawing
,
1558 drawing
->damage_begin
,
1560 drawing
->damage_end
-drawing
->damage_begin
,
1569 gint
continue_notify(void *hook_data
, void *call_data
)
1571 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
1572 Drawing_t
*drawing
= resourceview_data
->drawing
;
1574 if(drawing
->damage_begin
< drawing
->damage_end
)
1576 drawing_data_request(drawing
,
1577 drawing
->damage_begin
,
1579 drawing
->damage_end
-drawing
->damage_begin
,
1587 gint
update_current_time_hook(void *hook_data
, void *call_data
)
1589 ControlFlowData
*resourceview_data
= (ControlFlowData
*)hook_data
;
1590 Drawing_t
*drawing
= resourceview_data
->drawing
;
1592 LttTime current_time
= *((LttTime
*)call_data
);
1594 TimeWindow time_window
=
1595 lttvwindow_get_time_window(resourceview_data
->tab
);
1597 LttTime time_begin
= time_window
.start_time
;
1598 LttTime width
= time_window
.time_width
;
1601 guint64 time_ll
= ltt_time_to_uint64(width
);
1602 time_ll
= time_ll
>> 1; /* divide by two */
1603 half_width
= ltt_time_from_uint64(time_ll
);
1605 LttTime time_end
= ltt_time_add(time_begin
, width
);
1607 LttvTracesetContext
* tsc
=
1608 lttvwindow_get_traceset_context(resourceview_data
->tab
);
1610 LttTime trace_start
= tsc
->time_span
.start_time
;
1611 LttTime trace_end
= tsc
->time_span
.end_time
;
1613 g_info("New current time HOOK : %lu, %lu", current_time
.tv_sec
,
1614 current_time
.tv_nsec
);
1616 /* If current time is inside time interval, just move the highlight
1619 /* Else, we have to change the time interval. We have to tell it
1620 * to the main window. */
1621 /* The time interval change will take care of placing the current
1622 * time at the center of the visible area, or nearest possible if we are
1623 * at one end of the trace. */
1626 if(ltt_time_compare(current_time
, time_begin
) < 0)
1628 TimeWindow new_time_window
;
1630 if(ltt_time_compare(current_time
,
1631 ltt_time_add(trace_start
,half_width
)) < 0)
1632 time_begin
= trace_start
;
1634 time_begin
= ltt_time_sub(current_time
,half_width
);
1636 new_time_window
.start_time
= time_begin
;
1637 new_time_window
.time_width
= width
;
1638 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1639 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1641 lttvwindow_report_time_window(resourceview_data
->tab
, new_time_window
);
1643 else if(ltt_time_compare(current_time
, time_end
) > 0)
1645 TimeWindow new_time_window
;
1647 if(ltt_time_compare(current_time
, ltt_time_sub(trace_end
, half_width
)) > 0)
1648 time_begin
= ltt_time_sub(trace_end
,width
);
1650 time_begin
= ltt_time_sub(current_time
,half_width
);
1652 new_time_window
.start_time
= time_begin
;
1653 new_time_window
.time_width
= width
;
1654 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1655 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1657 lttvwindow_report_time_window(resourceview_data
->tab
, new_time_window
);
1660 gtk_widget_queue_draw(resourceview_data
->drawing
->drawing_area
);
1662 /* Update directly when scrolling */
1663 gdk_window_process_updates(resourceview_data
->drawing
->drawing_area
->window
,
1669 typedef struct _ClosureData
{
1670 EventsRequest
*events_request
;
1671 LttvTracesetState
*tss
;
1676 /* Draw line until end of the screen */
1678 void draw_closure(gpointer key
, gpointer value
, gpointer user_data
)
1680 ResourceUniqueNumeric
*process_info
= (ResourceUniqueNumeric
*)key
;
1681 HashedResourceData
*hashed_process_data
= (HashedResourceData
*)value
;
1682 ClosureData
*closure_data
= (ClosureData
*)user_data
;
1684 EventsRequest
*events_request
= closure_data
->events_request
;
1685 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1687 LttvTracesetState
*tss
= closure_data
->tss
;
1688 LttvTracesetContext
*tsc
= (LttvTracesetContext
*)tss
;
1690 LttTime evtime
= closure_data
->end_time
;
1692 gboolean dodraw
= TRUE
;
1694 if(hashed_process_data
->type
== RV_RESOURCE_MACHINE
)
1698 /* For the process */
1699 /* First, check if the current process is in the state computation
1700 * process list. If it is there, that means we must add it right now and
1701 * draw items from the beginning of the read for it. If it is not
1702 * present, it's a new process and it was not present : it will
1703 * be added after the state update. */
1705 g_assert(lttv_traceset_number(tsc
->ts
) > 0);
1706 #endif //EXTRA_CHECK
1707 LttvTraceContext
*tc
= tsc
->traces
[process_info
->trace_num
];
1708 LttvTraceState
*ts
= (LttvTraceState
*)tc
;
1710 /* Only draw for processes that are currently in the trace states */
1712 ProcessList
*process_list
= resourceview_data
->process_list
;
1714 /* Should be alike when background info is ready */
1715 if(resourceview_data
->background_info_waiting
==0)
1716 g_assert(ltt_time_compare(process
->creation_time
,
1717 process_info
->birth
) == 0);
1718 #endif //EXTRA_CHECK
1720 /* Now, the process is in the state hash and our own process hash.
1721 * We definitely can draw the items related to the ending state.
1724 if(unlikely(ltt_time_compare(hashed_process_data
->next_good_time
,
1727 TimeWindow time_window
=
1728 lttvwindow_get_time_window(resourceview_data
->tab
);
1731 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1732 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1734 #endif //EXTRA_CHECK
1735 Drawing_t
*drawing
= resourceview_data
->drawing
;
1736 guint width
= drawing
->width
;
1738 guint x
= closure_data
->x_end
;
1740 DrawContext draw_context
;
1742 /* Now create the drawing context that will be used to draw
1743 * items related to the last state. */
1744 draw_context
.drawable
= hashed_process_data
->pixmap
;
1745 draw_context
.gc
= drawing
->gc
;
1746 draw_context
.pango_layout
= drawing
->pango_layout
;
1747 draw_context
.drawinfo
.end
.x
= x
;
1749 draw_context
.drawinfo
.y
.over
= 1;
1750 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
1751 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
1753 draw_context
.drawinfo
.start
.offset
.over
= 0;
1754 draw_context
.drawinfo
.start
.offset
.middle
= 0;
1755 draw_context
.drawinfo
.start
.offset
.under
= 0;
1756 draw_context
.drawinfo
.end
.offset
.over
= 0;
1757 draw_context
.drawinfo
.end
.offset
.middle
= 0;
1758 draw_context
.drawinfo
.end
.offset
.under
= 0;
1760 /* Jump over draw if we are at the same x position */
1761 if(x
== hashed_process_data
->x
.over
)
1765 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.over
;
1767 PropertiesLine prop_line
= prepare_execmode_line(process
);
1768 draw_line((void*)&prop_line
, (void*)&draw_context
);
1770 hashed_process_data
->x
.over
= x
;
1774 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1775 hashed_process_data
->x
.middle_used
)) {
1776 #if 0 /* do not mark closure : not missing information */
1777 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
1778 /* Draw collision indicator */
1779 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1780 gdk_draw_point(drawing
->pixmap
,
1784 hashed_process_data
->x
.middle_marked
= TRUE
;
1789 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1792 PropertiesLine prop_line
;
1793 prop_line
.line_width
= STATE_LINE_WIDTH
;
1794 prop_line
.style
= GDK_LINE_SOLID
;
1795 prop_line
.y
= MIDDLE
;
1796 if(hashed_process_data
->type
== RV_RESOURCE_CPU
)
1797 cpu_set_line_color(&prop_line
, &ts
->cpu_states
[process_info
->id
]);
1798 else if(hashed_process_data
->type
== RV_RESOURCE_IRQ
)
1799 irq_set_line_color(&prop_line
, &ts
->irq_states
[process_info
->id
]);
1800 else if(hashed_process_data
->type
== RV_RESOURCE_SOFT_IRQ
)
1801 soft_irq_set_line_color(&prop_line
, &ts
->soft_irq_states
[process_info
->id
]);
1802 else if(hashed_process_data
->type
== RV_RESOURCE_BDEV
) {
1803 gint devcode_gint
= process_info
->id
;
1804 LttvBdevState
*bdev
= g_hash_table_lookup(ts
->bdev_states
, &devcode_gint
);
1805 // the lookup may return null; bdev_set_line_color must act appropriately
1806 bdev_set_line_color(&prop_line
, bdev
);
1809 draw_line((void*)&prop_line
, (void*)&draw_context
);
1812 /* become the last x position */
1813 if(likely(x
!= hashed_process_data
->x
.middle
)) {
1814 hashed_process_data
->x
.middle
= x
;
1815 /* but don't use the pixel */
1816 hashed_process_data
->x
.middle_used
= FALSE
;
1818 /* Calculate the next good time */
1819 convert_pixels_to_time(width
, x
+1, time_window
,
1820 &hashed_process_data
->next_good_time
);
1827 int before_chunk(void *hook_data
, void *call_data
)
1829 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1830 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1831 ControlFlowData
*cfd
= (ControlFlowData
*)events_request
->viewer_data
;
1833 /* Deactivate sort */
1834 gtk_tree_sortable_set_sort_column_id(
1835 GTK_TREE_SORTABLE(cfd
->process_list
->list_store
),
1837 GTK_SORT_ASCENDING
);
1839 drawing_chunk_begin(events_request
, tss
);
1844 int before_request(void *hook_data
, void *call_data
)
1846 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1847 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1849 drawing_data_request_begin(events_request
, tss
);
1856 * after request is necessary in addition of after chunk in order to draw
1857 * lines until the end of the screen. after chunk just draws lines until
1864 int after_request(void *hook_data
, void *call_data
)
1867 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1868 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1869 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1871 ProcessList
*process_list
= resourceview_data
->process_list
;
1872 LttTime end_time
= events_request
->end_time
;
1874 ClosureData closure_data
;
1875 closure_data
.events_request
= (EventsRequest
*)hook_data
;
1876 closure_data
.tss
= tss
;
1877 closure_data
.end_time
= end_time
;
1879 TimeWindow time_window
=
1880 lttvwindow_get_time_window(resourceview_data
->tab
);
1881 guint width
= resourceview_data
->drawing
->width
;
1882 convert_time_to_pixels(
1886 &closure_data
.x_end
);
1889 /* Draw last items */
1890 for(i
=0; i
<RV_RESOURCE_COUNT
; i
++) {
1891 g_hash_table_foreach(resourcelist_get_resource_hash_table(resourceview_data
, i
), draw_closure
,
1892 (void*)&closure_data
);
1895 /* Request expose */
1896 drawing_request_expose(events_request
, tss
, end_time
);
1905 int after_chunk(void *hook_data
, void *call_data
)
1907 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1908 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1909 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1910 LttvTracesetContext
*tsc
= (LttvTracesetContext
*)call_data
;
1911 LttvTracefileContext
*tfc
= lttv_traceset_context_get_current_tfc(tsc
);
1914 ProcessList
*process_list
= resourceview_data
->process_list
;
1916 LttvTraceset
*traceset
= tsc
->ts
;
1917 guint nb_trace
= lttv_traceset_number(traceset
);
1919 /* Only execute when called for the first trace's events request */
1920 if(!process_list
->current_hash_data
) return;
1922 for(i
= 0 ; i
< nb_trace
; i
++) {
1923 g_free(process_list
->current_hash_data
[i
]);
1925 g_free(process_list
->current_hash_data
);
1926 process_list
->current_hash_data
= NULL
;
1929 end_time
= LTT_TIME_MIN(tfc
->timestamp
, events_request
->end_time
);
1930 else /* end of traceset, or position now out of request : end */
1931 end_time
= events_request
->end_time
;
1933 ClosureData closure_data
;
1934 closure_data
.events_request
= (EventsRequest
*)hook_data
;
1935 closure_data
.tss
= tss
;
1936 closure_data
.end_time
= end_time
;
1938 TimeWindow time_window
=
1939 lttvwindow_get_time_window(resourceview_data
->tab
);
1940 guint width
= resourceview_data
->drawing
->width
;
1941 convert_time_to_pixels(
1945 &closure_data
.x_end
);
1947 /* Draw last items */
1948 for(i
=0; i
<RV_RESOURCE_COUNT
; i
++) {
1949 g_hash_table_foreach(resourcelist_get_resource_hash_table(resourceview_data
, i
), draw_closure
,
1950 (void*)&closure_data
);
1953 /* Reactivate sort */
1954 gtk_tree_sortable_set_sort_column_id(
1955 GTK_TREE_SORTABLE(resourceview_data
->process_list
->list_store
),
1956 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
,
1957 GTK_SORT_ASCENDING
);
1959 update_index_to_pixmap(resourceview_data
->process_list
);
1960 /* Request a full expose : drawing scrambled */
1961 gtk_widget_queue_draw(resourceview_data
->drawing
->drawing_area
);
1963 /* Request expose (updates damages zone also) */
1964 drawing_request_expose(events_request
, tss
, end_time
);
1969 /* after_statedump_end
1971 * @param hook_data ControlFlowData structure of the viewer.
1972 * @param call_data Event context.
1974 * This function adds items to be drawn in a queue for each process.
1977 int before_statedump_end(void *hook_data
, void *call_data
)
1981 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
1982 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
1983 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1985 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
1987 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
1989 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
1991 LttvTracesetState
*tss
= (LttvTracesetState
*)tfc
->t_context
->ts_context
;
1992 ProcessList
*process_list
= resourceview_data
->process_list
;
1995 e
= ltt_tracefile_get_event(tfc
->tf
);
1997 LttvFilter
*filter
= resourceview_data
->filter
;
1998 if(filter
!= NULL
&& filter
->head
!= NULL
)
1999 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
2000 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
2003 LttTime evtime
= ltt_event_time(e
);
2005 ClosureData closure_data
;
2006 closure_data
.events_request
= events_request
;
2007 closure_data
.tss
= tss
;
2008 closure_data
.end_time
= evtime
;
2010 TimeWindow time_window
=
2011 lttvwindow_get_time_window(resourceview_data
->tab
);
2012 guint width
= resourceview_data
->drawing
->width
;
2013 convert_time_to_pixels(
2017 &closure_data
.x_end
);
2019 /* Draw last items */
2021 for(i
=0; i
<RV_RESOURCE_COUNT
; i
++) {
2022 g_hash_table_foreach(resourcelist_get_resource_hash_table(resourceview_data
, i
), draw_closure
,
2023 (void*)&closure_data
);
2026 /* Reactivate sort */
2027 gtk_tree_sortable_set_sort_column_id(
2028 GTK_TREE_SORTABLE(resourceview_data
->process_list
->list_store
),
2029 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
,
2030 GTK_SORT_ASCENDING
);
2032 update_index_to_pixmap(resourceview_data
->process_list
);
2033 /* Request a full expose : drawing scrambled */
2034 gtk_widget_queue_draw(resourceview_data
->drawing
->drawing_area
);
2036 /* Request expose (updates damages zone also) */
2037 drawing_request_expose(events_request
, tss
, evtime
);