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,
27 #include <ltt/trace.h>
29 #include <lttv/lttv.h>
30 #include <lttvwindow/lttvwindow.h>
31 #include <lttv/state.h>
32 #include <lttv/hook.h>
34 #include "histodrawing.h"
35 #include "histoeventhooks.h"
39 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
42 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
46 // fixed #define TRACE_NUMBER 0
47 #define EXTRA_ALLOC 1024 // pixels
48 #define padding_width 50
50 #if 0 /* colors for two lines representation */
51 GdkColor histo_drawing_colors
[NUM_COLORS
] =
52 { /* Pixel, R, G, B */
53 { 0, 0, 0, 0 }, /* COL_BLACK */
54 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
55 { 0, 0x0FFF, 0xFFFF, 0xFFFF }, /* COL_WAIT_FORK : pale blue */
56 { 0, 0xFFFF, 0xFFFF, 0x0000 }, /* COL_WAIT_CPU : yellow */
57 { 0, 0xFFFF, 0xA000, 0xFCFF }, /* COL_EXIT : pale magenta */
58 { 0, 0xFFFF, 0x0000, 0xFFFF }, /* COL_ZOMBIE : purple */
59 { 0, 0xFFFF, 0x0000, 0x0000 }, /* COL_WAIT : red */
60 { 0, 0x0000, 0xFFFF, 0x0000 }, /* COL_RUN : green */
61 { 0, 0x8800, 0xFFFF, 0x8A00 }, /* COL_USER_MODE : pale green */
62 { 0, 0x09FF, 0x01FF, 0xFFFF }, /* COL_SYSCALL : blue */
63 { 0, 0xF900, 0x4200, 0xFF00 }, /* COL_TRAP : pale purple */
64 { 0, 0xFFFF, 0x5AFF, 0x01FF }, /* COL_IRQ : orange */
65 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_MODE_UNKNOWN : white */
71 GdkColor histo_drawing_colors
[NUM_COLORS
] =
72 { /* Pixel, R, G, B */
73 { 0, 0, 0, 0 }, /* COL_BLACK */
74 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
75 { 0, 0x0000, 0xFF00, 0x0000 }, /* COL_RUN_USER_MODE : green */
76 { 0, 0x0100, 0x9E00, 0xFFFF }, /* COL_RUN_SYSCALL : pale blue */
77 { 0, 0xFF00, 0xFF00, 0x0100 }, /* COL_RUN_TRAP : yellow */
78 { 0, 0xFFFF, 0x5E00, 0x0000 }, /* COL_RUN_IRQ : red */
79 { 0, 0x6600, 0x0000, 0x0000 }, /* COL_WAIT : dark red */
80 { 0, 0x7700, 0x7700, 0x0000 }, /* COL_WAIT_CPU : dark yellow */
81 { 0, 0x6400, 0x0000, 0x5D00 }, /* COL_ZOMBIE : dark purple */
82 { 0, 0x0700, 0x6400, 0x0000 }, /* COL_WAIT_FORK : dark green */
83 { 0, 0x8900, 0x0000, 0x8400 }, /* COL_EXIT : "less dark" magenta */
84 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_MODE_UNKNOWN : white */
85 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_UNNAMED : white */
95 WAIT CPU + WAIT FORK vert foncé ou jaune
104 /*****************************************************************************
105 * drawing functions *
106 *****************************************************************************/
109 histo_expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
);
112 histo_expose_vertical_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
);
115 histo_motion_notify_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
);
118 histo_motion_notify_vertical_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
);
120 /* Function responsible for updating the exposed area.
121 * It must do an events request to the lttvwindow API to ask for this update.
122 * Note : this function cannot clear the background, because it may
123 * erase drawing already present (SAFETY).
125 void histo_drawing_data_request(histoDrawing_t
*drawing
,
134 void histo_drawing_data_request_begin(EventsRequest
*events_request
, LttvTraceset
*traceset
)
136 g_debug("Begin of data request");
137 HistoControlFlowData
*cfd
= events_request
->viewer_data
;
138 TimeWindow time_window
=
139 lttvwindow_get_time_window(cfd
->tab
);
141 guint width
= cfd
->drawing
->width
;
144 cfd
->drawing
->last_start
= events_request
->start_time
;
146 histo_convert_time_to_pixels(
148 events_request
->start_time
,
154 void histo_drawing_chunk_begin(EventsRequest
*events_request
, LttvTraceset
*traceset
)
156 g_debug("Begin of chunk");
157 HistoControlFlowData
*cfd
= events_request
->viewer_data
;
159 if(cfd
->chunk_has_begun
) return;
161 cfd
->chunk_has_begun
= TRUE
;
165 void histo_drawing_request_expose(EventsRequest
*events_request
,
166 LttvTraceset
*traceset
,
169 HistoControlFlowData
*cfd
= events_request
->viewer_data
;
170 histoDrawing_t
*drawing
= cfd
->drawing
;
172 guint x
, x_end
, width
;
174 TimeWindow time_window
=
175 lttvwindow_get_time_window(cfd
->tab
);
177 g_debug("histo request expose");
179 histo_convert_time_to_pixels(
184 x
= drawing
->damage_begin
;
188 drawing
->damage_begin
= x
+width
;
191 //changed for histogram:
192 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
195 drawing
->/*drawing_area->allocation.*/height
);
197 // Update directly when scrolling
198 gdk_window_process_updates(drawing
->drawing_area
->window
,
206 /* Create a new backing pixmap of the appropriate size */
207 /* As the scaling will always change, it's of no use to copy old
210 * Change the size if width or height changes.
211 * (different from control flow viewer!)
214 histo_configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
217 histoDrawing_t
*drawing
= (histoDrawing_t
*)user_data
;
219 /* First, get the new time interval of the main window */
220 /* we assume (see documentation) that the main window
221 * has updated the time interval before this configure gets
224 //lttvwindow_get_time_window(drawing->histo_control_flow_data->mw,
225 // &drawing->histo_control_flow_data->time_window);
227 /* New pixmap, size of the configure event */
228 //GdkPixmap *pixmap = gdk_pixmap_new(widget->window,
229 // widget->allocation.width + SAFETY,
230 // widget->allocation.height + SAFETY,
232 g_debug("drawing configure event");
233 g_debug("New alloc draw size : %i by %i",widget
->allocation
.width
,
234 widget
->allocation
.height
);
236 /*modified for histogram, if width is not changed, GArray is valid so
237 just redraw, else recalculate all.(event request again)*/
239 //enabled again for histogram:
241 gdk_pixmap_unref(drawing
->pixmap
);
243 drawing
->pixmap
= gdk_pixmap_new(widget
->window
,
244 widget
->allocation
.width
,//+ SAFETY + EXTRA_ALLOC,
245 widget
->allocation
.height
+ EXTRA_ALLOC
,
249 drawing
->alloc_width
= drawing
->width
+ SAFETY
+ EXTRA_ALLOC
;
250 drawing
->alloc_height
= drawing
->height
+ EXTRA_ALLOC
;
252 //drawing->height = widget->allocation.height;
257 // gdk_draw_rectangle (drawing->pixmap,
258 // widget->style->black_gc,
261 // drawing->width+SAFETY,
264 //g_info("init data request");
267 /* Initial data request */
268 /* no, do initial data request in the expose event */
269 // Do not need to ask for data of 1 pixel : not synchronized with
270 // main window time at this moment.
271 //histo_drawing_data_request(drawing, &drawing->pixmap, 0, 0,
272 // widget->allocation.width,
273 // widget->allocation.height);
275 //drawing->width = widget->allocation.width;
276 //drawing->height = widget->allocation.height;
278 drawing
->damage_begin
= 0;
279 drawing
->damage_end
= widget
->allocation
.width
;
281 if((widget
->allocation
.width
!= 1 &&
282 widget
->allocation
.height
!= 1)
283 /*&& drawing->damage_begin < drawing->damage_end */)
286 gdk_draw_rectangle (drawing
->pixmap
,
287 drawing
->drawing_area
->style
->black_gc
,
290 drawing
->drawing_area
->allocation
.width
, drawing
->drawing_area
->allocation
.height
);
291 /* histo_drawing_data_request(drawing,
292 drawing->damage_begin,
294 drawing->damage_end - drawing->damage_begin,
297 //modified for histogram
299 if(widget
->allocation
.width
== drawing
->width
)
302 drawing
->height
= widget
->allocation
.height
;
303 histogram_show( drawing
->histo_control_flow_data
,0,
304 drawing
->histo_control_flow_data
->number_of_process
->len
);
308 drawing
->width
= widget
->allocation
.width
;
309 drawing
->height
= widget
->allocation
.height
;
311 g_array_set_size (drawing
->histo_control_flow_data
->number_of_process
,
312 widget
->allocation
.width
);
313 histo_request_event( drawing
->histo_control_flow_data
,drawing
->damage_begin
314 ,drawing
->damage_end
- drawing
->damage_begin
);
320 /* Redraw the screen from the backing pixmap */
322 histo_expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
324 histoDrawing_t
*drawing
= (histoDrawing_t
*)user_data
;
326 HistoControlFlowData
*histo_control_flow_data
=
327 (HistoControlFlowData
*)g_object_get_data(
329 "histo_control_flow_data");
331 if(unlikely(drawing
->gc
== NULL
)) {
332 drawing
->gc
= gdk_gc_new(drawing
->drawing_area
->window
);
333 gdk_gc_copy(drawing
->gc
, drawing
->drawing_area
->style
->black_gc
);
336 TimeWindow time_window
=
337 lttvwindow_get_time_window(histo_control_flow_data
->tab
);
338 LttTime current_time
=
339 lttvwindow_get_current_time(histo_control_flow_data
->tab
);
343 LttTime window_end
= time_window
.end_time
;
346 /* update the screen from the pixmap buffer */
347 //added again for histogram:
349 gdk_draw_pixmap(widget
->window
,
350 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
352 event
->area
.x
, event
->area
.y
,
353 event
->area
.x
, event
->area
.y
,
354 event
->area
.width
, event
->area
.height
);
357 drawing
->height
= drawing
-> drawing_area
->allocation
.height
;
360 copy_pixmap_to_screen(histo_control_flow_data
->process_list
,
362 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
363 event
->area
.x
, event
->area
.y
,
364 event
->area
.width
, event
->area
.height
);
368 /* //disabled for histogram
369 copy_pixmap_to_screen(histo_control_flow_data->process_list,
372 event->area.x, event->area.y,
373 event->area.width, event->area.height);*/
375 /* Erase the dotted lines left.. */
376 if(widget
->allocation
.height
> drawing
->height
)
378 gdk_draw_rectangle (widget
->window
,
379 drawing
->drawing_area
->style
->black_gc
,
381 event
->area
.x
, drawing
->height
,
382 event
->area
.width
, // do not overlap
383 widget
->allocation
.height
- drawing
->height
);
385 if(ltt_time_compare(time_window
.start_time
, current_time
) <= 0 &&
386 ltt_time_compare(window_end
, current_time
) >= 0)
388 /* Draw the dotted lines */
389 histo_convert_time_to_pixels(
396 if(drawing
->dotted_gc
== NULL
) {
398 drawing
->dotted_gc
= gdk_gc_new(drawing
->drawing_area
->window
);
399 gdk_gc_copy(drawing
->dotted_gc
, widget
->style
->white_gc
);
401 gint8 dash_list
[] = { 1, 2 };
402 gdk_gc_set_line_attributes(drawing
->dotted_gc
,
404 GDK_LINE_ON_OFF_DASH
,
407 gdk_gc_set_dashes(drawing
->dotted_gc
,
413 gint height_tot
= MAX(widget
->allocation
.height
, drawing
->height
);
414 gdk_draw_line(widget
->window
,
417 cursor_x
, height_tot
);
424 histo_after_expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
427 g_debug("AFTER EXPOSE");
434 histo_button_press_event( GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
436 HistoControlFlowData
*histo_control_flow_data
=
437 (HistoControlFlowData
*)g_object_get_data(
439 "histo_control_flow_data");
440 histoDrawing_t
*drawing
= histo_control_flow_data
->drawing
;
441 TimeWindow time_window
=
442 lttvwindow_get_time_window(histo_control_flow_data
->tab
);
445 if(event
->button
== 1)
449 /* left mouse button click */
450 g_debug("x click is : %f", event
->x
);
452 histo_convert_pixels_to_time(drawing
->width
, (guint
)event
->x
,
456 lttvwindow_report_current_time(histo_control_flow_data
->tab
, time
);
457 ////report event->y for vertical zoom +,-
463 //Viewer's vertical scroll bar is already omitted, not needed for histogram.
465 scrollbar_size_allocate(GtkWidget *widget,
466 GtkAllocation *allocation,
469 histoDrawing_t *drawing = (histoDrawing_t*)user_data;
471 gtk_widget_set_size_request(drawing->padding, allocation->width, -1);
472 //gtk_widget_queue_resize(drawing->padding);
473 //gtk_widget_queue_resize(drawing->ruler);
474 gtk_container_check_resize(GTK_CONTAINER(drawing->ruler_hbox));
480 histoDrawing_t
*histo_drawing_construct(HistoControlFlowData
*histo_control_flow_data
)
482 histoDrawing_t
*drawing
= g_new(histoDrawing_t
, 1);
484 drawing
->histo_control_flow_data
= histo_control_flow_data
;
486 drawing
->vbox
= gtk_vbox_new(FALSE
, 1);
489 drawing
->ruler_hbox
= gtk_hbox_new(FALSE
, 1);
490 drawing
->ruler
= gtk_drawing_area_new ();
491 //gtk_widget_set_size_request(drawing->ruler, -1, 27);
493 drawing
->padding
= gtk_drawing_area_new ();
494 //gtk_widget_set_size_request(drawing->padding, -1, 27);
496 gtk_box_pack_start(GTK_BOX(drawing
->ruler_hbox
), drawing
->padding
,FALSE
, FALSE
, 0);
498 gtk_box_pack_end(GTK_BOX(drawing
->ruler_hbox
), drawing
->ruler
,
501 drawing
->drawing_area
= gtk_drawing_area_new ();
505 ///at this time not necessary for histogram
506 drawing->hbox = gtk_hbox_new(FALSE, 1);
508 drawing->viewport = gtk_viewport_new(NULL, histo_control_flow_data->v_adjust);
509 drawing->scrollbar = gtk_vscrollbar_new(histo_control_flow_data->v_adjust);
510 gtk_box_pack_start(GTK_BOX(drawing->hbox), drawing->viewport,
512 gtk_box_pack_end(GTK_BOX(drawing->hbox), drawing->scrollbar,
514 gtk_container_add(GTK_CONTAINER(drawing->viewport),
515 drawing->drawing_area);*/
517 //add vertical ruler:
518 drawing
->vruler_drawing_hbox
= gtk_hbox_new(FALSE
, 1);
519 drawing
-> vertical_ruler
=gtk_drawing_area_new ();
520 gtk_box_pack_start(GTK_BOX(drawing
->vruler_drawing_hbox
), drawing
->vertical_ruler
,
522 gtk_box_pack_end(GTK_BOX(drawing
->vruler_drawing_hbox
), drawing
->drawing_area
,
524 gtk_widget_set_size_request(drawing
->vertical_ruler
, padding_width
, -1);
526 gtk_box_pack_start(GTK_BOX(drawing
->vbox
), drawing
->ruler_hbox
,
528 gtk_box_pack_end(GTK_BOX(drawing
->vbox
), drawing
->vruler_drawing_hbox
/*drawing_area*/,
531 drawing
->pango_layout
=
532 gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
537 drawing
->alloc_height
= 1;
538 drawing
->alloc_width
= 1;
540 drawing
->damage_begin
= 0;
541 drawing
->damage_end
= 0;
542 drawing
->horizontal_sel
= -1;
544 //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50);
545 g_object_set_data_full(
546 G_OBJECT(drawing
->drawing_area
),
547 "histo_Link_drawing_Data",
549 (GDestroyNotify
)histo_drawing_destroy
);
552 G_OBJECT(drawing
->ruler
),
557 G_OBJECT(drawing
->vertical_ruler
),
561 //gtk_widget_modify_bg( drawing->drawing_area,
563 // &CF_Colors[BLACK]);
565 //gdk_window_get_geometry(drawing->drawing_area->window,
567 // &(drawing->width),
568 // &(drawing->height),
571 //drawing->pixmap = gdk_pixmap_new(
572 // drawing->drawing_area->window,
577 drawing
->pixmap
= NULL
;
579 // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
580 // drawing->drawing_area->allocation.width,
581 // drawing->drawing_area->allocation.height,
584 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
586 G_CALLBACK (histo_configure_event
),
589 g_signal_connect (G_OBJECT(drawing
->ruler
),
591 G_CALLBACK(histo_expose_ruler
),
594 gtk_widget_add_events(drawing
->ruler
, GDK_POINTER_MOTION_MASK
);
595 gtk_widget_add_events(drawing
->vertical_ruler
, GDK_POINTER_MOTION_MASK
);
597 g_signal_connect (G_OBJECT(drawing
->ruler
),
598 "motion-notify-event",
599 G_CALLBACK(histo_motion_notify_ruler
),
603 g_signal_connect (G_OBJECT(drawing
->vertical_ruler
),
605 G_CALLBACK(histo_expose_vertical_ruler
),
608 g_signal_connect (G_OBJECT(drawing
->vertical_ruler
),
609 "motion-notify-event",
610 G_CALLBACK(histo_motion_notify_vertical_ruler
),
613 /*//not necessary for historam.
614 g_signal_connect (G_OBJECT(drawing->drawing_area),
616 G_CALLBACK(scrollbar_size_allocate),
617 (gpointer)drawing); */
620 gtk_widget_set_size_request(drawing
->padding
, padding_width
, -1);//use it for vertical ruler
622 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
624 G_CALLBACK (histo_expose_event
),
627 g_signal_connect_after (G_OBJECT(drawing
->drawing_area
),
629 G_CALLBACK (histo_after_expose_event
),
632 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
633 "button-press-event",
634 G_CALLBACK (histo_button_press_event
),
637 gtk_widget_show(drawing
->ruler
);
638 gtk_widget_show(drawing
->padding
);
639 gtk_widget_show(drawing
->ruler_hbox
);
640 gtk_widget_show(drawing
->vertical_ruler
);
641 gtk_widget_show(drawing
->vruler_drawing_hbox
);
642 gtk_widget_show(drawing
->drawing_area
);
644 /// gtk_widget_show(drawing->viewport);
645 /// gtk_widget_show(drawing->scrollbar);
646 /// gtk_widget_show(drawing->hbox);
648 /* Allocate the colors */
649 GdkColormap
* colormap
= gdk_colormap_get_system();
650 gboolean success
[NUM_COLORS
];
651 gdk_colormap_alloc_colors(colormap
, histo_drawing_colors
, NUM_COLORS
, FALSE
,
655 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data
->tab
)->window
));
657 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data
->tab
)->window
));
659 gdk_gc_copy(drawing
->gc
,
660 main_window_get_widget(histo_control_flow_data
->tab
)->style
->black_gc
);
661 gdk_gc_copy(drawing
->dotted_gc
,
662 main_window_get_widget(histo_control_flow_data
->tab
)->style
->white_gc
);
664 gint8 dash_list
[] = { 1, 2 };
665 gdk_gc_set_line_attributes(drawing
->dotted_gc
,
667 GDK_LINE_ON_OFF_DASH
,
670 gdk_gc_set_dashes(drawing
->dotted_gc
,
675 drawing
->ruler_gc_butt
=
676 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data
->tab
)->window
));
677 gdk_gc_copy(drawing
->ruler_gc_butt
,
678 main_window_get_widget(histo_control_flow_data
->tab
)->style
->black_gc
);
679 drawing
->ruler_gc_round
=
680 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data
->tab
)->window
));
681 gdk_gc_copy(drawing
->ruler_gc_round
,
682 main_window_get_widget(histo_control_flow_data
->tab
)->style
->black_gc
);
685 gdk_gc_set_line_attributes(drawing
->ruler_gc_butt
,
691 gdk_gc_set_line_attributes(drawing
->ruler_gc_round
,
699 void histo_drawing_destroy(histoDrawing_t
*drawing
)
701 g_info("histo_drawing_destroy %p", drawing
);
703 /* Free the colors */
704 GdkColormap
* colormap
= gdk_colormap_get_system();
706 gdk_colormap_free_colors(colormap
, histo_drawing_colors
, NUM_COLORS
);
708 // Do not unref here, histoDrawing_t destroyed by it's widget.
709 //g_object_unref( G_OBJECT(drawing->drawing_area));
710 if(drawing
->gc
!= NULL
)
711 gdk_gc_unref(drawing
->gc
);
713 g_object_unref(drawing
->pango_layout
);
714 if(drawing
->dotted_gc
!= NULL
) gdk_gc_unref(drawing
->dotted_gc
);
715 if(drawing
->ruler_gc_butt
!= NULL
) gdk_gc_unref(drawing
->ruler_gc_butt
);
716 if(drawing
->ruler_gc_round
!= NULL
) gdk_gc_unref(drawing
->ruler_gc_round
);
718 //added for histogram
720 gdk_pixmap_unref(drawing
->pixmap
);
722 g_info("histo_drawing_destroy end");
725 GtkWidget
*histo_drawing_get_drawing_area(histoDrawing_t
*drawing
)
727 return drawing
->drawing_area
;
730 GtkWidget
*histo_drawing_get_widget(histoDrawing_t
*drawing
)
732 return drawing
->vbox
;
735 void histo_drawing_draw_line( histoDrawing_t
*drawing
,
741 gdk_draw_line (pixmap
,
746 void histo_drawing_clear(histoDrawing_t
*drawing
,guint clear_from
,guint clear_to
)
748 guint clear_width
= clear_to
- clear_from
;
750 //disabled for histogram
751 rectangle_pixmap(cfd->process_list,
752 drawing->drawing_area->style->black_gc,
755 drawing->alloc_width, // do not overlap
757 //instead, this is added for histogram
759 histo_rectangle_pixmap (drawing
->drawing_area
->style
->black_gc
,
762 clear_width
/*drawing->width*/,
767 /* gdk_draw_rectangle (drawing->pixmap,
768 drawing->drawing_area->style->black_gc,
771 drawing->drawing_area->allocation.width,drawing->drawing_area->allocation.height );
774 /* ask for the buffer to be redrawn */
775 //enabled again for histogram.
776 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
778 clear_width
, drawing
->height
);
779 gdk_window_process_updates(drawing
->drawing_area
->window
,TRUE
);
780 //disabled instead for histogram
781 //gtk_widget_queue_draw ( drawing->drawing_area);
786 /* Insert a square corresponding to a new process in the list */
787 /* Applies to whole drawing->width */
788 void drawing_insert_square(histoDrawing_t
*drawing
,
792 //GdkRectangle update_rect;
793 gboolean reallocate
= FALSE
;
794 GdkPixmap
*new_pixmap
;
796 /* Allocate a new pixmap with new height */
797 if(drawing
->alloc_height
< drawing
->height
+ height
) {
799 new_pixmap
= gdk_pixmap_new(drawing
->drawing_area
->window
,
800 drawing
->width
+ SAFETY
+ EXTRA_ALLOC
,
801 drawing
->height
+ height
+ EXTRA_ALLOC
,
803 drawing
->alloc_width
= drawing
->width
+ SAFETY
+ EXTRA_ALLOC
;
804 drawing
->alloc_height
= drawing
->height
+ height
+ EXTRA_ALLOC
;
807 /* Copy the high region */
808 gdk_draw_pixmap (new_pixmap
,
809 drawing
->drawing_area
->style
->black_gc
,
813 drawing
->width
+ SAFETY
, y
);
816 new_pixmap
= drawing
->pixmap
;
819 //GdkPixmap *pixmap = gdk_pixmap_new(drawing->drawing_area->window,
820 // drawing->width + SAFETY,
821 // drawing->height + height,
824 /* add an empty square */
825 gdk_draw_rectangle (new_pixmap
,
826 drawing
->drawing_area
->style
->black_gc
,
829 drawing
->width
+ SAFETY
, // do not overlap
832 /* copy the bottom of the region */
833 gdk_draw_pixmap (new_pixmap
,
834 drawing
->drawing_area
->style
->black_gc
,
838 drawing
->width
+SAFETY
, drawing
->height
- y
);
841 if(reallocate
&& likely(drawing
->pixmap
)) {
842 gdk_pixmap_unref(drawing
->pixmap
);
843 drawing
->pixmap
= new_pixmap
;
846 if(unlikely(drawing
->height
==1)) drawing
->height
= height
;
847 else drawing
->height
+= height
;
849 gtk_widget_set_size_request(drawing
->drawing_area
,
852 gtk_widget_queue_resize_no_redraw(drawing
->drawing_area
);
854 /* ask for the buffer to be redrawn */
855 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
857 drawing
->width
, drawing
->height
-y
);
861 /* Remove a square corresponding to a removed process in the list */
862 void drawing_remove_square(histoDrawing_t
*drawing
,
868 if(unlikely((guint
)drawing
->height
== height
)) {
869 //pixmap = gdk_pixmap_new(
870 // drawing->drawing_area->window,
871 // drawing->width + SAFETY,
874 pixmap
= drawing
->pixmap
;
877 /* Allocate a new pixmap with new height */
878 //pixmap = gdk_pixmap_new(
879 // drawing->drawing_area->window,
880 // drawing->width + SAFETY,
881 // drawing->height - height,
883 /* Keep the same preallocated pixmap */
884 pixmap
= drawing
->pixmap
;
886 /* Copy the high region */
887 gdk_draw_pixmap (pixmap
,
888 drawing
->drawing_area
->style
->black_gc
,
892 drawing
->width
+ SAFETY
, y
);
894 /* Copy up the bottom of the region */
895 gdk_draw_pixmap (pixmap
,
896 drawing
->drawing_area
->style
->black_gc
,
900 drawing
->width
, drawing
->height
- y
- height
);
902 drawing
->height
-=height
;
905 //if(likely(drawing->pixmap))
906 // gdk_pixmap_unref(drawing->pixmap);
908 //drawing->pixmap = pixmap;
910 gtk_widget_set_size_request(drawing
->drawing_area
,
913 gtk_widget_queue_resize_no_redraw(drawing
->drawing_area
);
914 /* ask for the buffer to be redrawn */
915 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
917 drawing
->width
, MAX(drawing
->height
-y
, 1));
921 void histo_drawing_update_ruler(histoDrawing_t
*drawing
, TimeWindow
*time_window
)
923 gtk_widget_queue_draw(drawing
->ruler
);
926 /* Redraw the ruler */
928 histo_expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
930 histoDrawing_t
*drawing
= (histoDrawing_t
*)user_data
;
931 TimeWindow time_window
= lttvwindow_get_time_window(drawing
->histo_control_flow_data
->tab
);
934 PangoContext
*context
;
936 PangoFontDescription
*FontDesc
;
937 PangoRectangle ink_rect
;
939 GdkColor foreground
= { 0, 0, 0, 0 };
940 GdkColor background
= { 0, 0xffff, 0xffff, 0xffff };
942 LttTime window_end
= time_window
.end_time
;
944 ltt_time_div(time_window
.time_width
,2.0);
945 LttTime window_middle
=
946 ltt_time_add(half_width
,
947 time_window
.start_time
);
948 g_debug("ruler expose event");
950 gdk_draw_rectangle (drawing
->ruler
->window
,
951 drawing
->ruler
->style
->white_gc
,
953 event
->area
.x
, event
->area
.y
,
957 gdk_draw_line (drawing
->ruler
->window
,
958 drawing
->ruler_gc_butt
,
960 event
->area
.x
+ event
->area
.width
, 1);
963 snprintf(text
, 255, "%lus\n%luns",
964 time_window
.start_time
.tv_sec
,
965 time_window
.start_time
.tv_nsec
);
967 layout
= gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
969 context
= pango_layout_get_context(layout
);
970 FontDesc
= pango_context_get_font_description(context
);
972 pango_font_description_set_size(FontDesc
, 6*PANGO_SCALE
);
973 pango_layout_context_changed(layout
);
975 pango_layout_set_text(layout
, text
, -1);
976 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
977 global_width
+= ink_rect
.width
;
979 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
980 drawing
->ruler_gc_butt
,
983 layout
, &foreground
, &background
);
985 gdk_draw_line (drawing
->ruler
->window
,
986 drawing
->ruler_gc_round
,
991 snprintf(text
, 255, "%lus\n%luns", window_end
.tv_sec
,
994 pango_layout_set_text(layout
, text
, -1);
995 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
996 global_width
+= ink_rect
.width
;
998 if(global_width
<= drawing
->ruler
->allocation
.width
)
1000 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
1001 drawing
->ruler_gc_butt
,
1002 drawing
->ruler
->allocation
.width
- ink_rect
.width
,
1004 layout
, &foreground
, &background
);
1006 gdk_draw_line (drawing
->ruler
->window
,
1007 drawing
->ruler_gc_butt
,
1008 drawing
->ruler
->allocation
.width
-1, 1,
1009 drawing
->ruler
->allocation
.width
-1, 7);
1013 snprintf(text
, 255, "%lus\n%luns", window_middle
.tv_sec
,
1014 window_middle
.tv_nsec
);
1016 pango_layout_set_text(layout
, text
, -1);
1017 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1018 global_width
+= ink_rect
.width
;
1020 if(global_width
<= drawing
->ruler
->allocation
.width
)
1022 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
1023 drawing
->ruler_gc_butt
,
1024 (drawing
->ruler
->allocation
.width
- ink_rect
.width
)/2,
1026 layout
, &foreground
, &background
);
1028 gdk_draw_line (drawing
->ruler
->window
,
1029 drawing
->ruler_gc_butt
,
1030 drawing
->ruler
->allocation
.width
/2, 1,
1031 drawing
->ruler
->allocation
.width
/2, 7);
1034 g_object_unref(layout
);
1039 void histo_drawing_update_vertical_ruler(histoDrawing_t
*drawing
)//, TimeWindow *time_window)
1041 gtk_widget_queue_draw(drawing
->vertical_ruler
);
1044 /* notify mouse on ruler */
1046 histo_motion_notify_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1048 //g_debug("motion");
1049 //eventually follow mouse and show time here
1054 histo_motion_notify_vertical_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1056 //g_debug("motion");
1057 //eventually follow mouse and show time here
1063 /* Redraw the vertical ruler */
1065 histo_expose_vertical_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
1067 histoDrawing_t
*drawing
= (histoDrawing_t
*)user_data
;
1068 HistoControlFlowData
*histo_cfv
= drawing
->histo_control_flow_data
;
1071 PangoContext
*context
;
1072 PangoLayout
*layout
;
1073 PangoFontDescription
*FontDesc
;
1074 PangoRectangle ink_rect
;
1075 gint global_height
=0;
1076 GdkColor foreground
= { 0, 0, 0, 0 };
1077 GdkColor background
= { 0, 0xffff, 0xffff, 0xffff };
1078 GdkColor red
={ 0, 0xFFFF, 0x1E00, 0x1000 };
1079 //GdkColor magneta ={ 0, 0x8900, 0x0000, 0x8400 };
1080 g_debug("vertical ruler expose event");
1082 gdk_draw_rectangle (drawing
->vertical_ruler
->window
,
1083 drawing
->vertical_ruler
->style
->white_gc
,
1085 event
->area
.x
, event
->area
.y
,
1087 event
->area
.height
);
1089 gdk_draw_line (drawing
->vertical_ruler
->window
,
1090 drawing
->ruler_gc_butt
,
1091 padding_width
-1/*event->area.width-1*/,event
->area
.y
,
1092 padding_width
-1/*event->area.width-1*/,event
->area
.y
+ event
->area
.height
);
1094 snprintf(text
, 255, "%.1f", (float)histo_cfv
->max_height
);
1096 layout
= gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
1098 context
= pango_layout_get_context(layout
);
1099 FontDesc
= pango_context_get_font_description(context
);
1101 pango_font_description_set_size(FontDesc
, 6*PANGO_SCALE
);
1102 pango_layout_context_changed(layout
);
1104 pango_layout_set_text(layout
, text
, -1);
1105 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1106 global_height
+= ink_rect
.height
;
1108 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1109 drawing
->ruler_gc_butt
,
1112 layout
, &foreground
, &background
);
1114 gdk_draw_line (drawing
->vertical_ruler
->window
,
1115 drawing
->ruler_gc_round
,
1116 drawing
->vertical_ruler
-> allocation
.width
-1, 1,
1117 drawing
->vertical_ruler
-> allocation
.width
-7, 1);
1120 snprintf(text
, 255, "%d", 0);
1122 pango_layout_set_text(layout
, text
, -1);
1123 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1124 global_height
+= ink_rect
.height
;
1126 if(global_height
<= drawing
->vertical_ruler
->allocation
.height
)
1128 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1129 drawing
->ruler_gc_butt
,
1131 drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
-2,
1132 layout
, &foreground
, &background
);
1134 gdk_draw_line (drawing
->vertical_ruler
->window
,
1135 drawing
->ruler_gc_butt
,
1136 drawing
->vertical_ruler
-> allocation
.width
-1,
1137 drawing
->vertical_ruler
->allocation
.height
-1,
1138 drawing
->vertical_ruler
-> allocation
.width
-7,
1139 drawing
->vertical_ruler
->allocation
.height
-1);
1143 snprintf(text
, 255, "%.1f",(float) histo_cfv
->max_height
/2.0);
1145 pango_layout_set_text(layout
, text
, -1);
1146 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1147 global_height
+= ink_rect
.height
;
1149 if(global_height
<= drawing
->vertical_ruler
->allocation
.height
)
1151 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1152 drawing
->ruler_gc_butt
,
1154 (drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
)/2,
1155 layout
, &foreground
, &background
);
1157 gdk_draw_line (drawing
->vertical_ruler
->window
,
1158 drawing
->ruler_gc_butt
,
1159 drawing
->vertical_ruler
-> allocation
.width
-1,
1160 drawing
->vertical_ruler
-> allocation
.height
/2,
1161 drawing
->vertical_ruler
-> allocation
.width
-7,
1162 drawing
->vertical_ruler
->allocation
.height
/2);
1165 //show number of events at current time:
1166 LttTime current_time
=
1167 lttvwindow_get_current_time(histo_cfv
->tab
);
1168 TimeWindow time_window
=
1169 lttvwindow_get_time_window(histo_cfv
->tab
);
1170 LttTime time_begin
= time_window
.start_time
;
1171 LttTime time_width
= time_window
.time_width
;
1172 LttTime time_end
= ltt_time_add(time_begin
, time_width
);
1173 if((ltt_time_compare(current_time
, time_begin
) >= 0)&&
1174 (ltt_time_compare(current_time
, time_end
) <= 0))
1176 guint
*events_at_currenttime
;
1177 guint max_height
=histo_cfv
->max_height
;
1179 histo_convert_time_to_pixels(
1184 // if(x_test<histo_cfv->number_of_process->len)
1187 events_at_currenttime
=
1188 &g_array_index(histo_cfv
->number_of_process
,guint
,x
);
1191 if((*events_at_currenttime
) > max_height
)
1193 snprintf(text
, 255, "OverFlow!");
1194 pango_layout_set_text(layout
, text
, -1);
1195 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1196 global_height
+= ink_rect
.height
;
1197 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1198 drawing
->ruler_gc_butt
,
1200 (drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
)/5,
1201 layout
, &red
, &background
);
1203 // if((*events_at_currenttime) <= max_height)
1205 snprintf(text
, 255, "%.1f",
1206 (float) *events_at_currenttime
);
1208 pango_layout_set_text(layout
, text
, -1);
1209 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1210 global_height
+= ink_rect
.height
;
1212 if ((*events_at_currenttime
) == 0)
1214 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1215 drawing
->ruler_gc_butt
,
1217 (drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
)-2,
1218 layout
, &red
, &background
);
1220 else if ((*events_at_currenttime
) == max_height
)
1222 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1223 drawing
->ruler_gc_butt
,
1226 layout
, &red
, &background
);
1228 /*else if ((*events_at_currenttime) == max_height/2)
1230 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1231 drawing->ruler_gc_butt,
1233 (drawing->vertical_ruler->allocation.height - ink_rect.height)/2,
1234 layout, &red, &background);
1236 else if ((*events_at_currenttime
) > max_height
/2)
1238 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1239 drawing
->ruler_gc_butt
,
1241 (drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
)/4,
1242 layout
, &red
, &background
);
1245 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1246 drawing
->ruler_gc_butt
,
1248 ((drawing
->vertical_ruler
->allocation
.height
1249 - ink_rect
.height
)*3)/4,
1250 layout
, &red
, &background
);
1257 g_object_unref(layout
);