use time_window.end_time directly
[lttv.git] / ltt / branches / poly / lttv / modules / gui / controlflow / eventhooks.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
20 /*****************************************************************************
21 * Hooks to be called by the main window *
22 *****************************************************************************/
23
24
25 /* Event hooks are the drawing hooks called during traceset read. They draw the
26 * icons, text, lines and background color corresponding to the events read.
27 *
28 * Two hooks are used for drawing : before_schedchange and after_schedchange hooks. The
29 * before_schedchange is called before the state update that occurs with an event and
30 * the after_schedchange hook is called after this state update.
31 *
32 * The before_schedchange hooks fulfill the task of drawing the visible objects that
33 * corresponds to the data accumulated by the after_schedchange hook.
34 *
35 * The after_schedchange hook accumulates the data that need to be shown on the screen
36 * (items) into a queue. Then, the next before_schedchange hook will draw what that
37 * queue contains. That's the Right Way (TM) of drawing items on the screen,
38 * because we need to draw the background first (and then add icons, text, ...
39 * over it), but we only know the length of a background region once the state
40 * corresponding to it is over, which happens to be at the next before_schedchange
41 * hook.
42 *
43 * We also have a hook called at the end of a chunk to draw the information left
44 * undrawn in each process queue. We use the current time as end of
45 * line/background.
46 */
47
48
49 //#define PANGO_ENABLE_BACKEND
50 #include <gtk/gtk.h>
51 #include <gdk/gdk.h>
52 #include <glib.h>
53 #include <assert.h>
54 #include <string.h>
55 #include <stdio.h>
56
57 //#include <pango/pango.h>
58
59 #include <ltt/event.h>
60 #include <ltt/time.h>
61 #include <ltt/type.h>
62
63 #include <lttv/lttv.h>
64 #include <lttv/hook.h>
65 #include <lttv/state.h>
66 #include <lttvwindow/lttvwindow.h>
67 #include <lttvwindow/lttvwindowtraces.h>
68
69
70 #include "eventhooks.h"
71 #include "cfv.h"
72 #include "processlist.h"
73 #include "drawing.h"
74 #include "cfv-private.h"
75
76
77 #define MAX_PATH_LEN 256
78
79
80 #if 0
81 typedef struct _ProcessAddClosure {
82 ControlFlowData *cfd;
83 guint trace_num;
84 } ProcessAddClosure;
85
86 static void process_add(gpointer key,
87 gpointer value,
88 gpointer user_data)
89 {
90 LttvProcessState *process = (LttvProcessState*)value;
91 ProcessAddClosure *closure = (ProcessAddClosure*)user_data;
92 ControlFlowData *control_flow_data = closure->cfd;
93 guint trace_num = closure->trace_num;
94
95 /* Add process to process list (if not present) */
96 guint pid;
97 LttTime birth;
98 guint y = 0, height = 0, pl_height = 0;
99
100 ProcessList *process_list = control_flow_data->process_list;
101
102 pid = process->pid;
103 birth = process->creation_time;
104 const gchar *name = g_quark_to_string(process->name);
105 HashedProcessData *hashed_process_data = NULL;
106
107 if(processlist_get_process_pixels(process_list,
108 pid,
109 &birth,
110 trace_num,
111 &y,
112 &height,
113 &hashed_process_data) == 1)
114 {
115 /* Process not present */
116 processlist_add(process_list,
117 pid,
118 &birth,
119 trace_num,
120 name,
121 &pl_height,
122 &hashed_process_data);
123 processlist_get_process_pixels(process_list,
124 pid,
125 &birth,
126 trace_num,
127 &y,
128 &height,
129 &hashed_process_data);
130 drawing_insert_square( control_flow_data->drawing, y, height);
131 }
132 }
133 #endif //0
134
135
136 /* Action to do when background computation completed.
137 *
138 * Wait for all the awaited computations to be over.
139 */
140
141 gint background_ready(void *hook_data, void *call_data)
142 {
143 ControlFlowData *control_flow_data = (ControlFlowData *)hook_data;
144 LttvTrace *trace = (LttvTrace*)call_data;
145 LttvTracesetContext *tsc =
146 lttvwindow_get_traceset_context(control_flow_data->tab);
147
148 control_flow_data->background_info_waiting--;
149
150 if(control_flow_data->background_info_waiting == 0) {
151 g_debug("control flow viewer : background computation data ready.");
152
153 drawing_clear(control_flow_data->drawing);
154 processlist_clear(control_flow_data->process_list);
155 redraw_notify(control_flow_data, NULL);
156 }
157
158 return 0;
159 }
160
161
162 /* Request background computation. Verify if it is in progress or ready first.
163 * Only for each trace in the tab's traceset.
164 */
165 void request_background_data(ControlFlowData *control_flow_data)
166 {
167 LttvTracesetContext * tsc =
168 lttvwindow_get_traceset_context(control_flow_data->tab);
169 gint num_traces = lttv_traceset_number(tsc->ts);
170 gint i;
171 LttvTrace *trace;
172
173 LttvHooks *background_ready_hook =
174 lttv_hooks_new();
175 lttv_hooks_add(background_ready_hook, background_ready, control_flow_data,
176 LTTV_PRIO_DEFAULT);
177 control_flow_data->background_info_waiting = 0;
178
179 for(i=0;i<num_traces;i++) {
180 trace = lttv_traceset_get(tsc->ts, i);
181
182 if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace)==FALSE) {
183
184 if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"),
185 trace) == FALSE) {
186 /* We first remove requests that could have been done for the same
187 * information. Happens when two viewers ask for it before servicing
188 * starts.
189 */
190 lttvwindowtraces_background_request_remove(trace, "state");
191 lttvwindowtraces_background_request_queue(trace,
192 "state");
193 lttvwindowtraces_background_notify_queue(control_flow_data,
194 trace,
195 ltt_time_infinite,
196 NULL,
197 background_ready_hook);
198 control_flow_data->background_info_waiting++;
199 } else { /* in progress */
200
201 lttvwindowtraces_background_notify_current(control_flow_data,
202 trace,
203 ltt_time_infinite,
204 NULL,
205 background_ready_hook);
206 control_flow_data->background_info_waiting++;
207 }
208 } else {
209 /* Data ready. Be its nature, this viewer doesn't need to have
210 * its data ready hook called htere, because a background
211 * request is always linked with a redraw.
212 */
213 }
214
215 }
216
217 lttv_hooks_destroy(background_ready_hook);
218 }
219
220
221
222
223 /**
224 * Event Viewer's constructor hook
225 *
226 * This constructor is given as a parameter to the menuitem and toolbar button
227 * registration. It creates the list.
228 * @param tab A pointer to the parent tab.
229 * @return The widget created.
230 */
231 GtkWidget *
232 h_guicontrolflow(Tab *tab)
233 {
234 g_info("h_guicontrolflow, %p", tab);
235 ControlFlowData *control_flow_data = guicontrolflow() ;
236
237 control_flow_data->tab = tab;
238
239 //g_debug("time width2 : %u",time_window->time_width);
240 // Unreg done in the GuiControlFlow_Destructor
241 lttvwindow_register_traceset_notify(tab,
242 traceset_notify,
243 control_flow_data);
244
245 lttvwindow_register_time_window_notify(tab,
246 update_time_window_hook,
247 control_flow_data);
248 lttvwindow_register_current_time_notify(tab,
249 update_current_time_hook,
250 control_flow_data);
251 lttvwindow_register_redraw_notify(tab,
252 redraw_notify,
253 control_flow_data);
254 lttvwindow_register_continue_notify(tab,
255 continue_notify,
256 control_flow_data);
257 request_background_data(control_flow_data);
258
259
260 return guicontrolflow_get_widget(control_flow_data) ;
261
262 }
263
264 int event_selected_hook(void *hook_data, void *call_data)
265 {
266 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
267 guint *event_number = (guint*) call_data;
268
269 g_debug("DEBUG : event selected by main window : %u", *event_number);
270
271 }
272
273 /* Function that selects the color of status&exemode line */
274 static __inline PropertiesLine prepare_s_e_line(LttvProcessState *process)
275 {
276 PropertiesLine prop_line;
277 prop_line.line_width = 2;
278 prop_line.style = GDK_LINE_SOLID;
279 prop_line.y = MIDDLE;
280 //GdkColormap *colormap = gdk_colormap_get_system();
281
282 g_debug("prepare_status_line for state : %s",
283 g_quark_to_string(process->state->s));
284
285 if(process->state->s == LTTV_STATE_RUN) {
286 if(process->state->t == LTTV_STATE_USER_MODE)
287 prop_line.color = drawing_colors[COL_RUN_USER_MODE];
288 else if(process->state->t == LTTV_STATE_SYSCALL)
289 prop_line.color = drawing_colors[COL_RUN_SYSCALL];
290 else if(process->state->t == LTTV_STATE_TRAP)
291 prop_line.color = drawing_colors[COL_RUN_TRAP];
292 else if(process->state->t == LTTV_STATE_IRQ)
293 prop_line.color = drawing_colors[COL_RUN_IRQ];
294 else if(process->state->t == LTTV_STATE_MODE_UNKNOWN)
295 prop_line.color = drawing_colors[COL_MODE_UNKNOWN];
296 else
297 g_assert(FALSE); /* RUNNING MODE UNKNOWN */
298 } else if(process->state->s == LTTV_STATE_WAIT) {
299 /* We don't show if we wait while in user mode, trap, irq or syscall */
300 prop_line.color = drawing_colors[COL_WAIT];
301 } else if(process->state->s == LTTV_STATE_WAIT_CPU) {
302 /* We don't show if we wait for CPU while in user mode, trap, irq
303 * or syscall */
304 prop_line.color = drawing_colors[COL_WAIT_CPU];
305 } else if(process->state->s == LTTV_STATE_ZOMBIE) {
306 prop_line.color = drawing_colors[COL_ZOMBIE];
307 } else if(process->state->s == LTTV_STATE_WAIT_FORK) {
308 prop_line.color = drawing_colors[COL_WAIT_FORK];
309 } else if(process->state->s == LTTV_STATE_EXIT) {
310 prop_line.color = drawing_colors[COL_EXIT];
311 } else if(process->state->s == LTTV_STATE_UNNAMED) {
312 prop_line.color = drawing_colors[COL_UNNAMED];
313 } else
314 g_assert(FALSE); /* UNKNOWN STATE */
315
316 return prop_line;
317
318 }
319
320 #if 0
321 static __inline PropertiesLine prepare_status_line(LttvProcessState *process)
322 {
323 PropertiesLine prop_line;
324 prop_line.line_width = 2;
325 prop_line.style = GDK_LINE_SOLID;
326 prop_line.y = MIDDLE;
327 //GdkColormap *colormap = gdk_colormap_get_system();
328
329 g_debug("prepare_status_line for state : %s",
330 g_quark_to_string(process->state->s));
331
332 /* color of line : status of the process */
333 if(process->state->s == LTTV_STATE_UNNAMED)
334 prop_line.color = drawing_colors[COL_WHITE];
335 else if(process->state->s == LTTV_STATE_WAIT_FORK)
336 prop_line.color = drawing_colors[COL_WAIT_FORK];
337 else if(process->state->s == LTTV_STATE_WAIT_CPU)
338 prop_line.color = drawing_colors[COL_WAIT_CPU];
339 else if(process->state->s == LTTV_STATE_EXIT)
340 prop_line.color = drawing_colors[COL_EXIT];
341 else if(process->state->s == LTTV_STATE_ZOMBIE)
342 prop_line.color = drawing_colors[COL_ZOMBIE];
343 else if(process->state->s == LTTV_STATE_WAIT)
344 prop_line.color = drawing_colors[COL_WAIT];
345 else if(process->state->s == LTTV_STATE_RUN)
346 prop_line.color = drawing_colors[COL_RUN];
347 else
348 prop_line.color = drawing_colors[COL_WHITE];
349
350 //gdk_colormap_alloc_color(colormap,
351 // prop_line.color,
352 // FALSE,
353 // TRUE);
354
355 return prop_line;
356
357 }
358 #endif //0
359
360
361 /* before_schedchange_hook
362 *
363 * This function basically draw lines and icons. Two types of lines are drawn :
364 * one small (3 pixels?) representing the state of the process and the second
365 * type is thicker (10 pixels?) representing on which CPU a process is running
366 * (and this only in running state).
367 *
368 * Extremums of the lines :
369 * x_min : time of the last event context for this process kept in memory.
370 * x_max : time of the current event.
371 * y : middle of the process in the process list. The process is found in the
372 * list, therefore is it's position in pixels.
373 *
374 * The choice of lines'color is defined by the context of the last event for this
375 * process.
376 */
377
378
379 int before_schedchange_hook(void *hook_data, void *call_data)
380 {
381 EventsRequest *events_request = (EventsRequest*)hook_data;
382 ControlFlowData *control_flow_data = events_request->viewer_data;
383 Drawing_t *drawing = control_flow_data->drawing;
384
385 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
386
387 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
388 LttvTraceState *ts =(LttvTraceState *)((LttvTracefileContext*)tfs)->t_context;
389
390 LttEvent *e;
391 e = tfc->e;
392
393 LttTime evtime = ltt_event_time(e);
394 TimeWindow time_window =
395 lttvwindow_get_time_window(control_flow_data->tab);
396 #ifdef EXTRA_CHECK
397 if(ltt_time_compare(evtime, time_window.start_time) == -1
398 || ltt_time_compare(evtime, time_window.end_time) == 1)
399 return;
400 #endif //EXTRA_CHECK
401 guint width = drawing->width;
402
403 /* we are in a schedchange, before the state update. We must draw the
404 * items corresponding to the state before it changes : now is the right
405 * time to do it.
406 */
407
408 guint pid_out;
409 guint pid_in;
410 {
411 LttField *f = ltt_event_field(e);
412 LttField *element;
413 element = ltt_field_member(f,0);
414 pid_out = ltt_event_get_long_unsigned(e,element);
415 element = ltt_field_member(f,1);
416 pid_in = ltt_event_get_long_unsigned(e,element);
417 g_debug("out : %u in : %u", pid_out, pid_in);
418 }
419
420 {
421 /* For the pid_out */
422 /* First, check if the current process is in the state computation
423 * process list. If it is there, that means we must add it right now and
424 * draw items from the beginning of the read for it. If it is not
425 * present, it's a new process and it was not present : it will
426 * be added after the state update. */
427 LttvProcessState *process;
428 process = lttv_state_find_process(tfs, pid_out);
429 //process = tfs->process;
430
431 if(process != NULL) {
432 /* Well, the process_out existed : we must get it in the process hash
433 * or add it, and draw its items.
434 */
435 /* Add process to process list (if not present) */
436 guint y = 0, height = 0, pl_height = 0;
437 HashedProcessData *hashed_process_data = NULL;
438 ProcessList *process_list = control_flow_data->process_list;
439 LttTime birth = process->creation_time;
440 const gchar *name = g_quark_to_string(process->name);
441
442 if(processlist_get_process_pixels(process_list,
443 pid_out,
444 process->last_cpu,
445 &birth,
446 tfc->t_context->index,
447 &y,
448 &height,
449 &hashed_process_data) == 1)
450 {
451 g_assert(pid_out == 0 || pid_out != process->ppid);
452 /* Process not present */
453 ProcessInfo *process_info;
454 processlist_add(process_list,
455 pid_out,
456 process->last_cpu,
457 process->ppid,
458 &birth,
459 tfc->t_context->index,
460 name,
461 &pl_height,
462 &process_info,
463 &hashed_process_data);
464 processlist_get_pixels_from_data(process_list,
465 process_info,
466 hashed_process_data,
467 &y,
468 &height);
469 drawing_insert_square( drawing, y, height);
470 }
471
472 /* Now, the process is in the state hash and our own process hash.
473 * We definitely can draw the items related to the ending state.
474 */
475
476 /* Check if the x position is unset. In can have been left unset by
477 * a draw closure from a after chunk hook. This should never happen,
478 * because it must be set by before chunk hook to the damage_begin
479 * value.
480 */
481 g_assert(hashed_process_data->x.middle != -1);
482 if(ltt_time_compare(hashed_process_data->next_good_time,
483 evtime) > 0)
484 {
485 if(hashed_process_data->x.middle_marked == FALSE) {
486 guint x;
487 convert_time_to_pixels(
488 time_window,
489 evtime,
490 width,
491 &x);
492
493 /* Draw collision indicator */
494 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
495 gdk_draw_point(drawing->pixmap,
496 drawing->gc,
497 x,
498 y+(height/2)-3);
499 hashed_process_data->x.middle_marked = TRUE;
500 }
501 } else {
502 guint x;
503 convert_time_to_pixels(
504 time_window,
505 evtime,
506 width,
507 &x);
508
509
510 /* Jump over draw if we are at the same x position */
511 if(x == hashed_process_data->x.middle &&
512 hashed_process_data->x.middle_used)
513 {
514 if(hashed_process_data->x.middle_marked == FALSE) {
515 /* Draw collision indicator */
516 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
517 gdk_draw_point(drawing->pixmap,
518 drawing->gc,
519 x,
520 y+(height/2)-3);
521 hashed_process_data->x.middle_marked = TRUE;
522 }
523 /* jump */
524 } else {
525 DrawContext draw_context;
526
527 /* Now create the drawing context that will be used to draw
528 * items related to the last state. */
529 draw_context.drawable = drawing->pixmap;
530 draw_context.gc = drawing->gc;
531 draw_context.pango_layout = drawing->pango_layout;
532 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
533 draw_context.drawinfo.end.x = x;
534
535 draw_context.drawinfo.y.over = y+1;
536 draw_context.drawinfo.y.middle = y+(height/2);
537 draw_context.drawinfo.y.under = y+height;
538
539 draw_context.drawinfo.start.offset.over = 0;
540 draw_context.drawinfo.start.offset.middle = 0;
541 draw_context.drawinfo.start.offset.under = 0;
542 draw_context.drawinfo.end.offset.over = 0;
543 draw_context.drawinfo.end.offset.middle = 0;
544 draw_context.drawinfo.end.offset.under = 0;
545
546 {
547 /* Draw the line */
548 PropertiesLine prop_line = prepare_s_e_line(process);
549 draw_line((void*)&prop_line, (void*)&draw_context);
550
551 }
552 /* become the last x position */
553 hashed_process_data->x.middle = x;
554 hashed_process_data->x.middle_used = TRUE;
555 hashed_process_data->x.middle_marked = FALSE;
556
557 /* Calculate the next good time */
558 convert_pixels_to_time(width, x+1, time_window,
559 &hashed_process_data->next_good_time);
560 }
561 }
562 }
563 }
564
565 {
566 /* For the pid_in */
567 /* First, check if the current process is in the state computation
568 * process list. If it is there, that means we must add it right now and
569 * draw items from the beginning of the read for it. If it is not
570 * present, it's a new process and it was not present : it will
571 * be added after the state update. */
572 LttvProcessState *process;
573 process = lttv_state_find_process(tfs, pid_in);
574
575 if(process != NULL) {
576 /* Well, the process_out existed : we must get it in the process hash
577 * or add it, and draw its items.
578 */
579 /* Add process to process list (if not present) */
580 guint y = 0, height = 0, pl_height = 0;
581 HashedProcessData *hashed_process_data = NULL;
582 ProcessList *process_list = control_flow_data->process_list;
583 LttTime birth = process->creation_time;
584 const gchar *name = g_quark_to_string(process->name);
585
586 if(processlist_get_process_pixels(process_list,
587 pid_in,
588 process->last_cpu,
589 &birth,
590 tfc->t_context->index,
591 &y,
592 &height,
593 &hashed_process_data) == 1)
594 {
595 g_assert(pid_in == 0 || pid_in != process->ppid);
596 /* Process not present */
597 ProcessInfo *process_info;
598 processlist_add(process_list,
599 pid_in,
600 process->last_cpu,
601 process->ppid,
602 &birth,
603 tfc->t_context->index,
604 name,
605 &pl_height,
606 &process_info,
607 &hashed_process_data);
608 processlist_get_pixels_from_data(process_list,
609 process_info,
610 hashed_process_data,
611 &y,
612 &height);
613 drawing_insert_square( drawing, y, height);
614 }
615
616 /* Now, the process is in the state hash and our own process hash.
617 * We definitely can draw the items related to the ending state.
618 */
619
620 /* Check if the x position is unset. In can have been left unset by
621 * a draw closure from a after chunk hook. This should never happen,
622 * because it must be set by before chunk hook to the damage_begin
623 * value.
624 */
625 g_assert(hashed_process_data->x.middle != -1);
626
627 if(ltt_time_compare(hashed_process_data->next_good_time,
628 evtime) > 0)
629 {
630 if(hashed_process_data->x.middle_marked == FALSE) {
631 guint x;
632 convert_time_to_pixels(
633 time_window,
634 evtime,
635 width,
636 &x);
637
638 /* Draw collision indicator */
639 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
640 gdk_draw_point(drawing->pixmap,
641 drawing->gc,
642 x,
643 y+(height/2)-3);
644 hashed_process_data->x.middle_marked = TRUE;
645 }
646 } else {
647 guint x;
648
649 convert_time_to_pixels(
650 time_window,
651 evtime,
652 width,
653 &x);
654
655
656 /* Jump over draw if we are at the same x position */
657 if(x == hashed_process_data->x.middle &&
658 hashed_process_data->x.middle_used)
659 {
660 if(hashed_process_data->x.middle_marked == FALSE) {
661 /* Draw collision indicator */
662 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
663 gdk_draw_point(drawing->pixmap,
664 drawing->gc,
665 x,
666 y+(height/2)-3);
667 hashed_process_data->x.middle_marked = TRUE;
668 }
669 /* jump */
670 } else {
671 DrawContext draw_context;
672
673 /* Now create the drawing context that will be used to draw
674 * items related to the last state. */
675 draw_context.drawable = drawing->pixmap;
676 draw_context.gc = drawing->gc;
677 draw_context.pango_layout = drawing->pango_layout;
678 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
679 draw_context.drawinfo.end.x = x;
680
681 draw_context.drawinfo.y.over = y+1;
682 draw_context.drawinfo.y.middle = y+(height/2);
683 draw_context.drawinfo.y.under = y+height;
684
685 draw_context.drawinfo.start.offset.over = 0;
686 draw_context.drawinfo.start.offset.middle = 0;
687 draw_context.drawinfo.start.offset.under = 0;
688 draw_context.drawinfo.end.offset.over = 0;
689 draw_context.drawinfo.end.offset.middle = 0;
690 draw_context.drawinfo.end.offset.under = 0;
691
692 {
693 /* Draw the line */
694 PropertiesLine prop_line = prepare_s_e_line(process);
695 draw_line((void*)&prop_line, (void*)&draw_context);
696 }
697
698
699 /* become the last x position */
700 hashed_process_data->x.middle = x;
701 hashed_process_data->x.middle_used = TRUE;
702 hashed_process_data->x.middle_marked = FALSE;
703
704 /* Calculate the next good time */
705 convert_pixels_to_time(width, x+1, time_window,
706 &hashed_process_data->next_good_time);
707 }
708 }
709 }
710 }
711 return 0;
712
713
714 #if 0
715 EventsRequest *events_request = (EventsRequest*)hook_data;
716 ControlFlowData *control_flow_data =
717 (ControlFlowData*)events_request->viewer_data;
718 Tab *tab = control_flow_data->tab;
719
720 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
721
722 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
723 LttvTraceState *ts =(LttvTraceState *)LTTV_TRACEFILE_CONTEXT(tfs)->t_context;
724
725 LttEvent *e;
726 e = tfc->e;
727
728 LttTime evtime = ltt_event_time(e);
729 TimeWindow time_window =
730 lttvwindow_get_time_window(tab);
731
732 LttTime time_window.end_time = time_window.time_window.end_time;
733
734 //if(time < time_beg || time > time_end) return;
735 if(ltt_time_compare(evtime, time_window.start_time) == -1
736 || ltt_time_compare(evtime, time_window.end_time) == 1)
737 return;
738
739 if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0)
740 {
741 g_debug("schedchange!");
742
743 /* Add process to process list (if not present) and get drawing "y" from
744 * process position */
745 guint pid_out, pid_in;
746 LttvProcessState *process_out, *process_in;
747 LttTime birth;
748 guint y_in = 0, y_out = 0, height = 0, pl_height = 0;
749
750 ProcessList *process_list = control_flow_data->process_list;
751
752
753 LttField *f = ltt_event_field(e);
754 LttField *element;
755 element = ltt_field_member(f,0);
756 pid_out = ltt_event_get_long_unsigned(e,element);
757 element = ltt_field_member(f,1);
758 pid_in = ltt_event_get_long_unsigned(e,element);
759 g_debug("out : %u in : %u", pid_out, pid_in);
760
761
762 /* Find process pid_out in the list... */
763 process_out = lttv_state_find_process(tfs, pid_out);
764 if(process_out == NULL) return 0;
765 g_debug("out : %s",g_quark_to_string(process_out->state->s));
766
767 birth = process_out->creation_time;
768 const gchar *name = g_quark_to_string(process_out->name);
769 HashedProcessData *hashed_process_data_out = NULL;
770
771 if(processlist_get_process_pixels(process_list,
772 pid_out,
773 &birth,
774 tfc->t_context->index,
775 &y_out,
776 &height,
777 &hashed_process_data_out) == 1)
778 {
779 /* Process not present */
780 processlist_add(process_list,
781 pid_out,
782 &birth,
783 tfc->t_context->index,
784 name,
785 &pl_height,
786 &hashed_process_data_out);
787 g_assert(processlist_get_process_pixels(process_list,
788 pid_out,
789 &birth,
790 tfc->t_context->index,
791 &y_out,
792 &height,
793 &hashed_process_data_out)==0);
794 drawing_insert_square( control_flow_data->drawing, y_out, height);
795 }
796 //g_free(name);
797
798 /* Find process pid_in in the list... */
799 process_in = lttv_state_find_process(tfs, pid_in);
800 if(process_in == NULL) return 0;
801 g_debug("in : %s",g_quark_to_string(process_in->state->s));
802
803 birth = process_in->creation_time;
804 name = g_quark_to_string(process_in->name);
805 HashedProcessData *hashed_process_data_in = NULL;
806
807 if(processlist_get_process_pixels(process_list,
808 pid_in,
809 &birth,
810 tfc->t_context->index,
811 &y_in,
812 &height,
813 &hashed_process_data_in) == 1)
814 {
815 /* Process not present */
816 processlist_add(process_list,
817 pid_in,
818 &birth,
819 tfc->t_context->index,
820 name,
821 &pl_height,
822 &hashed_process_data_in);
823 processlist_get_process_pixels(process_list,
824 pid_in,
825 &birth,
826 tfc->t_context->index,
827 &y_in,
828 &height,
829 &hashed_process_data_in);
830
831 drawing_insert_square( control_flow_data->drawing, y_in, height);
832 }
833 //g_free(name);
834
835
836 /* Find pixels corresponding to time of the event. If the time does
837 * not fit in the window, show a warning, not supposed to happend. */
838 guint x = 0;
839 guint width = control_flow_data->drawing->width;
840
841 LttTime time = ltt_event_time(e);
842
843 LttTime window_end = time_window.time_window.end_time;
844
845 convert_time_to_pixels(
846 time_window,
847 time,
848 width,
849 &x);
850 //assert(x <= width);
851 //
852 /* draw what represents the event for outgoing process. */
853
854 DrawContext *draw_context_out = hashed_process_data_out->draw_context;
855 draw_context_out->current->modify_over->x = x;
856 draw_context_out->current->modify_under->x = x;
857 draw_context_out->current->modify_over->y = y_out;
858 draw_context_out->current->modify_under->y = y_out+(height/2)+2;
859 draw_context_out->drawable = control_flow_data->drawing->pixmap;
860 draw_context_out->pango_layout = control_flow_data->drawing->pango_layout;
861 GtkWidget *widget = control_flow_data->drawing->drawing_area;
862 //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
863 //draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
864 //gdk_gc_copy(draw_context_out->gc, widget->style->black_gc);
865 //draw_context_out->gc = widget->style->black_gc;
866
867 //draw_arc((void*)&prop_arc, (void*)draw_context_out);
868 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
869
870 /* Draw the line/background of the out process */
871 if(draw_context_out->previous->middle->x == -1)
872 {
873 draw_context_out->previous->over->x =
874 control_flow_data->drawing->damage_begin;
875 draw_context_out->previous->middle->x =
876 control_flow_data->drawing->damage_begin;
877 draw_context_out->previous->under->x =
878 control_flow_data->drawing->damage_begin;
879
880 g_debug("out middle x_beg : %u",control_flow_data->drawing->damage_begin);
881 }
882
883 draw_context_out->current->middle->x = x;
884 draw_context_out->current->over->x = x;
885 draw_context_out->current->under->x = x;
886 draw_context_out->current->middle->y = y_out + height/2;
887 draw_context_out->current->over->y = y_out;
888 draw_context_out->current->under->y = y_out + height;
889 draw_context_out->previous->middle->y = y_out + height/2;
890 draw_context_out->previous->over->y = y_out;
891 draw_context_out->previous->under->y = y_out + height;
892
893 draw_context_out->drawable = control_flow_data->drawing->pixmap;
894 draw_context_out->pango_layout = control_flow_data->drawing->pango_layout;
895
896 if(process_out->state->s == LTTV_STATE_RUN)
897 {
898 //draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
899 //gdk_gc_copy(draw_context_out->gc, widget->style->black_gc);
900 draw_context_out->gc = control_flow_data->drawing->gc;
901
902 PropertiesBG prop_bg;
903 prop_bg.color = g_new(GdkColor,1);
904
905 switch(tfc->index) {
906 case 0:
907 prop_bg.color->red = 0x1515;
908 prop_bg.color->green = 0x1515;
909 prop_bg.color->blue = 0x8c8c;
910 break;
911 case 1:
912 prop_bg.color->red = 0x4e4e;
913 prop_bg.color->green = 0xa9a9;
914 prop_bg.color->blue = 0xa4a4;
915 break;
916 case 2:
917 prop_bg.color->red = 0x7a7a;
918 prop_bg.color->green = 0x4a4a;
919 prop_bg.color->blue = 0x8b8b;
920 break;
921 case 3:
922 prop_bg.color->red = 0x8080;
923 prop_bg.color->green = 0x7777;
924 prop_bg.color->blue = 0x4747;
925 break;
926 default:
927 prop_bg.color->red = 0xe7e7;
928 prop_bg.color->green = 0xe7e7;
929 prop_bg.color->blue = 0xe7e7;
930 }
931
932 g_debug("calling from draw_event");
933 draw_bg((void*)&prop_bg, (void*)draw_context_out);
934 g_free(prop_bg.color);
935 //gdk_gc_unref(draw_context_out->gc);
936 }
937
938 draw_context_out->gc = widget->style->black_gc;
939
940 GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 };
941 GdkColor colorbg_out = { 0, 0x0000, 0x0000, 0x0000 };
942 PropertiesText prop_text_out;
943 prop_text_out.foreground = &colorfg_out;
944 prop_text_out.background = &colorbg_out;
945 prop_text_out.size = 6;
946 prop_text_out.position = OVER;
947
948 /* color of text : status of the process */
949 if(process_out->state->s == LTTV_STATE_UNNAMED)
950 {
951 prop_text_out.foreground->red = 0xffff;
952 prop_text_out.foreground->green = 0xffff;
953 prop_text_out.foreground->blue = 0xffff;
954 }
955 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
956 {
957 prop_text_out.foreground->red = 0x0fff;
958 prop_text_out.foreground->green = 0xffff;
959 prop_text_out.foreground->blue = 0xfff0;
960 }
961 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
962 {
963 prop_text_out.foreground->red = 0xffff;
964 prop_text_out.foreground->green = 0xffff;
965 prop_text_out.foreground->blue = 0x0000;
966 }
967 else if(process_out->state->s == LTTV_STATE_ZOMBIE)
968 {
969 prop_text_out.foreground->red = 0xffff;
970 prop_text_out.foreground->green = 0x0000;
971 prop_text_out.foreground->blue = 0xffff;
972 }
973 else if(process_out->state->s == LTTV_STATE_WAIT)
974 {
975 prop_text_out.foreground->red = 0xffff;
976 prop_text_out.foreground->green = 0x0000;
977 prop_text_out.foreground->blue = 0x0000;
978 }
979 else if(process_out->state->s == LTTV_STATE_RUN)
980 {
981 prop_text_out.foreground->red = 0x0000;
982 prop_text_out.foreground->green = 0xffff;
983 prop_text_out.foreground->blue = 0x0000;
984 }
985 else
986 {
987 prop_text_out.foreground->red = 0xffff;
988 prop_text_out.foreground->green = 0xffff;
989 prop_text_out.foreground->blue = 0xffff;
990 }
991
992
993 /* Print status of the process : U, WF, WC, E, W, R */
994 if(process_out->state->s == LTTV_STATE_UNNAMED)
995 prop_text_out.text = "U->";
996 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
997 prop_text_out.text = "WF->";
998 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
999 prop_text_out.text = "WC->";
1000 else if(process_out->state->s == LTTV_STATE_ZOMBIE)
1001 prop_text_out.text = "E->";
1002 else if(process_out->state->s == LTTV_STATE_WAIT)
1003 prop_text_out.text = "W->";
1004 else if(process_out->state->s == LTTV_STATE_RUN)
1005 prop_text_out.text = "R->";
1006 else
1007 prop_text_out.text = "U";
1008
1009 draw_text((void*)&prop_text_out, (void*)draw_context_out);
1010 //gdk_gc_unref(draw_context_out->gc);
1011
1012 //draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
1013 //gdk_gc_copy(draw_context_out->gc, widget->style->black_gc);
1014 draw_context_out->gc = control_flow_data->drawing->gc;
1015
1016 PropertiesLine prop_line_out;
1017 prop_line_out.color = g_new(GdkColor,1);
1018 prop_line_out.line_width = 2;
1019 prop_line_out.style = GDK_LINE_SOLID;
1020 prop_line_out.position = MIDDLE;
1021
1022 g_debug("out state : %s", g_quark_to_string(process_out->state->s));
1023
1024 /* color of line : status of the process */
1025 if(process_out->state->s == LTTV_STATE_UNNAMED)
1026 {
1027 prop_line_out.color->red = 0xffff;
1028 prop_line_out.color->green = 0xffff;
1029 prop_line_out.color->blue = 0xffff;
1030 }
1031 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
1032 {
1033 prop_line_out.color->red = 0x0fff;
1034 prop_line_out.color->green = 0xffff;
1035 prop_line_out.color->blue = 0xfff0;
1036 }
1037 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
1038 {
1039 prop_line_out.color->red = 0xffff;
1040 prop_line_out.color->green = 0xffff;
1041 prop_line_out.color->blue = 0x0000;
1042 }
1043 else if(process_out->state->s == LTTV_STATE_ZOMBIE)
1044 {
1045 prop_line_out.color->red = 0xffff;
1046 prop_line_out.color->green = 0x0000;
1047 prop_line_out.color->blue = 0xffff;
1048 }
1049 else if(process_out->state->s == LTTV_STATE_WAIT)
1050 {
1051 prop_line_out.color->red = 0xffff;
1052 prop_line_out.color->green = 0x0000;
1053 prop_line_out.color->blue = 0x0000;
1054 }
1055 else if(process_out->state->s == LTTV_STATE_RUN)
1056 {
1057 prop_line_out.color->red = 0x0000;
1058 prop_line_out.color->green = 0xffff;
1059 prop_line_out.color->blue = 0x0000;
1060 }
1061 else
1062 {
1063 prop_line_out.color->red = 0xffff;
1064 prop_line_out.color->green = 0xffff;
1065 prop_line_out.color->blue = 0xffff;
1066 }
1067
1068 draw_line((void*)&prop_line_out, (void*)draw_context_out);
1069 g_free(prop_line_out.color);
1070 //gdk_gc_unref(draw_context_out->gc);
1071 /* Note : finishing line will have to be added when trace read over. */
1072
1073 /* Finally, update the drawing context of the pid_in. */
1074
1075 DrawContext *draw_context_in = hashed_process_data_in->draw_context;
1076 draw_context_in->current->modify_over->x = x;
1077 draw_context_in->current->modify_under->x = x;
1078 draw_context_in->current->modify_over->y = y_in;
1079 draw_context_in->current->modify_under->y = y_in+(height/2)+2;
1080 draw_context_in->drawable = control_flow_data->drawing->pixmap;
1081 draw_context_in->pango_layout = control_flow_data->drawing->pango_layout;
1082 widget = control_flow_data->drawing->drawing_area;
1083 //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
1084 //draw_context_in->gc = widget->style->black_gc;
1085 //draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
1086 //gdk_gc_copy(draw_context_in->gc, widget->style->black_gc);
1087
1088 //draw_arc((void*)&prop_arc, (void*)draw_context_in);
1089 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
1090
1091 /* Draw the line/bg of the in process */
1092 if(draw_context_in->previous->middle->x == -1)
1093 {
1094 draw_context_in->previous->over->x =
1095 control_flow_data->drawing->damage_begin;
1096 draw_context_in->previous->middle->x =
1097 control_flow_data->drawing->damage_begin;
1098 draw_context_in->previous->under->x =
1099 control_flow_data->drawing->damage_begin;
1100
1101 g_debug("in middle x_beg : %u",control_flow_data->drawing->damage_begin);
1102
1103 }
1104
1105 draw_context_in->current->middle->x = x;
1106 draw_context_in->current->over->x = x;
1107 draw_context_in->current->under->x = x;
1108 draw_context_in->current->middle->y = y_in + height/2;
1109 draw_context_in->current->over->y = y_in;
1110 draw_context_in->current->under->y = y_in + height;
1111 draw_context_in->previous->middle->y = y_in + height/2;
1112 draw_context_in->previous->over->y = y_in;
1113 draw_context_in->previous->under->y = y_in + height;
1114
1115 draw_context_in->drawable = control_flow_data->drawing->pixmap;
1116 draw_context_in->pango_layout = control_flow_data->drawing->pango_layout;
1117
1118
1119 if(process_in->state->s == LTTV_STATE_RUN)
1120 {
1121 //draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
1122 //gdk_gc_copy(draw_context_in->gc, widget->style->black_gc);
1123 draw_context_in->gc = control_flow_data->drawing->gc;
1124
1125 PropertiesBG prop_bg;
1126 prop_bg.color = g_new(GdkColor,1);
1127
1128 switch(tfc->index) {
1129 case 0:
1130 prop_bg.color->red = 0x1515;
1131 prop_bg.color->green = 0x1515;
1132 prop_bg.color->blue = 0x8c8c;
1133 break;
1134 case 1:
1135 prop_bg.color->red = 0x4e4e;
1136 prop_bg.color->green = 0xa9a9;
1137 prop_bg.color->blue = 0xa4a4;
1138 break;
1139 case 2:
1140 prop_bg.color->red = 0x7a7a;
1141 prop_bg.color->green = 0x4a4a;
1142 prop_bg.color->blue = 0x8b8b;
1143 break;
1144 case 3:
1145 prop_bg.color->red = 0x8080;
1146 prop_bg.color->green = 0x7777;
1147 prop_bg.color->blue = 0x4747;
1148 break;
1149 default:
1150 prop_bg.color->red = 0xe7e7;
1151 prop_bg.color->green = 0xe7e7;
1152 prop_bg.color->blue = 0xe7e7;
1153 }
1154
1155
1156 draw_bg((void*)&prop_bg, (void*)draw_context_in);
1157 g_free(prop_bg.color);
1158 //gdk_gc_unref(draw_context_in->gc);
1159 }
1160
1161 draw_context_in->gc = widget->style->black_gc;
1162
1163 GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 };
1164 GdkColor colorbg_in = { 0, 0x0000, 0x0000, 0x0000 };
1165 PropertiesText prop_text_in;
1166 prop_text_in.foreground = &colorfg_in;
1167 prop_text_in.background = &colorbg_in;
1168 prop_text_in.size = 6;
1169 prop_text_in.position = OVER;
1170
1171 g_debug("in state : %s", g_quark_to_string(process_in->state->s));
1172 /* foreground of text : status of the process */
1173 if(process_in->state->s == LTTV_STATE_UNNAMED)
1174 {
1175 prop_text_in.foreground->red = 0xffff;
1176 prop_text_in.foreground->green = 0xffff;
1177 prop_text_in.foreground->blue = 0xffff;
1178 }
1179 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
1180 {
1181 prop_text_in.foreground->red = 0x0fff;
1182 prop_text_in.foreground->green = 0xffff;
1183 prop_text_in.foreground->blue = 0xfff0;
1184 }
1185 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
1186 {
1187 prop_text_in.foreground->red = 0xffff;
1188 prop_text_in.foreground->green = 0xffff;
1189 prop_text_in.foreground->blue = 0x0000;
1190 }
1191 else if(process_in->state->s == LTTV_STATE_ZOMBIE)
1192 {
1193 prop_text_in.foreground->red = 0xffff;
1194 prop_text_in.foreground->green = 0x0000;
1195 prop_text_in.foreground->blue = 0xffff;
1196 }
1197 else if(process_in->state->s == LTTV_STATE_WAIT)
1198 {
1199 prop_text_in.foreground->red = 0xffff;
1200 prop_text_in.foreground->green = 0x0000;
1201 prop_text_in.foreground->blue = 0x0000;
1202 }
1203 else if(process_in->state->s == LTTV_STATE_RUN)
1204 {
1205 prop_text_in.foreground->red = 0x0000;
1206 prop_text_in.foreground->green = 0xffff;
1207 prop_text_in.foreground->blue = 0x0000;
1208 }
1209 else
1210 {
1211 prop_text_in.foreground->red = 0xffff;
1212 prop_text_in.foreground->green = 0xffff;
1213 prop_text_in.foreground->blue = 0xffff;
1214 }
1215
1216
1217
1218 /* Print status of the process : U, WF, WC, E, W, R */
1219 if(process_in->state->s == LTTV_STATE_UNNAMED)
1220 prop_text_in.text = "U->";
1221 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
1222 prop_text_in.text = "WF->";
1223 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
1224 prop_text_in.text = "WC->";
1225 else if(process_in->state->s == LTTV_STATE_ZOMBIE)
1226 prop_text_in.text = "E->";
1227 else if(process_in->state->s == LTTV_STATE_WAIT)
1228 prop_text_in.text = "W->";
1229 else if(process_in->state->s == LTTV_STATE_RUN)
1230 prop_text_in.text = "R->";
1231 else
1232 prop_text_in.text = "U";
1233
1234 draw_text((void*)&prop_text_in, (void*)draw_context_in);
1235 //gdk_gc_unref(draw_context_in->gc);
1236
1237 //draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
1238 //gdk_gc_copy(draw_context_in->gc, widget->style->black_gc);
1239 draw_context_in->gc = control_flow_data->drawing->gc;
1240
1241 PropertiesLine prop_line_in;
1242 prop_line_in.color = g_new(GdkColor,1);
1243 prop_line_in.line_width = 2;
1244 prop_line_in.style = GDK_LINE_SOLID;
1245 prop_line_in.position = MIDDLE;
1246
1247 /* color of line : status of the process */
1248 if(process_in->state->s == LTTV_STATE_UNNAMED)
1249 {
1250 prop_line_in.color->red = 0xffff;
1251 prop_line_in.color->green = 0xffff;
1252 prop_line_in.color->blue = 0xffff;
1253 }
1254 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
1255 {
1256 prop_line_in.color->red = 0x0fff;
1257 prop_line_in.color->green = 0xffff;
1258 prop_line_in.color->blue = 0xfff0;
1259 }
1260 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
1261 {
1262 prop_line_in.color->red = 0xffff;
1263 prop_line_in.color->green = 0xffff;
1264 prop_line_in.color->blue = 0x0000;
1265 }
1266 else if(process_in->state->s == LTTV_STATE_ZOMBIE)
1267 {
1268 prop_line_in.color->red = 0xffff;
1269 prop_line_in.color->green = 0x0000;
1270 prop_line_in.color->blue = 0xffff;
1271 }
1272 else if(process_in->state->s == LTTV_STATE_WAIT)
1273 {
1274 prop_line_in.color->red = 0xffff;
1275 prop_line_in.color->green = 0x0000;
1276 prop_line_in.color->blue = 0x0000;
1277 }
1278 else if(process_in->state->s == LTTV_STATE_RUN)
1279 {
1280 prop_line_in.color->red = 0x0000;
1281 prop_line_in.color->green = 0xffff;
1282 prop_line_in.color->blue = 0x0000;
1283 }
1284 else
1285 {
1286 prop_line_in.color->red = 0xffff;
1287 prop_line_in.color->green = 0xffff;
1288 prop_line_in.color->blue = 0xffff;
1289 }
1290
1291 draw_line((void*)&prop_line_in, (void*)draw_context_in);
1292 g_free(prop_line_in.color);
1293 //gdk_gc_unref(draw_context_in->gc);
1294 }
1295
1296 return 0;
1297 #endif //0
1298
1299
1300
1301 /* Text dump */
1302 #ifdef DONTSHOW
1303 GString *string = g_string_new("");;
1304 gboolean field_names = TRUE, state = TRUE;
1305
1306 lttv_event_to_string(e, tfc->tf, string, TRUE, field_names, tfs);
1307 g_string_append_printf(string,"\n");
1308
1309 if(state) {
1310 g_string_append_printf(string, " %s",
1311 g_quark_to_string(tfs->process->state->s));
1312 }
1313
1314 g_info("%s",string->str);
1315
1316 g_string_free(string, TRUE);
1317
1318 /* End of text dump */
1319 #endif //DONTSHOW
1320
1321 }
1322
1323 /* after_schedchange_hook
1324 *
1325 * The draw after hook is called by the reading API to have a
1326 * particular event drawn on the screen.
1327 * @param hook_data ControlFlowData structure of the viewer.
1328 * @param call_data Event context.
1329 *
1330 * This function adds items to be drawn in a queue for each process.
1331 *
1332 */
1333 int after_schedchange_hook(void *hook_data, void *call_data)
1334 {
1335 EventsRequest *events_request = (EventsRequest*)hook_data;
1336 ControlFlowData *control_flow_data = events_request->viewer_data;
1337
1338 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
1339
1340 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
1341 LttvTraceState *ts =(LttvTraceState *)((LttvTracefileContext*)tfs)->t_context;
1342
1343 LttEvent *e;
1344 e = tfc->e;
1345
1346 LttTime evtime = ltt_event_time(e);
1347 TimeWindow time_window =
1348 lttvwindow_get_time_window(control_flow_data->tab);
1349
1350 #ifdef EXTRA_CHECK
1351 if(ltt_time_compare(evtime, time_window.start_time) == -1
1352 || ltt_time_compare(evtime, time_window.end_time) == 1)
1353 return;
1354 #endif //EXTRA_CHECK
1355
1356 guint width = control_flow_data->drawing->width;
1357
1358 /* Add process to process list (if not present) */
1359 LttvProcessState *process_out, *process_in;
1360 LttTime birth;
1361 guint y_in = 0, y_out = 0, height = 0, pl_height = 0;
1362 HashedProcessData *hashed_process_data_in = NULL;
1363
1364 ProcessList *process_list = control_flow_data->process_list;
1365
1366 guint pid_in;
1367 {
1368 guint pid_out;
1369 LttField *f = ltt_event_field(e);
1370 LttField *element;
1371 element = ltt_field_member(f,0);
1372 pid_out = ltt_event_get_long_unsigned(e,element);
1373 element = ltt_field_member(f,1);
1374 pid_in = ltt_event_get_long_unsigned(e,element);
1375 g_debug("out : %u in : %u", pid_out, pid_in);
1376 }
1377
1378
1379 /* Find process pid_in in the list... */
1380 process_in = lttv_state_find_process(tfs, pid_in);
1381 /* It should exist, because we are after the state update. */
1382 g_assert(process_in != NULL);
1383
1384 birth = process_in->creation_time;
1385 const gchar *name = g_quark_to_string(process_in->name);
1386
1387 if(processlist_get_process_pixels(process_list,
1388 pid_in,
1389 process_in->last_cpu,
1390 &birth,
1391 tfc->t_context->index,
1392 &y_in,
1393 &height,
1394 &hashed_process_data_in) == 1)
1395 {
1396 g_assert(pid_in == 0 || pid_in != process_in->ppid);
1397 ProcessInfo *process_info;
1398 /* Process not present */
1399 processlist_add(process_list,
1400 pid_in,
1401 process_in->last_cpu,
1402 process_in->ppid,
1403 &birth,
1404 tfc->t_context->index,
1405 name,
1406 &pl_height,
1407 &process_info,
1408 &hashed_process_data_in);
1409 processlist_get_pixels_from_data(process_list,
1410 process_info,
1411 hashed_process_data_in,
1412 &y_in,
1413 &height);
1414 drawing_insert_square( control_flow_data->drawing, y_in, height);
1415 }
1416
1417 if(ltt_time_compare(hashed_process_data_in->next_good_time,
1418 evtime) <= 0)
1419 {
1420 guint new_x;
1421
1422 convert_time_to_pixels(
1423 time_window,
1424 evtime,
1425 width,
1426 &new_x);
1427
1428 if(hashed_process_data_in->x.middle != new_x) {
1429 hashed_process_data_in->x.middle = new_x;
1430 hashed_process_data_in->x.middle_used = FALSE;
1431 hashed_process_data_in->x.middle_marked = FALSE;
1432 }
1433 }
1434 return 0;
1435
1436
1437
1438
1439
1440 #if 0
1441 EventsRequest *events_request = (EventsRequest*)hook_data;
1442 ControlFlowData *control_flow_data = events_request->viewer_data;
1443
1444 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
1445
1446 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
1447 LttvTraceState *ts =(LttvTraceState *)LTTV_TRACEFILE_CONTEXT(tfs)->t_context;
1448
1449
1450 LttEvent *e;
1451 e = tfc->e;
1452
1453 LttTime evtime = ltt_event_time(e);
1454 TimeWindow time_window =
1455 lttvwindow_get_time_window(control_flow_data->tab);
1456
1457 LttTime time_window.end_time = time_window.time_window.end_time;
1458
1459 //if(time < time_beg || time > time_end) return;
1460 if(ltt_time_compare(evtime, time_window.start_time) == -1
1461 || ltt_time_compare(evtime, time_window.end_time) == 1)
1462 return;
1463
1464
1465 if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0)
1466 {
1467 g_debug("schedchange!");
1468
1469 /* Add process to process list (if not present) and get drawing "y" from
1470 * process position */
1471 guint pid_out, pid_in;
1472 LttvProcessState *process_out, *process_in;
1473 LttTime birth;
1474 guint y_in = 0, y_out = 0, height = 0, pl_height = 0;
1475
1476 ProcessList *process_list = control_flow_data->process_list;
1477
1478
1479 LttField *f = ltt_event_field(e);
1480 LttField *element;
1481 element = ltt_field_member(f,0);
1482 pid_out = ltt_event_get_long_unsigned(e,element);
1483 element = ltt_field_member(f,1);
1484 pid_in = ltt_event_get_long_unsigned(e,element);
1485 //g_debug("out : %u in : %u", pid_out, pid_in);
1486
1487
1488 /* Find process pid_out in the list... */
1489 process_out = lttv_state_find_process(tfs, pid_out);
1490 if(process_out == NULL) return 0;
1491 //g_debug("out : %s",g_quark_to_string(process_out->state->s));
1492
1493 birth = process_out->creation_time;
1494 gchar *name = strdup(g_quark_to_string(process_out->name));
1495 HashedProcessData *hashed_process_data_out = NULL;
1496
1497 if(processlist_get_process_pixels(process_list,
1498 pid_out,
1499 &birth,
1500 tfc->t_context->index,
1501 &y_out,
1502 &height,
1503 &hashed_process_data_out) == 1)
1504 {
1505 /* Process not present */
1506 processlist_add(process_list,
1507 pid_out,
1508 &birth,
1509 tfc->t_context->index,
1510 name,
1511 &pl_height,
1512 &hashed_process_data_out);
1513 processlist_get_process_pixels(process_list,
1514 pid_out,
1515 &birth,
1516 tfc->t_context->index,
1517 &y_out,
1518 &height,
1519 &hashed_process_data_out);
1520 drawing_insert_square( control_flow_data->drawing, y_out, height);
1521 }
1522
1523 g_free(name);
1524
1525 /* Find process pid_in in the list... */
1526 process_in = lttv_state_find_process(tfs, pid_in);
1527 if(process_in == NULL) return 0;
1528 //g_debug("in : %s",g_quark_to_string(process_in->state->s));
1529
1530 birth = process_in->creation_time;
1531 name = strdup(g_quark_to_string(process_in->name));
1532 HashedProcessData *hashed_process_data_in = NULL;
1533
1534 if(processlist_get_process_pixels(process_list,
1535 pid_in,
1536 &birth,
1537 tfc->t_context->index,
1538 &y_in,
1539 &height,
1540 &hashed_process_data_in) == 1)
1541 {
1542 /* Process not present */
1543 processlist_add(process_list,
1544 pid_in,
1545 &birth,
1546 tfc->t_context->index,
1547 name,
1548 &pl_height,
1549 &hashed_process_data_in);
1550 processlist_get_process_pixels(process_list,
1551 pid_in,
1552 &birth,
1553 tfc->t_context->index,
1554 &y_in,
1555 &height,
1556 &hashed_process_data_in);
1557
1558 drawing_insert_square( control_flow_data->drawing, y_in, height);
1559 }
1560 g_free(name);
1561
1562
1563 /* Find pixels corresponding to time of the event. If the time does
1564 * not fit in the window, show a warning, not supposed to happend. */
1565 //guint x = 0;
1566 //guint width = control_flow_data->drawing->drawing_area->allocation.width;
1567
1568 //LttTime time = ltt_event_time(e);
1569
1570 //LttTime window_end = time_window->time_window.end_time;
1571
1572
1573 //convert_time_to_pixels(
1574 // *time_window,
1575 // time,
1576 // width,
1577 // &x);
1578
1579 //assert(x <= width);
1580
1581 /* draw what represents the event for outgoing process. */
1582
1583 DrawContext *draw_context_out = hashed_process_data_out->draw_context;
1584 //draw_context_out->current->modify_over->x = x;
1585 draw_context_out->current->modify_over->y = y_out;
1586 draw_context_out->current->modify_under->y = y_out+(height/2)+2;
1587 draw_context_out->drawable = control_flow_data->drawing->pixmap;
1588 draw_context_out->pango_layout = control_flow_data->drawing->pango_layout;
1589 GtkWidget *widget = control_flow_data->drawing->drawing_area;
1590 //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
1591
1592 //draw_arc((void*)&prop_arc, (void*)draw_context_out);
1593 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
1594
1595 /*if(process_out->state->s == LTTV_STATE_RUN)
1596 {
1597 draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
1598 gdk_gc_copy(draw_context_out->gc, widget->style->black_gc);
1599 PropertiesBG prop_bg;
1600 prop_bg.color = g_new(GdkColor,1);
1601
1602 prop_bg.color->red = 0xffff;
1603 prop_bg.color->green = 0xffff;
1604 prop_bg.color->blue = 0xffff;
1605
1606 draw_bg((void*)&prop_bg, (void*)draw_context_out);
1607 g_free(prop_bg.color);
1608 gdk_gc_unref(draw_context_out->gc);
1609 }*/
1610
1611 draw_context_out->gc = widget->style->black_gc;
1612
1613 GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 };
1614 GdkColor colorbg_out = { 0, 0x0000, 0x0000, 0x0000 };
1615 PropertiesText prop_text_out;
1616 prop_text_out.foreground = &colorfg_out;
1617 prop_text_out.background = &colorbg_out;
1618 prop_text_out.size = 6;
1619 prop_text_out.position = OVER;
1620
1621 /* color of text : status of the process */
1622 if(process_out->state->s == LTTV_STATE_UNNAMED)
1623 {
1624 prop_text_out.foreground->red = 0xffff;
1625 prop_text_out.foreground->green = 0xffff;
1626 prop_text_out.foreground->blue = 0xffff;
1627 }
1628 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
1629 {
1630 prop_text_out.foreground->red = 0x0fff;
1631 prop_text_out.foreground->green = 0xffff;
1632 prop_text_out.foreground->blue = 0xfff0;
1633 }
1634 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
1635 {
1636 prop_text_out.foreground->red = 0xffff;
1637 prop_text_out.foreground->green = 0xffff;
1638 prop_text_out.foreground->blue = 0x0000;
1639 }
1640 else if(process_out->state->s == LTTV_STATE_ZOMBIE)
1641 {
1642 prop_text_out.foreground->red = 0xffff;
1643 prop_text_out.foreground->green = 0x0000;
1644 prop_text_out.foreground->blue = 0xffff;
1645 }
1646 else if(process_out->state->s == LTTV_STATE_WAIT)
1647 {
1648 prop_text_out.foreground->red = 0xffff;
1649 prop_text_out.foreground->green = 0x0000;
1650 prop_text_out.foreground->blue = 0x0000;
1651 }
1652 else if(process_out->state->s == LTTV_STATE_RUN)
1653 {
1654 prop_text_out.foreground->red = 0x0000;
1655 prop_text_out.foreground->green = 0xffff;
1656 prop_text_out.foreground->blue = 0x0000;
1657 }
1658 else
1659 {
1660 prop_text_out.foreground->red = 0xffff;
1661 prop_text_out.foreground->green = 0xffff;
1662 prop_text_out.foreground->blue = 0xffff;
1663 }
1664
1665 /* Print status of the process : U, WF, WC, E, W, R */
1666 if(process_out->state->s == LTTV_STATE_UNNAMED)
1667 prop_text_out.text = "U";
1668 else if(process_out->state->s == LTTV_STATE_WAIT_FORK)
1669 prop_text_out.text = "WF";
1670 else if(process_out->state->s == LTTV_STATE_WAIT_CPU)
1671 prop_text_out.text = "WC";
1672 else if(process_out->state->s == LTTV_STATE_ZOMBIE)
1673 prop_text_out.text = "E";
1674 else if(process_out->state->s == LTTV_STATE_WAIT)
1675 prop_text_out.text = "W";
1676 else if(process_out->state->s == LTTV_STATE_RUN)
1677 prop_text_out.text = "R";
1678 else
1679 prop_text_out.text = "U";
1680
1681 draw_text((void*)&prop_text_out, (void*)draw_context_out);
1682
1683 //gdk_gc_unref(draw_context_out->gc);
1684
1685 draw_context_out->current->middle->y = y_out+height/2;
1686 draw_context_out->current->over->y = y_out;
1687 draw_context_out->current->under->y = y_out+height;
1688 draw_context_out->current->status = process_out->state->s;
1689
1690 /* for pid_out : remove previous, Prev = current, new current (default) */
1691 g_free(draw_context_out->previous->modify_under);
1692 g_free(draw_context_out->previous->modify_middle);
1693 g_free(draw_context_out->previous->modify_over);
1694 g_free(draw_context_out->previous->under);
1695 g_free(draw_context_out->previous->middle);
1696 g_free(draw_context_out->previous->over);
1697 g_free(draw_context_out->previous);
1698
1699 draw_context_out->previous = draw_context_out->current;
1700
1701 draw_context_out->current = g_new(DrawInfo,1);
1702 draw_context_out->current->over = g_new(ItemInfo,1);
1703 draw_context_out->current->over->x = -1;
1704 draw_context_out->current->over->y = -1;
1705 draw_context_out->current->middle = g_new(ItemInfo,1);
1706 draw_context_out->current->middle->x = -1;
1707 draw_context_out->current->middle->y = -1;
1708 draw_context_out->current->under = g_new(ItemInfo,1);
1709 draw_context_out->current->under->x = -1;
1710 draw_context_out->current->under->y = -1;
1711 draw_context_out->current->modify_over = g_new(ItemInfo,1);
1712 draw_context_out->current->modify_over->x = -1;
1713 draw_context_out->current->modify_over->y = -1;
1714 draw_context_out->current->modify_middle = g_new(ItemInfo,1);
1715 draw_context_out->current->modify_middle->x = -1;
1716 draw_context_out->current->modify_middle->y = -1;
1717 draw_context_out->current->modify_under = g_new(ItemInfo,1);
1718 draw_context_out->current->modify_under->x = -1;
1719 draw_context_out->current->modify_under->y = -1;
1720 draw_context_out->current->status = LTTV_STATE_UNNAMED;
1721
1722 /* Finally, update the drawing context of the pid_in. */
1723
1724 DrawContext *draw_context_in = hashed_process_data_in->draw_context;
1725 //draw_context_in->current->modify_over->x = x;
1726 draw_context_in->current->modify_over->y = y_in;
1727 draw_context_in->current->modify_under->y = y_in+(height/2)+2;
1728 draw_context_in->drawable = control_flow_data->drawing->pixmap;
1729 draw_context_in->pango_layout = control_flow_data->drawing->pango_layout;
1730 widget = control_flow_data->drawing->drawing_area;
1731 //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)];
1732
1733 //draw_arc((void*)&prop_arc, (void*)draw_context_in);
1734 //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap);
1735
1736 /*if(process_in->state->s == LTTV_STATE_RUN)
1737 {
1738 draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap);
1739 gdk_gc_copy(draw_context_in->gc, widget->style->black_gc);
1740 PropertiesBG prop_bg;
1741 prop_bg.color = g_new(GdkColor,1);
1742
1743 prop_bg.color->red = 0xffff;
1744 prop_bg.color->green = 0xffff;
1745 prop_bg.color->blue = 0xffff;
1746
1747 draw_bg((void*)&prop_bg, (void*)draw_context_in);
1748 g_free(prop_bg.color);
1749 gdk_gc_unref(draw_context_in->gc);
1750 }*/
1751
1752 draw_context_in->gc = widget->style->black_gc;
1753
1754 GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 };
1755 GdkColor colorbg_in = { 0, 0x0000, 0x0000, 0x0000 };
1756 PropertiesText prop_text_in;
1757 prop_text_in.foreground = &colorfg_in;
1758 prop_text_in.background = &colorbg_in;
1759 prop_text_in.size = 6;
1760 prop_text_in.position = OVER;
1761
1762 /* foreground of text : status of the process */
1763 if(process_in->state->s == LTTV_STATE_UNNAMED)
1764 {
1765 prop_text_in.foreground->red = 0xffff;
1766 prop_text_in.foreground->green = 0xffff;
1767 prop_text_in.foreground->blue = 0xffff;
1768 }
1769 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
1770 {
1771 prop_text_in.foreground->red = 0x0fff;
1772 prop_text_in.foreground->green = 0xffff;
1773 prop_text_in.foreground->blue = 0xfff0;
1774 }
1775 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
1776 {
1777 prop_text_in.foreground->red = 0xffff;
1778 prop_text_in.foreground->green = 0xffff;
1779 prop_text_in.foreground->blue = 0x0000;
1780 }
1781 else if(process_in->state->s == LTTV_STATE_ZOMBIE)
1782 {
1783 prop_text_in.foreground->red = 0xffff;
1784 prop_text_in.foreground->green = 0x0000;
1785 prop_text_in.foreground->blue = 0xffff;
1786 }
1787 else if(process_in->state->s == LTTV_STATE_WAIT)
1788 {
1789 prop_text_in.foreground->red = 0xffff;
1790 prop_text_in.foreground->green = 0x0000;
1791 prop_text_in.foreground->blue = 0x0000;
1792 }
1793 else if(process_in->state->s == LTTV_STATE_RUN)
1794 {
1795 prop_text_in.foreground->red = 0x0000;
1796 prop_text_in.foreground->green = 0xffff;
1797 prop_text_in.foreground->blue = 0x0000;
1798 }
1799 else
1800 {
1801 prop_text_in.foreground->red = 0xffff;
1802 prop_text_in.foreground->green = 0xffff;
1803 prop_text_in.foreground->blue = 0xffff;
1804 }
1805
1806
1807 /* Print status of the process : U, WF, WC, E, W, R */
1808 if(process_in->state->s == LTTV_STATE_UNNAMED)
1809 prop_text_in.text = "U";
1810 else if(process_in->state->s == LTTV_STATE_WAIT_FORK)
1811 prop_text_in.text = "WF";
1812 else if(process_in->state->s == LTTV_STATE_WAIT_CPU)
1813 prop_text_in.text = "WC";
1814 else if(process_in->state->s == LTTV_STATE_ZOMBIE)
1815 prop_text_in.text = "E";
1816 else if(process_in->state->s == LTTV_STATE_WAIT)
1817 prop_text_in.text = "W";
1818 else if(process_in->state->s == LTTV_STATE_RUN)
1819 prop_text_in.text = "R";
1820 else
1821 prop_text_in.text = "U";
1822
1823 draw_text((void*)&prop_text_in, (void*)draw_context_in);
1824
1825
1826 if(process_in->state->s == LTTV_STATE_RUN)
1827 {
1828 gchar tmp[255];
1829 prop_text_in.foreground = &colorfg_in;
1830 prop_text_in.background = &colorbg_in;
1831 prop_text_in.foreground->red = 0xffff;
1832 prop_text_in.foreground->green = 0xffff;
1833 prop_text_in.foreground->blue = 0xffff;
1834 prop_text_in.size = 6;
1835 prop_text_in.position = UNDER;
1836
1837 prop_text_in.text = g_new(gchar, 260);
1838 strcpy(prop_text_in.text, "CPU ");
1839 snprintf(tmp, 255, "%u", tfc->index);
1840 strcat(prop_text_in.text, tmp);
1841
1842 draw_text((void*)&prop_text_in, (void*)draw_context_in);
1843 g_free(prop_text_in.text);
1844 }
1845
1846
1847 draw_context_in->current->middle->y = y_in+height/2;
1848 draw_context_in->current->over->y = y_in;
1849 draw_context_in->current->under->y = y_in+height;
1850 draw_context_in->current->status = process_in->state->s;
1851
1852 /* for pid_in : remove previous, Prev = current, new current (default) */
1853 g_free(draw_context_in->previous->modify_under);
1854 g_free(draw_context_in->previous->modify_middle);
1855 g_free(draw_context_in->previous->modify_over);
1856 g_free(draw_context_in->previous->under);
1857 g_free(draw_context_in->previous->middle);
1858 g_free(draw_context_in->previous->over);
1859 g_free(draw_context_in->previous);
1860
1861 draw_context_in->previous = draw_context_in->current;
1862
1863 draw_context_in->current = g_new(DrawInfo,1);
1864 draw_context_in->current->over = g_new(ItemInfo,1);
1865 draw_context_in->current->over->x = -1;
1866 draw_context_in->current->over->y = -1;
1867 draw_context_in->current->middle = g_new(ItemInfo,1);
1868 draw_context_in->current->middle->x = -1;
1869 draw_context_in->current->middle->y = -1;
1870 draw_context_in->current->under = g_new(ItemInfo,1);
1871 draw_context_in->current->under->x = -1;
1872 draw_context_in->current->under->y = -1;
1873 draw_context_in->current->modify_over = g_new(ItemInfo,1);
1874 draw_context_in->current->modify_over->x = -1;
1875 draw_context_in->current->modify_over->y = -1;
1876 draw_context_in->current->modify_middle = g_new(ItemInfo,1);
1877 draw_context_in->current->modify_middle->x = -1;
1878 draw_context_in->current->modify_middle->y = -1;
1879 draw_context_in->current->modify_under = g_new(ItemInfo,1);
1880 draw_context_in->current->modify_under->x = -1;
1881 draw_context_in->current->modify_under->y = -1;
1882 draw_context_in->current->status = LTTV_STATE_UNNAMED;
1883
1884 }
1885
1886 return 0;
1887 #endif //0
1888 }
1889
1890 #if 0
1891 static __inline PropertiesLine prepare_execmode_line(LttvProcessState *process)
1892 {
1893 PropertiesLine prop_line;
1894 prop_line.line_width = 1;
1895 prop_line.style = GDK_LINE_SOLID;
1896 prop_line.y = OVER;
1897 //GdkColormap *colormap = gdk_colormap_get_system();
1898
1899 /* color of line : execution mode of the process */
1900 if(process->state->t == LTTV_STATE_USER_MODE)
1901 prop_line.color = drawing_colors[COL_USER_MODE];
1902 else if(process->state->t == LTTV_STATE_SYSCALL)
1903 prop_line.color = drawing_colors[COL_SYSCALL];
1904 else if(process->state->t == LTTV_STATE_TRAP)
1905 prop_line.color = drawing_colors[COL_TRAP];
1906 else if(process->state->t == LTTV_STATE_IRQ)
1907 prop_line.color = drawing_colors[COL_IRQ];
1908 else if(process->state->t == LTTV_STATE_MODE_UNKNOWN)
1909 prop_line.color = drawing_colors[COL_MODE_UNKNOWN];
1910 else
1911 prop_line.color = drawing_colors[COL_WHITE];
1912
1913 //gdk_colormap_alloc_color(colormap,
1914 // prop_line.color,
1915 // FALSE,
1916 // TRUE);
1917
1918 return prop_line;
1919
1920 }
1921 #endif //0
1922
1923
1924 /* before_execmode_hook
1925 *
1926 * This function basically draw lines and icons. Two types of lines are drawn :
1927 * one small (3 pixels?) representing the state of the process and the second
1928 * type is thicker (10 pixels?) representing on which CPU a process is running
1929 * (and this only in running state).
1930 *
1931 * Extremums of the lines :
1932 * x_min : time of the last event context for this process kept in memory.
1933 * x_max : time of the current event.
1934 * y : middle of the process in the process list. The process is found in the
1935 * list, therefore is it's position in pixels.
1936 *
1937 * The choice of lines'color is defined by the context of the last event for this
1938 * process.
1939 */
1940
1941
1942 int before_execmode_hook(void *hook_data, void *call_data)
1943 {
1944 EventsRequest *events_request = (EventsRequest*)hook_data;
1945 ControlFlowData *control_flow_data = events_request->viewer_data;
1946 Drawing_t *drawing = control_flow_data->drawing;
1947
1948 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
1949
1950 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
1951 LttvTraceState *ts =(LttvTraceState *)((LttvTracefileContext*)tfs)->t_context;
1952
1953 LttEvent *e;
1954 e = tfc->e;
1955
1956 LttTime evtime = ltt_event_time(e);
1957 TimeWindow time_window =
1958 lttvwindow_get_time_window(control_flow_data->tab);
1959
1960 #ifdef EXTRA_CHECK
1961 if(ltt_time_compare(evtime, time_window.start_time) == -1
1962 || ltt_time_compare(evtime, time_window.end_time) == 1)
1963 return;
1964 #endif //EXTRA_CHECK
1965
1966 guint width = drawing->width;
1967
1968 /* we are in a execmode, before the state update. We must draw the
1969 * items corresponding to the state before it changes : now is the right
1970 * time to do it.
1971 */
1972 /* For the pid */
1973 LttvProcessState *process = tfs->process;
1974 g_assert(process != NULL);
1975
1976 guint pid = process->pid;
1977
1978 /* Well, the process_out existed : we must get it in the process hash
1979 * or add it, and draw its items.
1980 */
1981 /* Add process to process list (if not present) */
1982 guint y = 0, height = 0, pl_height = 0;
1983 HashedProcessData *hashed_process_data = NULL;
1984 ProcessList *process_list = control_flow_data->process_list;
1985 LttTime birth = process->creation_time;
1986 const gchar *name = g_quark_to_string(process->name);
1987
1988 if(processlist_get_process_pixels(process_list,
1989 pid,
1990 process->last_cpu,
1991 &birth,
1992 tfc->t_context->index,
1993 &y,
1994 &height,
1995 &hashed_process_data) == 1)
1996 {
1997 g_assert(pid == 0 || pid != process->ppid);
1998 ProcessInfo *process_info;
1999 /* Process not present */
2000 processlist_add(process_list,
2001 pid,
2002 process->last_cpu,
2003 process->ppid,
2004 &birth,
2005 tfc->t_context->index,
2006 name,
2007 &pl_height,
2008 &process_info,
2009 &hashed_process_data);
2010 processlist_get_pixels_from_data(process_list,
2011 process_info,
2012 hashed_process_data,
2013 &y,
2014 &height);
2015 drawing_insert_square( drawing, y, height);
2016 }
2017
2018 /* Now, the process is in the state hash and our own process hash.
2019 * We definitely can draw the items related to the ending state.
2020 */
2021
2022 /* Check if the x position is unset. In can have been left unset by
2023 * a draw closure from a after chunk hook. This should never happen,
2024 * because it must be set by before chunk hook to the damage_begin
2025 * value.
2026 */
2027 g_assert(hashed_process_data->x.over != -1);
2028
2029 if(ltt_time_compare(hashed_process_data->next_good_time,
2030 evtime) > 0)
2031 {
2032 if(hashed_process_data->x.middle_marked == FALSE) {
2033 guint x;
2034 convert_time_to_pixels(
2035 time_window,
2036 evtime,
2037 width,
2038 &x);
2039
2040 /* Draw collision indicator */
2041 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
2042 gdk_draw_point(drawing->pixmap,
2043 drawing->gc,
2044 x,
2045 y+(height/2)-3);
2046 hashed_process_data->x.middle_marked = TRUE;
2047 }
2048 } else {
2049 guint x;
2050
2051 convert_time_to_pixels(
2052 time_window,
2053 evtime,
2054 width,
2055 &x);
2056
2057
2058 /* Jump over draw if we are at the same x position */
2059 if(x == hashed_process_data->x.middle &&
2060 hashed_process_data->x.middle_used)
2061 {
2062 if(hashed_process_data->x.middle_marked == FALSE) {
2063 /* Draw collision indicator */
2064 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
2065 gdk_draw_point(drawing->pixmap,
2066 drawing->gc,
2067 x,
2068 y+(height/2)-3);
2069 hashed_process_data->x.middle_marked = TRUE;
2070 }
2071 /* jump */
2072 } else {
2073
2074 DrawContext draw_context;
2075 /* Now create the drawing context that will be used to draw
2076 * items related to the last state. */
2077 draw_context.drawable = drawing->pixmap;
2078 draw_context.gc = drawing->gc;
2079 draw_context.pango_layout = drawing->pango_layout;
2080 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
2081 draw_context.drawinfo.end.x = x;
2082
2083 draw_context.drawinfo.y.over = y+1;
2084 draw_context.drawinfo.y.middle = y+(height/2);
2085 draw_context.drawinfo.y.under = y+height;
2086
2087 draw_context.drawinfo.start.offset.over = 0;
2088 draw_context.drawinfo.start.offset.middle = 0;
2089 draw_context.drawinfo.start.offset.under = 0;
2090 draw_context.drawinfo.end.offset.over = 0;
2091 draw_context.drawinfo.end.offset.middle = 0;
2092 draw_context.drawinfo.end.offset.under = 0;
2093
2094 {
2095 /* Draw the line */
2096 PropertiesLine prop_line = prepare_s_e_line(process);
2097 draw_line((void*)&prop_line, (void*)&draw_context);
2098
2099 }
2100 /* become the last x position */
2101 hashed_process_data->x.middle = x;
2102 hashed_process_data->x.middle_used = TRUE;
2103 hashed_process_data->x.middle_marked = FALSE;
2104
2105 /* Calculate the next good time */
2106 convert_pixels_to_time(width, x+1, time_window,
2107 &hashed_process_data->next_good_time);
2108 }
2109 }
2110
2111 return 0;
2112 }
2113
2114 /* after_execmode_hook
2115 *
2116 * The draw after hook is called by the reading API to have a
2117 * particular event drawn on the screen.
2118 * @param hook_data ControlFlowData structure of the viewer.
2119 * @param call_data Event context.
2120 *
2121 * This function adds items to be drawn in a queue for each process.
2122 *
2123 */
2124 int after_execmode_hook(void *hook_data, void *call_data)
2125 {
2126 EventsRequest *events_request = (EventsRequest*)hook_data;
2127 ControlFlowData *control_flow_data = events_request->viewer_data;
2128
2129 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
2130
2131 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
2132 LttvTraceState *ts =(LttvTraceState *)((LttvTracefileContext*)tfs)->t_context;
2133
2134 LttEvent *e;
2135 e = tfc->e;
2136
2137 LttTime evtime = ltt_event_time(e);
2138 TimeWindow time_window =
2139 lttvwindow_get_time_window(control_flow_data->tab);
2140
2141 #ifdef EXTRA_CHECK
2142 if(ltt_time_compare(evtime, time_window.start_time) == -1
2143 || ltt_time_compare(evtime, time_window.end_time) == 1)
2144 return;
2145 #endif //EXTRA_CHECK
2146
2147 guint width = control_flow_data->drawing->width;
2148
2149 /* Add process to process list (if not present) */
2150 LttvProcessState *process;
2151 LttTime birth;
2152 guint y = 0, height = 0, pl_height = 0;
2153 HashedProcessData *hashed_process_data = NULL;
2154
2155 ProcessList *process_list = control_flow_data->process_list;
2156
2157 /* Find process pid_in in the list... */
2158 process = tfs->process;
2159 /* It should exist, because we are after the state update. */
2160 g_assert(process != NULL);
2161
2162 guint pid = process->pid;
2163
2164 birth = process->creation_time;
2165 const gchar *name = g_quark_to_string(process->name);
2166
2167 if(processlist_get_process_pixels(process_list,
2168 pid,
2169 process->last_cpu,
2170 &birth,
2171 tfc->t_context->index,
2172 &y,
2173 &height,
2174 &hashed_process_data) == 1)
2175 {
2176 g_assert(pid == 0 || pid != process->ppid);
2177 /* Process not present */
2178 ProcessInfo *process_info;
2179 processlist_add(process_list,
2180 pid,
2181 process->last_cpu,
2182 process->ppid,
2183 &birth,
2184 tfc->t_context->index,
2185 name,
2186 &pl_height,
2187 &process_info,
2188 &hashed_process_data);
2189 processlist_get_pixels_from_data(process_list,
2190 process_info,
2191 hashed_process_data,
2192 &y,
2193 &height);
2194 drawing_insert_square( control_flow_data->drawing, y, height);
2195 }
2196
2197 if(ltt_time_compare(hashed_process_data->next_good_time,
2198 evtime) <= 0)
2199 {
2200 guint new_x;
2201
2202 convert_time_to_pixels(
2203 time_window,
2204 evtime,
2205 width,
2206 &new_x);
2207
2208 if(hashed_process_data->x.middle != new_x) {
2209 hashed_process_data->x.middle = new_x;
2210 hashed_process_data->x.middle_used = FALSE;
2211 hashed_process_data->x.middle_marked = FALSE;
2212 }
2213 }
2214 return 0;
2215 }
2216
2217
2218
2219 /* before_process_hook
2220 *
2221 * Draw lines for process event.
2222 *
2223 * @param hook_data ControlFlowData structure of the viewer.
2224 * @param call_data Event context.
2225 *
2226 * This function adds items to be drawn in a queue for each process.
2227 *
2228 */
2229 int before_process_hook(void *hook_data, void *call_data)
2230 {
2231 EventsRequest *events_request = (EventsRequest*)hook_data;
2232 ControlFlowData *control_flow_data = events_request->viewer_data;
2233 Drawing_t *drawing = control_flow_data->drawing;
2234
2235 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
2236
2237 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
2238 LttvTraceState *ts =(LttvTraceState *)((LttvTracefileContext*)tfs)->t_context;
2239
2240 LttEvent *e;
2241 e = tfc->e;
2242
2243 LttTime evtime = ltt_event_time(e);
2244 TimeWindow time_window =
2245 lttvwindow_get_time_window(control_flow_data->tab);
2246
2247 #ifdef EXTRA_CHECK
2248 if(ltt_time_compare(evtime, time_window.start_time) == -1
2249 || ltt_time_compare(evtime, time_window.end_time) == 1)
2250 return;
2251 #endif //EXTRA_CHECK
2252
2253 guint width = control_flow_data->drawing->width;
2254
2255 guint sub_id;
2256 {
2257 LttField *f = ltt_event_field(e);
2258 LttField *element;
2259 element = ltt_field_member(f,0);
2260 sub_id = ltt_event_get_long_unsigned(e,element);
2261 }
2262
2263 if(sub_id == 3) { /* exit */
2264
2265 /* Add process to process list (if not present) */
2266 LttvProcessState *process = tfs->process;
2267 guint pid = process->pid;
2268 LttTime birth;
2269 guint y = 0, height = 0, pl_height = 0;
2270 HashedProcessData *hashed_process_data = NULL;
2271
2272 ProcessList *process_list = control_flow_data->process_list;
2273
2274 g_assert(process != NULL);
2275
2276 birth = process->creation_time;
2277 const gchar *name = g_quark_to_string(process->name);
2278
2279 if(processlist_get_process_pixels(process_list,
2280 pid,
2281 process->last_cpu,
2282 &birth,
2283 tfc->t_context->index,
2284 &y,
2285 &height,
2286 &hashed_process_data) == 1)
2287 {
2288 g_assert(pid == 0 || pid != process->ppid);
2289 /* Process not present */
2290 ProcessInfo *process_info;
2291 processlist_add(process_list,
2292 pid,
2293 process->last_cpu,
2294 process->ppid,
2295 &birth,
2296 tfc->t_context->index,
2297 name,
2298 &pl_height,
2299 &process_info,
2300 &hashed_process_data);
2301 processlist_get_pixels_from_data(process_list,
2302 process_info,
2303 hashed_process_data,
2304 &y,
2305 &height);
2306 drawing_insert_square( control_flow_data->drawing, y, height);
2307 }
2308
2309 /* Now, the process is in the state hash and our own process hash.
2310 * We definitely can draw the items related to the ending state.
2311 */
2312
2313 /* Check if the x position is unset. In can have been left unset by
2314 * a draw closure from a after chunk hook. This should never happen,
2315 * because it must be set by before chunk hook to the damage_begin
2316 * value.
2317 */
2318 g_assert(hashed_process_data->x.over != -1);
2319
2320 if(ltt_time_compare(hashed_process_data->next_good_time,
2321 evtime) > 0)
2322 {
2323 if(hashed_process_data->x.middle_marked == FALSE) {
2324 guint x;
2325 convert_time_to_pixels(
2326 time_window,
2327 evtime,
2328 width,
2329 &x);
2330
2331 /* Draw collision indicator */
2332 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
2333 gdk_draw_point(drawing->pixmap,
2334 drawing->gc,
2335 x,
2336 y+(height/2)-3);
2337 hashed_process_data->x.middle_marked = TRUE;
2338 }
2339 } else {
2340 guint x;
2341
2342 convert_time_to_pixels(
2343 time_window,
2344 evtime,
2345 width,
2346 &x);
2347
2348
2349 /* Jump over draw if we are at the same x position */
2350 if(x == hashed_process_data->x.middle &&
2351 hashed_process_data->x.middle_used)
2352 {
2353 if(hashed_process_data->x.middle_marked == FALSE) {
2354 /* Draw collision indicator */
2355 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
2356 gdk_draw_point(drawing->pixmap,
2357 drawing->gc,
2358 x,
2359 y+(height/2)-3);
2360 hashed_process_data->x.middle_marked = TRUE;
2361 }
2362 /* jump */
2363 } else {
2364 DrawContext draw_context;
2365
2366 /* Now create the drawing context that will be used to draw
2367 * items related to the last state. */
2368 draw_context.drawable = drawing->pixmap;
2369 draw_context.gc = drawing->gc;
2370 draw_context.pango_layout = drawing->pango_layout;
2371 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
2372 draw_context.drawinfo.end.x = x;
2373
2374 draw_context.drawinfo.y.over = y+1;
2375 draw_context.drawinfo.y.middle = y+(height/2);
2376 draw_context.drawinfo.y.under = y+height;
2377
2378 draw_context.drawinfo.start.offset.over = 0;
2379 draw_context.drawinfo.start.offset.middle = 0;
2380 draw_context.drawinfo.start.offset.under = 0;
2381 draw_context.drawinfo.end.offset.over = 0;
2382 draw_context.drawinfo.end.offset.middle = 0;
2383 draw_context.drawinfo.end.offset.under = 0;
2384
2385 {
2386 /* Draw the line */
2387 PropertiesLine prop_line = prepare_s_e_line(process);
2388 draw_line((void*)&prop_line, (void*)&draw_context);
2389
2390 }
2391 /* become the last x position */
2392 hashed_process_data->x.middle = x;
2393 hashed_process_data->x.middle_used = TRUE;
2394 hashed_process_data->x.middle_marked = FALSE;
2395
2396 /* Calculate the next good time */
2397 convert_pixels_to_time(width, x+1, time_window,
2398 &hashed_process_data->next_good_time);
2399 }
2400 }
2401
2402 }
2403 return 0;
2404
2405 }
2406
2407
2408
2409
2410
2411
2412 /* after_process_hook
2413 *
2414 * Create the processlist entry for the child process. Put the last
2415 * position in x at the current time value.
2416 *
2417 * @param hook_data ControlFlowData structure of the viewer.
2418 * @param call_data Event context.
2419 *
2420 * This function adds items to be drawn in a queue for each process.
2421 *
2422 */
2423 int after_process_hook(void *hook_data, void *call_data)
2424 {
2425 EventsRequest *events_request = (EventsRequest*)hook_data;
2426 ControlFlowData *control_flow_data = events_request->viewer_data;
2427
2428 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
2429
2430 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
2431 LttvTraceState *ts =(LttvTraceState *)((LttvTracefileContext*)tfs)->t_context;
2432
2433 LttEvent *e;
2434 e = tfc->e;
2435
2436 LttTime evtime = ltt_event_time(e);
2437 TimeWindow time_window =
2438 lttvwindow_get_time_window(control_flow_data->tab);
2439
2440 #ifdef EXTRA_CHECK
2441 if(ltt_time_compare(evtime, time_window.start_time) == -1
2442 || ltt_time_compare(evtime, time_window.end_time) == 1)
2443 return;
2444 #endif //EXTRA_CHECK
2445
2446 guint width = control_flow_data->drawing->width;
2447
2448 guint sub_id;
2449 guint param1;
2450 {
2451 LttField *f = ltt_event_field(e);
2452 LttField *element;
2453 element = ltt_field_member(f,0);
2454 sub_id = ltt_event_get_long_unsigned(e,element);
2455 element = ltt_field_member(f,1);
2456 param1 = ltt_event_get_long_unsigned(e,element);
2457 }
2458
2459 if(sub_id == 2) { /* fork */
2460
2461 guint child_pid = param1;
2462 /* Add process to process list (if not present) */
2463 LttvProcessState *process_child;
2464 LttTime birth;
2465 guint y_child = 0, height = 0, pl_height = 0;
2466 HashedProcessData *hashed_process_data_child = NULL;
2467
2468 ProcessList *process_list = control_flow_data->process_list;
2469
2470 /* Find child in the list... */
2471 process_child = lttv_state_find_process(tfs, child_pid);
2472 /* It should exist, because we are after the state update. */
2473 g_assert(process_child != NULL);
2474
2475 birth = process_child->creation_time;
2476 const gchar *name = g_quark_to_string(process_child->name);
2477
2478 if(processlist_get_process_pixels(process_list,
2479 child_pid,
2480 process_child->last_cpu,
2481 &birth,
2482 tfc->t_context->index,
2483 &y_child,
2484 &height,
2485 &hashed_process_data_child) == 1)
2486 {
2487 g_assert(child_pid == 0 || child_pid != process_child->ppid);
2488 /* Process not present */
2489 ProcessInfo *process_info;
2490 processlist_add(process_list,
2491 child_pid,
2492 process_child->last_cpu,
2493 process_child->ppid,
2494 &birth,
2495 tfc->t_context->index,
2496 name,
2497 &pl_height,
2498 &process_info,
2499 &hashed_process_data_child);
2500 processlist_get_pixels_from_data(process_list,
2501 process_info,
2502 hashed_process_data_child,
2503 &y_child,
2504 &height);
2505 drawing_insert_square( control_flow_data->drawing, y_child, height);
2506 }
2507
2508 if(ltt_time_compare(hashed_process_data_child->next_good_time,
2509 evtime) <= 0)
2510 {
2511 guint new_x;
2512 convert_time_to_pixels(
2513 time_window,
2514 evtime,
2515 width,
2516 &new_x);
2517
2518 if(hashed_process_data_child->x.over != new_x) {
2519 hashed_process_data_child->x.over = new_x;
2520 hashed_process_data_child->x.over_used = FALSE;
2521 hashed_process_data_child->x.over_marked = FALSE;
2522 }
2523 if(hashed_process_data_child->x.middle != new_x) {
2524 hashed_process_data_child->x.middle = new_x;
2525 hashed_process_data_child->x.middle_used = FALSE;
2526 hashed_process_data_child->x.middle_marked = FALSE;
2527 }
2528 if(hashed_process_data_child->x.under != new_x) {
2529 hashed_process_data_child->x.under = new_x;
2530 hashed_process_data_child->x.under_used = FALSE;
2531 hashed_process_data_child->x.under_marked = FALSE;
2532 }
2533 }
2534
2535 } else if(sub_id == 3) { /* exit */
2536
2537 /* Add process to process list (if not present) */
2538 LttvProcessState *process = tfs->process;
2539 guint pid = process->pid;
2540 LttTime birth;
2541 guint y = 0, height = 0, pl_height = 0;
2542 HashedProcessData *hashed_process_data = NULL;
2543
2544 ProcessList *process_list = control_flow_data->process_list;
2545
2546 /* It should exist, because we are after the state update. */
2547 g_assert(process != NULL);
2548
2549 birth = process->creation_time;
2550 const gchar *name = g_quark_to_string(process->name);
2551
2552 if(processlist_get_process_pixels(process_list,
2553 pid,
2554 process->last_cpu,
2555 &birth,
2556 tfc->t_context->index,
2557 &y,
2558 &height,
2559 &hashed_process_data) == 1)
2560 {
2561 g_assert(pid == 0 || pid != process->ppid);
2562 /* Process not present */
2563 ProcessInfo *process_info;
2564 processlist_add(process_list,
2565 pid,
2566 process->last_cpu,
2567 process->ppid,
2568 &birth,
2569 tfc->t_context->index,
2570 name,
2571 &pl_height,
2572 &process_info,
2573 &hashed_process_data);
2574 processlist_get_pixels_from_data(process_list,
2575 process_info,
2576 hashed_process_data,
2577 &y,
2578 &height);
2579 drawing_insert_square( control_flow_data->drawing, y, height);
2580 }
2581
2582 if(ltt_time_compare(hashed_process_data->next_good_time,
2583 evtime) <= 0)
2584 {
2585 guint new_x;
2586 convert_time_to_pixels(
2587 time_window,
2588 evtime,
2589 width,
2590 &new_x);
2591 if(hashed_process_data->x.middle != new_x) {
2592 hashed_process_data->x.middle = new_x;
2593 hashed_process_data->x.middle_used = FALSE;
2594 hashed_process_data->x.middle_marked = FALSE;
2595 }
2596 }
2597
2598 }
2599 return 0;
2600
2601 }
2602
2603
2604 gint update_time_window_hook(void *hook_data, void *call_data)
2605 {
2606 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
2607 Drawing_t *drawing = control_flow_data->drawing;
2608
2609 const TimeWindowNotifyData *time_window_nofify_data =
2610 ((const TimeWindowNotifyData *)call_data);
2611
2612 TimeWindow *old_time_window =
2613 time_window_nofify_data->old_time_window;
2614 TimeWindow *new_time_window =
2615 time_window_nofify_data->new_time_window;
2616
2617 /* Update the ruler */
2618 drawing_update_ruler(control_flow_data->drawing,
2619 new_time_window);
2620
2621
2622 /* Two cases : zoom in/out or scrolling */
2623
2624 /* In order to make sure we can reuse the old drawing, the scale must
2625 * be the same and the new time interval being partly located in the
2626 * currently shown time interval. (reuse is only for scrolling)
2627 */
2628
2629 g_info("Old time window HOOK : %u, %u to %u, %u",
2630 old_time_window->start_time.tv_sec,
2631 old_time_window->start_time.tv_nsec,
2632 old_time_window->time_width.tv_sec,
2633 old_time_window->time_width.tv_nsec);
2634
2635 g_info("New time window HOOK : %u, %u to %u, %u",
2636 new_time_window->start_time.tv_sec,
2637 new_time_window->start_time.tv_nsec,
2638 new_time_window->time_width.tv_sec,
2639 new_time_window->time_width.tv_nsec);
2640
2641 if( new_time_window->time_width.tv_sec == old_time_window->time_width.tv_sec
2642 && new_time_window->time_width.tv_nsec == old_time_window->time_width.tv_nsec)
2643 {
2644 /* Same scale (scrolling) */
2645 g_info("scrolling");
2646 LttTime *ns = &new_time_window->start_time;
2647 LttTime *nw = &new_time_window->time_width;
2648 LttTime *os = &old_time_window->start_time;
2649 LttTime *ow = &old_time_window->time_width;
2650 LttTime old_end = old_time_window->end_time;
2651 LttTime new_end = new_time_window->end_time;
2652 //if(ns<os+w<ns+w)
2653 //if(ns<os+w && os+w<ns+w)
2654 //if(ns<old_end && os<ns)
2655 if(ltt_time_compare(*ns, old_end) == -1
2656 && ltt_time_compare(*os, *ns) == -1)
2657 {
2658 g_info("scrolling near right");
2659 /* Scroll right, keep right part of the screen */
2660 guint x = 0;
2661 guint width = control_flow_data->drawing->width;
2662 convert_time_to_pixels(
2663 *old_time_window,
2664 *ns,
2665 width,
2666 &x);
2667
2668 /* Copy old data to new location */
2669 gdk_draw_drawable (control_flow_data->drawing->pixmap,
2670 control_flow_data->drawing->drawing_area->style->black_gc,
2671 control_flow_data->drawing->pixmap,
2672 x, 0,
2673 0, 0,
2674 control_flow_data->drawing->width-x+SAFETY, -1);
2675
2676 if(drawing->damage_begin == drawing->damage_end)
2677 drawing->damage_begin = control_flow_data->drawing->width-x;
2678 else
2679 drawing->damage_begin = 0;
2680
2681 drawing->damage_end = control_flow_data->drawing->width;
2682
2683 /* Clear the data request background, but not SAFETY */
2684 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
2685 //control_flow_data->drawing->drawing_area->style->black_gc,
2686 control_flow_data->drawing->drawing_area->style->black_gc,
2687 TRUE,
2688 drawing->damage_begin+SAFETY, 0,
2689 drawing->damage_end - drawing->damage_begin, // do not overlap
2690 control_flow_data->drawing->height);
2691
2692 gtk_widget_queue_draw_area (drawing->drawing_area,
2693 0,0,
2694 control_flow_data->drawing->width,
2695 control_flow_data->drawing->height);
2696
2697 /* Get new data for the rest. */
2698 drawing_data_request(control_flow_data->drawing,
2699 &control_flow_data->drawing->pixmap,
2700 drawing->damage_begin, 0,
2701 drawing->damage_end - drawing->damage_begin,
2702 control_flow_data->drawing->height);
2703 } else {
2704 //if(ns<os<ns+w)
2705 //if(ns<os && os<ns+w)
2706 //if(ns<os && os<new_end)
2707 if(ltt_time_compare(*ns,*os) == -1
2708 && ltt_time_compare(*os,new_end) == -1)
2709 {
2710 g_info("scrolling near left");
2711 /* Scroll left, keep left part of the screen */
2712 guint x = 0;
2713 guint width = control_flow_data->drawing->width;
2714 convert_time_to_pixels(
2715 *new_time_window,
2716 *os,
2717 width,
2718 &x);
2719
2720
2721 /* Copy old data to new location */
2722 gdk_draw_drawable (control_flow_data->drawing->pixmap,
2723 control_flow_data->drawing->drawing_area->style->black_gc,
2724 control_flow_data->drawing->pixmap,
2725 0, 0,
2726 x, 0,
2727 -1, -1);
2728
2729 if(drawing->damage_begin == drawing->damage_end)
2730 drawing->damage_end = x;
2731 else
2732 drawing->damage_end =
2733 control_flow_data->drawing->width;
2734
2735 drawing->damage_begin = 0;
2736
2737 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
2738 control_flow_data->drawing->drawing_area->style->black_gc,
2739 TRUE,
2740 drawing->damage_begin, 0,
2741 drawing->damage_end - drawing->damage_begin, // do not overlap
2742 control_flow_data->drawing->height);
2743
2744 gtk_widget_queue_draw_area (drawing->drawing_area,
2745 0,0,
2746 control_flow_data->drawing->width,
2747 control_flow_data->drawing->height);
2748
2749
2750 /* Get new data for the rest. */
2751 drawing_data_request(control_flow_data->drawing,
2752 &control_flow_data->drawing->pixmap,
2753 drawing->damage_begin, 0,
2754 drawing->damage_end - drawing->damage_begin,
2755 control_flow_data->drawing->height);
2756
2757 } else {
2758 if(ltt_time_compare(*ns,*os) == 0)
2759 {
2760 g_info("not scrolling");
2761 } else {
2762 g_info("scrolling far");
2763 /* Cannot reuse any part of the screen : far jump */
2764
2765
2766 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
2767 control_flow_data->drawing->drawing_area->style->black_gc,
2768 TRUE,
2769 0, 0,
2770 control_flow_data->drawing->width+SAFETY, // do not overlap
2771 control_flow_data->drawing->height);
2772
2773 gtk_widget_queue_draw_area (drawing->drawing_area,
2774 0,0,
2775 control_flow_data->drawing->width,
2776 control_flow_data->drawing->height);
2777
2778 drawing->damage_begin = 0;
2779 drawing->damage_end = control_flow_data->drawing->width;
2780
2781 drawing_data_request(control_flow_data->drawing,
2782 &control_flow_data->drawing->pixmap,
2783 0, 0,
2784 control_flow_data->drawing->width,
2785 control_flow_data->drawing->height);
2786
2787 }
2788 }
2789 }
2790 } else {
2791 /* Different scale (zoom) */
2792 g_info("zoom");
2793
2794 gdk_draw_rectangle (control_flow_data->drawing->pixmap,
2795 control_flow_data->drawing->drawing_area->style->black_gc,
2796 TRUE,
2797 0, 0,
2798 control_flow_data->drawing->width+SAFETY, // do not overlap
2799 control_flow_data->drawing->height);
2800
2801 gtk_widget_queue_draw_area (drawing->drawing_area,
2802 0,0,
2803 control_flow_data->drawing->width,
2804 control_flow_data->drawing->height);
2805
2806 drawing->damage_begin = 0;
2807 drawing->damage_end = control_flow_data->drawing->width;
2808
2809 drawing_data_request(control_flow_data->drawing,
2810 &control_flow_data->drawing->pixmap,
2811 0, 0,
2812 control_flow_data->drawing->width,
2813 control_flow_data->drawing->height);
2814 }
2815
2816
2817
2818 return 0;
2819 }
2820
2821 gint traceset_notify(void *hook_data, void *call_data)
2822 {
2823 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
2824 Drawing_t *drawing = control_flow_data->drawing;
2825 GtkWidget *widget = drawing->drawing_area;
2826
2827
2828 drawing_clear(control_flow_data->drawing);
2829 processlist_clear(control_flow_data->process_list);
2830 redraw_notify(control_flow_data, NULL);
2831
2832 request_background_data(control_flow_data);
2833 #if 0
2834 drawing->damage_begin = 0;
2835 drawing->damage_end = drawing->width;
2836 if(drawing->damage_begin < drawing->damage_end)
2837 {
2838 drawing_data_request(drawing,
2839 &drawing->pixmap,
2840 drawing->damage_begin,
2841 0,
2842 drawing->damage_end-drawing->damage_begin,
2843 drawing->height);
2844 }
2845
2846 gtk_widget_queue_draw_area(drawing->drawing_area,
2847 0,0,
2848 drawing->width,
2849 drawing->height);
2850 #endif //0
2851
2852 return FALSE;
2853 }
2854
2855 gint redraw_notify(void *hook_data, void *call_data)
2856 {
2857 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
2858 Drawing_t *drawing = control_flow_data->drawing;
2859 GtkWidget *widget = drawing->drawing_area;
2860
2861 drawing->damage_begin = 0;
2862 drawing->damage_end = drawing->width;
2863
2864 /* fun feature, to be separated someday... */
2865 drawing_clear(control_flow_data->drawing);
2866 processlist_clear(control_flow_data->process_list);
2867
2868 // Clear the image
2869 gdk_draw_rectangle (drawing->pixmap,
2870 widget->style->black_gc,
2871 TRUE,
2872 0, 0,
2873 drawing->width+SAFETY,
2874 drawing->height);
2875
2876
2877 if(drawing->damage_begin < drawing->damage_end)
2878 {
2879 drawing_data_request(drawing,
2880 &drawing->pixmap,
2881 drawing->damage_begin,
2882 0,
2883 drawing->damage_end-drawing->damage_begin,
2884 drawing->height);
2885 }
2886
2887 gtk_widget_queue_draw_area(drawing->drawing_area,
2888 0,0,
2889 drawing->width,
2890 drawing->height);
2891 return FALSE;
2892
2893 }
2894
2895
2896 gint continue_notify(void *hook_data, void *call_data)
2897 {
2898 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
2899 Drawing_t *drawing = control_flow_data->drawing;
2900 GtkWidget *widget = drawing->drawing_area;
2901
2902 //g_assert(widget->allocation.width == drawing->damage_end);
2903
2904 if(drawing->damage_begin < drawing->damage_end)
2905 {
2906 drawing_data_request(drawing,
2907 &drawing->pixmap,
2908 drawing->damage_begin,
2909 0,
2910 drawing->damage_end-drawing->damage_begin,
2911 drawing->height);
2912 }
2913
2914 return FALSE;
2915 }
2916
2917
2918 gint update_current_time_hook(void *hook_data, void *call_data)
2919 {
2920 ControlFlowData *control_flow_data = (ControlFlowData*)hook_data;
2921 Drawing_t *drawing = control_flow_data->drawing;
2922
2923 LttTime current_time = *((LttTime*)call_data);
2924
2925 TimeWindow time_window =
2926 lttvwindow_get_time_window(control_flow_data->tab);
2927
2928 LttTime time_begin = time_window.start_time;
2929 LttTime width = time_window.time_width;
2930 LttTime half_width;
2931 {
2932 guint64 time_ll = ltt_time_to_uint64(width);
2933 time_ll = time_ll >> 1; /* divide by two */
2934 half_width = ltt_time_from_uint64(time_ll);
2935 }
2936 LttTime time_end = ltt_time_add(time_begin, width);
2937
2938 LttvTracesetContext * tsc =
2939 lttvwindow_get_traceset_context(control_flow_data->tab);
2940
2941 LttTime trace_start = tsc->time_span.start_time;
2942 LttTime trace_end = tsc->time_span.end_time;
2943
2944 g_info("New current time HOOK : %u, %u", current_time.tv_sec,
2945 current_time.tv_nsec);
2946
2947
2948
2949 /* If current time is inside time interval, just move the highlight
2950 * bar */
2951
2952 /* Else, we have to change the time interval. We have to tell it
2953 * to the main window. */
2954 /* The time interval change will take care of placing the current
2955 * time at the center of the visible area, or nearest possible if we are
2956 * at one end of the trace. */
2957
2958
2959 if(ltt_time_compare(current_time, time_begin) == -1)
2960 {
2961 TimeWindow new_time_window;
2962
2963 if(ltt_time_compare(current_time,
2964 ltt_time_add(trace_start,half_width)) == -1)
2965 time_begin = trace_start;
2966 else
2967 time_begin = ltt_time_sub(current_time,half_width);
2968
2969 new_time_window.start_time = time_begin;
2970 new_time_window.time_width = width;
2971 new_time_window.time_width_double = ltt_time_to_double(width);
2972 new_time_window.end_time = ltt_time_add(time_begin, width);
2973
2974 lttvwindow_report_time_window(control_flow_data->tab, new_time_window);
2975 }
2976 else if(ltt_time_compare(current_time, time_end) == 1)
2977 {
2978 TimeWindow new_time_window;
2979
2980 if(ltt_time_compare(current_time, ltt_time_sub(trace_end, half_width)) == 1)
2981 time_begin = ltt_time_sub(trace_end,width);
2982 else
2983 time_begin = ltt_time_sub(current_time,half_width);
2984
2985 new_time_window.start_time = time_begin;
2986 new_time_window.time_width = width;
2987 new_time_window.time_width_double = ltt_time_to_double(width);
2988 new_time_window.end_time = ltt_time_add(time_begin, width);
2989
2990 lttvwindow_report_time_window(control_flow_data->tab, new_time_window);
2991
2992 }
2993 //gtk_widget_queue_draw(control_flow_data->drawing->drawing_area);
2994 gtk_widget_queue_draw_area(drawing->drawing_area,
2995 0,0,
2996 drawing->width,
2997 drawing->height);
2998
2999 return 0;
3000 }
3001
3002 typedef struct _ClosureData {
3003 EventsRequest *events_request;
3004 LttvTracesetState *tss;
3005 LttTime end_time;
3006 } ClosureData;
3007
3008
3009 void draw_closure(gpointer key, gpointer value, gpointer user_data)
3010 {
3011 ProcessInfo *process_info = (ProcessInfo*)key;
3012 HashedProcessData *hashed_process_data = (HashedProcessData*)value;
3013 ClosureData *closure_data = (ClosureData*)user_data;
3014
3015 EventsRequest *events_request = closure_data->events_request;
3016 ControlFlowData *control_flow_data = events_request->viewer_data;
3017 Drawing_t *drawing = control_flow_data->drawing;
3018
3019 LttvTracesetState *tss = closure_data->tss;
3020 LttvTracesetContext *tsc = (LttvTracesetContext*)closure_data->tss;
3021
3022 LttTime evtime = closure_data->end_time;
3023 TimeWindow time_window =
3024 lttvwindow_get_time_window(control_flow_data->tab);
3025
3026 #ifdef EXTRA_CHECK
3027 if(ltt_time_compare(evtime, time_window.start_time) == -1
3028 || ltt_time_compare(evtime, time_window.end_time) == 1)
3029 return;
3030 #endif //EXTRA_CHECK
3031
3032 guint width = drawing->width;
3033
3034 {
3035 /* For the process */
3036 /* First, check if the current process is in the state computation
3037 * process list. If it is there, that means we must add it right now and
3038 * draw items from the beginning of the read for it. If it is not
3039 * present, it's a new process and it was not present : it will
3040 * be added after the state update. */
3041 g_assert(lttv_traceset_number(tsc->ts) > 0);
3042
3043 /* tracefiles[0] is ok here, because we draw for every PID, and
3044 * assume CPU 0 for PID 0 //FIXME */
3045 LttvTracefileState *tfs =
3046 (LttvTracefileState*)tsc->traces[process_info->trace_num]->tracefiles[0];
3047
3048 LttvProcessState *process;
3049 process = lttv_state_find_process(tfs,
3050 process_info->pid);
3051
3052 if(process != NULL) {
3053
3054 /* Only draw for processes that are currently in the trace states */
3055
3056 guint y = 0, height = 0, pl_height = 0;
3057 ProcessList *process_list = control_flow_data->process_list;
3058 LttTime birth = process_info->birth;
3059
3060 /* Should be alike when background info is ready */
3061 if(control_flow_data->background_info_waiting==0)
3062 g_assert(ltt_time_compare(process->creation_time,
3063 process_info->birth) == 0);
3064 const gchar *name = g_quark_to_string(process->name);
3065
3066 /* process HAS to be present */
3067 processlist_get_pixels_from_data(process_list,
3068 process_info,
3069 hashed_process_data,
3070 &y,
3071 &height);
3072
3073 /* Now, the process is in the state hash and our own process hash.
3074 * We definitely can draw the items related to the ending state.
3075 */
3076
3077 /* Check if the x position is unset. In can have been left unset by
3078 * a draw closure from a after chunk hook. This should never happen,
3079 * because it must be set by before chunk hook to the damage_begin
3080 * value.
3081 */
3082 g_assert(hashed_process_data->x.over != -1);
3083
3084 if(ltt_time_compare(hashed_process_data->next_good_time,
3085 evtime) <= 0)
3086 {
3087 guint x;
3088
3089 convert_time_to_pixels(
3090 time_window,
3091 evtime,
3092 width,
3093 &x);
3094
3095 DrawContext draw_context;
3096
3097 /* Now create the drawing context that will be used to draw
3098 * items related to the last state. */
3099 draw_context.drawable = drawing->pixmap;
3100 draw_context.gc = drawing->gc;
3101 draw_context.pango_layout = drawing->pango_layout;
3102 draw_context.drawinfo.end.x = x;
3103
3104 draw_context.drawinfo.y.over = y+1;
3105 draw_context.drawinfo.y.middle = y+(height/2);
3106 draw_context.drawinfo.y.under = y+height;
3107
3108 draw_context.drawinfo.start.offset.over = 0;
3109 draw_context.drawinfo.start.offset.middle = 0;
3110 draw_context.drawinfo.start.offset.under = 0;
3111 draw_context.drawinfo.end.offset.over = 0;
3112 draw_context.drawinfo.end.offset.middle = 0;
3113 draw_context.drawinfo.end.offset.under = 0;
3114 #if 0
3115 /* Jump over draw if we are at the same x position */
3116 if(x == hashed_process_data->x.over)
3117 {
3118 /* jump */
3119 } else {
3120 draw_context.drawinfo.start.x = hashed_process_data->x.over;
3121 /* Draw the line */
3122 PropertiesLine prop_line = prepare_execmode_line(process);
3123 draw_line((void*)&prop_line, (void*)&draw_context);
3124
3125 hashed_process_data->x.over = x;
3126 }
3127 #endif //0
3128
3129 if(x == hashed_process_data->x.middle &&
3130 hashed_process_data->x.middle_used) {
3131 #if 0 /* do not mark closure : not missing information */
3132 if(hashed_process_data->x.middle_marked == FALSE) {
3133 /* Draw collision indicator */
3134 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
3135 gdk_draw_point(drawing->pixmap,
3136 drawing->gc,
3137 x,
3138 y+(height/2)-3);
3139 hashed_process_data->x.middle_marked = TRUE;
3140 }
3141 #endif //0
3142 /* Jump */
3143 } else {
3144 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
3145 /* Draw the line */
3146 PropertiesLine prop_line = prepare_s_e_line(process);
3147 draw_line((void*)&prop_line, (void*)&draw_context);
3148
3149 /* become the last x position */
3150 if(x != hashed_process_data->x.middle) {
3151 hashed_process_data->x.middle = x;
3152 /* but don't use the pixel */
3153 hashed_process_data->x.middle_used = FALSE;
3154
3155 /* Calculate the next good time */
3156 convert_pixels_to_time(width, x+1, time_window,
3157 &hashed_process_data->next_good_time);
3158 }
3159 }
3160 }
3161 }
3162 }
3163 return;
3164 }
3165
3166 int before_chunk(void *hook_data, void *call_data)
3167 {
3168 EventsRequest *events_request = (EventsRequest*)hook_data;
3169 LttvTracesetState *tss = (LttvTracesetState*)call_data;
3170
3171 drawing_chunk_begin(events_request, tss);
3172
3173 return 0;
3174 }
3175
3176 int before_request(void *hook_data, void *call_data)
3177 {
3178 EventsRequest *events_request = (EventsRequest*)hook_data;
3179 LttvTracesetState *tss = (LttvTracesetState*)call_data;
3180
3181 drawing_data_request_begin(events_request, tss);
3182
3183 return 0;
3184 }
3185
3186
3187 /*
3188 * after request is necessary in addition of after chunk in order to draw
3189 * lines until the end of the screen. after chunk just draws lines until
3190 * the last event.
3191 *
3192 * for each process
3193 * draw closing line
3194 * expose
3195 */
3196 int after_request(void *hook_data, void *call_data)
3197 {
3198 EventsRequest *events_request = (EventsRequest*)hook_data;
3199 ControlFlowData *control_flow_data = events_request->viewer_data;
3200 LttvTracesetState *tss = (LttvTracesetState*)call_data;
3201 LttvTracesetContext *tsc = (LttvTracesetContext*)call_data;
3202
3203 ProcessList *process_list = control_flow_data->process_list;
3204 LttTime end_time = events_request->end_time;
3205
3206 ClosureData closure_data;
3207 closure_data.events_request = (EventsRequest*)hook_data;
3208 closure_data.tss = tss;
3209 closure_data.end_time = end_time;
3210
3211 /* Draw last items */
3212 g_hash_table_foreach(process_list->process_hash, draw_closure,
3213 (void*)&closure_data);
3214
3215 /* Request expose */
3216 drawing_request_expose(events_request, tss, end_time);
3217 return 0;
3218 }
3219
3220 /*
3221 * for each process
3222 * draw closing line
3223 * expose
3224 */
3225 int after_chunk(void *hook_data, void *call_data)
3226 {
3227 EventsRequest *events_request = (EventsRequest*)hook_data;
3228 ControlFlowData *control_flow_data = events_request->viewer_data;
3229 LttvTracesetState *tss = (LttvTracesetState*)call_data;
3230 LttvTracesetContext *tsc = (LttvTracesetContext*)call_data;
3231 LttvTracefileContext *tfc = lttv_traceset_context_get_current_tfc(tsc);
3232 LttTime end_time;
3233
3234 ProcessList *process_list = control_flow_data->process_list;
3235
3236 if(tfc != NULL)
3237 end_time = LTT_TIME_MIN(tfc->timestamp, events_request->end_time);
3238 else /* end of traceset, or position now out of request : end */
3239 end_time = events_request->end_time;
3240
3241 ClosureData closure_data;
3242 closure_data.events_request = (EventsRequest*)hook_data;
3243 closure_data.tss = tss;
3244 closure_data.end_time = end_time;
3245
3246 /* Draw last items */
3247 g_hash_table_foreach(process_list->process_hash, draw_closure,
3248 (void*)&closure_data);
3249
3250 /* Request expose */
3251 drawing_request_expose(events_request, tss, end_time);
3252
3253 return 0;
3254 }
3255
This page took 0.095907 seconds and 5 git commands to generate.