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