fix seek so that adding and removing a trace from a traceset will work
[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#ifdef HAVE_CONFIG_H
49#include <config.h>
50#endif
51
52//#define PANGO_ENABLE_BACKEND
53#include <gtk/gtk.h>
54#include <gdk/gdk.h>
55#include <glib.h>
56#include <assert.h>
57#include <string.h>
58#include <stdio.h>
59
60//#include <pango/pango.h>
61
62#include <ltt/event.h>
63#include <ltt/time.h>
64#include <ltt/type.h>
65#include <ltt/trace.h>
66
67#include <lttv/lttv.h>
68#include <lttv/hook.h>
69#include <lttv/state.h>
70#include <lttvwindow/lttvwindow.h>
71#include <lttvwindow/lttvwindowtraces.h>
72#include <lttvwindow/support.h>
73
74
75#include "eventhooks.h"
76#include "cfv.h"
77#include "processlist.h"
78#include "drawing.h"
79
80
81#define MAX_PATH_LEN 256
82
83extern GSList *g_legend_list;
84
85
86/* Action to do when background computation completed.
87 *
88 * Wait for all the awaited computations to be over.
89 */
90
91gint background_ready(void *hook_data, void *call_data)
92{
93 ControlFlowData *control_flow_data = (ControlFlowData *)hook_data;
94 LttvTrace *trace = (LttvTrace*)call_data;
95
96 control_flow_data->background_info_waiting--;
97
98 if(control_flow_data->background_info_waiting == 0) {
99 g_message("control flow viewer : background computation data ready.");
100
101 drawing_clear(control_flow_data->drawing);
102 processlist_clear(control_flow_data->process_list);
103 gtk_widget_set_size_request(
104 control_flow_data->drawing->drawing_area,
105 -1, processlist_get_height(control_flow_data->process_list));
106 redraw_notify(control_flow_data, NULL);
107 }
108
109 return 0;
110}
111
112
113/* Request background computation. Verify if it is in progress or ready first.
114 * Only for each trace in the tab's traceset.
115 */
116void request_background_data(ControlFlowData *control_flow_data)
117{
118 LttvTracesetContext * tsc =
119 lttvwindow_get_traceset_context(control_flow_data->tab);
120 gint num_traces = lttv_traceset_number(tsc->ts);
121 gint i;
122 LttvTrace *trace;
123
124 LttvHooks *background_ready_hook =
125 lttv_hooks_new();
126 lttv_hooks_add(background_ready_hook, background_ready, control_flow_data,
127 LTTV_PRIO_DEFAULT);
128 control_flow_data->background_info_waiting = 0;
129
130 for(i=0;i<num_traces;i++) {
131 trace = lttv_traceset_get(tsc->ts, i);
132
133 if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace)==FALSE) {
134
135 if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"),
136 trace) == FALSE) {
137 /* We first remove requests that could have been done for the same
138 * information. Happens when two viewers ask for it before servicing
139 * starts.
140 */
141 lttvwindowtraces_background_request_remove(trace, "state");
142 lttvwindowtraces_background_request_queue(trace,
143 "state");
144 lttvwindowtraces_background_notify_queue(control_flow_data,
145 trace,
146 ltt_time_infinite,
147 NULL,
148 background_ready_hook);
149 control_flow_data->background_info_waiting++;
150 } else { /* in progress */
151
152 lttvwindowtraces_background_notify_current(control_flow_data,
153 trace,
154 ltt_time_infinite,
155 NULL,
156 background_ready_hook);
157 control_flow_data->background_info_waiting++;
158 }
159 } else {
160 /* Data ready. Be its nature, this viewer doesn't need to have
161 * its data ready hook called htere, because a background
162 * request is always linked with a redraw.
163 */
164 }
165
166 }
167
168 lttv_hooks_destroy(background_ready_hook);
169}
170
171
172
173
174/**
175 * Event Viewer's constructor hook
176 *
177 * This constructor is given as a parameter to the menuitem and toolbar button
178 * registration. It creates the list.
179 * @param tab A pointer to the parent tab.
180 * @return The widget created.
181 */
182GtkWidget *
183h_guicontrolflow(Tab *tab)
184{
185 g_info("h_guicontrolflow, %p", tab);
186 ControlFlowData *control_flow_data = guicontrolflow() ;
187
188 control_flow_data->tab = tab;
189
190 // Unreg done in the GuiControlFlow_Destructor
191 lttvwindow_register_traceset_notify(tab,
192 traceset_notify,
193 control_flow_data);
194
195 lttvwindow_register_time_window_notify(tab,
196 update_time_window_hook,
197 control_flow_data);
198 lttvwindow_register_current_time_notify(tab,
199 update_current_time_hook,
200 control_flow_data);
201 lttvwindow_register_redraw_notify(tab,
202 redraw_notify,
203 control_flow_data);
204 lttvwindow_register_continue_notify(tab,
205 continue_notify,
206 control_flow_data);
207 request_background_data(control_flow_data);
208
209
210 return guicontrolflow_get_widget(control_flow_data) ;
211
212}
213
214void legend_destructor(GtkWindow *legend)
215{
216 g_legend_list = g_slist_remove(g_legend_list, legend);
217}
218
219/* Create a popup legend */
220GtkWidget *
221h_legend(Tab *tab)
222{
223 g_info("h_legend, %p", tab);
224
225 GtkWindow *legend = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
226
227 g_legend_list = g_slist_append(
228 g_legend_list,
229 legend);
230
231 g_object_set_data_full(
232 G_OBJECT(legend),
233 "legend",
234 legend,
235 (GDestroyNotify)legend_destructor);
236
237 gtk_window_set_title(legend, "Control Flow View Legend");
238
239 GtkWidget *pixmap = create_pixmap(GTK_WIDGET(legend), "lttv-color-list.png");
240
241 // GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixmap(
242 // GDK_PIXMAP(pixmap), NULL));
243
244 gtk_container_add(GTK_CONTAINER(legend), GTK_WIDGET(pixmap));
245
246 gtk_widget_show(GTK_WIDGET(pixmap));
247 gtk_widget_show(GTK_WIDGET(legend));
248
249
250 return NULL; /* This is a popup window */
251}
252
253
254int event_selected_hook(void *hook_data, void *call_data)
255{
256 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
257 guint *event_number = (guint*) call_data;
258
259 g_debug("DEBUG : event selected by main window : %u", *event_number);
260
261 return 0;
262}
263
264/* Function that selects the color of status&exemode line */
265static inline PropertiesLine prepare_s_e_line(LttvProcessState *process)
266{
267 PropertiesLine prop_line;
268 prop_line.line_width = 2;
269 prop_line.style = GDK_LINE_SOLID;
270 prop_line.y = MIDDLE;
271 //GdkColormap *colormap = gdk_colormap_get_system();
272
273 if(process->state->s == LTTV_STATE_RUN) {
274 if(process->state->t == LTTV_STATE_USER_MODE)
275 prop_line.color = drawing_colors[COL_RUN_USER_MODE];
276 else if(process->state->t == LTTV_STATE_SYSCALL)
277 prop_line.color = drawing_colors[COL_RUN_SYSCALL];
278 else if(process->state->t == LTTV_STATE_TRAP)
279 prop_line.color = drawing_colors[COL_RUN_TRAP];
280 else if(process->state->t == LTTV_STATE_IRQ)
281 prop_line.color = drawing_colors[COL_RUN_IRQ];
282 else if(process->state->t == LTTV_STATE_MODE_UNKNOWN)
283 prop_line.color = drawing_colors[COL_MODE_UNKNOWN];
284 else
285 g_assert(FALSE); /* RUNNING MODE UNKNOWN */
286 } else if(process->state->s == LTTV_STATE_WAIT) {
287 /* We don't show if we wait while in user mode, trap, irq or syscall */
288 prop_line.color = drawing_colors[COL_WAIT];
289 } else if(process->state->s == LTTV_STATE_WAIT_CPU) {
290 /* We don't show if we wait for CPU while in user mode, trap, irq
291 * or syscall */
292 prop_line.color = drawing_colors[COL_WAIT_CPU];
293 } else if(process->state->s == LTTV_STATE_ZOMBIE) {
294 prop_line.color = drawing_colors[COL_ZOMBIE];
295 } else if(process->state->s == LTTV_STATE_WAIT_FORK) {
296 prop_line.color = drawing_colors[COL_WAIT_FORK];
297 } else if(process->state->s == LTTV_STATE_EXIT) {
298 prop_line.color = drawing_colors[COL_EXIT];
299 } else if(process->state->s == LTTV_STATE_UNNAMED) {
300 prop_line.color = drawing_colors[COL_UNNAMED];
301 } else
302 g_assert(FALSE); /* UNKNOWN STATE */
303
304 return prop_line;
305
306}
307
308
309/* before_schedchange_hook
310 *
311 * This function basically draw lines and icons. Two types of lines are drawn :
312 * one small (3 pixels?) representing the state of the process and the second
313 * type is thicker (10 pixels?) representing on which CPU a process is running
314 * (and this only in running state).
315 *
316 * Extremums of the lines :
317 * x_min : time of the last event context for this process kept in memory.
318 * x_max : time of the current event.
319 * y : middle of the process in the process list. The process is found in the
320 * list, therefore is it's position in pixels.
321 *
322 * The choice of lines'color is defined by the context of the last event for this
323 * process.
324 */
325
326
327int before_schedchange_hook(void *hook_data, void *call_data)
328{
329 LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data;
330 EventsRequest *events_request = (EventsRequest*)thf->hook_data;
331 ControlFlowData *control_flow_data = events_request->viewer_data;
332
333 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
334
335 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
336 LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
337
338 LttEvent *e;
339 e = ltt_tracefile_get_event(tfc->tf);
340
341 LttTime evtime = ltt_event_time(e);
342
343 /* we are in a schedchange, before the state update. We must draw the
344 * items corresponding to the state before it changes : now is the right
345 * time to do it.
346 */
347
348 guint pid_out;
349 guint pid_in;
350 {
351 pid_out = ltt_event_get_long_unsigned(e, thf->f1);
352 pid_in = ltt_event_get_long_unsigned(e, thf->f2);
353 }
354
355 {
356 /* For the pid_out */
357 /* First, check if the current process is in the state computation
358 * process list. If it is there, that means we must add it right now and
359 * draw items from the beginning of the read for it. If it is not
360 * present, it's a new process and it was not present : it will
361 * be added after the state update. */
362 guint cpu = ltt_tracefile_num(tfc->tf);
363 LttvProcessState *process = ts->running_process[cpu];
364 /* unknown state, bad current pid */
365 if(process->pid != pid_out)
366 process = lttv_state_find_process(ts,
367 ltt_tracefile_num(tfc->tf), pid_out);
368
369 if(process != NULL) {
370 /* Well, the process_out existed : we must get it in the process hash
371 * or add it, and draw its items.
372 */
373 /* Add process to process list (if not present) */
374 guint pl_height = 0;
375 HashedProcessData *hashed_process_data = NULL;
376 ProcessList *process_list = control_flow_data->process_list;
377 LttTime birth = process->creation_time;
378
379 hashed_process_data = processlist_get_process_data(process_list,
380 pid_out,
381 process->cpu,
382 &birth,
383 tfc->t_context->index);
384 if(hashed_process_data == NULL)
385 {
386 g_assert(pid_out == 0 || pid_out != process->ppid);
387 /* Process not present */
388 ProcessInfo *process_info;
389 Drawing_t *drawing = control_flow_data->drawing;
390 processlist_add(process_list,
391 drawing,
392 pid_out,
393 process->cpu,
394 process->ppid,
395 &birth,
396 tfc->t_context->index,
397 process->name,
398 &pl_height,
399 &process_info,
400 &hashed_process_data);
401 gtk_widget_set_size_request(drawing->drawing_area,
402 -1,
403 pl_height);
404 gtk_widget_queue_draw(drawing->drawing_area);
405
406 }
407
408 /* Now, the process is in the state hash and our own process hash.
409 * We definitely can draw the items related to the ending state.
410 */
411
412 if(ltt_time_compare(hashed_process_data->next_good_time,
413 evtime) > 0)
414 {
415 if(hashed_process_data->x.middle_marked == FALSE) {
416
417 TimeWindow time_window =
418 lttvwindow_get_time_window(control_flow_data->tab);
419#ifdef EXTRA_CHECK
420 if(ltt_time_compare(evtime, time_window.start_time) == -1
421 || ltt_time_compare(evtime, time_window.end_time) == 1)
422 return;
423#endif //EXTRA_CHECK
424 Drawing_t *drawing = control_flow_data->drawing;
425 guint width = drawing->width;
426 guint x;
427 convert_time_to_pixels(
428 time_window,
429 evtime,
430 width,
431 &x);
432
433 /* Draw collision indicator */
434 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
435 gdk_draw_point(hashed_process_data->pixmap,
436 drawing->gc,
437 x,
438 (hashed_process_data->height/2)-3);
439 hashed_process_data->x.middle_marked = TRUE;
440 }
441 } else {
442 TimeWindow time_window =
443 lttvwindow_get_time_window(control_flow_data->tab);
444#ifdef EXTRA_CHECK
445 if(ltt_time_compare(evtime, time_window.start_time) == -1
446 || ltt_time_compare(evtime, time_window.end_time) == 1)
447 return;
448#endif //EXTRA_CHECK
449 Drawing_t *drawing = control_flow_data->drawing;
450 guint width = drawing->width;
451 guint x;
452 convert_time_to_pixels(
453 time_window,
454 evtime,
455 width,
456 &x);
457
458
459 /* Jump over draw if we are at the same x position */
460 if(x == hashed_process_data->x.middle &&
461 hashed_process_data->x.middle_used)
462 {
463 if(hashed_process_data->x.middle_marked == FALSE) {
464 /* Draw collision indicator */
465 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
466 gdk_draw_point(hashed_process_data->pixmap,
467 drawing->gc,
468 x,
469 (hashed_process_data->height/2)-3);
470 hashed_process_data->x.middle_marked = TRUE;
471 }
472 /* jump */
473 } else {
474 DrawContext draw_context;
475
476 /* Now create the drawing context that will be used to draw
477 * items related to the last state. */
478 draw_context.drawable = hashed_process_data->pixmap;
479 draw_context.gc = drawing->gc;
480 draw_context.pango_layout = drawing->pango_layout;
481 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
482 draw_context.drawinfo.end.x = x;
483
484 draw_context.drawinfo.y.over = 1;
485 draw_context.drawinfo.y.middle = (hashed_process_data->height/2);
486 draw_context.drawinfo.y.under = hashed_process_data->height;
487
488 draw_context.drawinfo.start.offset.over = 0;
489 draw_context.drawinfo.start.offset.middle = 0;
490 draw_context.drawinfo.start.offset.under = 0;
491 draw_context.drawinfo.end.offset.over = 0;
492 draw_context.drawinfo.end.offset.middle = 0;
493 draw_context.drawinfo.end.offset.under = 0;
494
495 {
496 /* Draw the line */
497 PropertiesLine prop_line = prepare_s_e_line(process);
498 draw_line((void*)&prop_line, (void*)&draw_context);
499
500 }
501 /* become the last x position */
502 hashed_process_data->x.middle = x;
503 hashed_process_data->x.middle_used = TRUE;
504 hashed_process_data->x.middle_marked = FALSE;
505
506 /* Calculate the next good time */
507 convert_pixels_to_time(width, x+1, time_window,
508 &hashed_process_data->next_good_time);
509 }
510 }
511 }
512 }
513
514 {
515 /* For the pid_in */
516 /* First, check if the current process is in the state computation
517 * process list. If it is there, that means we must add it right now and
518 * draw items from the beginning of the read for it. If it is not
519 * present, it's a new process and it was not present : it will
520 * be added after the state update. */
521 LttvProcessState *process;
522 process = lttv_state_find_process(ts,
523 ltt_tracefile_num(tfc->tf), pid_in);
524
525 if(process != NULL) {
526 /* Well, the process existed : we must get it in the process hash
527 * or add it, and draw its items.
528 */
529 /* Add process to process list (if not present) */
530 guint pl_height = 0;
531 HashedProcessData *hashed_process_data = NULL;
532 ProcessList *process_list = control_flow_data->process_list;
533 LttTime birth = process->creation_time;
534
535 hashed_process_data = processlist_get_process_data(process_list,
536 pid_in,
537 process->cpu,
538 &birth,
539 tfc->t_context->index);
540 if(hashed_process_data == NULL)
541 {
542 g_assert(pid_in == 0 || pid_in != process->ppid);
543 /* Process not present */
544 ProcessInfo *process_info;
545 Drawing_t *drawing = control_flow_data->drawing;
546 processlist_add(process_list,
547 drawing,
548 pid_in,
549 process->cpu,
550 process->ppid,
551 &birth,
552 tfc->t_context->index,
553 process->name,
554 &pl_height,
555 &process_info,
556 &hashed_process_data);
557 gtk_widget_set_size_request(drawing->drawing_area,
558 -1,
559 pl_height);
560 gtk_widget_queue_draw(drawing->drawing_area);
561
562 }
563 //We could set the current process and hash here, but will be done
564 //by after schedchange hook
565
566 /* Now, the process is in the state hash and our own process hash.
567 * We definitely can draw the items related to the ending state.
568 */
569
570 if(ltt_time_compare(hashed_process_data->next_good_time,
571 evtime) > 0)
572 {
573 if(hashed_process_data->x.middle_marked == FALSE) {
574
575 TimeWindow time_window =
576 lttvwindow_get_time_window(control_flow_data->tab);
577#ifdef EXTRA_CHECK
578 if(ltt_time_compare(evtime, time_window.start_time) == -1
579 || ltt_time_compare(evtime, time_window.end_time) == 1)
580 return;
581#endif //EXTRA_CHECK
582 Drawing_t *drawing = control_flow_data->drawing;
583 guint width = drawing->width;
584 guint x;
585 convert_time_to_pixels(
586 time_window,
587 evtime,
588 width,
589 &x);
590
591 /* Draw collision indicator */
592 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
593 gdk_draw_point(hashed_process_data->pixmap,
594 drawing->gc,
595 x,
596 (hashed_process_data->height/2)-3);
597 hashed_process_data->x.middle_marked = TRUE;
598 }
599 } else {
600 TimeWindow time_window =
601 lttvwindow_get_time_window(control_flow_data->tab);
602#ifdef EXTRA_CHECK
603 if(ltt_time_compare(evtime, time_window.start_time) == -1
604 || ltt_time_compare(evtime, time_window.end_time) == 1)
605 return;
606#endif //EXTRA_CHECK
607 Drawing_t *drawing = control_flow_data->drawing;
608 guint width = drawing->width;
609 guint x;
610
611 convert_time_to_pixels(
612 time_window,
613 evtime,
614 width,
615 &x);
616
617
618 /* Jump over draw if we are at the same x position */
619 if(x == hashed_process_data->x.middle &&
620 hashed_process_data->x.middle_used)
621 {
622 if(hashed_process_data->x.middle_marked == FALSE) {
623 /* Draw collision indicator */
624 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
625 gdk_draw_point(hashed_process_data->pixmap,
626 drawing->gc,
627 x,
628 (hashed_process_data->height/2)-3);
629 hashed_process_data->x.middle_marked = TRUE;
630 }
631 /* jump */
632 } else {
633 DrawContext draw_context;
634
635 /* Now create the drawing context that will be used to draw
636 * items related to the last state. */
637 draw_context.drawable = hashed_process_data->pixmap;
638 draw_context.gc = drawing->gc;
639 draw_context.pango_layout = drawing->pango_layout;
640 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
641 draw_context.drawinfo.end.x = x;
642
643 draw_context.drawinfo.y.over = 1;
644 draw_context.drawinfo.y.middle = (hashed_process_data->height/2);
645 draw_context.drawinfo.y.under = hashed_process_data->height;
646
647 draw_context.drawinfo.start.offset.over = 0;
648 draw_context.drawinfo.start.offset.middle = 0;
649 draw_context.drawinfo.start.offset.under = 0;
650 draw_context.drawinfo.end.offset.over = 0;
651 draw_context.drawinfo.end.offset.middle = 0;
652 draw_context.drawinfo.end.offset.under = 0;
653
654 {
655 /* Draw the line */
656 PropertiesLine prop_line = prepare_s_e_line(process);
657 draw_line((void*)&prop_line, (void*)&draw_context);
658 }
659
660
661 /* become the last x position */
662 hashed_process_data->x.middle = x;
663 hashed_process_data->x.middle_used = TRUE;
664 hashed_process_data->x.middle_marked = FALSE;
665
666 /* Calculate the next good time */
667 convert_pixels_to_time(width, x+1, time_window,
668 &hashed_process_data->next_good_time);
669 }
670 }
671 }
672 }
673 return 0;
674
675
676
677
678 /* Text dump */
679#ifdef DONTSHOW
680 GString *string = g_string_new("");;
681 gboolean field_names = TRUE, state = TRUE;
682
683 lttv_event_to_string(e, tfc->tf, string, TRUE, field_names, tfs);
684 g_string_append_printf(string,"\n");
685
686 if(state) {
687 g_string_append_printf(string, " %s",
688 g_quark_to_string(tfs->process->state->s));
689 }
690
691 g_info("%s",string->str);
692
693 g_string_free(string, TRUE);
694
695 /* End of text dump */
696#endif //DONTSHOW
697
698}
699
700/* after_schedchange_hook
701 *
702 * The draw after hook is called by the reading API to have a
703 * particular event drawn on the screen.
704 * @param hook_data ControlFlowData structure of the viewer.
705 * @param call_data Event context.
706 *
707 * This function adds items to be drawn in a queue for each process.
708 *
709 */
710int after_schedchange_hook(void *hook_data, void *call_data)
711{
712 LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data;
713 EventsRequest *events_request = (EventsRequest*)thf->hook_data;
714 ControlFlowData *control_flow_data = events_request->viewer_data;
715
716 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
717
718 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
719
720 LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
721
722 LttEvent *e;
723 e = ltt_tracefile_get_event(tfc->tf);
724
725 LttTime evtime = ltt_event_time(e);
726
727 /* Add process to process list (if not present) */
728 LttvProcessState *process_in;
729 LttTime birth;
730 guint pl_height = 0;
731 HashedProcessData *hashed_process_data_in = NULL;
732
733 ProcessList *process_list = control_flow_data->process_list;
734
735 guint pid_in;
736 {
737 guint pid_out;
738 pid_out = ltt_event_get_long_unsigned(e, thf->f1);
739 pid_in = ltt_event_get_long_unsigned(e, thf->f2);
740 }
741
742
743 /* Find process pid_in in the list... */
744 //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in);
745 //process_in = tfs->process;
746 guint cpu = ltt_tracefile_num(tfc->tf);
747 process_in = ts->running_process[cpu];
748 /* It should exist, because we are after the state update. */
749#ifdef EXTRA_CHECK
750 g_assert(process_in != NULL);
751#endif //EXTRA_CHECK
752 birth = process_in->creation_time;
753
754 hashed_process_data_in = processlist_get_process_data(process_list,
755 pid_in,
756 process_in->cpu,
757 &birth,
758 tfc->t_context->index);
759 if(hashed_process_data_in == NULL)
760 {
761 g_assert(pid_in == 0 || pid_in != process_in->ppid);
762 ProcessInfo *process_info;
763 Drawing_t *drawing = control_flow_data->drawing;
764 /* Process not present */
765 processlist_add(process_list,
766 drawing,
767 pid_in,
768 process_in->cpu,
769 process_in->ppid,
770 &birth,
771 tfc->t_context->index,
772 process_in->name,
773 &pl_height,
774 &process_info,
775 &hashed_process_data_in);
776 gtk_widget_set_size_request(drawing->drawing_area,
777 -1,
778 pl_height);
779 gtk_widget_queue_draw(drawing->drawing_area);
780 }
781 /* Set the current process */
782 process_list->current_hash_data[process_in->cpu] =
783 hashed_process_data_in;
784
785 if(ltt_time_compare(hashed_process_data_in->next_good_time,
786 evtime) <= 0)
787 {
788 TimeWindow time_window =
789 lttvwindow_get_time_window(control_flow_data->tab);
790
791#ifdef EXTRA_CHECK
792 if(ltt_time_compare(evtime, time_window.start_time) == -1
793 || ltt_time_compare(evtime, time_window.end_time) == 1)
794 return;
795#endif //EXTRA_CHECK
796 Drawing_t *drawing = control_flow_data->drawing;
797 guint width = drawing->width;
798 guint new_x;
799
800 convert_time_to_pixels(
801 time_window,
802 evtime,
803 width,
804 &new_x);
805
806 if(hashed_process_data_in->x.middle != new_x) {
807 hashed_process_data_in->x.middle = new_x;
808 hashed_process_data_in->x.middle_used = FALSE;
809 hashed_process_data_in->x.middle_marked = FALSE;
810 }
811 }
812 return 0;
813}
814
815
816
817
818/* before_execmode_hook
819 *
820 * This function basically draw lines and icons. Two types of lines are drawn :
821 * one small (3 pixels?) representing the state of the process and the second
822 * type is thicker (10 pixels?) representing on which CPU a process is running
823 * (and this only in running state).
824 *
825 * Extremums of the lines :
826 * x_min : time of the last event context for this process kept in memory.
827 * x_max : time of the current event.
828 * y : middle of the process in the process list. The process is found in the
829 * list, therefore is it's position in pixels.
830 *
831 * The choice of lines'color is defined by the context of the last event for this
832 * process.
833 */
834
835
836int before_execmode_hook(void *hook_data, void *call_data)
837{
838 LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data;
839 EventsRequest *events_request = (EventsRequest*)thf->hook_data;
840 ControlFlowData *control_flow_data = events_request->viewer_data;
841
842 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
843
844 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
845
846 LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
847
848 LttEvent *e;
849 e = ltt_tracefile_get_event(tfc->tf);
850
851 LttTime evtime = ltt_event_time(e);
852
853 /* we are in a execmode, before the state update. We must draw the
854 * items corresponding to the state before it changes : now is the right
855 * time to do it.
856 */
857 /* For the pid */
858 //LttvProcessState *process = tfs->process;
859 guint cpu = ltt_tracefile_num(tfc->tf);
860 LttvProcessState *process = ts->running_process[cpu];
861 g_assert(process != NULL);
862
863 guint pid = process->pid;
864
865 /* Well, the process_out existed : we must get it in the process hash
866 * or add it, and draw its items.
867 */
868 /* Add process to process list (if not present) */
869 guint pl_height = 0;
870 HashedProcessData *hashed_process_data = NULL;
871 ProcessList *process_list = control_flow_data->process_list;
872 LttTime birth = process->creation_time;
873
874 if(likely(process_list->current_hash_data[cpu] != NULL)) {
875 hashed_process_data = process_list->current_hash_data[cpu];
876 } else {
877 hashed_process_data = processlist_get_process_data(process_list,
878 pid,
879 process->cpu,
880 &birth,
881 tfc->t_context->index);
882 if(unlikely(hashed_process_data == NULL))
883 {
884 g_assert(pid == 0 || pid != process->ppid);
885 ProcessInfo *process_info;
886 /* Process not present */
887 Drawing_t *drawing = control_flow_data->drawing;
888 processlist_add(process_list,
889 drawing,
890 pid,
891 process->cpu,
892 process->ppid,
893 &birth,
894 tfc->t_context->index,
895 process->name,
896 &pl_height,
897 &process_info,
898 &hashed_process_data);
899 gtk_widget_set_size_request(drawing->drawing_area,
900 -1,
901 pl_height);
902 gtk_widget_queue_draw(drawing->drawing_area);
903 }
904 /* Set the current process */
905 process_list->current_hash_data[process->cpu] =
906 hashed_process_data;
907 }
908
909 /* Now, the process is in the state hash and our own process hash.
910 * We definitely can draw the items related to the ending state.
911 */
912
913 if(likely(ltt_time_compare(hashed_process_data->next_good_time,
914 evtime) > 0))
915 {
916 if(unlikely(hashed_process_data->x.middle_marked == FALSE)) {
917 TimeWindow time_window =
918 lttvwindow_get_time_window(control_flow_data->tab);
919
920#ifdef EXTRA_CHECK
921 if(ltt_time_compare(evtime, time_window.start_time) == -1
922 || ltt_time_compare(evtime, time_window.end_time) == 1)
923 return;
924#endif //EXTRA_CHECK
925 Drawing_t *drawing = control_flow_data->drawing;
926 guint width = drawing->width;
927 guint x;
928 convert_time_to_pixels(
929 time_window,
930 evtime,
931 width,
932 &x);
933
934 /* Draw collision indicator */
935 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
936 gdk_draw_point(hashed_process_data->pixmap,
937 drawing->gc,
938 x,
939 (hashed_process_data->height/2)-3);
940 hashed_process_data->x.middle_marked = TRUE;
941 }
942 } else {
943 TimeWindow time_window =
944 lttvwindow_get_time_window(control_flow_data->tab);
945
946#ifdef EXTRA_CHECK
947 if(ltt_time_compare(evtime, time_window.start_time) == -1
948 || ltt_time_compare(evtime, time_window.end_time) == 1)
949 return;
950#endif //EXTRA_CHECK
951 Drawing_t *drawing = control_flow_data->drawing;
952 guint width = drawing->width;
953 guint x;
954
955 convert_time_to_pixels(
956 time_window,
957 evtime,
958 width,
959 &x);
960
961
962 /* Jump over draw if we are at the same x position */
963 if(unlikely(x == hashed_process_data->x.middle &&
964 hashed_process_data->x.middle_used))
965 {
966 if(unlikely(hashed_process_data->x.middle_marked == FALSE)) {
967 /* Draw collision indicator */
968 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
969 gdk_draw_point(hashed_process_data->pixmap,
970 drawing->gc,
971 x,
972 (hashed_process_data->height/2)-3);
973 hashed_process_data->x.middle_marked = TRUE;
974 }
975 /* jump */
976 } else {
977
978 DrawContext draw_context;
979 /* Now create the drawing context that will be used to draw
980 * items related to the last state. */
981 draw_context.drawable = hashed_process_data->pixmap;
982 draw_context.gc = drawing->gc;
983 draw_context.pango_layout = drawing->pango_layout;
984 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
985 draw_context.drawinfo.end.x = x;
986
987 draw_context.drawinfo.y.over = 1;
988 draw_context.drawinfo.y.middle = (hashed_process_data->height/2);
989 draw_context.drawinfo.y.under = hashed_process_data->height;
990
991 draw_context.drawinfo.start.offset.over = 0;
992 draw_context.drawinfo.start.offset.middle = 0;
993 draw_context.drawinfo.start.offset.under = 0;
994 draw_context.drawinfo.end.offset.over = 0;
995 draw_context.drawinfo.end.offset.middle = 0;
996 draw_context.drawinfo.end.offset.under = 0;
997
998 {
999 /* Draw the line */
1000 PropertiesLine prop_line = prepare_s_e_line(process);
1001 draw_line((void*)&prop_line, (void*)&draw_context);
1002
1003 }
1004 /* become the last x position */
1005 hashed_process_data->x.middle = x;
1006 hashed_process_data->x.middle_used = TRUE;
1007 hashed_process_data->x.middle_marked = FALSE;
1008
1009 /* Calculate the next good time */
1010 convert_pixels_to_time(width, x+1, time_window,
1011 &hashed_process_data->next_good_time);
1012 }
1013 }
1014
1015 return 0;
1016}
1017
1018/* before_process_exit_hook
1019 *
1020 * Draw lines for process event.
1021 *
1022 * @param hook_data ControlFlowData structure of the viewer.
1023 * @param call_data Event context.
1024 *
1025 * This function adds items to be drawn in a queue for each process.
1026 *
1027 */
1028
1029
1030int before_process_exit_hook(void *hook_data, void *call_data)
1031{
1032 LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data;
1033 EventsRequest *events_request = (EventsRequest*)thf->hook_data;
1034
1035 ControlFlowData *control_flow_data = events_request->viewer_data;
1036
1037 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
1038
1039 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
1040
1041 LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
1042
1043 LttEvent *e;
1044 e = ltt_tracefile_get_event(tfc->tf);
1045
1046 LttTime evtime = ltt_event_time(e);
1047
1048 /* Add process to process list (if not present) */
1049 //LttvProcessState *process = tfs->process;
1050 guint cpu = ltt_tracefile_num(tfc->tf);
1051 LttvProcessState *process = ts->running_process[cpu];
1052 guint pid = process->pid;
1053 LttTime birth;
1054 guint pl_height = 0;
1055 HashedProcessData *hashed_process_data = NULL;
1056
1057 ProcessList *process_list = control_flow_data->process_list;
1058
1059 g_assert(process != NULL);
1060
1061 birth = process->creation_time;
1062
1063 if(likely(process_list->current_hash_data[cpu] != NULL)) {
1064 hashed_process_data = process_list->current_hash_data[cpu];
1065 } else {
1066 hashed_process_data = processlist_get_process_data(process_list,
1067 pid,
1068 process->cpu,
1069 &birth,
1070 tfc->t_context->index);
1071 if(unlikely(hashed_process_data == NULL))
1072 {
1073 g_assert(pid == 0 || pid != process->ppid);
1074 /* Process not present */
1075 Drawing_t *drawing = control_flow_data->drawing;
1076 ProcessInfo *process_info;
1077 processlist_add(process_list,
1078 drawing,
1079 pid,
1080 process->cpu,
1081 process->ppid,
1082 &birth,
1083 tfc->t_context->index,
1084 process->name,
1085 &pl_height,
1086 &process_info,
1087 &hashed_process_data);
1088 gtk_widget_set_size_request(drawing->drawing_area,
1089 -1,
1090 pl_height);
1091 gtk_widget_queue_draw(drawing->drawing_area);
1092 }
1093 }
1094
1095 /* Now, the process is in the state hash and our own process hash.
1096 * We definitely can draw the items related to the ending state.
1097 */
1098
1099 if(likely(ltt_time_compare(hashed_process_data->next_good_time,
1100 evtime) > 0))
1101 {
1102 if(unlikely(hashed_process_data->x.middle_marked == FALSE)) {
1103 TimeWindow time_window =
1104 lttvwindow_get_time_window(control_flow_data->tab);
1105
1106#ifdef EXTRA_CHECK
1107 if(ltt_time_compare(evtime, time_window.start_time) == -1
1108 || ltt_time_compare(evtime, time_window.end_time) == 1)
1109 return;
1110#endif //EXTRA_CHECK
1111 Drawing_t *drawing = control_flow_data->drawing;
1112 guint width = drawing->width;
1113 guint x;
1114 convert_time_to_pixels(
1115 time_window,
1116 evtime,
1117 width,
1118 &x);
1119
1120 /* Draw collision indicator */
1121 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
1122 gdk_draw_point(hashed_process_data->pixmap,
1123 drawing->gc,
1124 x,
1125 (hashed_process_data->height/2)-3);
1126 hashed_process_data->x.middle_marked = TRUE;
1127 }
1128 } else {
1129 TimeWindow time_window =
1130 lttvwindow_get_time_window(control_flow_data->tab);
1131
1132#ifdef EXTRA_CHECK
1133 if(ltt_time_compare(evtime, time_window.start_time) == -1
1134 || ltt_time_compare(evtime, time_window.end_time) == 1)
1135 return;
1136#endif //EXTRA_CHECK
1137 Drawing_t *drawing = control_flow_data->drawing;
1138 guint width = drawing->width;
1139 guint x;
1140
1141 convert_time_to_pixels(
1142 time_window,
1143 evtime,
1144 width,
1145 &x);
1146
1147
1148 /* Jump over draw if we are at the same x position */
1149 if(unlikely(x == hashed_process_data->x.middle &&
1150 hashed_process_data->x.middle_used))
1151 {
1152 if(unlikely(hashed_process_data->x.middle_marked == FALSE)) {
1153 /* Draw collision indicator */
1154 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
1155 gdk_draw_point(hashed_process_data->pixmap,
1156 drawing->gc,
1157 x,
1158 (hashed_process_data->height/2)-3);
1159 hashed_process_data->x.middle_marked = TRUE;
1160 }
1161 /* jump */
1162 } else {
1163 DrawContext draw_context;
1164
1165 /* Now create the drawing context that will be used to draw
1166 * items related to the last state. */
1167 draw_context.drawable = hashed_process_data->pixmap;
1168 draw_context.gc = drawing->gc;
1169 draw_context.pango_layout = drawing->pango_layout;
1170 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
1171 draw_context.drawinfo.end.x = x;
1172
1173 draw_context.drawinfo.y.over = 1;
1174 draw_context.drawinfo.y.middle = (hashed_process_data->height/2);
1175 draw_context.drawinfo.y.under = hashed_process_data->height;
1176
1177 draw_context.drawinfo.start.offset.over = 0;
1178 draw_context.drawinfo.start.offset.middle = 0;
1179 draw_context.drawinfo.start.offset.under = 0;
1180 draw_context.drawinfo.end.offset.over = 0;
1181 draw_context.drawinfo.end.offset.middle = 0;
1182 draw_context.drawinfo.end.offset.under = 0;
1183
1184 {
1185 /* Draw the line */
1186 PropertiesLine prop_line = prepare_s_e_line(process);
1187 draw_line((void*)&prop_line, (void*)&draw_context);
1188
1189 }
1190 /* become the last x position */
1191 hashed_process_data->x.middle = x;
1192 hashed_process_data->x.middle_used = TRUE;
1193 hashed_process_data->x.middle_marked = FALSE;
1194
1195 /* Calculate the next good time */
1196 convert_pixels_to_time(width, x+1, time_window,
1197 &hashed_process_data->next_good_time);
1198 }
1199 }
1200
1201 return 0;
1202
1203}
1204
1205
1206
1207/* before_process_release_hook
1208 *
1209 * Draw lines for process event.
1210 *
1211 * @param hook_data ControlFlowData structure of the viewer.
1212 * @param call_data Event context.
1213 *
1214 * This function adds items to be drawn in a queue for each process.
1215 *
1216 */
1217
1218
1219int before_process_release_hook(void *hook_data, void *call_data)
1220{
1221 LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data;
1222 EventsRequest *events_request = (EventsRequest*)thf->hook_data;
1223
1224 ControlFlowData *control_flow_data = events_request->viewer_data;
1225
1226 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
1227
1228 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
1229
1230 LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
1231
1232 LttEvent *e;
1233 e = ltt_tracefile_get_event(tfc->tf);
1234
1235 LttTime evtime = ltt_event_time(e);
1236
1237
1238 guint pid;
1239 {
1240 pid = ltt_event_get_long_unsigned(e, thf->f1);
1241 }
1242
1243 /* Add process to process list (if not present) */
1244 /* Don't care about the process if it's not in the state hash already :
1245 * that means a process that has never done anything in the trace and
1246 * unknown suddently gets destroyed : no state meaningful to show. */
1247 LttvProcessState *process = lttv_state_find_process(ts, ANY_CPU, pid);
1248
1249 if(process != NULL) {
1250 LttTime birth;
1251 guint pl_height = 0;
1252 HashedProcessData *hashed_process_data = NULL;
1253
1254 ProcessList *process_list = control_flow_data->process_list;
1255
1256 birth = process->creation_time;
1257
1258 /* Cannot use current process : this event happens on another process,
1259 * action done by the parent. */
1260 hashed_process_data = processlist_get_process_data(process_list,
1261 pid,
1262 process->cpu,
1263 &birth,
1264 tfc->t_context->index);
1265 if(unlikely(hashed_process_data == NULL))
1266 {
1267 g_assert(pid == 0 || pid != process->ppid);
1268 /* Process not present */
1269 Drawing_t *drawing = control_flow_data->drawing;
1270 ProcessInfo *process_info;
1271 processlist_add(process_list,
1272 drawing,
1273 pid,
1274 process->cpu,
1275 process->ppid,
1276 &birth,
1277 tfc->t_context->index,
1278 process->name,
1279 &pl_height,
1280 &process_info,
1281 &hashed_process_data);
1282 gtk_widget_set_size_request(drawing->drawing_area,
1283 -1,
1284 pl_height);
1285 gtk_widget_queue_draw(drawing->drawing_area);
1286 }
1287
1288 /* Now, the process is in the state hash and our own process hash.
1289 * We definitely can draw the items related to the ending state.
1290 */
1291
1292 if(likely(ltt_time_compare(hashed_process_data->next_good_time,
1293 evtime) > 0))
1294 {
1295 if(unlikely(hashed_process_data->x.middle_marked == FALSE)) {
1296 TimeWindow time_window =
1297 lttvwindow_get_time_window(control_flow_data->tab);
1298
1299#ifdef EXTRA_CHECK
1300 if(ltt_time_compare(evtime, time_window.start_time) == -1
1301 || ltt_time_compare(evtime, time_window.end_time) == 1)
1302 return;
1303#endif //EXTRA_CHECK
1304 Drawing_t *drawing = control_flow_data->drawing;
1305 guint width = drawing->width;
1306 guint x;
1307 convert_time_to_pixels(
1308 time_window,
1309 evtime,
1310 width,
1311 &x);
1312
1313 /* Draw collision indicator */
1314 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
1315 gdk_draw_point(hashed_process_data->pixmap,
1316 drawing->gc,
1317 x,
1318 (hashed_process_data->height/2)-3);
1319 hashed_process_data->x.middle_marked = TRUE;
1320 }
1321 } else {
1322 TimeWindow time_window =
1323 lttvwindow_get_time_window(control_flow_data->tab);
1324
1325#ifdef EXTRA_CHECK
1326 if(ltt_time_compare(evtime, time_window.start_time) == -1
1327 || ltt_time_compare(evtime, time_window.end_time) == 1)
1328 return;
1329#endif //EXTRA_CHECK
1330 Drawing_t *drawing = control_flow_data->drawing;
1331 guint width = drawing->width;
1332 guint x;
1333
1334 convert_time_to_pixels(
1335 time_window,
1336 evtime,
1337 width,
1338 &x);
1339
1340
1341 /* Jump over draw if we are at the same x position */
1342 if(unlikely(x == hashed_process_data->x.middle &&
1343 hashed_process_data->x.middle_used))
1344 {
1345 if(unlikely(hashed_process_data->x.middle_marked == FALSE)) {
1346 /* Draw collision indicator */
1347 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
1348 gdk_draw_point(hashed_process_data->pixmap,
1349 drawing->gc,
1350 x,
1351 (hashed_process_data->height/2)-3);
1352 hashed_process_data->x.middle_marked = TRUE;
1353 }
1354 /* jump */
1355 } else {
1356 DrawContext draw_context;
1357
1358 /* Now create the drawing context that will be used to draw
1359 * items related to the last state. */
1360 draw_context.drawable = hashed_process_data->pixmap;
1361 draw_context.gc = drawing->gc;
1362 draw_context.pango_layout = drawing->pango_layout;
1363 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
1364 draw_context.drawinfo.end.x = x;
1365
1366 draw_context.drawinfo.y.over = 1;
1367 draw_context.drawinfo.y.middle = (hashed_process_data->height/2);
1368 draw_context.drawinfo.y.under = hashed_process_data->height;
1369
1370 draw_context.drawinfo.start.offset.over = 0;
1371 draw_context.drawinfo.start.offset.middle = 0;
1372 draw_context.drawinfo.start.offset.under = 0;
1373 draw_context.drawinfo.end.offset.over = 0;
1374 draw_context.drawinfo.end.offset.middle = 0;
1375 draw_context.drawinfo.end.offset.under = 0;
1376
1377 {
1378 /* Draw the line */
1379 PropertiesLine prop_line = prepare_s_e_line(process);
1380 draw_line((void*)&prop_line, (void*)&draw_context);
1381
1382 }
1383 /* become the last x position */
1384 hashed_process_data->x.middle = x;
1385 hashed_process_data->x.middle_used = TRUE;
1386 hashed_process_data->x.middle_marked = FALSE;
1387
1388 /* Calculate the next good time */
1389 convert_pixels_to_time(width, x+1, time_window,
1390 &hashed_process_data->next_good_time);
1391 }
1392 }
1393 }
1394
1395 return 0;
1396}
1397
1398
1399
1400
1401
1402/* after_process_fork_hook
1403 *
1404 * Create the processlist entry for the child process. Put the last
1405 * position in x at the current time value.
1406 *
1407 * @param hook_data ControlFlowData structure of the viewer.
1408 * @param call_data Event context.
1409 *
1410 * This function adds items to be drawn in a queue for each process.
1411 *
1412 */
1413int after_process_fork_hook(void *hook_data, void *call_data)
1414{
1415 LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data;
1416 EventsRequest *events_request = (EventsRequest*)thf->hook_data;
1417 ControlFlowData *control_flow_data = events_request->viewer_data;
1418
1419 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
1420
1421 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
1422
1423 LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
1424
1425 LttEvent *e;
1426 e = ltt_tracefile_get_event(tfc->tf);
1427
1428 LttTime evtime = ltt_event_time(e);
1429
1430 guint child_pid;
1431 {
1432 child_pid = ltt_event_get_long_unsigned(e, thf->f2);
1433 }
1434
1435 /* Add process to process list (if not present) */
1436 LttvProcessState *process_child;
1437 LttTime birth;
1438 guint pl_height = 0;
1439 HashedProcessData *hashed_process_data_child = NULL;
1440
1441 ProcessList *process_list = control_flow_data->process_list;
1442
1443 /* Find child in the list... */
1444 process_child = lttv_state_find_process(ts, ANY_CPU, child_pid);
1445 /* It should exist, because we are after the state update. */
1446 g_assert(process_child != NULL);
1447
1448 birth = process_child->creation_time;
1449
1450 /* Cannot use current process, because this action is done by the parent
1451 * on its child. */
1452 hashed_process_data_child = processlist_get_process_data(process_list,
1453 child_pid,
1454 process_child->cpu,
1455 &birth,
1456 tfc->t_context->index);
1457 if(likely(hashed_process_data_child == NULL))
1458 {
1459 g_assert(child_pid == 0 || child_pid != process_child->ppid);
1460 /* Process not present */
1461 Drawing_t *drawing = control_flow_data->drawing;
1462 ProcessInfo *process_info;
1463 processlist_add(process_list,
1464 drawing,
1465 child_pid,
1466 process_child->cpu,
1467 process_child->ppid,
1468 &birth,
1469 tfc->t_context->index,
1470 process_child->name,
1471 &pl_height,
1472 &process_info,
1473 &hashed_process_data_child);
1474 gtk_widget_set_size_request(drawing->drawing_area,
1475 -1,
1476 pl_height);
1477 gtk_widget_queue_draw(drawing->drawing_area);
1478 }
1479
1480
1481 if(likely(ltt_time_compare(hashed_process_data_child->next_good_time,
1482 evtime) <= 0))
1483 {
1484 TimeWindow time_window =
1485 lttvwindow_get_time_window(control_flow_data->tab);
1486
1487#ifdef EXTRA_CHECK
1488 if(ltt_time_compare(evtime, time_window.start_time) == -1
1489 || ltt_time_compare(evtime, time_window.end_time) == 1)
1490 return;
1491#endif //EXTRA_CHECK
1492 Drawing_t *drawing = control_flow_data->drawing;
1493 guint width = drawing->width;
1494 guint new_x;
1495 convert_time_to_pixels(
1496 time_window,
1497 evtime,
1498 width,
1499 &new_x);
1500
1501 if(likely(hashed_process_data_child->x.over != new_x)) {
1502 hashed_process_data_child->x.over = new_x;
1503 hashed_process_data_child->x.over_used = FALSE;
1504 hashed_process_data_child->x.over_marked = FALSE;
1505 }
1506 if(likely(hashed_process_data_child->x.middle != new_x)) {
1507 hashed_process_data_child->x.middle = new_x;
1508 hashed_process_data_child->x.middle_used = FALSE;
1509 hashed_process_data_child->x.middle_marked = FALSE;
1510 }
1511 if(likely(hashed_process_data_child->x.under != new_x)) {
1512 hashed_process_data_child->x.under = new_x;
1513 hashed_process_data_child->x.under_used = FALSE;
1514 hashed_process_data_child->x.under_marked = FALSE;
1515 }
1516 }
1517 return 0;
1518}
1519
1520
1521
1522/* after_process_exit_hook
1523 *
1524 * Create the processlist entry for the child process. Put the last
1525 * position in x at the current time value.
1526 *
1527 * @param hook_data ControlFlowData structure of the viewer.
1528 * @param call_data Event context.
1529 *
1530 * This function adds items to be drawn in a queue for each process.
1531 *
1532 */
1533int after_process_exit_hook(void *hook_data, void *call_data)
1534{
1535 LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data;
1536 EventsRequest *events_request = (EventsRequest*)thf->hook_data;
1537 ControlFlowData *control_flow_data = events_request->viewer_data;
1538
1539 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
1540
1541 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
1542
1543 LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
1544
1545 LttEvent *e;
1546 e = ltt_tracefile_get_event(tfc->tf);
1547
1548 LttTime evtime = ltt_event_time(e);
1549
1550 /* Add process to process list (if not present) */
1551 //LttvProcessState *process = tfs->process;
1552 guint cpu = ltt_tracefile_num(tfc->tf);
1553 LttvProcessState *process = ts->running_process[cpu];
1554
1555 /* It should exist, because we are after the state update. */
1556 g_assert(process != NULL);
1557
1558 guint pid = process->pid;
1559 LttTime birth;
1560 guint pl_height = 0;
1561 HashedProcessData *hashed_process_data = NULL;
1562
1563 ProcessList *process_list = control_flow_data->process_list;
1564
1565 birth = process->creation_time;
1566
1567 if(likely(process_list->current_hash_data[cpu] != NULL) ){
1568 hashed_process_data = process_list->current_hash_data[cpu];
1569 } else {
1570 hashed_process_data = processlist_get_process_data(process_list,
1571 pid,
1572 process->cpu,
1573 &birth,
1574 tfc->t_context->index);
1575 if(unlikely(hashed_process_data == NULL))
1576 {
1577 g_assert(pid == 0 || pid != process->ppid);
1578 /* Process not present */
1579 Drawing_t *drawing = control_flow_data->drawing;
1580 ProcessInfo *process_info;
1581 processlist_add(process_list,
1582 drawing,
1583 pid,
1584 process->cpu,
1585 process->ppid,
1586 &birth,
1587 tfc->t_context->index,
1588 process->name,
1589 &pl_height,
1590 &process_info,
1591 &hashed_process_data);
1592 gtk_widget_set_size_request(drawing->drawing_area,
1593 -1,
1594 pl_height);
1595 gtk_widget_queue_draw(drawing->drawing_area);
1596 }
1597
1598 /* Set the current process */
1599 process_list->current_hash_data[process->cpu] =
1600 hashed_process_data;
1601 }
1602
1603 if(unlikely(ltt_time_compare(hashed_process_data->next_good_time,
1604 evtime) <= 0))
1605 {
1606 TimeWindow time_window =
1607 lttvwindow_get_time_window(control_flow_data->tab);
1608
1609#ifdef EXTRA_CHECK
1610 if(ltt_time_compare(evtime, time_window.start_time) == -1
1611 || ltt_time_compare(evtime, time_window.end_time) == 1)
1612 return;
1613#endif //EXTRA_CHECK
1614 Drawing_t *drawing = control_flow_data->drawing;
1615 guint width = drawing->width;
1616 guint new_x;
1617 convert_time_to_pixels(
1618 time_window,
1619 evtime,
1620 width,
1621 &new_x);
1622 if(unlikely(hashed_process_data->x.middle != new_x)) {
1623 hashed_process_data->x.middle = new_x;
1624 hashed_process_data->x.middle_used = FALSE;
1625 hashed_process_data->x.middle_marked = FALSE;
1626 }
1627 }
1628
1629 return 0;
1630}
1631
1632
1633/* Get the filename of the process to print */
1634int after_fs_exec_hook(void *hook_data, void *call_data)
1635{
1636 LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data;
1637 EventsRequest *events_request = (EventsRequest*)thf->hook_data;
1638 ControlFlowData *control_flow_data = events_request->viewer_data;
1639
1640 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
1641
1642 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
1643
1644 LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
1645
1646 guint cpu = ltt_tracefile_num(tfc->tf);
1647 LttvProcessState *process = ts->running_process[cpu];
1648 g_assert(process != NULL);
1649
1650 guint pid = process->pid;
1651
1652 /* Well, the process_out existed : we must get it in the process hash
1653 * or add it, and draw its items.
1654 */
1655 /* Add process to process list (if not present) */
1656 guint pl_height = 0;
1657 HashedProcessData *hashed_process_data = NULL;
1658 ProcessList *process_list = control_flow_data->process_list;
1659 LttTime birth = process->creation_time;
1660
1661 if(likely(process_list->current_hash_data[cpu] != NULL)) {
1662 hashed_process_data = process_list->current_hash_data[cpu];
1663 } else {
1664 hashed_process_data = processlist_get_process_data(process_list,
1665 pid,
1666 process->cpu,
1667 &birth,
1668 tfc->t_context->index);
1669 if(unlikely(hashed_process_data == NULL))
1670 {
1671 g_assert(pid == 0 || pid != process->ppid);
1672 ProcessInfo *process_info;
1673 /* Process not present */
1674 Drawing_t *drawing = control_flow_data->drawing;
1675 processlist_add(process_list,
1676 drawing,
1677 pid,
1678 process->cpu,
1679 process->ppid,
1680 &birth,
1681 tfc->t_context->index,
1682 process->name,
1683 &pl_height,
1684 &process_info,
1685 &hashed_process_data);
1686 gtk_widget_set_size_request(drawing->drawing_area,
1687 -1,
1688 pl_height);
1689 gtk_widget_queue_draw(drawing->drawing_area);
1690 }
1691 /* Set the current process */
1692 process_list->current_hash_data[process->cpu] =
1693 hashed_process_data;
1694 }
1695
1696 processlist_set_name(process_list, process->name, hashed_process_data);
1697
1698 return 0;
1699
1700}
1701
1702
1703
1704
1705gint update_time_window_hook(void *hook_data, void *call_data)
1706{
1707 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
1708 Drawing_t *drawing = control_flow_data->drawing;
1709 ProcessList *process_list = control_flow_data->process_list;
1710
1711 const TimeWindowNotifyData *time_window_nofify_data =
1712 ((const TimeWindowNotifyData *)call_data);
1713
1714 TimeWindow *old_time_window =
1715 time_window_nofify_data->old_time_window;
1716 TimeWindow *new_time_window =
1717 time_window_nofify_data->new_time_window;
1718
1719 /* Update the ruler */
1720 drawing_update_ruler(control_flow_data->drawing,
1721 new_time_window);
1722
1723
1724 /* Two cases : zoom in/out or scrolling */
1725
1726 /* In order to make sure we can reuse the old drawing, the scale must
1727 * be the same and the new time interval being partly located in the
1728 * currently shown time interval. (reuse is only for scrolling)
1729 */
1730
1731 g_info("Old time window HOOK : %lu, %lu to %lu, %lu",
1732 old_time_window->start_time.tv_sec,
1733 old_time_window->start_time.tv_nsec,
1734 old_time_window->time_width.tv_sec,
1735 old_time_window->time_width.tv_nsec);
1736
1737 g_info("New time window HOOK : %lu, %lu to %lu, %lu",
1738 new_time_window->start_time.tv_sec,
1739 new_time_window->start_time.tv_nsec,
1740 new_time_window->time_width.tv_sec,
1741 new_time_window->time_width.tv_nsec);
1742
1743 if( new_time_window->time_width.tv_sec == old_time_window->time_width.tv_sec
1744 && new_time_window->time_width.tv_nsec == old_time_window->time_width.tv_nsec)
1745 {
1746 /* Same scale (scrolling) */
1747 g_info("scrolling");
1748 LttTime *ns = &new_time_window->start_time;
1749 LttTime *nw = &new_time_window->time_width;
1750 LttTime *os = &old_time_window->start_time;
1751 LttTime *ow = &old_time_window->time_width;
1752 LttTime old_end = old_time_window->end_time;
1753 LttTime new_end = new_time_window->end_time;
1754 //if(ns<os+w<ns+w)
1755 //if(ns<os+w && os+w<ns+w)
1756 //if(ns<old_end && os<ns)
1757 if(ltt_time_compare(*ns, old_end) == -1
1758 && ltt_time_compare(*os, *ns) == -1)
1759 {
1760 g_info("scrolling near right");
1761 /* Scroll right, keep right part of the screen */
1762 guint x = 0;
1763 guint width = control_flow_data->drawing->width;
1764 convert_time_to_pixels(
1765 *old_time_window,
1766 *ns,
1767 width,
1768 &x);
1769
1770 /* Copy old data to new location */
1771 copy_pixmap_region(process_list,
1772 NULL,
1773 control_flow_data->drawing->drawing_area->style->black_gc,
1774 NULL,
1775 x, 0,
1776 0, 0,
1777 control_flow_data->drawing->width-x+SAFETY, -1);
1778
1779 if(drawing->damage_begin == drawing->damage_end)
1780 drawing->damage_begin = control_flow_data->drawing->width-x;
1781 else
1782 drawing->damage_begin = 0;
1783
1784 drawing->damage_end = control_flow_data->drawing->width;
1785
1786 /* Clear the data request background, but not SAFETY */
1787 rectangle_pixmap(process_list,
1788 control_flow_data->drawing->drawing_area->style->black_gc,
1789 TRUE,
1790 drawing->damage_begin+SAFETY, 0,
1791 drawing->damage_end - drawing->damage_begin, // do not overlap
1792 -1);
1793 gtk_widget_queue_draw(drawing->drawing_area);
1794 //gtk_widget_queue_draw_area (drawing->drawing_area,
1795 // 0,0,
1796 // control_flow_data->drawing->width,
1797 // control_flow_data->drawing->height);
1798
1799 /* Get new data for the rest. */
1800 drawing_data_request(control_flow_data->drawing,
1801 drawing->damage_begin, 0,
1802 drawing->damage_end - drawing->damage_begin,
1803 control_flow_data->drawing->height);
1804 } else {
1805 //if(ns<os<ns+w)
1806 //if(ns<os && os<ns+w)
1807 //if(ns<os && os<new_end)
1808 if(ltt_time_compare(*ns,*os) == -1
1809 && ltt_time_compare(*os,new_end) == -1)
1810 {
1811 g_info("scrolling near left");
1812 /* Scroll left, keep left part of the screen */
1813 guint x = 0;
1814 guint width = control_flow_data->drawing->width;
1815 convert_time_to_pixels(
1816 *new_time_window,
1817 *os,
1818 width,
1819 &x);
1820
1821 /* Copy old data to new location */
1822 copy_pixmap_region (process_list,
1823 NULL,
1824 control_flow_data->drawing->drawing_area->style->black_gc,
1825 NULL,
1826 0, 0,
1827 x, 0,
1828 -1, -1);
1829
1830 if(drawing->damage_begin == drawing->damage_end)
1831 drawing->damage_end = x;
1832 else
1833 drawing->damage_end =
1834 control_flow_data->drawing->width;
1835
1836 drawing->damage_begin = 0;
1837
1838 rectangle_pixmap (process_list,
1839 control_flow_data->drawing->drawing_area->style->black_gc,
1840 TRUE,
1841 drawing->damage_begin, 0,
1842 drawing->damage_end - drawing->damage_begin, // do not overlap
1843 -1);
1844
1845 gtk_widget_queue_draw(drawing->drawing_area);
1846 //gtk_widget_queue_draw_area (drawing->drawing_area,
1847 // 0,0,
1848 // control_flow_data->drawing->width,
1849 // control_flow_data->drawing->height);
1850
1851
1852 /* Get new data for the rest. */
1853 drawing_data_request(control_flow_data->drawing,
1854 drawing->damage_begin, 0,
1855 drawing->damage_end - drawing->damage_begin,
1856 control_flow_data->drawing->height);
1857
1858 } else {
1859 if(ltt_time_compare(*ns,*os) == 0)
1860 {
1861 g_info("not scrolling");
1862 } else {
1863 g_info("scrolling far");
1864 /* Cannot reuse any part of the screen : far jump */
1865
1866
1867 rectangle_pixmap (process_list,
1868 control_flow_data->drawing->drawing_area->style->black_gc,
1869 TRUE,
1870 0, 0,
1871 control_flow_data->drawing->width+SAFETY, // do not overlap
1872 -1);
1873
1874 //gtk_widget_queue_draw_area (drawing->drawing_area,
1875 // 0,0,
1876 // control_flow_data->drawing->width,
1877 // control_flow_data->drawing->height);
1878 gtk_widget_queue_draw(drawing->drawing_area);
1879
1880 drawing->damage_begin = 0;
1881 drawing->damage_end = control_flow_data->drawing->width;
1882
1883 drawing_data_request(control_flow_data->drawing,
1884 0, 0,
1885 control_flow_data->drawing->width,
1886 control_flow_data->drawing->height);
1887
1888 }
1889 }
1890 }
1891 } else {
1892 /* Different scale (zoom) */
1893 g_info("zoom");
1894
1895 rectangle_pixmap (process_list,
1896 control_flow_data->drawing->drawing_area->style->black_gc,
1897 TRUE,
1898 0, 0,
1899 control_flow_data->drawing->width+SAFETY, // do not overlap
1900 -1);
1901
1902 //gtk_widget_queue_draw_area (drawing->drawing_area,
1903 // 0,0,
1904 // control_flow_data->drawing->width,
1905 // control_flow_data->drawing->height);
1906 gtk_widget_queue_draw(drawing->drawing_area);
1907
1908 drawing->damage_begin = 0;
1909 drawing->damage_end = control_flow_data->drawing->width;
1910
1911 drawing_data_request(control_flow_data->drawing,
1912 0, 0,
1913 control_flow_data->drawing->width,
1914 control_flow_data->drawing->height);
1915 }
1916
1917
1918
1919 return 0;
1920}
1921
1922gint traceset_notify(void *hook_data, void *call_data)
1923{
1924 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
1925 Drawing_t *drawing = control_flow_data->drawing;
1926
1927
1928 drawing_clear(control_flow_data->drawing);
1929 processlist_clear(control_flow_data->process_list);
1930 gtk_widget_set_size_request(
1931 control_flow_data->drawing->drawing_area,
1932 -1, processlist_get_height(control_flow_data->process_list));
1933 redraw_notify(control_flow_data, NULL);
1934
1935 request_background_data(control_flow_data);
1936
1937 return FALSE;
1938}
1939
1940gint redraw_notify(void *hook_data, void *call_data)
1941{
1942 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
1943 Drawing_t *drawing = control_flow_data->drawing;
1944 GtkWidget *widget = drawing->drawing_area;
1945
1946 drawing->damage_begin = 0;
1947 drawing->damage_end = drawing->width;
1948
1949 /* fun feature, to be separated someday... */
1950 drawing_clear(control_flow_data->drawing);
1951 processlist_clear(control_flow_data->process_list);
1952 gtk_widget_set_size_request(
1953 control_flow_data->drawing->drawing_area,
1954 -1, processlist_get_height(control_flow_data->process_list));
1955 // Clear the images
1956 rectangle_pixmap (control_flow_data->process_list,
1957 widget->style->black_gc,
1958 TRUE,
1959 0, 0,
1960 drawing->alloc_width,
1961 -1);
1962
1963 gtk_widget_queue_draw(drawing->drawing_area);
1964
1965 if(drawing->damage_begin < drawing->damage_end)
1966 {
1967 drawing_data_request(drawing,
1968 drawing->damage_begin,
1969 0,
1970 drawing->damage_end-drawing->damage_begin,
1971 drawing->height);
1972 }
1973
1974 //gtk_widget_queue_draw_area(drawing->drawing_area,
1975 // 0,0,
1976 // drawing->width,
1977 // drawing->height);
1978 return FALSE;
1979
1980}
1981
1982
1983gint continue_notify(void *hook_data, void *call_data)
1984{
1985 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
1986 Drawing_t *drawing = control_flow_data->drawing;
1987
1988 //g_assert(widget->allocation.width == drawing->damage_end);
1989
1990 if(drawing->damage_begin < drawing->damage_end)
1991 {
1992 drawing_data_request(drawing,
1993 drawing->damage_begin,
1994 0,
1995 drawing->damage_end-drawing->damage_begin,
1996 drawing->height);
1997 }
1998
1999 return FALSE;
2000}
2001
2002
2003gint update_current_time_hook(void *hook_data, void *call_data)
2004{
2005 ControlFlowData *control_flow_data = (ControlFlowData*)hook_data;
2006 Drawing_t *drawing = control_flow_data->drawing;
2007
2008 LttTime current_time = *((LttTime*)call_data);
2009
2010 TimeWindow time_window =
2011 lttvwindow_get_time_window(control_flow_data->tab);
2012
2013 LttTime time_begin = time_window.start_time;
2014 LttTime width = time_window.time_width;
2015 LttTime half_width;
2016 {
2017 guint64 time_ll = ltt_time_to_uint64(width);
2018 time_ll = time_ll >> 1; /* divide by two */
2019 half_width = ltt_time_from_uint64(time_ll);
2020 }
2021 LttTime time_end = ltt_time_add(time_begin, width);
2022
2023 LttvTracesetContext * tsc =
2024 lttvwindow_get_traceset_context(control_flow_data->tab);
2025
2026 LttTime trace_start = tsc->time_span.start_time;
2027 LttTime trace_end = tsc->time_span.end_time;
2028
2029 g_info("New current time HOOK : %lu, %lu", current_time.tv_sec,
2030 current_time.tv_nsec);
2031
2032
2033
2034 /* If current time is inside time interval, just move the highlight
2035 * bar */
2036
2037 /* Else, we have to change the time interval. We have to tell it
2038 * to the main window. */
2039 /* The time interval change will take care of placing the current
2040 * time at the center of the visible area, or nearest possible if we are
2041 * at one end of the trace. */
2042
2043
2044 if(ltt_time_compare(current_time, time_begin) < 0)
2045 {
2046 TimeWindow new_time_window;
2047
2048 if(ltt_time_compare(current_time,
2049 ltt_time_add(trace_start,half_width)) < 0)
2050 time_begin = trace_start;
2051 else
2052 time_begin = ltt_time_sub(current_time,half_width);
2053
2054 new_time_window.start_time = time_begin;
2055 new_time_window.time_width = width;
2056 new_time_window.time_width_double = ltt_time_to_double(width);
2057 new_time_window.end_time = ltt_time_add(time_begin, width);
2058
2059 lttvwindow_report_time_window(control_flow_data->tab, new_time_window);
2060 }
2061 else if(ltt_time_compare(current_time, time_end) > 0)
2062 {
2063 TimeWindow new_time_window;
2064
2065 if(ltt_time_compare(current_time, ltt_time_sub(trace_end, half_width)) > 0)
2066 time_begin = ltt_time_sub(trace_end,width);
2067 else
2068 time_begin = ltt_time_sub(current_time,half_width);
2069
2070 new_time_window.start_time = time_begin;
2071 new_time_window.time_width = width;
2072 new_time_window.time_width_double = ltt_time_to_double(width);
2073 new_time_window.end_time = ltt_time_add(time_begin, width);
2074
2075 lttvwindow_report_time_window(control_flow_data->tab, new_time_window);
2076
2077 }
2078 gtk_widget_queue_draw(control_flow_data->drawing->drawing_area);
2079
2080
2081 return 0;
2082}
2083
2084typedef struct _ClosureData {
2085 EventsRequest *events_request;
2086 LttvTracesetState *tss;
2087 LttTime end_time;
2088 guint x_end;
2089} ClosureData;
2090
2091
2092void draw_closure(gpointer key, gpointer value, gpointer user_data)
2093{
2094 ProcessInfo *process_info = (ProcessInfo*)key;
2095 HashedProcessData *hashed_process_data = (HashedProcessData*)value;
2096 ClosureData *closure_data = (ClosureData*)user_data;
2097
2098 EventsRequest *events_request = closure_data->events_request;
2099 ControlFlowData *control_flow_data = events_request->viewer_data;
2100
2101 LttvTracesetState *tss = closure_data->tss;
2102 LttvTracesetContext *tsc = (LttvTracesetContext*)tss;
2103
2104 LttTime evtime = closure_data->end_time;
2105
2106 {
2107 /* For the process */
2108 /* First, check if the current process is in the state computation
2109 * process list. If it is there, that means we must add it right now and
2110 * draw items from the beginning of the read for it. If it is not
2111 * present, it's a new process and it was not present : it will
2112 * be added after the state update. */
2113#ifdef EXTRA_CHECK
2114 g_assert(lttv_traceset_number(tsc->ts) > 0);
2115#endif //EXTRA_CHECK
2116 LttvTraceContext *tc = tsc->traces[process_info->trace_num];
2117 LttvTraceState *ts = (LttvTraceState*)tc;
2118
2119#if 0
2120 //FIXME : optimize data structures.
2121 LttvTracefileState *tfs;
2122 LttvTracefileContext *tfc;
2123 guint i;
2124 for(i=0;i<tc->tracefiles->len;i++) {
2125 tfc = g_array_index(tc->tracefiles, LttvTracefileContext*, i);
2126 if(ltt_tracefile_name(tfc->tf) == LTT_NAME_CPU
2127 && ltt_tracefile_num(tfc->tf) == process_info->cpu)
2128 break;
2129
2130 }
2131 g_assert(i<tc->tracefiles->len);
2132 tfs = LTTV_TRACEFILE_STATE(tfc);
2133#endif //0
2134 // LttvTracefileState *tfs =
2135 // (LttvTracefileState*)tsc->traces[process_info->trace_num]->
2136 // tracefiles[process_info->cpu];
2137
2138 LttvProcessState *process;
2139 process = lttv_state_find_process(ts, process_info->cpu,
2140 process_info->pid);
2141
2142 if(unlikely(process != NULL)) {
2143
2144 /* Only draw for processes that are currently in the trace states */
2145
2146 ProcessList *process_list = control_flow_data->process_list;
2147#ifdef EXTRA_CHECK
2148 /* Should be alike when background info is ready */
2149 if(control_flow_data->background_info_waiting==0)
2150 g_assert(ltt_time_compare(process->creation_time,
2151 process_info->birth) == 0);
2152#endif //EXTRA_CHECK
2153
2154 /* Now, the process is in the state hash and our own process hash.
2155 * We definitely can draw the items related to the ending state.
2156 */
2157
2158 if(unlikely(ltt_time_compare(hashed_process_data->next_good_time,
2159 evtime) <= 0))
2160 {
2161 TimeWindow time_window =
2162 lttvwindow_get_time_window(control_flow_data->tab);
2163
2164#ifdef EXTRA_CHECK
2165 if(ltt_time_compare(evtime, time_window.start_time) == -1
2166 || ltt_time_compare(evtime, time_window.end_time) == 1)
2167 return;
2168#endif //EXTRA_CHECK
2169 Drawing_t *drawing = control_flow_data->drawing;
2170 guint width = drawing->width;
2171
2172 guint x = closure_data->x_end;
2173
2174 DrawContext draw_context;
2175
2176 /* Now create the drawing context that will be used to draw
2177 * items related to the last state. */
2178 draw_context.drawable = hashed_process_data->pixmap;
2179 draw_context.gc = drawing->gc;
2180 draw_context.pango_layout = drawing->pango_layout;
2181 draw_context.drawinfo.end.x = x;
2182
2183 draw_context.drawinfo.y.over = 1;
2184 draw_context.drawinfo.y.middle = (hashed_process_data->height/2);
2185 draw_context.drawinfo.y.under = hashed_process_data->height;
2186
2187 draw_context.drawinfo.start.offset.over = 0;
2188 draw_context.drawinfo.start.offset.middle = 0;
2189 draw_context.drawinfo.start.offset.under = 0;
2190 draw_context.drawinfo.end.offset.over = 0;
2191 draw_context.drawinfo.end.offset.middle = 0;
2192 draw_context.drawinfo.end.offset.under = 0;
2193#if 0
2194 /* Jump over draw if we are at the same x position */
2195 if(x == hashed_process_data->x.over)
2196 {
2197 /* jump */
2198 } else {
2199 draw_context.drawinfo.start.x = hashed_process_data->x.over;
2200 /* Draw the line */
2201 PropertiesLine prop_line = prepare_execmode_line(process);
2202 draw_line((void*)&prop_line, (void*)&draw_context);
2203
2204 hashed_process_data->x.over = x;
2205 }
2206#endif //0
2207
2208 if(unlikely(x == hashed_process_data->x.middle &&
2209 hashed_process_data->x.middle_used)) {
2210#if 0 /* do not mark closure : not missing information */
2211 if(hashed_process_data->x.middle_marked == FALSE) {
2212 /* Draw collision indicator */
2213 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
2214 gdk_draw_point(drawing->pixmap,
2215 drawing->gc,
2216 x,
2217 y+(height/2)-3);
2218 hashed_process_data->x.middle_marked = TRUE;
2219 }
2220#endif //0
2221 /* Jump */
2222 } else {
2223 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
2224 /* Draw the line */
2225 PropertiesLine prop_line = prepare_s_e_line(process);
2226 draw_line((void*)&prop_line, (void*)&draw_context);
2227
2228 /* become the last x position */
2229 if(likely(x != hashed_process_data->x.middle)) {
2230 hashed_process_data->x.middle = x;
2231 /* but don't use the pixel */
2232 hashed_process_data->x.middle_used = FALSE;
2233
2234 /* Calculate the next good time */
2235 convert_pixels_to_time(width, x+1, time_window,
2236 &hashed_process_data->next_good_time);
2237 }
2238 }
2239 }
2240 }
2241 }
2242 return;
2243}
2244
2245int before_chunk(void *hook_data, void *call_data)
2246{
2247 EventsRequest *events_request = (EventsRequest*)hook_data;
2248 LttvTracesetState *tss = (LttvTracesetState*)call_data;
2249 ControlFlowData *cfd = (ControlFlowData*)events_request->viewer_data;
2250#if 0
2251 /* Desactivate sort */
2252 gtk_tree_sortable_set_sort_column_id(
2253 GTK_TREE_SORTABLE(cfd->process_list->list_store),
2254 TRACE_COLUMN,
2255 GTK_SORT_ASCENDING);
2256#endif //0
2257 drawing_chunk_begin(events_request, tss);
2258
2259 return 0;
2260}
2261
2262int before_request(void *hook_data, void *call_data)
2263{
2264 EventsRequest *events_request = (EventsRequest*)hook_data;
2265 LttvTracesetState *tss = (LttvTracesetState*)call_data;
2266
2267 drawing_data_request_begin(events_request, tss);
2268
2269 return 0;
2270}
2271
2272
2273/*
2274 * after request is necessary in addition of after chunk in order to draw
2275 * lines until the end of the screen. after chunk just draws lines until
2276 * the last event.
2277 *
2278 * for each process
2279 * draw closing line
2280 * expose
2281 */
2282int after_request(void *hook_data, void *call_data)
2283{
2284 EventsRequest *events_request = (EventsRequest*)hook_data;
2285 ControlFlowData *control_flow_data = events_request->viewer_data;
2286 LttvTracesetState *tss = (LttvTracesetState*)call_data;
2287
2288 ProcessList *process_list = control_flow_data->process_list;
2289 LttTime end_time = events_request->end_time;
2290
2291 ClosureData closure_data;
2292 closure_data.events_request = (EventsRequest*)hook_data;
2293 closure_data.tss = tss;
2294 closure_data.end_time = end_time;
2295
2296 TimeWindow time_window =
2297 lttvwindow_get_time_window(control_flow_data->tab);
2298 guint width = control_flow_data->drawing->width;
2299 convert_time_to_pixels(
2300 time_window,
2301 end_time,
2302 width,
2303 &closure_data.x_end);
2304
2305
2306 /* Draw last items */
2307 g_hash_table_foreach(process_list->process_hash, draw_closure,
2308 (void*)&closure_data);
2309
2310
2311 /* Request expose */
2312 drawing_request_expose(events_request, tss, end_time);
2313 return 0;
2314}
2315
2316/*
2317 * for each process
2318 * draw closing line
2319 * expose
2320 */
2321int after_chunk(void *hook_data, void *call_data)
2322{
2323 EventsRequest *events_request = (EventsRequest*)hook_data;
2324 ControlFlowData *control_flow_data = events_request->viewer_data;
2325 LttvTracesetState *tss = (LttvTracesetState*)call_data;
2326 LttvTracesetContext *tsc = (LttvTracesetContext*)call_data;
2327 LttvTracefileContext *tfc = lttv_traceset_context_get_current_tfc(tsc);
2328 LttTime end_time;
2329
2330 ProcessList *process_list = control_flow_data->process_list;
2331
2332 g_free(process_list->current_hash_data);
2333 process_list->current_hash_data = NULL;
2334
2335 if(tfc != NULL)
2336 end_time = LTT_TIME_MIN(tfc->timestamp, events_request->end_time);
2337 else /* end of traceset, or position now out of request : end */
2338 end_time = events_request->end_time;
2339
2340 ClosureData closure_data;
2341 closure_data.events_request = (EventsRequest*)hook_data;
2342 closure_data.tss = tss;
2343 closure_data.end_time = end_time;
2344
2345 TimeWindow time_window =
2346 lttvwindow_get_time_window(control_flow_data->tab);
2347 guint width = control_flow_data->drawing->width;
2348 convert_time_to_pixels(
2349 time_window,
2350 end_time,
2351 width,
2352 &closure_data.x_end);
2353
2354 /* Draw last items */
2355 g_hash_table_foreach(process_list->process_hash, draw_closure,
2356 (void*)&closure_data);
2357#if 0
2358 /* Reactivate sort */
2359 gtk_tree_sortable_set_sort_column_id(
2360 GTK_TREE_SORTABLE(control_flow_data->process_list->list_store),
2361 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
2362 GTK_SORT_ASCENDING);
2363
2364 update_index_to_pixmap(control_flow_data->process_list);
2365 /* Request a full expose : drawing scrambled */
2366 gtk_widget_queue_draw(control_flow_data->drawing->drawing_area);
2367#endif //0
2368 /* Request expose (updates damages zone also) */
2369 drawing_request_expose(events_request, tss, end_time);
2370
2371 return 0;
2372}
2373
This page took 0.028957 seconds and 4 git commands to generate.