1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 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>
36 #include "eventhooks.h"
39 //#define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
42 // fixed #define TRACE_NUMBER 0
43 #define EXTRA_ALLOC 1024 // pixels
46 #if 0 /* colors for two lines representation */
47 GdkColor drawing_colors
[NUM_COLORS
] =
48 { /* Pixel, R, G, B */
49 { 0, 0, 0, 0 }, /* COL_BLACK */
50 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
51 { 0, 0x0FFF, 0xFFFF, 0xFFFF }, /* COL_WAIT_FORK : pale blue */
52 { 0, 0xFFFF, 0xFFFF, 0x0000 }, /* COL_WAIT_CPU : yellow */
53 { 0, 0xFFFF, 0xA000, 0xFCFF }, /* COL_EXIT : pale magenta */
54 { 0, 0xFFFF, 0x0000, 0xFFFF }, /* COL_ZOMBIE : purple */
55 { 0, 0xFFFF, 0x0000, 0x0000 }, /* COL_WAIT : red */
56 { 0, 0x0000, 0xFFFF, 0x0000 }, /* COL_RUN : green */
57 { 0, 0x8800, 0xFFFF, 0x8A00 }, /* COL_USER_MODE : pale green */
58 { 0, 0x09FF, 0x01FF, 0xFFFF }, /* COL_SYSCALL : blue */
59 { 0, 0xF900, 0x4200, 0xFF00 }, /* COL_TRAP : pale purple */
60 { 0, 0xFFFF, 0x5AFF, 0x01FF }, /* COL_IRQ : orange */
61 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_MODE_UNKNOWN : white */
67 GdkColor drawing_colors
[NUM_COLORS
] =
68 { /* Pixel, R, G, B */
69 { 0, 0, 0, 0 }, /* COL_BLACK */
70 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
71 { 0, 0x0000, 0xFF00, 0x0000 }, /* COL_RUN_USER_MODE : green */
72 { 0, 0x0100, 0x9E00, 0xFFFF }, /* COL_RUN_SYSCALL : pale blue */
73 { 0, 0xFF00, 0xFF00, 0x0100 }, /* COL_RUN_TRAP : yellow */
74 { 0, 0xFFFF, 0x5E00, 0x0000 }, /* COL_RUN_IRQ : orange */
75 { 0, 0xFFFF, 0x9400, 0x9600 }, /* COL_RUN_SOFT_IRQ : pink */
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 */
86 GdkColor drawing_colors_cpu
[NUM_COLORS_CPU
] =
87 { /* Pixel, R, G, B */
88 { 0, 0x0000, 0x0000, 0x0000 }, /* COL_CPU_UNKNOWN */
89 { 0, 0xBBBB, 0xBBBB, 0xBBBB }, /* COL_CPU_IDLE */
90 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_CPU_BUSY */
91 { 0, 0xFFFF, 0x5E00, 0x0000 }, /* COL_CPU_IRQ */
92 { 0, 0xFF00, 0xFF00, 0x0100 }, /* COL_CPU_TRAP */
95 GdkColor drawing_colors_irq
[NUM_COLORS_IRQ
] =
96 { /* Pixel, R, G, B */
97 { 0, 0x0000, 0x0000, 0x0000 }, /* COL_IRQ_UNKNOWN */
98 { 0, 0xBBBB, 0xBBBB, 0xBBBB }, /* COL_IRQ_IDLE */
99 { 0, 0xFFFF, 0x5E00, 0x0000 }, /* COL_IRQ_BUSY */
102 GdkColor drawing_colors_bdev
[NUM_COLORS_BDEV
] =
103 { /* Pixel, R, G, B */
104 { 0, 0x0000, 0x0000, 0x0000 }, /* COL_BDEV_UNKNOWN */
105 { 0, 0xBBBB, 0xBBBB, 0xBBBB }, /* COL_BDEV_IDLE */
106 { 0, 0x0000, 0x0000, 0xFFFF }, /* COL_BDEV_BUSY_READING */
107 { 0, 0xFFFF, 0x0000, 0x0000 }, /* COL_BDEV_BUSY_WRITING */
110 /*****************************************************************************
111 * drawing functions *
112 *****************************************************************************/
115 expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
);
118 motion_notify_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 drawing_data_request(Drawing_t
*drawing
,
131 if(width
< 0) return ;
132 if(height
< 0) return ;
135 Tab
*tab
= drawing
->control_flow_data
->tab
;
136 TimeWindow time_window
=
137 lttvwindow_get_time_window(tab
);
139 ControlFlowData
*control_flow_data
= drawing
->control_flow_data
;
140 // (ControlFlowData*)g_object_get_data(
141 // G_OBJECT(drawing->drawing_area), "control_flow_data");
143 LttTime start
, time_end
;
144 LttTime window_end
= time_window
.end_time
;
146 g_debug("req : window start_time : %lu, %lu", time_window
.start_time
.tv_sec
,
147 time_window
.start_time
.tv_nsec
);
149 g_debug("req : window time width : %lu, %lu", time_window
.time_width
.tv_sec
,
150 time_window
.time_width
.tv_nsec
);
152 g_debug("req : window_end : %lu, %lu", window_end
.tv_sec
,
155 g_debug("x is : %i, x+width is : %i", x
, x
+width
);
157 convert_pixels_to_time(drawing
->width
, x
,
161 convert_pixels_to_time(drawing
->width
, x
+width
,
164 time_end
= ltt_time_add(time_end
, ltt_time_one
); // because main window
165 // doesn't deliver end time.
167 lttvwindow_events_request_remove_all(tab
,
171 /* find the tracehooks */
172 LttvTracesetContext
*tsc
= lttvwindow_get_traceset_context(tab
);
174 LttvTraceset
*traceset
= tsc
->ts
;
176 guint i
, k
, l
, nb_trace
;
180 LttvTracefileState
*tfs
;
191 nb_trace
= lttv_traceset_number(traceset
);
192 // FIXME (fixed) : eventually request for more traces
193 for(i
= 0 ; i
< nb_trace
; i
++) {
194 EventsRequest
*events_request
= g_new(EventsRequest
, 1);
196 //LttvHooks *event = lttv_hooks_new();
197 LttvHooksById
*event_by_id
= lttv_hooks_by_id_new();
198 LttvHooks
*before_chunk_traceset
= lttv_hooks_new();
199 LttvHooks
*after_chunk_traceset
= lttv_hooks_new();
200 LttvHooks
*before_request_hook
= lttv_hooks_new();
201 LttvHooks
*after_request_hook
= lttv_hooks_new();
203 lttv_hooks_add(before_chunk_traceset
,
208 lttv_hooks_add(after_chunk_traceset
,
213 lttv_hooks_add(before_request_hook
,
218 lttv_hooks_add(after_request_hook
,
224 ts
= (LttvTraceState
*)tsc
->traces
[i
];
226 /* Find the eventtype id for the following events and register the
227 associated by id hooks. */
229 hooks
= g_array_sized_new(FALSE
, FALSE
, sizeof(LttvTraceHook
), 18);
233 // lttv_trace_find_hook(ts->parent.t,
234 // LTT_FACILITY_KERNEL_ARCH,
235 // LTT_EVENT_SYSCALL_ENTRY,
236 // FIELD_ARRAY(LTT_FIELD_SYSCALL_ID),
237 // before_execmode_hook,
241 // lttv_trace_find_hook(ts->parent.t,
242 // LTT_FACILITY_KERNEL_ARCH,
243 // LTT_EVENT_SYSCALL_EXIT,
245 // before_execmode_hook,
249 lttv_trace_find_hook(ts
->parent
.t
,
250 LTT_FACILITY_KERNEL_ARCH
,
251 LTT_EVENT_TRAP_ENTRY
,
252 FIELD_ARRAY(LTT_FIELD_TRAP_ID
),
253 before_execmode_hook
,
257 lttv_trace_find_hook(ts
->parent
.t
,
258 LTT_FACILITY_KERNEL_ARCH
,
261 before_execmode_hook
,
265 lttv_trace_find_hook(ts
->parent
.t
,
268 FIELD_ARRAY(LTT_FIELD_IRQ_ID
),
269 before_execmode_hook
,
273 lttv_trace_find_hook(ts
->parent
.t
,
277 before_execmode_hook
,
281 // lttv_trace_find_hook(ts->parent.t,
282 // LTT_FACILITY_KERNEL,
283 // LTT_EVENT_SOFT_IRQ_ENTRY,
284 // FIELD_ARRAY(LTT_FIELD_SOFT_IRQ_ID),
285 // before_execmode_hook,
289 // lttv_trace_find_hook(ts->parent.t,
290 // LTT_FACILITY_KERNEL,
291 // LTT_EVENT_SOFT_IRQ_EXIT,
293 // before_execmode_hook,
298 lttv_trace_find_hook(ts
->parent
.t
,
300 LTT_EVENT_SCHED_SCHEDULE
,
301 FIELD_ARRAY(LTT_FIELD_PREV_PID
, LTT_FIELD_NEXT_PID
, LTT_FIELD_PREV_STATE
),
302 before_schedchange_hook
,
306 // lttv_trace_find_hook(ts->parent.t,
307 // LTT_FACILITY_KERNEL,
308 // LTT_EVENT_PROCESS_EXIT,
309 // FIELD_ARRAY(LTT_FIELD_PID),
310 // before_process_exit_hook,
314 // lttv_trace_find_hook(ts->parent.t,
315 // LTT_FACILITY_KERNEL,
316 // LTT_EVENT_PROCESS_FREE,
317 // FIELD_ARRAY(LTT_FIELD_PID),
318 // before_process_release_hook,
322 // lttv_trace_find_hook(ts->parent.t,
323 // LTT_FACILITY_LIST,
324 // LTT_EVENT_STATEDUMP_END,
326 // before_statedump_end,
330 lttv_trace_find_hook(ts
->parent
.t
,
332 LTT_EVENT_REQUEST_ISSUE
,
333 FIELD_ARRAY(LTT_FIELD_MAJOR
, LTT_FIELD_MINOR
, LTT_FIELD_OPERATION
),
334 before_bdev_event_hook
,
338 lttv_trace_find_hook(ts
->parent
.t
,
340 LTT_EVENT_REQUEST_COMPLETE
,
341 FIELD_ARRAY(LTT_FIELD_MAJOR
, LTT_FIELD_MINOR
, LTT_FIELD_OPERATION
),
342 before_bdev_event_hook
,
347 first_after
= hooks
->len
;
349 lttv_trace_find_hook(ts
->parent
.t
,
351 LTT_EVENT_SCHED_SCHEDULE
,
352 FIELD_ARRAY(LTT_FIELD_PREV_PID
, LTT_FIELD_NEXT_PID
, LTT_FIELD_PREV_STATE
),
353 after_schedchange_hook
,
357 // lttv_trace_find_hook(ts->parent.t,
358 // LTT_FACILITY_KERNEL,
359 // LTT_EVENT_PROCESS_FORK,
360 // FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID),
361 // after_process_fork_hook,
365 // lttv_trace_find_hook(ts->parent.t,
366 // LTT_FACILITY_KERNEL,
367 // LTT_EVENT_PROCESS_EXIT,
368 // FIELD_ARRAY(LTT_FIELD_PID),
369 // after_process_exit_hook,
373 // lttv_trace_find_hook(ts->parent.t,
374 // LTT_FACILITY_KERNEL,
377 // after_fs_exec_hook,
381 // lttv_trace_find_hook(ts->parent.t,
382 // LTT_FACILITY_USER_GENERIC,
383 // LTT_EVENT_THREAD_BRAND,
384 // FIELD_ARRAY(LTT_FIELD_NAME),
385 // after_user_generic_thread_brand_hook,
389 // lttv_trace_find_hook(ts->parent.t,
390 // LTT_FACILITY_LIST,
391 // LTT_EVENT_PROCESS_STATE,
392 // FIELD_ARRAY(LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME),
393 // after_event_enum_process_hook,
398 /* Add these hooks to each event_by_id hooks list */
400 for(k
= 0 ; k
< first_after
; k
++) {
401 th
= &g_array_index(hooks
, LttvTraceHook
, k
);
402 lttv_hooks_add(lttv_hooks_by_id_find(event_by_id
, th
->id
),
409 for(k
= first_after
; k
< hooks
->len
; k
++) {
410 th
= &g_array_index(hooks
, LttvTraceHook
, k
);
411 lttv_hooks_add(lttv_hooks_by_id_find(event_by_id
, th
->id
),
417 events_request
->hooks
= hooks
;
419 // Fill the events request
420 events_request
->owner
= control_flow_data
;
421 events_request
->viewer_data
= control_flow_data
;
422 events_request
->servicing
= FALSE
;
423 events_request
->start_time
= start
;
424 events_request
->start_position
= NULL
;
425 events_request
->stop_flag
= FALSE
;
426 events_request
->end_time
= time_end
;
427 events_request
->num_events
= G_MAXUINT
;
428 events_request
->end_position
= NULL
;
429 events_request
->trace
= i
; //fixed /* FIXME */
430 events_request
->before_chunk_traceset
= before_chunk_traceset
;
431 events_request
->before_chunk_trace
= NULL
;
432 events_request
->before_chunk_tracefile
= NULL
;
433 events_request
->event
= NULL
;
434 events_request
->event_by_id
= event_by_id
;
435 events_request
->after_chunk_tracefile
= NULL
;
436 events_request
->after_chunk_trace
= NULL
;
437 events_request
->after_chunk_traceset
= after_chunk_traceset
;
438 events_request
->before_request
= before_request_hook
;
439 events_request
->after_request
= after_request_hook
;
441 g_debug("req : start : %lu, %lu", start
.tv_sec
,
444 g_debug("req : end : %lu, %lu", time_end
.tv_sec
,
447 lttvwindow_events_request(tab
, events_request
);
454 static void set_last_start(gpointer key
, gpointer value
, gpointer user_data
)
456 ResourceInfo
*process_info
= (ResourceInfo
*)key
;
457 HashedResourceData
*hashed_process_data
= (HashedResourceData
*)value
;
458 guint x
= (guint
)user_data
;
460 hashed_process_data
->x
.over
= x
;
461 hashed_process_data
->x
.over_used
= FALSE
;
462 hashed_process_data
->x
.over_marked
= FALSE
;
463 hashed_process_data
->x
.middle
= x
;
464 hashed_process_data
->x
.middle_used
= FALSE
;
465 hashed_process_data
->x
.middle_marked
= FALSE
;
466 hashed_process_data
->x
.under
= x
;
467 hashed_process_data
->x
.under_used
= FALSE
;
468 hashed_process_data
->x
.under_marked
= FALSE
;
469 hashed_process_data
->next_good_time
= ltt_time_zero
;
474 void drawing_data_request_begin(EventsRequest
*events_request
, LttvTracesetState
*tss
)
476 g_debug("Begin of data request");
477 ControlFlowData
*cfd
= events_request
->viewer_data
;
478 LttvTracesetContext
*tsc
= LTTV_TRACESET_CONTEXT(tss
);
479 TimeWindow time_window
=
480 lttvwindow_get_time_window(cfd
->tab
);
482 guint width
= cfd
->drawing
->width
;
485 cfd
->drawing
->last_start
= events_request
->start_time
;
487 convert_time_to_pixels(
489 events_request
->start_time
,
493 g_hash_table_foreach(cfd
->process_list
->process_hash
, set_last_start
,
498 void drawing_chunk_begin(EventsRequest
*events_request
, LttvTracesetState
*tss
)
500 g_debug("Begin of chunk");
501 ControlFlowData
*cfd
= events_request
->viewer_data
;
502 LttvTracesetContext
*tsc
= &tss
->parent
.parent
;
503 //LttTime current_time = lttv_traceset_context_get_current_tfc(tsc)->timestamp;
505 LttvTraceset
*traceset
= tsc
->ts
;
506 guint nb_trace
= lttv_traceset_number(traceset
);
508 if(!cfd
->process_list
->current_hash_data
) {
509 cfd
->process_list
->current_hash_data
= g_new(HashedResourceData
**,nb_trace
);
510 for(i
= 0 ; i
< nb_trace
; i
++) {
511 guint num_cpu
= ltt_trace_get_num_cpu(tss
->parent
.traces
[i
]->t
);
512 cfd
->process_list
->current_hash_data
[i
] = g_new(HashedResourceData
*,num_cpu
);
513 memset(cfd
->process_list
->current_hash_data
[i
], 0,
514 sizeof(HashedResourceData
*)*num_cpu
);
517 //cfd->drawing->last_start = LTT_TIME_MIN(current_time,
518 // events_request->end_time);
522 void drawing_request_expose(EventsRequest
*events_request
,
523 LttvTracesetState
*tss
,
529 ControlFlowData
*cfd
= events_request
->viewer_data
;
530 LttvTracesetContext
*tsc
= (LttvTracesetContext
*)tss
;
531 Drawing_t
*drawing
= cfd
->drawing
;
533 TimeWindow time_window
=
534 lttvwindow_get_time_window(cfd
->tab
);
536 g_debug("request expose");
538 convert_time_to_pixels(
543 x
= drawing
->damage_begin
;
547 drawing
->damage_begin
= x
+width
;
550 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
552 width
, drawing
->drawing_area
->allocation
.height
);
554 /* Update directly when scrolling */
555 gdk_window_process_updates(drawing
->drawing_area
->window
,
563 /* Create a new backing pixmap of the appropriate size */
564 /* As the scaling will always change, it's of no use to copy old
567 * Only change the size if width changes. The height is specified and changed
568 * when process ID are added or removed from the process list.
571 configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
574 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
577 /* First, get the new time interval of the main window */
578 /* we assume (see documentation) that the main window
579 * has updated the time interval before this configure gets
582 //lttvwindow_get_time_window(drawing->control_flow_data->mw,
583 // &drawing->control_flow_data->time_window);
585 /* New pixmap, size of the configure event */
586 //GdkPixmap *pixmap = gdk_pixmap_new(widget->window,
587 // widget->allocation.width + SAFETY,
588 // widget->allocation.height + SAFETY,
591 if(widget
->allocation
.width
!= drawing
->width
) {
592 g_debug("drawing configure event");
593 g_debug("New alloc draw size : %i by %i",widget
->allocation
.width
,
594 widget
->allocation
.height
);
596 drawing
->width
= widget
->allocation
.width
;
598 if(drawing
->alloc_width
< widget
->allocation
.width
) {
599 //if(drawing->pixmap)
600 // gdk_pixmap_unref(drawing->pixmap);
602 //drawing->pixmap = gdk_pixmap_new(widget->window,
603 // drawing->width + SAFETY + EXTRA_ALLOC,
604 // drawing->height + EXTRA_ALLOC,
606 drawing
->alloc_width
= drawing
->width
+ SAFETY
+ EXTRA_ALLOC
;
607 drawing
->alloc_height
= drawing
->height
+ EXTRA_ALLOC
;
608 update_pixmap_size(drawing
->control_flow_data
->process_list
,
609 drawing
->alloc_width
);
610 update_index_to_pixmap(drawing
->control_flow_data
->process_list
);
612 //drawing->height = widget->allocation.height;
614 //ProcessList_get_height
615 // (GuiControlFlow_get_process_list(drawing->control_flow_data)),
619 //gdk_draw_rectangle (drawing->pixmap,
620 // widget->style->black_gc,
623 // drawing->width+SAFETY,
626 //g_info("init data request");
629 /* Initial data request */
630 /* no, do initial data request in the expose event */
631 // Do not need to ask for data of 1 pixel : not synchronized with
632 // main window time at this moment.
633 //drawing_data_request(drawing, &drawing->pixmap, 0, 0,
634 // widget->allocation.width,
635 // widget->allocation.height);
637 //drawing->width = widget->allocation.width;
638 //drawing->height = widget->allocation.height;
640 drawing
->damage_begin
= 0;
641 drawing
->damage_end
= widget
->allocation
.width
;
643 if((widget
->allocation
.width
!= 1 &&
644 widget
->allocation
.height
!= 1)
645 && drawing
->damage_begin
< drawing
->damage_end
)
648 rectangle_pixmap (drawing
->control_flow_data
->process_list
,
649 drawing
->drawing_area
->style
->black_gc
,
652 drawing
->alloc_width
, // do not overlap
656 drawing_data_request(drawing
,
657 drawing
->damage_begin
,
659 drawing
->damage_end
- drawing
->damage_begin
,
667 /* Redraw the screen from the backing pixmap */
669 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
671 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
673 ControlFlowData
*control_flow_data
=
674 (ControlFlowData
*)g_object_get_data(
676 "control_flow_data");
678 if(unlikely(drawing
->gc
== NULL
)) {
679 drawing
->gc
= gdk_gc_new(drawing
->drawing_area
->window
);
680 gdk_gc_copy(drawing
->gc
, drawing
->drawing_area
->style
->black_gc
);
683 TimeWindow time_window
=
684 lttvwindow_get_time_window(control_flow_data
->tab
);
685 LttTime current_time
=
686 lttvwindow_get_current_time(control_flow_data
->tab
);
690 LttTime window_end
= time_window
.end_time
;
692 /* update the screen from the pixmap buffer */
694 gdk_draw_pixmap(widget
->window
,
695 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
697 event
->area
.x
, event
->area
.y
,
698 event
->area
.x
, event
->area
.y
,
699 event
->area
.width
, event
->area
.height
);
701 drawing
->height
= processlist_get_height(control_flow_data
->process_list
);
703 copy_pixmap_to_screen(control_flow_data
->process_list
,
705 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
706 event
->area
.x
, event
->area
.y
,
707 event
->area
.width
, event
->area
.height
);
709 copy_pixmap_to_screen(control_flow_data
->process_list
,
712 event
->area
.x
, event
->area
.y
,
713 event
->area
.width
, event
->area
.height
);
716 /* Erase the dotted lines left.. */
717 if(widget
->allocation
.height
> drawing
->height
)
719 gdk_draw_rectangle (widget
->window
,
720 drawing
->drawing_area
->style
->black_gc
,
722 event
->area
.x
, drawing
->height
,
723 event
->area
.width
, // do not overlap
724 widget
->allocation
.height
- drawing
->height
);
726 if(ltt_time_compare(time_window
.start_time
, current_time
) <= 0 &&
727 ltt_time_compare(window_end
, current_time
) >= 0)
729 /* Draw the dotted lines */
730 convert_time_to_pixels(
737 if(drawing
->dotted_gc
== NULL
) {
739 drawing
->dotted_gc
= gdk_gc_new(drawing
->drawing_area
->window
);
740 gdk_gc_copy(drawing
->dotted_gc
, widget
->style
->white_gc
);
742 gint8 dash_list
[] = { 1, 2 };
743 gdk_gc_set_line_attributes(drawing
->dotted_gc
,
745 GDK_LINE_ON_OFF_DASH
,
748 gdk_gc_set_dashes(drawing
->dotted_gc
,
754 gint height_tot
= MAX(widget
->allocation
.height
, drawing
->height
);
755 gdk_draw_line(widget
->window
,
758 cursor_x
, height_tot
);
764 after_expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
767 g_debug("AFTER EXPOSE");
776 tree_row_activated(GtkTreeModel
*treemodel
,
778 GtkTreeViewColumn
*arg2
,
781 ControlFlowData
*cfd
= (ControlFlowData
*)user_data
;
782 Drawing_t
*drawing
= cfd
->drawing
;
783 GtkTreeView
*treeview
= cfd
->process_list
->process_list_widget
;
787 path_indices
= gtk_tree_path_get_indices (arg1
);
789 height
= get_cell_height(cfd
->process_list
,
790 GTK_TREE_VIEW(treeview
));
791 drawing
->horizontal_sel
= height
* path_indices
[0];
792 g_critical("new hor sel : %i", drawing
->horizontal_sel
);
798 button_press_event( GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
800 ControlFlowData
*control_flow_data
=
801 (ControlFlowData
*)g_object_get_data(
803 "control_flow_data");
804 Drawing_t
*drawing
= control_flow_data
->drawing
;
805 TimeWindow time_window
=
806 lttvwindow_get_time_window(control_flow_data
->tab
);
809 if(event
->button
== 1)
813 /* left mouse button click */
814 g_debug("x click is : %f", event
->x
);
816 convert_pixels_to_time(drawing
->width
, (guint
)event
->x
,
820 lttvwindow_report_current_time(control_flow_data
->tab
, time
);
828 scrollbar_size_allocate(GtkWidget
*widget
,
829 GtkAllocation
*allocation
,
832 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
834 gtk_widget_set_size_request(drawing
->padding
, allocation
->width
, -1);
835 //gtk_widget_queue_resize(drawing->padding);
836 //gtk_widget_queue_resize(drawing->ruler);
837 gtk_container_check_resize(GTK_CONTAINER(drawing
->ruler_hbox
));
843 Drawing_t
*drawing_construct(ControlFlowData
*control_flow_data
)
845 Drawing_t
*drawing
= g_new(Drawing_t
, 1);
847 drawing
->control_flow_data
= control_flow_data
;
849 drawing
->vbox
= gtk_vbox_new(FALSE
, 1);
852 drawing
->ruler_hbox
= gtk_hbox_new(FALSE
, 1);
853 drawing
->ruler
= gtk_drawing_area_new ();
854 //gtk_widget_set_size_request(drawing->ruler, -1, 27);
856 drawing
->padding
= gtk_drawing_area_new ();
857 //gtk_widget_set_size_request(drawing->padding, -1, 27);
858 gtk_box_pack_start(GTK_BOX(drawing
->ruler_hbox
), drawing
->ruler
,
860 gtk_box_pack_end(GTK_BOX(drawing
->ruler_hbox
), drawing
->padding
,
865 drawing
->drawing_area
= gtk_drawing_area_new ();
869 drawing
->hbox
= gtk_hbox_new(FALSE
, 1);
870 drawing
->viewport
= gtk_viewport_new(NULL
, control_flow_data
->v_adjust
);
871 drawing
->scrollbar
= gtk_vscrollbar_new(control_flow_data
->v_adjust
);
872 gtk_box_pack_start(GTK_BOX(drawing
->hbox
), drawing
->viewport
,
874 gtk_box_pack_end(GTK_BOX(drawing
->hbox
), drawing
->scrollbar
,
877 //drawing->scrolled_window =
878 // gtk_scrolled_window_new (NULL,
879 // control_flow_data->v_adjust);
881 //gtk_scrolled_window_set_policy(
882 // GTK_SCROLLED_WINDOW(drawing->scrolled_window),
884 // GTK_POLICY_AUTOMATIC);
886 gtk_container_add(GTK_CONTAINER(drawing
->viewport
),
887 drawing
->drawing_area
);
888 //gtk_scrolled_window_add_with_viewport(
889 // GTK_SCROLLED_WINDOW(drawing->scrolled_window),
890 // drawing->drawing_area);
892 gtk_box_pack_start(GTK_BOX(drawing
->vbox
), drawing
->ruler_hbox
,
894 gtk_box_pack_end(GTK_BOX(drawing
->vbox
), drawing
->hbox
,
897 drawing
->pango_layout
=
898 gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
903 drawing
->alloc_height
= 1;
904 drawing
->alloc_width
= 1;
906 drawing
->damage_begin
= 0;
907 drawing
->damage_end
= 0;
908 drawing
->horizontal_sel
= -1;
910 //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50);
911 g_object_set_data_full(
912 G_OBJECT(drawing
->drawing_area
),
915 (GDestroyNotify
)drawing_destroy
);
918 G_OBJECT(drawing
->ruler
),
923 //gtk_widget_modify_bg( drawing->drawing_area,
925 // &CF_Colors[BLACK]);
927 //gdk_window_get_geometry(drawing->drawing_area->window,
929 // &(drawing->width),
930 // &(drawing->height),
933 //drawing->pixmap = gdk_pixmap_new(
934 // drawing->drawing_area->window,
939 //drawing->pixmap = NULL;
941 // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
942 // drawing->drawing_area->allocation.width,
943 // drawing->drawing_area->allocation.height,
946 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
948 G_CALLBACK (configure_event
),
951 g_signal_connect (G_OBJECT(drawing
->ruler
),
953 G_CALLBACK(expose_ruler
),
956 gtk_widget_add_events(drawing
->ruler
, GDK_POINTER_MOTION_MASK
);
958 g_signal_connect (G_OBJECT(drawing
->ruler
),
959 "motion-notify-event",
960 G_CALLBACK(motion_notify_ruler
),
964 g_signal_connect (G_OBJECT(drawing
->scrollbar
),
966 G_CALLBACK(scrollbar_size_allocate
),
971 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
973 G_CALLBACK (expose_event
),
976 g_signal_connect_after (G_OBJECT(drawing
->drawing_area
),
978 G_CALLBACK (after_expose_event
),
981 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
982 "button-press-event",
983 G_CALLBACK (button_press_event
),
987 gtk_widget_show(drawing
->ruler
);
988 gtk_widget_show(drawing
->padding
);
989 gtk_widget_show(drawing
->ruler_hbox
);
991 gtk_widget_show(drawing
->drawing_area
);
992 //gtk_widget_show(drawing->scrolled_window);
993 gtk_widget_show(drawing
->viewport
);
994 gtk_widget_show(drawing
->scrollbar
);
995 gtk_widget_show(drawing
->hbox
);
997 /* Allocate the colors */
998 GdkColormap
* colormap
= gdk_colormap_get_system();
999 gboolean success
[NUM_COLORS
];
1000 gdk_colormap_alloc_colors(colormap
, drawing_colors
, NUM_COLORS
, FALSE
,
1002 gdk_colormap_alloc_colors(colormap
, drawing_colors_cpu
, NUM_COLORS_CPU
, FALSE
,
1004 gdk_colormap_alloc_colors(colormap
, drawing_colors_irq
, NUM_COLORS_IRQ
, FALSE
,
1006 gdk_colormap_alloc_colors(colormap
, drawing_colors_bdev
, NUM_COLORS_BDEV
, FALSE
,
1010 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(control_flow_data
->tab
)->window
));
1011 drawing
->dotted_gc
=
1012 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(control_flow_data
->tab
)->window
));
1014 gdk_gc_copy(drawing
->gc
,
1015 main_window_get_widget(control_flow_data
->tab
)->style
->black_gc
);
1016 gdk_gc_copy(drawing
->dotted_gc
,
1017 main_window_get_widget(control_flow_data
->tab
)->style
->white_gc
);
1019 gint8 dash_list
[] = { 1, 2 };
1020 gdk_gc_set_line_attributes(drawing
->dotted_gc
,
1022 GDK_LINE_ON_OFF_DASH
,
1025 gdk_gc_set_dashes(drawing
->dotted_gc
,
1030 drawing
->ruler_gc_butt
=
1031 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(control_flow_data
->tab
)->window
));
1032 gdk_gc_copy(drawing
->ruler_gc_butt
,
1033 main_window_get_widget(control_flow_data
->tab
)->style
->black_gc
);
1034 drawing
->ruler_gc_round
=
1035 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(control_flow_data
->tab
)->window
));
1036 gdk_gc_copy(drawing
->ruler_gc_round
,
1037 main_window_get_widget(control_flow_data
->tab
)->style
->black_gc
);
1040 gdk_gc_set_line_attributes(drawing
->ruler_gc_butt
,
1046 gdk_gc_set_line_attributes(drawing
->ruler_gc_round
,
1056 void drawing_destroy(Drawing_t
*drawing
)
1058 g_info("drawing_destroy %p", drawing
);
1060 /* Free the colors */
1061 GdkColormap
* colormap
= gdk_colormap_get_system();
1063 gdk_colormap_free_colors(colormap
, drawing_colors
, NUM_COLORS
);
1064 gdk_colormap_free_colors(colormap
, drawing_colors_cpu
, NUM_COLORS_CPU
);
1065 gdk_colormap_free_colors(colormap
, drawing_colors_irq
, NUM_COLORS_IRQ
);
1066 gdk_colormap_free_colors(colormap
, drawing_colors_bdev
, NUM_COLORS_BDEV
);
1068 // Do not unref here, Drawing_t destroyed by it's widget.
1069 //g_object_unref( G_OBJECT(drawing->drawing_area));
1070 if(drawing
->gc
!= NULL
)
1071 gdk_gc_unref(drawing
->gc
);
1073 g_object_unref(drawing
->pango_layout
);
1074 if(drawing
->dotted_gc
!= NULL
) gdk_gc_unref(drawing
->dotted_gc
);
1075 if(drawing
->ruler_gc_butt
!= NULL
) gdk_gc_unref(drawing
->ruler_gc_butt
);
1076 if(drawing
->ruler_gc_round
!= NULL
) gdk_gc_unref(drawing
->ruler_gc_round
);
1079 g_info("drawing_destroy end");
1082 GtkWidget
*drawing_get_drawing_area(Drawing_t
*drawing
)
1084 return drawing
->drawing_area
;
1087 GtkWidget
*drawing_get_widget(Drawing_t
*drawing
)
1089 return drawing
->vbox
;
1092 void drawing_draw_line( Drawing_t
*drawing
,
1098 gdk_draw_line (pixmap
,
1103 void drawing_clear(Drawing_t
*drawing
)
1105 //if (drawing->pixmap)
1106 // gdk_pixmap_unref(drawing->pixmap);
1107 ControlFlowData
*cfd
= drawing
->control_flow_data
;
1110 rectangle_pixmap(cfd
->process_list
,
1111 drawing
->drawing_area
->style
->black_gc
,
1114 drawing
->alloc_width
, // do not overlap
1117 //drawing->height = 1;
1118 /* Allocate a new pixmap with new height */
1119 //drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
1120 // drawing->width + SAFETY + EXTRA_ALLOC,
1121 // drawing->height + EXTRA_ALLOC,
1123 //drawing->alloc_width = drawing->width + SAFETY + EXTRA_ALLOC;
1124 //drawing->alloc_height = drawing->height + EXTRA_ALLOC;
1126 //gtk_widget_set_size_request(drawing->drawing_area,
1128 // drawing->height);
1129 //gtk_widget_queue_resize_no_redraw(drawing->drawing_area);
1131 /* ask for the buffer to be redrawn */
1132 gtk_widget_queue_draw ( drawing
->drawing_area
);
1136 /* Insert a square corresponding to a new process in the list */
1137 /* Applies to whole drawing->width */
1138 void drawing_insert_square(Drawing_t
*drawing
,
1142 //GdkRectangle update_rect;
1143 gboolean reallocate
= FALSE
;
1144 GdkPixmap
*new_pixmap
;
1146 /* Allocate a new pixmap with new height */
1147 if(drawing
->alloc_height
< drawing
->height
+ height
) {
1149 new_pixmap
= gdk_pixmap_new(drawing
->drawing_area
->window
,
1150 drawing
->width
+ SAFETY
+ EXTRA_ALLOC
,
1151 drawing
->height
+ height
+ EXTRA_ALLOC
,
1153 drawing
->alloc_width
= drawing
->width
+ SAFETY
+ EXTRA_ALLOC
;
1154 drawing
->alloc_height
= drawing
->height
+ height
+ EXTRA_ALLOC
;
1157 /* Copy the high region */
1158 gdk_draw_pixmap (new_pixmap
,
1159 drawing
->drawing_area
->style
->black_gc
,
1163 drawing
->width
+ SAFETY
, y
);
1166 new_pixmap
= drawing
->pixmap
;
1169 //GdkPixmap *pixmap = gdk_pixmap_new(drawing->drawing_area->window,
1170 // drawing->width + SAFETY,
1171 // drawing->height + height,
1174 /* add an empty square */
1175 gdk_draw_rectangle (new_pixmap
,
1176 drawing
->drawing_area
->style
->black_gc
,
1179 drawing
->width
+ SAFETY
, // do not overlap
1182 /* copy the bottom of the region */
1183 gdk_draw_pixmap (new_pixmap
,
1184 drawing
->drawing_area
->style
->black_gc
,
1188 drawing
->width
+SAFETY
, drawing
->height
- y
);
1191 if(reallocate
&& likely(drawing
->pixmap
)) {
1192 gdk_pixmap_unref(drawing
->pixmap
);
1193 drawing
->pixmap
= new_pixmap
;
1196 if(unlikely(drawing
->height
==1)) drawing
->height
= height
;
1197 else drawing
->height
+= height
;
1199 gtk_widget_set_size_request(drawing
->drawing_area
,
1202 gtk_widget_queue_resize_no_redraw(drawing
->drawing_area
);
1204 /* ask for the buffer to be redrawn */
1205 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
1207 drawing
->width
, drawing
->height
-y
);
1211 /* Remove a square corresponding to a removed process in the list */
1212 void drawing_remove_square(Drawing_t
*drawing
,
1218 if(unlikely((guint
)drawing
->height
== height
)) {
1219 //pixmap = gdk_pixmap_new(
1220 // drawing->drawing_area->window,
1221 // drawing->width + SAFETY,
1224 pixmap
= drawing
->pixmap
;
1227 /* Allocate a new pixmap with new height */
1228 //pixmap = gdk_pixmap_new(
1229 // drawing->drawing_area->window,
1230 // drawing->width + SAFETY,
1231 // drawing->height - height,
1233 /* Keep the same preallocated pixmap */
1234 pixmap
= drawing
->pixmap
;
1236 /* Copy the high region */
1237 gdk_draw_pixmap (pixmap
,
1238 drawing
->drawing_area
->style
->black_gc
,
1242 drawing
->width
+ SAFETY
, y
);
1244 /* Copy up the bottom of the region */
1245 gdk_draw_pixmap (pixmap
,
1246 drawing
->drawing_area
->style
->black_gc
,
1250 drawing
->width
, drawing
->height
- y
- height
);
1252 drawing
->height
-=height
;
1255 //if(likely(drawing->pixmap))
1256 // gdk_pixmap_unref(drawing->pixmap);
1258 //drawing->pixmap = pixmap;
1260 gtk_widget_set_size_request(drawing
->drawing_area
,
1263 gtk_widget_queue_resize_no_redraw(drawing
->drawing_area
);
1264 /* ask for the buffer to be redrawn */
1265 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
1267 drawing
->width
, MAX(drawing
->height
-y
, 1));
1271 void drawing_update_ruler(Drawing_t
*drawing
, TimeWindow
*time_window
)
1276 req
.width
= drawing
->ruler
->allocation
.width
;
1277 req
.height
= drawing
->ruler
->allocation
.height
;
1282 rect
.width
= req
.width
;
1283 rect
.height
= req
.height
;
1285 gtk_widget_queue_draw(drawing
->ruler
);
1286 //gtk_widget_draw( drawing->ruler, &rect);
1289 /* Redraw the ruler */
1291 expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
1293 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
1294 TimeWindow time_window
= lttvwindow_get_time_window(drawing
->control_flow_data
->tab
);
1297 PangoContext
*context
;
1298 PangoLayout
*layout
;
1299 PangoFontDescription
*FontDesc
;
1300 PangoRectangle ink_rect
;
1301 gint global_width
=0;
1302 GdkColor foreground
= { 0, 0, 0, 0 };
1303 GdkColor background
= { 0, 0xffff, 0xffff, 0xffff };
1305 LttTime window_end
= time_window
.end_time
;
1306 LttTime half_width
=
1307 ltt_time_div(time_window
.time_width
,2.0);
1308 LttTime window_middle
=
1309 ltt_time_add(half_width
,
1310 time_window
.start_time
);
1311 g_debug("ruler expose event");
1313 gdk_draw_rectangle (drawing
->ruler
->window
,
1314 drawing
->ruler
->style
->white_gc
,
1316 event
->area
.x
, event
->area
.y
,
1318 event
->area
.height
);
1320 gdk_draw_line (drawing
->ruler
->window
,
1321 drawing
->ruler_gc_butt
,
1323 event
->area
.x
+ event
->area
.width
, 1);
1326 snprintf(text
, 255, "%lus\n%luns",
1327 time_window
.start_time
.tv_sec
,
1328 time_window
.start_time
.tv_nsec
);
1330 layout
= gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
1332 context
= pango_layout_get_context(layout
);
1333 FontDesc
= pango_context_get_font_description(context
);
1335 pango_font_description_set_size(FontDesc
, 6*PANGO_SCALE
);
1336 pango_layout_context_changed(layout
);
1338 pango_layout_set_text(layout
, text
, -1);
1339 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1340 global_width
+= ink_rect
.width
;
1342 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
1343 drawing
->ruler_gc_butt
,
1346 layout
, &foreground
, &background
);
1348 gdk_draw_line (drawing
->ruler
->window
,
1349 drawing
->ruler_gc_round
,
1354 snprintf(text
, 255, "%lus\n%luns", window_end
.tv_sec
,
1355 window_end
.tv_nsec
);
1357 pango_layout_set_text(layout
, text
, -1);
1358 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1359 global_width
+= ink_rect
.width
;
1361 if(global_width
<= drawing
->ruler
->allocation
.width
)
1363 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
1364 drawing
->ruler_gc_butt
,
1365 drawing
->ruler
->allocation
.width
- ink_rect
.width
,
1367 layout
, &foreground
, &background
);
1369 gdk_draw_line (drawing
->ruler
->window
,
1370 drawing
->ruler_gc_butt
,
1371 drawing
->ruler
->allocation
.width
-1, 1,
1372 drawing
->ruler
->allocation
.width
-1, 7);
1376 snprintf(text
, 255, "%lus\n%luns", window_middle
.tv_sec
,
1377 window_middle
.tv_nsec
);
1379 pango_layout_set_text(layout
, text
, -1);
1380 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1381 global_width
+= ink_rect
.width
;
1383 if(global_width
<= drawing
->ruler
->allocation
.width
)
1385 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
1386 drawing
->ruler_gc_butt
,
1387 (drawing
->ruler
->allocation
.width
- ink_rect
.width
)/2,
1389 layout
, &foreground
, &background
);
1391 gdk_draw_line (drawing
->ruler
->window
,
1392 drawing
->ruler_gc_butt
,
1393 drawing
->ruler
->allocation
.width
/2, 1,
1394 drawing
->ruler
->allocation
.width
/2, 7);
1401 g_object_unref(layout
);
1407 /* notify mouse on ruler */
1409 motion_notify_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1411 //g_debug("motion");
1412 //eventually follow mouse and show time here