add block device resource tracing to resourceview plugin
[lttv.git] / ltt / branches / poly / lttv / modules / gui / resourceview / drawing.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Mathieu Desnoyers
3 *
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;
7 *
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.
12 *
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,
16 * MA 02111-1307, USA.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #include <gtk/gtk.h>
24 #include <gdk/gdk.h>
25 #include <string.h>
26
27 #include <ltt/trace.h>
28
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>
34
35 #include "drawing.h"
36 #include "eventhooks.h"
37 #include "cfv.h"
38
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)
41
42 //FIXME
43 // fixed #define TRACE_NUMBER 0
44 #define EXTRA_ALLOC 1024 // pixels
45
46
47 #if 0 /* colors for two lines representation */
48 GdkColor 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 */
63
64 };
65 #endif //0
66
67
68 GdkColor 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 : orange */
76 { 0, 0xFFFF, 0x9400, 0x9600 }, /* COL_RUN_SOFT_IRQ : pink */
77 { 0, 0x6600, 0x0000, 0x0000 }, /* COL_WAIT : dark red */
78 { 0, 0x7700, 0x7700, 0x0000 }, /* COL_WAIT_CPU : dark yellow */
79 { 0, 0x6400, 0x0000, 0x5D00 }, /* COL_ZOMBIE : dark purple */
80 { 0, 0x0700, 0x6400, 0x0000 }, /* COL_WAIT_FORK : dark green */
81 { 0, 0x8900, 0x0000, 0x8400 }, /* COL_EXIT : "less dark" magenta */
82 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_MODE_UNKNOWN : white */
83 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_UNNAMED : white */
84
85 };
86
87 GdkColor drawing_colors_cpu[NUM_COLORS_CPU] =
88 { /* Pixel, R, G, B */
89 { 0, 0x0000, 0x0000, 0x0000 }, /* COL_CPU_UNKNOWN */
90 { 0, 0xBBBB, 0xBBBB, 0xBBBB }, /* COL_CPU_IDLE */
91 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_CPU_BUSY */
92 { 0, 0xFFFF, 0x5E00, 0x0000 }, /* COL_CPU_IRQ */
93 { 0, 0xFF00, 0xFF00, 0x0100 }, /* COL_CPU_TRAP */
94 };
95
96 GdkColor drawing_colors_irq[NUM_COLORS_IRQ] =
97 { /* Pixel, R, G, B */
98 { 0, 0x0000, 0x0000, 0x0000 }, /* COL_IRQ_UNKNOWN */
99 { 0, 0xBBBB, 0xBBBB, 0xBBBB }, /* COL_IRQ_IDLE */
100 { 0, 0xFFFF, 0x5E00, 0x0000 }, /* COL_IRQ_BUSY */
101 };
102
103 GdkColor drawing_colors_bdev[NUM_COLORS_BDEV] =
104 { /* Pixel, R, G, B */
105 { 0, 0x0000, 0x0000, 0x0000 }, /* COL_BDEV_UNKNOWN */
106 { 0, 0xBBBB, 0xBBBB, 0xBBBB }, /* COL_BDEV_IDLE */
107 { 0, 0x0000, 0x0000, 0xFFFF }, /* COL_BDEV_BUSY_READING */
108 { 0, 0xFFFF, 0x0000, 0x0000 }, /* COL_BDEV_BUSY_WRITING */
109 };
110
111 /*****************************************************************************
112 * drawing functions *
113 *****************************************************************************/
114
115 static gboolean
116 expose_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data );
117
118 static gboolean
119 motion_notify_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data);
120
121
122 /* Function responsible for updating the exposed area.
123 * It must do an events request to the lttvwindow API to ask for this update.
124 * Note : this function cannot clear the background, because it may
125 * erase drawing already present (SAFETY).
126 */
127 void drawing_data_request(Drawing_t *drawing,
128 gint x, gint y,
129 gint width,
130 gint height)
131 {
132 if(width < 0) return ;
133 if(height < 0) return ;
134
135
136 Tab *tab = drawing->control_flow_data->tab;
137 TimeWindow time_window =
138 lttvwindow_get_time_window(tab);
139
140 ControlFlowData *control_flow_data = drawing->control_flow_data;
141 // (ControlFlowData*)g_object_get_data(
142 // G_OBJECT(drawing->drawing_area), "control_flow_data");
143
144 LttTime start, time_end;
145 LttTime window_end = time_window.end_time;
146
147 g_debug("req : window start_time : %lu, %lu", time_window.start_time.tv_sec,
148 time_window.start_time.tv_nsec);
149
150 g_debug("req : window time width : %lu, %lu", time_window.time_width.tv_sec,
151 time_window.time_width.tv_nsec);
152
153 g_debug("req : window_end : %lu, %lu", window_end.tv_sec,
154 window_end.tv_nsec);
155
156 g_debug("x is : %i, x+width is : %i", x, x+width);
157
158 convert_pixels_to_time(drawing->width, x,
159 time_window,
160 &start);
161
162 convert_pixels_to_time(drawing->width, x+width,
163 time_window,
164 &time_end);
165 time_end = ltt_time_add(time_end, ltt_time_one); // because main window
166 // doesn't deliver end time.
167
168 lttvwindow_events_request_remove_all(tab,
169 control_flow_data);
170
171 {
172 /* find the tracehooks */
173 LttvTracesetContext *tsc = lttvwindow_get_traceset_context(tab);
174
175 LttvTraceset *traceset = tsc->ts;
176
177 guint i, k, l, nb_trace;
178
179 LttvTraceState *ts;
180
181 LttvTracefileState *tfs;
182
183 GArray *hooks;
184
185 LttvTraceHook *hook;
186
187 LttvTraceHookByFacility *thf;
188
189 guint ret;
190 gint before_hn, after_hn;
191
192 nb_trace = lttv_traceset_number(traceset);
193 // FIXME (fixed) : eventually request for more traces
194 for(i = 0 ; i < nb_trace ; i++) {
195 //for(i = 0; i<MIN(TRACE_NUMBER+1, nb_trace);i++) {
196 EventsRequest *events_request = g_new(EventsRequest, 1);
197 // Create the hooks
198 //LttvHooks *event = lttv_hooks_new();
199 LttvHooksById *event_by_id = lttv_hooks_by_id_new();
200 LttvHooks *before_chunk_traceset = lttv_hooks_new();
201 LttvHooks *after_chunk_traceset = lttv_hooks_new();
202 LttvHooks *before_request_hook = lttv_hooks_new();
203 LttvHooks *after_request_hook = lttv_hooks_new();
204
205 lttv_hooks_add(before_chunk_traceset,
206 before_chunk,
207 events_request,
208 LTTV_PRIO_DEFAULT);
209
210 lttv_hooks_add(after_chunk_traceset,
211 after_chunk,
212 events_request,
213 LTTV_PRIO_DEFAULT);
214
215 lttv_hooks_add(before_request_hook,
216 before_request,
217 events_request,
218 LTTV_PRIO_DEFAULT);
219
220 lttv_hooks_add(after_request_hook,
221 after_request,
222 events_request,
223 LTTV_PRIO_DEFAULT);
224
225
226 ts = (LttvTraceState *)tsc->traces[i];
227
228 /* Find the eventtype id for the following events and register the
229 associated by id hooks. */
230
231 hooks = g_array_new(FALSE, FALSE, sizeof(LttvTraceHook));
232 hooks = g_array_set_size(hooks, 18);
233 before_hn = after_hn = 0;
234
235 /* before hooks */
236
237 // ret = lttv_trace_find_hook(ts->parent.t,
238 // LTT_FACILITY_KERNEL_ARCH, LTT_EVENT_SYSCALL_ENTRY,
239 // LTT_FIELD_SYSCALL_ID, 0, 0,
240 // before_execmode_hook,
241 // events_request,
242 // &g_array_index(hooks, LttvTraceHook, before_hn++));
243 // if(ret) before_hn--;
244 //
245 // ret = lttv_trace_find_hook(ts->parent.t,
246 // LTT_FACILITY_KERNEL_ARCH, LTT_EVENT_SYSCALL_EXIT,
247 // 0, 0, 0,
248 // before_execmode_hook,
249 // events_request,
250 // &g_array_index(hooks, LttvTraceHook, before_hn++));
251 // if(ret) before_hn--;
252 //
253 ret = lttv_trace_find_hook(ts->parent.t,
254 LTT_FACILITY_KERNEL_ARCH, LTT_EVENT_TRAP_ENTRY,
255 LTT_FIELD_TRAP_ID, 0, 0,
256 before_execmode_hook,
257 events_request,
258 &g_array_index(hooks, LttvTraceHook, before_hn++));
259 if(ret) before_hn--;
260
261 ret = lttv_trace_find_hook(ts->parent.t,
262 LTT_FACILITY_KERNEL_ARCH, LTT_EVENT_TRAP_EXIT,
263 0, 0, 0,
264 before_execmode_hook,
265 events_request,
266 &g_array_index(hooks, LttvTraceHook, before_hn++));
267 if(ret) before_hn--;
268
269 ret = lttv_trace_find_hook(ts->parent.t,
270 LTT_FACILITY_KERNEL, LTT_EVENT_IRQ_ENTRY,
271 LTT_FIELD_IRQ_ID, 0, 0,
272 before_execmode_hook,
273 events_request,
274 &g_array_index(hooks, LttvTraceHook, before_hn++));
275 if(ret) before_hn--;
276
277 ret = lttv_trace_find_hook(ts->parent.t,
278 LTT_FACILITY_KERNEL, LTT_EVENT_IRQ_EXIT,
279 0, 0, 0,
280 before_execmode_hook,
281 events_request,
282 &g_array_index(hooks, LttvTraceHook, before_hn++));
283 if(ret) before_hn--;
284 //
285 // ret = lttv_trace_find_hook(ts->parent.t,
286 // LTT_FACILITY_KERNEL, LTT_EVENT_SOFT_IRQ_ENTRY,
287 // LTT_FIELD_SOFT_IRQ_ID, 0, 0,
288 // before_execmode_hook,
289 // events_request,
290 // &g_array_index(hooks, LttvTraceHook, before_hn++));
291 // if(ret) before_hn--;
292 //
293 // ret = lttv_trace_find_hook(ts->parent.t,
294 // LTT_FACILITY_KERNEL, LTT_EVENT_SOFT_IRQ_EXIT,
295 // 0, 0, 0,
296 // before_execmode_hook,
297 // events_request,
298 // &g_array_index(hooks, LttvTraceHook, before_hn++));
299 // if(ret) before_hn--;
300
301
302 ret = lttv_trace_find_hook(ts->parent.t,
303 LTT_FACILITY_KERNEL, LTT_EVENT_SCHED_SCHEDULE,
304 LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE,
305 before_schedchange_hook,
306 events_request,
307 &g_array_index(hooks, LttvTraceHook, before_hn++));
308 if(ret) before_hn--;
309
310 // ret = lttv_trace_find_hook(ts->parent.t,
311 // LTT_FACILITY_KERNEL, LTT_EVENT_PROCESS_EXIT,
312 // LTT_FIELD_PID, 0, 0,
313 // before_process_exit_hook,
314 // events_request,
315 // &g_array_index(hooks, LttvTraceHook, before_hn++));
316 // if(ret) before_hn--;
317 //
318 // ret = lttv_trace_find_hook(ts->parent.t,
319 // LTT_FACILITY_KERNEL, LTT_EVENT_PROCESS_FREE,
320 // LTT_FIELD_PID, 0, 0,
321 // before_process_release_hook,
322 // events_request,
323 // &g_array_index(hooks, LttvTraceHook, before_hn++));
324 // if(ret) before_hn--;
325 //
326 // ret = lttv_trace_find_hook(ts->parent.t,
327 // LTT_FACILITY_LIST, LTT_EVENT_STATEDUMP_END,
328 // 0, 0, 0,
329 // before_statedump_end,
330 // events_request,
331 // &g_array_index(hooks, LttvTraceHook, before_hn++));
332 // if(ret) before_hn--;
333
334 #if 0
335 lttv_trace_find_hook(ts->parent.t,
336 "core", "process", "event_sub_id",
337 "event_data1", "event_data2", before_process_hook,
338 &g_array_index(hooks, LttvTraceHook, hn++));
339 #endif //0
340 #if 0
341 lttv_trace_find_hook(ts->parent.t, "core", "process_fork", "child_pid",
342 NULL, NULL, process_fork, &g_array_index(hooks, LttvTraceHook, hn++));
343
344 lttv_trace_find_hook(ts->parent.t, "core", "process_exit", NULL, NULL,
345 NULL, process_exit, &g_array_index(hooks, LttvTraceHook, hn++));
346 #endif //0
347
348 /* after hooks */
349
350 #if 0
351 /**** DESACTIVATED ****/
352 lttv_trace_find_hook(ts->parent.t, "core","syscall_entry","syscall_id",
353 NULL, NULL, after_execmode_hook, &g_array_index(hooks, LttvTraceHook, hn++));
354 /**** DESACTIVATED ****/
355 lttv_trace_find_hook(ts->parent.t, "core", "syscall_exit", NULL, NULL,
356 NULL, after_execmode_hook, &g_array_index(hooks, LttvTraceHook, hn++));
357
358 /**** DESACTIVATED ****/
359 lttv_trace_find_hook(ts->parent.t, "core", "trap_entry", "trap_id",
360 NULL, NULL, after_execmode_hook, &g_array_index(hooks, LttvTraceHook, hn++));
361
362 /**** DESACTIVATED ****/
363 lttv_trace_find_hook(ts->parent.t, "core", "trap_exit", NULL, NULL, NULL,
364 after_execmode_hook, &g_array_index(hooks, LttvTraceHook, hn++));
365
366 /**** DESACTIVATED ****/
367 lttv_trace_find_hook(ts->parent.t, "core", "irq_entry", "irq_id", NULL,
368 NULL, after_execmode_hook, &g_array_index(hooks, LttvTraceHook, hn++));
369
370 /**** DESACTIVATED ****/
371 lttv_trace_find_hook(ts->parent.t, "core", "irq_exit", NULL, NULL, NULL,
372 after_execmode_hook, &g_array_index(hooks, LttvTraceHook, hn++));
373 #endif //0
374 #if 0
375 lttv_trace_find_hook(ts->parent.t, "core", "schedchange", "in", "out",
376 "out_state", after_schedchange_hook,
377 &g_array_index(hooks, LttvTraceHook, hn++));
378
379 lttv_trace_find_hook(ts->parent.t, "core", "process", "event_sub_id",
380 "event_data1", "event_data2", after_process_hook,
381 &g_array_index(hooks, LttvTraceHook, hn++));
382 #endif //0
383 after_hn = before_hn;
384
385 ret = lttv_trace_find_hook(ts->parent.t,
386 LTT_FACILITY_KERNEL, LTT_EVENT_SCHED_SCHEDULE,
387 LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE,
388 after_schedchange_hook,
389 events_request,
390 &g_array_index(hooks, LttvTraceHook, after_hn++));
391 if(ret) after_hn--;
392
393 // ret = lttv_trace_find_hook(ts->parent.t,
394 // LTT_FACILITY_KERNEL, LTT_EVENT_PROCESS_FORK,
395 // LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID, 0,
396 // after_process_fork_hook,
397 // events_request,
398 // &g_array_index(hooks, LttvTraceHook, after_hn++));
399 // if(ret) after_hn--;
400 //
401 // ret = lttv_trace_find_hook(ts->parent.t,
402 // LTT_FACILITY_KERNEL, LTT_EVENT_PROCESS_EXIT,
403 // LTT_FIELD_PID, 0, 0,
404 // after_process_exit_hook,
405 // events_request,
406 // &g_array_index(hooks, LttvTraceHook, after_hn++));
407 // if(ret) after_hn--;
408 //
409 // ret = lttv_trace_find_hook(ts->parent.t,
410 // LTT_FACILITY_FS, LTT_EVENT_EXEC,
411 // 0, 0, 0,
412 // after_fs_exec_hook,
413 // events_request,
414 // &g_array_index(hooks, LttvTraceHook, after_hn++));
415 // if(ret) after_hn--;
416 //
417 // ret = lttv_trace_find_hook(ts->parent.t,
418 // LTT_FACILITY_USER_GENERIC, LTT_EVENT_THREAD_BRAND,
419 // LTT_FIELD_NAME, 0, 0,
420 // after_user_generic_thread_brand_hook,
421 // events_request,
422 // &g_array_index(hooks, LttvTraceHook, after_hn++));
423 // if(ret) after_hn--;
424 //
425 // ret = lttv_trace_find_hook(ts->parent.t,
426 // LTT_FACILITY_LIST, LTT_EVENT_PROCESS_STATE,
427 // LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME,
428 // after_event_enum_process_hook,
429 // events_request,
430 // &g_array_index(hooks, LttvTraceHook, after_hn++));
431 // if(ret) after_hn--;
432
433 ret = lttv_trace_find_hook(ts->parent.t,
434 LTT_FACILITY_BLOCK, LTT_EVENT_REQUEST_ISSUE,
435 LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION,
436 before_bdev_event_hook,
437 events_request,
438 &g_array_index(hooks, LttvTraceHook, after_hn++));
439 if(ret) after_hn--;
440
441 ret = lttv_trace_find_hook(ts->parent.t,
442 LTT_FACILITY_BLOCK, LTT_EVENT_REQUEST_COMPLETE,
443 LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION,
444 before_bdev_event_hook,
445 events_request,
446 &g_array_index(hooks, LttvTraceHook, after_hn++));
447 if(ret) after_hn--;
448
449 hooks = g_array_set_size(hooks, after_hn);
450
451 #if 0
452 lttv_trace_find_hook(ts->parent.t, "core", "process_fork", "child_pid",
453 NULL, NULL, process_fork, &g_array_index(hooks, LttvTraceHook, hn++));
454
455 lttv_trace_find_hook(ts->parent.t, "core", "process_exit", NULL, NULL,
456 NULL, process_exit, &g_array_index(hooks, LttvTraceHook, hn++));
457 #endif //0
458
459
460
461 /* Add these hooks to each event_by_id hooks list */
462 /* add before */
463 for(k = 0 ; k < before_hn ; k++) {
464 hook = &g_array_index(hooks, LttvTraceHook, k);
465 for(l=0;l<hook->fac_list->len;l++) {
466 thf = g_array_index(hook->fac_list, LttvTraceHookByFacility*, l);
467 lttv_hooks_add(lttv_hooks_by_id_find(event_by_id, thf->id),
468 thf->h,
469 thf,
470 LTTV_PRIO_STATE-5);
471 }
472 }
473
474 /* add after */
475 for(k = before_hn ; k < after_hn ; k++) {
476 hook = &g_array_index(hooks, LttvTraceHook, k);
477 for(l=0;l<hook->fac_list->len;l++) {
478 thf = g_array_index(hook->fac_list, LttvTraceHookByFacility*, l);
479 lttv_hooks_add(lttv_hooks_by_id_find(event_by_id, thf->id),
480 thf->h,
481 thf,
482 LTTV_PRIO_STATE+5);
483 }
484 }
485
486 events_request->hooks = hooks;
487
488 // Fill the events request
489 events_request->owner = control_flow_data;
490 events_request->viewer_data = control_flow_data;
491 events_request->servicing = FALSE;
492 events_request->start_time = start;
493 events_request->start_position = NULL;
494 events_request->stop_flag = FALSE;
495 events_request->end_time = time_end;
496 events_request->num_events = G_MAXUINT;
497 events_request->end_position = NULL;
498 events_request->trace = i; //fixed /* FIXME */
499 events_request->before_chunk_traceset = before_chunk_traceset;
500 events_request->before_chunk_trace = NULL;
501 events_request->before_chunk_tracefile = NULL;
502 events_request->event = NULL;
503 events_request->event_by_id = event_by_id;
504 events_request->after_chunk_tracefile = NULL;
505 events_request->after_chunk_trace = NULL;
506 events_request->after_chunk_traceset = after_chunk_traceset;
507 events_request->before_request = before_request_hook;
508 events_request->after_request = after_request_hook;
509
510 g_debug("req : start : %lu, %lu", start.tv_sec,
511 start.tv_nsec);
512
513 g_debug("req : end : %lu, %lu", time_end.tv_sec,
514 time_end.tv_nsec);
515
516 lttvwindow_events_request(tab, events_request);
517
518 }
519
520 }
521
522 #if 0
523 lttv_hooks_add(event,
524 before_schedchange_hook,
525 events_request,
526 LTTV_PRIO_STATE-5);
527 lttv_hooks_add(event,
528 after_schedchange_hook,
529 events_request,
530 LTTV_PRIO_STATE+5);
531 lttv_hooks_add(event,
532 before_execmode_hook,
533 events_request,
534 LTTV_PRIO_STATE-5);
535 lttv_hooks_add(event,
536 after_execmode_hook,
537 events_request,
538 LTTV_PRIO_STATE+5);
539 lttv_hooks_add(event,
540 before_process_hook,
541 events_request,
542 LTTV_PRIO_STATE-5);
543 lttv_hooks_add(event,
544 after_process_hook,
545 events_request,
546 LTTV_PRIO_STATE+5);
547 #endif //0
548
549 }
550
551
552 static void set_last_start(gpointer key, gpointer value, gpointer user_data)
553 {
554 ResourceInfo *process_info = (ResourceInfo*)key;
555 HashedResourceData *hashed_process_data = (HashedResourceData*)value;
556 guint x = (guint)user_data;
557
558 hashed_process_data->x.over = x;
559 hashed_process_data->x.over_used = FALSE;
560 hashed_process_data->x.over_marked = FALSE;
561 hashed_process_data->x.middle = x;
562 hashed_process_data->x.middle_used = FALSE;
563 hashed_process_data->x.middle_marked = FALSE;
564 hashed_process_data->x.under = x;
565 hashed_process_data->x.under_used = FALSE;
566 hashed_process_data->x.under_marked = FALSE;
567 hashed_process_data->next_good_time = ltt_time_zero;
568
569 return;
570 }
571
572 void drawing_data_request_begin(EventsRequest *events_request, LttvTracesetState *tss)
573 {
574 g_debug("Begin of data request");
575 ControlFlowData *cfd = events_request->viewer_data;
576 LttvTracesetContext *tsc = LTTV_TRACESET_CONTEXT(tss);
577 TimeWindow time_window =
578 lttvwindow_get_time_window(cfd->tab);
579
580 guint width = cfd->drawing->width;
581 guint x=0;
582
583 cfd->drawing->last_start = events_request->start_time;
584
585 convert_time_to_pixels(
586 time_window,
587 events_request->start_time,
588 width,
589 &x);
590
591 g_hash_table_foreach(cfd->process_list->process_hash, set_last_start,
592 (gpointer)x);
593
594 }
595
596 void drawing_chunk_begin(EventsRequest *events_request, LttvTracesetState *tss)
597 {
598 g_debug("Begin of chunk");
599 ControlFlowData *cfd = events_request->viewer_data;
600 LttvTracesetContext *tsc = &tss->parent.parent;
601 //LttTime current_time = lttv_traceset_context_get_current_tfc(tsc)->timestamp;
602 guint i;
603 LttvTraceset *traceset = tsc->ts;
604 guint nb_trace = lttv_traceset_number(traceset);
605
606 if(!cfd->process_list->current_hash_data) {
607 cfd->process_list->current_hash_data = g_new(HashedResourceData**,nb_trace);
608 for(i = 0 ; i < nb_trace ; i++) {
609 guint num_cpu = ltt_trace_get_num_cpu(tss->parent.traces[i]->t);
610 cfd->process_list->current_hash_data[i] = g_new(HashedResourceData*,num_cpu);
611 memset(cfd->process_list->current_hash_data[i], 0,
612 sizeof(HashedResourceData*)*num_cpu);
613 }
614 }
615 //cfd->drawing->last_start = LTT_TIME_MIN(current_time,
616 // events_request->end_time);
617 }
618
619
620 void drawing_request_expose(EventsRequest *events_request,
621 LttvTracesetState *tss,
622 LttTime end_time)
623 {
624 gint x, width;
625 guint x_end;
626
627 ControlFlowData *cfd = events_request->viewer_data;
628 LttvTracesetContext *tsc = (LttvTracesetContext*)tss;
629 Drawing_t *drawing = cfd->drawing;
630
631 TimeWindow time_window =
632 lttvwindow_get_time_window(cfd->tab);
633
634 g_debug("request expose");
635
636 convert_time_to_pixels(
637 time_window,
638 end_time,
639 drawing->width,
640 &x_end);
641 x = drawing->damage_begin;
642
643 width = x_end - x;
644
645 drawing->damage_begin = x+width;
646
647 // FIXME ?
648 gtk_widget_queue_draw_area ( drawing->drawing_area,
649 x, 0,
650 width, drawing->drawing_area->allocation.height);
651
652 /* Update directly when scrolling */
653 gdk_window_process_updates(drawing->drawing_area->window,
654 TRUE);
655 }
656
657
658 /* Callbacks */
659
660
661 /* Create a new backing pixmap of the appropriate size */
662 /* As the scaling will always change, it's of no use to copy old
663 * pixmap.
664 *
665 * Only change the size if width changes. The height is specified and changed
666 * when process ID are added or removed from the process list.
667 */
668 static gboolean
669 configure_event( GtkWidget *widget, GdkEventConfigure *event,
670 gpointer user_data)
671 {
672 Drawing_t *drawing = (Drawing_t*)user_data;
673
674
675 /* First, get the new time interval of the main window */
676 /* we assume (see documentation) that the main window
677 * has updated the time interval before this configure gets
678 * executed.
679 */
680 //lttvwindow_get_time_window(drawing->control_flow_data->mw,
681 // &drawing->control_flow_data->time_window);
682
683 /* New pixmap, size of the configure event */
684 //GdkPixmap *pixmap = gdk_pixmap_new(widget->window,
685 // widget->allocation.width + SAFETY,
686 // widget->allocation.height + SAFETY,
687 // -1);
688
689 if(widget->allocation.width != drawing->width) {
690 g_debug("drawing configure event");
691 g_debug("New alloc draw size : %i by %i",widget->allocation.width,
692 widget->allocation.height);
693
694 drawing->width = widget->allocation.width;
695
696 if(drawing->alloc_width < widget->allocation.width) {
697 //if(drawing->pixmap)
698 // gdk_pixmap_unref(drawing->pixmap);
699
700 //drawing->pixmap = gdk_pixmap_new(widget->window,
701 // drawing->width + SAFETY + EXTRA_ALLOC,
702 // drawing->height + EXTRA_ALLOC,
703 // -1);
704 drawing->alloc_width = drawing->width + SAFETY + EXTRA_ALLOC;
705 drawing->alloc_height = drawing->height + EXTRA_ALLOC;
706 update_pixmap_size(drawing->control_flow_data->process_list,
707 drawing->alloc_width);
708 update_index_to_pixmap(drawing->control_flow_data->process_list);
709 }
710 //drawing->height = widget->allocation.height;
711
712 //ProcessList_get_height
713 // (GuiControlFlow_get_process_list(drawing->control_flow_data)),
714
715
716 // Clear the image
717 //gdk_draw_rectangle (drawing->pixmap,
718 // widget->style->black_gc,
719 // TRUE,
720 // 0, 0,
721 // drawing->width+SAFETY,
722 // drawing->height);
723
724 //g_info("init data request");
725
726
727 /* Initial data request */
728 /* no, do initial data request in the expose event */
729 // Do not need to ask for data of 1 pixel : not synchronized with
730 // main window time at this moment.
731 //drawing_data_request(drawing, &drawing->pixmap, 0, 0,
732 // widget->allocation.width,
733 // widget->allocation.height);
734
735 //drawing->width = widget->allocation.width;
736 //drawing->height = widget->allocation.height;
737
738 drawing->damage_begin = 0;
739 drawing->damage_end = widget->allocation.width;
740
741 if((widget->allocation.width != 1 &&
742 widget->allocation.height != 1)
743 && drawing->damage_begin < drawing->damage_end)
744 {
745
746 rectangle_pixmap (drawing->control_flow_data->process_list,
747 drawing->drawing_area->style->black_gc,
748 TRUE,
749 0, 0,
750 drawing->alloc_width, // do not overlap
751 -1);
752
753
754 drawing_data_request(drawing,
755 drawing->damage_begin,
756 0,
757 drawing->damage_end - drawing->damage_begin,
758 drawing->height);
759 }
760 }
761 return TRUE;
762 }
763
764
765 /* Redraw the screen from the backing pixmap */
766 static gboolean
767 expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
768 {
769 Drawing_t *drawing = (Drawing_t*)user_data;
770
771 ControlFlowData *control_flow_data =
772 (ControlFlowData*)g_object_get_data(
773 G_OBJECT(widget),
774 "control_flow_data");
775 #if 0
776 if(unlikely(drawing->gc == NULL)) {
777 drawing->gc = gdk_gc_new(drawing->drawing_area->window);
778 gdk_gc_copy(drawing->gc, drawing->drawing_area->style->black_gc);
779 }
780 #endif //0
781 TimeWindow time_window =
782 lttvwindow_get_time_window(control_flow_data->tab);
783 LttTime current_time =
784 lttvwindow_get_current_time(control_flow_data->tab);
785
786 guint cursor_x=0;
787
788 LttTime window_end = time_window.end_time;
789
790 /* update the screen from the pixmap buffer */
791 #if 0
792 gdk_draw_pixmap(widget->window,
793 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
794 drawing->pixmap,
795 event->area.x, event->area.y,
796 event->area.x, event->area.y,
797 event->area.width, event->area.height);
798 #endif //0
799 drawing->height = processlist_get_height(control_flow_data->process_list);
800 #if 0
801 copy_pixmap_to_screen(control_flow_data->process_list,
802 widget->window,
803 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
804 event->area.x, event->area.y,
805 event->area.width, event->area.height);
806 #endif //0
807 copy_pixmap_to_screen(control_flow_data->process_list,
808 widget->window,
809 drawing->gc,
810 event->area.x, event->area.y,
811 event->area.width, event->area.height);
812
813
814 /* Erase the dotted lines left.. */
815 if(widget->allocation.height > drawing->height)
816 {
817 gdk_draw_rectangle (widget->window,
818 drawing->drawing_area->style->black_gc,
819 TRUE,
820 event->area.x, drawing->height,
821 event->area.width, // do not overlap
822 widget->allocation.height - drawing->height);
823 }
824 if(ltt_time_compare(time_window.start_time, current_time) <= 0 &&
825 ltt_time_compare(window_end, current_time) >= 0)
826 {
827 /* Draw the dotted lines */
828 convert_time_to_pixels(
829 time_window,
830 current_time,
831 drawing->width,
832 &cursor_x);
833
834 #if 0
835 if(drawing->dotted_gc == NULL) {
836
837 drawing->dotted_gc = gdk_gc_new(drawing->drawing_area->window);
838 gdk_gc_copy(drawing->dotted_gc, widget->style->white_gc);
839
840 gint8 dash_list[] = { 1, 2 };
841 gdk_gc_set_line_attributes(drawing->dotted_gc,
842 1,
843 GDK_LINE_ON_OFF_DASH,
844 GDK_CAP_BUTT,
845 GDK_JOIN_MITER);
846 gdk_gc_set_dashes(drawing->dotted_gc,
847 0,
848 dash_list,
849 2);
850 }
851 #endif //0
852 gint height_tot = MAX(widget->allocation.height, drawing->height);
853 gdk_draw_line(widget->window,
854 drawing->dotted_gc,
855 cursor_x, 0,
856 cursor_x, height_tot);
857 }
858 return FALSE;
859 }
860
861 static gboolean
862 after_expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
863 {
864 //g_assert(0);
865 g_debug("AFTER EXPOSE");
866
867 return FALSE;
868
869
870 }
871
872 #if 0
873 void
874 tree_row_activated(GtkTreeModel *treemodel,
875 GtkTreePath *arg1,
876 GtkTreeViewColumn *arg2,
877 gpointer user_data)
878 {
879 ControlFlowData *cfd = (ControlFlowData*)user_data;
880 Drawing_t *drawing = cfd->drawing;
881 GtkTreeView *treeview = cfd->process_list->process_list_widget;
882 gint *path_indices;
883 gint height;
884
885 path_indices = gtk_tree_path_get_indices (arg1);
886
887 height = get_cell_height(cfd->process_list,
888 GTK_TREE_VIEW(treeview));
889 drawing->horizontal_sel = height * path_indices[0];
890 g_critical("new hor sel : %i", drawing->horizontal_sel);
891 }
892 #endif //0
893
894 /* mouse click */
895 static gboolean
896 button_press_event( GtkWidget *widget, GdkEventButton *event, gpointer user_data )
897 {
898 ControlFlowData *control_flow_data =
899 (ControlFlowData*)g_object_get_data(
900 G_OBJECT(widget),
901 "control_flow_data");
902 Drawing_t *drawing = control_flow_data->drawing;
903 TimeWindow time_window =
904 lttvwindow_get_time_window(control_flow_data->tab);
905
906 g_debug("click");
907 if(event->button == 1)
908 {
909 LttTime time;
910
911 /* left mouse button click */
912 g_debug("x click is : %f", event->x);
913
914 convert_pixels_to_time(drawing->width, (guint)event->x,
915 time_window,
916 &time);
917
918 lttvwindow_report_current_time(control_flow_data->tab, time);
919
920 }
921
922 return FALSE;
923 }
924
925 static gboolean
926 scrollbar_size_allocate(GtkWidget *widget,
927 GtkAllocation *allocation,
928 gpointer user_data)
929 {
930 Drawing_t *drawing = (Drawing_t*)user_data;
931
932 gtk_widget_set_size_request(drawing->padding, allocation->width, -1);
933 //gtk_widget_queue_resize(drawing->padding);
934 //gtk_widget_queue_resize(drawing->ruler);
935 gtk_container_check_resize(GTK_CONTAINER(drawing->ruler_hbox));
936 return 0;
937 }
938
939
940
941 Drawing_t *drawing_construct(ControlFlowData *control_flow_data)
942 {
943 Drawing_t *drawing = g_new(Drawing_t, 1);
944
945 drawing->control_flow_data = control_flow_data;
946
947 drawing->vbox = gtk_vbox_new(FALSE, 1);
948
949
950 drawing->ruler_hbox = gtk_hbox_new(FALSE, 1);
951 drawing->ruler = gtk_drawing_area_new ();
952 //gtk_widget_set_size_request(drawing->ruler, -1, 27);
953
954 drawing->padding = gtk_drawing_area_new ();
955 //gtk_widget_set_size_request(drawing->padding, -1, 27);
956 gtk_box_pack_start(GTK_BOX(drawing->ruler_hbox), drawing->ruler,
957 TRUE, TRUE, 0);
958 gtk_box_pack_end(GTK_BOX(drawing->ruler_hbox), drawing->padding,
959 FALSE, FALSE, 0);
960
961
962
963 drawing->drawing_area = gtk_drawing_area_new ();
964
965 drawing->gc = NULL;
966
967 drawing->hbox = gtk_hbox_new(FALSE, 1);
968 drawing->viewport = gtk_viewport_new(NULL, control_flow_data->v_adjust);
969 drawing->scrollbar = gtk_vscrollbar_new(control_flow_data->v_adjust);
970 gtk_box_pack_start(GTK_BOX(drawing->hbox), drawing->viewport,
971 TRUE, TRUE, 0);
972 gtk_box_pack_end(GTK_BOX(drawing->hbox), drawing->scrollbar,
973 FALSE, FALSE, 0);
974
975 //drawing->scrolled_window =
976 // gtk_scrolled_window_new (NULL,
977 // control_flow_data->v_adjust);
978
979 //gtk_scrolled_window_set_policy(
980 // GTK_SCROLLED_WINDOW(drawing->scrolled_window),
981 // GTK_POLICY_NEVER,
982 // GTK_POLICY_AUTOMATIC);
983
984 gtk_container_add(GTK_CONTAINER(drawing->viewport),
985 drawing->drawing_area);
986 //gtk_scrolled_window_add_with_viewport(
987 // GTK_SCROLLED_WINDOW(drawing->scrolled_window),
988 // drawing->drawing_area);
989
990 gtk_box_pack_start(GTK_BOX(drawing->vbox), drawing->ruler_hbox,
991 FALSE, FALSE, 0);
992 gtk_box_pack_end(GTK_BOX(drawing->vbox), drawing->hbox,
993 TRUE, TRUE, 0);
994
995 drawing->pango_layout =
996 gtk_widget_create_pango_layout(drawing->drawing_area, NULL);
997
998 drawing->height = 1;
999 drawing->width = 1;
1000 drawing->depth = 0;
1001 drawing->alloc_height = 1;
1002 drawing->alloc_width = 1;
1003
1004 drawing->damage_begin = 0;
1005 drawing->damage_end = 0;
1006 drawing->horizontal_sel = -1;
1007
1008 //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50);
1009 g_object_set_data_full(
1010 G_OBJECT(drawing->drawing_area),
1011 "Link_drawing_Data",
1012 drawing,
1013 (GDestroyNotify)drawing_destroy);
1014
1015 g_object_set_data(
1016 G_OBJECT(drawing->ruler),
1017 "drawing",
1018 drawing);
1019
1020
1021 //gtk_widget_modify_bg( drawing->drawing_area,
1022 // GTK_STATE_NORMAL,
1023 // &CF_Colors[BLACK]);
1024
1025 //gdk_window_get_geometry(drawing->drawing_area->window,
1026 // NULL, NULL,
1027 // &(drawing->width),
1028 // &(drawing->height),
1029 // -1);
1030
1031 //drawing->pixmap = gdk_pixmap_new(
1032 // drawing->drawing_area->window,
1033 // drawing->width,
1034 // drawing->height,
1035 // drawing->depth);
1036
1037 //drawing->pixmap = NULL;
1038
1039 // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
1040 // drawing->drawing_area->allocation.width,
1041 // drawing->drawing_area->allocation.height,
1042 // -1);
1043
1044 g_signal_connect (G_OBJECT(drawing->drawing_area),
1045 "configure_event",
1046 G_CALLBACK (configure_event),
1047 (gpointer)drawing);
1048
1049 g_signal_connect (G_OBJECT(drawing->ruler),
1050 "expose_event",
1051 G_CALLBACK(expose_ruler),
1052 (gpointer)drawing);
1053
1054 gtk_widget_add_events(drawing->ruler, GDK_POINTER_MOTION_MASK);
1055
1056 g_signal_connect (G_OBJECT(drawing->ruler),
1057 "motion-notify-event",
1058 G_CALLBACK(motion_notify_ruler),
1059 (gpointer)drawing);
1060
1061
1062 g_signal_connect (G_OBJECT(drawing->scrollbar),
1063 "size-allocate",
1064 G_CALLBACK(scrollbar_size_allocate),
1065 (gpointer)drawing);
1066
1067
1068
1069 g_signal_connect (G_OBJECT(drawing->drawing_area),
1070 "expose_event",
1071 G_CALLBACK (expose_event),
1072 (gpointer)drawing);
1073
1074 g_signal_connect_after (G_OBJECT(drawing->drawing_area),
1075 "expose_event",
1076 G_CALLBACK (after_expose_event),
1077 (gpointer)drawing);
1078
1079 g_signal_connect (G_OBJECT(drawing->drawing_area),
1080 "button-press-event",
1081 G_CALLBACK (button_press_event),
1082 (gpointer)drawing);
1083
1084
1085 gtk_widget_show(drawing->ruler);
1086 gtk_widget_show(drawing->padding);
1087 gtk_widget_show(drawing->ruler_hbox);
1088
1089 gtk_widget_show(drawing->drawing_area);
1090 //gtk_widget_show(drawing->scrolled_window);
1091 gtk_widget_show(drawing->viewport);
1092 gtk_widget_show(drawing->scrollbar);
1093 gtk_widget_show(drawing->hbox);
1094
1095 /* Allocate the colors */
1096 GdkColormap* colormap = gdk_colormap_get_system();
1097 gboolean success[NUM_COLORS];
1098 gdk_colormap_alloc_colors(colormap, drawing_colors, NUM_COLORS, FALSE,
1099 TRUE, success);
1100 gdk_colormap_alloc_colors(colormap, drawing_colors_cpu, NUM_COLORS_CPU, FALSE,
1101 TRUE, success);
1102 gdk_colormap_alloc_colors(colormap, drawing_colors_irq, NUM_COLORS_IRQ, FALSE,
1103 TRUE, success);
1104 gdk_colormap_alloc_colors(colormap, drawing_colors_bdev, NUM_COLORS_BDEV, FALSE,
1105 TRUE, success);
1106
1107 drawing->gc =
1108 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(control_flow_data->tab)->window));
1109 drawing->dotted_gc =
1110 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(control_flow_data->tab)->window));
1111
1112 gdk_gc_copy(drawing->gc,
1113 main_window_get_widget(control_flow_data->tab)->style->black_gc);
1114 gdk_gc_copy(drawing->dotted_gc,
1115 main_window_get_widget(control_flow_data->tab)->style->white_gc);
1116
1117 gint8 dash_list[] = { 1, 2 };
1118 gdk_gc_set_line_attributes(drawing->dotted_gc,
1119 1,
1120 GDK_LINE_ON_OFF_DASH,
1121 GDK_CAP_BUTT,
1122 GDK_JOIN_MITER);
1123 gdk_gc_set_dashes(drawing->dotted_gc,
1124 0,
1125 dash_list,
1126 2);
1127
1128 drawing->ruler_gc_butt =
1129 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(control_flow_data->tab)->window));
1130 gdk_gc_copy(drawing->ruler_gc_butt,
1131 main_window_get_widget(control_flow_data->tab)->style->black_gc);
1132 drawing->ruler_gc_round =
1133 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(control_flow_data->tab)->window));
1134 gdk_gc_copy(drawing->ruler_gc_round,
1135 main_window_get_widget(control_flow_data->tab)->style->black_gc);
1136
1137
1138 gdk_gc_set_line_attributes(drawing->ruler_gc_butt,
1139 2,
1140 GDK_LINE_SOLID,
1141 GDK_CAP_BUTT,
1142 GDK_JOIN_MITER);
1143
1144 gdk_gc_set_line_attributes(drawing->ruler_gc_round,
1145 2,
1146 GDK_LINE_SOLID,
1147 GDK_CAP_ROUND,
1148 GDK_JOIN_ROUND);
1149
1150
1151 return drawing;
1152 }
1153
1154 void drawing_destroy(Drawing_t *drawing)
1155 {
1156 g_info("drawing_destroy %p", drawing);
1157
1158 /* Free the colors */
1159 GdkColormap* colormap = gdk_colormap_get_system();
1160
1161 gdk_colormap_free_colors(colormap, drawing_colors, NUM_COLORS);
1162 gdk_colormap_free_colors(colormap, drawing_colors_cpu, NUM_COLORS_CPU);
1163 gdk_colormap_free_colors(colormap, drawing_colors_irq, NUM_COLORS_IRQ);
1164 gdk_colormap_free_colors(colormap, drawing_colors_bdev, NUM_COLORS_BDEV);
1165
1166 // Do not unref here, Drawing_t destroyed by it's widget.
1167 //g_object_unref( G_OBJECT(drawing->drawing_area));
1168 if(drawing->gc != NULL)
1169 gdk_gc_unref(drawing->gc);
1170
1171 g_object_unref(drawing->pango_layout);
1172 if(drawing->dotted_gc != NULL) gdk_gc_unref(drawing->dotted_gc);
1173 if(drawing->ruler_gc_butt != NULL) gdk_gc_unref(drawing->ruler_gc_butt);
1174 if(drawing->ruler_gc_round != NULL) gdk_gc_unref(drawing->ruler_gc_round);
1175
1176 g_free(drawing);
1177 g_info("drawing_destroy end");
1178 }
1179
1180 GtkWidget *drawing_get_drawing_area(Drawing_t *drawing)
1181 {
1182 return drawing->drawing_area;
1183 }
1184
1185 GtkWidget *drawing_get_widget(Drawing_t *drawing)
1186 {
1187 return drawing->vbox;
1188 }
1189
1190 void drawing_draw_line( Drawing_t *drawing,
1191 GdkPixmap *pixmap,
1192 guint x1, guint y1,
1193 guint x2, guint y2,
1194 GdkGC *GC)
1195 {
1196 gdk_draw_line (pixmap,
1197 GC,
1198 x1, y1, x2, y2);
1199 }
1200
1201 void drawing_clear(Drawing_t *drawing)
1202 {
1203 //if (drawing->pixmap)
1204 // gdk_pixmap_unref(drawing->pixmap);
1205 ControlFlowData *cfd = drawing->control_flow_data;
1206
1207
1208 rectangle_pixmap(cfd->process_list,
1209 drawing->drawing_area->style->black_gc,
1210 TRUE,
1211 0, 0,
1212 drawing->alloc_width, // do not overlap
1213 -1);
1214
1215 //drawing->height = 1;
1216 /* Allocate a new pixmap with new height */
1217 //drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
1218 // drawing->width + SAFETY + EXTRA_ALLOC,
1219 // drawing->height + EXTRA_ALLOC,
1220 // -1);
1221 //drawing->alloc_width = drawing->width + SAFETY + EXTRA_ALLOC;
1222 //drawing->alloc_height = drawing->height + EXTRA_ALLOC;
1223
1224 //gtk_widget_set_size_request(drawing->drawing_area,
1225 // -1,
1226 // drawing->height);
1227 //gtk_widget_queue_resize_no_redraw(drawing->drawing_area);
1228
1229 /* ask for the buffer to be redrawn */
1230 gtk_widget_queue_draw ( drawing->drawing_area);
1231 }
1232
1233 #if 0
1234 /* Insert a square corresponding to a new process in the list */
1235 /* Applies to whole drawing->width */
1236 void drawing_insert_square(Drawing_t *drawing,
1237 guint y,
1238 guint height)
1239 {
1240 //GdkRectangle update_rect;
1241 gboolean reallocate = FALSE;
1242 GdkPixmap *new_pixmap;
1243
1244 /* Allocate a new pixmap with new height */
1245 if(drawing->alloc_height < drawing->height + height) {
1246
1247 new_pixmap = gdk_pixmap_new(drawing->drawing_area->window,
1248 drawing->width + SAFETY + EXTRA_ALLOC,
1249 drawing->height + height + EXTRA_ALLOC,
1250 -1);
1251 drawing->alloc_width = drawing->width + SAFETY + EXTRA_ALLOC;
1252 drawing->alloc_height = drawing->height + height + EXTRA_ALLOC;
1253 reallocate = TRUE;
1254
1255 /* Copy the high region */
1256 gdk_draw_pixmap (new_pixmap,
1257 drawing->drawing_area->style->black_gc,
1258 drawing->pixmap,
1259 0, 0,
1260 0, 0,
1261 drawing->width + SAFETY, y);
1262
1263 } else {
1264 new_pixmap = drawing->pixmap;
1265 }
1266
1267 //GdkPixmap *pixmap = gdk_pixmap_new(drawing->drawing_area->window,
1268 // drawing->width + SAFETY,
1269 // drawing->height + height,
1270 // -1);
1271
1272 /* add an empty square */
1273 gdk_draw_rectangle (new_pixmap,
1274 drawing->drawing_area->style->black_gc,
1275 TRUE,
1276 0, y,
1277 drawing->width + SAFETY, // do not overlap
1278 height);
1279
1280 /* copy the bottom of the region */
1281 gdk_draw_pixmap (new_pixmap,
1282 drawing->drawing_area->style->black_gc,
1283 drawing->pixmap,
1284 0, y,
1285 0, y + height,
1286 drawing->width+SAFETY, drawing->height - y);
1287
1288
1289 if(reallocate && likely(drawing->pixmap)) {
1290 gdk_pixmap_unref(drawing->pixmap);
1291 drawing->pixmap = new_pixmap;
1292 }
1293
1294 if(unlikely(drawing->height==1)) drawing->height = height;
1295 else drawing->height += height;
1296
1297 gtk_widget_set_size_request(drawing->drawing_area,
1298 -1,
1299 drawing->height);
1300 gtk_widget_queue_resize_no_redraw(drawing->drawing_area);
1301
1302 /* ask for the buffer to be redrawn */
1303 gtk_widget_queue_draw_area ( drawing->drawing_area,
1304 0, y,
1305 drawing->width, drawing->height-y);
1306 }
1307
1308
1309 /* Remove a square corresponding to a removed process in the list */
1310 void drawing_remove_square(Drawing_t *drawing,
1311 guint y,
1312 guint height)
1313 {
1314 GdkPixmap *pixmap;
1315
1316 if(unlikely((guint)drawing->height == height)) {
1317 //pixmap = gdk_pixmap_new(
1318 // drawing->drawing_area->window,
1319 // drawing->width + SAFETY,
1320 // 1,
1321 // -1);
1322 pixmap = drawing->pixmap;
1323 drawing->height=1;
1324 } else {
1325 /* Allocate a new pixmap with new height */
1326 //pixmap = gdk_pixmap_new(
1327 // drawing->drawing_area->window,
1328 // drawing->width + SAFETY,
1329 // drawing->height - height,
1330 // -1);
1331 /* Keep the same preallocated pixmap */
1332 pixmap = drawing->pixmap;
1333
1334 /* Copy the high region */
1335 gdk_draw_pixmap (pixmap,
1336 drawing->drawing_area->style->black_gc,
1337 drawing->pixmap,
1338 0, 0,
1339 0, 0,
1340 drawing->width + SAFETY, y);
1341
1342 /* Copy up the bottom of the region */
1343 gdk_draw_pixmap (pixmap,
1344 drawing->drawing_area->style->black_gc,
1345 drawing->pixmap,
1346 0, y + height,
1347 0, y,
1348 drawing->width, drawing->height - y - height);
1349
1350 drawing->height-=height;
1351 }
1352
1353 //if(likely(drawing->pixmap))
1354 // gdk_pixmap_unref(drawing->pixmap);
1355
1356 //drawing->pixmap = pixmap;
1357
1358 gtk_widget_set_size_request(drawing->drawing_area,
1359 -1,
1360 drawing->height);
1361 gtk_widget_queue_resize_no_redraw(drawing->drawing_area);
1362 /* ask for the buffer to be redrawn */
1363 gtk_widget_queue_draw_area ( drawing->drawing_area,
1364 0, y,
1365 drawing->width, MAX(drawing->height-y, 1));
1366 }
1367 #endif //0
1368
1369 void drawing_update_ruler(Drawing_t *drawing, TimeWindow *time_window)
1370 {
1371 GtkRequisition req;
1372 GdkRectangle rect;
1373
1374 req.width = drawing->ruler->allocation.width;
1375 req.height = drawing->ruler->allocation.height;
1376
1377
1378 rect.x = 0;
1379 rect.y = 0;
1380 rect.width = req.width;
1381 rect.height = req.height;
1382
1383 gtk_widget_queue_draw(drawing->ruler);
1384 //gtk_widget_draw( drawing->ruler, &rect);
1385 }
1386
1387 /* Redraw the ruler */
1388 static gboolean
1389 expose_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
1390 {
1391 Drawing_t *drawing = (Drawing_t*)user_data;
1392 TimeWindow time_window = lttvwindow_get_time_window(drawing->control_flow_data->tab);
1393 gchar text[255];
1394
1395 PangoContext *context;
1396 PangoLayout *layout;
1397 PangoFontDescription *FontDesc;
1398 PangoRectangle ink_rect;
1399 gint global_width=0;
1400 GdkColor foreground = { 0, 0, 0, 0 };
1401 GdkColor background = { 0, 0xffff, 0xffff, 0xffff };
1402
1403 LttTime window_end = time_window.end_time;
1404 LttTime half_width =
1405 ltt_time_div(time_window.time_width,2.0);
1406 LttTime window_middle =
1407 ltt_time_add(half_width,
1408 time_window.start_time);
1409 g_debug("ruler expose event");
1410
1411 gdk_draw_rectangle (drawing->ruler->window,
1412 drawing->ruler->style->white_gc,
1413 TRUE,
1414 event->area.x, event->area.y,
1415 event->area.width,
1416 event->area.height);
1417
1418 gdk_draw_line (drawing->ruler->window,
1419 drawing->ruler_gc_butt,
1420 event->area.x, 1,
1421 event->area.x + event->area.width, 1);
1422
1423
1424 snprintf(text, 255, "%lus\n%luns",
1425 time_window.start_time.tv_sec,
1426 time_window.start_time.tv_nsec);
1427
1428 layout = gtk_widget_create_pango_layout(drawing->drawing_area, NULL);
1429
1430 context = pango_layout_get_context(layout);
1431 FontDesc = pango_context_get_font_description(context);
1432
1433 pango_font_description_set_size(FontDesc, 6*PANGO_SCALE);
1434 pango_layout_context_changed(layout);
1435
1436 pango_layout_set_text(layout, text, -1);
1437 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1438 global_width += ink_rect.width;
1439
1440 gdk_draw_layout_with_colors(drawing->ruler->window,
1441 drawing->ruler_gc_butt,
1442 0,
1443 6,
1444 layout, &foreground, &background);
1445
1446 gdk_draw_line (drawing->ruler->window,
1447 drawing->ruler_gc_round,
1448 1, 1,
1449 1, 7);
1450
1451
1452 snprintf(text, 255, "%lus\n%luns", window_end.tv_sec,
1453 window_end.tv_nsec);
1454
1455 pango_layout_set_text(layout, text, -1);
1456 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1457 global_width += ink_rect.width;
1458
1459 if(global_width <= drawing->ruler->allocation.width)
1460 {
1461 gdk_draw_layout_with_colors(drawing->ruler->window,
1462 drawing->ruler_gc_butt,
1463 drawing->ruler->allocation.width - ink_rect.width,
1464 6,
1465 layout, &foreground, &background);
1466
1467 gdk_draw_line (drawing->ruler->window,
1468 drawing->ruler_gc_butt,
1469 drawing->ruler->allocation.width-1, 1,
1470 drawing->ruler->allocation.width-1, 7);
1471 }
1472
1473
1474 snprintf(text, 255, "%lus\n%luns", window_middle.tv_sec,
1475 window_middle.tv_nsec);
1476
1477 pango_layout_set_text(layout, text, -1);
1478 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1479 global_width += ink_rect.width;
1480
1481 if(global_width <= drawing->ruler->allocation.width)
1482 {
1483 gdk_draw_layout_with_colors(drawing->ruler->window,
1484 drawing->ruler_gc_butt,
1485 (drawing->ruler->allocation.width - ink_rect.width)/2,
1486 6,
1487 layout, &foreground, &background);
1488
1489 gdk_draw_line (drawing->ruler->window,
1490 drawing->ruler_gc_butt,
1491 drawing->ruler->allocation.width/2, 1,
1492 drawing->ruler->allocation.width/2, 7);
1493
1494
1495
1496
1497 }
1498
1499 g_object_unref(layout);
1500
1501 return FALSE;
1502 }
1503
1504
1505 /* notify mouse on ruler */
1506 static gboolean
1507 motion_notify_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
1508 {
1509 //g_debug("motion");
1510 //eventually follow mouse and show time here
1511 return 0;
1512 }
This page took 0.063865 seconds and 5 git commands to generate.