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 <lttv/lttv.h>
28 #include <lttvwindow/lttvwindow.h>
29 #include <lttv/state.h>
30 #include <lttv/hook.h>
33 #include "eventhooks.h"
36 //#define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
39 // fixed #define TRACE_NUMBER 0
40 #define EXTRA_ALLOC 1024 // pixels
43 #if 0 /* colors for two lines representation */
44 GdkColor drawing_colors
[NUM_COLORS
] =
45 { /* Pixel, R, G, B */
46 { 0, 0, 0, 0 }, /* COL_BLACK */
47 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
48 { 0, 0x0FFF, 0xFFFF, 0xFFFF }, /* COL_WAIT_FORK : pale blue */
49 { 0, 0xFFFF, 0xFFFF, 0x0000 }, /* COL_WAIT_CPU : yellow */
50 { 0, 0xFFFF, 0xA000, 0xFCFF }, /* COL_EXIT : pale magenta */
51 { 0, 0xFFFF, 0x0000, 0xFFFF }, /* COL_ZOMBIE : purple */
52 { 0, 0xFFFF, 0x0000, 0x0000 }, /* COL_WAIT : red */
53 { 0, 0x0000, 0xFFFF, 0x0000 }, /* COL_RUN : green */
54 { 0, 0x8800, 0xFFFF, 0x8A00 }, /* COL_USER_MODE : pale green */
55 { 0, 0x09FF, 0x01FF, 0xFFFF }, /* COL_SYSCALL : blue */
56 { 0, 0xF900, 0x4200, 0xFF00 }, /* COL_TRAP : pale purple */
57 { 0, 0xFFFF, 0x5AFF, 0x01FF }, /* COL_IRQ : orange */
58 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_MODE_UNKNOWN : white */
64 GdkColor drawing_colors
[NUM_COLORS
] =
65 { /* Pixel, R, G, B */
66 { 0, 0, 0, 0 }, /* COL_BLACK */
67 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
68 { 0, 0x0000, 0xFF00, 0x0000 }, /* COL_RUN_USER_MODE : green */
69 { 0, 0x0100, 0x9E00, 0xFFFF }, /* COL_RUN_SYSCALL : pale blue */
70 { 0, 0xFF00, 0xFF00, 0x0100 }, /* COL_RUN_TRAP : yellow */
71 { 0, 0xFFFF, 0x5E00, 0x0000 }, /* COL_RUN_IRQ : orange */
72 { 0, 0xFFFF, 0x9400, 0x9600 }, /* COL_RUN_SOFT_IRQ : pink */
73 { 0, 0x6600, 0x0000, 0x0000 }, /* COL_WAIT : dark red */
74 { 0, 0x7700, 0x7700, 0x0000 }, /* COL_WAIT_CPU : dark yellow */
75 { 0, 0x6400, 0x0000, 0x5D00 }, /* COL_ZOMBIE : dark purple */
76 { 0, 0x0700, 0x6400, 0x0000 }, /* COL_WAIT_FORK : dark green */
77 { 0, 0x8900, 0x0000, 0x8400 }, /* COL_EXIT : "less dark" magenta */
78 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_MODE_UNKNOWN : white */
79 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_UNNAMED : white */
83 GdkColor drawing_colors_cpu
[NUM_COLORS_CPU
] =
84 { /* Pixel, R, G, B */
85 { 0, 0x0000, 0x0000, 0x0000 }, /* COL_CPU_UNKNOWN */
86 { 0, 0xBBBB, 0xBBBB, 0xBBBB }, /* COL_CPU_IDLE */
87 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_CPU_BUSY */
88 { 0, 0xFFFF, 0x5E00, 0x0000 }, /* COL_CPU_IRQ */
89 { 0, 0xFFFF, 0x9400, 0x9600 }, /* COL_CPU_SOFT_IRQ */
90 { 0, 0xFF00, 0xFF00, 0x0100 }, /* COL_CPU_TRAP */
93 GdkColor drawing_colors_irq
[NUM_COLORS_IRQ
] =
94 { /* Pixel, R, G, B */
95 { 0, 0x0000, 0x0000, 0x0000 }, /* COL_IRQ_UNKNOWN */
96 { 0, 0xBBBB, 0xBBBB, 0xBBBB }, /* COL_IRQ_IDLE */
97 { 0, 0xFFFF, 0x5E00, 0x0000 }, /* COL_IRQ_BUSY */
100 GdkColor drawing_colors_soft_irq
[NUM_COLORS_SOFT_IRQ
] =
101 { /* Pixel, R, G, B */
102 { 0, 0x0000, 0x0000, 0x0000 }, /* COL_SOFT_IRQ_UNKNOWN */
103 { 0, 0x0000, 0x0000, 0x0000 }, /* COL_SOFT_IRQ_IDLE */
104 { 0, 0xFFFF, 0xD400, 0xD400 }, /* COL_SOFT_IRQ_PENDING */
105 { 0, 0xFFFF, 0x9400, 0x9600 }, /* COL_SOFT_IRQ_BUSY */
108 GdkColor drawing_colors_trap
[NUM_COLORS_TRAP
] =
109 { /* Pixel, R, G, B */
110 { 0, 0x0000, 0x0000, 0x0000 }, /* COL_TRAP_UNKNOWN */
111 { 0, 0x0000, 0x0000, 0x0000 }, /* COL_TRAP_IDLE */
112 { 0, 0xFF00, 0xFF00, 0x0100 }, /* COL_TRAP_BUSY */
115 GdkColor drawing_colors_bdev
[NUM_COLORS_BDEV
] =
116 { /* Pixel, R, G, B */
117 { 0, 0x0000, 0x0000, 0x0000 }, /* COL_BDEV_UNKNOWN */
118 { 0, 0xBBBB, 0xBBBB, 0xBBBB }, /* COL_BDEV_IDLE */
119 { 0, 0x0000, 0x0000, 0xFFFF }, /* COL_BDEV_BUSY_READING */
120 { 0, 0xFFFF, 0x0000, 0x0000 }, /* COL_BDEV_BUSY_WRITING */
123 /*****************************************************************************
124 * drawing functions *
125 *****************************************************************************/
128 expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
);
131 motion_notify_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
);
134 /* Function responsible for updating the exposed area.
135 * It must do an events request to the lttvwindow API to ask for this update.
136 * Note : this function cannot clear the background, because it may
137 * erase drawing already present (SAFETY).
139 void drawing_data_request(Drawing_t
*drawing
,
144 if(width
< 0) return ;
145 if(height
< 0) return ;
148 Tab
*tab
= drawing
->control_flow_data
->tab
;
149 TimeWindow time_window
=
150 lttvwindow_get_time_window(tab
);
151 LttvTraceset
*traceset
= lttvwindow_get_traceset(tab
);
153 ControlFlowData
*control_flow_data
= drawing
->control_flow_data
;
154 // (ControlFlowData*)g_object_get_data(
155 // G_OBJECT(drawing->drawing_area), "resourceview_data");
157 LttTime start
, time_end
;
158 LttTime window_end
= time_window
.end_time
;
160 g_debug("req : window start_time : %lu, %lu", time_window
.start_time
.tv_sec
,
161 time_window
.start_time
.tv_nsec
);
163 g_debug("req : window time width : %lu, %lu", time_window
.time_width
.tv_sec
,
164 time_window
.time_width
.tv_nsec
);
166 g_debug("req : window_end : %lu, %lu", window_end
.tv_sec
,
169 g_debug("x is : %i, x+width is : %i", x
, x
+width
);
171 convert_pixels_to_time(drawing
->width
, x
,
175 convert_pixels_to_time(drawing
->width
, x
+width
,
178 time_end
= ltt_time_add(time_end
, ltt_time_one
); // because main window
179 // doesn't deliver end time.
181 lttvwindow_events_request_remove_all(tab
,
185 LttvHooks
*event_hook
= lttv_hooks_new();
187 lttv_hooks_add(event_hook
,before_schedchange_hook
, control_flow_data
, LTTV_PRIO_STATE
-5);
188 lttv_hooks_add(event_hook
,before_execmode_hook
, control_flow_data
, LTTV_PRIO_STATE
-5);
189 lttv_hooks_add(event_hook
, after_schedchange_hook
, control_flow_data
, LTTV_PRIO_STATE
+5);
191 /* find the tracehooks */
199 guint nb_trace
= lttv_traceset_number(traceset
);
200 // FIXME (fixed) : eventually request for more traces
201 for(i
= 0 ; i
< nb_trace
; i
++) {
202 EventsRequest
*events_request
= g_new(EventsRequest
, 1);
204 //LttvHooks *event = lttv_hooks_new();
206 LttvHooks
*before_chunk_traceset
= lttv_hooks_new();
207 LttvHooks
*after_chunk_traceset
= lttv_hooks_new();
208 LttvHooks
*before_request_hook
= lttv_hooks_new();
209 LttvHooks
*after_request_hook
= lttv_hooks_new();
211 lttv_hooks_add(before_chunk_traceset
,
216 lttv_hooks_add(after_chunk_traceset
,
221 lttv_hooks_add(before_request_hook
,
226 lttv_hooks_add(after_request_hook
,
232 ts
= (LttvTraceState
*)tsc
->traces
[i
];
234 /* Find the eventtype id for the following events and register the
235 associated by id hooks. */
237 hooks
= g_array_sized_new(FALSE
, FALSE
, sizeof(LttvTraceHook
), 18);
241 // lttv_trace_find_hook(ts->parent.t,
242 // LTT_FACILITY_ARCH,
243 // LTT_EVENT_SYSCALL_ENTRY,
244 // FIELD_ARRAY(LTT_FIELD_SYSCALL_ID),
245 // before_execmode_hook,
249 // lttv_trace_find_hook(ts->parent.t,
250 // LTT_FACILITY_ARCH,
251 // LTT_EVENT_SYSCALL_EXIT,
253 // before_execmode_hook,
257 lttv_trace_find_hook(ts
->parent
.t
,
259 LTT_EVENT_TRAP_ENTRY
,
260 FIELD_ARRAY(LTT_FIELD_TRAP_ID
),
261 before_execmode_hook
,
265 lttv_trace_find_hook(ts
->parent
.t
,
269 before_execmode_hook
,
273 lttv_trace_find_hook(ts
->parent
.t
,
275 LTT_EVENT_PAGE_FAULT_ENTRY
,
276 FIELD_ARRAY(LTT_FIELD_TRAP_ID
),
277 before_execmode_hook
,
281 lttv_trace_find_hook(ts
->parent
.t
,
283 LTT_EVENT_PAGE_FAULT_EXIT
,
285 before_execmode_hook
,
289 lttv_trace_find_hook(ts
->parent
.t
,
291 LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY
,
292 FIELD_ARRAY(LTT_FIELD_TRAP_ID
),
293 before_execmode_hook
,
297 lttv_trace_find_hook(ts
->parent
.t
,
299 LTT_EVENT_PAGE_FAULT_NOSEM_EXIT
,
301 before_execmode_hook
,
305 lttv_trace_find_hook(ts
->parent
.t
,
308 FIELD_ARRAY(LTT_FIELD_IRQ_ID
),
309 before_execmode_hook
,
313 lttv_trace_find_hook(ts
->parent
.t
,
317 before_execmode_hook
,
321 lttv_trace_find_hook(ts
->parent
.t
,
323 LTT_EVENT_SOFT_IRQ_RAISE
,
324 FIELD_ARRAY(LTT_FIELD_SOFT_IRQ_ID
),
325 before_execmode_hook
,
329 lttv_trace_find_hook(ts
->parent
.t
,
331 LTT_EVENT_SOFT_IRQ_ENTRY
,
332 FIELD_ARRAY(LTT_FIELD_SOFT_IRQ_ID
),
333 before_execmode_hook
,
337 lttv_trace_find_hook(ts
->parent
.t
,
339 LTT_EVENT_SOFT_IRQ_EXIT
,
341 before_execmode_hook
,
346 lttv_trace_find_hook(ts
->parent
.t
,
348 LTT_EVENT_SCHED_SCHEDULE
,
349 FIELD_ARRAY(LTT_FIELD_PREV_PID
, LTT_FIELD_NEXT_PID
, LTT_FIELD_PREV_STATE
),
350 before_schedchange_hook
,
354 // lttv_trace_find_hook(ts->parent.t,
355 // LTT_CHANNEL_KERNEL,
356 // LTT_EVENT_PROCESS_EXIT,
357 // FIELD_ARRAY(LTT_FIELD_PID),
358 // before_process_exit_hook,
362 // lttv_trace_find_hook(ts->parent.t,
363 // LTT_CHANNEL_KERNEL,
364 // LTT_EVENT_PROCESS_FREE,
365 // FIELD_ARRAY(LTT_FIELD_PID),
366 // before_process_release_hook,
370 // lttv_trace_find_hook(ts->parent.t,
371 // LTT_FACILITY_LIST,
372 // LTT_EVENT_STATEDUMP_END,
374 // before_statedump_end,
378 lttv_trace_find_hook(ts
->parent
.t
,
380 LTT_EVENT_REQUEST_ISSUE
,
381 FIELD_ARRAY(LTT_FIELD_MAJOR
, LTT_FIELD_MINOR
, LTT_FIELD_OPERATION
),
382 before_bdev_event_hook
,
386 lttv_trace_find_hook(ts
->parent
.t
,
388 LTT_EVENT_REQUEST_COMPLETE
,
389 FIELD_ARRAY(LTT_FIELD_MAJOR
, LTT_FIELD_MINOR
, LTT_FIELD_OPERATION
),
390 before_bdev_event_hook
,
395 first_after
= hooks
->len
;
397 lttv_trace_find_hook(ts
->parent
.t
,
399 LTT_EVENT_SCHED_SCHEDULE
,
400 FIELD_ARRAY(LTT_FIELD_PREV_PID
, LTT_FIELD_NEXT_PID
, LTT_FIELD_PREV_STATE
),
401 after_schedchange_hook
,
405 // lttv_trace_find_hook(ts->parent.t,
406 // LTT_CHANNEL_KERNEL,
407 // LTT_EVENT_PROCESS_FORK,
408 // FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID),
409 // after_process_fork_hook,
413 // lttv_trace_find_hook(ts->parent.t,
414 // LTT_CHANNEL_KERNEL,
415 // LTT_EVENT_PROCESS_EXIT,
416 // FIELD_ARRAY(LTT_FIELD_PID),
417 // after_process_exit_hook,
421 // lttv_trace_find_hook(ts->parent.t,
422 // LTT_CHANNEL_KERNEL,
425 // after_fs_exec_hook,
429 // lttv_trace_find_hook(ts->parent.t,
430 // LTT_FACILITY_USER_GENERIC,
431 // LTT_EVENT_THREAD_BRAND,
432 // FIELD_ARRAY(LTT_FIELD_NAME),
433 // after_user_generic_thread_brand_hook,
437 // lttv_trace_find_hook(ts->parent.t,
438 // LTT_FACILITY_LIST,
439 // LTT_EVENT_PROCESS_STATE,
440 // FIELD_ARRAY(LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME),
441 // after_event_enum_process_hook,
446 /* Add these hooks to each event_by_id hooks list */
448 for(k
= 0 ; k
< first_after
; k
++) {
449 th
= &g_array_index(hooks
, LttvTraceHook
, k
);
450 lttv_hooks_add(lttv_hooks_by_id_channel_find(event_by_id_channel
,
451 th
->channel
, th
->id
),
458 for(k
= first_after
; k
< hooks
->len
; k
++) {
459 th
= &g_array_index(hooks
, LttvTraceHook
, k
);
460 lttv_hooks_add(lttv_hooks_by_id_channel_find(event_by_id_channel
,
461 th
->channel
, th
->id
),
467 events_request
->hooks
= hooks
;
469 // Fill the events request
470 events_request
->owner
= control_flow_data
;
471 events_request
->viewer_data
= control_flow_data
;
472 events_request
->servicing
= FALSE
;
473 events_request
->start_time
= start
;
474 events_request
->start_position
= NULL
;
475 events_request
->stop_flag
= FALSE
;
476 events_request
->end_time
= time_end
;
477 events_request
->num_events
= G_MAXUINT
;
478 events_request
->end_position
= NULL
;
479 events_request
->trace
= i
; //fixed /* FIXME */
480 events_request
->before_chunk_traceset
= before_chunk_traceset
;
481 events_request
->before_chunk_trace
= NULL
;
482 events_request
->before_chunk_tracefile
= NULL
;
483 events_request
->event
= event_hook
;
484 events_request
->after_chunk_tracefile
= NULL
;
485 events_request
->after_chunk_trace
= NULL
;
486 events_request
->after_chunk_traceset
= after_chunk_traceset
;
487 events_request
->before_request
= before_request_hook
;
488 events_request
->after_request
= after_request_hook
;
490 g_debug("req : start : %lu, %lu", start
.tv_sec
,
493 g_debug("req : end : %lu, %lu", time_end
.tv_sec
,
496 lttvwindow_events_request(tab
, events_request
);
503 static void set_last_start(gpointer key
, gpointer value
, gpointer user_data
)
505 //ResourceInfo *process_info = (ResourceInfo*)key;
506 HashedResourceData
*hashed_process_data
= (HashedResourceData
*)value
;
507 guint x
= GPOINTER_TO_UINT(user_data
);
509 hashed_process_data
->x
.over
= x
;
510 hashed_process_data
->x
.over_used
= FALSE
;
511 hashed_process_data
->x
.over_marked
= FALSE
;
512 hashed_process_data
->x
.middle
= x
;
513 hashed_process_data
->x
.middle_used
= FALSE
;
514 hashed_process_data
->x
.middle_marked
= FALSE
;
515 hashed_process_data
->x
.under
= x
;
516 hashed_process_data
->x
.under_used
= FALSE
;
517 hashed_process_data
->x
.under_marked
= FALSE
;
518 hashed_process_data
->next_good_time
= ltt_time_zero
;
523 void drawing_data_request_begin(EventsRequest
*events_request
)
527 g_debug("Begin of data request");
528 ControlFlowData
*cfd
= events_request
->viewer_data
;
529 TimeWindow time_window
=
530 lttvwindow_get_time_window(cfd
->tab
);
532 guint width
= cfd
->drawing
->width
;
535 cfd
->drawing
->last_start
= events_request
->start_time
;
537 convert_time_to_pixels(
539 events_request
->start_time
,
543 for(i
=0; i
<RV_RESOURCE_COUNT
; i
++) {
544 g_hash_table_foreach(cfd
->process_list
->restypes
[i
].hash_table
, set_last_start
,
545 GUINT_TO_POINTER(x
));
550 void drawing_chunk_begin(EventsRequest
*events_request
, LttvTraceset
*ts
)
552 g_debug("Begin of chunk");
553 ControlFlowData
*cfd
= events_request
->viewer_data
;
555 guint nb_trace
= lttv_traceset_number(ts
);
557 if(!cfd
->process_list
->current_hash_data
) {
558 cfd
->process_list
->current_hash_data
= g_new(HashedResourceData
**,nb_trace
);
559 for(i
= 0 ; i
< nb_trace
; i
++) {
560 guint num_cpu
= lttv_trace_get_num_cpu(lttv_traceset_get(ts
, i
));
561 cfd
->process_list
->current_hash_data
[i
] = g_new(HashedResourceData
*,num_cpu
);
562 memset(cfd
->process_list
->current_hash_data
[i
], 0,
563 sizeof(HashedResourceData
*)*num_cpu
);
566 //cfd->drawing->last_start = LTT_TIME_MIN(current_time,
567 // events_request->end_time);
571 void drawing_request_expose(EventsRequest
*events_request
,
577 ControlFlowData
*cfd
= events_request
->viewer_data
;
578 Drawing_t
*drawing
= cfd
->drawing
;
580 TimeWindow time_window
=
581 lttvwindow_get_time_window(cfd
->tab
);
583 g_debug("request expose");
585 convert_time_to_pixels(
590 x
= drawing
->damage_begin
;
594 drawing
->damage_begin
= x
+width
;
597 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
599 width
, drawing
->drawing_area
->allocation
.height
);
601 /* Update directly when scrolling */
602 gdk_window_process_updates(drawing
->drawing_area
->window
,
610 /* Create a new backing pixmap of the appropriate size */
611 /* As the scaling will always change, it's of no use to copy old
614 * Only change the size if width changes. The height is specified and changed
615 * when process ID are added or removed from the process list.
618 configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
621 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
624 /* First, get the new time interval of the main window */
625 /* we assume (see documentation) that the main window
626 * has updated the time interval before this configure gets
629 //lttvwindow_get_time_window(drawing->control_flow_data->mw,
630 // &drawing->control_flow_data->time_window);
632 /* New pixmap, size of the configure event */
633 //GdkPixmap *pixmap = gdk_pixmap_new(widget->window,
634 // widget->allocation.width + SAFETY,
635 // widget->allocation.height + SAFETY,
638 if(widget
->allocation
.width
!= drawing
->width
) {
639 g_debug("drawing configure event");
640 g_debug("New alloc draw size : %i by %i",widget
->allocation
.width
,
641 widget
->allocation
.height
);
643 drawing
->width
= widget
->allocation
.width
;
645 if(drawing
->alloc_width
< widget
->allocation
.width
) {
646 //if(drawing->pixmap)
647 // gdk_pixmap_unref(drawing->pixmap);
649 //drawing->pixmap = gdk_pixmap_new(widget->window,
650 // drawing->width + SAFETY + EXTRA_ALLOC,
651 // drawing->height + EXTRA_ALLOC,
653 drawing
->alloc_width
= drawing
->width
+ SAFETY
+ EXTRA_ALLOC
;
654 drawing
->alloc_height
= drawing
->height
+ EXTRA_ALLOC
;
655 update_pixmap_size(drawing
->control_flow_data
->process_list
,
656 drawing
->alloc_width
);
657 update_index_to_pixmap(drawing
->control_flow_data
->process_list
);
659 //drawing->height = widget->allocation.height;
661 //ProcessList_get_height
662 // (GuiControlFlow_get_process_list(drawing->control_flow_data)),
666 //gdk_draw_rectangle (drawing->pixmap,
667 // widget->style->black_gc,
670 // drawing->width+SAFETY,
673 //g_info("init data request");
676 /* Initial data request */
677 /* no, do initial data request in the expose event */
678 // Do not need to ask for data of 1 pixel : not synchronized with
679 // main window time at this moment.
680 //drawing_data_request(drawing, &drawing->pixmap, 0, 0,
681 // widget->allocation.width,
682 // widget->allocation.height);
684 //drawing->width = widget->allocation.width;
685 //drawing->height = widget->allocation.height;
687 drawing
->damage_begin
= 0;
688 drawing
->damage_end
= widget
->allocation
.width
;
690 if((widget
->allocation
.width
!= 1 &&
691 widget
->allocation
.height
!= 1)
692 && drawing
->damage_begin
< drawing
->damage_end
)
695 rectangle_pixmap (drawing
->control_flow_data
->process_list
,
696 drawing
->drawing_area
->style
->black_gc
,
699 drawing
->alloc_width
, // do not overlap
703 drawing_data_request(drawing
,
704 drawing
->damage_begin
,
706 drawing
->damage_end
- drawing
->damage_begin
,
714 /* Redraw the screen from the backing pixmap */
716 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
718 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
720 ControlFlowData
*control_flow_data
=
721 (ControlFlowData
*)g_object_get_data(
723 "resourceview_data");
725 if(unlikely(drawing
->gc
== NULL
)) {
726 drawing
->gc
= gdk_gc_new(drawing
->drawing_area
->window
);
727 gdk_gc_copy(drawing
->gc
, drawing
->drawing_area
->style
->black_gc
);
730 TimeWindow time_window
=
731 lttvwindow_get_time_window(control_flow_data
->tab
);
732 LttTime current_time
=
733 lttvwindow_get_current_time(control_flow_data
->tab
);
737 LttTime window_end
= time_window
.end_time
;
739 /* update the screen from the pixmap buffer */
741 gdk_draw_pixmap(widget
->window
,
742 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
744 event
->area
.x
, event
->area
.y
,
745 event
->area
.x
, event
->area
.y
,
746 event
->area
.width
, event
->area
.height
);
748 drawing
->height
= processlist_get_height(control_flow_data
->process_list
);
750 copy_pixmap_to_screen(control_flow_data
->process_list
,
752 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
753 event
->area
.x
, event
->area
.y
,
754 event
->area
.width
, event
->area
.height
);
756 copy_pixmap_to_screen(control_flow_data
->process_list
,
759 event
->area
.x
, event
->area
.y
,
760 event
->area
.width
, event
->area
.height
);
763 /* Erase the dotted lines left.. */
764 if(widget
->allocation
.height
> drawing
->height
)
766 gdk_draw_rectangle (widget
->window
,
767 drawing
->drawing_area
->style
->black_gc
,
769 event
->area
.x
, drawing
->height
,
770 event
->area
.width
, // do not overlap
771 widget
->allocation
.height
- drawing
->height
);
773 if(ltt_time_compare(time_window
.start_time
, current_time
) <= 0 &&
774 ltt_time_compare(window_end
, current_time
) >= 0)
776 /* Draw the dotted lines */
777 convert_time_to_pixels(
784 if(drawing
->dotted_gc
== NULL
) {
786 drawing
->dotted_gc
= gdk_gc_new(drawing
->drawing_area
->window
);
787 gdk_gc_copy(drawing
->dotted_gc
, widget
->style
->white_gc
);
789 gint8 dash_list
[] = { 1, 2 };
790 gdk_gc_set_line_attributes(drawing
->dotted_gc
,
792 GDK_LINE_ON_OFF_DASH
,
795 gdk_gc_set_dashes(drawing
->dotted_gc
,
801 gint height_tot
= MAX(widget
->allocation
.height
, drawing
->height
);
802 gdk_draw_line(widget
->window
,
805 cursor_x
, height_tot
);
811 after_expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
814 g_debug("AFTER EXPOSE");
823 tree_row_activated(GtkTreeModel
*treemodel
,
825 GtkTreeViewColumn
*arg2
,
828 ControlFlowData
*cfd
= (ControlFlowData
*)user_data
;
829 Drawing_t
*drawing
= cfd
->drawing
;
830 GtkTreeView
*treeview
= cfd
->process_list
->process_list_widget
;
834 path_indices
= gtk_tree_path_get_indices (arg1
);
836 height
= get_cell_height(cfd
->process_list
,
837 GTK_TREE_VIEW(treeview
));
838 drawing
->horizontal_sel
= height
* path_indices
[0];
839 g_critical("new hor sel : %i", drawing
->horizontal_sel
);
845 button_press_event( GtkWidget
*widget
, GdkEventButton
*event
, gpointer user_data
)
847 ControlFlowData
*control_flow_data
=
848 (ControlFlowData
*)g_object_get_data(
850 "resourceview_data");
851 Drawing_t
*drawing
= control_flow_data
->drawing
;
852 TimeWindow time_window
=
853 lttvwindow_get_time_window(control_flow_data
->tab
);
856 if(event
->button
== 1)
860 /* left mouse button click */
861 g_debug("x click is : %f", event
->x
);
863 convert_pixels_to_time(drawing
->width
, (guint
)event
->x
,
867 lttvwindow_report_current_time(control_flow_data
->tab
, time
);
875 scrollbar_size_allocate(GtkWidget
*widget
,
876 GtkAllocation
*allocation
,
879 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
881 gtk_widget_set_size_request(drawing
->padding
, allocation
->width
, -1);
882 //gtk_widget_queue_resize(drawing->padding);
883 //gtk_widget_queue_resize(drawing->ruler);
884 gtk_container_check_resize(GTK_CONTAINER(drawing
->ruler_hbox
));
890 Drawing_t
*drawing_construct(ControlFlowData
*control_flow_data
)
892 Drawing_t
*drawing
= g_new(Drawing_t
, 1);
894 drawing
->control_flow_data
= control_flow_data
;
896 drawing
->vbox
= gtk_vbox_new(FALSE
, 1);
899 drawing
->ruler_hbox
= gtk_hbox_new(FALSE
, 1);
900 drawing
->ruler
= gtk_drawing_area_new ();
901 //gtk_widget_set_size_request(drawing->ruler, -1, 27);
903 drawing
->padding
= gtk_drawing_area_new ();
904 //gtk_widget_set_size_request(drawing->padding, -1, 27);
905 gtk_box_pack_start(GTK_BOX(drawing
->ruler_hbox
), drawing
->ruler
,
907 gtk_box_pack_end(GTK_BOX(drawing
->ruler_hbox
), drawing
->padding
,
912 drawing
->drawing_area
= gtk_drawing_area_new ();
916 drawing
->hbox
= gtk_hbox_new(FALSE
, 1);
917 drawing
->viewport
= gtk_viewport_new(NULL
, control_flow_data
->v_adjust
);
918 drawing
->scrollbar
= gtk_vscrollbar_new(control_flow_data
->v_adjust
);
919 gtk_box_pack_start(GTK_BOX(drawing
->hbox
), drawing
->viewport
,
921 gtk_box_pack_end(GTK_BOX(drawing
->hbox
), drawing
->scrollbar
,
924 //drawing->scrolled_window =
925 // gtk_scrolled_window_new (NULL,
926 // control_flow_data->v_adjust);
928 //gtk_scrolled_window_set_policy(
929 // GTK_SCROLLED_WINDOW(drawing->scrolled_window),
931 // GTK_POLICY_AUTOMATIC);
933 gtk_container_add(GTK_CONTAINER(drawing
->viewport
),
934 drawing
->drawing_area
);
935 //gtk_scrolled_window_add_with_viewport(
936 // GTK_SCROLLED_WINDOW(drawing->scrolled_window),
937 // drawing->drawing_area);
939 gtk_box_pack_start(GTK_BOX(drawing
->vbox
), drawing
->ruler_hbox
,
941 gtk_box_pack_end(GTK_BOX(drawing
->vbox
), drawing
->hbox
,
944 drawing
->pango_layout
=
945 gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
950 drawing
->alloc_height
= 1;
951 drawing
->alloc_width
= 1;
953 drawing
->damage_begin
= 0;
954 drawing
->damage_end
= 0;
955 drawing
->horizontal_sel
= -1;
957 //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50);
958 g_object_set_data_full(
959 G_OBJECT(drawing
->drawing_area
),
962 (GDestroyNotify
)drawing_destroy
);
965 G_OBJECT(drawing
->ruler
),
970 //gtk_widget_modify_bg( drawing->drawing_area,
972 // &CF_Colors[BLACK]);
974 //gdk_window_get_geometry(drawing->drawing_area->window,
976 // &(drawing->width),
977 // &(drawing->height),
980 //drawing->pixmap = gdk_pixmap_new(
981 // drawing->drawing_area->window,
986 //drawing->pixmap = NULL;
988 // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
989 // drawing->drawing_area->allocation.width,
990 // drawing->drawing_area->allocation.height,
993 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
995 G_CALLBACK (configure_event
),
998 g_signal_connect (G_OBJECT(drawing
->ruler
),
1000 G_CALLBACK(expose_ruler
),
1003 gtk_widget_add_events(drawing
->ruler
, GDK_POINTER_MOTION_MASK
);
1005 g_signal_connect (G_OBJECT(drawing
->ruler
),
1006 "motion-notify-event",
1007 G_CALLBACK(motion_notify_ruler
),
1011 g_signal_connect (G_OBJECT(drawing
->scrollbar
),
1013 G_CALLBACK(scrollbar_size_allocate
),
1018 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
1020 G_CALLBACK (expose_event
),
1023 g_signal_connect_after (G_OBJECT(drawing
->drawing_area
),
1025 G_CALLBACK (after_expose_event
),
1028 g_signal_connect (G_OBJECT(drawing
->drawing_area
),
1029 "button-press-event",
1030 G_CALLBACK (button_press_event
),
1034 gtk_widget_show(drawing
->ruler
);
1035 gtk_widget_show(drawing
->padding
);
1036 gtk_widget_show(drawing
->ruler_hbox
);
1038 gtk_widget_show(drawing
->drawing_area
);
1039 //gtk_widget_show(drawing->scrolled_window);
1040 gtk_widget_show(drawing
->viewport
);
1041 gtk_widget_show(drawing
->scrollbar
);
1042 gtk_widget_show(drawing
->hbox
);
1044 /* Allocate the colors */
1045 GdkColormap
* colormap
= gdk_colormap_get_system();
1046 gboolean success
[NUM_COLORS
];
1047 gdk_colormap_alloc_colors(colormap
, drawing_colors
, NUM_COLORS
, FALSE
,
1049 gdk_colormap_alloc_colors(colormap
, drawing_colors_cpu
, NUM_COLORS_CPU
, FALSE
,
1051 gdk_colormap_alloc_colors(colormap
, drawing_colors_irq
, NUM_COLORS_IRQ
, FALSE
,
1053 gdk_colormap_alloc_colors(colormap
, drawing_colors_soft_irq
, NUM_COLORS_SOFT_IRQ
, FALSE
,
1055 gdk_colormap_alloc_colors(colormap
, drawing_colors_trap
, NUM_COLORS_TRAP
, FALSE
,
1057 gdk_colormap_alloc_colors(colormap
, drawing_colors_bdev
, NUM_COLORS_BDEV
, FALSE
,
1061 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(control_flow_data
->tab
)->window
));
1062 drawing
->dotted_gc
=
1063 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(control_flow_data
->tab
)->window
));
1065 gdk_gc_copy(drawing
->gc
,
1066 main_window_get_widget(control_flow_data
->tab
)->style
->black_gc
);
1067 gdk_gc_copy(drawing
->dotted_gc
,
1068 main_window_get_widget(control_flow_data
->tab
)->style
->white_gc
);
1070 gint8 dash_list
[] = { 1, 2 };
1071 gdk_gc_set_line_attributes(drawing
->dotted_gc
,
1073 GDK_LINE_ON_OFF_DASH
,
1076 gdk_gc_set_dashes(drawing
->dotted_gc
,
1081 drawing
->ruler_gc_butt
=
1082 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(control_flow_data
->tab
)->window
));
1083 gdk_gc_copy(drawing
->ruler_gc_butt
,
1084 main_window_get_widget(control_flow_data
->tab
)->style
->black_gc
);
1085 drawing
->ruler_gc_round
=
1086 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(control_flow_data
->tab
)->window
));
1087 gdk_gc_copy(drawing
->ruler_gc_round
,
1088 main_window_get_widget(control_flow_data
->tab
)->style
->black_gc
);
1091 gdk_gc_set_line_attributes(drawing
->ruler_gc_butt
,
1097 gdk_gc_set_line_attributes(drawing
->ruler_gc_round
,
1107 void drawing_destroy(Drawing_t
*drawing
)
1109 g_info("drawing_destroy %p", drawing
);
1111 /* Free the colors */
1112 GdkColormap
* colormap
= gdk_colormap_get_system();
1114 gdk_colormap_free_colors(colormap
, drawing_colors
, NUM_COLORS
);
1115 gdk_colormap_free_colors(colormap
, drawing_colors_cpu
, NUM_COLORS_CPU
);
1116 gdk_colormap_free_colors(colormap
, drawing_colors_irq
, NUM_COLORS_IRQ
);
1117 gdk_colormap_free_colors(colormap
, drawing_colors_soft_irq
, NUM_COLORS_IRQ
);
1118 gdk_colormap_free_colors(colormap
, drawing_colors_trap
, NUM_COLORS_TRAP
);
1119 gdk_colormap_free_colors(colormap
, drawing_colors_bdev
, NUM_COLORS_BDEV
);
1121 // Do not unref here, Drawing_t destroyed by it's widget.
1122 //g_object_unref( G_OBJECT(drawing->drawing_area));
1123 if(drawing
->gc
!= NULL
)
1124 gdk_gc_unref(drawing
->gc
);
1126 g_object_unref(drawing
->pango_layout
);
1127 if(drawing
->dotted_gc
!= NULL
) gdk_gc_unref(drawing
->dotted_gc
);
1128 if(drawing
->ruler_gc_butt
!= NULL
) gdk_gc_unref(drawing
->ruler_gc_butt
);
1129 if(drawing
->ruler_gc_round
!= NULL
) gdk_gc_unref(drawing
->ruler_gc_round
);
1132 g_info("drawing_destroy end");
1135 GtkWidget
*drawing_get_drawing_area(Drawing_t
*drawing
)
1137 return drawing
->drawing_area
;
1140 GtkWidget
*drawing_get_widget(Drawing_t
*drawing
)
1142 return drawing
->vbox
;
1145 void drawing_draw_line( Drawing_t
*drawing
,
1151 gdk_draw_line (pixmap
,
1156 void drawing_clear(Drawing_t
*drawing
)
1158 //if (drawing->pixmap)
1159 // gdk_pixmap_unref(drawing->pixmap);
1160 ControlFlowData
*cfd
= drawing
->control_flow_data
;
1163 rectangle_pixmap(cfd
->process_list
,
1164 drawing
->drawing_area
->style
->black_gc
,
1167 drawing
->alloc_width
, // do not overlap
1170 //drawing->height = 1;
1171 /* Allocate a new pixmap with new height */
1172 //drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
1173 // drawing->width + SAFETY + EXTRA_ALLOC,
1174 // drawing->height + EXTRA_ALLOC,
1176 //drawing->alloc_width = drawing->width + SAFETY + EXTRA_ALLOC;
1177 //drawing->alloc_height = drawing->height + EXTRA_ALLOC;
1179 //gtk_widget_set_size_request(drawing->drawing_area,
1181 // drawing->height);
1182 //gtk_widget_queue_resize_no_redraw(drawing->drawing_area);
1184 /* ask for the buffer to be redrawn */
1185 gtk_widget_queue_draw ( drawing
->drawing_area
);
1189 /* Insert a square corresponding to a new process in the list */
1190 /* Applies to whole drawing->width */
1191 void drawing_insert_square(Drawing_t
*drawing
,
1195 //GdkRectangle update_rect;
1196 gboolean reallocate
= FALSE
;
1197 GdkPixmap
*new_pixmap
;
1199 /* Allocate a new pixmap with new height */
1200 if(drawing
->alloc_height
< drawing
->height
+ height
) {
1202 new_pixmap
= gdk_pixmap_new(drawing
->drawing_area
->window
,
1203 drawing
->width
+ SAFETY
+ EXTRA_ALLOC
,
1204 drawing
->height
+ height
+ EXTRA_ALLOC
,
1206 drawing
->alloc_width
= drawing
->width
+ SAFETY
+ EXTRA_ALLOC
;
1207 drawing
->alloc_height
= drawing
->height
+ height
+ EXTRA_ALLOC
;
1210 /* Copy the high region */
1211 gdk_draw_pixmap (new_pixmap
,
1212 drawing
->drawing_area
->style
->black_gc
,
1216 drawing
->width
+ SAFETY
, y
);
1219 new_pixmap
= drawing
->pixmap
;
1222 //GdkPixmap *pixmap = gdk_pixmap_new(drawing->drawing_area->window,
1223 // drawing->width + SAFETY,
1224 // drawing->height + height,
1227 /* add an empty square */
1228 gdk_draw_rectangle (new_pixmap
,
1229 drawing
->drawing_area
->style
->black_gc
,
1232 drawing
->width
+ SAFETY
, // do not overlap
1235 /* copy the bottom of the region */
1236 gdk_draw_pixmap (new_pixmap
,
1237 drawing
->drawing_area
->style
->black_gc
,
1241 drawing
->width
+SAFETY
, drawing
->height
- y
);
1244 if(reallocate
&& likely(drawing
->pixmap
)) {
1245 gdk_pixmap_unref(drawing
->pixmap
);
1246 drawing
->pixmap
= new_pixmap
;
1249 if(unlikely(drawing
->height
==1)) drawing
->height
= height
;
1250 else drawing
->height
+= height
;
1252 gtk_widget_set_size_request(drawing
->drawing_area
,
1255 gtk_widget_queue_resize_no_redraw(drawing
->drawing_area
);
1257 /* ask for the buffer to be redrawn */
1258 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
1260 drawing
->width
, drawing
->height
-y
);
1264 /* Remove a square corresponding to a removed process in the list */
1265 void drawing_remove_square(Drawing_t
*drawing
,
1271 if(unlikely((guint
)drawing
->height
== height
)) {
1272 //pixmap = gdk_pixmap_new(
1273 // drawing->drawing_area->window,
1274 // drawing->width + SAFETY,
1277 pixmap
= drawing
->pixmap
;
1280 /* Allocate a new pixmap with new height */
1281 //pixmap = gdk_pixmap_new(
1282 // drawing->drawing_area->window,
1283 // drawing->width + SAFETY,
1284 // drawing->height - height,
1286 /* Keep the same preallocated pixmap */
1287 pixmap
= drawing
->pixmap
;
1289 /* Copy the high region */
1290 gdk_draw_pixmap (pixmap
,
1291 drawing
->drawing_area
->style
->black_gc
,
1295 drawing
->width
+ SAFETY
, y
);
1297 /* Copy up the bottom of the region */
1298 gdk_draw_pixmap (pixmap
,
1299 drawing
->drawing_area
->style
->black_gc
,
1303 drawing
->width
, drawing
->height
- y
- height
);
1305 drawing
->height
-=height
;
1308 //if(likely(drawing->pixmap))
1309 // gdk_pixmap_unref(drawing->pixmap);
1311 //drawing->pixmap = pixmap;
1313 gtk_widget_set_size_request(drawing
->drawing_area
,
1316 gtk_widget_queue_resize_no_redraw(drawing
->drawing_area
);
1317 /* ask for the buffer to be redrawn */
1318 gtk_widget_queue_draw_area ( drawing
->drawing_area
,
1320 drawing
->width
, MAX(drawing
->height
-y
, 1));
1324 void drawing_update_ruler(Drawing_t
*drawing
, TimeWindow
*time_window
)
1326 gtk_widget_queue_draw(drawing
->ruler
);
1329 /* Redraw the ruler */
1331 expose_ruler( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
1333 Drawing_t
*drawing
= (Drawing_t
*)user_data
;
1334 TimeWindow time_window
= lttvwindow_get_time_window(drawing
->control_flow_data
->tab
);
1337 PangoContext
*context
;
1338 PangoLayout
*layout
;
1339 PangoFontDescription
*FontDesc
;
1340 PangoRectangle ink_rect
;
1341 gint global_width
=0;
1342 GdkColor foreground
= { 0, 0, 0, 0 };
1343 GdkColor background
= { 0, 0xffff, 0xffff, 0xffff };
1345 LttTime window_end
= time_window
.end_time
;
1346 LttTime half_width
=
1347 ltt_time_div(time_window
.time_width
,2.0);
1348 LttTime window_middle
=
1349 ltt_time_add(half_width
,
1350 time_window
.start_time
);
1351 g_debug("ruler expose event");
1353 gdk_draw_rectangle (drawing
->ruler
->window
,
1354 drawing
->ruler
->style
->white_gc
,
1356 event
->area
.x
, event
->area
.y
,
1358 event
->area
.height
);
1360 gdk_draw_line (drawing
->ruler
->window
,
1361 drawing
->ruler_gc_butt
,
1363 event
->area
.x
+ event
->area
.width
, 1);
1366 snprintf(text
, 255, "%lus\n%luns",
1367 time_window
.start_time
.tv_sec
,
1368 time_window
.start_time
.tv_nsec
);
1370 layout
= gtk_widget_create_pango_layout(drawing
->drawing_area
, NULL
);
1372 context
= pango_layout_get_context(layout
);
1373 FontDesc
= pango_context_get_font_description(context
);
1375 pango_font_description_set_size(FontDesc
, 6*PANGO_SCALE
);
1376 pango_layout_context_changed(layout
);
1378 pango_layout_set_text(layout
, text
, -1);
1379 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1380 global_width
+= ink_rect
.width
;
1382 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
1383 drawing
->ruler_gc_butt
,
1386 layout
, &foreground
, &background
);
1388 gdk_draw_line (drawing
->ruler
->window
,
1389 drawing
->ruler_gc_round
,
1394 snprintf(text
, 255, "%lus\n%luns", window_end
.tv_sec
,
1395 window_end
.tv_nsec
);
1397 pango_layout_set_text(layout
, text
, -1);
1398 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1399 global_width
+= ink_rect
.width
;
1401 if(global_width
<= drawing
->ruler
->allocation
.width
)
1403 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
1404 drawing
->ruler_gc_butt
,
1405 drawing
->ruler
->allocation
.width
- ink_rect
.width
,
1407 layout
, &foreground
, &background
);
1409 gdk_draw_line (drawing
->ruler
->window
,
1410 drawing
->ruler_gc_butt
,
1411 drawing
->ruler
->allocation
.width
-1, 1,
1412 drawing
->ruler
->allocation
.width
-1, 7);
1416 snprintf(text
, 255, "%lus\n%luns", window_middle
.tv_sec
,
1417 window_middle
.tv_nsec
);
1419 pango_layout_set_text(layout
, text
, -1);
1420 pango_layout_get_pixel_extents(layout
, &ink_rect
, NULL
);
1421 global_width
+= ink_rect
.width
;
1423 if(global_width
<= drawing
->ruler
->allocation
.width
)
1425 gdk_draw_layout_with_colors(drawing
->ruler
->window
,
1426 drawing
->ruler_gc_butt
,
1427 (drawing
->ruler
->allocation
.width
- ink_rect
.width
)/2,
1429 layout
, &foreground
, &background
);
1431 gdk_draw_line (drawing
->ruler
->window
,
1432 drawing
->ruler_gc_butt
,
1433 drawing
->ruler
->allocation
.width
/2, 1,
1434 drawing
->ruler
->allocation
.width
/2, 7);
1441 g_object_unref(layout
);
1447 /* notify mouse on ruler */
1449 motion_notify_ruler(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer user_data
)
1451 //g_debug("motion");
1452 //eventually follow mouse and show time here