Enable support for opening multiple trace
[lttv.git] / lttv / modules / gui / resourceview / eventhooks.c
CommitLineData
9e01e6d4 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>
43ed82b5 59#include <inttypes.h>
9e01e6d4 60
61//#include <pango/pango.h>
62
63#include <ltt/event.h>
64#include <ltt/time.h>
9e01e6d4 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
3d27be8a 82#define STATE_LINE_WIDTH 6
9e01e6d4 83#define COLLISION_POSITION(height) (((height - STATE_LINE_WIDTH)/2) -3)
84
85extern 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
93static gint background_ready(void *hook_data, void *call_data)
94{
67f72973 95 ControlFlowData *resourceview_data = (ControlFlowData *)hook_data;
9e01e6d4 96
67f72973 97 resourceview_data->background_info_waiting--;
9e01e6d4 98
67f72973 99 if(resourceview_data->background_info_waiting == 0) {
9e01e6d4 100 g_message("control flow viewer : background computation data ready.");
101
67f72973 102 drawing_clear(resourceview_data->drawing);
103 processlist_clear(resourceview_data->process_list);
9e01e6d4 104 gtk_widget_set_size_request(
67f72973 105 resourceview_data->drawing->drawing_area,
106 -1, processlist_get_height(resourceview_data->process_list));
107 redraw_notify(resourceview_data, NULL);
9e01e6d4 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 */
67f72973 117static void request_background_data(ControlFlowData *resourceview_data)
9e01e6d4 118{
dd47d0d8
YB
119 LttvTraceset* ts =
120 lttvwindow_get_traceset(resourceview_data->tab);
121 gint num_traces = lttv_traceset_number(ts);
9e01e6d4 122 gint i;
123 LttvTrace *trace;
124 LttvTraceState *tstate;
125
126 LttvHooks *background_ready_hook =
127 lttv_hooks_new();
67f72973 128 lttv_hooks_add(background_ready_hook, background_ready, resourceview_data,
9e01e6d4 129 LTTV_PRIO_DEFAULT);
67f72973 130 resourceview_data->background_info_waiting = 0;
9e01e6d4 131
132 for(i=0;i<num_traces;i++) {
dd47d0d8
YB
133 trace = lttv_traceset_get(ts, i);
134
9e01e6d4 135 if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace)==FALSE
dd47d0d8 136 && !ts->has_precomputed_states) {
9e01e6d4 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(
67f72973 146 main_window_get_widget(resourceview_data->tab), trace, "state");
147 lttvwindowtraces_background_notify_queue(resourceview_data,
9e01e6d4 148 trace,
149 ltt_time_infinite,
150 NULL,
151 background_ready_hook);
67f72973 152 resourceview_data->background_info_waiting++;
9e01e6d4 153 } else { /* in progress */
154
67f72973 155 lttvwindowtraces_background_notify_current(resourceview_data,
9e01e6d4 156 trace,
157 ltt_time_infinite,
158 NULL,
159 background_ready_hook);
67f72973 160 resourceview_data->background_info_waiting++;
9e01e6d4 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 }
9e01e6d4 168 }
169
170 lttv_hooks_destroy(background_ready_hook);
171}
172
173
9e01e6d4 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 */
182GtkWidget *
58a9b31b 183h_resourceview(LttvPlugin *plugin)
9e01e6d4 184{
185 LttvPluginTab *ptab = LTTV_PLUGIN_TAB(plugin);
186 Tab *tab = ptab->tab;
187 g_info("h_guicontrolflow, %p", tab);
67f72973 188 ControlFlowData *resourceview_data = resourceview(ptab);
9e01e6d4 189
67f72973 190 resourceview_data->tab = tab;
9e01e6d4 191
192 // Unreg done in the GuiControlFlow_Destructor
193 lttvwindow_register_traceset_notify(tab,
194 traceset_notify,
67f72973 195 resourceview_data);
9e01e6d4 196
197 lttvwindow_register_time_window_notify(tab,
198 update_time_window_hook,
67f72973 199 resourceview_data);
9e01e6d4 200 lttvwindow_register_current_time_notify(tab,
201 update_current_time_hook,
67f72973 202 resourceview_data);
9e01e6d4 203 lttvwindow_register_redraw_notify(tab,
204 redraw_notify,
67f72973 205 resourceview_data);
9e01e6d4 206 lttvwindow_register_continue_notify(tab,
207 continue_notify,
67f72973 208 resourceview_data);
209 request_background_data(resourceview_data);
9e01e6d4 210
211
67f72973 212 return guicontrolflow_get_widget(resourceview_data) ;
9e01e6d4 213
214}
215
216void legend_destructor(GtkWindow *legend)
217{
218 g_legend_list = g_slist_remove(g_legend_list, legend);
219}
220
221/* Create a popup legend */
222GtkWidget *
223h_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
9e01e6d4 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
255int event_selected_hook(void *hook_data, void *call_data)
256{
9e01e6d4 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
d3d99fde 264static void cpu_set_line_color(PropertiesLine *prop_line, LttvCPUState *s)
598026ba 265{
1b171947 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];
d3d99fde 272
201fcc15 273 if(present_state == LTTV_CPU_IDLE) {
598026ba 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 }
d34141ca 282 else if(present_state == LTTV_CPU_SOFT_IRQ) {
283 prop_line->color = drawing_colors_cpu[COL_CPU_SOFT_IRQ];
284 }
d3d99fde 285 else if(present_state == LTTV_CPU_TRAP) {
286 prop_line->color = drawing_colors_cpu[COL_CPU_TRAP];
201fcc15 287 } else {
288 prop_line->color = drawing_colors_cpu[COL_CPU_UNKNOWN];
d3d99fde 289 }
598026ba 290}
9e01e6d4 291
8743690d 292static void irq_set_line_color(PropertiesLine *prop_line, LttvIRQState *s)
293{
1b171947 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];
8743690d 299
1b171947 300 if(present_state == LTTV_IRQ_IDLE) {
8743690d 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 }
1b171947 306 else {
307 prop_line->color = drawing_colors_irq[COL_IRQ_UNKNOWN];
308 }
8743690d 309}
310
0305fe77 311static void soft_irq_set_line_color(PropertiesLine *prop_line, LttvSoftIRQState *s)
312{
67c73bb3 313 if(s->running)
0305fe77 314 prop_line->color = drawing_colors_soft_irq[COL_SOFT_IRQ_BUSY];
67c73bb3 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];
0305fe77 319}
320
38726a78 321static void trap_set_line_color(PropertiesLine *prop_line, LttvTrapState *s)
322{
38726a78 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
20d16f82 329static void bdev_set_line_color(PropertiesLine *prop_line, LttvBdevState *s)
330{
1b171947 331 GQuark present_state;
23e59a12 332 if(s == 0 || s->mode_stack->len == 0)
1b171947 333 present_state = LTTV_BDEV_UNKNOWN;
334 else
335 present_state = ((GQuark*)s->mode_stack->data)[s->mode_stack->len-1];
20d16f82 336
1b171947 337 if(present_state == LTTV_BDEV_IDLE) {
20d16f82 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 }
1b171947 346 else {
347 prop_line->color = drawing_colors_bdev[COL_BDEV_UNKNOWN];
348 }
20d16f82 349}
350
9e01e6d4 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
369int before_schedchange_hook(void *hook_data, void *call_data)
370{
9e01e6d4 371
dd47d0d8
YB
372 LttvEvent *event;
373 LttvTraceState *ts;
9e01e6d4 374
dd47d0d8
YB
375 event = (LttvEvent *) call_data;
376 if (strcmp(lttv_traceset_get_name_from_event(event),"sched_switch") != 0)
377 return FALSE;
9e01e6d4 378
dd47d0d8 379 ControlFlowData *resourceview_data = (ControlFlowData*)hook_data;
9e01e6d4 380
dd47d0d8 381 LttTime evtime = lttv_event_get_timestamp(event);
58a9b31b 382
9e01e6d4 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;
dd47d0d8 389 pid_out = lttv_event_get_long(event, "prev_tid");
67f72973 390// TODO: can't we reenable this? pmf
44ffb95f 391// if(pid_in != 0 && pid_out != 0) {
392// /* not a transition to/from idle */
393// return 0;
394// }
c4e6f4dc 395
58a9b31b 396
dd47d0d8
YB
397 guint cpu = lttv_traceset_get_cpuid_from_event(event);
398 ts = event->state;
9e01e6d4 399
8284135e
YB
400 guint trace_num = lttv_traceset_get_trace_index_from_event(event);
401
8d8c5ea7 402 /* Add process to process list (if not present) */
67f72973 403 HashedResourceData *hashed_process_data = NULL;
9e01e6d4 404
67f72973 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);
9e01e6d4 418#ifdef EXTRA_CHECK
67f72973 419 if(ltt_time_compare(evtime, time_window.start_time) == -1
420 || ltt_time_compare(evtime, time_window.end_time) == 1)
421 return;
9e01e6d4 422#endif //EXTRA_CHECK
67f72973 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);
9e01e6d4 443#ifdef EXTRA_CHECK
67f72973 444 if(ltt_time_compare(evtime, time_window.start_time) == -1
9e01e6d4 445 || ltt_time_compare(evtime, time_window.end_time) == 1)
67f72973 446 return;
9e01e6d4 447#endif //EXTRA_CHECK
67f72973 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);
9e01e6d4 456
67f72973 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;
58a9b31b 469 }
67f72973 470 /* jump */
471 } else {
472 DrawContext draw_context;
9e01e6d4 473
67f72973 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;
9e01e6d4 481
67f72973 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;
9e01e6d4 485
67f72973 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;
9e01e6d4 492
67f72973 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;
dd47d0d8 500 cpu_set_line_color(&prop_line, &(ts->cpu_states[cpu]));
67f72973 501 draw_line((void*)&prop_line, (void*)&draw_context);
9e01e6d4 502
67f72973 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;
9e01e6d4 508
67f72973 509 /* Calculate the next good time */
510 convert_pixels_to_time(width, x+1, time_window,
511 &hashed_process_data->next_good_time);
512 }
9e01e6d4 513 }
514
67f72973 515 return 0;
9e01e6d4 516}
517
58a9b31b 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 */
528int after_schedchange_hook(void *hook_data, void *call_data)
9e01e6d4 529{
dd47d0d8 530 LttvEvent *event;
67f72973 531
dd47d0d8
YB
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;
44ffb95f 538
dd47d0d8
YB
539 LttvTraceState *ts = event->state;
540#ifdef BABEL_CLEANUP
67f72973 541 LttvFilter *filter = resourceview_data->filter;
44ffb95f 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;
dd47d0d8 546#endif
44ffb95f 547
dd47d0d8 548 LttTime evtime = lttv_event_get_timestamp(event);
44ffb95f 549
44ffb95f 550 /* Add process to process list (if not present) */
551 LttvProcessState *process_in;
44ffb95f 552 HashedResourceData *hashed_process_data_in = NULL;
553
67f72973 554 ProcessList *process_list = resourceview_data->process_list;
44ffb95f 555
44ffb95f 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;
dd47d0d8 559 guint cpu = lttv_traceset_get_cpuid_from_event(event);
8284135e 560 guint trace_num = lttv_traceset_get_trace_index_from_event(event);
44ffb95f 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
44ffb95f 566
67f72973 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
44ffb95f 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 =
67f72973 578 lttvwindow_get_time_window(resourceview_data->tab);
44ffb95f 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
67f72973 585 Drawing_t *drawing = resourceview_data->drawing;
44ffb95f 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 }
58a9b31b 601 return 0;
602}
9e01e6d4 603
43ed82b5 604int before_execmode_hook_irq(void *hook_data, void *call_data);
605int before_execmode_hook_soft_irq(void *hook_data, void *call_data);
606int before_execmode_hook_trap(void *hook_data, void *call_data);
607
58a9b31b 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 */
9e01e6d4 624
598026ba 625int before_execmode_hook(void *hook_data, void *call_data)
626{
dd47d0d8
YB
627 LttvEvent *event;
628 guint cpu;
629 guint pid = 0;
630 LttvTraceState *ts;
631 LttvProcessState *process;
598026ba 632
8743690d 633 before_execmode_hook_irq(hook_data, call_data);
0305fe77 634 before_execmode_hook_soft_irq(hook_data, call_data);
dd47d0d8 635#ifdef TRAP_NO_EXIST
38726a78 636 before_execmode_hook_trap(hook_data, call_data);
dd47d0d8 637#endif
598026ba 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 */
dd47d0d8
YB
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
598026ba 651 /* For the pid */
dd47d0d8
YB
652 LttvTraceset *traceSet = lttvwindow_get_traceset(resourceview_data->tab);
653
654 cpu = lttv_traceset_get_cpuid_from_event(event);
655 ts = event->state;
656
8284135e 657 guint trace_num = lttv_traceset_get_trace_index_from_event(event);
67f72973 658
dd47d0d8 659 process = ts->running_process[cpu];
598026ba 660 g_assert(process != NULL);
661
598026ba 662 /* Well, the process_out existed : we must get it in the process hash
663 * or add it, and draw its items.
664 */
8d8c5ea7 665 /* Add process to process list (if not present) */
598026ba 666 HashedResourceData *hashed_process_data = NULL;
67f72973 667 ProcessList *process_list = resourceview_data->process_list;
598026ba 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 {
67f72973 672 hashed_process_data = resourcelist_obtain_cpu(resourceview_data, trace_num, cpu);
673
598026ba 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 =
67f72973 688 lttvwindow_get_time_window(resourceview_data->tab);
598026ba 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
67f72973 695 Drawing_t *drawing = resourceview_data->drawing;
598026ba 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 }
d3d99fde 712 }
713 else {
598026ba 714 TimeWindow time_window =
67f72973 715 lttvwindow_get_time_window(resourceview_data->tab);
598026ba 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
67f72973 722 Drawing_t *drawing = resourceview_data->drawing;
598026ba 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 */
d3d99fde 747 }
748 else {
598026ba 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;
d3d99fde 773 prop_line.line_width = STATE_LINE_WIDTH;
774 prop_line.style = GDK_LINE_SOLID;
775 prop_line.y = MIDDLE;
dd47d0d8 776 cpu_set_line_color(&prop_line, &ts->cpu_states[cpu]);
598026ba 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 }
dd47d0d8 788 }
598026ba 789 }
598026ba 790 return 0;
791}
9e01e6d4 792
8743690d 793int before_execmode_hook_irq(void *hook_data, void *call_data)
794{
dd47d0d8 795 LttvEvent *event;
8743690d 796
dd47d0d8
YB
797 event = (LttvEvent *) call_data;
798
799 LttTime evtime = lttv_event_get_timestamp(event);
800 ControlFlowData *resourceview_data = (ControlFlowData*)hook_data;
8743690d 801
8743690d 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;
dd47d0d8
YB
809 guint cpu = lttv_traceset_get_cpuid_from_event(event);
810 LttvTraceset *traceSet = lttvwindow_get_traceset(resourceview_data->tab);
811 LttvTraceState *ts = event->state;;
8743690d 812
750eb11a 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 */
dd47d0d8
YB
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) {
55a35306 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 }
750eb11a 827 } else
8743690d 828 return 0;
8743690d 829
8284135e 830 guint trace_num = lttv_traceset_get_trace_index_from_event(event);
8743690d 831
8743690d 832 /* Well, the process_out existed : we must get it in the process hash
833 * or add it, and draw its items.
834 */
8d8c5ea7 835 /* Add process to process list (if not present) */
8743690d 836 HashedResourceData *hashed_process_data = NULL;
67f72973 837
838 hashed_process_data = resourcelist_obtain_irq(resourceview_data, trace_num, irq);
671c625b 839 // TODO: fix this, it's ugly and slow:
840 GQuark name;
841 {
842 gchar *str;
1cd9058f
MD
843 str = g_strdup_printf("IRQ %" PRIu64 " [%s]", irq,
844 (char*)g_quark_to_string(ts->name_tables->irq_names[irq]));
671c625b 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);
8743690d 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 =
67f72973 859 lttvwindow_get_time_window(resourceview_data->tab);
8743690d 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
67f72973 866 Drawing_t *drawing = resourceview_data->drawing;
8743690d 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 =
67f72973 886 lttvwindow_get_time_window(resourceview_data->tab);
8743690d 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
67f72973 893 Drawing_t *drawing = resourceview_data->drawing;
8743690d 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
0305fe77 964int before_execmode_hook_soft_irq(void *hook_data, void *call_data)
965{
0305fe77 966
dd47d0d8
YB
967 LttvEvent *event;
968 LttvTraceState *ts;
0305fe77 969
dd47d0d8
YB
970 event = (LttvEvent *) call_data;
971
972
973
0305fe77 974
0305fe77 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;
dd47d0d8 982
0305fe77 983
750eb11a 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 */
dd47d0d8
YB
989
990 if (strncmp(lttv_traceset_get_name_from_event(event),"softirq_entry",sizeof("softirq_entry")) == 0
d14a4a7a
YB
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
dd47d0d8 994 softirq = lttv_event_get_long_unsigned(event, "vec");
d14a4a7a
YB
995
996 } else {
997 return 0;
998 }
dd47d0d8 999
d14a4a7a
YB
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;
8284135e 1005 guint trace_num = lttv_traceset_get_trace_index_from_event(event);
0305fe77 1006
1007 /* Well, the process_out existed : we must get it in the process hash
1008 * or add it, and draw its items.
1009 */
8d8c5ea7 1010 /* Add process to process list (if not present) */
0305fe77 1011 HashedResourceData *hashed_process_data = NULL;
0305fe77 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 }
d14a4a7a 1125
0305fe77 1126 return 0;
1127}
dd47d0d8 1128#ifdef TRAP_NO_EXIST
38726a78 1129int 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;
750eb11a 1139 struct marker_info *minfo;
38726a78 1140
1141 LttEvent *e;
1142 e = ltt_tracefile_get_event(tfc->tf);
1143
1144 LttTime evtime = ltt_event_time(e);
1145
38726a78 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
750eb11a 1155 /*
1156 * Check for LTT_CHANNEL_KERNEL channel name and event ID
4e9bbbd3 1157 * corresponding to LTT_EVENT_TRAP/PAGE_FAULT_ENTRY or
1158 * LTT_EVENT_TRAP/PAGE_FAULT_EXIT.
750eb11a 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);
4e9bbbd3 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) {
38726a78 1167 trap = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 0));
4e9bbbd3 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) {
16e4e89b 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 }
750eb11a 1178 } else
38726a78 1179 return 0;
38726a78 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 */
8d8c5ea7 1186 /* Add process to process list (if not present) */
38726a78 1187 HashedResourceData *hashed_process_data = NULL;
38726a78 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}
dd47d0d8
YB
1304#endif
1305#ifdef BABEL_CLEANUP
1306//TODO investigate the use of block dev resource
20d16f82 1307int before_bdev_event_hook(void *hook_data, void *call_data)
1308{
dd47d0d8
YB
1309LttvEvent *event;
1310 guint cpu;
1311 guint pid = 0;
1312 LttvTraceState *ts;
1313 LttvProcessState *process;
20d16f82 1314
20d16f82 1315
20d16f82 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 */
dd47d0d8
YB
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;
20d16f82 1329 /* For the pid */
1330
ca5c76ed 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));
20d16f82 1333 gint devcode_gint = MKDEV(major,minor);
1334
8284135e 1335 guint trace_num = lttv_traceset_get_trace_index_from_event(event);
20d16f82 1336
1337 LttvBdevState *bdev = g_hash_table_lookup(ts->bdev_states, &devcode_gint);
23e59a12 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 */
20d16f82 1340
20d16f82 1341 /* Well, the process_out existed : we must get it in the process hash
1342 * or add it, and draw its items.
1343 */
8d8c5ea7 1344 /* Add process to process list (if not present) */
20d16f82 1345 HashedResourceData *hashed_process_data = NULL;
20d16f82 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 {
67f72973 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);
20d16f82 1353// hashed_process_data = processlist_get_process_data(process_list,
1354// pid,
1355// process->cpu,
1356// &birth,
1357// trace_num);
67f72973 1358//
20d16f82 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 =
67f72973 1373 lttvwindow_get_time_window(resourceview_data->tab);
20d16f82 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
67f72973 1380 Drawing_t *drawing = resourceview_data->drawing;
20d16f82 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 =
67f72973 1400 lttvwindow_get_time_window(resourceview_data->tab);
20d16f82 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
67f72973 1407 Drawing_t *drawing = resourceview_data->drawing;
20d16f82 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}
dd47d0d8 1477#endif
9e01e6d4 1478gint update_time_window_hook(void *hook_data, void *call_data)
1479{
67f72973 1480 ControlFlowData *resourceview_data = (ControlFlowData*) hook_data;
1481 Drawing_t *drawing = resourceview_data->drawing;
1482 ProcessList *process_list = resourceview_data->process_list;
9e01e6d4 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 */
67f72973 1493 drawing_update_ruler(resourceview_data->drawing,
9e01e6d4 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;
9e01e6d4 1522 LttTime *os = &old_time_window->start_time;
9e01e6d4 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;
67f72973 1534 guint width = resourceview_data->drawing->width;
9e01e6d4 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,
67f72973 1544 resourceview_data->drawing->drawing_area->style->black_gc,
9e01e6d4 1545 NULL,
1546 x, 0,
1547 0, 0,
67f72973 1548 resourceview_data->drawing->width-x+SAFETY, -1);
9e01e6d4 1549
1550 if(drawing->damage_begin == drawing->damage_end)
67f72973 1551 drawing->damage_begin = resourceview_data->drawing->width-x;
9e01e6d4 1552 else
1553 drawing->damage_begin = 0;
1554
67f72973 1555 drawing->damage_end = resourceview_data->drawing->width;
9e01e6d4 1556
1557 /* Clear the data request background, but not SAFETY */
1558 rectangle_pixmap(process_list,
67f72973 1559 resourceview_data->drawing->drawing_area->style->black_gc,
9e01e6d4 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);
9e01e6d4 1565
1566 /* Get new data for the rest. */
67f72973 1567 drawing_data_request(resourceview_data->drawing,
9e01e6d4 1568 drawing->damage_begin, 0,
1569 drawing->damage_end - drawing->damage_begin,
67f72973 1570 resourceview_data->drawing->height);
9e01e6d4 1571 } else {
9e01e6d4 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;
67f72973 1578 guint width = resourceview_data->drawing->width;
9e01e6d4 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,
67f72973 1588 resourceview_data->drawing->drawing_area->style->black_gc,
9e01e6d4 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 =
67f72973 1598 resourceview_data->drawing->width;
9e01e6d4 1599
1600 drawing->damage_begin = 0;
1601
1602 rectangle_pixmap (process_list,
67f72973 1603 resourceview_data->drawing->drawing_area->style->black_gc,
9e01e6d4 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);
9e01e6d4 1610
1611 /* Get new data for the rest. */
67f72973 1612 drawing_data_request(resourceview_data->drawing,
9e01e6d4 1613 drawing->damage_begin, 0,
1614 drawing->damage_end - drawing->damage_begin,
67f72973 1615 resourceview_data->drawing->height);
9e01e6d4 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,
67f72973 1627 resourceview_data->drawing->drawing_area->style->black_gc,
9e01e6d4 1628 TRUE,
1629 0, 0,
67f72973 1630 resourceview_data->drawing->width+SAFETY, // do not overlap
9e01e6d4 1631 -1);
1632
9e01e6d4 1633 gtk_widget_queue_draw(drawing->drawing_area);
1634
1635 drawing->damage_begin = 0;
67f72973 1636 drawing->damage_end = resourceview_data->drawing->width;
9e01e6d4 1637
67f72973 1638 drawing_data_request(resourceview_data->drawing,
9e01e6d4 1639 0, 0,
67f72973 1640 resourceview_data->drawing->width,
1641 resourceview_data->drawing->height);
9e01e6d4 1642
1643 }
1644 }
1645 }
1646 } else {
1647 /* Different scale (zoom) */
1648 g_info("zoom");
1649
1650 rectangle_pixmap (process_list,
67f72973 1651 resourceview_data->drawing->drawing_area->style->black_gc,
9e01e6d4 1652 TRUE,
1653 0, 0,
67f72973 1654 resourceview_data->drawing->width+SAFETY, // do not overlap
9e01e6d4 1655 -1);
1656
9e01e6d4 1657 gtk_widget_queue_draw(drawing->drawing_area);
1658
1659 drawing->damage_begin = 0;
67f72973 1660 drawing->damage_end = resourceview_data->drawing->width;
9e01e6d4 1661
67f72973 1662 drawing_data_request(resourceview_data->drawing,
9e01e6d4 1663 0, 0,
67f72973 1664 resourceview_data->drawing->width,
1665 resourceview_data->drawing->height);
9e01e6d4 1666 }
1667
1668 /* Update directly when scrolling */
67f72973 1669 gdk_window_process_updates(resourceview_data->drawing->drawing_area->window,
9e01e6d4 1670 TRUE);
1671
1672 return 0;
1673}
1674
1675gint traceset_notify(void *hook_data, void *call_data)
1676{
67f72973 1677 ControlFlowData *resourceview_data = (ControlFlowData*) hook_data;
1678 Drawing_t *drawing = resourceview_data->drawing;
9e01e6d4 1679
1680 if(unlikely(drawing->gc == NULL)) {
1681 return FALSE;
1682 }
1683 if(drawing->dotted_gc == NULL) {
1684 return FALSE;
1685 }
1686
67f72973 1687 drawing_clear(resourceview_data->drawing);
1688 processlist_clear(resourceview_data->process_list);
9e01e6d4 1689 gtk_widget_set_size_request(
67f72973 1690 resourceview_data->drawing->drawing_area,
1691 -1, processlist_get_height(resourceview_data->process_list));
1692 redraw_notify(resourceview_data, NULL);
9e01e6d4 1693
67f72973 1694 request_background_data(resourceview_data);
9e01e6d4 1695
1696 return FALSE;
1697}
1698
1699gint redraw_notify(void *hook_data, void *call_data)
1700{
67f72973 1701 ControlFlowData *resourceview_data = (ControlFlowData*) hook_data;
1702 Drawing_t *drawing = resourceview_data->drawing;
9e01e6d4 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... */
67f72973 1709 drawing_clear(resourceview_data->drawing);
1710 processlist_clear(resourceview_data->process_list);
9e01e6d4 1711 gtk_widget_set_size_request(
67f72973 1712 resourceview_data->drawing->drawing_area,
1713 -1, processlist_get_height(resourceview_data->process_list));
9e01e6d4 1714 // Clear the images
67f72973 1715 rectangle_pixmap (resourceview_data->process_list,
9e01e6d4 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
9e01e6d4 1733 return FALSE;
1734
1735}
1736
1737
1738gint continue_notify(void *hook_data, void *call_data)
1739{
67f72973 1740 ControlFlowData *resourceview_data = (ControlFlowData*) hook_data;
1741 Drawing_t *drawing = resourceview_data->drawing;
9e01e6d4 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
1756gint update_current_time_hook(void *hook_data, void *call_data)
1757{
67f72973 1758 ControlFlowData *resourceview_data = (ControlFlowData*)hook_data;
9e01e6d4 1759
1760 LttTime current_time = *((LttTime*)call_data);
1761
1762 TimeWindow time_window =
67f72973 1763 lttvwindow_get_time_window(resourceview_data->tab);
9e01e6d4 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
dd47d0d8
YB
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;
9e01e6d4 1780
1781 g_info("New current time HOOK : %lu, %lu", current_time.tv_sec,
1782 current_time.tv_nsec);
9e01e6d4 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
67f72973 1809 lttvwindow_report_time_window(resourceview_data->tab, new_time_window);
9e01e6d4 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
67f72973 1825 lttvwindow_report_time_window(resourceview_data->tab, new_time_window);
9e01e6d4 1826
1827 }
67f72973 1828 gtk_widget_queue_draw(resourceview_data->drawing->drawing_area);
9e01e6d4 1829
1830 /* Update directly when scrolling */
67f72973 1831 gdk_window_process_updates(resourceview_data->drawing->drawing_area->window,
9e01e6d4 1832 TRUE);
1833
1834 return 0;
1835}
1836
1837typedef struct _ClosureData {
1838 EventsRequest *events_request;
9e01e6d4 1839 LttTime end_time;
1840 guint x_end;
1841} ClosureData;
1842
58a9b31b 1843/* Draw line until end of the screen */
9e01e6d4 1844
1845void draw_closure(gpointer key, gpointer value, gpointer user_data)
1846{
67f72973 1847 ResourceUniqueNumeric *process_info = (ResourceUniqueNumeric*)key;
44ffb95f 1848 HashedResourceData *hashed_process_data = (HashedResourceData*)value;
1849 ClosureData *closure_data = (ClosureData*)user_data;
1850
1851 EventsRequest *events_request = closure_data->events_request;
67f72973 1852 ControlFlowData *resourceview_data = events_request->viewer_data;
dd47d0d8 1853 LttvTraceset *ts = lttvwindow_get_traceset(resourceview_data->tab);
44ffb95f 1854
1855 LttTime evtime = closure_data->end_time;
1856
1857 gboolean dodraw = TRUE;
1858
67f72973 1859 if(hashed_process_data->type == RV_RESOURCE_MACHINE)
1860 return;
1861
44ffb95f 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
8284135e
YB
1872
1873 LttvTrace *trace = lttv_traceset_get(ts,process_info->trace_num);
dd47d0d8 1874 LttvTraceState *ts = trace->state;
44ffb95f 1875
67f72973 1876 /* Only draw for processes that are currently in the trace states */
44ffb95f 1877
44ffb95f 1878#ifdef EXTRA_CHECK
67f72973 1879 /* Should be alike when background info is ready */
1880 if(resourceview_data->background_info_waiting==0)
44ffb95f 1881 g_assert(ltt_time_compare(process->creation_time,
1882 process_info->birth) == 0);
1883#endif //EXTRA_CHECK
1884
67f72973 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);
44ffb95f 1894
1895#ifdef EXTRA_CHECK
67f72973 1896 if(ltt_time_compare(evtime, time_window.start_time) == -1
1897 || ltt_time_compare(evtime, time_window.end_time) == 1)
1898 return;
44ffb95f 1899#endif //EXTRA_CHECK
67f72973 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;
44ffb95f 1924#if 0
67f72973 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);
44ffb95f 1934
67f72973 1935 hashed_process_data->x.over = x;
1936 }
44ffb95f 1937#endif //0
1938
67f72973 1939 if(unlikely(x == hashed_process_data->x.middle &&
1940 hashed_process_data->x.middle_used)) {
44ffb95f 1941#if 0 /* do not mark closure : not missing information */
67f72973 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 }
44ffb95f 1951#endif //0
67f72973 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]);
0305fe77 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]);
38726a78 1967 else if(hashed_process_data->type == RV_RESOURCE_TRAP)
1968 trap_set_line_color(&prop_line, &ts->trap_states[process_info->id]);
67f72973 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);
44ffb95f 1974 }
67f72973 1975
1976 draw_line((void*)&prop_line, (void*)&draw_context);
1977 }
44ffb95f 1978
67f72973 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;
44ffb95f 1984
67f72973 1985 /* Calculate the next good time */
1986 convert_pixels_to_time(width, x+1, time_window,
1987 &hashed_process_data->next_good_time);
44ffb95f 1988 }
1989 }
67f72973 1990 }
44ffb95f 1991 }
9e01e6d4 1992}
1993
1994int before_chunk(void *hook_data, void *call_data)
1995{
1996 EventsRequest *events_request = (EventsRequest*)hook_data;
dd47d0d8
YB
1997 LttvTraceset *ts = (LttvTraceset*)call_data;
1998
9e01e6d4 1999#if 0
67f72973 2000 /* Deactivate sort */
9e01e6d4 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
dd47d0d8 2006 drawing_chunk_begin(events_request, ts);
9e01e6d4 2007
2008 return 0;
2009}
2010
d389bc8d 2011/* before_request
2012 *
2013 * This gets executed just before an events request is executed
2014 */
2015
9e01e6d4 2016int before_request(void *hook_data, void *call_data)
2017{
2018 EventsRequest *events_request = (EventsRequest*)hook_data;
9e01e6d4 2019
dd47d0d8 2020 drawing_data_request_begin(events_request);
9e01e6d4 2021
2022 return 0;
2023}
2024
dd47d0d8
YB
2025void draw_closing_lines(ControlFlowData *resourceview_data,
2026 EventsRequest* events_request)
9e01e6d4 2027{
dd47d0d8 2028 LttTime end_time = events_request->end_time;
67f72973 2029 ClosureData closure_data;
dd47d0d8 2030 closure_data.events_request = events_request;
67f72973 2031 closure_data.end_time = end_time;
2032
dd47d0d8 2033
67f72973 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
dd47d0d8 2043 guint i;
67f72973 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 */
dd47d0d8
YB
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 */
2063int 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
9e01e6d4 2071 return 0;
2072}
2073
2074/*
2075 * for each process
2076 * draw closing line
2077 * expose
2078 */
2079int after_chunk(void *hook_data, void *call_data)
2080{
2081 EventsRequest *events_request = (EventsRequest*)hook_data;
67f72973 2082 ControlFlowData *resourceview_data = events_request->viewer_data;
dd47d0d8
YB
2083 LttvTraceset *ts = (LttvTraceset*)call_data;
2084
9e01e6d4 2085 LttTime end_time;
2086
67f72973 2087 ProcessList *process_list = resourceview_data->process_list;
9e01e6d4 2088 guint i;
dd47d0d8 2089 guint nb_trace = lttv_traceset_number(ts);
9e01e6d4 2090
2091 /* Only execute when called for the first trace's events request */
43ed82b5 2092 if(!process_list->current_hash_data)
2093 return 0;
9e01e6d4 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;
dd47d0d8 2100#ifdef BABEL_CLEANUP
9e01e6d4 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;
dd47d0d8
YB
2105#endif
2106 draw_closing_lines(resourceview_data, events_request);
9e01e6d4 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 */
2119int before_statedump_end(void *hook_data, void *call_data)
2120{
dd47d0d8 2121 LttvEvent *event;
67f72973 2122
dd47d0d8
YB
2123 event = (LttvEvent *) call_data;
2124
2125 if (strcmp(lttv_traceset_get_name_from_event(event),"lttng_statedump_end") != 0)
2126 return FALSE;
9e01e6d4 2127
dd47d0d8 2128 ControlFlowData *resourceview_data = (ControlFlowData*) hook_data;
9e01e6d4 2129
9e01e6d4 2130
dd47d0d8
YB
2131 LttvTraceState *ts = event->state;
2132
2133
2134 gint i;
2135
2136#ifdef BABEL_CLEANUP
9e01e6d4 2137
67f72973 2138 LttvFilter *filter = resourceview_data->filter;
9e01e6d4 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;
dd47d0d8 2143#endif
9e01e6d4 2144
dd47d0d8 2145 LttTime evtime = lttv_event_get_timestamp(event);
9e01e6d4 2146
2147 ClosureData closure_data;
dd47d0d8
YB
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;
9e01e6d4 2154 closure_data.end_time = evtime;
2155
2156 TimeWindow time_window =
67f72973 2157 lttvwindow_get_time_window(resourceview_data->tab);
2158 guint width = resourceview_data->drawing->width;
9e01e6d4 2159 convert_time_to_pixels(
2160 time_window,
2161 evtime,
2162 width,
2163 &closure_data.x_end);
2164
2165 /* Draw last items */
67f72973 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,
9e01e6d4 2169 (void*)&closure_data);
67f72973 2170 }
9e01e6d4 2171#if 0
2172 /* Reactivate sort */
2173 gtk_tree_sortable_set_sort_column_id(
67f72973 2174 GTK_TREE_SORTABLE(resourceview_data->process_list->list_store),
9e01e6d4 2175 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
2176 GTK_SORT_ASCENDING);
2177
67f72973 2178 update_index_to_pixmap(resourceview_data->process_list);
9e01e6d4 2179 /* Request a full expose : drawing scrambled */
67f72973 2180 gtk_widget_queue_draw(resourceview_data->drawing->drawing_area);
9e01e6d4 2181#endif //0
2182 /* Request expose (updates damages zone also) */
dd47d0d8 2183 drawing_request_expose(&events_request, evtime);
9e01e6d4 2184
2185 return 0;
dd47d0d8 2186
9e01e6d4 2187}
This page took 0.152735 seconds and 4 git commands to generate.