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