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
15 //#include <pango/pango.h>
17 #include <ltt/event.h>
19 #include <lttv/hook.h>
20 #include <lttv/common.h>
21 #include <lttv/state.h>
24 #include "Event_Hooks.h"
26 #include "Process_List.h"
28 #include "CFV-private.h"
31 #define MAX_PATH_LEN 256
33 //FIXME : remove this include when tests finished.
36 void test_draw_item(Drawing_t
*Drawing
,
39 PropertiesIcon properties_icon
;
40 DrawContext draw_context
;
42 DrawInfo current
, previous
;
43 ItemInfo over
, middle
, under
, modify_over
, modify_middle
, modify_under
;
47 //for(i=0; i<1024;i=i+15)
49 // for(j=0;j<768;j=j+15)
54 current
.modify_over
= &over
;
56 draw_context
.drawable
= Pixmap
;
57 draw_context
.gc
= Drawing
->Drawing_Area_V
->style
->black_gc
;
59 draw_context
.Current
= ¤t
;
60 draw_context
.Previous
= NULL
;
62 properties_icon
.icon_name
= g_new(char, MAX_PATH_LEN
);
63 strncpy(properties_icon
.icon_name
,
64 "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm",
66 properties_icon
.width
= -1;
67 properties_icon
.height
= -1;
68 properties_icon
.position
= OVER
;
69 draw_icon(&properties_icon
, &draw_context
);
70 g_free(properties_icon
.icon_name
);
77 /* NOTE : no drawing data should be sent there, since the drawing widget
78 * has not been initialized */
79 void send_test_drawing(ProcessList
*Process_List
,
82 gint x
, gint y
, // y not used here?
84 gint height
) // height won't be used here ?
87 ProcessInfo Process_Info
= {10000, 12000, 55600};
88 //ProcessInfo Process_Info = {156, 14000, 55500};
89 GtkTreeRowReference
*got_RowRef
;
90 PangoContext
*context
;
92 PangoFontDescription
*FontDesc
;// = pango_font_description_new();
96 //GdkBitmap *mask = g_new(GdkBitmap, 1);
97 //GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1);
100 GdkColor color
= { 0, 0xffff, 0x0000, 0x0000 };
102 gc
= gdk_gc_new(Pixmap
);
104 layout
= gtk_widget_create_pango_layout(Drawing
->Drawing_Area_V
,
106 context
= pango_layout_get_context(layout
);
107 FontDesc
= pango_context_get_font_description(context
);
108 Font_Size
= pango_font_description_get_size(FontDesc
);
109 pango_font_description_set_size(FontDesc
, Font_Size
-3*PANGO_SCALE
);
115 birth
.tv_sec
= 12000;
116 birth
.tv_nsec
= 55500;
117 g_info("we have : x : %u, y : %u, width : %u, height : %u", x
, y
, width
, height
);
118 processlist_get_process_pixels(Process_List
,
124 g_info("we draw : x : %u, y : %u, width : %u, height : %u", x
, y
, width
, height
);
127 y
+(height
/2), x
+ width
, y
+(height
/2),
128 Drawing
->Drawing_Area_V
->style
->black_gc
);
130 pango_layout_set_text(layout
, "Test", -1);
131 gdk_draw_layout(Pixmap
, Drawing
->Drawing_Area_V
->style
->black_gc
,
132 0, y
+height
, layout
);
134 birth
.tv_sec
= 14000;
135 birth
.tv_nsec
= 55500;
137 processlist_get_process_pixels(Process_List
,
146 y
+(height
/2), x
+ width
, y
+(height
/2),
147 Drawing
->Drawing_Area_V
->style
->black_gc
);
149 g_info("y : %u, height : %u", y
, height
);
153 birth
.tv_sec
= 12000;
154 birth
.tv_nsec
= 55700;
156 processlist_get_process_pixels(Process_List
,
162 /* Draw rectangle (background color) */
163 gdk_gc_copy(gc
, Drawing
->Drawing_Area_V
->style
->black_gc
);
164 gdk_gc_set_rgb_fg_color(gc
, &color
);
165 gdk_draw_rectangle(Pixmap
, gc
,
167 x
, y
, width
, height
);
171 y
+(height
/2), x
+ width
, y
+(height
/2),
172 Drawing
->Drawing_Area_V
->style
->black_gc
);
176 gdk_draw_arc(Pixmap
, Drawing
->Drawing_Area_V
->style
->black_gc
,
177 TRUE
, 100, y
, height
/2, height
/2, 0, 360*64);
179 g_info("y : %u, height : %u", y
, height
);
183 birth
.tv_sec
= i
*12000;
184 birth
.tv_nsec
= i
*55700;
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_critical("y : %u, height : %u", y
, height
);
202 birth
.tv_sec
= 12000;
203 birth
.tv_nsec
= 55600;
205 processlist_get_process_pixels(Process_List
,
214 y
+(height
/2), x
+ width
, y
+(height
/2),
215 Drawing
->Drawing_Area_V
->style
->black_gc
);
217 g_info("y : %u, height : %u", y
, height
);
220 /* IMPORTANT : This action uses the cpu heavily! */
221 //icon_pixmap = gdk_pixmap_create_from_xpm(Pixmap, &mask, NULL,
222 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/move_message.xpm");
223 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm");
225 // gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, mask);
227 // for(i=x;i<x+width;i=i+15)
229 // for(j=0;j<height*20;j=j+15)
233 //gdk_gc_copy(gc, Drawing->Drawing_Area_V->style->black_gc);
234 // gdk_gc_set_clip_origin(Drawing->Drawing_Area_V->style->black_gc, i, j);
235 // gdk_draw_drawable(Pixmap,
236 // Drawing->Drawing_Area_V->style->black_gc,
238 // 0, 0, i, j, -1, -1);
243 test_draw_item(Drawing
,Pixmap
);
245 //gdk_gc_set_clip_origin(Drawing->Drawing_Area_V->style->black_gc, 0, 0);
246 //gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, NULL);
248 //g_free(icon_pixmap);
256 pango_font_description_set_size(FontDesc
, Font_Size
);
257 g_object_unref(layout
);
261 void send_test_process(ProcessList
*Process_List
, Drawing_t
*Drawing
)
265 ProcessInfo Process_Info
= {10000, 12000, 55600};
266 //ProcessInfo Process_Info = {156, 14000, 55500};
267 GtkTreeRowReference
*got_RowRef
;
271 if(Process_List
->Test_Process_Sent
) return;
273 birth
.tv_sec
= 12000;
274 birth
.tv_nsec
= 55500;
276 processlist_add(Process_List
,
280 processlist_get_process_pixels(Process_List
,
285 drawing_insert_square( Drawing
, y
, height
);
287 //g_critical("y : %u, height : %u", y, height);
289 birth
.tv_sec
= 14000;
290 birth
.tv_nsec
= 55500;
292 processlist_add(Process_List
,
296 processlist_get_process_pixels(Process_List
,
301 drawing_insert_square( Drawing
, y
, height
);
303 //g_critical("y : %u, height : %u", y, height);
305 birth
.tv_sec
= 12000;
306 birth
.tv_nsec
= 55700;
308 processlist_add(Process_List
,
312 processlist_get_process_pixels(Process_List
,
317 drawing_insert_square( Drawing
, y
, height
);
319 //g_critical("y : %u, height : %u", y, height);
321 //drawing_insert_square( Drawing, height, 5);
325 birth
.tv_sec
= i
*12000;
326 birth
.tv_nsec
= i
*55700;
328 processlist_add(Process_List
,
332 processlist_get_process_pixels(Process_List
,
337 drawing_insert_square( Drawing
, y
, height
);
339 // g_critical("y : %u, height : %u", y, height);
342 //g_critical("height : %u", height);
344 birth
.tv_sec
= 12000;
345 birth
.tv_nsec
= 55600;
347 processlist_add(Process_List
,
351 processlist_get_process_pixels(Process_List
,
356 drawing_insert_square( Drawing
, y
, height
);
358 //g_critical("y : %u, height : %u", y, height);
360 processlist_add(Process_List
,
364 processlist_get_process_pixels(Process_List
,
369 drawing_insert_square( Drawing
, y
, height
);
371 //g_critical("y : %u, height : %u", y, height);
373 //drawing_insert_square( Drawing, height, 5);
374 //g_critical("height : %u", height);
377 processlist_get_process_pixels(Process_List
,
381 processlist_remove( Process_List
,
385 drawing_remove_square( Drawing
, y
, height
);
388 (GtkTreeRowReference
*)g_hash_table_lookup(
389 Process_List
->Process_Hash
,
392 g_critical("key found");
393 g_critical("position in the list : %s",
394 gtk_tree_path_to_string (
395 gtk_tree_row_reference_get_path(
396 (GtkTreeRowReference
*)got_RowRef
)
401 Process_List
->Test_Process_Sent
= TRUE
;
408 * Event Viewer's constructor hook
410 * This constructor is given as a parameter to the menuitem and toolbar button
411 * registration. It creates the list.
412 * @param pmParentWindow A pointer to the parent window.
413 * @return The widget created.
416 h_guicontrolflow(MainWindow
*pmParentWindow
, LttvTracesetSelector
* s
, char * key
)
418 g_info("h_guicontrolflow, %p, %p, %s", pmParentWindow
, s
, key
);
419 ControlFlowData
*Control_Flow_Data
= guicontrolflow() ;
421 Control_Flow_Data
->Parent_Window
= pmParentWindow
;
422 TimeWindow
*time_window
= guicontrolflow_get_time_window(Control_Flow_Data
);
423 time_window
->start_time
.tv_sec
= 0;
424 time_window
->start_time
.tv_nsec
= 0;
425 time_window
->time_width
.tv_sec
= 0;
426 time_window
->time_width
.tv_nsec
= 0;
428 LttTime
*current_time
= guicontrolflow_get_current_time(Control_Flow_Data
);
429 current_time
->tv_sec
= 0;
430 current_time
->tv_nsec
= 0;
432 //g_critical("time width1 : %u",time_window->time_width);
434 get_time_window(pmParentWindow
,
436 get_current_time(pmParentWindow
,
439 //g_critical("time width2 : %u",time_window->time_width);
440 // Unreg done in the GuiControlFlow_Destructor
441 reg_update_time_window(update_time_window_hook
, Control_Flow_Data
,
443 reg_update_current_time(update_current_time_hook
, Control_Flow_Data
,
445 return guicontrolflow_get_widget(Control_Flow_Data
) ;
449 int event_selected_hook(void *hook_data
, void *call_data
)
451 ControlFlowData
*Control_Flow_Data
= (ControlFlowData
*) hook_data
;
452 guint
*Event_Number
= (guint
*) call_data
;
454 g_critical("DEBUG : event selected by main window : %u", *Event_Number
);
456 // Control_Flow_Data->Currently_Selected_Event = *Event_Number;
457 // Control_Flow_Data->Selected_Event = TRUE ;
459 // tree_v_set_cursor(Control_Flow_Data);
463 /* Hook called before drawing. Gets the initial context at the beginning of the
464 * drawing interval and copy it to the context in Event_Request.
466 int draw_before_hook(void *hook_data
, void *call_data
)
468 EventRequest
*Event_Request
= (EventRequest
*)hook_data
;
469 //EventsContext Events_Context = (EventsContext*)call_data;
471 //Event_Request->Events_Context = Events_Context;
477 * The draw event hook is called by the reading API to have a
478 * particular event drawn on the screen.
479 * @param hook_data ControlFlowData structure of the viewer.
480 * @param call_data Event context.
482 * This function basically draw lines and icons. Two types of lines are drawn :
483 * one small (3 pixels?) representing the state of the process and the second
484 * type is thicker (10 pixels?) representing on which CPU a process is running
485 * (and this only in running state).
487 * Extremums of the lines :
488 * x_min : time of the last event context for this process kept in memory.
489 * x_max : time of the current event.
490 * y : middle of the process in the process list. The process is found in the
491 * list, therefore is it's position in pixels.
493 * The choice of lines'color is defined by the context of the last event for this
496 int draw_event_hook(void *hook_data
, void *call_data
)
498 EventRequest
*Event_Request
= (EventRequest
*)hook_data
;
499 ControlFlowData
*control_flow_data
= Event_Request
->Control_Flow_Data
;
503 //g_critical("%i", i);
504 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
506 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
513 GString
*string
= g_string_new("");;
514 gboolean field_names
= TRUE
, state
= TRUE
;
516 lttv_event_to_string(e
, tfc
->tf
, string
, TRUE
, field_names
, tfs
);
517 g_string_append_printf(string
,"\n");
520 g_string_append_printf(string
, " %s",
521 g_quark_to_string(tfs
->process
->state
->s
));
524 g_info("%s",string
->str
);
526 g_string_free(string
, TRUE
);
528 /* End of text dump */
530 /* Add process to process list (if not present) and get drawing "y" from
531 * process position */
532 guint pid
= tfs
->process
->pid
;
533 LttTime birth
= tfs
->process
->creation_time
;
534 guint y
= 0, height
= 0, pl_height
= 0;
535 HashedProcessData
*Hashed_Process_Data
= NULL
;
537 ProcessList
*process_list
=
538 guicontrolflow_get_process_list(Event_Request
->Control_Flow_Data
);
540 if(processlist_get_process_pixels(process_list
,
545 &Hashed_Process_Data
) == 1)
547 /* Process not present */
548 processlist_add(process_list
,
552 &Hashed_Process_Data
);
553 drawing_insert_square( Event_Request
->Control_Flow_Data
->Drawing
, y
, height
);
556 /* Find pixels corresponding to time of the event. If the time does
557 * not fit in the window, show a warning, not supposed to happend. */
559 guint width
= control_flow_data
->Drawing
->Drawing_Area_V
->allocation
.width
;
561 LttTime time
= ltt_event_time(e
);
563 LttTime window_end
= ltt_time_add(control_flow_data
->Time_Window
.time_width
,
564 control_flow_data
->Time_Window
.start_time
);
567 convert_time_to_pixels(
568 control_flow_data
->Time_Window
.start_time
,
576 /* Finally, draw what represents the event. */
578 GdkColor color
= { 0, 0xffff, 0x0000, 0x0000 };
579 PropertiesArc prop_arc
;
580 prop_arc
.color
= &color
;
582 prop_arc
.filled
= TRUE
;
583 prop_arc
.position
= OVER
;
584 DrawContext
*draw_context
= Hashed_Process_Data
->draw_context
;
585 draw_context
->Current
->modify_over
->x
= x
;
586 g_critical("x should be %i", x
);
587 draw_context
->Current
->modify_over
->y
= y
;
588 g_critical("y should be %i", y
);
589 draw_context
->drawable
= control_flow_data
->Drawing
->Pixmap
;
590 GtkWidget
*widget
= control_flow_data
->Drawing
->Drawing_Area_V
;
591 //draw_context->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
592 draw_context
->gc
= widget
->style
->black_gc
;
594 draw_arc((void*)&prop_arc
, (void*)draw_context
);
595 //test_draw_item(control_flow_data->Drawing, control_flow_data->Drawing->Pixmap);
600 int draw_after_hook(void *hook_data
, void *call_data
)
602 EventRequest
*Event_Request
= (EventRequest
*)hook_data
;
604 g_free(Event_Request
);
611 void update_time_window_hook(void *hook_data
, void *call_data
)
613 ControlFlowData
*Control_Flow_Data
= (ControlFlowData
*) hook_data
;
614 TimeWindow
* Time_Window
=
615 guicontrolflow_get_time_window(Control_Flow_Data
);
616 TimeWindow
*New_Time_Window
= ((TimeWindow
*)call_data
);
618 // As the time interval change will mostly be used for
619 // zoom in and out, it's not useful to keep old drawing
620 // sections, as scale will be changed.
623 *Time_Window
= *New_Time_Window
;
624 g_info("New time window HOOK : %u, %u to %u, %u",
625 Time_Window
->start_time
.tv_sec
,
626 Time_Window
->start_time
.tv_nsec
,
627 Time_Window
->time_width
.tv_sec
,
628 Time_Window
->time_width
.tv_nsec
);
630 drawing_data_request(Control_Flow_Data
->Drawing
,
631 &Control_Flow_Data
->Drawing
->Pixmap
,
633 Control_Flow_Data
->Drawing
->width
,
634 Control_Flow_Data
->Drawing
->height
);
636 drawing_refresh(Control_Flow_Data
->Drawing
,
638 Control_Flow_Data
->Drawing
->width
,
639 Control_Flow_Data
->Drawing
->height
);
643 void update_current_time_hook(void *hook_data
, void *call_data
)
645 ControlFlowData
*Control_Flow_Data
= (ControlFlowData
*) hook_data
;
646 LttTime
* Current_Time
=
647 guicontrolflow_get_current_time(Control_Flow_Data
);
648 *Current_Time
= *((LttTime
*)call_data
);
649 g_info("New Current time HOOK : %u, %u", Current_Time
->tv_sec
,
650 Current_Time
->tv_nsec
);
652 /* If current time is inside time interval, just move the highlight
655 /* Else, we have to change the time interval. We have to tell it
656 * to the main window. */
657 /* The time interval change will take care of placing the current
658 * time at the center of the visible area */