1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2006 Parisa heidari (inspired from CFV by 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>
65 #include <ltt/trace.h>
67 #include <lttv/lttv.h>
68 #include <lttv/hook.h>
69 #include <lttv/state.h>
70 #include <lttvwindow/lttvwindow.h>
71 #include <lttvwindow/lttvwindowtraces.h>
72 #include <lttvwindow/support.h>
75 #include "histoeventhooks.h"
77 #include "histobuttonwidget.h"
78 #include "histodrawing.h"
81 #define MAX_PATH_LEN 256
82 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
84 #define TRACE_NUMBER 0
85 #define EXTRA_ALLOC 1024 // pixels
87 /* Action to do when background computation completed.
89 * Wait for all the awaited computations to be over.
92 static gint
histo_background_ready(void *hook_data
, void *call_data
)
94 HistoControlFlowData
*histocontrol_flow_data
= (HistoControlFlowData
*)hook_data
;
95 LttvTrace
*trace
= (LttvTrace
*)call_data
;
97 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
98 histocontrol_flow_data
->background_info_waiting
--;
100 if(histocontrol_flow_data
->background_info_waiting
== 0) {
101 g_message("Histocontrol flow viewer : background computation data ready.");
103 histo_drawing_clear(drawing
,0,drawing
->width
);
105 gtk_widget_set_size_request(drawing
->drawing_area
,
107 histo_redraw_notify(histocontrol_flow_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 histo_request_background_data(HistoControlFlowData
*histocontrol_flow_data
)
119 LttvTracesetContext
* tsc
=
120 lttvwindow_get_traceset_context(histocontrol_flow_data
->tab
);
121 gint num_traces
= lttv_traceset_number(tsc
->ts
);
125 LttvHooks
*histo_background_ready_hook
=
127 lttv_hooks_add(histo_background_ready_hook
, histo_background_ready
, histocontrol_flow_data
,
129 histocontrol_flow_data
->background_info_waiting
= 0;
131 for(i
=0;i
<num_traces
;i
++) {
132 trace
= lttv_traceset_get(tsc
->ts
, i
);
134 if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace
)==FALSE
) {
136 if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"),
138 /* We first remove requests that could have been done for the same
139 * information. Happens when two viewers ask for it before servicing
142 if(!lttvwindowtraces_background_request_find(trace
, "state"))
143 lttvwindowtraces_background_request_queue(
144 main_window_get_widget(histocontrol_flow_data
->tab
), trace
, "state");
145 lttvwindowtraces_background_notify_queue(histocontrol_flow_data
,
149 histo_background_ready_hook
);
150 histocontrol_flow_data
->background_info_waiting
++;
151 } else { /* in progress */
153 lttvwindowtraces_background_notify_current(histocontrol_flow_data
,
157 histo_background_ready_hook
);
158 histocontrol_flow_data
->background_info_waiting
++;
161 /* Data ready. Be its nature, this viewer doesn't need to have
162 * its data ready hook called there, because a background
163 * request is always linked with a redraw.
169 lttv_hooks_destroy(histo_background_ready_hook
);
173 * Histogram Viewer's constructor hook
175 * This constructor is given as a parameter to the menuitem and toolbar button
176 * registration. It creates the list.
177 * @param tab A pointer to the parent tab.
178 * @return The widget created.
181 h_guihistocontrolflow(Tab
*tab
)
183 g_info("h_guihistocontrolflow, %p", tab
);
184 HistoControlFlowData
*histocontrol_flow_data
= guihistocontrolflow(tab
) ;
186 histocontrol_flow_data
->tab
= tab
;
188 // Unreg done in the GuiHistoControlFlow_Destructor
189 lttvwindow_register_traceset_notify(tab
,
190 histo_traceset_notify
,
191 histocontrol_flow_data
);
193 lttvwindow_register_time_window_notify(tab
,
194 histo_update_time_window_hook
,
195 histocontrol_flow_data
);
196 lttvwindow_register_current_time_notify(tab
,
197 histo_update_current_time_hook
,
198 histocontrol_flow_data
);
199 lttvwindow_register_redraw_notify(tab
,
201 histocontrol_flow_data
);
202 lttvwindow_register_continue_notify(tab
,
203 histo_continue_notify
,
204 histocontrol_flow_data
);
205 //added for histogram, enable filter:
206 lttvwindow_register_filter_notify(tab
,
207 histo_filter_changed
,histocontrol_flow_data
);
208 histocontrol_flow_data
->histo_main_win_filter
= lttvwindow_get_filter(tab
);
210 // histo_request_background_data(histocontrol_flow_data);
212 return guihistocontrolflow_get_widget(histocontrol_flow_data
) ;
218 /// added for histogram.
219 void histo_request_event( HistoControlFlowData
*histocontrol_flow_data
, guint x
, guint width
)
221 if(width
< 0) return ;
224 Tab
*tab
= histocontrol_flow_data
->tab
;
225 TimeWindow time_window
= lttvwindow_get_time_window( tab
);
226 LttTime time_start
, time_end
;
230 //find the tracehooks
231 LttvTracesetContext
*tsc
= lttvwindow_get_traceset_context(tab
);
233 LttvTraceset
*traceset
= tsc
->ts
;
234 nb_trace
= lttv_traceset_number(traceset
);
235 guint drawing_width
= histocontrol_flow_data
->drawing
->width
;
236 //start time for chunk.
237 histo_convert_pixels_to_time(drawing_width
, /*0*/x
, time_window
,
239 //end time for chunk.
240 histo_convert_pixels_to_time(drawing_width
,
241 /*width*/x
+width
,time_window
,
243 time_end
= ltt_time_add(time_end
, ltt_time_one
); // because main window
244 // doesn't deliver end time.
246 lttvwindow_events_request_remove_all(tab
,
247 histocontrol_flow_data
);
250 // LttvHooksById *histo_event_by_id = lttv_hooks_by_id_new();//if necessary for filter!
251 // FIXME : eventually request for more traces
252 for(i
= 0; i
<MIN(TRACE_NUMBER
+1, nb_trace
);i
++)
254 //should be in the loop or before?
255 EventsRequest
*histo_events_request
= g_new(EventsRequest
, 1);
257 LttvHooks
*histo_before_trace_hooks
= lttv_hooks_new();
258 lttv_hooks_add(histo_before_trace_hooks
, histo_before_trace
,
259 histo_events_request
, LTTV_PRIO_DEFAULT
);
261 LttvHooks
*histo_count_event_hooks
= lttv_hooks_new();
262 lttv_hooks_add(histo_count_event_hooks
, histo_count_event
,
263 histo_events_request
, LTTV_PRIO_DEFAULT
);
265 LttvHooks
*histo_after_trace_hooks
= lttv_hooks_new();
266 lttv_hooks_add(histo_after_trace_hooks
, histo_after_trace
,
267 histo_events_request
, LTTV_PRIO_DEFAULT
);
270 LttvHooks
*histo_before_chunk_traceset
= lttv_hooks_new();
271 LttvHooks
*histo_after_chunk_traceset
= lttv_hooks_new();
273 lttv_hooks_add(histo_before_chunk_traceset
,
275 histo_events_request
,
278 lttv_hooks_add(histo_after_chunk_traceset
,
280 histo_events_request
,
282 ts
= (LttvTraceState
*)tsc
->traces
[i
];
283 // Fill the events request
284 histo_events_request
->owner
= histocontrol_flow_data
;
285 histo_events_request
->viewer_data
= histocontrol_flow_data
;
286 histo_events_request
->servicing
= FALSE
;
287 histo_events_request
->start_time
= time_start
;//time_window.start_time;
289 histo_events_request
->start_position
= NULL
;
290 histo_events_request
->stop_flag
= FALSE
;
291 histo_events_request
->end_time
= time_end
;//time_window.end_time;
293 histo_events_request
->num_events
= G_MAXUINT
;
294 histo_events_request
->end_position
= NULL
;
295 histo_events_request
->trace
= i
;
296 histo_events_request
->hooks
= NULL
;
297 histo_events_request
->before_chunk_traceset
= histo_before_chunk_traceset
;//NULL;
298 histo_events_request
->before_chunk_trace
= NULL
;
299 histo_events_request
->before_chunk_tracefile
= NULL
;
300 histo_events_request
->event
= histo_count_event_hooks
;
301 histo_events_request
->event_by_id
= NULL
;//histo_event_by_id;//NULL;
302 histo_events_request
->after_chunk_tracefile
= NULL
;
303 histo_events_request
->after_chunk_trace
= NULL
;
304 histo_events_request
->after_chunk_traceset
= histo_after_chunk_traceset
;//NULL;
305 histo_events_request
->before_request
= histo_before_trace_hooks
;
306 histo_events_request
->after_request
= histo_after_trace_hooks
;
308 lttvwindow_events_request(histocontrol_flow_data
->tab
, histo_events_request
);
313 //hook,added for histogram
314 int histo_count_event(void *hook_data
, void *call_data
){
316 guint x
;//time to pixel
317 guint i
;// number of events
322 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
323 HistoControlFlowData
*histocontrol_flow_data
= events_request
->viewer_data
;
325 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
326 int width
= drawing
->width
;
328 g_info("Histogram: count_event() \n");
331 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
332 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
334 e
= ltt_tracefile_get_event(tfc
->tf
);
336 LttvFilter
*histo_filter
= histocontrol_flow_data
->histo_main_win_filter
;
337 if(histo_filter
!= NULL
&& histo_filter
->head
!= NULL
)
338 if(!lttv_filter_tree_parse(histo_filter
->head
,e
,tfc
->tf
,
339 tfc
->t_context
->t
,tfc
))
342 TimeWindow time_window
= lttvwindow_get_time_window(histocontrol_flow_data
->tab
);
343 event_time
= ltt_event_time(e
);
345 histo_convert_time_to_pixels(
350 element
= &g_array_index(histocontrol_flow_data
->number_of_process
, guint
, x
);
355 ///befor hook:Added for histogram
356 int histo_before_trace(void *hook_data
, void *call_data
){
358 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
359 HistoControlFlowData
*histocontrol_flow_data
= events_request
->viewer_data
;
361 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
363 //in order to reset all of the array elements.
365 end
= MIN(histocontrol_flow_data
->number_of_process
->len
,drawing
->damage_end
);
366 for(i
=drawing
->damage_begin
/*0*/;
367 i
< end
/*histocontrol_flow_data->number_of_process->len*/;i
++)
369 g_array_index(histocontrol_flow_data
->number_of_process
, guint
, i
) = 0;
371 histo_drawing_clear(drawing
,drawing
->damage_begin
/*0*/,
372 drawing
->damage_end
- drawing
->damage_begin
/*drawing->width*/);
373 //g_array_free(histocontrol_flow_data->number_of_process,TRUE);
374 //histocontrol_flow_data->number_of_process =g_array_new (FALSE,
376 // sizeof(guint));//4 byte for guint
377 //g_array_set_size (histocontrol_flow_data->number_of_process,
378 // drawing->drawing_area->allocation.width);
379 // gtk_widget_set_size_request(drawing->drawing_area,-1,-1);
380 gtk_widget_queue_draw(drawing
->drawing_area
);
383 //after hook,added for histogram
384 int histo_after_trace(void *hook_data
, void *call_data
){
386 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
387 HistoControlFlowData
*histocontrol_flow_data
= events_request
->viewer_data
;
388 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
389 guint x
, x_end
, width
;
390 LttTime end_time
= events_request
->end_time
;
391 TimeWindow time_window
=
392 lttvwindow_get_time_window(histocontrol_flow_data
->tab
);
394 g_debug("histo after trace");
396 histo_convert_time_to_pixels(
401 x
= drawing
->damage_begin
;
403 drawing
->damage_begin
= x
+width
;
404 histogram_show (histocontrol_flow_data
,x
,x_end
);
409 void histogram_show(HistoControlFlowData
*histocontrol_flow_data
,guint draw_begin
,
412 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
413 GtkWidget
*drawingarea
= histo_drawing_get_drawing_area(drawing
);
414 guint width
= drawing
->width
;
415 guint height
= drawing
->height
;//drawingarea->allocation.height;
417 /* gdk_gc_set_line_attributes(drawing->gc,
423 histo_drawing_clear(drawing
,draw_begin
,draw_end
);
425 TimeWindow time_window
=
426 lttvwindow_get_time_window(histocontrol_flow_data
->tab
);
430 guint i
,line_src
,line_end
;
431 guint end_chunk
=MIN(draw_end
,(histocontrol_flow_data
->number_of_process
)->len
);
433 for (i
=draw_begin
/*0*/;i
<end_chunk
/* (histocontrol_flow_data->number_of_process)->len*/;i
++){
434 val
=g_array_index(histocontrol_flow_data
->number_of_process
,guint
,i
);
435 h_val
= height
-((height
*val
)/histocontrol_flow_data
->max_height
);
437 histo_convert_pixels_to_time(width
, i
,
440 histo_convert_pixels_to_time(width
, i
+1,
445 //check if zoom in is used and more than 1 pixel correspond to each 1nsec
446 //used for drawing point (not line) on the screen.
447 /* while (ltt_time_compare(t1,t2)==0)
449 histo_convert_pixels_to_time(width, i++,
452 histo_convert_pixels_to_time(width, i+1,
458 */ //replaced later for lines.
460 if(val
> drawing
->histo_control_flow_data
->max_height
){
461 //overlimit, yellow color
462 gdk_gc_set_foreground(drawing
->gc
,&histo_drawing_colors
[COL_WHITE
] );//COL_RUN_TRAP
463 gdk_draw_line (drawing
->pixmap
,
469 gdk_gc_set_foreground(drawing
->gc
,&histo_drawing_colors
[COL_RUN_USER_MODE
] );
470 gdk_draw_line (drawing
->pixmap
,
476 while ((ltt_time_compare(t1
,t2
)==0)&&(i
<end_chunk
))//-1 , i to be incremented later
480 if(val
> drawing
->histo_control_flow_data
->max_height
){
481 //overlimit, yellow color
482 gdk_gc_set_foreground(drawing
->gc
,
483 &histo_drawing_colors
[COL_RUN_TRAP
] );
484 gdk_draw_line (drawing
->pixmap
,
490 gdk_gc_set_foreground(drawing
->gc
,&histo_drawing_colors
[COL_RUN_USER_MODE
] );
491 gdk_draw_line (drawing
->pixmap
,
496 histo_convert_pixels_to_time(width
, i
,
500 histo_convert_pixels_to_time(width
, i
+1,
504 }//while (t1==t2)////
508 histo_drawing_update_vertical_ruler(drawing
);
509 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
511 draw_end
-draw_begin
, drawing
->height
);
512 gdk_window_process_updates(drawingarea
->window
,TRUE
);
515 int histo_event_selected_hook(void *hook_data
, void *call_data
)
517 HistoControlFlowData
*histocontrol_flow_data
= (HistoControlFlowData
*) hook_data
;
518 guint
*event_number
= (guint
*) call_data
;
520 g_debug("DEBUG : event selected by main window : %u", *event_number
);
527 /* histo_before_schedchange_hook
529 * This function basically draw lines and icons. Two types of lines are drawn :
530 * one small (3 pixels?) representing the state of the process and the second
531 * type is thicker (10 pixels?) representing on which CPU a process is running
532 * (and this only in running state).
534 * Extremums of the lines :
535 * x_min : time of the last event context for this process kept in memory.
536 * x_max : time of the current event.
537 * y : middle of the process in the process list. The process is found in the
538 * list, therefore is it's position in pixels.
540 * The choice of lines'color is defined by the context of the last event for this
545 int histo_before_schedchange_hook(void *hook_data, void *call_data)
551 gint
histo_update_time_window_hook(void *hook_data
, void *call_data
)
553 HistoControlFlowData
*histocontrol_flow_data
= (HistoControlFlowData
*) hook_data
;
554 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
556 const TimeWindowNotifyData
*histo_time_window_nofify_data
=
557 ((const TimeWindowNotifyData
*)call_data
);
559 TimeWindow
*histo_old_time_window
=
560 histo_time_window_nofify_data
->old_time_window
;
561 TimeWindow
*histo_new_time_window
=
562 histo_time_window_nofify_data
->new_time_window
;
565 histo_drawing_update_ruler(drawing
,
566 histo_new_time_window
);
568 /* Two cases : zoom in/out or scrolling */
570 /* In order to make sure we can reuse the old drawing, the scale must
571 * be the same and the new time interval being partly located in the
572 * currently shown time interval. (reuse is only for scrolling)
575 g_info("Old time window HOOK : %lu, %lu to %lu, %lu",
576 histo_old_time_window
->start_time
.tv_sec
,
577 histo_old_time_window
->start_time
.tv_nsec
,
578 histo_old_time_window
->time_width
.tv_sec
,
579 histo_old_time_window
->time_width
.tv_nsec
);
581 g_info("New time window HOOK : %lu, %lu to %lu, %lu",
582 histo_new_time_window
->start_time
.tv_sec
,
583 histo_new_time_window
->start_time
.tv_nsec
,
584 histo_new_time_window
->time_width
.tv_sec
,
585 histo_new_time_window
->time_width
.tv_nsec
);
587 //For Histo,redraw always except if zoom fit is pushed 2 times consequently
588 if( histo_new_time_window
->start_time
.tv_sec
== histo_old_time_window
->start_time
.tv_sec
589 && histo_new_time_window
->start_time
.tv_nsec
== histo_old_time_window
->start_time
.tv_nsec
590 && histo_new_time_window
->time_width
.tv_sec
== histo_old_time_window
->time_width
.tv_sec
591 && histo_new_time_window
->time_width
.tv_nsec
== histo_old_time_window
->time_width
.tv_nsec
)
595 histo_rectangle_pixmap (drawing
->drawing_area
->style
->black_gc
,
598 drawing
->width
,//+SAFETY, // do not overlap
601 drawing
->damage_begin
= 0;
602 drawing
->damage_end
= drawing
->width
;
604 gtk_widget_queue_draw(drawing
->drawing_area
);
605 histo_request_event(histocontrol_flow_data
,drawing
->damage_begin
,
606 drawing
->damage_end
- drawing
->damage_begin
);
608 gdk_window_process_updates(drawing
->drawing_area
->window
,TRUE
);
610 //show number of event at current time
612 histo_drawing_update_vertical_ruler(drawing
);
616 /*// if( histo_new_time_window->time_width.tv_sec == histo_old_time_window->time_width.tv_sec
617 && histo_new_time_window->time_width.tv_nsec == histo_old_time_window->time_width.tv_nsec)
619 // Same scale (scrolling)
622 while scrolling no matter far or near ,
623 right or left it's necessary to redraw whole screen!*/
624 /*// LttTime *ns = &histo_new_time_window->start_time;
625 LttTime *nw = &histo_new_time_window->time_width;
626 LttTime *os = &histo_old_time_window->start_time;
627 LttTime *ow = &histo_old_time_window->time_width;
628 LttTime histo_old_end = histo_old_time_window->end_time;
629 LttTime histo_new_end = histo_new_time_window->end_time;
631 //if(ns<os+w && os+w<ns+w)
632 //if(ns<histo_old_end && os<ns)
634 //added for histogram
635 gtk_widget_queue_draw(drawing->drawing_area);
637 drawing->damage_begin = 0;
638 drawing->damage_end = drawing->width;
640 //replaced for hisogram
641 histo_request_event(histocontrol_flow_data,drawing->damage_begin,
642 drawing->damage_end- drawing->damage_begin);
644 if(ltt_time_compare(*ns, histo_old_end) == -1
645 && ltt_time_compare(*os, *ns) == -1)
647 g_info("scrolling near right");
648 // Scroll right, keep right part of the screen
650 guint width = drawing->width;
651 histo_convert_time_to_pixels(
652 *histo_old_time_window,
657 // Copy old data to new location
658 //replaced for histogram:
659 histo_copy_pixmap_region(drawing,NULL,
660 drawing->drawing_area->style->black_gc,//drawing->gc,
663 0, 0, (drawing->width-x)
666 if(drawing->damage_begin == drawing->damage_end)
667 drawing->damage_begin = drawing->width-x;
669 drawing->damage_begin = 0;
671 drawing->damage_end = drawing->width;
673 //(histo) copy corresponding array region too:
676 for(i=0; i < histocontrol_flow_data->number_of_process->len-x;i++)
678 g_array_index(histocontrol_flow_data->number_of_process, guint, i) =
679 g_array_index(histocontrol_flow_data->number_of_process, guint, i+x);
682 // Clear the data request background, but not SAFETY
685 //not necessary for histo, because in before chunk ,it clears the area
686 /* histo_rectangle_pixmap (
687 drawing->drawing_area->style->black_gc,
689 drawing->damage_begin, 0,
690 drawing->damage_end - drawing->damage_begin, // do not overlap
693 /* gtk_widget_queue_draw(drawing->drawing_area);
694 //gtk_widget_queue_draw_area (drawing->drawing_area,
696 // histocontrol_flow_data->drawing->width,
697 // histocontrol_flow_data->drawing->height);
699 // Get new data for the rest.
700 //replaced for hisogram
701 histo_request_event(histocontrol_flow_data,drawing->damage_begin,
702 drawing->damage_end- drawing->damage_begin);
705 //if(ns<os && os<ns+w)
706 //if(ns<os && os<histo_new_end)
707 if(ltt_time_compare(*ns,*os) == -1
708 && ltt_time_compare(*os,histo_new_end) == -1)
710 g_info("scrolling near left");
711 // Scroll left, keep left part of the screen
713 guint width = drawing->width;
714 histo_convert_time_to_pixels(
715 *histo_new_time_window,
720 // Copy old data to new location
721 //replaced for histogram
723 histo_copy_pixmap_region(drawing,NULL,
724 drawing->drawing_area->style->black_gc,//drawing->gc,
728 //(histo) copy corresponding array region too:
730 for(i=histocontrol_flow_data->number_of_process->len; i > x-1;i--)
732 g_array_index(histocontrol_flow_data->number_of_process, guint, i) =
733 g_array_index(histocontrol_flow_data->number_of_process, guint, i-x);
736 if(drawing->damage_begin == drawing->damage_end)
737 drawing->damage_end = x;
739 drawing->damage_end =
742 drawing->damage_begin = 0;
745 //not necessary for histo, because in before chunk ,it clears the area
746 /* histo_rectangle_pixmap (drawing->drawing_area->style->black_gc,
748 drawing->damage_begin, 0,
749 drawing->damage_end - drawing->damage_begin, // do not overlap
752 /* gtk_widget_queue_draw(drawing->drawing_area);
753 //gtk_widget_queue_draw_area (drawing->drawing_area,
755 // histocontrol_flow_data->drawing->width,
756 // histocontrol_flow_data->drawing->height);
759 // Get new data for the rest.
761 //replaced for hisogram
762 histo_request_event(histocontrol_flow_data,drawing->damage_begin,
763 drawing->damage_end- drawing->damage_begin);
766 if(ltt_time_compare(*ns,*os) == 0)
768 g_info("not scrolling");
770 g_info("scrolling far");
771 // Cannot reuse any part of the screen : far jump
773 //not necessary for histo, because in before chunk ,it clears the area
774 /* histo_rectangle_pixmap (histocontrol_flow_data->drawing->drawing_area->style->black_gc,
777 histocontrol_flow_data->drawing->width,//+SAFETY, // do not overlap
780 //gtk_widget_queue_draw_area (drawing->drawing_area,
782 // histocontrol_flow_data->drawing->width,
783 // histocontrol_flow_data->drawing->height);
784 /* gtk_widget_queue_draw(drawing->drawing_area);
786 drawing->damage_begin = 0;
787 drawing->damage_end = histocontrol_flow_data->drawing->width;
789 histo_drawing_data_request(histocontrol_flow_data->drawing,
791 histocontrol_flow_data->drawing->width,
792 histocontrol_flow_data->drawing->height);*/
793 //replaced for hisogram
794 /* histo_request_event(histocontrol_flow_data,drawing->damage_begin,
795 drawing->damage_end- drawing->damage_begin);
800 // Different scale (zoom)
803 //not necessary for histo, because in before chunk ,it clears the area
805 histo_rectangle_pixmap (drawing->drawing_area->style->black_gc,
808 histocontrol_flow_data->drawing->width+SAFETY, // do not overlap
811 //gtk_widget_queue_draw_area (drawing->drawing_area,
813 // histocontrol_flow_data->drawing->width,
814 // histocontrol_flow_data->drawing->height);
815 /*// gtk_widget_queue_draw(drawing->drawing_area);
817 drawing->damage_begin = 0;
818 drawing->damage_end = drawing->width;
820 //replaced for hisogram
821 histo_request_event(histocontrol_flow_data,drawing->damage_begin,
822 drawing->damage_end- drawing->damage_begin);
825 // Update directly when scrolling
826 gdk_window_process_updates(drawing->drawing_area->window,
829 //show number of event at current time
831 histo_drawing_update_vertical_ruler(drawing);
833 //disabled for histogram, always redraw whole screen.
837 gint
histo_traceset_notify(void *hook_data
, void *call_data
)
839 HistoControlFlowData
*histocontrol_flow_data
= (HistoControlFlowData
*) hook_data
;
840 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
842 if(unlikely(drawing
->gc
== NULL
)) {
845 if(drawing
->dotted_gc
== NULL
) {
849 histo_drawing_clear(drawing
,0,drawing
->width
);
852 for(i
=0;i
< histocontrol_flow_data
->number_of_process
->len
;i
++)
854 g_array_index(histocontrol_flow_data
->number_of_process
, guint
, i
) = 0;
856 gtk_widget_set_size_request(
857 drawing
->drawing_area
,
859 histo_redraw_notify(histocontrol_flow_data
, NULL
);
861 ///histo_request_background_data(histocontrol_flow_data);
866 gint
histo_redraw_notify(void *hook_data
, void *call_data
)
868 HistoControlFlowData
*histocontrol_flow_data
= (HistoControlFlowData
*) hook_data
;
869 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
870 GtkWidget
*widget
= drawing
->drawing_area
;
872 drawing
->damage_begin
= 0;
873 drawing
->damage_end
= drawing
->width
;
875 // fun feature, to be separated someday...
877 histo_drawing_clear(drawing
,0,drawing
->width
);
879 gtk_widget_set_size_request(
880 drawing
->drawing_area
,
884 histo_rectangle_pixmap (widget
->style
->black_gc
,
887 drawing
->alloc_width
,
889 gtk_widget_queue_draw(widget
);
892 if(drawing
->damage_begin
< drawing
->damage_end
)
894 //replaced for histogram
895 histo_request_event(histocontrol_flow_data
,0,drawing
->width
);
899 //gtk_widget_queue_draw_area(drawing->drawing_area,
908 gint
histo_continue_notify(void *hook_data
, void *call_data
)
910 HistoControlFlowData
*histocontrol_flow_data
= (HistoControlFlowData
*) hook_data
;
911 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
913 //g_assert(widget->allocation.width == drawing->damage_end);
915 if(drawing
->damage_begin
< drawing
->damage_end
)
917 histo_request_event(histocontrol_flow_data
,drawing
->damage_begin
,
918 drawing
->damage_end
-drawing
->damage_begin
);
925 gint
histo_update_current_time_hook(void *hook_data
, void *call_data
)
927 HistoControlFlowData
*histocontrol_flow_data
= (HistoControlFlowData
*)hook_data
;
928 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
930 LttTime current_time
= *((LttTime
*)call_data
);
932 TimeWindow time_window
=
933 lttvwindow_get_time_window(histocontrol_flow_data
->tab
);
935 LttTime time_begin
= time_window
.start_time
;
936 LttTime width
= time_window
.time_width
;
939 guint64 time_ll
= ltt_time_to_uint64(width
);
940 time_ll
= time_ll
>> 1; /* divide by two */
941 half_width
= ltt_time_from_uint64(time_ll
);
943 LttTime time_end
= ltt_time_add(time_begin
, width
);
945 LttvTracesetContext
* tsc
=
946 lttvwindow_get_traceset_context(histocontrol_flow_data
->tab
);
948 LttTime trace_start
= tsc
->time_span
.start_time
;
949 LttTime trace_end
= tsc
->time_span
.end_time
;
951 g_info("Histogram: New current time HOOK : %lu, %lu", current_time
.tv_sec
,
952 current_time
.tv_nsec
);
956 /* If current time is inside time interval, just move the highlight
959 /* Else, we have to change the time interval. We have to tell it
960 * to the main window. */
961 /* The time interval change will take care of placing the current
962 * time at the center of the visible area, or nearest possible if we are
963 * at one end of the trace. */
966 if(ltt_time_compare(current_time
, time_begin
) < 0)
968 TimeWindow histo_new_time_window
;
970 if(ltt_time_compare(current_time
,
971 ltt_time_add(trace_start
,half_width
)) < 0)
972 time_begin
= trace_start
;
974 time_begin
= ltt_time_sub(current_time
,half_width
);
976 histo_new_time_window
.start_time
= time_begin
;
977 histo_new_time_window
.time_width
= width
;
978 histo_new_time_window
.time_width_double
= ltt_time_to_double(width
);
979 histo_new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
981 lttvwindow_report_time_window(histocontrol_flow_data
->tab
, histo_new_time_window
);
983 else if(ltt_time_compare(current_time
, time_end
) > 0)
985 TimeWindow histo_new_time_window
;
987 if(ltt_time_compare(current_time
, ltt_time_sub(trace_end
, half_width
)) > 0)
988 time_begin
= ltt_time_sub(trace_end
,width
);
990 time_begin
= ltt_time_sub(current_time
,half_width
);
992 histo_new_time_window
.start_time
= time_begin
;
993 histo_new_time_window
.time_width
= width
;
994 histo_new_time_window
.time_width_double
= ltt_time_to_double(width
);
995 histo_new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
997 lttvwindow_report_time_window(histocontrol_flow_data
->tab
, histo_new_time_window
);
1000 gtk_widget_queue_draw(drawing
->drawing_area
);
1002 /* Update directly when scrolling */
1003 gdk_window_process_updates(drawing
->drawing_area
->window
,
1006 histo_drawing_update_vertical_ruler(drawing
);
1011 gboolean
histo_filter_changed(void * hook_data
, void * call_data
)
1013 HistoControlFlowData
*histocontrol_flow_data
= (HistoControlFlowData
*)hook_data
;
1014 histoDrawing_t
*drawing
=histocontrol_flow_data
->drawing
;
1016 LttvTracesetContext
* tsc
=
1017 lttvwindow_get_traceset_context(histocontrol_flow_data
->tab
);
1019 histocontrol_flow_data
->histo_main_win_filter
=
1020 (LttvFilter
*)call_data
;
1021 //get_events(event_viewer_data->vadjust_c->value, event_viewer_data);
1022 gtk_widget_set_size_request(
1023 drawing
->drawing_area
,
1025 drawing
->damage_begin
= 0;
1026 drawing
->damage_end
= drawing
->width
;
1028 /* //done in, before request!
1029 histo_drawing_clear(drawing,0,drawing->width);
1031 for(i=0;i < histocontrol_flow_data->number_of_process->len;i++)
1033 g_array_index(histocontrol_flow_data->number_of_process, guint, i) = 0;
1036 histo_request_event(histocontrol_flow_data
,0,drawing
->width
);
1041 typedef struct _histo_ClosureData
{
1042 EventsRequest
*events_request
;
1043 LttvTracesetState
*tss
;
1046 } histo_ClosureData
;
1050 int histo_before_chunk(void *hook_data
, void *call_data
)
1052 EventsRequest
*histo_events_request
= (EventsRequest
*)hook_data
;
1053 LttvTracesetState
*histo_tss
= (LttvTracesetState
*)call_data
;
1054 HistoControlFlowData
*histo_cfd
= (HistoControlFlowData
*)histo_events_request
->viewer_data
;
1056 /* Desactivate sort */
1057 gtk_tree_sortable_set_sort_column_id(
1058 GTK_TREE_SORTABLE(cfd
->process_list
->list_store
),
1060 GTK_SORT_ASCENDING
);
1062 histo_drawing_chunk_begin(histo_events_request
, histo_tss
);
1067 /*int histo_before_request(void *hook_data, void *call_data)
1069 EventsRequest *events_request = (EventsRequest*)hook_data;
1070 LttvTracesetState *tss = (LttvTracesetState*)call_data;
1072 histo_drawing_data_request_begin(events_request, tss);
1080 * after request is necessary in addition of after chunk in order to draw
1081 * lines until the end of the screen. after chunk just draws lines until
1088 /*int histo_after_request(void *hook_data, void *call_data)
1099 int histo_after_chunk(void *hook_data
, void *call_data
)
1101 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1102 HistoControlFlowData
*histocontrol_flow_data
= events_request
->viewer_data
;
1103 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1104 LttvTracesetContext
*tsc
= (LttvTracesetContext
*)call_data
;
1105 LttvTracefileContext
*tfc
= lttv_traceset_context_get_current_tfc(tsc
);
1108 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
1111 end_time
= LTT_TIME_MIN(tfc
->timestamp
, events_request
->end_time
);
1112 else /* end of traceset, or position now out of request : end */
1113 end_time
= events_request
->end_time
;
1115 guint x
, x_end
, width
;
1117 TimeWindow time_window
=
1118 lttvwindow_get_time_window(histocontrol_flow_data
->tab
);
1120 g_debug("histo after chunk");
1122 histo_convert_time_to_pixels(
1127 x
= drawing
->damage_begin
;
1129 drawing
->damage_begin
= x
+width
;
1131 histogram_show (histocontrol_flow_data
,x
,x_end
);