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