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 <lttv/tracecontext.h>
31 #include <lttvwindow/lttvwindow.h>
32 #include <lttv/state.h>
33 #include <lttv/hook.h>
35 #include "histodrawing.h"
36 #include "histoeventhooks.h"
40 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
43 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
47 // fixed #define TRACE_NUMBER 0
48 #define EXTRA_ALLOC 1024 // pixels
49 #define padding_width 50
51 #if 0 /* colors for two lines representation */
52 GdkColor histo_drawing_colors
[NUM_COLORS
] =
53 { /* Pixel, R, G, B */
54 { 0, 0, 0, 0 }, /* COL_BLACK */
55 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
56 { 0, 0x0FFF, 0xFFFF, 0xFFFF }, /* COL_WAIT_FORK : pale blue */
57 { 0, 0xFFFF, 0xFFFF, 0x0000 }, /* COL_WAIT_CPU : yellow */
58 { 0, 0xFFFF, 0xA000, 0xFCFF }, /* COL_EXIT : pale magenta */
59 { 0, 0xFFFF, 0x0000, 0xFFFF }, /* COL_ZOMBIE : purple */
60 { 0, 0xFFFF, 0x0000, 0x0000 }, /* COL_WAIT : red */
61 { 0, 0x0000, 0xFFFF, 0x0000 }, /* COL_RUN : green */
62 { 0, 0x8800, 0xFFFF, 0x8A00 }, /* COL_USER_MODE : pale green */
63 { 0, 0x09FF, 0x01FF, 0xFFFF }, /* COL_SYSCALL : blue */
64 { 0, 0xF900, 0x4200, 0xFF00 }, /* COL_TRAP : pale purple */
65 { 0, 0xFFFF, 0x5AFF, 0x01FF }, /* COL_IRQ : orange */
66 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_MODE_UNKNOWN : white */
72 GdkColor histo_drawing_colors
[NUM_COLORS
] =
73 { /* Pixel, R, G, B */
74 { 0, 0, 0, 0 }, /* COL_BLACK */
75 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
76 { 0, 0x0000, 0xFF00, 0x0000 }, /* COL_RUN_USER_MODE : green */
77 { 0, 0x0100, 0x9E00, 0xFFFF }, /* COL_RUN_SYSCALL : pale blue */
78 { 0, 0xFF00, 0xFF00, 0x0100 }, /* COL_RUN_TRAP : yellow */
79 { 0, 0xFFFF, 0x5E00, 0x0000 }, /* COL_RUN_IRQ : red */
80 { 0, 0x6600, 0x0000, 0x0000 }, /* COL_WAIT : dark red */
81 { 0, 0x7700, 0x7700, 0x0000 }, /* COL_WAIT_CPU : dark yellow */
82 { 0, 0x6400, 0x0000, 0x5D00 }, /* COL_ZOMBIE : dark purple */
83 { 0, 0x0700, 0x6400, 0x0000 }, /* COL_WAIT_FORK : dark green */
84 { 0, 0x8900, 0x0000, 0x8400 }, /* COL_EXIT : "less dark" magenta */
85 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_MODE_UNKNOWN : white */
86 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_UNNAMED : white */
96 WAIT CPU + WAIT FORK vert foncé ou jaune
105 /*****************************************************************************
106 * drawing functions *
107 *****************************************************************************/
110 histo_expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
);
113 histo_expose_vertical_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
);
116 histo_motion_notify_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
);
119 histo_motion_notify_vertical_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
);
121 /* Function responsible for updating the exposed area.
122 * It must do an events request to the lttvwindow API to ask for this update.
123 * Note : this function cannot clear the background, because it may
124 * erase drawing already present (SAFETY).
126 void histo_drawing_data_request(histoDrawing_t
*drawing
,
135 void histo_drawing_data_request_begin(EventsRequest
*events_request
, LttvTracesetState
*tss
)
137 g_debug("Begin of data request");
138 HistoControlFlowData
*cfd
= events_request
->viewer_data
;
139 TimeWindow time_window
=
140 lttvwindow_get_time_window(cfd
->tab
);
142 guint width
= cfd
->drawing
->width
;
145 cfd
->drawing
->last_start
= events_request
->start_time
;
147 histo_convert_time_to_pixels(
149 events_request
->start_time
,
155 void histo_drawing_chunk_begin(EventsRequest
*events_request
, LttvTracesetState
*tss
)
157 g_debug("Begin of chunk");
158 HistoControlFlowData
*cfd
= events_request
->viewer_data
;
160 if(cfd
->chunk_has_begun
) return;
162 cfd
->chunk_has_begun
= TRUE
;
166 void histo_drawing_request_expose(EventsRequest
*events_request
,
167 LttvTracesetState
*tss
,
170 HistoControlFlowData
*cfd
= events_request
->viewer_data
;
171 histoDrawing_t
*drawing
= cfd
->drawing
;
173 guint x
, x_end
, width
;
175 TimeWindow time_window
=
176 lttvwindow_get_time_window(cfd
->tab
);
178 g_debug("histo request expose");
180 histo_convert_time_to_pixels(
185 x
= drawing
->damage_begin
;
189 drawing
->damage_begin
= x
+width
;
192 //changed for histogram:
193 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
196 drawing
->/*drawing_area->allocation.*/height
);
198 // Update directly when scrolling
199 gdk_window_process_updates(drawing
->drawing_area
->window
,
207 /* Create a new backing pixmap of the appropriate size */
208 /* As the scaling will always change, it's of no use to copy old
211 * Change the size if width or height changes.
212 * (different from control flow viewer!)
215 histo_configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
218 histoDrawing_t
*drawing
= (histoDrawing_t
*)user_data
;
220 /* First, get the new time interval of the main window */
221 /* we assume (see documentation) that the main window
222 * has updated the time interval before this configure gets
225 //lttvwindow_get_time_window(drawing->histo_control_flow_data->mw,
226 // &drawing->histo_control_flow_data->time_window);
228 /* New pixmap, size of the configure event */
229 //GdkPixmap *pixmap = gdk_pixmap_new(widget->window,
230 // widget->allocation.width + SAFETY,
231 // widget->allocation.height + SAFETY,
233 g_debug("drawing configure event");
234 g_debug("New alloc draw size : %i by %i",widget
->allocation
.width
,
235 widget
->allocation
.height
);
237 /*modified for histogram, if width is not changed, GArray is valid so
238 just redraw, else recalculate all.(event request again)*/
240 //enabled again for histogram:
242 gdk_pixmap_unref(drawing
->pixmap
);
244 drawing
->pixmap
= gdk_pixmap_new(widget
->window
,
245 widget
->allocation
.width
,//+ SAFETY + EXTRA_ALLOC,
246 widget
->allocation
.height
+ EXTRA_ALLOC
,
250 drawing
->alloc_width
= drawing
->width
+ SAFETY
+ EXTRA_ALLOC
;
251 drawing
->alloc_height
= drawing
->height
+ EXTRA_ALLOC
;
253 //drawing->height = widget->allocation.height;
258 // gdk_draw_rectangle (drawing->pixmap,
259 // widget->style->black_gc,
262 // drawing->width+SAFETY,
265 //g_info("init data request");
268 /* Initial data request */
269 /* no, do initial data request in the expose event */
270 // Do not need to ask for data of 1 pixel : not synchronized with
271 // main window time at this moment.
272 //histo_drawing_data_request(drawing, &drawing->pixmap, 0, 0,
273 // widget->allocation.width,
274 // widget->allocation.height);
276 //drawing->width = widget->allocation.width;
277 //drawing->height = widget->allocation.height;
279 drawing
->damage_begin
= 0;
280 drawing
->damage_end
= widget
->allocation
.width
;
282 if((widget
->allocation
.width
!= 1 &&
283 widget
->allocation
.height
!= 1)
284 /*&& drawing->damage_begin < drawing->damage_end */)
287 gdk_draw_rectangle (drawing
->pixmap
,
288 drawing
->drawing_area
->style
->black_gc
,
291 drawing
->drawing_area
->allocation
.width
, drawing
->drawing_area
->allocation
.height
);
292 /* histo_drawing_data_request(drawing,
293 drawing->damage_begin,
295 drawing->damage_end - drawing->damage_begin,
298 //modified for histogram
300 if(widget
->allocation
.width
== drawing
->width
)
303 drawing
->height
= widget
->allocation
.height
;
304 histogram_show( drawing
->histo_control_flow_data
,0,
305 drawing
->histo_control_flow_data
->number_of_process
->len
);
309 drawing
->width
= widget
->allocation
.width
;
310 drawing
->height
= widget
->allocation
.height
;
312 g_array_set_size (drawing
->histo_control_flow_data
->number_of_process
,
313 widget
->allocation
.width
);
314 histo_request_event( drawing
->histo_control_flow_data
,drawing
->damage_begin
315 ,drawing
->damage_end
- drawing
->damage_begin
);
321 /* Redraw the screen from the backing pixmap */
323 histo_expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
325 histoDrawing_t
*drawing
= (histoDrawing_t
*)user_data
;
327 HistoControlFlowData
*histo_control_flow_data
=
328 (HistoControlFlowData
*)g_object_get_data(
330 "histo_control_flow_data");
332 if(unlikely(drawing
->gc
== NULL
)) {
333 drawing
->gc
= gdk_gc_new(drawing
->drawing_area
->window
);
334 gdk_gc_copy(drawing
->gc
, drawing
->drawing_area
->style
->black_gc
);
337 TimeWindow time_window
=
338 lttvwindow_get_time_window(histo_control_flow_data
->tab
);
339 LttTime current_time
=
340 lttvwindow_get_current_time(histo_control_flow_data
->tab
);
344 LttTime window_end
= time_window
.end_time
;
347 /* update the screen from the pixmap buffer */
348 //added again for histogram:
350 gdk_draw_pixmap(widget
->window
,
351 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
353 event
->area
.x
, event
->area
.y
,
354 event
->area
.x
, event
->area
.y
,
355 event
->area
.width
, event
->area
.height
);
358 drawing
->height
= drawing
-> drawing_area
->allocation
.height
;
361 copy_pixmap_to_screen(histo_control_flow_data
->process_list
,
363 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
364 event
->area
.x
, event
->area
.y
,
365 event
->area
.width
, event
->area
.height
);
369 /* //disabled for histogram
370 copy_pixmap_to_screen(histo_control_flow_data->process_list,
373 event->area.x, event->area.y,
374 event->area.width, event->area.height);*/
376 /* Erase the dotted lines left.. */
377 if(widget
->allocation
.height
> drawing
->height
)
379 gdk_draw_rectangle (widget
->window
,
380 drawing
->drawing_area
->style
->black_gc
,
382 event
->area
.x
, drawing
->height
,
383 event
->area
.width
, // do not overlap
384 widget
->allocation
.height
- drawing
->height
);
386 if(ltt_time_compare(time_window
.start_time
, current_time
) <= 0 &&
387 ltt_time_compare(window_end
, current_time
) >= 0)
389 /* Draw the dotted lines */
390 histo_convert_time_to_pixels(
397 if(drawing
->dotted_gc
== NULL
) {
399 drawing
->dotted_gc
= gdk_gc_new(drawing
->drawing_area
->window
);
400 gdk_gc_copy(drawing
->dotted_gc
, widget
->style
->white_gc
);
402 gint8 dash_list
[] = { 1, 2 };
403 gdk_gc_set_line_attributes(drawing
->dotted_gc
,
405 GDK_LINE_ON_OFF_DASH
,
408 gdk_gc_set_dashes(drawing
->dotted_gc
,
414 gint height_tot
= MAX(widget
->allocation
.height
, drawing
->height
);
415 gdk_draw_line(widget
->window
,
418 cursor_x
, height_tot
);
425 histo_after_expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
428 g_debug("AFTER EXPOSE");
435 histo_button_press_event( GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
437 HistoControlFlowData
*histo_control_flow_data
=
438 (HistoControlFlowData
*)g_object_get_data(
440 "histo_control_flow_data");
441 histoDrawing_t
*drawing
= histo_control_flow_data
->drawing
;
442 TimeWindow time_window
=
443 lttvwindow_get_time_window(histo_control_flow_data
->tab
);
446 if(event
->button
== 1)
450 /* left mouse button click */
451 g_debug("x click is : %f", event
->x
);
453 histo_convert_pixels_to_time(drawing
->width
, (guint
)event
->x
,
457 lttvwindow_report_current_time(histo_control_flow_data
->tab
, time
);
458 ////report event->y for vertical zoom +,-
464 //Viewer's vertical scroll bar is already omitted, not needed for histogram.
466 scrollbar_size_allocate(GtkWidget *widget,
467 GtkAllocation *allocation,
470 histoDrawing_t *drawing = (histoDrawing_t*)user_data;
472 gtk_widget_set_size_request(drawing->padding, allocation->width, -1);
473 //gtk_widget_queue_resize(drawing->padding);
474 //gtk_widget_queue_resize(drawing->ruler);
475 gtk_container_check_resize(GTK_CONTAINER(drawing->ruler_hbox));
481 histoDrawing_t
*histo_drawing_construct(HistoControlFlowData
*histo_control_flow_data
)
483 histoDrawing_t
*drawing
= g_new(histoDrawing_t
, 1);
485 drawing
->histo_control_flow_data
= histo_control_flow_data
;
487 drawing
->vbox
= gtk_vbox_new(FALSE
, 1);
490 drawing
->ruler_hbox
= gtk_hbox_new(FALSE
, 1);
491 drawing
->ruler
= gtk_drawing_area_new ();
492 //gtk_widget_set_size_request(drawing->ruler, -1, 27);
494 drawing
->padding
= gtk_drawing_area_new ();
495 //gtk_widget_set_size_request(drawing->padding, -1, 27);
497 gtk_box_pack_start(GTK_BOX(drawing
->ruler_hbox
), drawing
->padding
,FALSE
, FALSE
, 0);
499 gtk_box_pack_end(GTK_BOX(drawing
->ruler_hbox
), drawing
->ruler
,
502 drawing
->drawing_area
= gtk_drawing_area_new ();
506 ///at this time not necessary for histogram
507 drawing->hbox = gtk_hbox_new(FALSE, 1);
509 drawing->viewport = gtk_viewport_new(NULL, histo_control_flow_data->v_adjust);
510 drawing->scrollbar = gtk_vscrollbar_new(histo_control_flow_data->v_adjust);
511 gtk_box_pack_start(GTK_BOX(drawing->hbox), drawing->viewport,
513 gtk_box_pack_end(GTK_BOX(drawing->hbox), drawing->scrollbar,
515 gtk_container_add(GTK_CONTAINER(drawing->viewport),
516 drawing->drawing_area);*/
518 //add vertical ruler:
519 drawing
->vruler_drawing_hbox
= gtk_hbox_new(FALSE
, 1);
520 drawing
-> vertical_ruler
=gtk_drawing_area_new ();
521 gtk_box_pack_start(GTK_BOX(drawing
->vruler_drawing_hbox
), drawing
->vertical_ruler
,
523 gtk_box_pack_end(GTK_BOX(drawing
->vruler_drawing_hbox
), drawing
->drawing_area
,
525 gtk_widget_set_size_request(drawing
->vertical_ruler
, padding_width
, -1);
527 gtk_box_pack_start(GTK_BOX(drawing
->vbox
), drawing
->ruler_hbox
,
529 gtk_box_pack_end(GTK_BOX(drawing
->vbox
), drawing
->vruler_drawing_hbox
/*drawing_area*/,
532 drawing
->pango_layout
=
533 gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
538 drawing
->alloc_height
= 1;
539 drawing
->alloc_width
= 1;
541 drawing
->damage_begin
= 0;
542 drawing
->damage_end
= 0;
543 drawing
->horizontal_sel
= -1;
545 //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50);
546 g_object_set_data_full(
547 G_OBJECT(drawing
->drawing_area
),
548 "histo_Link_drawing_Data",
550 (GDestroyNotify
)histo_drawing_destroy
);
553 G_OBJECT(drawing
->ruler
),
558 G_OBJECT(drawing
->vertical_ruler
),
562 //gtk_widget_modify_bg( drawing->drawing_area,
564 // &CF_Colors[BLACK]);
566 //gdk_window_get_geometry(drawing->drawing_area->window,
568 // &(drawing->width),
569 // &(drawing->height),
572 //drawing->pixmap = gdk_pixmap_new(
573 // drawing->drawing_area->window,
578 drawing
->pixmap
= NULL
;
580 // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
581 // drawing->drawing_area->allocation.width,
582 // drawing->drawing_area->allocation.height,
585 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
587 G_CALLBACK (histo_configure_event
),
590 g_signal_connect (G_OBJECT(drawing
->ruler
),
592 G_CALLBACK(histo_expose_ruler
),
595 gtk_widget_add_events(drawing
->ruler
, GDK_POINTER_MOTION_MASK
);
596 gtk_widget_add_events(drawing
->vertical_ruler
, GDK_POINTER_MOTION_MASK
);
598 g_signal_connect (G_OBJECT(drawing
->ruler
),
599 "motion-notify-event",
600 G_CALLBACK(histo_motion_notify_ruler
),
604 g_signal_connect (G_OBJECT(drawing
->vertical_ruler
),
606 G_CALLBACK(histo_expose_vertical_ruler
),
609 g_signal_connect (G_OBJECT(drawing
->vertical_ruler
),
610 "motion-notify-event",
611 G_CALLBACK(histo_motion_notify_vertical_ruler
),
614 /*//not necessary for historam.
615 g_signal_connect (G_OBJECT(drawing->drawing_area),
617 G_CALLBACK(scrollbar_size_allocate),
618 (gpointer)drawing); */
621 gtk_widget_set_size_request(drawing
->padding
, padding_width
, -1);//use it for vertical ruler
623 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
625 G_CALLBACK (histo_expose_event
),
628 g_signal_connect_after (G_OBJECT(drawing
->drawing_area
),
630 G_CALLBACK (histo_after_expose_event
),
633 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
634 "button-press-event",
635 G_CALLBACK (histo_button_press_event
),
638 gtk_widget_show(drawing
->ruler
);
639 gtk_widget_show(drawing
->padding
);
640 gtk_widget_show(drawing
->ruler_hbox
);
641 gtk_widget_show(drawing
->vertical_ruler
);
642 gtk_widget_show(drawing
->vruler_drawing_hbox
);
643 gtk_widget_show(drawing
->drawing_area
);
645 /// gtk_widget_show(drawing->viewport);
646 /// gtk_widget_show(drawing->scrollbar);
647 /// gtk_widget_show(drawing->hbox);
649 /* Allocate the colors */
650 GdkColormap
* colormap
= gdk_colormap_get_system();
651 gboolean success
[NUM_COLORS
];
652 gdk_colormap_alloc_colors(colormap
, histo_drawing_colors
, NUM_COLORS
, FALSE
,
656 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data
->tab
)->window
));
658 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data
->tab
)->window
));
660 gdk_gc_copy(drawing
->gc
,
661 main_window_get_widget(histo_control_flow_data
->tab
)->style
->black_gc
);
662 gdk_gc_copy(drawing
->dotted_gc
,
663 main_window_get_widget(histo_control_flow_data
->tab
)->style
->white_gc
);
665 gint8 dash_list
[] = { 1, 2 };
666 gdk_gc_set_line_attributes(drawing
->dotted_gc
,
668 GDK_LINE_ON_OFF_DASH
,
671 gdk_gc_set_dashes(drawing
->dotted_gc
,
676 drawing
->ruler_gc_butt
=
677 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data
->tab
)->window
));
678 gdk_gc_copy(drawing
->ruler_gc_butt
,
679 main_window_get_widget(histo_control_flow_data
->tab
)->style
->black_gc
);
680 drawing
->ruler_gc_round
=
681 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data
->tab
)->window
));
682 gdk_gc_copy(drawing
->ruler_gc_round
,
683 main_window_get_widget(histo_control_flow_data
->tab
)->style
->black_gc
);
686 gdk_gc_set_line_attributes(drawing
->ruler_gc_butt
,
692 gdk_gc_set_line_attributes(drawing
->ruler_gc_round
,
700 void histo_drawing_destroy(histoDrawing_t
*drawing
)
702 g_info("histo_drawing_destroy %p", drawing
);
704 /* Free the colors */
705 GdkColormap
* colormap
= gdk_colormap_get_system();
707 gdk_colormap_free_colors(colormap
, histo_drawing_colors
, NUM_COLORS
);
709 // Do not unref here, histoDrawing_t destroyed by it's widget.
710 //g_object_unref( G_OBJECT(drawing->drawing_area));
711 if(drawing
->gc
!= NULL
)
712 gdk_gc_unref(drawing
->gc
);
714 g_object_unref(drawing
->pango_layout
);
715 if(drawing
->dotted_gc
!= NULL
) gdk_gc_unref(drawing
->dotted_gc
);
716 if(drawing
->ruler_gc_butt
!= NULL
) gdk_gc_unref(drawing
->ruler_gc_butt
);
717 if(drawing
->ruler_gc_round
!= NULL
) gdk_gc_unref(drawing
->ruler_gc_round
);
719 //added for histogram
721 gdk_pixmap_unref(drawing
->pixmap
);
723 g_info("histo_drawing_destroy end");
726 GtkWidget
*histo_drawing_get_drawing_area(histoDrawing_t
*drawing
)
728 return drawing
->drawing_area
;
731 GtkWidget
*histo_drawing_get_widget(histoDrawing_t
*drawing
)
733 return drawing
->vbox
;
736 void histo_drawing_draw_line( histoDrawing_t
*drawing
,
742 gdk_draw_line (pixmap
,
747 void histo_drawing_clear(histoDrawing_t
*drawing
,guint clear_from
,guint clear_to
)
749 guint clear_width
= clear_to
- clear_from
;
751 //disabled for histogram
752 rectangle_pixmap(cfd->process_list,
753 drawing->drawing_area->style->black_gc,
756 drawing->alloc_width, // do not overlap
758 //instead, this is added for histogram
760 histo_rectangle_pixmap (drawing
->drawing_area
->style
->black_gc
,
763 clear_width
/*drawing->width*/,
768 /* gdk_draw_rectangle (drawing->pixmap,
769 drawing->drawing_area->style->black_gc,
772 drawing->drawing_area->allocation.width,drawing->drawing_area->allocation.height );
775 /* ask for the buffer to be redrawn */
776 //enabled again for histogram.
777 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
779 clear_width
, drawing
->height
);
780 gdk_window_process_updates(drawing
->drawing_area
->window
,TRUE
);
781 //disabled instead for histogram
782 //gtk_widget_queue_draw ( drawing->drawing_area);
787 /* Insert a square corresponding to a new process in the list */
788 /* Applies to whole drawing->width */
789 void drawing_insert_square(histoDrawing_t
*drawing
,
793 //GdkRectangle update_rect;
794 gboolean reallocate
= FALSE
;
795 GdkPixmap
*new_pixmap
;
797 /* Allocate a new pixmap with new height */
798 if(drawing
->alloc_height
< drawing
->height
+ height
) {
800 new_pixmap
= gdk_pixmap_new(drawing
->drawing_area
->window
,
801 drawing
->width
+ SAFETY
+ EXTRA_ALLOC
,
802 drawing
->height
+ height
+ EXTRA_ALLOC
,
804 drawing
->alloc_width
= drawing
->width
+ SAFETY
+ EXTRA_ALLOC
;
805 drawing
->alloc_height
= drawing
->height
+ height
+ EXTRA_ALLOC
;
808 /* Copy the high region */
809 gdk_draw_pixmap (new_pixmap
,
810 drawing
->drawing_area
->style
->black_gc
,
814 drawing
->width
+ SAFETY
, y
);
817 new_pixmap
= drawing
->pixmap
;
820 //GdkPixmap *pixmap = gdk_pixmap_new(drawing->drawing_area->window,
821 // drawing->width + SAFETY,
822 // drawing->height + height,
825 /* add an empty square */
826 gdk_draw_rectangle (new_pixmap
,
827 drawing
->drawing_area
->style
->black_gc
,
830 drawing
->width
+ SAFETY
, // do not overlap
833 /* copy the bottom of the region */
834 gdk_draw_pixmap (new_pixmap
,
835 drawing
->drawing_area
->style
->black_gc
,
839 drawing
->width
+SAFETY
, drawing
->height
- y
);
842 if(reallocate
&& likely(drawing
->pixmap
)) {
843 gdk_pixmap_unref(drawing
->pixmap
);
844 drawing
->pixmap
= new_pixmap
;
847 if(unlikely(drawing
->height
==1)) drawing
->height
= height
;
848 else drawing
->height
+= height
;
850 gtk_widget_set_size_request(drawing
->drawing_area
,
853 gtk_widget_queue_resize_no_redraw(drawing
->drawing_area
);
855 /* ask for the buffer to be redrawn */
856 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
858 drawing
->width
, drawing
->height
-y
);
862 /* Remove a square corresponding to a removed process in the list */
863 void drawing_remove_square(histoDrawing_t
*drawing
,
869 if(unlikely((guint
)drawing
->height
== height
)) {
870 //pixmap = gdk_pixmap_new(
871 // drawing->drawing_area->window,
872 // drawing->width + SAFETY,
875 pixmap
= drawing
->pixmap
;
878 /* Allocate a new pixmap with new height */
879 //pixmap = gdk_pixmap_new(
880 // drawing->drawing_area->window,
881 // drawing->width + SAFETY,
882 // drawing->height - height,
884 /* Keep the same preallocated pixmap */
885 pixmap
= drawing
->pixmap
;
887 /* Copy the high region */
888 gdk_draw_pixmap (pixmap
,
889 drawing
->drawing_area
->style
->black_gc
,
893 drawing
->width
+ SAFETY
, y
);
895 /* Copy up the bottom of the region */
896 gdk_draw_pixmap (pixmap
,
897 drawing
->drawing_area
->style
->black_gc
,
901 drawing
->width
, drawing
->height
- y
- height
);
903 drawing
->height
-=height
;
906 //if(likely(drawing->pixmap))
907 // gdk_pixmap_unref(drawing->pixmap);
909 //drawing->pixmap = pixmap;
911 gtk_widget_set_size_request(drawing
->drawing_area
,
914 gtk_widget_queue_resize_no_redraw(drawing
->drawing_area
);
915 /* ask for the buffer to be redrawn */
916 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
918 drawing
->width
, MAX(drawing
->height
-y
, 1));
922 void histo_drawing_update_ruler(histoDrawing_t
*drawing
, TimeWindow
*time_window
)
924 gtk_widget_queue_draw(drawing
->ruler
);
927 /* Redraw the ruler */
929 histo_expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
931 histoDrawing_t
*drawing
= (histoDrawing_t
*)user_data
;
932 TimeWindow time_window
= lttvwindow_get_time_window(drawing
->histo_control_flow_data
->tab
);
935 PangoContext
*context
;
937 PangoFontDescription
*FontDesc
;
938 PangoRectangle ink_rect
;
940 GdkColor foreground
= { 0, 0, 0, 0 };
941 GdkColor background
= { 0, 0xffff, 0xffff, 0xffff };
943 LttTime window_end
= time_window
.end_time
;
945 ltt_time_div(time_window
.time_width
,2.0);
946 LttTime window_middle
=
947 ltt_time_add(half_width
,
948 time_window
.start_time
);
949 g_debug("ruler expose event");
951 gdk_draw_rectangle (drawing
->ruler
->window
,
952 drawing
->ruler
->style
->white_gc
,
954 event
->area
.x
, event
->area
.y
,
958 gdk_draw_line (drawing
->ruler
->window
,
959 drawing
->ruler_gc_butt
,
961 event
->area
.x
+ event
->area
.width
, 1);
964 snprintf(text
, 255, "%lus\n%luns",
965 time_window
.start_time
.tv_sec
,
966 time_window
.start_time
.tv_nsec
);
968 layout
= gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
970 context
= pango_layout_get_context(layout
);
971 FontDesc
= pango_context_get_font_description(context
);
973 pango_font_description_set_size(FontDesc
, 6*PANGO_SCALE
);
974 pango_layout_context_changed(layout
);
976 pango_layout_set_text(layout
, text
, -1);
977 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
978 global_width
+= ink_rect
.width
;
980 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
981 drawing
->ruler_gc_butt
,
984 layout
, &foreground
, &background
);
986 gdk_draw_line (drawing
->ruler
->window
,
987 drawing
->ruler_gc_round
,
992 snprintf(text
, 255, "%lus\n%luns", window_end
.tv_sec
,
995 pango_layout_set_text(layout
, text
, -1);
996 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
997 global_width
+= ink_rect
.width
;
999 if(global_width
<= drawing
->ruler
->allocation
.width
)
1001 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
1002 drawing
->ruler_gc_butt
,
1003 drawing
->ruler
->allocation
.width
- ink_rect
.width
,
1005 layout
, &foreground
, &background
);
1007 gdk_draw_line (drawing
->ruler
->window
,
1008 drawing
->ruler_gc_butt
,
1009 drawing
->ruler
->allocation
.width
-1, 1,
1010 drawing
->ruler
->allocation
.width
-1, 7);
1014 snprintf(text
, 255, "%lus\n%luns", window_middle
.tv_sec
,
1015 window_middle
.tv_nsec
);
1017 pango_layout_set_text(layout
, text
, -1);
1018 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1019 global_width
+= ink_rect
.width
;
1021 if(global_width
<= drawing
->ruler
->allocation
.width
)
1023 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
1024 drawing
->ruler_gc_butt
,
1025 (drawing
->ruler
->allocation
.width
- ink_rect
.width
)/2,
1027 layout
, &foreground
, &background
);
1029 gdk_draw_line (drawing
->ruler
->window
,
1030 drawing
->ruler_gc_butt
,
1031 drawing
->ruler
->allocation
.width
/2, 1,
1032 drawing
->ruler
->allocation
.width
/2, 7);
1035 g_object_unref(layout
);
1040 void histo_drawing_update_vertical_ruler(histoDrawing_t
*drawing
)//, TimeWindow *time_window)
1042 gtk_widget_queue_draw(drawing
->vertical_ruler
);
1045 /* notify mouse on ruler */
1047 histo_motion_notify_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1049 //g_debug("motion");
1050 //eventually follow mouse and show time here
1055 histo_motion_notify_vertical_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1057 //g_debug("motion");
1058 //eventually follow mouse and show time here
1064 /* Redraw the vertical ruler */
1066 histo_expose_vertical_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
1068 histoDrawing_t
*drawing
= (histoDrawing_t
*)user_data
;
1069 HistoControlFlowData
*histo_cfv
= drawing
->histo_control_flow_data
;
1072 PangoContext
*context
;
1073 PangoLayout
*layout
;
1074 PangoFontDescription
*FontDesc
;
1075 PangoRectangle ink_rect
;
1076 gint global_height
=0;
1077 GdkColor foreground
= { 0, 0, 0, 0 };
1078 GdkColor background
= { 0, 0xffff, 0xffff, 0xffff };
1079 GdkColor red
={ 0, 0xFFFF, 0x1E00, 0x1000 };
1080 //GdkColor magneta ={ 0, 0x8900, 0x0000, 0x8400 };
1081 g_debug("vertical ruler expose event");
1083 gdk_draw_rectangle (drawing
->vertical_ruler
->window
,
1084 drawing
->vertical_ruler
->style
->white_gc
,
1086 event
->area
.x
, event
->area
.y
,
1088 event
->area
.height
);
1090 gdk_draw_line (drawing
->vertical_ruler
->window
,
1091 drawing
->ruler_gc_butt
,
1092 padding_width
-1/*event->area.width-1*/,event
->area
.y
,
1093 padding_width
-1/*event->area.width-1*/,event
->area
.y
+ event
->area
.height
);
1095 snprintf(text
, 255, "%.1f", (float)histo_cfv
->max_height
);
1097 layout
= gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
1099 context
= pango_layout_get_context(layout
);
1100 FontDesc
= pango_context_get_font_description(context
);
1102 pango_font_description_set_size(FontDesc
, 6*PANGO_SCALE
);
1103 pango_layout_context_changed(layout
);
1105 pango_layout_set_text(layout
, text
, -1);
1106 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1107 global_height
+= ink_rect
.height
;
1109 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1110 drawing
->ruler_gc_butt
,
1113 layout
, &foreground
, &background
);
1115 gdk_draw_line (drawing
->vertical_ruler
->window
,
1116 drawing
->ruler_gc_round
,
1117 drawing
->vertical_ruler
-> allocation
.width
-1, 1,
1118 drawing
->vertical_ruler
-> allocation
.width
-7, 1);
1121 snprintf(text
, 255, "%d", 0);
1123 pango_layout_set_text(layout
, text
, -1);
1124 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1125 global_height
+= ink_rect
.height
;
1127 if(global_height
<= drawing
->vertical_ruler
->allocation
.height
)
1129 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1130 drawing
->ruler_gc_butt
,
1132 drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
-2,
1133 layout
, &foreground
, &background
);
1135 gdk_draw_line (drawing
->vertical_ruler
->window
,
1136 drawing
->ruler_gc_butt
,
1137 drawing
->vertical_ruler
-> allocation
.width
-1,
1138 drawing
->vertical_ruler
->allocation
.height
-1,
1139 drawing
->vertical_ruler
-> allocation
.width
-7,
1140 drawing
->vertical_ruler
->allocation
.height
-1);
1144 snprintf(text
, 255, "%.1f",(float) histo_cfv
->max_height
/2.0);
1146 pango_layout_set_text(layout
, text
, -1);
1147 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1148 global_height
+= ink_rect
.height
;
1150 if(global_height
<= drawing
->vertical_ruler
->allocation
.height
)
1152 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1153 drawing
->ruler_gc_butt
,
1155 (drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
)/2,
1156 layout
, &foreground
, &background
);
1158 gdk_draw_line (drawing
->vertical_ruler
->window
,
1159 drawing
->ruler_gc_butt
,
1160 drawing
->vertical_ruler
-> allocation
.width
-1,
1161 drawing
->vertical_ruler
-> allocation
.height
/2,
1162 drawing
->vertical_ruler
-> allocation
.width
-7,
1163 drawing
->vertical_ruler
->allocation
.height
/2);
1166 //show number of events at current time:
1167 LttTime current_time
=
1168 lttvwindow_get_current_time(histo_cfv
->tab
);
1169 TimeWindow time_window
=
1170 lttvwindow_get_time_window(histo_cfv
->tab
);
1171 LttTime time_begin
= time_window
.start_time
;
1172 LttTime time_width
= time_window
.time_width
;
1173 LttTime time_end
= ltt_time_add(time_begin
, time_width
);
1174 if((ltt_time_compare(current_time
, time_begin
) >= 0)&&
1175 (ltt_time_compare(current_time
, time_end
) <= 0))
1177 guint
*events_at_currenttime
;
1178 guint max_height
=histo_cfv
->max_height
;
1180 histo_convert_time_to_pixels(
1185 // if(x_test<histo_cfv->number_of_process->len)
1188 events_at_currenttime
=
1189 &g_array_index(histo_cfv
->number_of_process
,guint
,x
);
1192 if((*events_at_currenttime
) > max_height
)
1194 snprintf(text
, 255, "OverFlow!");
1195 pango_layout_set_text(layout
, text
, -1);
1196 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1197 global_height
+= ink_rect
.height
;
1198 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1199 drawing
->ruler_gc_butt
,
1201 (drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
)/5,
1202 layout
, &red
, &background
);
1204 // if((*events_at_currenttime) <= max_height)
1206 snprintf(text
, 255, "%.1f",
1207 (float) *events_at_currenttime
);
1209 pango_layout_set_text(layout
, text
, -1);
1210 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1211 global_height
+= ink_rect
.height
;
1213 if ((*events_at_currenttime
) == 0)
1215 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1216 drawing
->ruler_gc_butt
,
1218 (drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
)-2,
1219 layout
, &red
, &background
);
1221 else if ((*events_at_currenttime
) == max_height
)
1223 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1224 drawing
->ruler_gc_butt
,
1227 layout
, &red
, &background
);
1229 /*else if ((*events_at_currenttime) == max_height/2)
1231 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1232 drawing->ruler_gc_butt,
1234 (drawing->vertical_ruler->allocation.height - ink_rect.height)/2,
1235 layout, &red, &background);
1237 else if ((*events_at_currenttime
) > max_height
/2)
1239 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1240 drawing
->ruler_gc_butt
,
1242 (drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
)/4,
1243 layout
, &red
, &background
);
1246 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1247 drawing
->ruler_gc_butt
,
1249 ((drawing
->vertical_ruler
->allocation
.height
1250 - ink_rect
.height
)*3)/4,
1251 layout
, &red
, &background
);
1258 g_object_unref(layout
);