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., 51 Franklin Street, Fifth Floor, Boston,
27 #include <lttv/lttv.h>
28 #include <lttvwindow/lttvwindow.h>
29 #include <lttv/state.h>
30 #include <lttv/hook.h>
32 #include "histodrawing.h"
33 #include "histoeventhooks.h"
37 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
40 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
44 // fixed #define TRACE_NUMBER 0
45 #define EXTRA_ALLOC 1024 // pixels
46 #define padding_width 50
48 #if 0 /* colors for two lines representation */
49 GdkColor histo_drawing_colors
[NUM_COLORS
] =
50 { /* Pixel, R, G, B */
51 { 0, 0, 0, 0 }, /* COL_BLACK */
52 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
53 { 0, 0x0FFF, 0xFFFF, 0xFFFF }, /* COL_WAIT_FORK : pale blue */
54 { 0, 0xFFFF, 0xFFFF, 0x0000 }, /* COL_WAIT_CPU : yellow */
55 { 0, 0xFFFF, 0xA000, 0xFCFF }, /* COL_EXIT : pale magenta */
56 { 0, 0xFFFF, 0x0000, 0xFFFF }, /* COL_ZOMBIE : purple */
57 { 0, 0xFFFF, 0x0000, 0x0000 }, /* COL_WAIT : red */
58 { 0, 0x0000, 0xFFFF, 0x0000 }, /* COL_RUN : green */
59 { 0, 0x8800, 0xFFFF, 0x8A00 }, /* COL_USER_MODE : pale green */
60 { 0, 0x09FF, 0x01FF, 0xFFFF }, /* COL_SYSCALL : blue */
61 { 0, 0xF900, 0x4200, 0xFF00 }, /* COL_TRAP : pale purple */
62 { 0, 0xFFFF, 0x5AFF, 0x01FF }, /* COL_IRQ : orange */
63 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_MODE_UNKNOWN : white */
69 GdkColor histo_drawing_colors
[NUM_COLORS
] =
70 { /* Pixel, R, G, B */
71 { 0, 0, 0, 0 }, /* COL_BLACK */
72 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
73 { 0, 0x0000, 0xFF00, 0x0000 }, /* COL_RUN_USER_MODE : green */
74 { 0, 0x0100, 0x9E00, 0xFFFF }, /* COL_RUN_SYSCALL : pale blue */
75 { 0, 0xFF00, 0xFF00, 0x0100 }, /* COL_RUN_TRAP : yellow */
76 { 0, 0xFFFF, 0x5E00, 0x0000 }, /* COL_RUN_IRQ : red */
77 { 0, 0x6600, 0x0000, 0x0000 }, /* COL_WAIT : dark red */
78 { 0, 0x7700, 0x7700, 0x0000 }, /* COL_WAIT_CPU : dark yellow */
79 { 0, 0x6400, 0x0000, 0x5D00 }, /* COL_ZOMBIE : dark purple */
80 { 0, 0x0700, 0x6400, 0x0000 }, /* COL_WAIT_FORK : dark green */
81 { 0, 0x8900, 0x0000, 0x8400 }, /* COL_EXIT : "less dark" magenta */
82 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_MODE_UNKNOWN : white */
83 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_UNNAMED : white */
93 WAIT CPU + WAIT FORK vert foncé ou jaune
102 /*****************************************************************************
103 * drawing functions *
104 *****************************************************************************/
107 histo_expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
);
110 histo_expose_vertical_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
);
113 histo_motion_notify_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
);
116 histo_motion_notify_vertical_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
);
118 /* Function responsible for updating the exposed area.
119 * It must do an events request to the lttvwindow API to ask for this update.
120 * Note : this function cannot clear the background, because it may
121 * erase drawing already present (SAFETY).
123 void histo_drawing_data_request(histoDrawing_t
*drawing
,
132 void histo_drawing_data_request_begin(EventsRequest
*events_request
, LttvTraceset
*traceset
)
134 g_debug("Begin of data request");
135 HistoControlFlowData
*cfd
= events_request
->viewer_data
;
136 TimeWindow time_window
=
137 lttvwindow_get_time_window(cfd
->tab
);
139 guint width
= cfd
->drawing
->width
;
142 cfd
->drawing
->last_start
= events_request
->start_time
;
144 histo_convert_time_to_pixels(
146 events_request
->start_time
,
152 void histo_drawing_chunk_begin(EventsRequest
*events_request
, LttvTraceset
*traceset
)
154 g_debug("Begin of chunk");
155 HistoControlFlowData
*cfd
= events_request
->viewer_data
;
157 if(cfd
->chunk_has_begun
) return;
159 cfd
->chunk_has_begun
= TRUE
;
163 void histo_drawing_request_expose(EventsRequest
*events_request
,
164 LttvTraceset
*traceset
,
167 HistoControlFlowData
*cfd
= events_request
->viewer_data
;
168 histoDrawing_t
*drawing
= cfd
->drawing
;
170 guint x
, x_end
, width
;
172 TimeWindow time_window
=
173 lttvwindow_get_time_window(cfd
->tab
);
175 g_debug("histo request expose");
177 histo_convert_time_to_pixels(
182 x
= drawing
->damage_begin
;
186 drawing
->damage_begin
= x
+width
;
189 //changed for histogram:
190 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
193 drawing
->/*drawing_area->allocation.*/height
);
195 // Update directly when scrolling
196 gdk_window_process_updates(drawing
->drawing_area
->window
,
204 /* Create a new backing pixmap of the appropriate size */
205 /* As the scaling will always change, it's of no use to copy old
208 * Change the size if width or height changes.
209 * (different from control flow viewer!)
212 histo_configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
215 histoDrawing_t
*drawing
= (histoDrawing_t
*)user_data
;
217 /* First, get the new time interval of the main window */
218 /* we assume (see documentation) that the main window
219 * has updated the time interval before this configure gets
222 //lttvwindow_get_time_window(drawing->histo_control_flow_data->mw,
223 // &drawing->histo_control_flow_data->time_window);
225 /* New pixmap, size of the configure event */
226 //GdkPixmap *pixmap = gdk_pixmap_new(widget->window,
227 // widget->allocation.width + SAFETY,
228 // widget->allocation.height + SAFETY,
230 g_debug("drawing configure event");
231 g_debug("New alloc draw size : %i by %i",widget
->allocation
.width
,
232 widget
->allocation
.height
);
234 /*modified for histogram, if width is not changed, GArray is valid so
235 just redraw, else recalculate all.(event request again)*/
237 //enabled again for histogram:
239 gdk_pixmap_unref(drawing
->pixmap
);
241 drawing
->pixmap
= gdk_pixmap_new(widget
->window
,
242 widget
->allocation
.width
,//+ SAFETY + EXTRA_ALLOC,
243 widget
->allocation
.height
+ EXTRA_ALLOC
,
247 drawing
->alloc_width
= drawing
->width
+ SAFETY
+ EXTRA_ALLOC
;
248 drawing
->alloc_height
= drawing
->height
+ EXTRA_ALLOC
;
250 //drawing->height = widget->allocation.height;
255 // gdk_draw_rectangle (drawing->pixmap,
256 // widget->style->black_gc,
259 // drawing->width+SAFETY,
262 //g_info("init data request");
265 /* Initial data request */
266 /* no, do initial data request in the expose event */
267 // Do not need to ask for data of 1 pixel : not synchronized with
268 // main window time at this moment.
269 //histo_drawing_data_request(drawing, &drawing->pixmap, 0, 0,
270 // widget->allocation.width,
271 // widget->allocation.height);
273 //drawing->width = widget->allocation.width;
274 //drawing->height = widget->allocation.height;
276 drawing
->damage_begin
= 0;
277 drawing
->damage_end
= widget
->allocation
.width
;
279 if((widget
->allocation
.width
!= 1 &&
280 widget
->allocation
.height
!= 1)
281 /*&& drawing->damage_begin < drawing->damage_end */)
284 gdk_draw_rectangle (drawing
->pixmap
,
285 drawing
->drawing_area
->style
->black_gc
,
288 drawing
->drawing_area
->allocation
.width
, drawing
->drawing_area
->allocation
.height
);
289 /* histo_drawing_data_request(drawing,
290 drawing->damage_begin,
292 drawing->damage_end - drawing->damage_begin,
295 //modified for histogram
297 if(widget
->allocation
.width
== drawing
->width
)
300 drawing
->height
= widget
->allocation
.height
;
301 histogram_show( drawing
->histo_control_flow_data
,0,
302 drawing
->histo_control_flow_data
->number_of_process
->len
);
306 drawing
->width
= widget
->allocation
.width
;
307 drawing
->height
= widget
->allocation
.height
;
309 g_array_set_size (drawing
->histo_control_flow_data
->number_of_process
,
310 widget
->allocation
.width
);
311 histo_request_event( drawing
->histo_control_flow_data
,drawing
->damage_begin
312 ,drawing
->damage_end
- drawing
->damage_begin
);
318 /* Redraw the screen from the backing pixmap */
320 histo_expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
322 histoDrawing_t
*drawing
= (histoDrawing_t
*)user_data
;
324 HistoControlFlowData
*histo_control_flow_data
=
325 (HistoControlFlowData
*)g_object_get_data(
327 "histo_control_flow_data");
329 if(unlikely(drawing
->gc
== NULL
)) {
330 drawing
->gc
= gdk_gc_new(drawing
->drawing_area
->window
);
331 gdk_gc_copy(drawing
->gc
, drawing
->drawing_area
->style
->black_gc
);
334 TimeWindow time_window
=
335 lttvwindow_get_time_window(histo_control_flow_data
->tab
);
336 LttTime current_time
=
337 lttvwindow_get_current_time(histo_control_flow_data
->tab
);
341 LttTime window_end
= time_window
.end_time
;
344 /* update the screen from the pixmap buffer */
345 //added again for histogram:
347 gdk_draw_pixmap(widget
->window
,
348 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
350 event
->area
.x
, event
->area
.y
,
351 event
->area
.x
, event
->area
.y
,
352 event
->area
.width
, event
->area
.height
);
355 drawing
->height
= drawing
-> drawing_area
->allocation
.height
;
358 copy_pixmap_to_screen(histo_control_flow_data
->process_list
,
360 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
361 event
->area
.x
, event
->area
.y
,
362 event
->area
.width
, event
->area
.height
);
366 /* //disabled for histogram
367 copy_pixmap_to_screen(histo_control_flow_data->process_list,
370 event->area.x, event->area.y,
371 event->area.width, event->area.height);*/
373 /* Erase the dotted lines left.. */
374 if(widget
->allocation
.height
> drawing
->height
)
376 gdk_draw_rectangle (widget
->window
,
377 drawing
->drawing_area
->style
->black_gc
,
379 event
->area
.x
, drawing
->height
,
380 event
->area
.width
, // do not overlap
381 widget
->allocation
.height
- drawing
->height
);
383 if(ltt_time_compare(time_window
.start_time
, current_time
) <= 0 &&
384 ltt_time_compare(window_end
, current_time
) >= 0)
386 /* Draw the dotted lines */
387 histo_convert_time_to_pixels(
394 if(drawing
->dotted_gc
== NULL
) {
396 drawing
->dotted_gc
= gdk_gc_new(drawing
->drawing_area
->window
);
397 gdk_gc_copy(drawing
->dotted_gc
, widget
->style
->white_gc
);
399 gint8 dash_list
[] = { 1, 2 };
400 gdk_gc_set_line_attributes(drawing
->dotted_gc
,
402 GDK_LINE_ON_OFF_DASH
,
405 gdk_gc_set_dashes(drawing
->dotted_gc
,
411 gint height_tot
= MAX(widget
->allocation
.height
, drawing
->height
);
412 gdk_draw_line(widget
->window
,
415 cursor_x
, height_tot
);
422 histo_after_expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
425 g_debug("AFTER EXPOSE");
432 histo_button_press_event( GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
434 HistoControlFlowData
*histo_control_flow_data
=
435 (HistoControlFlowData
*)g_object_get_data(
437 "histo_control_flow_data");
438 histoDrawing_t
*drawing
= histo_control_flow_data
->drawing
;
439 TimeWindow time_window
=
440 lttvwindow_get_time_window(histo_control_flow_data
->tab
);
443 if(event
->button
== 1)
447 /* left mouse button click */
448 g_debug("x click is : %f", event
->x
);
450 histo_convert_pixels_to_time(drawing
->width
, (guint
)event
->x
,
454 lttvwindow_report_current_time(histo_control_flow_data
->tab
, time
);
455 ////report event->y for vertical zoom +,-
461 //Viewer's vertical scroll bar is already omitted, not needed for histogram.
463 scrollbar_size_allocate(GtkWidget *widget,
464 GtkAllocation *allocation,
467 histoDrawing_t *drawing = (histoDrawing_t*)user_data;
469 gtk_widget_set_size_request(drawing->padding, allocation->width, -1);
470 //gtk_widget_queue_resize(drawing->padding);
471 //gtk_widget_queue_resize(drawing->ruler);
472 gtk_container_check_resize(GTK_CONTAINER(drawing->ruler_hbox));
478 histoDrawing_t
*histo_drawing_construct(HistoControlFlowData
*histo_control_flow_data
)
480 histoDrawing_t
*drawing
= g_new(histoDrawing_t
, 1);
482 drawing
->histo_control_flow_data
= histo_control_flow_data
;
484 drawing
->vbox
= gtk_vbox_new(FALSE
, 1);
487 drawing
->ruler_hbox
= gtk_hbox_new(FALSE
, 1);
488 drawing
->ruler
= gtk_drawing_area_new ();
489 //gtk_widget_set_size_request(drawing->ruler, -1, 27);
491 drawing
->padding
= gtk_drawing_area_new ();
492 //gtk_widget_set_size_request(drawing->padding, -1, 27);
494 gtk_box_pack_start(GTK_BOX(drawing
->ruler_hbox
), drawing
->padding
,FALSE
, FALSE
, 0);
496 gtk_box_pack_end(GTK_BOX(drawing
->ruler_hbox
), drawing
->ruler
,
499 drawing
->drawing_area
= gtk_drawing_area_new ();
503 ///at this time not necessary for histogram
504 drawing->hbox = gtk_hbox_new(FALSE, 1);
506 drawing->viewport = gtk_viewport_new(NULL, histo_control_flow_data->v_adjust);
507 drawing->scrollbar = gtk_vscrollbar_new(histo_control_flow_data->v_adjust);
508 gtk_box_pack_start(GTK_BOX(drawing->hbox), drawing->viewport,
510 gtk_box_pack_end(GTK_BOX(drawing->hbox), drawing->scrollbar,
512 gtk_container_add(GTK_CONTAINER(drawing->viewport),
513 drawing->drawing_area);*/
515 //add vertical ruler:
516 drawing
->vruler_drawing_hbox
= gtk_hbox_new(FALSE
, 1);
517 drawing
-> vertical_ruler
=gtk_drawing_area_new ();
518 gtk_box_pack_start(GTK_BOX(drawing
->vruler_drawing_hbox
), drawing
->vertical_ruler
,
520 gtk_box_pack_end(GTK_BOX(drawing
->vruler_drawing_hbox
), drawing
->drawing_area
,
522 gtk_widget_set_size_request(drawing
->vertical_ruler
, padding_width
, -1);
524 gtk_box_pack_start(GTK_BOX(drawing
->vbox
), drawing
->ruler_hbox
,
526 gtk_box_pack_end(GTK_BOX(drawing
->vbox
), drawing
->vruler_drawing_hbox
/*drawing_area*/,
529 drawing
->pango_layout
=
530 gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
535 drawing
->alloc_height
= 1;
536 drawing
->alloc_width
= 1;
538 drawing
->damage_begin
= 0;
539 drawing
->damage_end
= 0;
540 drawing
->horizontal_sel
= -1;
542 //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50);
543 g_object_set_data_full(
544 G_OBJECT(drawing
->drawing_area
),
545 "histo_Link_drawing_Data",
547 (GDestroyNotify
)histo_drawing_destroy
);
550 G_OBJECT(drawing
->ruler
),
555 G_OBJECT(drawing
->vertical_ruler
),
559 //gtk_widget_modify_bg( drawing->drawing_area,
561 // &CF_Colors[BLACK]);
563 //gdk_window_get_geometry(drawing->drawing_area->window,
565 // &(drawing->width),
566 // &(drawing->height),
569 //drawing->pixmap = gdk_pixmap_new(
570 // drawing->drawing_area->window,
575 drawing
->pixmap
= NULL
;
577 // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
578 // drawing->drawing_area->allocation.width,
579 // drawing->drawing_area->allocation.height,
582 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
584 G_CALLBACK (histo_configure_event
),
587 g_signal_connect (G_OBJECT(drawing
->ruler
),
589 G_CALLBACK(histo_expose_ruler
),
592 gtk_widget_add_events(drawing
->ruler
, GDK_POINTER_MOTION_MASK
);
593 gtk_widget_add_events(drawing
->vertical_ruler
, GDK_POINTER_MOTION_MASK
);
595 g_signal_connect (G_OBJECT(drawing
->ruler
),
596 "motion-notify-event",
597 G_CALLBACK(histo_motion_notify_ruler
),
601 g_signal_connect (G_OBJECT(drawing
->vertical_ruler
),
603 G_CALLBACK(histo_expose_vertical_ruler
),
606 g_signal_connect (G_OBJECT(drawing
->vertical_ruler
),
607 "motion-notify-event",
608 G_CALLBACK(histo_motion_notify_vertical_ruler
),
611 /*//not necessary for historam.
612 g_signal_connect (G_OBJECT(drawing->drawing_area),
614 G_CALLBACK(scrollbar_size_allocate),
615 (gpointer)drawing); */
618 gtk_widget_set_size_request(drawing
->padding
, padding_width
, -1);//use it for vertical ruler
620 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
622 G_CALLBACK (histo_expose_event
),
625 g_signal_connect_after (G_OBJECT(drawing
->drawing_area
),
627 G_CALLBACK (histo_after_expose_event
),
630 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
631 "button-press-event",
632 G_CALLBACK (histo_button_press_event
),
635 gtk_widget_show(drawing
->ruler
);
636 gtk_widget_show(drawing
->padding
);
637 gtk_widget_show(drawing
->ruler_hbox
);
638 gtk_widget_show(drawing
->vertical_ruler
);
639 gtk_widget_show(drawing
->vruler_drawing_hbox
);
640 gtk_widget_show(drawing
->drawing_area
);
642 /// gtk_widget_show(drawing->viewport);
643 /// gtk_widget_show(drawing->scrollbar);
644 /// gtk_widget_show(drawing->hbox);
646 /* Allocate the colors */
647 GdkColormap
* colormap
= gdk_colormap_get_system();
648 gboolean success
[NUM_COLORS
];
649 gdk_colormap_alloc_colors(colormap
, histo_drawing_colors
, NUM_COLORS
, FALSE
,
653 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data
->tab
)->window
));
655 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data
->tab
)->window
));
657 gdk_gc_copy(drawing
->gc
,
658 main_window_get_widget(histo_control_flow_data
->tab
)->style
->black_gc
);
659 gdk_gc_copy(drawing
->dotted_gc
,
660 main_window_get_widget(histo_control_flow_data
->tab
)->style
->white_gc
);
662 gint8 dash_list
[] = { 1, 2 };
663 gdk_gc_set_line_attributes(drawing
->dotted_gc
,
665 GDK_LINE_ON_OFF_DASH
,
668 gdk_gc_set_dashes(drawing
->dotted_gc
,
673 drawing
->ruler_gc_butt
=
674 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data
->tab
)->window
));
675 gdk_gc_copy(drawing
->ruler_gc_butt
,
676 main_window_get_widget(histo_control_flow_data
->tab
)->style
->black_gc
);
677 drawing
->ruler_gc_round
=
678 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data
->tab
)->window
));
679 gdk_gc_copy(drawing
->ruler_gc_round
,
680 main_window_get_widget(histo_control_flow_data
->tab
)->style
->black_gc
);
683 gdk_gc_set_line_attributes(drawing
->ruler_gc_butt
,
689 gdk_gc_set_line_attributes(drawing
->ruler_gc_round
,
697 void histo_drawing_destroy(histoDrawing_t
*drawing
)
699 g_info("histo_drawing_destroy %p", drawing
);
701 /* Free the colors */
702 GdkColormap
* colormap
= gdk_colormap_get_system();
704 gdk_colormap_free_colors(colormap
, histo_drawing_colors
, NUM_COLORS
);
706 // Do not unref here, histoDrawing_t destroyed by it's widget.
707 //g_object_unref( G_OBJECT(drawing->drawing_area));
708 if(drawing
->gc
!= NULL
)
709 gdk_gc_unref(drawing
->gc
);
711 g_object_unref(drawing
->pango_layout
);
712 if(drawing
->dotted_gc
!= NULL
) gdk_gc_unref(drawing
->dotted_gc
);
713 if(drawing
->ruler_gc_butt
!= NULL
) gdk_gc_unref(drawing
->ruler_gc_butt
);
714 if(drawing
->ruler_gc_round
!= NULL
) gdk_gc_unref(drawing
->ruler_gc_round
);
716 //added for histogram
718 gdk_pixmap_unref(drawing
->pixmap
);
720 g_info("histo_drawing_destroy end");
723 GtkWidget
*histo_drawing_get_drawing_area(histoDrawing_t
*drawing
)
725 return drawing
->drawing_area
;
728 GtkWidget
*histo_drawing_get_widget(histoDrawing_t
*drawing
)
730 return drawing
->vbox
;
733 void histo_drawing_draw_line( histoDrawing_t
*drawing
,
739 gdk_draw_line (pixmap
,
744 void histo_drawing_clear(histoDrawing_t
*drawing
,guint clear_from
,guint clear_to
)
746 guint clear_width
= clear_to
- clear_from
;
748 //disabled for histogram
749 rectangle_pixmap(cfd->process_list,
750 drawing->drawing_area->style->black_gc,
753 drawing->alloc_width, // do not overlap
755 //instead, this is added for histogram
757 histo_rectangle_pixmap (drawing
->drawing_area
->style
->black_gc
,
760 clear_width
/*drawing->width*/,
765 /* gdk_draw_rectangle (drawing->pixmap,
766 drawing->drawing_area->style->black_gc,
769 drawing->drawing_area->allocation.width,drawing->drawing_area->allocation.height );
772 /* ask for the buffer to be redrawn */
773 //enabled again for histogram.
774 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
776 clear_width
, drawing
->height
);
777 gdk_window_process_updates(drawing
->drawing_area
->window
,TRUE
);
778 //disabled instead for histogram
779 //gtk_widget_queue_draw ( drawing->drawing_area);
784 /* Insert a square corresponding to a new process in the list */
785 /* Applies to whole drawing->width */
786 void drawing_insert_square(histoDrawing_t
*drawing
,
790 //GdkRectangle update_rect;
791 gboolean reallocate
= FALSE
;
792 GdkPixmap
*new_pixmap
;
794 /* Allocate a new pixmap with new height */
795 if(drawing
->alloc_height
< drawing
->height
+ height
) {
797 new_pixmap
= gdk_pixmap_new(drawing
->drawing_area
->window
,
798 drawing
->width
+ SAFETY
+ EXTRA_ALLOC
,
799 drawing
->height
+ height
+ EXTRA_ALLOC
,
801 drawing
->alloc_width
= drawing
->width
+ SAFETY
+ EXTRA_ALLOC
;
802 drawing
->alloc_height
= drawing
->height
+ height
+ EXTRA_ALLOC
;
805 /* Copy the high region */
806 gdk_draw_pixmap (new_pixmap
,
807 drawing
->drawing_area
->style
->black_gc
,
811 drawing
->width
+ SAFETY
, y
);
814 new_pixmap
= drawing
->pixmap
;
817 //GdkPixmap *pixmap = gdk_pixmap_new(drawing->drawing_area->window,
818 // drawing->width + SAFETY,
819 // drawing->height + height,
822 /* add an empty square */
823 gdk_draw_rectangle (new_pixmap
,
824 drawing
->drawing_area
->style
->black_gc
,
827 drawing
->width
+ SAFETY
, // do not overlap
830 /* copy the bottom of the region */
831 gdk_draw_pixmap (new_pixmap
,
832 drawing
->drawing_area
->style
->black_gc
,
836 drawing
->width
+SAFETY
, drawing
->height
- y
);
839 if(reallocate
&& likely(drawing
->pixmap
)) {
840 gdk_pixmap_unref(drawing
->pixmap
);
841 drawing
->pixmap
= new_pixmap
;
844 if(unlikely(drawing
->height
==1)) drawing
->height
= height
;
845 else drawing
->height
+= height
;
847 gtk_widget_set_size_request(drawing
->drawing_area
,
850 gtk_widget_queue_resize_no_redraw(drawing
->drawing_area
);
852 /* ask for the buffer to be redrawn */
853 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
855 drawing
->width
, drawing
->height
-y
);
859 /* Remove a square corresponding to a removed process in the list */
860 void drawing_remove_square(histoDrawing_t
*drawing
,
866 if(unlikely((guint
)drawing
->height
== height
)) {
867 //pixmap = gdk_pixmap_new(
868 // drawing->drawing_area->window,
869 // drawing->width + SAFETY,
872 pixmap
= drawing
->pixmap
;
875 /* Allocate a new pixmap with new height */
876 //pixmap = gdk_pixmap_new(
877 // drawing->drawing_area->window,
878 // drawing->width + SAFETY,
879 // drawing->height - height,
881 /* Keep the same preallocated pixmap */
882 pixmap
= drawing
->pixmap
;
884 /* Copy the high region */
885 gdk_draw_pixmap (pixmap
,
886 drawing
->drawing_area
->style
->black_gc
,
890 drawing
->width
+ SAFETY
, y
);
892 /* Copy up the bottom of the region */
893 gdk_draw_pixmap (pixmap
,
894 drawing
->drawing_area
->style
->black_gc
,
898 drawing
->width
, drawing
->height
- y
- height
);
900 drawing
->height
-=height
;
903 //if(likely(drawing->pixmap))
904 // gdk_pixmap_unref(drawing->pixmap);
906 //drawing->pixmap = pixmap;
908 gtk_widget_set_size_request(drawing
->drawing_area
,
911 gtk_widget_queue_resize_no_redraw(drawing
->drawing_area
);
912 /* ask for the buffer to be redrawn */
913 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
915 drawing
->width
, MAX(drawing
->height
-y
, 1));
919 void histo_drawing_update_ruler(histoDrawing_t
*drawing
, TimeWindow
*time_window
)
921 gtk_widget_queue_draw(drawing
->ruler
);
924 /* Redraw the ruler */
926 histo_expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
928 histoDrawing_t
*drawing
= (histoDrawing_t
*)user_data
;
929 TimeWindow time_window
= lttvwindow_get_time_window(drawing
->histo_control_flow_data
->tab
);
932 PangoContext
*context
;
934 PangoFontDescription
*FontDesc
;
935 PangoRectangle ink_rect
;
937 GdkColor foreground
= { 0, 0, 0, 0 };
938 GdkColor background
= { 0, 0xffff, 0xffff, 0xffff };
940 LttTime window_end
= time_window
.end_time
;
942 ltt_time_div(time_window
.time_width
,2.0);
943 LttTime window_middle
=
944 ltt_time_add(half_width
,
945 time_window
.start_time
);
946 g_debug("ruler expose event");
948 gdk_draw_rectangle (drawing
->ruler
->window
,
949 drawing
->ruler
->style
->white_gc
,
951 event
->area
.x
, event
->area
.y
,
955 gdk_draw_line (drawing
->ruler
->window
,
956 drawing
->ruler_gc_butt
,
958 event
->area
.x
+ event
->area
.width
, 1);
961 snprintf(text
, 255, "%lus\n%luns",
962 time_window
.start_time
.tv_sec
,
963 time_window
.start_time
.tv_nsec
);
965 layout
= gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
967 context
= pango_layout_get_context(layout
);
968 FontDesc
= pango_context_get_font_description(context
);
970 pango_font_description_set_size(FontDesc
, 6*PANGO_SCALE
);
971 pango_layout_context_changed(layout
);
973 pango_layout_set_text(layout
, text
, -1);
974 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
975 global_width
+= ink_rect
.width
;
977 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
978 drawing
->ruler_gc_butt
,
981 layout
, &foreground
, &background
);
983 gdk_draw_line (drawing
->ruler
->window
,
984 drawing
->ruler_gc_round
,
989 snprintf(text
, 255, "%lus\n%luns", window_end
.tv_sec
,
992 pango_layout_set_text(layout
, text
, -1);
993 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
994 global_width
+= ink_rect
.width
;
996 if(global_width
<= drawing
->ruler
->allocation
.width
)
998 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
999 drawing
->ruler_gc_butt
,
1000 drawing
->ruler
->allocation
.width
- ink_rect
.width
,
1002 layout
, &foreground
, &background
);
1004 gdk_draw_line (drawing
->ruler
->window
,
1005 drawing
->ruler_gc_butt
,
1006 drawing
->ruler
->allocation
.width
-1, 1,
1007 drawing
->ruler
->allocation
.width
-1, 7);
1011 snprintf(text
, 255, "%lus\n%luns", window_middle
.tv_sec
,
1012 window_middle
.tv_nsec
);
1014 pango_layout_set_text(layout
, text
, -1);
1015 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1016 global_width
+= ink_rect
.width
;
1018 if(global_width
<= drawing
->ruler
->allocation
.width
)
1020 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
1021 drawing
->ruler_gc_butt
,
1022 (drawing
->ruler
->allocation
.width
- ink_rect
.width
)/2,
1024 layout
, &foreground
, &background
);
1026 gdk_draw_line (drawing
->ruler
->window
,
1027 drawing
->ruler_gc_butt
,
1028 drawing
->ruler
->allocation
.width
/2, 1,
1029 drawing
->ruler
->allocation
.width
/2, 7);
1032 g_object_unref(layout
);
1037 void histo_drawing_update_vertical_ruler(histoDrawing_t
*drawing
)//, TimeWindow *time_window)
1039 gtk_widget_queue_draw(drawing
->vertical_ruler
);
1042 /* notify mouse on ruler */
1044 histo_motion_notify_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1046 //g_debug("motion");
1047 //eventually follow mouse and show time here
1052 histo_motion_notify_vertical_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1054 //g_debug("motion");
1055 //eventually follow mouse and show time here
1061 /* Redraw the vertical ruler */
1063 histo_expose_vertical_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
1065 histoDrawing_t
*drawing
= (histoDrawing_t
*)user_data
;
1066 HistoControlFlowData
*histo_cfv
= drawing
->histo_control_flow_data
;
1069 PangoContext
*context
;
1070 PangoLayout
*layout
;
1071 PangoFontDescription
*FontDesc
;
1072 PangoRectangle ink_rect
;
1073 gint global_height
=0;
1074 GdkColor foreground
= { 0, 0, 0, 0 };
1075 GdkColor background
= { 0, 0xffff, 0xffff, 0xffff };
1076 GdkColor red
={ 0, 0xFFFF, 0x1E00, 0x1000 };
1077 //GdkColor magneta ={ 0, 0x8900, 0x0000, 0x8400 };
1078 g_debug("vertical ruler expose event");
1080 gdk_draw_rectangle (drawing
->vertical_ruler
->window
,
1081 drawing
->vertical_ruler
->style
->white_gc
,
1083 event
->area
.x
, event
->area
.y
,
1085 event
->area
.height
);
1087 gdk_draw_line (drawing
->vertical_ruler
->window
,
1088 drawing
->ruler_gc_butt
,
1089 padding_width
-1/*event->area.width-1*/,event
->area
.y
,
1090 padding_width
-1/*event->area.width-1*/,event
->area
.y
+ event
->area
.height
);
1092 snprintf(text
, 255, "%.1f", (float)histo_cfv
->max_height
);
1094 layout
= gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
1096 context
= pango_layout_get_context(layout
);
1097 FontDesc
= pango_context_get_font_description(context
);
1099 pango_font_description_set_size(FontDesc
, 6*PANGO_SCALE
);
1100 pango_layout_context_changed(layout
);
1102 pango_layout_set_text(layout
, text
, -1);
1103 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1104 global_height
+= ink_rect
.height
;
1106 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1107 drawing
->ruler_gc_butt
,
1110 layout
, &foreground
, &background
);
1112 gdk_draw_line (drawing
->vertical_ruler
->window
,
1113 drawing
->ruler_gc_round
,
1114 drawing
->vertical_ruler
-> allocation
.width
-1, 1,
1115 drawing
->vertical_ruler
-> allocation
.width
-7, 1);
1118 snprintf(text
, 255, "%d", 0);
1120 pango_layout_set_text(layout
, text
, -1);
1121 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1122 global_height
+= ink_rect
.height
;
1124 if(global_height
<= drawing
->vertical_ruler
->allocation
.height
)
1126 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1127 drawing
->ruler_gc_butt
,
1129 drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
-2,
1130 layout
, &foreground
, &background
);
1132 gdk_draw_line (drawing
->vertical_ruler
->window
,
1133 drawing
->ruler_gc_butt
,
1134 drawing
->vertical_ruler
-> allocation
.width
-1,
1135 drawing
->vertical_ruler
->allocation
.height
-1,
1136 drawing
->vertical_ruler
-> allocation
.width
-7,
1137 drawing
->vertical_ruler
->allocation
.height
-1);
1141 snprintf(text
, 255, "%.1f",(float) histo_cfv
->max_height
/2.0);
1143 pango_layout_set_text(layout
, text
, -1);
1144 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1145 global_height
+= ink_rect
.height
;
1147 if(global_height
<= drawing
->vertical_ruler
->allocation
.height
)
1149 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1150 drawing
->ruler_gc_butt
,
1152 (drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
)/2,
1153 layout
, &foreground
, &background
);
1155 gdk_draw_line (drawing
->vertical_ruler
->window
,
1156 drawing
->ruler_gc_butt
,
1157 drawing
->vertical_ruler
-> allocation
.width
-1,
1158 drawing
->vertical_ruler
-> allocation
.height
/2,
1159 drawing
->vertical_ruler
-> allocation
.width
-7,
1160 drawing
->vertical_ruler
->allocation
.height
/2);
1163 //show number of events at current time:
1164 LttTime current_time
=
1165 lttvwindow_get_current_time(histo_cfv
->tab
);
1166 TimeWindow time_window
=
1167 lttvwindow_get_time_window(histo_cfv
->tab
);
1168 LttTime time_begin
= time_window
.start_time
;
1169 LttTime time_width
= time_window
.time_width
;
1170 LttTime time_end
= ltt_time_add(time_begin
, time_width
);
1171 if((ltt_time_compare(current_time
, time_begin
) >= 0)&&
1172 (ltt_time_compare(current_time
, time_end
) <= 0))
1174 guint
*events_at_currenttime
;
1175 guint max_height
=histo_cfv
->max_height
;
1177 histo_convert_time_to_pixels(
1182 // if(x_test<histo_cfv->number_of_process->len)
1185 events_at_currenttime
=
1186 &g_array_index(histo_cfv
->number_of_process
,guint
,x
);
1189 if((*events_at_currenttime
) > max_height
)
1191 snprintf(text
, 255, "OverFlow!");
1192 pango_layout_set_text(layout
, text
, -1);
1193 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1194 global_height
+= ink_rect
.height
;
1195 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1196 drawing
->ruler_gc_butt
,
1198 (drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
)/5,
1199 layout
, &red
, &background
);
1201 // if((*events_at_currenttime) <= max_height)
1203 snprintf(text
, 255, "%.1f",
1204 (float) *events_at_currenttime
);
1206 pango_layout_set_text(layout
, text
, -1);
1207 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1208 global_height
+= ink_rect
.height
;
1210 if ((*events_at_currenttime
) == 0)
1212 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1213 drawing
->ruler_gc_butt
,
1215 (drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
)-2,
1216 layout
, &red
, &background
);
1218 else if ((*events_at_currenttime
) == max_height
)
1220 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1221 drawing
->ruler_gc_butt
,
1224 layout
, &red
, &background
);
1226 /*else if ((*events_at_currenttime) == max_height/2)
1228 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1229 drawing->ruler_gc_butt,
1231 (drawing->vertical_ruler->allocation.height - ink_rect.height)/2,
1232 layout, &red, &background);
1234 else if ((*events_at_currenttime
) > max_height
/2)
1236 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1237 drawing
->ruler_gc_butt
,
1239 (drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
)/4,
1240 layout
, &red
, &background
);
1243 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1244 drawing
->ruler_gc_butt
,
1246 ((drawing
->vertical_ruler
->allocation
.height
1247 - ink_rect
.height
)*3)/4,
1248 layout
, &red
, &background
);
1255 g_object_unref(layout
);