Remove reference to thread brand
[lttv.git] / lttv / modules / gui / controlflow / eventhooks.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Mathieu Desnoyers
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
19
20 /*****************************************************************************
21 * Hooks to be called by the main window *
22 *****************************************************************************/
23
24
25 /* Event hooks are the drawing hooks called during traceset read. They draw the
26 * icons, text, lines and background color corresponding to the events read.
27 *
28 * Two hooks are used for drawing : before_schedchange and after_schedchange hooks. The
29 * before_schedchange is called before the state update that occurs with an event and
30 * the after_schedchange hook is called after this state update.
31 *
32 * The before_schedchange hooks fulfill the task of drawing the visible objects that
33 * corresponds to the data accumulated by the after_schedchange hook.
34 *
35 * The after_schedchange hook accumulates the data that need to be shown on the screen
36 * (items) into a queue. Then, the next before_schedchange hook will draw what that
37 * queue contains. That's the Right Way (TM) of drawing items on the screen,
38 * because we need to draw the background first (and then add icons, text, ...
39 * over it), but we only know the length of a background region once the state
40 * corresponding to it is over, which happens to be at the next before_schedchange
41 * hook.
42 *
43 * We also have a hook called at the end of a chunk to draw the information left
44 * undrawn in each process queue. We use the current time as end of
45 * line/background.
46 */
47
48 #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 <lttv/lttv.h>
63 #include <lttv/hook.h>
64 #include <lttv/state.h>
65 #include <lttvwindow/lttvwindow.h>
66 #include <lttvwindow/lttvwindowtraces.h>
67 #include <lttvwindow/support.h>
68
69
70 #include "eventhooks.h"
71 #include "cfv.h"
72 #include "processlist.h"
73 #include "drawing.h"
74
75
76 #define MAX_PATH_LEN 256
77 #define STATE_LINE_WIDTH 8
78 #define COLLISION_POSITION(height) (((height - STATE_LINE_WIDTH)/2) -3)
79
80 extern GSList *g_legend_list;
81
82
83 /* Action to do when background computation completed.
84 *
85 * Wait for all the awaited computations to be over.
86 */
87
88 static gint background_ready(void *hook_data, void *call_data)
89 {
90 ControlFlowData *control_flow_data = (ControlFlowData *)hook_data;
91
92 control_flow_data->background_info_waiting--;
93
94 if(control_flow_data->background_info_waiting == 0) {
95 g_message("control flow viewer : background computation data ready.");
96
97 drawing_clear(control_flow_data->drawing);
98 processlist_clear(control_flow_data->process_list);
99 gtk_widget_set_size_request(
100 control_flow_data->drawing->drawing_area,
101 -1, processlist_get_height(control_flow_data->process_list));
102 redraw_notify(control_flow_data, NULL);
103 }
104
105 return 0;
106 }
107
108
109 /* Request background computation. Verify if it is in progress or ready first.
110 * Only for each trace in the tab's traceset.
111 */
112
113 static void request_background_data(ControlFlowData *control_flow_data)
114 {
115
116 LttvTraceset *ts = lttvwindow_get_traceset(control_flow_data->tab);
117 gint num_traces = lttv_traceset_number(ts);
118 gint i;
119 LttvTrace *trace;
120 LttvTraceState *tstate;
121
122 LttvHooks *background_ready_hook = lttv_hooks_new();
123 lttv_hooks_add(background_ready_hook, background_ready, control_flow_data,
124 LTTV_PRIO_DEFAULT);
125 control_flow_data->background_info_waiting = 0;
126
127 for(i=0;i<num_traces;i++) {
128 trace = lttv_traceset_get(ts, i);
129
130 if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace)==FALSE
131 && !ts->has_precomputed_states) {
132
133 if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"),
134 trace) == FALSE) {
135 /* We first remove requests that could have been done for the same
136 * information. Happens when two viewers ask for it before servicing
137 * starts.
138 */
139 if(!lttvwindowtraces_background_request_find(trace, "state"))
140 lttvwindowtraces_background_request_queue(
141 main_window_get_widget(control_flow_data->tab), trace, "state");
142 lttvwindowtraces_background_notify_queue(control_flow_data,
143 trace,
144 ltt_time_infinite,
145 NULL,
146 background_ready_hook);
147 control_flow_data->background_info_waiting++;
148 } else { /* in progress */
149
150 lttvwindowtraces_background_notify_current(control_flow_data,
151 trace,
152 ltt_time_infinite,
153 NULL,
154 background_ready_hook);
155 control_flow_data->background_info_waiting++;
156 }
157 } else {
158 /* Data ready. By its nature, this viewer doesn't need to have
159 * its data ready hook called there, because a background
160 * request is always linked with a redraw.
161 */
162 }
163
164 }
165
166 lttv_hooks_destroy(background_ready_hook);
167 }
168
169
170
171
172 /**
173 * Event Viewer's constructor hook
174 *
175 * This constructor is given as a parameter to the menuitem and toolbar button
176 * registration. It creates the list.
177 * @param tab A pointer to the parent tab.
178 * @return The widget created.
179 */
180 GtkWidget *
181 h_guicontrolflow(LttvPlugin *plugin)
182 {
183 LttvPluginTab *ptab = LTTV_PLUGIN_TAB(plugin);
184 Tab *tab = ptab->tab;
185 g_info("h_guicontrolflow, %p", tab);
186 ControlFlowData *control_flow_data = guicontrolflow(ptab);
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
214 int event_selected_hook(void *hook_data, void *call_data)
215 {
216 guint *event_number = (guint*) call_data;
217
218 g_debug("DEBUG : event selected by main window : %u", *event_number);
219
220 return 0;
221 }
222
223 /* Function that selects the color of status&exemode line */
224 static inline PropertiesLine prepare_s_e_line(LttvProcessState *process)
225 {
226 PropertiesLine prop_line;
227 prop_line.line_width = STATE_LINE_WIDTH;
228 prop_line.style = GDK_LINE_SOLID;
229 prop_line.y = MIDDLE;
230 //GdkColormap *colormap = gdk_colormap_get_system();
231
232 if(process->state->s == LTTV_STATE_RUN) {
233 if(process->state->t == LTTV_STATE_USER_MODE)
234 prop_line.color = drawing_colors[COL_RUN_USER_MODE];
235 else if(process->state->t == LTTV_STATE_SYSCALL)
236 prop_line.color = drawing_colors[COL_RUN_SYSCALL];
237 else if(process->state->t == LTTV_STATE_TRAP)
238 prop_line.color = drawing_colors[COL_RUN_TRAP];
239 else if(process->state->t == LTTV_STATE_IRQ)
240 prop_line.color = drawing_colors[COL_RUN_IRQ];
241 else if(process->state->t == LTTV_STATE_SOFT_IRQ)
242 prop_line.color = drawing_colors[COL_RUN_SOFT_IRQ];
243 else if(process->state->t == LTTV_STATE_MAYBE_SYSCALL)
244 prop_line.color = drawing_colors[COL_MODE_UNKNOWN];
245 else if(process->state->t == LTTV_STATE_MAYBE_USER_MODE)
246 prop_line.color = drawing_colors[COL_MODE_UNKNOWN];
247 else if(process->state->t == LTTV_STATE_MAYBE_TRAP)
248 prop_line.color = drawing_colors[COL_MODE_UNKNOWN];
249 else if(process->state->t == LTTV_STATE_MODE_UNKNOWN)
250 prop_line.color = drawing_colors[COL_MODE_UNKNOWN];
251 else
252 g_assert(FALSE); /* RUNNING MODE UNKNOWN */
253 } else if(process->state->s == LTTV_STATE_WAIT) {
254 /* We don't show if we wait while in user mode, trap, irq or syscall */
255 prop_line.color = drawing_colors[COL_WAIT];
256 } else if(process->state->s == LTTV_STATE_WAIT_CPU) {
257 /* We don't show if we wait for CPU while in user mode, trap, irq
258 * or syscall */
259 prop_line.color = drawing_colors[COL_WAIT_CPU];
260 } else if(process->state->s == LTTV_STATE_ZOMBIE) {
261 prop_line.color = drawing_colors[COL_ZOMBIE];
262 } else if(process->state->s == LTTV_STATE_WAIT_FORK) {
263 prop_line.color = drawing_colors[COL_WAIT_FORK];
264 } else if(process->state->s == LTTV_STATE_EXIT) {
265 prop_line.color = drawing_colors[COL_EXIT];
266 } else if(process->state->s == LTTV_STATE_UNNAMED) {
267 prop_line.color = drawing_colors[COL_UNNAMED];
268 } else if(process->state->s == LTTV_STATE_DEAD) {
269 prop_line.color = drawing_colors[COL_DEAD];
270 } else {
271 g_critical("unknown state : %s", g_quark_to_string(process->state->s));
272 g_assert(FALSE); /* UNKNOWN STATE */
273 }
274
275 return prop_line;
276
277 }
278
279 HashedProcessData *get_hashed_process_data(ControlFlowData *control_flow_data,
280 LttvProcessState *process,
281 guint pid,
282 guint trace_num)
283 {
284 HashedProcessData *hashed_process_data = NULL;
285 ProcessList *process_list = control_flow_data->process_list;
286 LttTime birth = process->creation_time;
287 guint pl_height = 0;
288
289 hashed_process_data = processlist_get_process_data(process_list,
290 pid,
291 process->cpu,
292 &birth,
293 trace_num);
294 if(hashed_process_data == NULL)
295 {
296 g_assert(pid == 0 || pid != process->ppid);
297 ProcessInfo *process_info;
298 Drawing_t *drawing = control_flow_data->drawing;
299 /* Process not present */
300 processlist_add(process_list,
301 drawing,
302 pid,
303 process->tgid,
304 process->cpu,
305 process->ppid,
306 &birth,
307 trace_num,
308 process->name,
309 &pl_height,
310 &process_info,
311 &hashed_process_data);
312 gtk_widget_set_size_request(drawing->drawing_area,
313 -1,
314 pl_height);
315 gtk_widget_queue_draw(drawing->drawing_area);
316 }
317 return hashed_process_data;
318 }
319
320 void init_drawing_context(DrawContext *draw_context,
321 HashedProcessData *hashed_process_data,
322 Drawing_t *drawing,
323 guint x
324 )
325 {
326 draw_context->drawable = hashed_process_data->pixmap;
327 draw_context->gc = drawing->gc;
328 draw_context->pango_layout = drawing->pango_layout;
329 draw_context->drawinfo.start.x = hashed_process_data->x.middle;
330 draw_context->drawinfo.end.x = x;
331
332 draw_context->drawinfo.y.over = 1;
333 draw_context->drawinfo.y.middle = (hashed_process_data->height/2);
334 draw_context->drawinfo.y.under = hashed_process_data->height;
335
336 draw_context->drawinfo.start.offset.over = 0;
337 draw_context->drawinfo.start.offset.middle = 0;
338 draw_context->drawinfo.start.offset.under = 0;
339 draw_context->drawinfo.end.offset.over = 0;
340 draw_context->drawinfo.end.offset.middle = 0;
341 draw_context->drawinfo.end.offset.under = 0;
342
343 }
344
345 void draw_state_line(HashedProcessData *hashed_process_data,
346 LttvProcessState *process,
347 Drawing_t *drawing,
348 guint x,
349 TimeWindow time_window)
350 {
351 DrawContext draw_context;
352 guint width = drawing->width;
353
354 init_drawing_context(&draw_context,
355 hashed_process_data,
356 drawing,
357 x);
358
359
360 /* Draw the line */
361 PropertiesLine prop_line = prepare_s_e_line(process);
362 draw_line((void*)&prop_line, (void*)&draw_context);
363
364 /* become the last x position */
365 hashed_process_data->x.middle = x;
366 hashed_process_data->x.middle_used = TRUE;
367 hashed_process_data->x.middle_marked = FALSE;
368
369 /* Calculate the next good time */
370 convert_pixels_to_time(width, x+1, time_window,
371 &hashed_process_data->next_good_time);
372 }
373
374
375 void draw_state_items(ControlFlowData *control_flow_data,
376 HashedProcessData *hashed_process_data,
377 LttvProcessState *process,
378 LttTime evtime )
379 {
380
381
382 if(likely(ltt_time_compare(hashed_process_data->next_good_time,
383 evtime) > 0))
384 {
385 if(unlikely(hashed_process_data->x.middle_marked == FALSE)) {
386 TimeWindow time_window =
387 lttvwindow_get_time_window(control_flow_data->tab);
388
389 #ifdef EXTRA_CHECK
390 if(ltt_time_compare(evtime, time_window.start_time) == -1
391 || ltt_time_compare(evtime, time_window.end_time) == 1)
392 return FALSE;
393 #endif //EXTRA_CHECK
394 Drawing_t *drawing = control_flow_data->drawing;
395 guint width = drawing->width;
396 guint x;
397 convert_time_to_pixels(
398 time_window,
399 evtime,
400 width,
401 &x);
402
403 /* Draw collision indicator */
404 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
405 gdk_draw_point(hashed_process_data->pixmap,
406 drawing->gc,
407 x,
408 COLLISION_POSITION(hashed_process_data->height));
409 hashed_process_data->x.middle_marked = TRUE;
410 }
411 } else {
412 TimeWindow time_window =
413 lttvwindow_get_time_window(control_flow_data->tab);
414
415 #ifdef EXTRA_CHECK
416 if(ltt_time_compare(evtime, time_window.start_time) == -1
417 || ltt_time_compare(evtime, time_window.end_time) == 1)
418 return FALSE;
419 #endif //EXTRA_CHECK
420 Drawing_t *drawing = control_flow_data->drawing;
421 guint width = drawing->width;
422 guint x;
423
424 convert_time_to_pixels(
425 time_window,
426 evtime,
427 width,
428 &x);
429
430
431 /* Jump over draw if we are at the same x position */
432 if(unlikely(x == hashed_process_data->x.middle &&
433 hashed_process_data->x.middle_used))
434 {
435 if(unlikely(hashed_process_data->x.middle_marked == FALSE)) {
436 /* Draw collision indicator */
437 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
438 gdk_draw_point(hashed_process_data->pixmap,
439 drawing->gc,
440 x,
441 COLLISION_POSITION(hashed_process_data->height));
442 hashed_process_data->x.middle_marked = TRUE;
443 }
444 /* jump */
445 } else {
446
447 draw_state_line(hashed_process_data,
448 process,
449 drawing,
450 x,
451 time_window);
452 }
453 }
454 }
455
456
457 /* Before try-wake-up hook. A process is being woken; we need to draw its line up to this point in time
458 in that colour. This is basically like exec-state, but the change applies to a process other than that
459 which is currently running. */
460
461 int before_trywakeup_hook(void *hook_data, void *call_data)
462 {
463
464 LttvEvent *event;
465
466 event = (LttvEvent *) call_data;
467 if (strcmp(lttv_traceset_get_name_from_event(event),"sched_wakeup") != 0)
468 return FALSE;
469
470 ControlFlowData *control_flow_data = (ControlFlowData*)hook_data;
471
472 LttvTraceState *ts = event->state;;
473
474
475 LttTime evtime = lttv_event_get_timestamp(event);
476 #ifdef BABEL_CLEANUP
477 LttvFilter *filter = control_flow_data->filter;
478 #endif
479
480 guint woken_pid;
481 gint woken_cpu;
482
483 woken_pid = lttv_event_get_long(event, "tid");
484 woken_cpu = lttv_event_get_long(event, "target_cpu");
485
486 #ifdef BABEL_CLEANUP
487 if(!filter || !filter->head ||
488 lttv_filter_tree_parse(filter->head,e,tfc->tf,
489 tfc->t_context->t,tfc,NULL,NULL)) {
490 #else
491 {
492 #endif
493 /* First, check if the woken process is in the state computation
494 * process list. If it is there, that means we must add it right now and
495 * draw items from the beginning of the read for it. If it is not
496 * present, it's a new process and it was not present : it will
497 * be added after the state update. TOCHECK: What does that last para mean? */
498 guint trace_num = lttv_traceset_get_trace_index_from_event(event);
499 LttvProcessState *process = lttv_state_find_process(ts, woken_cpu, woken_pid);
500
501 if(process != NULL) {
502 /* Well, the woken process existed : we must get it in the process hash
503 * or add it, and draw its items.
504 */
505 /* Add process to process list (if not present) */
506
507 HashedProcessData *hashed_process_data = get_hashed_process_data(control_flow_data, process, woken_pid, trace_num);
508
509 /* Now, the process is in the state hash and our own process hash.
510 * We definitely can draw the items related to the ending state.
511 */
512
513 draw_state_items(control_flow_data,
514 hashed_process_data,
515 process,
516 evtime );
517
518 }
519 }
520
521
522
523
524 return 0;
525
526 }
527
528 /* before_schedchange_hook
529 *
530 * This function basically draw lines and icons. Two types of lines are drawn :
531 * one small (3 pixels?) representing the state of the process and the second
532 * type is thicker (10 pixels?) representing on which CPU a process is running
533 * (and this only in running state).
534 *
535 * Extremums of the lines :
536 * x_min : time of the last event context for this process kept in memory.
537 * x_max : time of the current event.
538 * y : middle of the process in the process list. The process is found in the
539 * list, therefore is it's position in pixels.
540 *
541 * The choice of lines'color is defined by the context of the last event for this
542 * process.
543 */
544
545
546 int before_schedchange_hook(void *hook_data, void *call_data)
547 {
548 LttvEvent *event;
549 guint cpu;
550 LttvTraceState *ts;
551 LttvProcessState *process;
552
553 //LttvProcessState *old_process = ts->running_process[cpu];
554
555 guint pid_in, pid_out;
556 gint64 state_out;
557 LttTime evtime;
558 event = (LttvEvent *) call_data;
559 if (strcmp(lttv_traceset_get_name_from_event(event),"sched_switch") != 0)
560 return FALSE;
561
562 ControlFlowData *control_flow_data = (ControlFlowData*)hook_data;
563
564
565 /* we are in a schedchange, before the state update. We must draw the
566 * items corresponding to the state before it changes : now is the right
567 * time to do it.
568 */
569 cpu = lttv_traceset_get_cpuid_from_event(event);
570 ts = event->state;
571
572 pid_out = lttv_event_get_long(event, "prev_tid");
573 pid_in = lttv_event_get_long(event, "next_tid");
574 state_out = lttv_event_get_long(event, "prev_state");
575 guint trace_number = lttv_traceset_get_trace_index_from_event(event);
576
577 process = lttv_state_find_process(ts,cpu,pid_out);
578 evtime = lttv_event_get_timestamp(event);
579 /* For the pid_out */
580 /* First, check if the current process is in the state computation
581 * process list. If it is there, that means we must add it right now and
582 * draw items from the beginning of the read for it. If it is not
583 * present, it's a new process and it was not present : it will
584 * be added after the state update. */
585
586 /* unknown state, bad current pid */
587
588 if(process != NULL) {
589 /* Well, the process_out existed : we must get it in the process hash
590 * or add it, and draw its items.
591 */
592 /* Add process to process list (if not present) */
593
594 HashedProcessData *hashed_process_data = get_hashed_process_data(control_flow_data, process, pid_out, trace_number);
595
596 /* Now, the process is in the state hash and our own process hash.
597 * We definitely can draw the items related to the ending state.
598 */
599
600 draw_state_items(control_flow_data,
601 hashed_process_data,
602 process,
603 evtime );
604 }
605
606 /* For the pid_in */
607 /* First, check if the current process is in the state computation
608 * process list. If it is there, that means we must add it right now and
609 * draw items from the beginning of the read for it. If it is not
610 * present, it's a new process and it was not present : it will
611 * be added after the state update. */
612 process = lttv_state_find_process(ts,cpu,pid_in);
613
614 if(process != NULL) {
615 /* Well, the process existed : we must get it in the process hash
616 * or add it, and draw its items.
617 */
618 /* Add process to process list (if not present) */
619
620 HashedProcessData *hashed_process_data = get_hashed_process_data(control_flow_data, process, pid_in, trace_number);
621
622 //We could set the current process and hash here, but will be done
623 //by after schedchange hook
624
625 /* Now, the process is in the state hash and our own process hash.
626 * We definitely can draw the items related to the ending state.
627 */
628 draw_state_items(control_flow_data,
629 hashed_process_data,
630 process,
631 evtime );
632
633 } else
634 g_warning("Cannot find pid_in in schedchange %u at %u.%u", pid_in, evtime.tv_sec, evtime.tv_nsec);
635 #ifdef BABEL_CLEANUP
636 tfc->target_pid = target_pid_saved;
637 #endif //babel_cleanup
638 return 0;
639
640
641
642
643 /* Text dump */
644 #ifdef DONTSHOW
645 GString *string = g_string_new("");;
646 gboolean field_names = TRUE, state = TRUE;
647
648 lttv_event_to_string(e, tfc->tf, string, TRUE, field_names, tfs);
649 g_string_append_printf(string,"\n");
650
651 if(state) {
652 g_string_append_printf(string, " %s",
653 g_quark_to_string(tfs->process->state->s));
654 }
655
656 g_info("%s",string->str);
657
658 g_string_free(string, TRUE);
659
660 /* End of text dump */
661 #endif //DONTSHOW
662
663 }
664
665 /* after_schedchange_hook
666 *
667 * The draw after hook is called by the reading API to have a
668 * particular event drawn on the screen.
669 * @param hook_data ControlFlowData structure of the viewer.
670 * @param call_data Event context.
671 *
672 * This function adds items to be drawn in a queue for each process.
673 *
674 */
675 int after_schedchange_hook(void *hook_data, void *call_data)
676 {
677 LttvEvent *event;
678
679 event = (LttvEvent *) call_data;
680
681 if (strcmp(lttv_traceset_get_name_from_event(event),"sched_switch") != 0)
682 return FALSE;
683
684 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
685
686
687 LttvTraceState *ts = event->state;
688
689 #ifdef BABEL_CLEANUP
690 LttvFilter *filter = control_flow_data->filter;
691 #endif
692 LttTime evtime = lttv_event_get_timestamp(event);
693
694 /* Add process to process list (if not present) */
695 LttvProcessState *process_in;
696 HashedProcessData *hashed_process_data_in = NULL;
697
698 ProcessList *process_list = control_flow_data->process_list;
699
700 guint pid_in;
701 {
702 pid_in = lttv_event_get_long(event, "next_tid");
703 }
704
705 #ifdef BABEL_CLEANUP
706 if(!filter || !filter->head ||
707 lttv_filter_tree_parse(filter->head,e,tfc->tf,
708 tfc->t_context->t,tfc,NULL,NULL)) {
709 #else
710 {
711 #endif
712 /* Find process pid_in in the list... */
713 //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in);
714 //process_in = tfs->process;
715 guint cpu = lttv_traceset_get_cpuid_from_event(event);
716 guint trace_num = lttv_traceset_get_trace_index_from_event(event);
717 process_in = ts->running_process[cpu];
718 /* It should exist, because we are after the state update. */
719 #ifdef EXTRA_CHECK
720 g_assert(process_in != NULL);
721 #endif //EXTRA_CHECK
722 hashed_process_data_in = get_hashed_process_data(control_flow_data, process_in, pid_in, trace_num);
723
724 /* Set the current process */
725 process_list->current_hash_data[trace_num][process_in->cpu] =
726 hashed_process_data_in;
727
728 if(ltt_time_compare(hashed_process_data_in->next_good_time,
729 evtime) <= 0)
730 {
731 TimeWindow time_window =
732 lttvwindow_get_time_window(control_flow_data->tab);
733
734 #ifdef EXTRA_CHECK
735 if(ltt_time_compare(evtime, time_window.start_time) == -1
736 || ltt_time_compare(evtime, time_window.end_time) == 1)
737 return FALSE;
738 #endif //EXTRA_CHECK
739 Drawing_t *drawing = control_flow_data->drawing;
740 guint width = drawing->width;
741 guint new_x;
742
743 convert_time_to_pixels(
744 time_window,
745 evtime,
746 width,
747 &new_x);
748
749 if(hashed_process_data_in->x.middle != new_x) {
750 hashed_process_data_in->x.middle = new_x;
751 hashed_process_data_in->x.middle_used = FALSE;
752 hashed_process_data_in->x.middle_marked = FALSE;
753 }
754 }
755 }
756
757 return 0;
758 }
759
760
761
762
763 /* before_execmode_hook
764 *
765 * This function basically draw lines and icons. Two types of lines are drawn :
766 * one small (3 pixels?) representing the state of the process and the second
767 * type is thicker (10 pixels?) representing on which CPU a process is running
768 * (and this only in running state).
769 *
770 * Extremums of the lines :
771 * x_min : time of the last event context for this process kept in memory.
772 * x_max : time of the current event.
773 * y : middle of the process in the process list. The process is found in the
774 * list, therefore is it's position in pixels.
775 *
776 * The choice of lines'color is defined by the context of the last event for this
777 * process.
778 */
779
780
781 int before_execmode_hook(void *hook_data, void *call_data)
782 {
783 LttvEvent *event;
784 guint cpu;
785 guint pid = 0;
786 LttvTraceState *ts;
787 LttvProcessState *process;
788
789 /* we are in a execmode, before the state update. We must draw the
790 * items corresponding to the state before it changes : now is the right
791 * time to do it.
792 */
793
794 event = (LttvEvent *) call_data;
795 if ((strncmp(lttv_traceset_get_name_from_event(event),"sys_", sizeof("sys_") - 1) == 0)
796 ||(strcmp(lttv_traceset_get_name_from_event(event),"exit_syscall") == 0)
797 ||(strncmp(lttv_traceset_get_name_from_event(event),"irq_handler_",sizeof("irq_handler_") -1) == 0)
798 ||(strncmp(lttv_traceset_get_name_from_event(event),"softirq_", sizeof("softirq_") - 1) == 0)) {
799
800 LttTime evtime = lttv_event_get_timestamp(event);
801 ControlFlowData *control_flow_data = (ControlFlowData*)hook_data;
802 /* For the pid */
803 LttvTraceset *traceSet = lttvwindow_get_traceset(control_flow_data->tab);
804
805 cpu = lttv_traceset_get_cpuid_from_event(event);
806 ts = event->state;
807
808 guint trace_number = lttv_traceset_get_trace_index_from_event(event);
809
810 //TODO ybrosseau 2013-04-09 validate that using the running process is the right choice
811 //process = lttv_state_find_process(ts ,cpu ,pid);
812 process = ts->running_process[cpu];
813
814 g_assert(process != NULL);
815
816 guint pid = process->pid;
817
818 /* Well, the process_out existed : we must get it in the process hash
819 * or add it, and draw its items.
820 */
821 /* Add process to process list (if not present) */
822 HashedProcessData *hashed_process_data = NULL;
823 ProcessList *process_list = control_flow_data->process_list;
824 if(process_list->current_hash_data == NULL){//TODO fdeslauriers 2012-07-17 : should not be necessary
825 return 0;
826 }
827
828 if(likely(process_list->current_hash_data[trace_number][cpu] != NULL)) {
829 hashed_process_data = process_list->current_hash_data[trace_number][cpu];
830 } else {
831 hashed_process_data = get_hashed_process_data(control_flow_data,
832 process, pid, trace_number);
833
834 /* Set the current process */
835 process_list->current_hash_data[trace_number][process->cpu] =
836 hashed_process_data;
837 }
838
839 /* Now, the process is in the state hash and our own process hash.
840 * We definitely can draw the items related to the ending state.
841 */
842
843 draw_state_items(control_flow_data,
844 hashed_process_data,
845 process,
846 evtime );
847 }
848
849 return 0;
850
851 }
852
853 /* before_process_exit_hook
854 *
855 * Draw lines for process event.
856 *
857 * @param hook_data ControlFlowData structure of the viewer.
858 * @param call_data Event context.
859 *
860 * This function adds items to be drawn in a queue for each process.
861 *
862 */
863
864
865 int before_process_exit_hook(void *hook_data, void *call_data)
866 {
867
868 LttvEvent *event;
869
870 event = (LttvEvent *) call_data;
871 if (strcmp(lttv_traceset_get_name_from_event(event),
872 "sched_process_exit") != 0)
873 return FALSE;
874
875
876 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
877 LttvTraceState *ts = event->state;
878
879 #ifdef BABEL_CLEANUP
880 LttvFilter *filter = control_flow_data->filter;
881 if(filter != NULL && filter->head != NULL)
882 if(!lttv_filter_tree_parse(filter->head,e,tfc->tf,
883 tfc->t_context->t,tfc,NULL,NULL))
884 return FALSE;
885 #endif
886
887 LttTime evtime = lttv_event_get_timestamp(event);
888
889 /* Add process to process list (if not present) */
890 //LttvProcessState *process = tfs->process;
891 guint cpu = lttv_traceset_get_cpuid_from_event(event);
892 guint trace_num = lttv_traceset_get_trace_index_from_event(event);
893
894 LttvProcessState *process = ts->running_process[cpu];
895 guint pid = process->pid;
896 HashedProcessData *hashed_process_data = NULL;
897
898 ProcessList *process_list = control_flow_data->process_list;
899
900 g_assert(process != NULL);
901
902 if(likely(process_list->current_hash_data[trace_num][cpu] != NULL)) {
903 hashed_process_data = process_list->current_hash_data[trace_num][cpu];
904 } else {
905 hashed_process_data = get_hashed_process_data(control_flow_data,
906 process, pid, trace_num);
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 draw_state_items(control_flow_data,
914 hashed_process_data,
915 process,
916 evtime);
917
918 return 0;
919
920 }
921
922
923
924 /* before_process_release_hook
925 *
926 * Draw lines for process event.
927 *
928 * @param hook_data ControlFlowData structure of the viewer.
929 * @param call_data Event context.
930 *
931 * This function adds items to be drawn in a queue for each process.
932 *
933 */
934
935
936 int before_process_release_hook(void *hook_data, void *call_data)
937 {
938
939 LttvEvent *event;
940
941 event = (LttvEvent *) call_data;
942
943 if (strcmp(lttv_traceset_get_name_from_event(event),"sched_process_free") != 0)
944 return FALSE;
945
946 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
947
948
949 LttvTraceState *ts = event->state;
950
951 #ifdef BABEL_CLEANUP
952 LttvFilter *filter = control_flow_data->filter;
953 if(filter != NULL && filter->head != NULL)
954 if(!lttv_filter_tree_parse(filter->head,e,tfc->tf,
955 tfc->t_context->t,tfc,NULL,NULL))
956 return FALSE;
957 #endif
958 LttTime evtime = lttv_event_get_timestamp(event);
959
960
961 guint trace_num = lttv_traceset_get_trace_index_from_event(event);
962
963 guint pid;
964 {
965 pid = lttv_event_get_long(event, "tid");
966 }
967
968 /* Add process to process list (if not present) */
969 /* Don't care about the process if it's not in the state hash already :
970 * that means a process that has never done anything in the trace and
971 * unknown suddently gets destroyed : no state meaningful to show. */
972 LttvProcessState *process = lttv_state_find_process(ts, ANY_CPU, pid);
973
974 if(process != NULL) {
975 LttTime birth;
976 HashedProcessData *hashed_process_data = NULL;
977
978 ProcessList *process_list = control_flow_data->process_list;
979
980 birth = process->creation_time;
981
982 /* Cannot use current process : this event happens on another process,
983 * action done by the parent. */
984 hashed_process_data = processlist_get_process_data(process_list,
985 pid,
986 process->cpu,
987 &birth,
988 trace_num);
989 if(unlikely(hashed_process_data == NULL))
990 /*
991 * Process already been scheduled out EXIT_DEAD, not in the process list
992 * anymore. Just return.
993 */
994 return FALSE;
995
996 /* Now, the process is in the state hash and our own process hash.
997 * We definitely can draw the items related to the ending state.
998 */
999
1000 draw_state_items(control_flow_data,
1001 hashed_process_data,
1002 process,
1003 evtime);
1004 }
1005 return 0;
1006 }
1007
1008
1009
1010
1011
1012 /* after_process_fork_hook
1013 *
1014 * Create the processlist entry for the child process. Put the last
1015 * position in x at the current time value.
1016 *
1017 * @param hook_data ControlFlowData structure of the viewer.
1018 * @param call_data Event context.
1019 *
1020 * This function adds items to be drawn in a queue for each process.
1021 *
1022 */
1023 int after_process_fork_hook(void *hook_data, void *call_data)
1024 {
1025 LttvEvent *event;
1026
1027 event = (LttvEvent *) call_data;
1028
1029 if (strcmp(lttv_traceset_get_name_from_event(event),"sched_process_fork") != 0)
1030 return FALSE;
1031
1032 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
1033
1034
1035 LttvTraceState *ts = event->state;
1036
1037 #ifdef BABEL_CLEANUP
1038 LttvFilter *filter = control_flow_data->filter;
1039 if(filter != NULL && filter->head != NULL)
1040 if(!lttv_filter_tree_parse(filter->head,e,tfc->tf,
1041 tfc->t_context->t,tfc,NULL,NULL))
1042 return FALSE;
1043 #endif
1044
1045 LttTime evtime = lttv_event_get_timestamp(event);
1046
1047 guint child_pid;
1048 {
1049 child_pid = lttv_event_get_long(event, "child_tid");
1050 }
1051
1052 /* Add process to process list (if not present) */
1053 LttvProcessState *process_child;
1054 HashedProcessData *hashed_process_data_child = NULL;
1055
1056 ProcessList *process_list = control_flow_data->process_list;
1057
1058 /* Find child in the list... */
1059 process_child = lttv_state_find_process(ts, ANY_CPU, child_pid);
1060 /* It should exist, because we are after the state update. */
1061 g_assert(process_child != NULL);
1062
1063 guint trace_num = lttv_traceset_get_trace_index_from_event(event);
1064
1065 /* Cannot use current process, because this action is done by the parent
1066 * on its child. */
1067 hashed_process_data_child = get_hashed_process_data(control_flow_data,
1068 process_child, child_pid, trace_num);
1069
1070
1071 processlist_set_ppid(process_list, process_child->ppid,
1072 hashed_process_data_child);
1073 processlist_set_tgid(process_list, process_child->tgid,
1074 hashed_process_data_child);
1075
1076
1077
1078 if(likely(ltt_time_compare(hashed_process_data_child->next_good_time,
1079 evtime) <= 0))
1080 {
1081 TimeWindow time_window =
1082 lttvwindow_get_time_window(control_flow_data->tab);
1083
1084 #ifdef EXTRA_CHECK
1085 if(ltt_time_compare(evtime, time_window.start_time) == -1
1086 || ltt_time_compare(evtime, time_window.end_time) == 1)
1087 return FALSE;
1088 #endif //EXTRA_CHECK
1089 Drawing_t *drawing = control_flow_data->drawing;
1090 guint width = drawing->width;
1091 guint new_x;
1092 convert_time_to_pixels(
1093 time_window,
1094 evtime,
1095 width,
1096 &new_x);
1097
1098 if(likely(hashed_process_data_child->x.over != new_x)) {
1099 hashed_process_data_child->x.over = new_x;
1100 hashed_process_data_child->x.over_used = FALSE;
1101 hashed_process_data_child->x.over_marked = FALSE;
1102 }
1103 if(likely(hashed_process_data_child->x.middle != new_x)) {
1104 hashed_process_data_child->x.middle = new_x;
1105 hashed_process_data_child->x.middle_used = FALSE;
1106 hashed_process_data_child->x.middle_marked = FALSE;
1107 }
1108 if(likely(hashed_process_data_child->x.under != new_x)) {
1109 hashed_process_data_child->x.under = new_x;
1110 hashed_process_data_child->x.under_used = FALSE;
1111 hashed_process_data_child->x.under_marked = FALSE;
1112 }
1113 }
1114 return FALSE;
1115 }
1116
1117
1118
1119 /* after_process_exit_hook
1120 *
1121 * Create the processlist entry for the child process. Put the last
1122 * position in x at the current time value.
1123 *
1124 * @param hook_data ControlFlowData structure of the viewer.
1125 * @param call_data Event context.
1126 *
1127 * This function adds items to be drawn in a queue for each process.
1128 *
1129 */
1130 int after_process_exit_hook(void *hook_data, void *call_data)
1131 {
1132
1133 LttvEvent *event;
1134
1135 event = (LttvEvent *) call_data;
1136
1137 if (strcmp(lttv_traceset_get_name_from_event(event),"sched_process_exit") != 0)
1138 return FALSE;
1139
1140 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
1141
1142 LttvTraceState *ts = event->state;
1143
1144 #ifdef BABEL_CLEANUP
1145 LttvFilter *filter = control_flow_data->filter;
1146 if(filter != NULL && filter->head != NULL)
1147 if(!lttv_filter_tree_parse(filter->head,e,tfc->tf,
1148 tfc->t_context->t,tfc,NULL,NULL))
1149 return FALSE;
1150 #endif
1151
1152 LttTime evtime = lttv_event_get_timestamp(event);
1153
1154 /* Add process to process list (if not present) */
1155 //LttvProcessState *process = tfs->process;
1156 guint cpu = lttv_traceset_get_cpuid_from_event(event);
1157 guint trace_num = lttv_traceset_get_trace_index_from_event(event);
1158 LttvProcessState *process = ts->running_process[cpu];
1159
1160 /* It should exist, because we are after the state update. */
1161 g_assert(process != NULL);
1162
1163 guint pid = process->pid;
1164 //LttTime birth;
1165 //guint pl_height = 0;
1166 HashedProcessData *hashed_process_data = NULL;
1167
1168 ProcessList *process_list = control_flow_data->process_list;
1169
1170 //birth = process->creation_time;
1171
1172 if(likely(process_list->current_hash_data[trace_num][cpu] != NULL) ){
1173 hashed_process_data = process_list->current_hash_data[trace_num][cpu];
1174 } else {
1175 hashed_process_data = get_hashed_process_data(control_flow_data,
1176 process, pid, trace_num);
1177
1178
1179 /* Set the current process */
1180 process_list->current_hash_data[trace_num][process->cpu] =
1181 hashed_process_data;
1182 }
1183
1184 if(unlikely(ltt_time_compare(hashed_process_data->next_good_time,
1185 evtime) <= 0))
1186 {
1187 TimeWindow time_window =
1188 lttvwindow_get_time_window(control_flow_data->tab);
1189
1190 #ifdef EXTRA_CHECK
1191 if(ltt_time_compare(evtime, time_window.start_time) == -1
1192 || ltt_time_compare(evtime, time_window.end_time) == 1)
1193 return FALSE;
1194 #endif //EXTRA_CHECK
1195 Drawing_t *drawing = control_flow_data->drawing;
1196 guint width = drawing->width;
1197 guint new_x;
1198 convert_time_to_pixels(
1199 time_window,
1200 evtime,
1201 width,
1202 &new_x);
1203 if(unlikely(hashed_process_data->x.middle != new_x)) {
1204 hashed_process_data->x.middle = new_x;
1205 hashed_process_data->x.middle_used = FALSE;
1206 hashed_process_data->x.middle_marked = FALSE;
1207 }
1208 }
1209
1210 return FALSE;
1211 }
1212
1213
1214 /* Get the filename of the process to print */
1215 int after_fs_exec_hook(void *hook_data, void *call_data)
1216 {
1217 #ifdef BABEL_CLEANUP
1218 LttvTraceHook *th = (LttvTraceHook*)hook_data;
1219 EventsRequest *events_request = (EventsRequest*)th->hook_data;
1220 ControlFlowData *control_flow_data = events_request->viewer_data;
1221
1222 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
1223
1224 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
1225
1226 LttvTraceState *ts = (LttvTraceState *)tfc->t_context;
1227
1228 LttEvent *e;
1229 e = ltt_tracefile_get_event(tfc->tf);
1230
1231 LttvFilter *filter = control_flow_data->filter;
1232 if(filter != NULL && filter->head != NULL)
1233 if(!lttv_filter_tree_parse(filter->head,e,tfc->tf,
1234 tfc->t_context->t,tfc,NULL,NULL))
1235 return FALSE;
1236
1237 guint cpu = tfs->cpu;
1238 guint trace_num = ts->parent.index;
1239 LttvProcessState *process = ts->running_process[cpu];
1240 g_assert(process != NULL);
1241
1242 guint pid = process->pid;
1243
1244 /* Well, the process_out existed : we must get it in the process hash
1245 * or add it, and draw its items.
1246 */
1247 /* Add process to process list (if not present) */
1248 guint pl_height = 0;
1249 HashedProcessData *hashed_process_data = NULL;
1250 ProcessList *process_list = control_flow_data->process_list;
1251 LttTime birth = process->creation_time;
1252
1253 if(likely(process_list->current_hash_data[trace_num][cpu] != NULL)) {
1254 hashed_process_data = process_list->current_hash_data[trace_num][cpu];
1255 } else {
1256 hashed_process_data = get_hashed_process_data(control_flow_data,
1257 process, pid, trace_num);
1258 /* Set the current process */
1259 process_list->current_hash_data[trace_num][process->cpu] =
1260 hashed_process_data;
1261 }
1262
1263 processlist_set_name(process_list, process->name, hashed_process_data);
1264
1265 #endif //babel_cleanup
1266 return 0;
1267
1268 }
1269
1270 /* after_event_enum_process_hook
1271 *
1272 * Create the processlist entry for the child process. Put the last
1273 * position in x at the current time value.
1274 *
1275 * @param hook_data ControlFlowData structure of the viewer.
1276 * @param call_data Event context.
1277 *
1278 * This function adds items to be drawn in a queue for each process.
1279 *
1280 */
1281 int after_event_enum_process_hook(void *hook_data, void *call_data)
1282 {
1283 LttvEvent *event;
1284
1285 event = (LttvEvent *) call_data;
1286
1287 if (strcmp(lttv_traceset_get_name_from_event(event),"lttng_statedump_process_state") != 0)
1288 return FALSE;
1289
1290 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
1291
1292
1293 LttvTraceState *ts = event->state;
1294
1295 guint first_cpu, nb_cpus, cpu;
1296
1297 #ifdef BABEL_CLEANUP
1298 LttvFilter *filter = control_flow_data->filter;
1299 if(filter != NULL && filter->head != NULL)
1300 if(!lttv_filter_tree_parse(filter->head,e,tfc->tf,
1301 tfc->t_context->t,tfc,NULL,NULL))
1302 return FALSE;
1303 #endif
1304 /* Add process to process list (if not present) */
1305 LttvProcessState *process_in;
1306 HashedProcessData *hashed_process_data_in = NULL;
1307
1308 ProcessList *process_list = control_flow_data->process_list;
1309 guint trace_num = lttv_traceset_get_trace_index_from_event(event);
1310
1311 guint pid_in;
1312 {
1313 pid_in = lttv_event_get_long(event, "tid");
1314 }
1315
1316 if(pid_in == 0) {
1317 first_cpu = 0;
1318 nb_cpus = lttv_trace_get_num_cpu(ts->trace);
1319 } else {
1320 first_cpu = ANY_CPU;
1321 nb_cpus = ANY_CPU+1;
1322 }
1323
1324 for(cpu = first_cpu; cpu < nb_cpus; cpu++) {
1325 /* Find process pid_in in the list... */
1326 process_in = lttv_state_find_process(ts, cpu, pid_in);
1327 //process_in = tfs->process;
1328 //guint cpu = tfs->cpu;
1329 //guint trace_num = ts->parent.index;
1330 //process_in = ts->running_process[cpu];
1331 /* It should exist, because we are after the state update. */
1332 #ifdef EXTRA_CHECK
1333 //g_assert(process_in != NULL);
1334 #endif //EXTRA_CHECK
1335
1336 hashed_process_data_in = get_hashed_process_data(control_flow_data,
1337 process_in, pid_in, trace_num);
1338
1339 processlist_set_name(process_list, process_in->name,
1340 hashed_process_data_in);
1341 processlist_set_ppid(process_list, process_in->ppid,
1342 hashed_process_data_in);
1343 processlist_set_tgid(process_list, process_in->tgid,
1344 hashed_process_data_in);
1345
1346 }
1347 return 0;
1348 }
1349
1350
1351 gint update_time_window_hook(void *hook_data, void *call_data)
1352 {
1353 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
1354
1355 Drawing_t *drawing = control_flow_data->drawing;
1356 ProcessList *process_list = control_flow_data->process_list;
1357
1358 const TimeWindowNotifyData *time_window_nofify_data =
1359 ((const TimeWindowNotifyData *)call_data);
1360
1361 TimeWindow *old_time_window =
1362 time_window_nofify_data->old_time_window;
1363 TimeWindow *new_time_window =
1364 time_window_nofify_data->new_time_window;
1365
1366 /* Update the ruler */
1367 drawing_update_ruler(control_flow_data->drawing,
1368 new_time_window);
1369
1370
1371 /* Two cases : zoom in/out or scrolling */
1372
1373 /* In order to make sure we can reuse the old drawing, the scale must
1374 * be the same and the new time interval being partly located in the
1375 * currently shown time interval. (reuse is only for scrolling)
1376 */
1377
1378 g_info("Old time window HOOK : %lu, %lu to %lu, %lu",
1379 old_time_window->start_time.tv_sec,
1380 old_time_window->start_time.tv_nsec,
1381 old_time_window->time_width.tv_sec,
1382 old_time_window->time_width.tv_nsec);
1383
1384 g_info("New time window HOOK : %lu, %lu to %lu, %lu",
1385 new_time_window->start_time.tv_sec,
1386 new_time_window->start_time.tv_nsec,
1387 new_time_window->time_width.tv_sec,
1388 new_time_window->time_width.tv_nsec);
1389
1390 if( new_time_window->time_width.tv_sec == old_time_window->time_width.tv_sec
1391 && new_time_window->time_width.tv_nsec == old_time_window->time_width.tv_nsec)
1392 {
1393 /* Same scale (scrolling) */
1394 g_info("scrolling");
1395 LttTime *ns = &new_time_window->start_time;
1396 LttTime *os = &old_time_window->start_time;
1397 LttTime old_end = old_time_window->end_time;
1398 LttTime new_end = new_time_window->end_time;
1399 //if(ns<os+w<ns+w)
1400 //if(ns<os+w && os+w<ns+w)
1401 //if(ns<old_end && os<ns)
1402 if(ltt_time_compare(*ns, old_end) == -1
1403 && ltt_time_compare(*os, *ns) == -1)
1404 {
1405 g_info("scrolling near right");
1406 /* Scroll right, keep right part of the screen */
1407 guint x = 0;
1408 guint width = control_flow_data->drawing->width;
1409 convert_time_to_pixels(
1410 *old_time_window,
1411 *ns,
1412 width,
1413 &x);
1414
1415 /* Copy old data to new location */
1416 copy_pixmap_region(process_list,
1417 NULL,
1418 control_flow_data->drawing->drawing_area->style->black_gc,
1419 NULL,
1420 x, 0,
1421 0, 0,
1422 control_flow_data->drawing->width-x+SAFETY, -1);
1423
1424 if(drawing->damage_begin == drawing->damage_end)
1425 drawing->damage_begin = control_flow_data->drawing->width-x;
1426 else
1427 drawing->damage_begin = 0;
1428
1429 drawing->damage_end = control_flow_data->drawing->width;
1430
1431 /* Clear the data request background, but not SAFETY */
1432 rectangle_pixmap(process_list,
1433 control_flow_data->drawing->drawing_area->style->black_gc,
1434 TRUE,
1435 drawing->damage_begin+SAFETY, 0,
1436 drawing->damage_end - drawing->damage_begin, // do not overlap
1437 -1);
1438 gtk_widget_queue_draw(drawing->drawing_area);
1439 //gtk_widget_queue_draw_area (drawing->drawing_area,
1440 // 0,0,
1441 // control_flow_data->drawing->width,
1442 // control_flow_data->drawing->height);
1443
1444 /* Get new data for the rest. */
1445 drawing_data_request(control_flow_data->drawing,
1446 drawing->damage_begin, 0,
1447 drawing->damage_end - drawing->damage_begin,
1448 control_flow_data->drawing->height);
1449 } else {
1450 //if(ns<os<ns+w)
1451 //if(ns<os && os<ns+w)
1452 //if(ns<os && os<new_end)
1453 if(ltt_time_compare(*ns,*os) == -1
1454 && ltt_time_compare(*os,new_end) == -1)
1455 {
1456 g_info("scrolling near left");
1457 /* Scroll left, keep left part of the screen */
1458 guint x = 0;
1459 guint width = control_flow_data->drawing->width;
1460 convert_time_to_pixels(
1461 *new_time_window,
1462 *os,
1463 width,
1464 &x);
1465
1466 /* Copy old data to new location */
1467 copy_pixmap_region (process_list,
1468 NULL,
1469 control_flow_data->drawing->drawing_area->style->black_gc,
1470 NULL,
1471 0, 0,
1472 x, 0,
1473 -1, -1);
1474
1475 if(drawing->damage_begin == drawing->damage_end)
1476 drawing->damage_end = x;
1477 else
1478 drawing->damage_end =
1479 control_flow_data->drawing->width;
1480
1481 drawing->damage_begin = 0;
1482
1483 rectangle_pixmap (process_list,
1484 control_flow_data->drawing->drawing_area->style->black_gc,
1485 TRUE,
1486 drawing->damage_begin, 0,
1487 drawing->damage_end - drawing->damage_begin, // do not overlap
1488 -1);
1489
1490 gtk_widget_queue_draw(drawing->drawing_area);
1491 //gtk_widget_queue_draw_area (drawing->drawing_area,
1492 // 0,0,
1493 // control_flow_data->drawing->width,
1494 // control_flow_data->drawing->height);
1495
1496
1497 /* Get new data for the rest. */
1498 drawing_data_request(control_flow_data->drawing,
1499 drawing->damage_begin, 0,
1500 drawing->damage_end - drawing->damage_begin,
1501 control_flow_data->drawing->height);
1502
1503 } else {
1504 if(ltt_time_compare(*ns,*os) == 0)
1505 {
1506 g_info("not scrolling");
1507 } else {
1508 g_info("scrolling far");
1509 /* Cannot reuse any part of the screen : far jump */
1510
1511
1512 rectangle_pixmap (process_list,
1513 control_flow_data->drawing->drawing_area->style->black_gc,
1514 TRUE,
1515 0, 0,
1516 control_flow_data->drawing->width+SAFETY, // do not overlap
1517 -1);
1518
1519 //gtk_widget_queue_draw_area (drawing->drawing_area,
1520 // 0,0,
1521 // control_flow_data->drawing->width,
1522 // control_flow_data->drawing->height);
1523 gtk_widget_queue_draw(drawing->drawing_area);
1524
1525 drawing->damage_begin = 0;
1526 drawing->damage_end = control_flow_data->drawing->width;
1527
1528 drawing_data_request(control_flow_data->drawing,
1529 0, 0,
1530 control_flow_data->drawing->width,
1531 control_flow_data->drawing->height);
1532
1533 }
1534 }
1535 }
1536 } else {
1537 /* Different scale (zoom) */
1538 g_info("zoom");
1539
1540 rectangle_pixmap (process_list,
1541 control_flow_data->drawing->drawing_area->style->black_gc,
1542 TRUE,
1543 0, 0,
1544 control_flow_data->drawing->width+SAFETY, // do not overlap
1545 -1);
1546
1547 //gtk_widget_queue_draw_area (drawing->drawing_area,
1548 // 0,0,
1549 // control_flow_data->drawing->width,
1550 // control_flow_data->drawing->height);
1551 gtk_widget_queue_draw(drawing->drawing_area);
1552
1553 drawing->damage_begin = 0;
1554 drawing->damage_end = control_flow_data->drawing->width;
1555
1556 drawing_data_request(control_flow_data->drawing,
1557 0, 0,
1558 control_flow_data->drawing->width,
1559 control_flow_data->drawing->height);
1560 }
1561
1562 /* Update directly when scrolling */
1563 gdk_window_process_updates(control_flow_data->drawing->drawing_area->window,
1564 TRUE);
1565
1566 return 0;
1567 }
1568
1569 gint traceset_notify(void *hook_data, void *call_data)
1570 {
1571 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
1572 Drawing_t *drawing = control_flow_data->drawing;
1573
1574 if(unlikely(drawing->gc == NULL)) {
1575 return FALSE;
1576 }
1577 if(drawing->dotted_gc == NULL) {
1578 return FALSE;
1579 }
1580
1581 drawing_clear(control_flow_data->drawing);
1582 processlist_clear(control_flow_data->process_list);
1583 gtk_widget_set_size_request(
1584 control_flow_data->drawing->drawing_area,
1585 -1, processlist_get_height(control_flow_data->process_list));
1586 redraw_notify(control_flow_data, NULL);
1587
1588 request_background_data(control_flow_data);
1589
1590 return FALSE;
1591 }
1592
1593 gint redraw_notify(void *hook_data, void *call_data)
1594 {
1595 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
1596 Drawing_t *drawing = control_flow_data->drawing;
1597 GtkWidget *widget = drawing->drawing_area;
1598
1599 drawing->damage_begin = 0;
1600 drawing->damage_end = drawing->width;
1601
1602 /* fun feature, to be separated someday... */
1603 drawing_clear(control_flow_data->drawing);
1604 processlist_clear(control_flow_data->process_list);
1605 gtk_widget_set_size_request(
1606 control_flow_data->drawing->drawing_area,
1607 -1, processlist_get_height(control_flow_data->process_list));
1608 // Clear the images
1609 rectangle_pixmap (control_flow_data->process_list,
1610 widget->style->black_gc,
1611 TRUE,
1612 0, 0,
1613 drawing->alloc_width,
1614 -1);
1615
1616 gtk_widget_queue_draw(drawing->drawing_area);
1617
1618 if(drawing->damage_begin < drawing->damage_end)
1619 {
1620 drawing_data_request(drawing,
1621 drawing->damage_begin,
1622 0,
1623 drawing->damage_end-drawing->damage_begin,
1624 drawing->height);
1625 }
1626
1627 //gtk_widget_queue_draw_area(drawing->drawing_area,
1628 // 0,0,
1629 // drawing->width,
1630 // drawing->height);
1631 return FALSE;
1632
1633 }
1634
1635
1636 gint continue_notify(void *hook_data, void *call_data)
1637 {
1638 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
1639 Drawing_t *drawing = control_flow_data->drawing;
1640
1641 //g_assert(widget->allocation.width == drawing->damage_end);
1642
1643 if(drawing->damage_begin < drawing->damage_end)
1644 {
1645 drawing_data_request(drawing,
1646 drawing->damage_begin,
1647 0,
1648 drawing->damage_end-drawing->damage_begin,
1649 drawing->height);
1650 }
1651
1652 return FALSE;
1653 }
1654
1655
1656 gint update_current_time_hook(void *hook_data, void *call_data)
1657 {
1658
1659 ControlFlowData *control_flow_data = (ControlFlowData*)hook_data;
1660
1661 LttTime current_time = *((LttTime*)call_data);
1662
1663 TimeWindow time_window =
1664 lttvwindow_get_time_window(control_flow_data->tab);
1665
1666 LttTime time_begin = time_window.start_time;
1667 LttTime width = time_window.time_width;
1668 LttTime half_width;
1669 {
1670 guint64 time_ll = ltt_time_to_uint64(width);
1671 time_ll = time_ll >> 1; /* divide by two */
1672 half_width = ltt_time_from_uint64(time_ll);
1673 }
1674 LttTime time_end = ltt_time_add(time_begin, width);
1675
1676 LttvTraceset * ts = lttvwindow_get_traceset(control_flow_data->tab);
1677
1678 TimeInterval time_span = lttv_traceset_get_time_span_real(ts);
1679 LttTime trace_start = time_span.start_time;
1680 LttTime trace_end = time_span.end_time;
1681
1682 g_info("New current time HOOK : %lu, %lu", current_time.tv_sec,
1683 current_time.tv_nsec);
1684
1685
1686
1687 /* If current time is inside time interval, just move the highlight
1688 * bar */
1689
1690 /* Else, we have to change the time interval. We have to tell it
1691 * to the main window. */
1692 /* The time interval change will take care of placing the current
1693 * time at the center of the visible area, or nearest possible if we are
1694 * at one end of the trace. */
1695
1696
1697 if(ltt_time_compare(current_time, time_begin) < 0)
1698 {
1699 TimeWindow new_time_window;
1700
1701 if(ltt_time_compare(current_time,
1702 ltt_time_add(trace_start,half_width)) < 0)
1703 time_begin = trace_start;
1704 else
1705 time_begin = ltt_time_sub(current_time,half_width);
1706
1707 new_time_window.start_time = time_begin;
1708 new_time_window.time_width = width;
1709 new_time_window.time_width_double = ltt_time_to_double(width);
1710 new_time_window.end_time = ltt_time_add(time_begin, width);
1711
1712 lttvwindow_report_time_window(control_flow_data->tab, new_time_window);
1713 }
1714 else if(ltt_time_compare(current_time, time_end) > 0)
1715 {
1716 TimeWindow new_time_window;
1717
1718 if(ltt_time_compare(current_time, ltt_time_sub(trace_end, half_width)) > 0)
1719 time_begin = ltt_time_sub(trace_end,width);
1720 else
1721 time_begin = ltt_time_sub(current_time,half_width);
1722
1723 new_time_window.start_time = time_begin;
1724 new_time_window.time_width = width;
1725 new_time_window.time_width_double = ltt_time_to_double(width);
1726 new_time_window.end_time = ltt_time_add(time_begin, width);
1727
1728 lttvwindow_report_time_window(control_flow_data->tab, new_time_window);
1729
1730 }
1731 gtk_widget_queue_draw(control_flow_data->drawing->drawing_area);
1732
1733 /* Update directly when scrolling */
1734 gdk_window_process_updates(control_flow_data->drawing->drawing_area->window,
1735 TRUE);
1736
1737 return 0;
1738
1739 }
1740
1741 typedef struct _ClosureData {
1742 EventsRequest *events_request;
1743 LttTime end_time;
1744 guint x_end;
1745 } ClosureData;
1746
1747
1748 void draw_closure(gpointer key, gpointer value, gpointer user_data)
1749 {
1750
1751 ProcessInfo *process_info = (ProcessInfo*)key;
1752 HashedProcessData *hashed_process_data = (HashedProcessData*)value;
1753 ClosureData *closure_data = (ClosureData*)user_data;
1754
1755 EventsRequest *events_request = closure_data->events_request;
1756 ControlFlowData *control_flow_data = events_request->viewer_data;
1757 LttvTraceset *ts = lttvwindow_get_traceset(control_flow_data->tab);
1758
1759
1760 LttTime evtime = closure_data->end_time;
1761
1762 gboolean dodraw = TRUE;
1763
1764 {
1765 /* For the process */
1766 /* First, check if the current process is in the state computation
1767 * process list. If it is there, that means we must add it right now and
1768 * draw items from the beginning of the read for it. If it is not
1769 * present, it's a new process and it was not present : it will
1770 * be added after the state update. */
1771 #ifdef EXTRA_CHECK
1772 g_assert(lttv_traceset_number(tsc->ts) > 0);
1773 #endif //EXTRA_CHECK
1774
1775 LttvTrace *trace = lttv_traceset_get(ts, process_info->trace_num);
1776 LttvTraceState *trace_state = trace->state;
1777
1778 #if 0
1779 //FIXME : optimize data structures.
1780 LttvTracefileState *tfs;
1781 LttvTracefileContext *tfc;
1782 guint i;
1783 for(i=0;i<tc->tracefiles->len;i++) {
1784 tfc = g_array_index(tc->tracefiles, LttvTracefileContext*, i);
1785 if(ltt_tracefile_name(tfc->tf) == LTT_NAME_CPU
1786 && tfs->cpu == process_info->cpu)
1787 break;
1788
1789 }
1790 g_assert(i<tc->tracefiles->len);
1791 tfs = LTTV_TRACEFILE_STATE(tfc);
1792 #endif //0
1793 // LttvTracefileState *tfs =ts
1794 // (LttvTracefileState*)tsc->traces[process_info->trace_num]->
1795 // tracefiles[process_info->cpu];
1796
1797 LttvProcessState *process;
1798 process = lttv_state_find_process(trace_state, process_info->cpu,
1799 process_info->pid);
1800
1801 if(unlikely(process != NULL)) {
1802 #ifdef BABEL_CLEANUP
1803 LttvFilter *filter = control_flow_data->filter;
1804 if(filter != NULL && filter->head != NULL)
1805 if(!lttv_filter_tree_parse(filter->head,NULL,NULL,
1806 tc->t,NULL,process,tc))
1807 dodraw = FALSE;
1808 #endif //babel_cleanup
1809 /* Only draw for processes that are currently in the trace states */
1810
1811 #ifdef EXTRA_CHECK
1812 /* Should be alike when background info is ready */
1813 if(control_flow_data->background_info_waiting==0)
1814 g_assert(ltt_time_compare(process->creation_time,
1815 process_info->birth) == 0);
1816 #endif //EXTRA_CHECK
1817
1818 /* Now, the process is in the state hash and our own process hash.
1819 * We definitely can draw the items related to the ending state.
1820 */
1821
1822 if(unlikely(ltt_time_compare(hashed_process_data->next_good_time,
1823 evtime) <= 0))
1824 {
1825 TimeWindow time_window =
1826 lttvwindow_get_time_window(control_flow_data->tab);
1827
1828 #ifdef EXTRA_CHECK
1829 if(ltt_time_compare(evtime, time_window.start_time) == -1
1830 || ltt_time_compare(evtime, time_window.end_time) == 1)
1831 return;
1832 #endif //EXTRA_CHECK
1833 Drawing_t *drawing = control_flow_data->drawing;
1834 guint width = drawing->width;
1835
1836 guint x = closure_data->x_end;
1837
1838 DrawContext draw_context;
1839
1840 init_drawing_context(&draw_context,
1841 hashed_process_data,
1842 drawing,
1843 x);
1844
1845 #if 0
1846 /* Jump over draw if we are at the same x position */
1847 if(x == hashed_process_data->x.over)
1848 {
1849 /* jump */
1850 } else {
1851 draw_context.drawinfo.start.x = hashed_process_data->x.over;
1852 /* Draw the line */
1853 PropertiesLine prop_line = prepare_execmode_line(process);
1854 draw_line((void*)&prop_line, (void*)&draw_context);
1855
1856 hashed_process_data->x.over = x;
1857 }
1858 #endif //0
1859
1860 if(unlikely(x == hashed_process_data->x.middle &&
1861 hashed_process_data->x.middle_used)) {
1862 #if 0 /* do not mark closure : not missing information */
1863 if(hashed_process_data->x.middle_marked == FALSE) {
1864 /* Draw collision indicator */
1865 gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]);
1866 gdk_draw_point(drawing->pixmap,
1867 drawing->gc,
1868 x,
1869 y+(height/2)-3);
1870 hashed_process_data->x.middle_marked = TRUE;
1871 }
1872 #endif //0
1873 /* Jump */
1874 } else {
1875 draw_context.drawinfo.start.x = hashed_process_data->x.middle;
1876 /* Draw the line */
1877 if(dodraw) {
1878 PropertiesLine prop_line = prepare_s_e_line(process);
1879 draw_line((void*)&prop_line, (void*)&draw_context);
1880 }
1881
1882 /* become the last x position */
1883 if(likely(x != hashed_process_data->x.middle)) {
1884 hashed_process_data->x.middle = x;
1885 /* but don't use the pixel */
1886 hashed_process_data->x.middle_used = FALSE;
1887
1888 /* Calculate the next good time */
1889 convert_pixels_to_time(width, x+1, time_window,
1890 &hashed_process_data->next_good_time);
1891 }
1892 }
1893 }
1894 }
1895 }
1896 return;
1897 }
1898
1899 int before_chunk(void *hook_data, void *call_data)
1900 {
1901
1902 EventsRequest *events_request = (EventsRequest*)hook_data;
1903 LttvTraceset *ts = (LttvTraceset*)call_data;
1904 #if 0
1905 /* Desactivate sort */
1906 gtk_tree_sortable_set_sort_column_id(
1907 GTK_TREE_SORTABLE(cfd->process_list->list_store),
1908 TRACE_COLUMN,
1909 GTK_SORT_ASCENDING);
1910 #endif //0
1911 drawing_chunk_begin(events_request, ts);
1912
1913 return 0;
1914 }
1915
1916 int before_request(void *hook_data, void *call_data)
1917 {
1918
1919 EventsRequest *events_request = (EventsRequest*)hook_data;
1920
1921 drawing_data_request_begin(events_request);
1922
1923 return 0;
1924
1925 }
1926
1927
1928 void draw_closing_lines(ControlFlowData *control_flow_data,
1929 EventsRequest* events_request)
1930 {
1931 ProcessList *process_list = control_flow_data->process_list;
1932
1933
1934 ClosureData closure_data;
1935 closure_data.events_request = events_request;
1936 closure_data.end_time = events_request->end_time;
1937
1938 TimeWindow time_window =
1939 lttvwindow_get_time_window(control_flow_data->tab);
1940 guint width = control_flow_data->drawing->width;
1941 convert_time_to_pixels(
1942 time_window,
1943 events_request->end_time,
1944 width,
1945 &closure_data.x_end);
1946
1947
1948 /* Draw last items */
1949 g_hash_table_foreach(process_list->process_hash, draw_closure,
1950 (void*)&closure_data);
1951
1952
1953 /* Request expose */
1954 drawing_request_expose(events_request, events_request->end_time);
1955 }
1956
1957 /*
1958 * after request is necessary in addition of after chunk in order to draw
1959 * lines until the end of the screen. after chunk just draws lines until
1960 * the last event.
1961 *
1962 * for each process
1963 * draw closing line
1964 * expose
1965 */
1966 int after_request(void *hook_data, void *call_data)
1967 {
1968
1969 EventsRequest *events_request = (EventsRequest*)hook_data;
1970 ControlFlowData *control_flow_data = events_request->viewer_data;
1971
1972 draw_closing_lines(control_flow_data, events_request);
1973
1974 return 0;
1975 }
1976
1977 /*
1978 * for each process
1979 * draw closing line
1980 * expose
1981 */
1982 int after_chunk(void *hook_data, void *call_data)
1983 {
1984
1985 EventsRequest *events_request = (EventsRequest*)hook_data;
1986 ControlFlowData *control_flow_data = events_request->viewer_data;
1987 LttvTraceset *ts = (LttvTraceset*)call_data;
1988
1989
1990 ProcessList *process_list = control_flow_data->process_list;
1991 guint i;
1992 guint nb_trace = lttv_traceset_number(ts);
1993
1994 /* Only execute when called for the first trace's events request */
1995 if(!process_list->current_hash_data)
1996 return 0;
1997
1998 for(i = 0 ; i < nb_trace ; i++) {
1999 g_free(process_list->current_hash_data[i]);
2000 }
2001 g_free(process_list->current_hash_data);
2002 process_list->current_hash_data = NULL;
2003
2004 draw_closing_lines(control_flow_data, events_request);
2005
2006 return 0;
2007 }
2008
2009 /* after_statedump_end
2010 *
2011 * @param hook_data ControlFlowData structure of the viewer.
2012 * @param call_data Event context.
2013 *
2014 * This function adds items to be drawn in a queue for each process.
2015 *
2016 */
2017 int before_statedump_end(void *hook_data, void *call_data)
2018 {
2019 LttvEvent *event;
2020
2021 event = (LttvEvent *) call_data;
2022
2023 if (strcmp(lttv_traceset_get_name_from_event(event),"lttng_statedump_end") != 0)
2024 return FALSE;
2025
2026 ControlFlowData *control_flow_data = (ControlFlowData*) hook_data;
2027
2028
2029 LttvTraceState *ts = event->state;
2030
2031
2032 ProcessList *process_list = control_flow_data->process_list;
2033
2034 #ifdef BABEL_CLEANUP
2035 LttvFilter *filter = control_flow_data->filter;
2036 if(filter != NULL && filter->head != NULL)
2037 if(!lttv_filter_tree_parse(filter->head,e,tfc->tf,
2038 tfc->t_context->t,tfc,NULL,NULL))
2039 return FALSE;
2040 #endif
2041
2042 LttTime evtime = lttv_event_get_timestamp(event);
2043
2044 ClosureData closure_data;
2045 //TODO ybrosseau 2013-03-27: Fake and event_request.
2046 // We need to change the API of drawing_request_expose to ask
2047 // For and control flow data only.
2048 EventsRequest events_request;
2049 events_request.viewer_data = control_flow_data;
2050 closure_data.events_request = &events_request;
2051 closure_data.end_time = evtime;
2052
2053 TimeWindow time_window =
2054 lttvwindow_get_time_window(control_flow_data->tab);
2055 guint width = control_flow_data->drawing->width;
2056 convert_time_to_pixels(
2057 time_window,
2058 evtime,
2059 width,
2060 &closure_data.x_end);
2061
2062 /* Draw last items */
2063 g_hash_table_foreach(process_list->process_hash, draw_closure,
2064 (void*)&closure_data);
2065
2066 #if 0
2067 /* Reactivate sort */
2068 gtk_tree_sortable_set_sort_column_id(
2069 GTK_TREE_SORTABLE(control_flow_data->process_list->list_store),
2070 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
2071 GTK_SORT_ASCENDING);
2072
2073 update_index_to_pixmap(control_flow_data->process_list);
2074 /* Request a full expose : drawing scrambled */
2075 gtk_widget_queue_draw(control_flow_data->drawing->drawing_area);
2076 #endif //0
2077 /* Request expose (updates damages zone also) */
2078 drawing_request_expose(&events_request, evtime);
2079
2080 return 0;
2081 }
This page took 0.10748 seconds and 4 git commands to generate.