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