1 /*****************************************************************************
2 * Hooks to be called by the main window *
3 *****************************************************************************/
6 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
7 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
9 //#define PANGO_ENABLE_BACKEND
14 //#include <pango/pango.h>
16 #include <lttv/hook.h>
17 #include <lttv/common.h>
19 #include "Event_Hooks.h"
21 #include "Process_List.h"
23 #include "CFV-private.h"
25 #define MAX_PATH_LEN 256
27 //FIXME : remove this include when tests finished.
28 #include "Draw_Item.h"
32 GdkDrawable
*drawable
;
45 ItemInfo
*modify_over
;
46 ItemInfo
*modify_middle
;
47 ItemInfo
*modify_under
;
50 /* LttvExecutionState is accessible through the LttvTracefileState. Is has
51 * a pointer to the LttvProcessState which points to the top of stack
52 * execution state : LttvExecutionState *state.
54 * LttvExecutionState contains (useful here):
55 * LttvExecutionMode t,
56 * LttvExecutionSubmode n,
60 * LttvTraceState will be used in the case we need the string of the
61 * different processes, eventtype_names, syscall_names, trap_names, irq_names.
63 * LttvTracefileState also gives the cpu_name and, as it herits from
64 * LttvTracefileContext, it gives the LttEvent structure, which is needed
65 * to get facility name and event name.
70 LttvTracefileState
*tfs
;
75 struct _PropertiesIcon
{
84 void test_draw_item(Drawing_t
*Drawing
,
87 PropertiesIcon properties_icon
;
88 DrawContext draw_context
;
90 DrawInfo current
, previous
;
91 ItemInfo over
, middle
, under
, modify_over
, modify_middle
, modify_under
;
95 for(i
=0; i
<1024;i
=i
+15)
104 current
.modify_over
= &over
;
106 draw_context
.drawable
= Pixmap
;
107 draw_context
.gc
= Drawing
->Drawing_Area_V
->style
->black_gc
;
109 draw_context
.Current
= ¤t
;
110 draw_context
.Previous
= NULL
;
112 properties_icon
.icon_name
= g_new(char, MAX_PATH_LEN
);
113 strncpy(properties_icon
.icon_name
,
114 "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm",
116 properties_icon
.width
= -1;
117 properties_icon
.height
= -1;
118 properties_icon
.position
= OVER
;
120 draw_icon(&properties_icon
, &draw_context
);
126 /* NOTE : no drawing data should be sent there, since the drawing widget
127 * has not been initialized */
128 void send_test_drawing(ProcessList
*Process_List
,
131 gint x
, gint y
, // y not used here?
133 gint height
) // height won't be used here ?
136 ProcessInfo Process_Info
= {10000, 12000, 55600};
137 //ProcessInfo Process_Info = {156, 14000, 55500};
138 GtkTreeRowReference
*got_RowRef
;
139 PangoContext
*context
;
141 PangoFontDescription
*FontDesc
;// = pango_font_description_new();
145 GdkBitmap
*mask
= g_new(GdkBitmap
, 1);
146 GdkPixmap
*icon_pixmap
= g_new(GdkPixmap
, 1);
147 GdkGC
* gc
= gdk_gc_new(Pixmap
);
150 GdkColor color
= { 0, 0xffff, 0x0000, 0x0000 };
153 layout
= gtk_widget_create_pango_layout(Drawing
->Drawing_Area_V
,
155 context
= pango_layout_get_context(layout
);
156 FontDesc
= pango_context_get_font_description(context
);
157 Font_Size
= pango_font_description_get_size(FontDesc
);
158 pango_font_description_set_size(FontDesc
, Font_Size
-3*PANGO_SCALE
);
164 birth
.tv_sec
= 12000;
165 birth
.tv_nsec
= 55500;
166 g_info("we have : x : %u, y : %u, width : %u, height : %u", x
, y
, width
, height
);
167 processlist_get_process_pixels(Process_List
,
173 g_info("we draw : x : %u, y : %u, width : %u, height : %u", x
, y
, width
, height
);
176 y
+(height
/2), x
+ width
, y
+(height
/2),
177 Drawing
->Drawing_Area_V
->style
->black_gc
);
179 pango_layout_set_text(layout
, "Test", -1);
180 gdk_draw_layout(Pixmap
, Drawing
->Drawing_Area_V
->style
->black_gc
,
181 0, y
+height
, layout
);
183 birth
.tv_sec
= 14000;
184 birth
.tv_nsec
= 55500;
186 processlist_get_process_pixels(Process_List
,
195 y
+(height
/2), x
+ width
, y
+(height
/2),
196 Drawing
->Drawing_Area_V
->style
->black_gc
);
198 g_info("y : %u, height : %u", y
, height
);
202 birth
.tv_sec
= 12000;
203 birth
.tv_nsec
= 55700;
205 processlist_get_process_pixels(Process_List
,
211 /* Draw rectangle (background color) */
212 gdk_gc_copy(gc
, Drawing
->Drawing_Area_V
->style
->black_gc
);
213 gdk_gc_set_rgb_fg_color(gc
, &color
);
214 gdk_draw_rectangle(Pixmap
, gc
,
216 x
, y
, width
, height
);
220 y
+(height
/2), x
+ width
, y
+(height
/2),
221 Drawing
->Drawing_Area_V
->style
->black_gc
);
225 gdk_draw_arc(Pixmap
, Drawing
->Drawing_Area_V
->style
->black_gc
,
226 TRUE
, 100, y
, height
/2, height
/2, 0, 360*64);
228 g_info("y : %u, height : %u", y
, height
);
232 birth
.tv_sec
= i
*12000;
233 birth
.tv_nsec
= i
*55700;
235 processlist_get_process_pixels(Process_List
,
244 y
+(height
/2), x
+ width
, y
+(height
/2),
245 Drawing
->Drawing_Area_V
->style
->black_gc
);
247 g_critical("y : %u, height : %u", y
, height
);
251 birth
.tv_sec
= 12000;
252 birth
.tv_nsec
= 55600;
254 processlist_get_process_pixels(Process_List
,
263 y
+(height
/2), x
+ width
, y
+(height
/2),
264 Drawing
->Drawing_Area_V
->style
->black_gc
);
266 g_info("y : %u, height : %u", y
, height
);
269 /* IMPORTANT : This action uses the cpu heavily! */
270 //icon_pixmap = gdk_pixmap_create_from_xpm(Pixmap, &mask, NULL,
271 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/move_message.xpm");
272 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm");
274 // gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, mask);
276 // for(i=x;i<x+width;i=i+15)
278 // for(j=0;j<height*20;j=j+15)
282 //gdk_gc_copy(gc, Drawing->Drawing_Area_V->style->black_gc);
283 // gdk_gc_set_clip_origin(Drawing->Drawing_Area_V->style->black_gc, i, j);
284 // gdk_draw_drawable(Pixmap,
285 // Drawing->Drawing_Area_V->style->black_gc,
287 // 0, 0, i, j, -1, -1);
292 test_draw_item(Drawing
,Pixmap
);
294 //gdk_gc_set_clip_origin(Drawing->Drawing_Area_V->style->black_gc, 0, 0);
295 //gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, NULL);
297 //g_free(icon_pixmap);
305 pango_font_description_set_size(FontDesc
, Font_Size
);
311 void send_test_process(ProcessList
*Process_List
, Drawing_t
*Drawing
)
315 ProcessInfo Process_Info
= {10000, 12000, 55600};
316 //ProcessInfo Process_Info = {156, 14000, 55500};
317 GtkTreeRowReference
*got_RowRef
;
321 if(Process_List
->Test_Process_Sent
) return;
323 birth
.tv_sec
= 12000;
324 birth
.tv_nsec
= 55500;
326 processlist_add(Process_List
,
330 processlist_get_process_pixels(Process_List
,
335 drawing_insert_square( Drawing
, y
, height
);
337 //g_critical("y : %u, height : %u", y, height);
339 birth
.tv_sec
= 14000;
340 birth
.tv_nsec
= 55500;
342 processlist_add(Process_List
,
346 processlist_get_process_pixels(Process_List
,
351 drawing_insert_square( Drawing
, y
, height
);
353 //g_critical("y : %u, height : %u", y, height);
355 birth
.tv_sec
= 12000;
356 birth
.tv_nsec
= 55700;
358 processlist_add(Process_List
,
362 processlist_get_process_pixels(Process_List
,
367 drawing_insert_square( Drawing
, y
, height
);
369 //g_critical("y : %u, height : %u", y, height);
371 //drawing_insert_square( Drawing, height, 5);
375 birth
.tv_sec
= i
*12000;
376 birth
.tv_nsec
= i
*55700;
378 processlist_add(Process_List
,
382 processlist_get_process_pixels(Process_List
,
387 drawing_insert_square( Drawing
, y
, height
);
389 // g_critical("y : %u, height : %u", y, height);
392 //g_critical("height : %u", height);
394 birth
.tv_sec
= 12000;
395 birth
.tv_nsec
= 55600;
397 processlist_add(Process_List
,
401 processlist_get_process_pixels(Process_List
,
406 drawing_insert_square( Drawing
, y
, height
);
408 //g_critical("y : %u, height : %u", y, height);
410 processlist_add(Process_List
,
414 processlist_get_process_pixels(Process_List
,
419 drawing_insert_square( Drawing
, y
, height
);
421 //g_critical("y : %u, height : %u", y, height);
423 //drawing_insert_square( Drawing, height, 5);
424 //g_critical("height : %u", height);
427 processlist_get_process_pixels(Process_List
,
431 processlist_remove( Process_List
,
435 drawing_remove_square( Drawing
, y
, height
);
438 (GtkTreeRowReference
*)g_hash_table_lookup(
439 Process_List
->Process_Hash
,
442 g_critical("key found");
443 g_critical("position in the list : %s",
444 gtk_tree_path_to_string (
445 gtk_tree_row_reference_get_path(
446 (GtkTreeRowReference
*)got_RowRef
)
451 Process_List
->Test_Process_Sent
= TRUE
;
458 * Event Viewer's constructor hook
460 * This constructor is given as a parameter to the menuitem and toolbar button
461 * registration. It creates the list.
462 * @param pmParentWindow A pointer to the parent window.
463 * @return The widget created.
466 h_guicontrolflow(MainWindow
*pmParentWindow
, LttvTracesetSelector
* s
, char * key
)
468 g_info("h_guicontrolflow, %p, %p, %s", pmParentWindow
, s
, key
);
469 ControlFlowData
*Control_Flow_Data
= guicontrolflow() ;
471 Control_Flow_Data
->Parent_Window
= pmParentWindow
;
473 get_time_window(pmParentWindow
,
474 guicontrolflow_get_time_window(Control_Flow_Data
));
475 get_current_time(pmParentWindow
,
476 guicontrolflow_get_current_time(Control_Flow_Data
));
478 // Unreg done in the GuiControlFlow_Destructor
479 reg_update_time_window(update_time_window_hook
, Control_Flow_Data
,
481 reg_update_current_time(update_current_time_hook
, Control_Flow_Data
,
483 return guicontrolflow_get_widget(Control_Flow_Data
) ;
487 int event_selected_hook(void *hook_data
, void *call_data
)
489 ControlFlowData
*Control_Flow_Data
= (ControlFlowData
*) hook_data
;
490 guint
*Event_Number
= (guint
*) call_data
;
492 g_critical("DEBUG : event selected by main window : %u", *Event_Number
);
494 // Control_Flow_Data->Currently_Selected_Event = *Event_Number;
495 // Control_Flow_Data->Selected_Event = TRUE ;
497 // tree_v_set_cursor(Control_Flow_Data);
502 /* Hook called before drawing. Gets the initial context at the beginning of the
503 * drawing interval and copy it to the context in Event_Request.
505 int draw_before_hook(void *hook_data
, void *call_data
)
507 EventRequest
*Event_Request
= (EventRequest
*)hook_data
;
508 EventsContext Events_Context
= (EventsContext
*)call_data
;
510 Event_Request
->Events_Context
= Events_Context
;
516 * The draw event hook is called by the reading API to have a
517 * particular event drawn on the screen.
518 * @param hook_data ControlFlowData structure of the viewer.
519 * @param call_data Event context.
521 * This function basically draw lines and icons. Two types of lines are drawn :
522 * one small (3 pixels?) representing the state of the process and the second
523 * type is thicker (10 pixels?) representing on which CPU a process is running
524 * (and this only in running state).
526 * Extremums of the lines :
527 * x_min : time of the last event context for this process kept in memory.
528 * x_max : time of the current event.
529 * y : middle of the process in the process list. The process is found in the
530 * list, therefore is it's position in pixels.
532 * The choice of lines'color is defined by the context of the last event for this
535 int draw_event_hook(void *hook_data
, void *call_data
)
537 EventRequest
*Event_Request
= (EventRequest
*)hook_data
;
543 int draw_after_hook(void *hook_data
, void *call_data
)
545 EventRequest
*Event_Request
= (EventRequest
*)hook_data
;
547 g_free(Event_Request
);
555 void update_time_window_hook(void *hook_data
, void *call_data
)
557 ControlFlowData
*Control_Flow_Data
= (ControlFlowData
*) hook_data
;
558 TimeWindow
* Time_Window
=
559 guicontrolflow_get_time_window(Control_Flow_Data
);
560 TimeWindow
*New_Time_Window
= ((TimeWindow
*)call_data
);
562 // As the time interval change will mostly be used for
563 // zoom in and out, it's not useful to keep old drawing
564 // sections, as scale will be changed.
567 *Time_Window
= *New_Time_Window
;
568 g_info("New time window HOOK : %u, %u to %u, %u",
569 Time_Window
->start_time
.tv_sec
,
570 Time_Window
->start_time
.tv_nsec
,
571 Time_Window
->time_width
.tv_sec
,
572 Time_Window
->time_width
.tv_nsec
);
574 drawing_data_request(Control_Flow_Data
->Drawing
,
575 &Control_Flow_Data
->Drawing
->Pixmap
,
577 Control_Flow_Data
->Drawing
->width
,
578 Control_Flow_Data
->Drawing
->height
);
580 drawing_refresh(Control_Flow_Data
->Drawing
,
582 Control_Flow_Data
->Drawing
->width
,
583 Control_Flow_Data
->Drawing
->height
);
587 void update_current_time_hook(void *hook_data
, void *call_data
)
589 ControlFlowData
*Control_Flow_Data
= (ControlFlowData
*) hook_data
;
590 LttTime
* Current_Time
=
591 guicontrolflow_get_current_time(Control_Flow_Data
);
592 *Current_Time
= *((LttTime
*)call_data
);
593 g_info("New Current time HOOK : %u, %u", Current_Time
->tv_sec
,
594 Current_Time
->tv_nsec
);
596 /* If current time is inside time interval, just move the highlight
599 /* Else, we have to change the time interval. We have to tell it
600 * to the main window. */
601 /* The time interval change will take care of placing the current
602 * time at the center of the visible area */