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