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