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 gchar
*name
= strdup("name");
536 guint y
= 0, height
= 0, pl_height
= 0;
537 HashedProcessData
*Hashed_Process_Data
= NULL
;
539 ProcessList
*process_list
=
540 guicontrolflow_get_process_list(Event_Request
->Control_Flow_Data
);
542 if(processlist_get_process_pixels(process_list
,
547 &Hashed_Process_Data
) == 1)
549 /* Process not present */
550 processlist_add(process_list
,
555 &Hashed_Process_Data
);
557 drawing_insert_square( Event_Request
->Control_Flow_Data
->Drawing
, y
, height
);
560 /* Find pixels corresponding to time of the event. If the time does
561 * not fit in the window, show a warning, not supposed to happend. */
563 guint width
= control_flow_data
->Drawing
->Drawing_Area_V
->allocation
.width
;
565 LttTime time
= ltt_event_time(e
);
567 LttTime window_end
= ltt_time_add(control_flow_data
->Time_Window
.time_width
,
568 control_flow_data
->Time_Window
.start_time
);
571 convert_time_to_pixels(
572 control_flow_data
->Time_Window
.start_time
,
580 /* Finally, draw what represents the event. */
582 GdkColor color
= { 0, 0xffff, 0x0000, 0x0000 };
583 PropertiesArc prop_arc
;
584 prop_arc
.color
= &color
;
586 prop_arc
.filled
= TRUE
;
587 prop_arc
.position
= OVER
;
588 DrawContext
*draw_context
= Hashed_Process_Data
->draw_context
;
589 draw_context
->Current
->modify_over
->x
= x
;
590 draw_context
->Current
->modify_over
->y
= y
;
591 draw_context
->drawable
= control_flow_data
->Drawing
->Pixmap
;
592 GtkWidget
*widget
= control_flow_data
->Drawing
->Drawing_Area_V
;
593 //draw_context->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
594 draw_context
->gc
= widget
->style
->black_gc
;
596 draw_arc((void*)&prop_arc
, (void*)draw_context
);
597 //test_draw_item(control_flow_data->Drawing, control_flow_data->Drawing->Pixmap);
602 int draw_after_hook(void *hook_data
, void *call_data
)
604 EventRequest
*Event_Request
= (EventRequest
*)hook_data
;
606 g_free(Event_Request
);
613 void update_time_window_hook(void *hook_data
, void *call_data
)
615 ControlFlowData
*control_flow_data
= (ControlFlowData
*) hook_data
;
616 TimeWindow
*Old_Time_Window
=
617 guicontrolflow_get_time_window(control_flow_data
);
618 TimeWindow
*New_Time_Window
= ((TimeWindow
*)call_data
);
620 /* Two cases : zoom in/out or scrolling */
622 /* In order to make sure we can reuse the old drawing, the scale must
623 * be the same and the new time interval being partly located in the
624 * currently shown time interval. (reuse is only for scrolling)
627 g_info("Old time window HOOK : %u, %u to %u, %u",
628 Old_Time_Window
->start_time
.tv_sec
,
629 Old_Time_Window
->start_time
.tv_nsec
,
630 Old_Time_Window
->time_width
.tv_sec
,
631 Old_Time_Window
->time_width
.tv_nsec
);
633 g_info("New time window HOOK : %u, %u to %u, %u",
634 New_Time_Window
->start_time
.tv_sec
,
635 New_Time_Window
->start_time
.tv_nsec
,
636 New_Time_Window
->time_width
.tv_sec
,
637 New_Time_Window
->time_width
.tv_nsec
);
639 if( New_Time_Window
->time_width
.tv_sec
== Old_Time_Window
->time_width
.tv_sec
640 && New_Time_Window
->time_width
.tv_nsec
== Old_Time_Window
->time_width
.tv_nsec
)
642 /* Same scale (scrolling) */
644 LttTime
*ns
= &New_Time_Window
->start_time
;
645 LttTime
*os
= &Old_Time_Window
->start_time
;
646 LttTime old_end
= ltt_time_add(Old_Time_Window
->start_time
,
647 Old_Time_Window
->time_width
);
648 LttTime new_end
= ltt_time_add(New_Time_Window
->start_time
,
649 New_Time_Window
->time_width
);
651 //if(ns<os+w && os+w<ns+w)
652 //if(ns<old_end && os<ns)
653 if(ltt_time_compare(*ns
, old_end
) == -1
654 && ltt_time_compare(*os
, *ns
) == -1)
656 g_info("scrolling near right");
657 /* Scroll right, keep right part of the screen */
659 guint width
= control_flow_data
->Drawing
->Drawing_Area_V
->allocation
.width
;
660 convert_time_to_pixels(
667 /* Copy old data to new location */
668 gdk_draw_drawable (control_flow_data
->Drawing
->Pixmap
,
669 control_flow_data
->Drawing
->Drawing_Area_V
->style
->white_gc
,
670 control_flow_data
->Drawing
->Pixmap
,
675 convert_time_to_pixels(
682 *Old_Time_Window
= *New_Time_Window
;
683 /* Clear the data request background, but not SAFETY */
684 gdk_draw_rectangle (control_flow_data
->Drawing
->Pixmap
,
685 control_flow_data
->Drawing
->Drawing_Area_V
->style
->white_gc
,
688 control_flow_data
->Drawing
->width
- x
, // do not overlap
689 control_flow_data
->Drawing
->height
+SAFETY
);
690 /* Get new data for the rest. */
691 drawing_data_request(control_flow_data
->Drawing
,
692 &control_flow_data
->Drawing
->Pixmap
,
694 control_flow_data
->Drawing
->width
- x
,
695 control_flow_data
->Drawing
->height
);
697 drawing_refresh(control_flow_data
->Drawing
,
699 control_flow_data
->Drawing
->width
,
700 control_flow_data
->Drawing
->height
);
705 //if(ns<os && os<ns+w)
706 //if(ns<os && os<new_end)
707 if(ltt_time_compare(*ns
,*os
) == -1
708 && ltt_time_compare(*os
,new_end
) == -1)
710 g_info("scrolling near left");
711 /* Scroll left, keep left part of the screen */
713 guint width
= control_flow_data
->Drawing
->Drawing_Area_V
->allocation
.width
;
714 convert_time_to_pixels(
721 /* Copy old data to new location */
722 gdk_draw_drawable (control_flow_data
->Drawing
->Pixmap
,
723 control_flow_data
->Drawing
->Drawing_Area_V
->style
->white_gc
,
724 control_flow_data
->Drawing
->Pixmap
,
729 *Old_Time_Window
= *New_Time_Window
;
731 /* Clean the data request background */
732 gdk_draw_rectangle (control_flow_data
->Drawing
->Pixmap
,
733 control_flow_data
->Drawing
->Drawing_Area_V
->style
->white_gc
,
737 control_flow_data
->Drawing
->height
+SAFETY
);
738 /* Get new data for the rest. */
739 drawing_data_request(control_flow_data
->Drawing
,
740 &control_flow_data
->Drawing
->Pixmap
,
743 control_flow_data
->Drawing
->height
);
745 drawing_refresh(control_flow_data
->Drawing
,
747 control_flow_data
->Drawing
->width
,
748 control_flow_data
->Drawing
->height
);
751 g_info("scrolling far");
752 /* Cannot reuse any part of the screen : far jump */
753 *Old_Time_Window
= *New_Time_Window
;
756 gdk_draw_rectangle (control_flow_data
->Drawing
->Pixmap
,
757 control_flow_data
->Drawing
->Drawing_Area_V
->style
->white_gc
,
760 control_flow_data
->Drawing
->width
+SAFETY
, // do not overlap
761 control_flow_data
->Drawing
->height
+SAFETY
);
763 drawing_data_request(control_flow_data
->Drawing
,
764 &control_flow_data
->Drawing
->Pixmap
,
766 control_flow_data
->Drawing
->width
,
767 control_flow_data
->Drawing
->height
);
769 drawing_refresh(control_flow_data
->Drawing
,
771 control_flow_data
->Drawing
->width
,
772 control_flow_data
->Drawing
->height
);
776 /* Different scale (zoom) */
779 *Old_Time_Window
= *New_Time_Window
;
781 gdk_draw_rectangle (control_flow_data
->Drawing
->Pixmap
,
782 control_flow_data
->Drawing
->Drawing_Area_V
->style
->white_gc
,
785 control_flow_data
->Drawing
->width
+SAFETY
, // do not overlap
786 control_flow_data
->Drawing
->height
+SAFETY
);
789 drawing_data_request(control_flow_data
->Drawing
,
790 &control_flow_data
->Drawing
->Pixmap
,
792 control_flow_data
->Drawing
->width
,
793 control_flow_data
->Drawing
->height
);
795 drawing_refresh(control_flow_data
->Drawing
,
797 control_flow_data
->Drawing
->width
,
798 control_flow_data
->Drawing
->height
);
804 void update_current_time_hook(void *hook_data
, void *call_data
)
806 ControlFlowData
*Control_Flow_Data
= (ControlFlowData
*) hook_data
;
807 LttTime
* Current_Time
=
808 guicontrolflow_get_current_time(Control_Flow_Data
);
809 *Current_Time
= *((LttTime
*)call_data
);
810 g_info("New Current time HOOK : %u, %u", Current_Time
->tv_sec
,
811 Current_Time
->tv_nsec
);
813 /* If current time is inside time interval, just move the highlight
816 /* Else, we have to change the time interval. We have to tell it
817 * to the main window. */
818 /* The time interval change will take care of placing the current
819 * time at the center of the visible area */