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 soft_irq_set_line_color(PropertiesLine
*prop_line
, LttvSoftIRQState
*s
)
312 GQuark present_state
;
314 prop_line
->color
= drawing_colors_soft_irq
[COL_SOFT_IRQ_IDLE
];
316 prop_line
->color
= drawing_colors_soft_irq
[COL_SOFT_IRQ_BUSY
];
319 static void bdev_set_line_color(PropertiesLine
*prop_line
, LttvBdevState
*s
)
321 GQuark present_state
;
322 if(s
== 0 || s
->mode_stack
->len
== 0)
323 present_state
= LTTV_BDEV_UNKNOWN
;
325 present_state
= ((GQuark
*)s
->mode_stack
->data
)[s
->mode_stack
->len
-1];
327 if(present_state
== LTTV_BDEV_IDLE
) {
328 prop_line
->color
= drawing_colors_bdev
[COL_BDEV_IDLE
];
330 else if(present_state
== LTTV_BDEV_BUSY_READING
) {
331 prop_line
->color
= drawing_colors_bdev
[COL_BDEV_BUSY_READING
];
333 else if(present_state
== LTTV_BDEV_BUSY_WRITING
) {
334 prop_line
->color
= drawing_colors_bdev
[COL_BDEV_BUSY_WRITING
];
337 prop_line
->color
= drawing_colors_bdev
[COL_BDEV_UNKNOWN
];
341 /* before_schedchange_hook
343 * This function basically draw lines and icons. Two types of lines are drawn :
344 * one small (3 pixels?) representing the state of the process and the second
345 * type is thicker (10 pixels?) representing on which CPU a process is running
346 * (and this only in running state).
348 * Extremums of the lines :
349 * x_min : time of the last event context for this process kept in memory.
350 * x_max : time of the current event.
351 * y : middle of the process in the process list. The process is found in the
352 * list, therefore is it's position in pixels.
354 * The choice of lines'color is defined by the context of the last event for this
359 int before_schedchange_hook(void *hook_data
, void *call_data
)
361 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
362 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
363 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
365 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
367 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
368 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
371 e
= ltt_tracefile_get_event(tfc
->tf
);
372 gint target_pid_saved
= tfc
->target_pid
;
374 LttTime evtime
= ltt_event_time(e
);
375 LttvFilter
*filter
= resourceview_data
->filter
;
377 /* we are in a schedchange, before the state update. We must draw the
378 * items corresponding to the state before it changes : now is the right
384 pid_out
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
385 pid_in
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
386 // TODO: can't we reenable this? pmf
387 // if(pid_in != 0 && pid_out != 0) {
388 // /* not a transition to/from idle */
392 tfc
->target_pid
= pid_out
;
394 guint cpu
= tfs
->cpu
;
396 guint trace_num
= ts
->parent
.index
;
397 /* Add process to process list (if not present) */
399 HashedResourceData
*hashed_process_data
= NULL
;
400 ProcessList
*process_list
= resourceview_data
->process_list
;
402 hashed_process_data
= resourcelist_obtain_cpu(resourceview_data
, trace_num
, cpu
);
404 /* Now, the process is in the state hash and our own process hash.
405 * We definitely can draw the items related to the ending state.
408 if(ltt_time_compare(hashed_process_data
->next_good_time
,
411 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
413 TimeWindow time_window
=
414 lttvwindow_get_time_window(resourceview_data
->tab
);
416 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
417 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
420 Drawing_t
*drawing
= resourceview_data
->drawing
;
421 guint width
= drawing
->width
;
423 convert_time_to_pixels(
429 /* Draw collision indicator */
430 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
431 gdk_draw_point(hashed_process_data
->pixmap
,
434 COLLISION_POSITION(hashed_process_data
->height
));
435 hashed_process_data
->x
.middle_marked
= TRUE
;
438 TimeWindow time_window
=
439 lttvwindow_get_time_window(resourceview_data
->tab
);
441 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
442 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
445 Drawing_t
*drawing
= resourceview_data
->drawing
;
446 guint width
= drawing
->width
;
448 convert_time_to_pixels(
454 /* Jump over draw if we are at the same x position */
455 if(x
== hashed_process_data
->x
.middle
&&
456 hashed_process_data
->x
.middle_used
)
458 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
459 /* Draw collision indicator */
460 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
461 gdk_draw_point(hashed_process_data
->pixmap
,
464 COLLISION_POSITION(hashed_process_data
->height
));
465 hashed_process_data
->x
.middle_marked
= TRUE
;
469 DrawContext draw_context
;
471 /* Now create the drawing context that will be used to draw
472 * items related to the last state. */
473 draw_context
.drawable
= hashed_process_data
->pixmap
;
474 draw_context
.gc
= drawing
->gc
;
475 draw_context
.pango_layout
= drawing
->pango_layout
;
476 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
477 draw_context
.drawinfo
.end
.x
= x
;
479 draw_context
.drawinfo
.y
.over
= 1;
480 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
481 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
483 draw_context
.drawinfo
.start
.offset
.over
= 0;
484 draw_context
.drawinfo
.start
.offset
.middle
= 0;
485 draw_context
.drawinfo
.start
.offset
.under
= 0;
486 draw_context
.drawinfo
.end
.offset
.over
= 0;
487 draw_context
.drawinfo
.end
.offset
.middle
= 0;
488 draw_context
.drawinfo
.end
.offset
.under
= 0;
492 //PropertiesLine prop_line = prepare_s_e_line(process);
493 PropertiesLine prop_line
;
494 prop_line
.line_width
= STATE_LINE_WIDTH
;
495 prop_line
.style
= GDK_LINE_SOLID
;
496 prop_line
.y
= MIDDLE
;
497 cpu_set_line_color(&prop_line
, tfs
->cpu_state
);
498 draw_line((void*)&prop_line
, (void*)&draw_context
);
501 /* become the last x position */
502 hashed_process_data
->x
.middle
= x
;
503 hashed_process_data
->x
.middle_used
= TRUE
;
504 hashed_process_data
->x
.middle_marked
= FALSE
;
506 /* Calculate the next good time */
507 convert_pixels_to_time(width
, x
+1, time_window
,
508 &hashed_process_data
->next_good_time
);
515 /* after_schedchange_hook
517 * The draw after hook is called by the reading API to have a
518 * particular event drawn on the screen.
519 * @param hook_data ControlFlowData structure of the viewer.
520 * @param call_data Event context.
522 * This function adds items to be drawn in a queue for each process.
525 int after_schedchange_hook(void *hook_data
, void *call_data
)
527 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
528 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
529 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
530 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
531 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
532 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
535 e
= ltt_tracefile_get_event(tfc
->tf
);
537 LttvFilter
*filter
= resourceview_data
->filter
;
538 if(filter
!= NULL
&& filter
->head
!= NULL
)
539 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
540 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
543 LttTime evtime
= ltt_event_time(e
);
545 /* Add process to process list (if not present) */
546 LttvProcessState
*process_in
;
549 HashedResourceData
*hashed_process_data_in
= NULL
;
551 ProcessList
*process_list
= resourceview_data
->process_list
;
556 pid_out
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
557 pid_in
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
561 /* Find process pid_in in the list... */
562 //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in);
563 //process_in = tfs->process;
564 guint cpu
= tfs
->cpu
;
565 guint trace_num
= ts
->parent
.index
;
566 process_in
= ts
->running_process
[cpu
];
567 /* It should exist, because we are after the state update. */
569 g_assert(process_in
!= NULL
);
571 birth
= process_in
->creation_time
;
573 //hashed_process_data_in = processlist_get_process_data(process_list, cpuq, trace_num);
574 hashed_process_data_in
= resourcelist_obtain_cpu(resourceview_data
, trace_num
, cpu
);
576 /* Set the current process */
577 process_list
->current_hash_data
[trace_num
][process_in
->cpu
] =
578 hashed_process_data_in
;
580 if(ltt_time_compare(hashed_process_data_in
->next_good_time
,
583 TimeWindow time_window
=
584 lttvwindow_get_time_window(resourceview_data
->tab
);
587 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
588 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
591 Drawing_t
*drawing
= resourceview_data
->drawing
;
592 guint width
= drawing
->width
;
595 convert_time_to_pixels(
601 if(hashed_process_data_in
->x
.middle
!= new_x
) {
602 hashed_process_data_in
->x
.middle
= new_x
;
603 hashed_process_data_in
->x
.middle_used
= FALSE
;
604 hashed_process_data_in
->x
.middle_marked
= FALSE
;
610 /* before_execmode_hook
612 * This function basically draw lines and icons. Two types of lines are drawn :
613 * one small (3 pixels?) representing the state of the process and the second
614 * type is thicker (10 pixels?) representing on which CPU a process is running
615 * (and this only in running state).
617 * Extremums of the lines :
618 * x_min : time of the last event context for this process kept in memory.
619 * x_max : time of the current event.
620 * y : middle of the process in the process list. The process is found in the
621 * list, therefore is it's position in pixels.
623 * The choice of lines'color is defined by the context of the last event for this
627 int before_execmode_hook(void *hook_data
, void *call_data
)
629 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
630 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
631 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
633 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
635 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
636 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
639 e
= ltt_tracefile_get_event(tfc
->tf
);
641 LttTime evtime
= ltt_event_time(e
);
643 before_execmode_hook_irq(hook_data
, call_data
);
644 before_execmode_hook_soft_irq(hook_data
, call_data
);
646 /* we are in a execmode, before the state update. We must draw the
647 * items corresponding to the state before it changes : now is the right
651 guint cpu
= tfs
->cpu
;
653 guint trace_num
= ts
->parent
.index
;
654 LttvProcessState
*process
= ts
->running_process
[cpu
];
655 g_assert(process
!= NULL
);
657 /* Well, the process_out existed : we must get it in the process hash
658 * or add it, and draw its items.
660 /* Add process to process list (if not present) */
662 HashedResourceData
*hashed_process_data
= NULL
;
663 ProcessList
*process_list
= resourceview_data
->process_list
;
665 LttTime birth
= process
->creation_time
;
667 if(likely(process_list
->current_hash_data
[trace_num
][cpu
] != NULL
)) {
668 hashed_process_data
= process_list
->current_hash_data
[trace_num
][cpu
];
670 hashed_process_data
= resourcelist_obtain_cpu(resourceview_data
, trace_num
, cpu
);
672 /* Set the current process */
673 process_list
->current_hash_data
[trace_num
][process
->cpu
] =
677 /* Now, the process is in the state hash and our own process hash.
678 * We definitely can draw the items related to the ending state.
681 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
684 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
685 TimeWindow time_window
=
686 lttvwindow_get_time_window(resourceview_data
->tab
);
689 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
690 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
693 Drawing_t
*drawing
= resourceview_data
->drawing
;
694 guint width
= drawing
->width
;
696 convert_time_to_pixels(
702 /* Draw collision indicator */
703 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
704 gdk_draw_point(hashed_process_data
->pixmap
,
707 COLLISION_POSITION(hashed_process_data
->height
));
708 hashed_process_data
->x
.middle_marked
= TRUE
;
712 TimeWindow time_window
=
713 lttvwindow_get_time_window(resourceview_data
->tab
);
716 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
717 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
720 Drawing_t
*drawing
= resourceview_data
->drawing
;
721 guint width
= drawing
->width
;
724 convert_time_to_pixels(
731 /* Jump over draw if we are at the same x position */
732 if(unlikely(x
== hashed_process_data
->x
.middle
&&
733 hashed_process_data
->x
.middle_used
))
735 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
736 /* Draw collision indicator */
737 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
738 gdk_draw_point(hashed_process_data
->pixmap
,
741 COLLISION_POSITION(hashed_process_data
->height
));
742 hashed_process_data
->x
.middle_marked
= TRUE
;
748 DrawContext draw_context
;
749 /* Now create the drawing context that will be used to draw
750 * items related to the last state. */
751 draw_context
.drawable
= hashed_process_data
->pixmap
;
752 draw_context
.gc
= drawing
->gc
;
753 draw_context
.pango_layout
= drawing
->pango_layout
;
754 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
755 draw_context
.drawinfo
.end
.x
= x
;
757 draw_context
.drawinfo
.y
.over
= 1;
758 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
759 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
761 draw_context
.drawinfo
.start
.offset
.over
= 0;
762 draw_context
.drawinfo
.start
.offset
.middle
= 0;
763 draw_context
.drawinfo
.start
.offset
.under
= 0;
764 draw_context
.drawinfo
.end
.offset
.over
= 0;
765 draw_context
.drawinfo
.end
.offset
.middle
= 0;
766 draw_context
.drawinfo
.end
.offset
.under
= 0;
770 PropertiesLine prop_line
;
771 prop_line
.line_width
= STATE_LINE_WIDTH
;
772 prop_line
.style
= GDK_LINE_SOLID
;
773 prop_line
.y
= MIDDLE
;
774 cpu_set_line_color(&prop_line
, tfs
->cpu_state
);
775 draw_line((void*)&prop_line
, (void*)&draw_context
);
777 /* become the last x position */
778 hashed_process_data
->x
.middle
= x
;
779 hashed_process_data
->x
.middle_used
= TRUE
;
780 hashed_process_data
->x
.middle_marked
= FALSE
;
782 /* Calculate the next good time */
783 convert_pixels_to_time(width
, x
+1, time_window
,
784 &hashed_process_data
->next_good_time
);
791 int before_execmode_hook_irq(void *hook_data
, void *call_data
)
793 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
794 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
795 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
797 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
799 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
800 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
803 e
= ltt_tracefile_get_event(tfc
->tf
);
805 LttTime evtime
= ltt_event_time(e
);
807 LttTrace
*trace
= tfc
->t_context
->t
;
809 /* we are in a execmode, before the state update. We must draw the
810 * items corresponding to the state before it changes : now is the right
816 guint cpu
= tfs
->cpu
;
818 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
)));
819 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
)));
820 if(ev_id_entry
== e
->event_id
) {
821 irq
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
823 else if(ev_id_exit
== e
->event_id
) {
824 irq
= ts
->cpu_states
[cpu
].last_irq
;
830 guint trace_num
= ts
->parent
.index
;
832 /* Well, the process_out existed : we must get it in the process hash
833 * or add it, and draw its items.
835 /* Add process to process list (if not present) */
837 HashedResourceData
*hashed_process_data
= NULL
;
838 ProcessList
*process_list
= resourceview_data
->process_list
;
840 hashed_process_data
= resourcelist_obtain_irq(resourceview_data
, trace_num
, irq
);
841 // TODO: fix this, it's ugly and slow:
845 str
= g_strdup_printf("IRQ %llu [%s]", irq
, (char*)g_quark_to_string(ts
->irq_names
[irq
]));
846 name
= g_quark_from_string(str
);
849 gtk_tree_store_set(resourceview_data
->process_list
->list_store
, &hashed_process_data
->y_iter
, NAME_COLUMN
, g_quark_to_string(name
), -1);
851 /* Now, the process is in the state hash and our own process hash.
852 * We definitely can draw the items related to the ending state.
855 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
858 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
859 TimeWindow time_window
=
860 lttvwindow_get_time_window(resourceview_data
->tab
);
863 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
864 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
867 Drawing_t
*drawing
= resourceview_data
->drawing
;
868 guint width
= drawing
->width
;
870 convert_time_to_pixels(
876 /* Draw collision indicator */
877 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
878 gdk_draw_point(hashed_process_data
->pixmap
,
881 COLLISION_POSITION(hashed_process_data
->height
));
882 hashed_process_data
->x
.middle_marked
= TRUE
;
886 TimeWindow time_window
=
887 lttvwindow_get_time_window(resourceview_data
->tab
);
890 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
891 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
894 Drawing_t
*drawing
= resourceview_data
->drawing
;
895 guint width
= drawing
->width
;
898 convert_time_to_pixels(
905 /* Jump over draw if we are at the same x position */
906 if(unlikely(x
== hashed_process_data
->x
.middle
&&
907 hashed_process_data
->x
.middle_used
))
909 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
910 /* Draw collision indicator */
911 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
912 gdk_draw_point(hashed_process_data
->pixmap
,
915 COLLISION_POSITION(hashed_process_data
->height
));
916 hashed_process_data
->x
.middle_marked
= TRUE
;
922 DrawContext draw_context
;
923 /* Now create the drawing context that will be used to draw
924 * items related to the last state. */
925 draw_context
.drawable
= hashed_process_data
->pixmap
;
926 draw_context
.gc
= drawing
->gc
;
927 draw_context
.pango_layout
= drawing
->pango_layout
;
928 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
929 draw_context
.drawinfo
.end
.x
= x
;
931 draw_context
.drawinfo
.y
.over
= 1;
932 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
933 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
935 draw_context
.drawinfo
.start
.offset
.over
= 0;
936 draw_context
.drawinfo
.start
.offset
.middle
= 0;
937 draw_context
.drawinfo
.start
.offset
.under
= 0;
938 draw_context
.drawinfo
.end
.offset
.over
= 0;
939 draw_context
.drawinfo
.end
.offset
.middle
= 0;
940 draw_context
.drawinfo
.end
.offset
.under
= 0;
944 PropertiesLine prop_line
;
945 prop_line
.line_width
= STATE_LINE_WIDTH
;
946 prop_line
.style
= GDK_LINE_SOLID
;
947 prop_line
.y
= MIDDLE
;
948 irq_set_line_color(&prop_line
, &ts
->irq_states
[irq
]);
949 draw_line((void*)&prop_line
, (void*)&draw_context
);
951 /* become the last x position */
952 hashed_process_data
->x
.middle
= x
;
953 hashed_process_data
->x
.middle_used
= TRUE
;
954 hashed_process_data
->x
.middle_marked
= FALSE
;
956 /* Calculate the next good time */
957 convert_pixels_to_time(width
, x
+1, time_window
,
958 &hashed_process_data
->next_good_time
);
965 int before_execmode_hook_soft_irq(void *hook_data
, void *call_data
)
967 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
968 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
969 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
971 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
973 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
974 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
977 e
= ltt_tracefile_get_event(tfc
->tf
);
979 LttTime evtime
= ltt_event_time(e
);
981 LttTrace
*trace
= tfc
->t_context
->t
;
983 /* we are in a execmode, before the state update. We must draw the
984 * items corresponding to the state before it changes : now is the right
990 guint cpu
= tfs
->cpu
;
992 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
)));
993 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
)));
994 if(ev_id_entry
== e
->event_id
) {
995 softirq
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
997 else if(ev_id_exit
== e
->event_id
) {
998 softirq
= ts
->cpu_states
[cpu
].last_soft_irq
;
1004 guint trace_num
= ts
->parent
.index
;
1006 /* Well, the process_out existed : we must get it in the process hash
1007 * or add it, and draw its items.
1009 /* Add process to process list (if not present) */
1010 guint pl_height
= 0;
1011 HashedResourceData
*hashed_process_data
= NULL
;
1012 ProcessList
*process_list
= resourceview_data
->process_list
;
1014 hashed_process_data
= resourcelist_obtain_soft_irq(resourceview_data
, trace_num
, softirq
);
1016 /* Now, the process is in the state hash and our own process hash.
1017 * We definitely can draw the items related to the ending state.
1020 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
1023 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1024 TimeWindow time_window
=
1025 lttvwindow_get_time_window(resourceview_data
->tab
);
1028 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1029 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1031 #endif //EXTRA_CHECK
1032 Drawing_t
*drawing
= resourceview_data
->drawing
;
1033 guint width
= drawing
->width
;
1035 convert_time_to_pixels(
1041 /* Draw collision indicator */
1042 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1043 gdk_draw_point(hashed_process_data
->pixmap
,
1046 COLLISION_POSITION(hashed_process_data
->height
));
1047 hashed_process_data
->x
.middle_marked
= TRUE
;
1051 TimeWindow time_window
=
1052 lttvwindow_get_time_window(resourceview_data
->tab
);
1055 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1056 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1058 #endif //EXTRA_CHECK
1059 Drawing_t
*drawing
= resourceview_data
->drawing
;
1060 guint width
= drawing
->width
;
1063 convert_time_to_pixels(
1070 /* Jump over draw if we are at the same x position */
1071 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1072 hashed_process_data
->x
.middle_used
))
1074 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1075 /* Draw collision indicator */
1076 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1077 gdk_draw_point(hashed_process_data
->pixmap
,
1080 COLLISION_POSITION(hashed_process_data
->height
));
1081 hashed_process_data
->x
.middle_marked
= TRUE
;
1087 DrawContext draw_context
;
1088 /* Now create the drawing context that will be used to draw
1089 * items related to the last state. */
1090 draw_context
.drawable
= hashed_process_data
->pixmap
;
1091 draw_context
.gc
= drawing
->gc
;
1092 draw_context
.pango_layout
= drawing
->pango_layout
;
1093 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1094 draw_context
.drawinfo
.end
.x
= x
;
1096 draw_context
.drawinfo
.y
.over
= 1;
1097 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
1098 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
1100 draw_context
.drawinfo
.start
.offset
.over
= 0;
1101 draw_context
.drawinfo
.start
.offset
.middle
= 0;
1102 draw_context
.drawinfo
.start
.offset
.under
= 0;
1103 draw_context
.drawinfo
.end
.offset
.over
= 0;
1104 draw_context
.drawinfo
.end
.offset
.middle
= 0;
1105 draw_context
.drawinfo
.end
.offset
.under
= 0;
1109 PropertiesLine prop_line
;
1110 prop_line
.line_width
= STATE_LINE_WIDTH
;
1111 prop_line
.style
= GDK_LINE_SOLID
;
1112 prop_line
.y
= MIDDLE
;
1113 soft_irq_set_line_color(&prop_line
, &ts
->soft_irq_states
[softirq
]);
1114 draw_line((void*)&prop_line
, (void*)&draw_context
);
1116 /* become the last x position */
1117 hashed_process_data
->x
.middle
= x
;
1118 hashed_process_data
->x
.middle_used
= TRUE
;
1119 hashed_process_data
->x
.middle_marked
= FALSE
;
1121 /* Calculate the next good time */
1122 convert_pixels_to_time(width
, x
+1, time_window
,
1123 &hashed_process_data
->next_good_time
);
1131 int before_bdev_event_hook(void *hook_data
, void *call_data
)
1133 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
1134 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
1135 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1137 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
1139 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
1140 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
1143 e
= ltt_tracefile_get_event(tfc
->tf
);
1145 LttTime evtime
= ltt_event_time(e
);
1147 /* we are in a execmode, before the state update. We must draw the
1148 * items corresponding to the state before it changes : now is the right
1153 guint cpu
= tfs
->cpu
;
1154 guint8 major
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 0));
1155 guint8 minor
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 1));
1156 guint oper
= ltt_event_get_long_unsigned(e
, lttv_trace_get_hook_field(th
, 2));
1157 gint devcode_gint
= MKDEV(major
,minor
);
1159 guint trace_num
= ts
->parent
.index
;
1161 LttvBdevState
*bdev
= g_hash_table_lookup(ts
->bdev_states
, &devcode_gint
);
1162 /* the result of the lookup might be NULL. that's ok, the rest of the function
1163 should understand it was not found and that its state is unknown */
1165 /* Well, the process_out existed : we must get it in the process hash
1166 * or add it, and draw its items.
1168 /* Add process to process list (if not present) */
1169 guint pl_height
= 0;
1170 HashedResourceData
*hashed_process_data
= NULL
;
1171 ProcessList
*process_list
= resourceview_data
->process_list
;
1172 // LttTime birth = process->creation_time;
1174 // if(likely(process_list->current_hash_data[trace_num][cpu] != NULL)) {
1175 // hashed_process_data = process_list->current_hash_data[trace_num][cpu];
1177 hashed_process_data
= resourcelist_obtain_bdev(resourceview_data
, trace_num
, devcode_gint
);
1178 ////hashed_process_data = processlist_get_process_data(process_list, resourceq, trace_num);
1179 // hashed_process_data = processlist_get_process_data(process_list,
1185 /* Set the current process */
1186 // process_list->current_hash_data[trace_num][process->cpu] =
1187 // hashed_process_data;
1190 /* Now, the process is in the state hash and our own process hash.
1191 * We definitely can draw the items related to the ending state.
1194 if(likely(ltt_time_compare(hashed_process_data
->next_good_time
,
1197 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1198 TimeWindow time_window
=
1199 lttvwindow_get_time_window(resourceview_data
->tab
);
1202 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1203 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1205 #endif //EXTRA_CHECK
1206 Drawing_t
*drawing
= resourceview_data
->drawing
;
1207 guint width
= drawing
->width
;
1209 convert_time_to_pixels(
1215 /* Draw collision indicator */
1216 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1217 gdk_draw_point(hashed_process_data
->pixmap
,
1220 COLLISION_POSITION(hashed_process_data
->height
));
1221 hashed_process_data
->x
.middle_marked
= TRUE
;
1225 TimeWindow time_window
=
1226 lttvwindow_get_time_window(resourceview_data
->tab
);
1229 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1230 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1232 #endif //EXTRA_CHECK
1233 Drawing_t
*drawing
= resourceview_data
->drawing
;
1234 guint width
= drawing
->width
;
1237 convert_time_to_pixels(
1244 /* Jump over draw if we are at the same x position */
1245 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1246 hashed_process_data
->x
.middle_used
))
1248 if(unlikely(hashed_process_data
->x
.middle_marked
== FALSE
)) {
1249 /* Draw collision indicator */
1250 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1251 gdk_draw_point(hashed_process_data
->pixmap
,
1254 COLLISION_POSITION(hashed_process_data
->height
));
1255 hashed_process_data
->x
.middle_marked
= TRUE
;
1261 DrawContext draw_context
;
1262 /* Now create the drawing context that will be used to draw
1263 * items related to the last state. */
1264 draw_context
.drawable
= hashed_process_data
->pixmap
;
1265 draw_context
.gc
= drawing
->gc
;
1266 draw_context
.pango_layout
= drawing
->pango_layout
;
1267 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1268 draw_context
.drawinfo
.end
.x
= x
;
1270 draw_context
.drawinfo
.y
.over
= 1;
1271 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
1272 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
1274 draw_context
.drawinfo
.start
.offset
.over
= 0;
1275 draw_context
.drawinfo
.start
.offset
.middle
= 0;
1276 draw_context
.drawinfo
.start
.offset
.under
= 0;
1277 draw_context
.drawinfo
.end
.offset
.over
= 0;
1278 draw_context
.drawinfo
.end
.offset
.middle
= 0;
1279 draw_context
.drawinfo
.end
.offset
.under
= 0;
1283 PropertiesLine prop_line
;
1284 prop_line
.line_width
= STATE_LINE_WIDTH
;
1285 prop_line
.style
= GDK_LINE_SOLID
;
1286 prop_line
.y
= MIDDLE
;
1287 bdev_set_line_color(&prop_line
, bdev
);
1288 draw_line((void*)&prop_line
, (void*)&draw_context
);
1290 /* become the last x position */
1291 hashed_process_data
->x
.middle
= x
;
1292 hashed_process_data
->x
.middle_used
= TRUE
;
1293 hashed_process_data
->x
.middle_marked
= FALSE
;
1295 /* Calculate the next good time */
1296 convert_pixels_to_time(width
, x
+1, time_window
,
1297 &hashed_process_data
->next_good_time
);
1304 gint
update_time_window_hook(void *hook_data
, void *call_data
)
1306 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
1307 Drawing_t
*drawing
= resourceview_data
->drawing
;
1308 ProcessList
*process_list
= resourceview_data
->process_list
;
1310 const TimeWindowNotifyData
*time_window_nofify_data
=
1311 ((const TimeWindowNotifyData
*)call_data
);
1313 TimeWindow
*old_time_window
=
1314 time_window_nofify_data
->old_time_window
;
1315 TimeWindow
*new_time_window
=
1316 time_window_nofify_data
->new_time_window
;
1318 /* Update the ruler */
1319 drawing_update_ruler(resourceview_data
->drawing
,
1323 /* Two cases : zoom in/out or scrolling */
1325 /* In order to make sure we can reuse the old drawing, the scale must
1326 * be the same and the new time interval being partly located in the
1327 * currently shown time interval. (reuse is only for scrolling)
1330 g_info("Old time window HOOK : %lu, %lu to %lu, %lu",
1331 old_time_window
->start_time
.tv_sec
,
1332 old_time_window
->start_time
.tv_nsec
,
1333 old_time_window
->time_width
.tv_sec
,
1334 old_time_window
->time_width
.tv_nsec
);
1336 g_info("New time window HOOK : %lu, %lu to %lu, %lu",
1337 new_time_window
->start_time
.tv_sec
,
1338 new_time_window
->start_time
.tv_nsec
,
1339 new_time_window
->time_width
.tv_sec
,
1340 new_time_window
->time_width
.tv_nsec
);
1342 if( new_time_window
->time_width
.tv_sec
== old_time_window
->time_width
.tv_sec
1343 && new_time_window
->time_width
.tv_nsec
== old_time_window
->time_width
.tv_nsec
)
1345 /* Same scale (scrolling) */
1346 g_info("scrolling");
1347 LttTime
*ns
= &new_time_window
->start_time
;
1348 LttTime
*nw
= &new_time_window
->time_width
;
1349 LttTime
*os
= &old_time_window
->start_time
;
1350 LttTime
*ow
= &old_time_window
->time_width
;
1351 LttTime old_end
= old_time_window
->end_time
;
1352 LttTime new_end
= new_time_window
->end_time
;
1354 //if(ns<os+w && os+w<ns+w)
1355 //if(ns<old_end && os<ns)
1356 if(ltt_time_compare(*ns
, old_end
) == -1
1357 && ltt_time_compare(*os
, *ns
) == -1)
1359 g_info("scrolling near right");
1360 /* Scroll right, keep right part of the screen */
1362 guint width
= resourceview_data
->drawing
->width
;
1363 convert_time_to_pixels(
1369 /* Copy old data to new location */
1370 copy_pixmap_region(process_list
,
1372 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1376 resourceview_data
->drawing
->width
-x
+SAFETY
, -1);
1378 if(drawing
->damage_begin
== drawing
->damage_end
)
1379 drawing
->damage_begin
= resourceview_data
->drawing
->width
-x
;
1381 drawing
->damage_begin
= 0;
1383 drawing
->damage_end
= resourceview_data
->drawing
->width
;
1385 /* Clear the data request background, but not SAFETY */
1386 rectangle_pixmap(process_list
,
1387 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1389 drawing
->damage_begin
+SAFETY
, 0,
1390 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1392 gtk_widget_queue_draw(drawing
->drawing_area
);
1394 /* Get new data for the rest. */
1395 drawing_data_request(resourceview_data
->drawing
,
1396 drawing
->damage_begin
, 0,
1397 drawing
->damage_end
- drawing
->damage_begin
,
1398 resourceview_data
->drawing
->height
);
1400 if(ltt_time_compare(*ns
,*os
) == -1
1401 && ltt_time_compare(*os
,new_end
) == -1)
1403 g_info("scrolling near left");
1404 /* Scroll left, keep left part of the screen */
1406 guint width
= resourceview_data
->drawing
->width
;
1407 convert_time_to_pixels(
1413 /* Copy old data to new location */
1414 copy_pixmap_region (process_list
,
1416 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1422 if(drawing
->damage_begin
== drawing
->damage_end
)
1423 drawing
->damage_end
= x
;
1425 drawing
->damage_end
=
1426 resourceview_data
->drawing
->width
;
1428 drawing
->damage_begin
= 0;
1430 rectangle_pixmap (process_list
,
1431 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1433 drawing
->damage_begin
, 0,
1434 drawing
->damage_end
- drawing
->damage_begin
, // do not overlap
1437 gtk_widget_queue_draw(drawing
->drawing_area
);
1439 /* Get new data for the rest. */
1440 drawing_data_request(resourceview_data
->drawing
,
1441 drawing
->damage_begin
, 0,
1442 drawing
->damage_end
- drawing
->damage_begin
,
1443 resourceview_data
->drawing
->height
);
1446 if(ltt_time_compare(*ns
,*os
) == 0)
1448 g_info("not scrolling");
1450 g_info("scrolling far");
1451 /* Cannot reuse any part of the screen : far jump */
1454 rectangle_pixmap (process_list
,
1455 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1458 resourceview_data
->drawing
->width
+SAFETY
, // do not overlap
1461 gtk_widget_queue_draw(drawing
->drawing_area
);
1463 drawing
->damage_begin
= 0;
1464 drawing
->damage_end
= resourceview_data
->drawing
->width
;
1466 drawing_data_request(resourceview_data
->drawing
,
1468 resourceview_data
->drawing
->width
,
1469 resourceview_data
->drawing
->height
);
1475 /* Different scale (zoom) */
1478 rectangle_pixmap (process_list
,
1479 resourceview_data
->drawing
->drawing_area
->style
->black_gc
,
1482 resourceview_data
->drawing
->width
+SAFETY
, // do not overlap
1485 gtk_widget_queue_draw(drawing
->drawing_area
);
1487 drawing
->damage_begin
= 0;
1488 drawing
->damage_end
= resourceview_data
->drawing
->width
;
1490 drawing_data_request(resourceview_data
->drawing
,
1492 resourceview_data
->drawing
->width
,
1493 resourceview_data
->drawing
->height
);
1496 /* Update directly when scrolling */
1497 gdk_window_process_updates(resourceview_data
->drawing
->drawing_area
->window
,
1503 gint
traceset_notify(void *hook_data
, void *call_data
)
1505 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
1506 Drawing_t
*drawing
= resourceview_data
->drawing
;
1508 if(unlikely(drawing
->gc
== NULL
)) {
1511 if(drawing
->dotted_gc
== NULL
) {
1515 drawing_clear(resourceview_data
->drawing
);
1516 processlist_clear(resourceview_data
->process_list
);
1517 gtk_widget_set_size_request(
1518 resourceview_data
->drawing
->drawing_area
,
1519 -1, processlist_get_height(resourceview_data
->process_list
));
1520 redraw_notify(resourceview_data
, NULL
);
1522 request_background_data(resourceview_data
);
1527 gint
redraw_notify(void *hook_data
, void *call_data
)
1529 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
1530 Drawing_t
*drawing
= resourceview_data
->drawing
;
1531 GtkWidget
*widget
= drawing
->drawing_area
;
1533 drawing
->damage_begin
= 0;
1534 drawing
->damage_end
= drawing
->width
;
1536 /* fun feature, to be separated someday... */
1537 drawing_clear(resourceview_data
->drawing
);
1538 processlist_clear(resourceview_data
->process_list
);
1539 gtk_widget_set_size_request(
1540 resourceview_data
->drawing
->drawing_area
,
1541 -1, processlist_get_height(resourceview_data
->process_list
));
1543 rectangle_pixmap (resourceview_data
->process_list
,
1544 widget
->style
->black_gc
,
1547 drawing
->alloc_width
,
1550 gtk_widget_queue_draw(drawing
->drawing_area
);
1552 if(drawing
->damage_begin
< drawing
->damage_end
)
1554 drawing_data_request(drawing
,
1555 drawing
->damage_begin
,
1557 drawing
->damage_end
-drawing
->damage_begin
,
1566 gint
continue_notify(void *hook_data
, void *call_data
)
1568 ControlFlowData
*resourceview_data
= (ControlFlowData
*) hook_data
;
1569 Drawing_t
*drawing
= resourceview_data
->drawing
;
1571 if(drawing
->damage_begin
< drawing
->damage_end
)
1573 drawing_data_request(drawing
,
1574 drawing
->damage_begin
,
1576 drawing
->damage_end
-drawing
->damage_begin
,
1584 gint
update_current_time_hook(void *hook_data
, void *call_data
)
1586 ControlFlowData
*resourceview_data
= (ControlFlowData
*)hook_data
;
1587 Drawing_t
*drawing
= resourceview_data
->drawing
;
1589 LttTime current_time
= *((LttTime
*)call_data
);
1591 TimeWindow time_window
=
1592 lttvwindow_get_time_window(resourceview_data
->tab
);
1594 LttTime time_begin
= time_window
.start_time
;
1595 LttTime width
= time_window
.time_width
;
1598 guint64 time_ll
= ltt_time_to_uint64(width
);
1599 time_ll
= time_ll
>> 1; /* divide by two */
1600 half_width
= ltt_time_from_uint64(time_ll
);
1602 LttTime time_end
= ltt_time_add(time_begin
, width
);
1604 LttvTracesetContext
* tsc
=
1605 lttvwindow_get_traceset_context(resourceview_data
->tab
);
1607 LttTime trace_start
= tsc
->time_span
.start_time
;
1608 LttTime trace_end
= tsc
->time_span
.end_time
;
1610 g_info("New current time HOOK : %lu, %lu", current_time
.tv_sec
,
1611 current_time
.tv_nsec
);
1613 /* If current time is inside time interval, just move the highlight
1616 /* Else, we have to change the time interval. We have to tell it
1617 * to the main window. */
1618 /* The time interval change will take care of placing the current
1619 * time at the center of the visible area, or nearest possible if we are
1620 * at one end of the trace. */
1623 if(ltt_time_compare(current_time
, time_begin
) < 0)
1625 TimeWindow new_time_window
;
1627 if(ltt_time_compare(current_time
,
1628 ltt_time_add(trace_start
,half_width
)) < 0)
1629 time_begin
= trace_start
;
1631 time_begin
= ltt_time_sub(current_time
,half_width
);
1633 new_time_window
.start_time
= time_begin
;
1634 new_time_window
.time_width
= width
;
1635 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1636 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1638 lttvwindow_report_time_window(resourceview_data
->tab
, new_time_window
);
1640 else if(ltt_time_compare(current_time
, time_end
) > 0)
1642 TimeWindow new_time_window
;
1644 if(ltt_time_compare(current_time
, ltt_time_sub(trace_end
, half_width
)) > 0)
1645 time_begin
= ltt_time_sub(trace_end
,width
);
1647 time_begin
= ltt_time_sub(current_time
,half_width
);
1649 new_time_window
.start_time
= time_begin
;
1650 new_time_window
.time_width
= width
;
1651 new_time_window
.time_width_double
= ltt_time_to_double(width
);
1652 new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
1654 lttvwindow_report_time_window(resourceview_data
->tab
, new_time_window
);
1657 gtk_widget_queue_draw(resourceview_data
->drawing
->drawing_area
);
1659 /* Update directly when scrolling */
1660 gdk_window_process_updates(resourceview_data
->drawing
->drawing_area
->window
,
1666 typedef struct _ClosureData
{
1667 EventsRequest
*events_request
;
1668 LttvTracesetState
*tss
;
1673 /* Draw line until end of the screen */
1675 void draw_closure(gpointer key
, gpointer value
, gpointer user_data
)
1677 ResourceUniqueNumeric
*process_info
= (ResourceUniqueNumeric
*)key
;
1678 HashedResourceData
*hashed_process_data
= (HashedResourceData
*)value
;
1679 ClosureData
*closure_data
= (ClosureData
*)user_data
;
1681 EventsRequest
*events_request
= closure_data
->events_request
;
1682 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1684 LttvTracesetState
*tss
= closure_data
->tss
;
1685 LttvTracesetContext
*tsc
= (LttvTracesetContext
*)tss
;
1687 LttTime evtime
= closure_data
->end_time
;
1689 gboolean dodraw
= TRUE
;
1691 if(hashed_process_data
->type
== RV_RESOURCE_MACHINE
)
1695 /* For the process */
1696 /* First, check if the current process is in the state computation
1697 * process list. If it is there, that means we must add it right now and
1698 * draw items from the beginning of the read for it. If it is not
1699 * present, it's a new process and it was not present : it will
1700 * be added after the state update. */
1702 g_assert(lttv_traceset_number(tsc
->ts
) > 0);
1703 #endif //EXTRA_CHECK
1704 LttvTraceContext
*tc
= tsc
->traces
[process_info
->trace_num
];
1705 LttvTraceState
*ts
= (LttvTraceState
*)tc
;
1707 /* Only draw for processes that are currently in the trace states */
1709 ProcessList
*process_list
= resourceview_data
->process_list
;
1711 /* Should be alike when background info is ready */
1712 if(resourceview_data
->background_info_waiting
==0)
1713 g_assert(ltt_time_compare(process
->creation_time
,
1714 process_info
->birth
) == 0);
1715 #endif //EXTRA_CHECK
1717 /* Now, the process is in the state hash and our own process hash.
1718 * We definitely can draw the items related to the ending state.
1721 if(unlikely(ltt_time_compare(hashed_process_data
->next_good_time
,
1724 TimeWindow time_window
=
1725 lttvwindow_get_time_window(resourceview_data
->tab
);
1728 if(ltt_time_compare(evtime
, time_window
.start_time
) == -1
1729 || ltt_time_compare(evtime
, time_window
.end_time
) == 1)
1731 #endif //EXTRA_CHECK
1732 Drawing_t
*drawing
= resourceview_data
->drawing
;
1733 guint width
= drawing
->width
;
1735 guint x
= closure_data
->x_end
;
1737 DrawContext draw_context
;
1739 /* Now create the drawing context that will be used to draw
1740 * items related to the last state. */
1741 draw_context
.drawable
= hashed_process_data
->pixmap
;
1742 draw_context
.gc
= drawing
->gc
;
1743 draw_context
.pango_layout
= drawing
->pango_layout
;
1744 draw_context
.drawinfo
.end
.x
= x
;
1746 draw_context
.drawinfo
.y
.over
= 1;
1747 draw_context
.drawinfo
.y
.middle
= (hashed_process_data
->height
/2);
1748 draw_context
.drawinfo
.y
.under
= hashed_process_data
->height
;
1750 draw_context
.drawinfo
.start
.offset
.over
= 0;
1751 draw_context
.drawinfo
.start
.offset
.middle
= 0;
1752 draw_context
.drawinfo
.start
.offset
.under
= 0;
1753 draw_context
.drawinfo
.end
.offset
.over
= 0;
1754 draw_context
.drawinfo
.end
.offset
.middle
= 0;
1755 draw_context
.drawinfo
.end
.offset
.under
= 0;
1757 /* Jump over draw if we are at the same x position */
1758 if(x
== hashed_process_data
->x
.over
)
1762 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.over
;
1764 PropertiesLine prop_line
= prepare_execmode_line(process
);
1765 draw_line((void*)&prop_line
, (void*)&draw_context
);
1767 hashed_process_data
->x
.over
= x
;
1771 if(unlikely(x
== hashed_process_data
->x
.middle
&&
1772 hashed_process_data
->x
.middle_used
)) {
1773 #if 0 /* do not mark closure : not missing information */
1774 if(hashed_process_data
->x
.middle_marked
== FALSE
) {
1775 /* Draw collision indicator */
1776 gdk_gc_set_foreground(drawing
->gc
, &drawing_colors
[COL_WHITE
]);
1777 gdk_draw_point(drawing
->pixmap
,
1781 hashed_process_data
->x
.middle_marked
= TRUE
;
1786 draw_context
.drawinfo
.start
.x
= hashed_process_data
->x
.middle
;
1789 PropertiesLine prop_line
;
1790 prop_line
.line_width
= STATE_LINE_WIDTH
;
1791 prop_line
.style
= GDK_LINE_SOLID
;
1792 prop_line
.y
= MIDDLE
;
1793 if(hashed_process_data
->type
== RV_RESOURCE_CPU
)
1794 cpu_set_line_color(&prop_line
, &ts
->cpu_states
[process_info
->id
]);
1795 else if(hashed_process_data
->type
== RV_RESOURCE_IRQ
)
1796 irq_set_line_color(&prop_line
, &ts
->irq_states
[process_info
->id
]);
1797 else if(hashed_process_data
->type
== RV_RESOURCE_SOFT_IRQ
)
1798 soft_irq_set_line_color(&prop_line
, &ts
->soft_irq_states
[process_info
->id
]);
1799 else if(hashed_process_data
->type
== RV_RESOURCE_BDEV
) {
1800 gint devcode_gint
= process_info
->id
;
1801 LttvBdevState
*bdev
= g_hash_table_lookup(ts
->bdev_states
, &devcode_gint
);
1802 // the lookup may return null; bdev_set_line_color must act appropriately
1803 bdev_set_line_color(&prop_line
, bdev
);
1806 draw_line((void*)&prop_line
, (void*)&draw_context
);
1809 /* become the last x position */
1810 if(likely(x
!= hashed_process_data
->x
.middle
)) {
1811 hashed_process_data
->x
.middle
= x
;
1812 /* but don't use the pixel */
1813 hashed_process_data
->x
.middle_used
= FALSE
;
1815 /* Calculate the next good time */
1816 convert_pixels_to_time(width
, x
+1, time_window
,
1817 &hashed_process_data
->next_good_time
);
1824 int before_chunk(void *hook_data
, void *call_data
)
1826 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1827 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1828 ControlFlowData
*cfd
= (ControlFlowData
*)events_request
->viewer_data
;
1830 /* Deactivate sort */
1831 gtk_tree_sortable_set_sort_column_id(
1832 GTK_TREE_SORTABLE(cfd
->process_list
->list_store
),
1834 GTK_SORT_ASCENDING
);
1836 drawing_chunk_begin(events_request
, tss
);
1841 int before_request(void *hook_data
, void *call_data
)
1843 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1844 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1846 drawing_data_request_begin(events_request
, tss
);
1853 * after request is necessary in addition of after chunk in order to draw
1854 * lines until the end of the screen. after chunk just draws lines until
1861 int after_request(void *hook_data
, void *call_data
)
1864 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1865 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1866 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1868 ProcessList
*process_list
= resourceview_data
->process_list
;
1869 LttTime end_time
= events_request
->end_time
;
1871 ClosureData closure_data
;
1872 closure_data
.events_request
= (EventsRequest
*)hook_data
;
1873 closure_data
.tss
= tss
;
1874 closure_data
.end_time
= end_time
;
1876 TimeWindow time_window
=
1877 lttvwindow_get_time_window(resourceview_data
->tab
);
1878 guint width
= resourceview_data
->drawing
->width
;
1879 convert_time_to_pixels(
1883 &closure_data
.x_end
);
1886 /* Draw last items */
1887 for(i
=0; i
<RV_RESOURCE_COUNT
; i
++) {
1888 g_hash_table_foreach(resourcelist_get_resource_hash_table(resourceview_data
, i
), draw_closure
,
1889 (void*)&closure_data
);
1892 /* Request expose */
1893 drawing_request_expose(events_request
, tss
, end_time
);
1902 int after_chunk(void *hook_data
, void *call_data
)
1904 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1905 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1906 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1907 LttvTracesetContext
*tsc
= (LttvTracesetContext
*)call_data
;
1908 LttvTracefileContext
*tfc
= lttv_traceset_context_get_current_tfc(tsc
);
1911 ProcessList
*process_list
= resourceview_data
->process_list
;
1913 LttvTraceset
*traceset
= tsc
->ts
;
1914 guint nb_trace
= lttv_traceset_number(traceset
);
1916 /* Only execute when called for the first trace's events request */
1917 if(!process_list
->current_hash_data
) return;
1919 for(i
= 0 ; i
< nb_trace
; i
++) {
1920 g_free(process_list
->current_hash_data
[i
]);
1922 g_free(process_list
->current_hash_data
);
1923 process_list
->current_hash_data
= NULL
;
1926 end_time
= LTT_TIME_MIN(tfc
->timestamp
, events_request
->end_time
);
1927 else /* end of traceset, or position now out of request : end */
1928 end_time
= events_request
->end_time
;
1930 ClosureData closure_data
;
1931 closure_data
.events_request
= (EventsRequest
*)hook_data
;
1932 closure_data
.tss
= tss
;
1933 closure_data
.end_time
= end_time
;
1935 TimeWindow time_window
=
1936 lttvwindow_get_time_window(resourceview_data
->tab
);
1937 guint width
= resourceview_data
->drawing
->width
;
1938 convert_time_to_pixels(
1942 &closure_data
.x_end
);
1944 /* Draw last items */
1945 for(i
=0; i
<RV_RESOURCE_COUNT
; i
++) {
1946 g_hash_table_foreach(resourcelist_get_resource_hash_table(resourceview_data
, i
), draw_closure
,
1947 (void*)&closure_data
);
1950 /* Reactivate sort */
1951 gtk_tree_sortable_set_sort_column_id(
1952 GTK_TREE_SORTABLE(resourceview_data
->process_list
->list_store
),
1953 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
,
1954 GTK_SORT_ASCENDING
);
1956 update_index_to_pixmap(resourceview_data
->process_list
);
1957 /* Request a full expose : drawing scrambled */
1958 gtk_widget_queue_draw(resourceview_data
->drawing
->drawing_area
);
1960 /* Request expose (updates damages zone also) */
1961 drawing_request_expose(events_request
, tss
, end_time
);
1966 /* after_statedump_end
1968 * @param hook_data ControlFlowData structure of the viewer.
1969 * @param call_data Event context.
1971 * This function adds items to be drawn in a queue for each process.
1974 int before_statedump_end(void *hook_data
, void *call_data
)
1978 LttvTraceHook
*th
= (LttvTraceHook
*)hook_data
;
1979 EventsRequest
*events_request
= (EventsRequest
*)th
->hook_data
;
1980 ControlFlowData
*resourceview_data
= events_request
->viewer_data
;
1982 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
1984 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
1986 LttvTraceState
*ts
= (LttvTraceState
*)tfc
->t_context
;
1988 LttvTracesetState
*tss
= (LttvTracesetState
*)tfc
->t_context
->ts_context
;
1989 ProcessList
*process_list
= resourceview_data
->process_list
;
1992 e
= ltt_tracefile_get_event(tfc
->tf
);
1994 LttvFilter
*filter
= resourceview_data
->filter
;
1995 if(filter
!= NULL
&& filter
->head
!= NULL
)
1996 if(!lttv_filter_tree_parse(filter
->head
,e
,tfc
->tf
,
1997 tfc
->t_context
->t
,tfc
,NULL
,NULL
))
2000 LttTime evtime
= ltt_event_time(e
);
2002 ClosureData closure_data
;
2003 closure_data
.events_request
= events_request
;
2004 closure_data
.tss
= tss
;
2005 closure_data
.end_time
= evtime
;
2007 TimeWindow time_window
=
2008 lttvwindow_get_time_window(resourceview_data
->tab
);
2009 guint width
= resourceview_data
->drawing
->width
;
2010 convert_time_to_pixels(
2014 &closure_data
.x_end
);
2016 /* Draw last items */
2018 for(i
=0; i
<RV_RESOURCE_COUNT
; i
++) {
2019 g_hash_table_foreach(resourcelist_get_resource_hash_table(resourceview_data
, i
), draw_closure
,
2020 (void*)&closure_data
);
2023 /* Reactivate sort */
2024 gtk_tree_sortable_set_sort_column_id(
2025 GTK_TREE_SORTABLE(resourceview_data
->process_list
->list_store
),
2026 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
,
2027 GTK_SORT_ASCENDING
);
2029 update_index_to_pixmap(resourceview_data
->process_list
);
2030 /* Request a full expose : drawing scrambled */
2031 gtk_widget_queue_draw(resourceview_data
->drawing
->drawing_area
);
2033 /* Request expose (updates damages zone also) */
2034 drawing_request_expose(events_request
, tss
, evtime
);