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