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