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>
20 #include <lttv/hook.h>
21 #include <lttv/common.h>
22 #include <lttv/state.h>
25 #include "Event_Hooks.h"
27 #include "Process_List.h"
29 #include "CFV-private.h"
32 #define MAX_PATH_LEN 256
34 //FIXME : remove this include when tests finished.
37 void test_draw_item(Drawing_t
*Drawing
,
40 PropertiesIcon properties_icon
;
41 DrawContext draw_context
;
43 DrawInfo current
, previous
;
44 ItemInfo over
, middle
, under
, modify_over
, modify_middle
, modify_under
;
48 //for(i=0; i<1024;i=i+15)
50 // for(j=0;j<768;j=j+15)
55 current
.modify_over
= &over
;
57 draw_context
.drawable
= Pixmap
;
58 draw_context
.gc
= Drawing
->Drawing_Area_V
->style
->black_gc
;
60 draw_context
.Current
= ¤t
;
61 draw_context
.Previous
= NULL
;
63 properties_icon
.icon_name
= g_new(char, MAX_PATH_LEN
);
64 strncpy(properties_icon
.icon_name
,
65 "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm",
67 properties_icon
.width
= -1;
68 properties_icon
.height
= -1;
69 properties_icon
.position
= OVER
;
70 draw_icon(&properties_icon
, &draw_context
);
71 g_free(properties_icon
.icon_name
);
78 /* NOTE : no drawing data should be sent there, since the drawing widget
79 * has not been initialized */
80 void send_test_drawing(ProcessList
*Process_List
,
83 gint x
, gint y
, // y not used here?
85 gint height
) // height won't be used here ?
88 ProcessInfo Process_Info
= {10000, 12000, 55600};
89 //ProcessInfo Process_Info = {156, 14000, 55500};
90 GtkTreeRowReference
*got_RowRef
;
91 PangoContext
*context
;
93 PangoFontDescription
*FontDesc
;// = pango_font_description_new();
97 //GdkBitmap *mask = g_new(GdkBitmap, 1);
98 //GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1);
101 GdkColor color
= { 0, 0xffff, 0x0000, 0x0000 };
103 gc
= gdk_gc_new(Pixmap
);
105 layout
= gtk_widget_create_pango_layout(Drawing
->Drawing_Area_V
,
107 context
= pango_layout_get_context(layout
);
108 FontDesc
= pango_context_get_font_description(context
);
109 Font_Size
= pango_font_description_get_size(FontDesc
);
110 pango_font_description_set_size(FontDesc
, Font_Size
-3*PANGO_SCALE
);
116 birth
.tv_sec
= 12000;
117 birth
.tv_nsec
= 55500;
118 g_info("we have : x : %u, y : %u, width : %u, height : %u", x
, y
, width
, height
);
119 processlist_get_process_pixels(Process_List
,
125 g_info("we draw : x : %u, y : %u, width : %u, height : %u", x
, y
, width
, height
);
128 y
+(height
/2), x
+ width
, y
+(height
/2),
129 Drawing
->Drawing_Area_V
->style
->black_gc
);
131 pango_layout_set_text(layout
, "Test", -1);
132 gdk_draw_layout(Pixmap
, Drawing
->Drawing_Area_V
->style
->black_gc
,
133 0, y
+height
, layout
);
135 birth
.tv_sec
= 14000;
136 birth
.tv_nsec
= 55500;
138 processlist_get_process_pixels(Process_List
,
147 y
+(height
/2), x
+ width
, y
+(height
/2),
148 Drawing
->Drawing_Area_V
->style
->black_gc
);
150 g_info("y : %u, height : %u", y
, height
);
154 birth
.tv_sec
= 12000;
155 birth
.tv_nsec
= 55700;
157 processlist_get_process_pixels(Process_List
,
163 /* Draw rectangle (background color) */
164 gdk_gc_copy(gc
, Drawing
->Drawing_Area_V
->style
->black_gc
);
165 gdk_gc_set_rgb_fg_color(gc
, &color
);
166 gdk_draw_rectangle(Pixmap
, gc
,
168 x
, y
, width
, height
);
172 y
+(height
/2), x
+ width
, y
+(height
/2),
173 Drawing
->Drawing_Area_V
->style
->black_gc
);
177 gdk_draw_arc(Pixmap
, Drawing
->Drawing_Area_V
->style
->black_gc
,
178 TRUE
, 100, y
, height
/2, height
/2, 0, 360*64);
180 g_info("y : %u, height : %u", y
, height
);
184 birth
.tv_sec
= i
*12000;
185 birth
.tv_nsec
= i
*55700;
187 processlist_get_process_pixels(Process_List
,
196 y
+(height
/2), x
+ width
, y
+(height
/2),
197 Drawing
->Drawing_Area_V
->style
->black_gc
);
199 g_critical("y : %u, height : %u", y
, height
);
203 birth
.tv_sec
= 12000;
204 birth
.tv_nsec
= 55600;
206 processlist_get_process_pixels(Process_List
,
215 y
+(height
/2), x
+ width
, y
+(height
/2),
216 Drawing
->Drawing_Area_V
->style
->black_gc
);
218 g_info("y : %u, height : %u", y
, height
);
221 /* IMPORTANT : This action uses the cpu heavily! */
222 //icon_pixmap = gdk_pixmap_create_from_xpm(Pixmap, &mask, NULL,
223 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/move_message.xpm");
224 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm");
226 // gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, mask);
228 // for(i=x;i<x+width;i=i+15)
230 // for(j=0;j<height*20;j=j+15)
234 //gdk_gc_copy(gc, Drawing->Drawing_Area_V->style->black_gc);
235 // gdk_gc_set_clip_origin(Drawing->Drawing_Area_V->style->black_gc, i, j);
236 // gdk_draw_drawable(Pixmap,
237 // Drawing->Drawing_Area_V->style->black_gc,
239 // 0, 0, i, j, -1, -1);
244 test_draw_item(Drawing
,Pixmap
);
246 //gdk_gc_set_clip_origin(Drawing->Drawing_Area_V->style->black_gc, 0, 0);
247 //gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, NULL);
249 //g_free(icon_pixmap);
257 pango_font_description_set_size(FontDesc
, Font_Size
);
258 g_object_unref(layout
);
262 void send_test_process(ProcessList
*Process_List
, Drawing_t
*Drawing
)
266 ProcessInfo Process_Info
= {10000, 12000, 55600};
267 //ProcessInfo Process_Info = {156, 14000, 55500};
268 GtkTreeRowReference
*got_RowRef
;
272 if(Process_List
->Test_Process_Sent
) return;
274 birth
.tv_sec
= 12000;
275 birth
.tv_nsec
= 55500;
277 processlist_add(Process_List
,
281 processlist_get_process_pixels(Process_List
,
286 drawing_insert_square( Drawing
, y
, height
);
288 //g_critical("y : %u, height : %u", y, height);
290 birth
.tv_sec
= 14000;
291 birth
.tv_nsec
= 55500;
293 processlist_add(Process_List
,
297 processlist_get_process_pixels(Process_List
,
302 drawing_insert_square( Drawing
, y
, height
);
304 //g_critical("y : %u, height : %u", y, height);
306 birth
.tv_sec
= 12000;
307 birth
.tv_nsec
= 55700;
309 processlist_add(Process_List
,
313 processlist_get_process_pixels(Process_List
,
318 drawing_insert_square( Drawing
, y
, height
);
320 //g_critical("y : %u, height : %u", y, height);
322 //drawing_insert_square( Drawing, height, 5);
326 birth
.tv_sec
= i
*12000;
327 birth
.tv_nsec
= i
*55700;
329 processlist_add(Process_List
,
333 processlist_get_process_pixels(Process_List
,
338 drawing_insert_square( Drawing
, y
, height
);
340 // g_critical("y : %u, height : %u", y, height);
343 //g_critical("height : %u", height);
345 birth
.tv_sec
= 12000;
346 birth
.tv_nsec
= 55600;
348 processlist_add(Process_List
,
352 processlist_get_process_pixels(Process_List
,
357 drawing_insert_square( Drawing
, y
, height
);
359 //g_critical("y : %u, height : %u", y, height);
361 processlist_add(Process_List
,
365 processlist_get_process_pixels(Process_List
,
370 drawing_insert_square( Drawing
, y
, height
);
372 //g_critical("y : %u, height : %u", y, height);
374 //drawing_insert_square( Drawing, height, 5);
375 //g_critical("height : %u", height);
378 processlist_get_process_pixels(Process_List
,
382 processlist_remove( Process_List
,
386 drawing_remove_square( Drawing
, y
, height
);
389 (GtkTreeRowReference
*)g_hash_table_lookup(
390 Process_List
->Process_Hash
,
393 g_critical("key found");
394 g_critical("position in the list : %s",
395 gtk_tree_path_to_string (
396 gtk_tree_row_reference_get_path(
397 (GtkTreeRowReference
*)got_RowRef
)
402 Process_List
->Test_Process_Sent
= TRUE
;
409 * Event Viewer's constructor hook
411 * This constructor is given as a parameter to the menuitem and toolbar button
412 * registration. It creates the list.
413 * @param pmParentWindow A pointer to the parent window.
414 * @return The widget created.
417 h_guicontrolflow(MainWindow
*pmParentWindow
, LttvTracesetSelector
* s
, char * key
)
419 g_info("h_guicontrolflow, %p, %p, %s", pmParentWindow
, s
, key
);
420 ControlFlowData
*Control_Flow_Data
= guicontrolflow() ;
422 Control_Flow_Data
->Parent_Window
= pmParentWindow
;
423 TimeWindow
*time_window
= guicontrolflow_get_time_window(Control_Flow_Data
);
424 time_window
->start_time
.tv_sec
= 0;
425 time_window
->start_time
.tv_nsec
= 0;
426 time_window
->time_width
.tv_sec
= 0;
427 time_window
->time_width
.tv_nsec
= 0;
429 LttTime
*current_time
= guicontrolflow_get_current_time(Control_Flow_Data
);
430 current_time
->tv_sec
= 0;
431 current_time
->tv_nsec
= 0;
433 //g_critical("time width1 : %u",time_window->time_width);
435 get_time_window(pmParentWindow
,
437 get_current_time(pmParentWindow
,
440 //g_critical("time width2 : %u",time_window->time_width);
441 // Unreg done in the GuiControlFlow_Destructor
442 reg_update_time_window(update_time_window_hook
, Control_Flow_Data
,
444 reg_update_current_time(update_current_time_hook
, Control_Flow_Data
,
446 return guicontrolflow_get_widget(Control_Flow_Data
) ;
450 int event_selected_hook(void *hook_data
, void *call_data
)
452 ControlFlowData
*Control_Flow_Data
= (ControlFlowData
*) hook_data
;
453 guint
*Event_Number
= (guint
*) call_data
;
455 g_critical("DEBUG : event selected by main window : %u", *Event_Number
);
457 // Control_Flow_Data->Currently_Selected_Event = *Event_Number;
458 // Control_Flow_Data->Selected_Event = TRUE ;
460 // tree_v_set_cursor(Control_Flow_Data);
464 /* Hook called before drawing. Gets the initial context at the beginning of the
465 * drawing interval and copy it to the context in Event_Request.
467 int draw_before_hook(void *hook_data
, void *call_data
)
469 EventRequest
*Event_Request
= (EventRequest
*)hook_data
;
470 //EventsContext Events_Context = (EventsContext*)call_data;
472 //Event_Request->Events_Context = Events_Context;
478 * The draw event hook is called by the reading API to have a
479 * particular event drawn on the screen.
480 * @param hook_data ControlFlowData structure of the viewer.
481 * @param call_data Event context.
483 * This function basically draw lines and icons. Two types of lines are drawn :
484 * one small (3 pixels?) representing the state of the process and the second
485 * type is thicker (10 pixels?) representing on which CPU a process is running
486 * (and this only in running state).
488 * Extremums of the lines :
489 * x_min : time of the last event context for this process kept in memory.
490 * x_max : time of the current event.
491 * y : middle of the process in the process list. The process is found in the
492 * list, therefore is it's position in pixels.
494 * The choice of lines'color is defined by the context of the last event for this
497 int draw_event_hook(void *hook_data
, void *call_data
)
499 EventRequest
*Event_Request
= (EventRequest
*)hook_data
;
500 ControlFlowData
*control_flow_data
= Event_Request
->Control_Flow_Data
;
504 //g_critical("%i", i);
505 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
507 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
514 GString
*string
= g_string_new("");;
515 gboolean field_names
= TRUE
, state
= TRUE
;
517 lttv_event_to_string(e
, tfc
->tf
, string
, TRUE
, field_names
, tfs
);
518 g_string_append_printf(string
,"\n");
521 g_string_append_printf(string
, " %s",
522 g_quark_to_string(tfs
->process
->state
->s
));
525 g_info("%s",string
->str
);
527 g_string_free(string
, TRUE
);
529 /* End of text dump */
531 /* Add process to process list (if not present) and get drawing "y" from
532 * process position */
533 guint pid
= tfs
->process
->pid
;
534 LttTime birth
= tfs
->process
->creation_time
;
535 guint y
= 0, height
= 0, pl_height
= 0;
536 HashedProcessData
*Hashed_Process_Data
= NULL
;
538 ProcessList
*process_list
=
539 guicontrolflow_get_process_list(Event_Request
->Control_Flow_Data
);
541 if(processlist_get_process_pixels(process_list
,
546 &Hashed_Process_Data
) == 1)
548 /* Process not present */
549 processlist_add(process_list
,
553 &Hashed_Process_Data
);
554 drawing_insert_square( Event_Request
->Control_Flow_Data
->Drawing
, y
, height
);
557 /* Find pixels corresponding to time of the event. If the time does
558 * not fit in the window, show a warning, not supposed to happend. */
560 guint width
= control_flow_data
->Drawing
->Drawing_Area_V
->allocation
.width
;
562 LttTime time
= ltt_event_time(e
);
564 LttTime window_end
= ltt_time_add(control_flow_data
->Time_Window
.time_width
,
565 control_flow_data
->Time_Window
.start_time
);
568 convert_time_to_pixels(
569 control_flow_data
->Time_Window
.start_time
,
577 /* Finally, draw what represents the event. */
579 GdkColor color
= { 0, 0xffff, 0x0000, 0x0000 };
580 PropertiesArc prop_arc
;
581 prop_arc
.color
= &color
;
583 prop_arc
.filled
= TRUE
;
584 prop_arc
.position
= OVER
;
585 DrawContext
*draw_context
= Hashed_Process_Data
->draw_context
;
586 draw_context
->Current
->modify_over
->x
= x
;
587 draw_context
->Current
->modify_over
->y
= y
;
588 draw_context
->drawable
= control_flow_data
->Drawing
->Pixmap
;
589 GtkWidget
*widget
= control_flow_data
->Drawing
->Drawing_Area_V
;
590 //draw_context->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
591 draw_context
->gc
= widget
->style
->black_gc
;
593 draw_arc((void*)&prop_arc
, (void*)draw_context
);
594 //test_draw_item(control_flow_data->Drawing, control_flow_data->Drawing->Pixmap);
599 int draw_after_hook(void *hook_data
, void *call_data
)
601 EventRequest
*Event_Request
= (EventRequest
*)hook_data
;
603 g_free(Event_Request
);
610 void update_time_window_hook(void *hook_data
, void *call_data
)
612 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
613 TimeWindow
*Old_Time_Window
=
614 guicontrolflow_get_time_window(control_flow_data
);
615 TimeWindow
*New_Time_Window
= ((TimeWindow
*)call_data
);
617 /* Two cases : zoom in/out or scrolling */
619 /* In order to make sure we can reuse the old drawing, the scale must
620 * be the same and the new time interval being partly located in the
621 * currently shown time interval. (reuse is only for scrolling)
624 g_info("Old time window HOOK : %u, %u to %u, %u",
625 Old_Time_Window
->start_time
.tv_sec
,
626 Old_Time_Window
->start_time
.tv_nsec
,
627 Old_Time_Window
->time_width
.tv_sec
,
628 Old_Time_Window
->time_width
.tv_nsec
);
630 g_info("New time window HOOK : %u, %u to %u, %u",
631 New_Time_Window
->start_time
.tv_sec
,
632 New_Time_Window
->start_time
.tv_nsec
,
633 New_Time_Window
->time_width
.tv_sec
,
634 New_Time_Window
->time_width
.tv_nsec
);
636 if( New_Time_Window
->time_width
.tv_sec
== Old_Time_Window
->time_width
.tv_sec
637 && New_Time_Window
->time_width
.tv_nsec
== Old_Time_Window
->time_width
.tv_nsec
)
639 /* Same scale (scrolling) */
641 LttTime
*ns
= &New_Time_Window
->start_time
;
642 LttTime
*os
= &Old_Time_Window
->start_time
;
643 LttTime old_end
= ltt_time_add(Old_Time_Window
->start_time
,
644 Old_Time_Window
->time_width
);
645 LttTime new_end
= ltt_time_add(New_Time_Window
->start_time
,
646 New_Time_Window
->time_width
);
648 //if(ns<os+w && os+w<ns+w)
649 //if(ns<old_end && os<ns)
650 if(ltt_time_compare(*ns
, old_end
) == -1
651 && ltt_time_compare(*os
, *ns
) == -1)
653 g_info("scrolling near right");
654 /* Scroll right, keep right part of the screen */
656 guint width
= control_flow_data
->Drawing
->Drawing_Area_V
->allocation
.width
;
657 convert_time_to_pixels(
664 /* Copy old data to new location */
665 gdk_draw_drawable (control_flow_data
->Drawing
->Pixmap
,
666 control_flow_data
->Drawing
->Drawing_Area_V
->style
->white_gc
,
667 control_flow_data
->Drawing
->Pixmap
,
672 /* Get new data for the rest. */
673 drawing_data_request(control_flow_data
->Drawing
,
674 &control_flow_data
->Drawing
->Pixmap
,
676 control_flow_data
->Drawing
->width
- x
,
677 control_flow_data
->Drawing
->height
);
679 drawing_refresh(control_flow_data
->Drawing
,
681 control_flow_data
->Drawing
->width
,
682 control_flow_data
->Drawing
->height
);
687 //if(ns<os && os<ns+w)
688 //if(ns<os && os<new_end)
689 if(ltt_time_compare(*ns
,*os
) == -1
690 && ltt_time_compare(*os
,new_end
) == -1)
692 g_info("scrolling near left");
693 /* Scroll left, keep left part of the screen */
695 guint width
= control_flow_data
->Drawing
->Drawing_Area_V
->allocation
.width
;
696 convert_time_to_pixels(
703 /* Copy old data to new location */
704 gdk_draw_drawable (control_flow_data
->Drawing
->Pixmap
,
705 control_flow_data
->Drawing
->Drawing_Area_V
->style
->white_gc
,
706 control_flow_data
->Drawing
->Pixmap
,
711 /* Get new data for the rest. */
712 drawing_data_request(control_flow_data
->Drawing
,
713 &control_flow_data
->Drawing
->Pixmap
,
716 control_flow_data
->Drawing
->height
);
718 drawing_refresh(control_flow_data
->Drawing
,
720 control_flow_data
->Drawing
->width
,
721 control_flow_data
->Drawing
->height
);
724 g_info("scrolling far");
725 /* Cannot reuse any part of the screen : far jump */
726 *Old_Time_Window
= *New_Time_Window
;
728 drawing_data_request(control_flow_data
->Drawing
,
729 &control_flow_data
->Drawing
->Pixmap
,
731 control_flow_data
->Drawing
->width
,
732 control_flow_data
->Drawing
->height
);
734 drawing_refresh(control_flow_data
->Drawing
,
736 control_flow_data
->Drawing
->width
,
737 control_flow_data
->Drawing
->height
);
741 /* Different scale (zoom) */
744 *Old_Time_Window
= *New_Time_Window
;
746 drawing_data_request(control_flow_data
->Drawing
,
747 &control_flow_data
->Drawing
->Pixmap
,
749 control_flow_data
->Drawing
->width
,
750 control_flow_data
->Drawing
->height
);
752 drawing_refresh(control_flow_data
->Drawing
,
754 control_flow_data
->Drawing
->width
,
755 control_flow_data
->Drawing
->height
);
761 void update_current_time_hook(void *hook_data
, void *call_data
)
763 ControlFlowData
*Control_Flow_Data
= (ControlFlowData
*) hook_data
;
764 LttTime
* Current_Time
=
765 guicontrolflow_get_current_time(Control_Flow_Data
);
766 *Current_Time
= *((LttTime
*)call_data
);
767 g_info("New Current time HOOK : %u, %u", Current_Time
->tv_sec
,
768 Current_Time
->tv_nsec
);
770 /* If current time is inside time interval, just move the highlight
773 /* Else, we have to change the time interval. We have to tell it
774 * to the main window. */
775 /* The time interval change will take care of placing the current
776 * time at the center of the visible area */