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 // fixed #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(LttvPlugin
*plugin
)
183 LttvPluginTab
*ptab
= LTTV_PLUGIN_TAB(plugin
);
184 g_info("h_guihistocontrolflow, %p", ptab
);
185 HistoControlFlowData
*histocontrol_flow_data
= guihistocontrolflow(ptab
) ;
187 Tab
*tab
= ptab
->tab
;
188 histocontrol_flow_data
->tab
= tab
;
190 // Unreg done in the GuiHistoControlFlow_Destructor
191 lttvwindow_register_traceset_notify(tab
,
192 histo_traceset_notify
,
193 histocontrol_flow_data
);
195 lttvwindow_register_time_window_notify(tab
,
196 histo_update_time_window_hook
,
197 histocontrol_flow_data
);
198 lttvwindow_register_current_time_notify(tab
,
199 histo_update_current_time_hook
,
200 histocontrol_flow_data
);
201 lttvwindow_register_redraw_notify(tab
,
203 histocontrol_flow_data
);
204 lttvwindow_register_continue_notify(tab
,
205 histo_continue_notify
,
206 histocontrol_flow_data
);
207 //added for histogram, enable filter:
208 lttvwindow_register_filter_notify(tab
,
209 histo_filter_changed
,histocontrol_flow_data
);
210 histocontrol_flow_data
->histo_main_win_filter
= lttvwindow_get_filter(tab
);
212 // histo_request_background_data(histocontrol_flow_data);
214 return guihistocontrolflow_get_widget(histocontrol_flow_data
) ;
220 /// added for histogram.
221 void histo_request_event( HistoControlFlowData
*histocontrol_flow_data
, guint x
, guint width
)
223 if(width
< 0) return ;
226 Tab
*tab
= histocontrol_flow_data
->tab
;
227 TimeWindow time_window
= lttvwindow_get_time_window( tab
);
228 LttTime time_start
, time_end
;
232 //find the tracehooks
233 LttvTracesetContext
*tsc
= lttvwindow_get_traceset_context(tab
);
235 LttvTraceset
*traceset
= tsc
->ts
;
236 nb_trace
= lttv_traceset_number(traceset
);
237 guint drawing_width
= histocontrol_flow_data
->drawing
->width
;
238 //start time for chunk.
239 histo_convert_pixels_to_time(drawing_width
, /*0*/x
, time_window
,
241 //end time for chunk.
242 histo_convert_pixels_to_time(drawing_width
,
243 /*width*/x
+width
,time_window
,
245 time_end
= ltt_time_add(time_end
, ltt_time_one
); // because main window
246 // doesn't deliver end time.
248 lttvwindow_events_request_remove_all(tab
,
249 histocontrol_flow_data
);
252 // LttvHooksById *histo_event_by_id = lttv_hooks_by_id_new();//if necessary for filter!
253 // FIXME : eventually request for more traces
254 // fixed for(i = 0; i<MIN(TRACE_NUMBER+1, nb_trace);i++) {
255 for(i
=0;i
<nb_trace
;i
++) {
256 //should be in the loop or before?
257 EventsRequest
*histo_events_request
= g_new(EventsRequest
, 1);
259 LttvHooks
*histo_before_trace_hooks
= lttv_hooks_new();
260 lttv_hooks_add(histo_before_trace_hooks
, histo_before_trace
,
261 histo_events_request
, LTTV_PRIO_DEFAULT
);
263 LttvHooks
*histo_count_event_hooks
= lttv_hooks_new();
264 lttv_hooks_add(histo_count_event_hooks
, histo_count_event
,
265 histo_events_request
, LTTV_PRIO_DEFAULT
);
267 LttvHooks
*histo_after_trace_hooks
= lttv_hooks_new();
268 lttv_hooks_add(histo_after_trace_hooks
, histo_after_trace
,
269 histo_events_request
, LTTV_PRIO_DEFAULT
);
272 LttvHooks
*histo_before_chunk_traceset
= lttv_hooks_new();
273 LttvHooks
*histo_after_chunk_traceset
= lttv_hooks_new();
275 lttv_hooks_add(histo_before_chunk_traceset
,
277 histo_events_request
,
280 lttv_hooks_add(histo_after_chunk_traceset
,
282 histo_events_request
,
284 ts
= (LttvTraceState
*)tsc
->traces
[i
];
285 // Fill the events request
286 histo_events_request
->owner
= histocontrol_flow_data
;
287 histo_events_request
->viewer_data
= histocontrol_flow_data
;
288 histo_events_request
->servicing
= FALSE
;
289 histo_events_request
->start_time
= time_start
;//time_window.start_time;
291 histo_events_request
->start_position
= NULL
;
292 histo_events_request
->stop_flag
= FALSE
;
293 histo_events_request
->end_time
= time_end
;//time_window.end_time;
295 histo_events_request
->num_events
= G_MAXUINT
;
296 histo_events_request
->end_position
= NULL
;
297 histo_events_request
->trace
= i
;
298 histo_events_request
->hooks
= NULL
;
299 histo_events_request
->before_chunk_traceset
= histo_before_chunk_traceset
;//NULL;
300 histo_events_request
->before_chunk_trace
= NULL
;
301 histo_events_request
->before_chunk_tracefile
= NULL
;
302 histo_events_request
->event
= histo_count_event_hooks
;
303 histo_events_request
->event_by_id
= NULL
;//histo_event_by_id;//NULL;
304 histo_events_request
->after_chunk_tracefile
= NULL
;
305 histo_events_request
->after_chunk_trace
= NULL
;
306 histo_events_request
->after_chunk_traceset
= histo_after_chunk_traceset
;//NULL;
307 histo_events_request
->before_request
= histo_before_trace_hooks
;
308 histo_events_request
->after_request
= histo_after_trace_hooks
;
310 lttvwindow_events_request(histocontrol_flow_data
->tab
, histo_events_request
);
315 //hook,added for histogram
316 int histo_count_event(void *hook_data
, void *call_data
){
318 guint x
;//time to pixel
319 guint i
;// number of events
324 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
325 HistoControlFlowData
*histocontrol_flow_data
= events_request
->viewer_data
;
327 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
328 int width
= drawing
->width
;
330 g_info("Histogram: count_event() \n");
333 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
334 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
336 e
= ltt_tracefile_get_event(tfc
->tf
);
338 LttvFilter
*histo_filter
= histocontrol_flow_data
->histo_main_win_filter
;
339 if(histo_filter
!= NULL
&& histo_filter
->head
!= NULL
)
340 if(!lttv_filter_tree_parse(histo_filter
->head
,e
,tfc
->tf
,
341 tfc
->t_context
->t
,tfc
))
344 TimeWindow time_window
= lttvwindow_get_time_window(histocontrol_flow_data
->tab
);
345 event_time
= ltt_event_time(e
);
347 histo_convert_time_to_pixels(
352 element
= &g_array_index(histocontrol_flow_data
->number_of_process
, guint
, x
);
357 ///befor hook:Added for histogram
358 int histo_before_trace(void *hook_data
, void *call_data
){
360 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
361 HistoControlFlowData
*histocontrol_flow_data
= events_request
->viewer_data
;
363 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
365 //in order to reset all of the array elements.
367 end
= MIN(histocontrol_flow_data
->number_of_process
->len
,drawing
->damage_end
);
368 for(i
=drawing
->damage_begin
/*0*/;
369 i
< end
/*histocontrol_flow_data->number_of_process->len*/;i
++)
371 g_array_index(histocontrol_flow_data
->number_of_process
, guint
, i
) = 0;
373 histo_drawing_clear(drawing
,drawing
->damage_begin
/*0*/,
374 drawing
->damage_end
- drawing
->damage_begin
/*drawing->width*/);
375 //g_array_free(histocontrol_flow_data->number_of_process,TRUE);
376 //histocontrol_flow_data->number_of_process =g_array_new (FALSE,
378 // sizeof(guint));//4 byte for guint
379 //g_array_set_size (histocontrol_flow_data->number_of_process,
380 // drawing->drawing_area->allocation.width);
381 // gtk_widget_set_size_request(drawing->drawing_area,-1,-1);
382 gtk_widget_queue_draw(drawing
->drawing_area
);
385 //after hook,added for histogram
386 int histo_after_trace(void *hook_data
, void *call_data
){
388 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
389 HistoControlFlowData
*histocontrol_flow_data
= events_request
->viewer_data
;
390 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
391 guint x
, x_end
, width
;
392 LttTime end_time
= events_request
->end_time
;
393 TimeWindow time_window
=
394 lttvwindow_get_time_window(histocontrol_flow_data
->tab
);
396 g_debug("histo after trace");
398 histo_convert_time_to_pixels(
403 x
= drawing
->damage_begin
;
405 drawing
->damage_begin
= x
+width
;
406 histogram_show (histocontrol_flow_data
,x
,x_end
);
411 void histogram_show(HistoControlFlowData
*histocontrol_flow_data
,guint draw_begin
,
414 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
415 GtkWidget
*drawingarea
= histo_drawing_get_drawing_area(drawing
);
416 guint width
= drawing
->width
;
417 guint height
= drawing
->height
;//drawingarea->allocation.height;
419 /* gdk_gc_set_line_attributes(drawing->gc,
425 histo_drawing_clear(drawing
,draw_begin
,draw_end
);
427 TimeWindow time_window
=
428 lttvwindow_get_time_window(histocontrol_flow_data
->tab
);
432 guint i
,line_src
,line_end
;
433 guint end_chunk
=MIN(draw_end
,(histocontrol_flow_data
->number_of_process
)->len
);
435 for (i
=draw_begin
/*0*/;i
<end_chunk
/* (histocontrol_flow_data->number_of_process)->len*/;i
++){
436 val
=g_array_index(histocontrol_flow_data
->number_of_process
,guint
,i
);
437 h_val
= height
-((height
*val
)/histocontrol_flow_data
->max_height
);
439 histo_convert_pixels_to_time(width
, i
,
442 histo_convert_pixels_to_time(width
, i
+1,
447 //check if zoom in is used and more than 1 pixel correspond to each 1nsec
448 //used for drawing point (not line) on the screen.
449 /* while (ltt_time_compare(t1,t2)==0)
451 histo_convert_pixels_to_time(width, i++,
454 histo_convert_pixels_to_time(width, i+1,
460 */ //replaced later for lines.
462 if(val
> drawing
->histo_control_flow_data
->max_height
){
463 //overlimit, yellow color
464 gdk_gc_set_foreground(drawing
->gc
,&histo_drawing_colors
[COL_WHITE
] );//COL_RUN_TRAP
465 gdk_draw_line (drawing
->pixmap
,
471 gdk_gc_set_foreground(drawing
->gc
,&histo_drawing_colors
[COL_RUN_USER_MODE
] );
472 gdk_draw_line (drawing
->pixmap
,
478 while ((ltt_time_compare(t1
,t2
)==0)&&(i
<end_chunk
))//-1 , i to be incremented later
482 if(val
> drawing
->histo_control_flow_data
->max_height
){
483 //overlimit, yellow color
484 gdk_gc_set_foreground(drawing
->gc
,
485 &histo_drawing_colors
[COL_RUN_TRAP
] );
486 gdk_draw_line (drawing
->pixmap
,
492 gdk_gc_set_foreground(drawing
->gc
,&histo_drawing_colors
[COL_RUN_USER_MODE
] );
493 gdk_draw_line (drawing
->pixmap
,
498 histo_convert_pixels_to_time(width
, i
,
502 histo_convert_pixels_to_time(width
, i
+1,
506 }//while (t1==t2)////
510 histo_drawing_update_vertical_ruler(drawing
);
511 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
513 draw_end
-draw_begin
, drawing
->height
);
514 gdk_window_process_updates(drawingarea
->window
,TRUE
);
517 int histo_event_selected_hook(void *hook_data
, void *call_data
)
519 HistoControlFlowData
*histocontrol_flow_data
= (HistoControlFlowData
*) hook_data
;
520 guint
*event_number
= (guint
*) call_data
;
522 g_debug("DEBUG : event selected by main window : %u", *event_number
);
529 /* histo_before_schedchange_hook
531 * This function basically draw lines and icons. Two types of lines are drawn :
532 * one small (3 pixels?) representing the state of the process and the second
533 * type is thicker (10 pixels?) representing on which CPU a process is running
534 * (and this only in running state).
536 * Extremums of the lines :
537 * x_min : time of the last event context for this process kept in memory.
538 * x_max : time of the current event.
539 * y : middle of the process in the process list. The process is found in the
540 * list, therefore is it's position in pixels.
542 * The choice of lines'color is defined by the context of the last event for this
547 int histo_before_schedchange_hook(void *hook_data, void *call_data)
553 gint
histo_update_time_window_hook(void *hook_data
, void *call_data
)
555 HistoControlFlowData
*histocontrol_flow_data
= (HistoControlFlowData
*) hook_data
;
556 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
558 const TimeWindowNotifyData
*histo_time_window_nofify_data
=
559 ((const TimeWindowNotifyData
*)call_data
);
561 TimeWindow
*histo_old_time_window
=
562 histo_time_window_nofify_data
->old_time_window
;
563 TimeWindow
*histo_new_time_window
=
564 histo_time_window_nofify_data
->new_time_window
;
567 histo_drawing_update_ruler(drawing
,
568 histo_new_time_window
);
570 /* Two cases : zoom in/out or scrolling */
572 /* In order to make sure we can reuse the old drawing, the scale must
573 * be the same and the new time interval being partly located in the
574 * currently shown time interval. (reuse is only for scrolling)
577 g_info("Old time window HOOK : %lu, %lu to %lu, %lu",
578 histo_old_time_window
->start_time
.tv_sec
,
579 histo_old_time_window
->start_time
.tv_nsec
,
580 histo_old_time_window
->time_width
.tv_sec
,
581 histo_old_time_window
->time_width
.tv_nsec
);
583 g_info("New time window HOOK : %lu, %lu to %lu, %lu",
584 histo_new_time_window
->start_time
.tv_sec
,
585 histo_new_time_window
->start_time
.tv_nsec
,
586 histo_new_time_window
->time_width
.tv_sec
,
587 histo_new_time_window
->time_width
.tv_nsec
);
589 //For Histo,redraw always except if zoom fit is pushed 2 times consequently
590 if( histo_new_time_window
->start_time
.tv_sec
== histo_old_time_window
->start_time
.tv_sec
591 && histo_new_time_window
->start_time
.tv_nsec
== histo_old_time_window
->start_time
.tv_nsec
592 && histo_new_time_window
->time_width
.tv_sec
== histo_old_time_window
->time_width
.tv_sec
593 && histo_new_time_window
->time_width
.tv_nsec
== histo_old_time_window
->time_width
.tv_nsec
)
597 histo_rectangle_pixmap (drawing
->drawing_area
->style
->black_gc
,
600 drawing
->width
,//+SAFETY, // do not overlap
603 drawing
->damage_begin
= 0;
604 drawing
->damage_end
= drawing
->width
;
606 gtk_widget_queue_draw(drawing
->drawing_area
);
607 histo_request_event(histocontrol_flow_data
,drawing
->damage_begin
,
608 drawing
->damage_end
- drawing
->damage_begin
);
610 gdk_window_process_updates(drawing
->drawing_area
->window
,TRUE
);
612 //show number of event at current time
614 histo_drawing_update_vertical_ruler(drawing
);
618 /*// if( histo_new_time_window->time_width.tv_sec == histo_old_time_window->time_width.tv_sec
619 && histo_new_time_window->time_width.tv_nsec == histo_old_time_window->time_width.tv_nsec)
621 // Same scale (scrolling)
624 while scrolling no matter far or near ,
625 right or left it's necessary to redraw whole screen!*/
626 /*// LttTime *ns = &histo_new_time_window->start_time;
627 LttTime *nw = &histo_new_time_window->time_width;
628 LttTime *os = &histo_old_time_window->start_time;
629 LttTime *ow = &histo_old_time_window->time_width;
630 LttTime histo_old_end = histo_old_time_window->end_time;
631 LttTime histo_new_end = histo_new_time_window->end_time;
633 //if(ns<os+w && os+w<ns+w)
634 //if(ns<histo_old_end && os<ns)
636 //added for histogram
637 gtk_widget_queue_draw(drawing->drawing_area);
639 drawing->damage_begin = 0;
640 drawing->damage_end = drawing->width;
642 //replaced for hisogram
643 histo_request_event(histocontrol_flow_data,drawing->damage_begin,
644 drawing->damage_end- drawing->damage_begin);
646 if(ltt_time_compare(*ns, histo_old_end) == -1
647 && ltt_time_compare(*os, *ns) == -1)
649 g_info("scrolling near right");
650 // Scroll right, keep right part of the screen
652 guint width = drawing->width;
653 histo_convert_time_to_pixels(
654 *histo_old_time_window,
659 // Copy old data to new location
660 //replaced for histogram:
661 histo_copy_pixmap_region(drawing,NULL,
662 drawing->drawing_area->style->black_gc,//drawing->gc,
665 0, 0, (drawing->width-x)
668 if(drawing->damage_begin == drawing->damage_end)
669 drawing->damage_begin = drawing->width-x;
671 drawing->damage_begin = 0;
673 drawing->damage_end = drawing->width;
675 //(histo) copy corresponding array region too:
678 for(i=0; i < histocontrol_flow_data->number_of_process->len-x;i++)
680 g_array_index(histocontrol_flow_data->number_of_process, guint, i) =
681 g_array_index(histocontrol_flow_data->number_of_process, guint, i+x);
684 // Clear the data request background, but not SAFETY
687 //not necessary for histo, because in before chunk ,it clears the area
688 /* histo_rectangle_pixmap (
689 drawing->drawing_area->style->black_gc,
691 drawing->damage_begin, 0,
692 drawing->damage_end - drawing->damage_begin, // do not overlap
695 /* gtk_widget_queue_draw(drawing->drawing_area);
696 //gtk_widget_queue_draw_area (drawing->drawing_area,
698 // histocontrol_flow_data->drawing->width,
699 // histocontrol_flow_data->drawing->height);
701 // Get new data for the rest.
702 //replaced for hisogram
703 histo_request_event(histocontrol_flow_data,drawing->damage_begin,
704 drawing->damage_end- drawing->damage_begin);
707 //if(ns<os && os<ns+w)
708 //if(ns<os && os<histo_new_end)
709 if(ltt_time_compare(*ns,*os) == -1
710 && ltt_time_compare(*os,histo_new_end) == -1)
712 g_info("scrolling near left");
713 // Scroll left, keep left part of the screen
715 guint width = drawing->width;
716 histo_convert_time_to_pixels(
717 *histo_new_time_window,
722 // Copy old data to new location
723 //replaced for histogram
725 histo_copy_pixmap_region(drawing,NULL,
726 drawing->drawing_area->style->black_gc,//drawing->gc,
730 //(histo) copy corresponding array region too:
732 for(i=histocontrol_flow_data->number_of_process->len; i > x-1;i--)
734 g_array_index(histocontrol_flow_data->number_of_process, guint, i) =
735 g_array_index(histocontrol_flow_data->number_of_process, guint, i-x);
738 if(drawing->damage_begin == drawing->damage_end)
739 drawing->damage_end = x;
741 drawing->damage_end =
744 drawing->damage_begin = 0;
747 //not necessary for histo, because in before chunk ,it clears the area
748 /* histo_rectangle_pixmap (drawing->drawing_area->style->black_gc,
750 drawing->damage_begin, 0,
751 drawing->damage_end - drawing->damage_begin, // do not overlap
754 /* gtk_widget_queue_draw(drawing->drawing_area);
755 //gtk_widget_queue_draw_area (drawing->drawing_area,
757 // histocontrol_flow_data->drawing->width,
758 // histocontrol_flow_data->drawing->height);
761 // Get new data for the rest.
763 //replaced for hisogram
764 histo_request_event(histocontrol_flow_data,drawing->damage_begin,
765 drawing->damage_end- drawing->damage_begin);
768 if(ltt_time_compare(*ns,*os) == 0)
770 g_info("not scrolling");
772 g_info("scrolling far");
773 // Cannot reuse any part of the screen : far jump
775 //not necessary for histo, because in before chunk ,it clears the area
776 /* histo_rectangle_pixmap (histocontrol_flow_data->drawing->drawing_area->style->black_gc,
779 histocontrol_flow_data->drawing->width,//+SAFETY, // do not overlap
782 //gtk_widget_queue_draw_area (drawing->drawing_area,
784 // histocontrol_flow_data->drawing->width,
785 // histocontrol_flow_data->drawing->height);
786 /* gtk_widget_queue_draw(drawing->drawing_area);
788 drawing->damage_begin = 0;
789 drawing->damage_end = histocontrol_flow_data->drawing->width;
791 histo_drawing_data_request(histocontrol_flow_data->drawing,
793 histocontrol_flow_data->drawing->width,
794 histocontrol_flow_data->drawing->height);*/
795 //replaced for hisogram
796 /* histo_request_event(histocontrol_flow_data,drawing->damage_begin,
797 drawing->damage_end- drawing->damage_begin);
802 // Different scale (zoom)
805 //not necessary for histo, because in before chunk ,it clears the area
807 histo_rectangle_pixmap (drawing->drawing_area->style->black_gc,
810 histocontrol_flow_data->drawing->width+SAFETY, // do not overlap
813 //gtk_widget_queue_draw_area (drawing->drawing_area,
815 // histocontrol_flow_data->drawing->width,
816 // histocontrol_flow_data->drawing->height);
817 /*// gtk_widget_queue_draw(drawing->drawing_area);
819 drawing->damage_begin = 0;
820 drawing->damage_end = drawing->width;
822 //replaced for hisogram
823 histo_request_event(histocontrol_flow_data,drawing->damage_begin,
824 drawing->damage_end- drawing->damage_begin);
827 // Update directly when scrolling
828 gdk_window_process_updates(drawing->drawing_area->window,
831 //show number of event at current time
833 histo_drawing_update_vertical_ruler(drawing);
835 //disabled for histogram, always redraw whole screen.
839 gint
histo_traceset_notify(void *hook_data
, void *call_data
)
841 HistoControlFlowData
*histocontrol_flow_data
= (HistoControlFlowData
*) hook_data
;
842 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
844 if(unlikely(drawing
->gc
== NULL
)) {
847 if(drawing
->dotted_gc
== NULL
) {
851 histo_drawing_clear(drawing
,0,drawing
->width
);
854 for(i
=0;i
< histocontrol_flow_data
->number_of_process
->len
;i
++)
856 g_array_index(histocontrol_flow_data
->number_of_process
, guint
, i
) = 0;
858 gtk_widget_set_size_request(
859 drawing
->drawing_area
,
861 histo_redraw_notify(histocontrol_flow_data
, NULL
);
863 ///histo_request_background_data(histocontrol_flow_data);
868 gint
histo_redraw_notify(void *hook_data
, void *call_data
)
870 HistoControlFlowData
*histocontrol_flow_data
= (HistoControlFlowData
*) hook_data
;
871 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
872 GtkWidget
*widget
= drawing
->drawing_area
;
874 drawing
->damage_begin
= 0;
875 drawing
->damage_end
= drawing
->width
;
877 // fun feature, to be separated someday...
879 histo_drawing_clear(drawing
,0,drawing
->width
);
881 gtk_widget_set_size_request(
882 drawing
->drawing_area
,
886 histo_rectangle_pixmap (widget
->style
->black_gc
,
889 drawing
->alloc_width
,
891 gtk_widget_queue_draw(widget
);
894 if(drawing
->damage_begin
< drawing
->damage_end
)
896 //replaced for histogram
897 histo_request_event(histocontrol_flow_data
,0,drawing
->width
);
901 //gtk_widget_queue_draw_area(drawing->drawing_area,
910 gint
histo_continue_notify(void *hook_data
, void *call_data
)
912 HistoControlFlowData
*histocontrol_flow_data
= (HistoControlFlowData
*) hook_data
;
913 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
915 //g_assert(widget->allocation.width == drawing->damage_end);
917 if(drawing
->damage_begin
< drawing
->damage_end
)
919 histo_request_event(histocontrol_flow_data
,drawing
->damage_begin
,
920 drawing
->damage_end
-drawing
->damage_begin
);
927 gint
histo_update_current_time_hook(void *hook_data
, void *call_data
)
929 HistoControlFlowData
*histocontrol_flow_data
= (HistoControlFlowData
*)hook_data
;
930 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
932 LttTime current_time
= *((LttTime
*)call_data
);
934 TimeWindow time_window
=
935 lttvwindow_get_time_window(histocontrol_flow_data
->tab
);
937 LttTime time_begin
= time_window
.start_time
;
938 LttTime width
= time_window
.time_width
;
941 guint64 time_ll
= ltt_time_to_uint64(width
);
942 time_ll
= time_ll
>> 1; /* divide by two */
943 half_width
= ltt_time_from_uint64(time_ll
);
945 LttTime time_end
= ltt_time_add(time_begin
, width
);
947 LttvTracesetContext
* tsc
=
948 lttvwindow_get_traceset_context(histocontrol_flow_data
->tab
);
950 LttTime trace_start
= tsc
->time_span
.start_time
;
951 LttTime trace_end
= tsc
->time_span
.end_time
;
953 g_info("Histogram: New current time HOOK : %lu, %lu", current_time
.tv_sec
,
954 current_time
.tv_nsec
);
958 /* If current time is inside time interval, just move the highlight
961 /* Else, we have to change the time interval. We have to tell it
962 * to the main window. */
963 /* The time interval change will take care of placing the current
964 * time at the center of the visible area, or nearest possible if we are
965 * at one end of the trace. */
968 if(ltt_time_compare(current_time
, time_begin
) < 0)
970 TimeWindow histo_new_time_window
;
972 if(ltt_time_compare(current_time
,
973 ltt_time_add(trace_start
,half_width
)) < 0)
974 time_begin
= trace_start
;
976 time_begin
= ltt_time_sub(current_time
,half_width
);
978 histo_new_time_window
.start_time
= time_begin
;
979 histo_new_time_window
.time_width
= width
;
980 histo_new_time_window
.time_width_double
= ltt_time_to_double(width
);
981 histo_new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
983 lttvwindow_report_time_window(histocontrol_flow_data
->tab
, histo_new_time_window
);
985 else if(ltt_time_compare(current_time
, time_end
) > 0)
987 TimeWindow histo_new_time_window
;
989 if(ltt_time_compare(current_time
, ltt_time_sub(trace_end
, half_width
)) > 0)
990 time_begin
= ltt_time_sub(trace_end
,width
);
992 time_begin
= ltt_time_sub(current_time
,half_width
);
994 histo_new_time_window
.start_time
= time_begin
;
995 histo_new_time_window
.time_width
= width
;
996 histo_new_time_window
.time_width_double
= ltt_time_to_double(width
);
997 histo_new_time_window
.end_time
= ltt_time_add(time_begin
, width
);
999 lttvwindow_report_time_window(histocontrol_flow_data
->tab
, histo_new_time_window
);
1002 gtk_widget_queue_draw(drawing
->drawing_area
);
1004 /* Update directly when scrolling */
1005 gdk_window_process_updates(drawing
->drawing_area
->window
,
1008 histo_drawing_update_vertical_ruler(drawing
);
1013 gboolean
histo_filter_changed(void * hook_data
, void * call_data
)
1015 HistoControlFlowData
*histocontrol_flow_data
= (HistoControlFlowData
*)hook_data
;
1016 histoDrawing_t
*drawing
=histocontrol_flow_data
->drawing
;
1018 LttvTracesetContext
* tsc
=
1019 lttvwindow_get_traceset_context(histocontrol_flow_data
->tab
);
1021 histocontrol_flow_data
->histo_main_win_filter
=
1022 (LttvFilter
*)call_data
;
1023 //get_events(event_viewer_data->vadjust_c->value, event_viewer_data);
1024 gtk_widget_set_size_request(
1025 drawing
->drawing_area
,
1027 drawing
->damage_begin
= 0;
1028 drawing
->damage_end
= drawing
->width
;
1030 /* //done in, before request!
1031 histo_drawing_clear(drawing,0,drawing->width);
1033 for(i=0;i < histocontrol_flow_data->number_of_process->len;i++)
1035 g_array_index(histocontrol_flow_data->number_of_process, guint, i) = 0;
1038 histo_request_event(histocontrol_flow_data
,0,drawing
->width
);
1043 typedef struct _histo_ClosureData
{
1044 EventsRequest
*events_request
;
1045 LttvTracesetState
*tss
;
1048 } histo_ClosureData
;
1052 int histo_before_chunk(void *hook_data
, void *call_data
)
1054 EventsRequest
*histo_events_request
= (EventsRequest
*)hook_data
;
1055 LttvTracesetState
*histo_tss
= (LttvTracesetState
*)call_data
;
1056 HistoControlFlowData
*histo_cfd
= (HistoControlFlowData
*)histo_events_request
->viewer_data
;
1058 /* Desactivate sort */
1059 gtk_tree_sortable_set_sort_column_id(
1060 GTK_TREE_SORTABLE(cfd
->process_list
->list_store
),
1062 GTK_SORT_ASCENDING
);
1064 histo_drawing_chunk_begin(histo_events_request
, histo_tss
);
1069 /*int histo_before_request(void *hook_data, void *call_data)
1071 EventsRequest *events_request = (EventsRequest*)hook_data;
1072 LttvTracesetState *tss = (LttvTracesetState*)call_data;
1074 histo_drawing_data_request_begin(events_request, tss);
1082 * after request is necessary in addition of after chunk in order to draw
1083 * lines until the end of the screen. after chunk just draws lines until
1090 /*int histo_after_request(void *hook_data, void *call_data)
1101 int histo_after_chunk(void *hook_data
, void *call_data
)
1103 EventsRequest
*events_request
= (EventsRequest
*)hook_data
;
1104 HistoControlFlowData
*histocontrol_flow_data
= events_request
->viewer_data
;
1105 LttvTracesetState
*tss
= (LttvTracesetState
*)call_data
;
1106 LttvTracesetContext
*tsc
= (LttvTracesetContext
*)call_data
;
1107 LttvTracefileContext
*tfc
= lttv_traceset_context_get_current_tfc(tsc
);
1110 histoDrawing_t
*drawing
= histocontrol_flow_data
->drawing
;
1112 if(!histocontrol_flow_data
->chunk_has_begun
) return;
1113 histocontrol_flow_data
->chunk_has_begun
= TRUE
;
1116 end_time
= LTT_TIME_MIN(tfc
->timestamp
, events_request
->end_time
);
1117 else /* end of traceset, or position now out of request : end */
1118 end_time
= events_request
->end_time
;
1120 guint x
, x_end
, width
;
1122 TimeWindow time_window
=
1123 lttvwindow_get_time_window(histocontrol_flow_data
->tab
);
1125 g_debug("histo after chunk");
1127 histo_convert_time_to_pixels(
1132 x
= drawing
->damage_begin
;
1134 drawing
->damage_begin
= x
+width
;
1136 histogram_show (histocontrol_flow_data
,x
,x_end
);