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"
39 #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)
43 // fixed #define TRACE_NUMBER 0
44 #define EXTRA_ALLOC 1024 // pixels
45 #define padding_width 50
47 #if 0 /* colors for two lines representation */
48 GdkColor histo_drawing_colors
[NUM_COLORS
] =
49 { /* Pixel, R, G, B */
50 { 0, 0, 0, 0 }, /* COL_BLACK */
51 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
52 { 0, 0x0FFF, 0xFFFF, 0xFFFF }, /* COL_WAIT_FORK : pale blue */
53 { 0, 0xFFFF, 0xFFFF, 0x0000 }, /* COL_WAIT_CPU : yellow */
54 { 0, 0xFFFF, 0xA000, 0xFCFF }, /* COL_EXIT : pale magenta */
55 { 0, 0xFFFF, 0x0000, 0xFFFF }, /* COL_ZOMBIE : purple */
56 { 0, 0xFFFF, 0x0000, 0x0000 }, /* COL_WAIT : red */
57 { 0, 0x0000, 0xFFFF, 0x0000 }, /* COL_RUN : green */
58 { 0, 0x8800, 0xFFFF, 0x8A00 }, /* COL_USER_MODE : pale green */
59 { 0, 0x09FF, 0x01FF, 0xFFFF }, /* COL_SYSCALL : blue */
60 { 0, 0xF900, 0x4200, 0xFF00 }, /* COL_TRAP : pale purple */
61 { 0, 0xFFFF, 0x5AFF, 0x01FF }, /* COL_IRQ : orange */
62 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_MODE_UNKNOWN : white */
68 GdkColor histo_drawing_colors
[NUM_COLORS
] =
69 { /* Pixel, R, G, B */
70 { 0, 0, 0, 0 }, /* COL_BLACK */
71 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
72 { 0, 0x0000, 0xFF00, 0x0000 }, /* COL_RUN_USER_MODE : green */
73 { 0, 0x0100, 0x9E00, 0xFFFF }, /* COL_RUN_SYSCALL : pale blue */
74 { 0, 0xFF00, 0xFF00, 0x0100 }, /* COL_RUN_TRAP : yellow */
75 { 0, 0xFFFF, 0x5E00, 0x0000 }, /* COL_RUN_IRQ : red */
76 { 0, 0x6600, 0x0000, 0x0000 }, /* COL_WAIT : dark red */
77 { 0, 0x7700, 0x7700, 0x0000 }, /* COL_WAIT_CPU : dark yellow */
78 { 0, 0x6400, 0x0000, 0x5D00 }, /* COL_ZOMBIE : dark purple */
79 { 0, 0x0700, 0x6400, 0x0000 }, /* COL_WAIT_FORK : dark green */
80 { 0, 0x8900, 0x0000, 0x8400 }, /* COL_EXIT : "less dark" magenta */
81 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_MODE_UNKNOWN : white */
82 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_UNNAMED : white */
92 WAIT CPU + WAIT FORK vert foncé ou jaune
101 /*****************************************************************************
102 * drawing functions *
103 *****************************************************************************/
106 histo_expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
);
109 histo_expose_vertical_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
);
112 histo_motion_notify_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
);
115 histo_motion_notify_vertical_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
);
117 /* Function responsible for updating the exposed area.
118 * It must do an events request to the lttvwindow API to ask for this update.
119 * Note : this function cannot clear the background, because it may
120 * erase drawing already present (SAFETY).
122 void histo_drawing_data_request(histoDrawing_t
*drawing
,
131 void histo_drawing_data_request_begin(EventsRequest
*events_request
, LttvTracesetState
*tss
)
133 g_debug("Begin of data request");
134 HistoControlFlowData
*cfd
= events_request
->viewer_data
;
135 LttvTracesetContext
*tsc
= LTTV_TRACESET_CONTEXT(tss
);
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
, LttvTracesetState
*tss
)
154 g_debug("Begin of chunk");
155 HistoControlFlowData
*cfd
= events_request
->viewer_data
;
156 LttvTracesetContext
*tsc
= LTTV_TRACESET_CONTEXT(tss
);
158 if(cfd
->chunk_has_begun
) return;
160 cfd
->chunk_has_begun
= TRUE
;
164 void histo_drawing_request_expose(EventsRequest
*events_request
,
165 LttvTracesetState
*tss
,
168 HistoControlFlowData
*cfd
= events_request
->viewer_data
;
169 histoDrawing_t
*drawing
= cfd
->drawing
;
171 gint x
, x_end
, width
;
172 LttvTracesetContext
*tsc
= (LttvTracesetContext
*)tss
;
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
)
749 HistoControlFlowData
*cfd
= drawing
->histo_control_flow_data
;
750 guint clear_width
= clear_to
- clear_from
;
752 //disabled for histogram
753 rectangle_pixmap(cfd->process_list,
754 drawing->drawing_area->style->black_gc,
757 drawing->alloc_width, // do not overlap
759 //instead, this is added for histogram
761 histo_rectangle_pixmap (drawing
->drawing_area
->style
->black_gc
,
764 clear_width
/*drawing->width*/,
769 /* gdk_draw_rectangle (drawing->pixmap,
770 drawing->drawing_area->style->black_gc,
773 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
)
927 req
.width
= drawing
->ruler
->allocation
.width
;
928 req
.height
= drawing
->ruler
->allocation
.height
;
933 rect
.width
= req
.width
;
934 rect
.height
= req
.height
;
936 gtk_widget_queue_draw(drawing
->ruler
);
937 //gtk_widget_draw( drawing->ruler, &rect);
940 /* Redraw the ruler */
942 histo_expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
944 histoDrawing_t
*drawing
= (histoDrawing_t
*)user_data
;
945 TimeWindow time_window
= lttvwindow_get_time_window(drawing
->histo_control_flow_data
->tab
);
948 PangoContext
*context
;
950 PangoFontDescription
*FontDesc
;
951 PangoRectangle ink_rect
;
953 GdkColor foreground
= { 0, 0, 0, 0 };
954 GdkColor background
= { 0, 0xffff, 0xffff, 0xffff };
956 LttTime window_end
= time_window
.end_time
;
958 ltt_time_div(time_window
.time_width
,2.0);
959 LttTime window_middle
=
960 ltt_time_add(half_width
,
961 time_window
.start_time
);
962 g_debug("ruler expose event");
964 gdk_draw_rectangle (drawing
->ruler
->window
,
965 drawing
->ruler
->style
->white_gc
,
967 event
->area
.x
, event
->area
.y
,
971 gdk_draw_line (drawing
->ruler
->window
,
972 drawing
->ruler_gc_butt
,
974 event
->area
.x
+ event
->area
.width
, 1);
977 snprintf(text
, 255, "%lus\n%luns",
978 time_window
.start_time
.tv_sec
,
979 time_window
.start_time
.tv_nsec
);
981 layout
= gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
983 context
= pango_layout_get_context(layout
);
984 FontDesc
= pango_context_get_font_description(context
);
986 pango_font_description_set_size(FontDesc
, 6*PANGO_SCALE
);
987 pango_layout_context_changed(layout
);
989 pango_layout_set_text(layout
, text
, -1);
990 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
991 global_width
+= ink_rect
.width
;
993 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
994 drawing
->ruler_gc_butt
,
997 layout
, &foreground
, &background
);
999 gdk_draw_line (drawing
->ruler
->window
,
1000 drawing
->ruler_gc_round
,
1005 snprintf(text
, 255, "%lus\n%luns", window_end
.tv_sec
,
1006 window_end
.tv_nsec
);
1008 pango_layout_set_text(layout
, text
, -1);
1009 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1010 global_width
+= ink_rect
.width
;
1012 if(global_width
<= drawing
->ruler
->allocation
.width
)
1014 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
1015 drawing
->ruler_gc_butt
,
1016 drawing
->ruler
->allocation
.width
- ink_rect
.width
,
1018 layout
, &foreground
, &background
);
1020 gdk_draw_line (drawing
->ruler
->window
,
1021 drawing
->ruler_gc_butt
,
1022 drawing
->ruler
->allocation
.width
-1, 1,
1023 drawing
->ruler
->allocation
.width
-1, 7);
1027 snprintf(text
, 255, "%lus\n%luns", window_middle
.tv_sec
,
1028 window_middle
.tv_nsec
);
1030 pango_layout_set_text(layout
, text
, -1);
1031 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1032 global_width
+= ink_rect
.width
;
1034 if(global_width
<= drawing
->ruler
->allocation
.width
)
1036 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
1037 drawing
->ruler_gc_butt
,
1038 (drawing
->ruler
->allocation
.width
- ink_rect
.width
)/2,
1040 layout
, &foreground
, &background
);
1042 gdk_draw_line (drawing
->ruler
->window
,
1043 drawing
->ruler_gc_butt
,
1044 drawing
->ruler
->allocation
.width
/2, 1,
1045 drawing
->ruler
->allocation
.width
/2, 7);
1048 g_object_unref(layout
);
1053 void histo_drawing_update_vertical_ruler(histoDrawing_t
*drawing
)//, TimeWindow *time_window)
1058 req
.width
= drawing
->vertical_ruler
->allocation
.width
;
1059 req
.height
= drawing
->vertical_ruler
->allocation
.height
;
1063 rect
.width
= req
.width
;
1064 rect
.height
= req
.height
;
1066 gtk_widget_queue_draw(drawing
->vertical_ruler
);
1067 //gtk_widget_draw( drawing->ruler, &rect);
1070 /* notify mouse on ruler */
1072 histo_motion_notify_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1074 //g_debug("motion");
1075 //eventually follow mouse and show time here
1079 histo_motion_notify_vertical_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1081 //g_debug("motion");
1082 //eventually follow mouse and show time here
1087 /* Redraw the vertical ruler */
1089 histo_expose_vertical_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
1091 histoDrawing_t
*drawing
= (histoDrawing_t
*)user_data
;
1092 HistoControlFlowData
*histo_cfv
= drawing
->histo_control_flow_data
;
1095 PangoContext
*context
;
1096 PangoLayout
*layout
;
1097 PangoFontDescription
*FontDesc
;
1098 PangoRectangle ink_rect
;
1099 gint global_height
=0;
1100 GdkColor foreground
= { 0, 0, 0, 0 };
1101 GdkColor background
= { 0, 0xffff, 0xffff, 0xffff };
1102 GdkColor red
={ 0, 0xFFFF, 0x1E00, 0x1000 };
1103 GdkColor magneta
={ 0, 0x8900, 0x0000, 0x8400 };
1104 g_debug("vertical ruler expose event");
1106 gdk_draw_rectangle (drawing
->vertical_ruler
->window
,
1107 drawing
->vertical_ruler
->style
->white_gc
,
1109 event
->area
.x
, event
->area
.y
,
1111 event
->area
.height
);
1113 gdk_draw_line (drawing
->vertical_ruler
->window
,
1114 drawing
->ruler_gc_butt
,
1115 padding_width
-1/*event->area.width-1*/,event
->area
.y
,
1116 padding_width
-1/*event->area.width-1*/,event
->area
.y
+ event
->area
.height
);
1118 snprintf(text
, 255, "%.1f", (float)histo_cfv
->max_height
);
1120 layout
= gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
1122 context
= pango_layout_get_context(layout
);
1123 FontDesc
= pango_context_get_font_description(context
);
1125 pango_font_description_set_size(FontDesc
, 6*PANGO_SCALE
);
1126 pango_layout_context_changed(layout
);
1128 pango_layout_set_text(layout
, text
, -1);
1129 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1130 global_height
+= ink_rect
.height
;
1132 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1133 drawing
->ruler_gc_butt
,
1136 layout
, &foreground
, &background
);
1138 gdk_draw_line (drawing
->vertical_ruler
->window
,
1139 drawing
->ruler_gc_round
,
1140 drawing
->vertical_ruler
-> allocation
.width
-1, 1,
1141 drawing
->vertical_ruler
-> allocation
.width
-7, 1);
1144 snprintf(text
, 255, "%lu",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
-1,
1162 drawing
->vertical_ruler
-> allocation
.width
-7,
1163 drawing
->vertical_ruler
->allocation
.height
-1);
1167 snprintf(text
, 255, "%.1f",(float) histo_cfv
->max_height
/2.0);
1169 pango_layout_set_text(layout
, text
, -1);
1170 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1171 global_height
+= ink_rect
.height
;
1173 if(global_height
<= drawing
->vertical_ruler
->allocation
.height
)
1175 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1176 drawing
->ruler_gc_butt
,
1178 (drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
)/2,
1179 layout
, &foreground
, &background
);
1181 gdk_draw_line (drawing
->vertical_ruler
->window
,
1182 drawing
->ruler_gc_butt
,
1183 drawing
->vertical_ruler
-> allocation
.width
-1,
1184 drawing
->vertical_ruler
-> allocation
.height
/2,
1185 drawing
->vertical_ruler
-> allocation
.width
-7,
1186 drawing
->vertical_ruler
->allocation
.height
/2);
1189 //show number of events at current time:
1190 LttTime current_time
=
1191 lttvwindow_get_current_time(histo_cfv
->tab
);
1192 TimeWindow time_window
=
1193 lttvwindow_get_time_window(histo_cfv
->tab
);
1194 LttTime time_begin
= time_window
.start_time
;
1195 LttTime time_width
= time_window
.time_width
;
1196 LttTime time_end
= ltt_time_add(time_begin
, time_width
);
1197 if((ltt_time_compare(current_time
, time_begin
) >= 0)&&
1198 (ltt_time_compare(current_time
, time_end
) <= 0))
1200 guint
*events_at_currenttime
;
1201 guint max_height
=histo_cfv
->max_height
;
1203 histo_convert_time_to_pixels(
1208 // if(x_test<histo_cfv->number_of_process->len)
1211 events_at_currenttime
=
1212 &g_array_index(histo_cfv
->number_of_process
,guint
,x
);
1215 if((*events_at_currenttime
) > max_height
)
1217 snprintf(text
, 255, "OverFlow!");
1218 pango_layout_set_text(layout
, text
, -1);
1219 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1220 global_height
+= ink_rect
.height
;
1221 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1222 drawing
->ruler_gc_butt
,
1224 (drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
)/5,
1225 layout
, &red
, &background
);
1227 // if((*events_at_currenttime) <= max_height)
1229 snprintf(text
, 255, "%.1f",
1230 (float) *events_at_currenttime
);
1232 pango_layout_set_text(layout
, text
, -1);
1233 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1234 global_height
+= ink_rect
.height
;
1236 if ((*events_at_currenttime
) == 0)
1238 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1239 drawing
->ruler_gc_butt
,
1241 (drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
)-2,
1242 layout
, &red
, &background
);
1244 else if ((*events_at_currenttime
) == max_height
)
1246 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1247 drawing
->ruler_gc_butt
,
1250 layout
, &red
, &background
);
1252 /*else if ((*events_at_currenttime) == max_height/2)
1254 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1255 drawing->ruler_gc_butt,
1257 (drawing->vertical_ruler->allocation.height - ink_rect.height)/2,
1258 layout, &red, &background);
1260 else if ((*events_at_currenttime
) > max_height
/2)
1262 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1263 drawing
->ruler_gc_butt
,
1265 (drawing
->vertical_ruler
->allocation
.height
- ink_rect
.height
)/4,
1266 layout
, &red
, &background
);
1269 gdk_draw_layout_with_colors(drawing
->vertical_ruler
->window
,
1270 drawing
->ruler_gc_butt
,
1272 ((drawing
->vertical_ruler
->allocation
.height
1273 - ink_rect
.height
)*3)/4,
1274 layout
, &red
, &background
);
1281 g_object_unref(layout
);