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 | |
84 | extern 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 | |
92 | static 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 |
117 | static 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 | */ |
183 | GtkWidget * |
58a9b31b |
184 | h_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 | |
217 | void legend_destructor(GtkWindow *legend) |
218 | { |
219 | g_legend_list = g_slist_remove(g_legend_list, legend); |
220 | } |
221 | |
222 | /* Create a popup legend */ |
223 | GtkWidget * |
224 | h_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 | |
256 | int 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 |
266 | static 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 |
294 | static 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 |
313 | static void soft_irq_set_line_color(PropertiesLine *prop_line, LttvSoftIRQState *s) |
314 | { |
315 | GQuark present_state; |
316 | if(s->running == 0) |
317 | prop_line->color = drawing_colors_soft_irq[COL_SOFT_IRQ_IDLE]; |
318 | else |
319 | prop_line->color = drawing_colors_soft_irq[COL_SOFT_IRQ_BUSY]; |
320 | } |
321 | |
20d16f82 |
322 | static void bdev_set_line_color(PropertiesLine *prop_line, LttvBdevState *s) |
323 | { |
1b171947 |
324 | GQuark present_state; |
23e59a12 |
325 | if(s == 0 || s->mode_stack->len == 0) |
1b171947 |
326 | present_state = LTTV_BDEV_UNKNOWN; |
327 | else |
328 | present_state = ((GQuark*)s->mode_stack->data)[s->mode_stack->len-1]; |
20d16f82 |
329 | |
1b171947 |
330 | if(present_state == LTTV_BDEV_IDLE) { |
20d16f82 |
331 | prop_line->color = drawing_colors_bdev[COL_BDEV_IDLE]; |
332 | } |
333 | else if(present_state == LTTV_BDEV_BUSY_READING) { |
334 | prop_line->color = drawing_colors_bdev[COL_BDEV_BUSY_READING]; |
335 | } |
336 | else if(present_state == LTTV_BDEV_BUSY_WRITING) { |
337 | prop_line->color = drawing_colors_bdev[COL_BDEV_BUSY_WRITING]; |
338 | } |
1b171947 |
339 | else { |
340 | prop_line->color = drawing_colors_bdev[COL_BDEV_UNKNOWN]; |
341 | } |
20d16f82 |
342 | } |
343 | |
9e01e6d4 |
344 | /* before_schedchange_hook |
345 | * |
346 | * This function basically draw lines and icons. Two types of lines are drawn : |
347 | * one small (3 pixels?) representing the state of the process and the second |
348 | * type is thicker (10 pixels?) representing on which CPU a process is running |
349 | * (and this only in running state). |
350 | * |
351 | * Extremums of the lines : |
352 | * x_min : time of the last event context for this process kept in memory. |
353 | * x_max : time of the current event. |
354 | * y : middle of the process in the process list. The process is found in the |
355 | * list, therefore is it's position in pixels. |
356 | * |
357 | * The choice of lines'color is defined by the context of the last event for this |
358 | * process. |
359 | */ |
360 | |
361 | |
362 | int before_schedchange_hook(void *hook_data, void *call_data) |
363 | { |
dd455fb8 |
364 | LttvTraceHook *th = (LttvTraceHook*)hook_data; |
365 | EventsRequest *events_request = (EventsRequest*)th->hook_data; |
67f72973 |
366 | ControlFlowData *resourceview_data = events_request->viewer_data; |
9e01e6d4 |
367 | |
368 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
369 | |
370 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
371 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
372 | |
373 | LttEvent *e; |
374 | e = ltt_tracefile_get_event(tfc->tf); |
375 | gint target_pid_saved = tfc->target_pid; |
376 | |
377 | LttTime evtime = ltt_event_time(e); |
67f72973 |
378 | LttvFilter *filter = resourceview_data->filter; |
58a9b31b |
379 | |
9e01e6d4 |
380 | /* we are in a schedchange, before the state update. We must draw the |
381 | * items corresponding to the state before it changes : now is the right |
382 | * time to do it. |
383 | */ |
384 | |
385 | guint pid_out; |
386 | guint pid_in; |
ca5c76ed |
387 | pid_out = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 0)); |
388 | pid_in = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 1)); |
67f72973 |
389 | // TODO: can't we reenable this? pmf |
44ffb95f |
390 | // if(pid_in != 0 && pid_out != 0) { |
391 | // /* not a transition to/from idle */ |
392 | // return 0; |
393 | // } |
c4e6f4dc |
394 | |
9e01e6d4 |
395 | tfc->target_pid = pid_out; |
58a9b31b |
396 | |
67f72973 |
397 | guint cpu = tfs->cpu; |
9e01e6d4 |
398 | |
67f72973 |
399 | guint trace_num = ts->parent.index; |
400 | /* Add process to process list (if not present) */ |
401 | guint pl_height = 0; |
402 | HashedResourceData *hashed_process_data = NULL; |
403 | ProcessList *process_list = resourceview_data->process_list; |
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; |
500 | cpu_set_line_color(&prop_line, tfs->cpu_state); |
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 | */ |
528 | int after_schedchange_hook(void *hook_data, void *call_data) |
9e01e6d4 |
529 | { |
dd455fb8 |
530 | LttvTraceHook *th = (LttvTraceHook*)hook_data; |
531 | EventsRequest *events_request = (EventsRequest*)th->hook_data; |
67f72973 |
532 | ControlFlowData *resourceview_data = events_request->viewer_data; |
44ffb95f |
533 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
44ffb95f |
534 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
44ffb95f |
535 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
44ffb95f |
536 | LttEvent *e; |
67f72973 |
537 | |
44ffb95f |
538 | e = ltt_tracefile_get_event(tfc->tf); |
539 | |
67f72973 |
540 | LttvFilter *filter = resourceview_data->filter; |
44ffb95f |
541 | if(filter != NULL && filter->head != NULL) |
542 | if(!lttv_filter_tree_parse(filter->head,e,tfc->tf, |
543 | tfc->t_context->t,tfc,NULL,NULL)) |
544 | return FALSE; |
545 | |
546 | LttTime evtime = ltt_event_time(e); |
547 | |
44ffb95f |
548 | /* Add process to process list (if not present) */ |
549 | LttvProcessState *process_in; |
550 | LttTime birth; |
551 | guint pl_height = 0; |
552 | HashedResourceData *hashed_process_data_in = NULL; |
553 | |
67f72973 |
554 | ProcessList *process_list = resourceview_data->process_list; |
44ffb95f |
555 | |
556 | guint pid_in; |
557 | { |
558 | guint pid_out; |
ca5c76ed |
559 | pid_out = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 0)); |
560 | pid_in = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 1)); |
44ffb95f |
561 | } |
562 | |
563 | |
564 | /* Find process pid_in in the list... */ |
565 | //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in); |
566 | //process_in = tfs->process; |
567 | guint cpu = tfs->cpu; |
44ffb95f |
568 | guint trace_num = ts->parent.index; |
569 | process_in = ts->running_process[cpu]; |
570 | /* It should exist, because we are after the state update. */ |
571 | #ifdef EXTRA_CHECK |
572 | g_assert(process_in != NULL); |
573 | #endif //EXTRA_CHECK |
574 | birth = process_in->creation_time; |
575 | |
67f72973 |
576 | //hashed_process_data_in = processlist_get_process_data(process_list, cpuq, trace_num); |
577 | hashed_process_data_in = resourcelist_obtain_cpu(resourceview_data, trace_num, cpu); |
578 | |
44ffb95f |
579 | /* Set the current process */ |
580 | process_list->current_hash_data[trace_num][process_in->cpu] = |
581 | hashed_process_data_in; |
582 | |
583 | if(ltt_time_compare(hashed_process_data_in->next_good_time, |
584 | evtime) <= 0) |
585 | { |
586 | TimeWindow time_window = |
67f72973 |
587 | lttvwindow_get_time_window(resourceview_data->tab); |
44ffb95f |
588 | |
589 | #ifdef EXTRA_CHECK |
590 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
591 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
592 | return; |
593 | #endif //EXTRA_CHECK |
67f72973 |
594 | Drawing_t *drawing = resourceview_data->drawing; |
44ffb95f |
595 | guint width = drawing->width; |
596 | guint new_x; |
597 | |
598 | convert_time_to_pixels( |
599 | time_window, |
600 | evtime, |
601 | width, |
602 | &new_x); |
603 | |
604 | if(hashed_process_data_in->x.middle != new_x) { |
605 | hashed_process_data_in->x.middle = new_x; |
606 | hashed_process_data_in->x.middle_used = FALSE; |
607 | hashed_process_data_in->x.middle_marked = FALSE; |
608 | } |
609 | } |
58a9b31b |
610 | return 0; |
611 | } |
9e01e6d4 |
612 | |
58a9b31b |
613 | /* before_execmode_hook |
614 | * |
615 | * This function basically draw lines and icons. Two types of lines are drawn : |
616 | * one small (3 pixels?) representing the state of the process and the second |
617 | * type is thicker (10 pixels?) representing on which CPU a process is running |
618 | * (and this only in running state). |
619 | * |
620 | * Extremums of the lines : |
621 | * x_min : time of the last event context for this process kept in memory. |
622 | * x_max : time of the current event. |
623 | * y : middle of the process in the process list. The process is found in the |
624 | * list, therefore is it's position in pixels. |
625 | * |
626 | * The choice of lines'color is defined by the context of the last event for this |
627 | * process. |
628 | */ |
9e01e6d4 |
629 | |
598026ba |
630 | int before_execmode_hook(void *hook_data, void *call_data) |
631 | { |
dd455fb8 |
632 | LttvTraceHook *th = (LttvTraceHook*)hook_data; |
633 | EventsRequest *events_request = (EventsRequest*)th->hook_data; |
67f72973 |
634 | ControlFlowData *resourceview_data = events_request->viewer_data; |
598026ba |
635 | |
636 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
637 | |
638 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
639 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
640 | |
641 | LttEvent *e; |
642 | e = ltt_tracefile_get_event(tfc->tf); |
643 | |
644 | LttTime evtime = ltt_event_time(e); |
645 | |
8743690d |
646 | before_execmode_hook_irq(hook_data, call_data); |
0305fe77 |
647 | before_execmode_hook_soft_irq(hook_data, call_data); |
8743690d |
648 | |
598026ba |
649 | /* we are in a execmode, before the state update. We must draw the |
650 | * items corresponding to the state before it changes : now is the right |
651 | * time to do it. |
652 | */ |
653 | /* For the pid */ |
598026ba |
654 | guint cpu = tfs->cpu; |
67f72973 |
655 | |
598026ba |
656 | guint trace_num = ts->parent.index; |
657 | LttvProcessState *process = ts->running_process[cpu]; |
658 | g_assert(process != NULL); |
659 | |
598026ba |
660 | /* Well, the process_out existed : we must get it in the process hash |
661 | * or add it, and draw its items. |
662 | */ |
663 | /* Add process to process list (if not present) */ |
664 | guint pl_height = 0; |
665 | HashedResourceData *hashed_process_data = NULL; |
67f72973 |
666 | ProcessList *process_list = resourceview_data->process_list; |
667 | |
598026ba |
668 | LttTime birth = process->creation_time; |
669 | |
670 | if(likely(process_list->current_hash_data[trace_num][cpu] != NULL)) { |
671 | hashed_process_data = process_list->current_hash_data[trace_num][cpu]; |
672 | } else { |
67f72973 |
673 | hashed_process_data = resourcelist_obtain_cpu(resourceview_data, trace_num, cpu); |
674 | |
598026ba |
675 | /* Set the current process */ |
676 | process_list->current_hash_data[trace_num][process->cpu] = |
677 | hashed_process_data; |
678 | } |
679 | |
680 | /* Now, the process is in the state hash and our own process hash. |
681 | * We definitely can draw the items related to the ending state. |
682 | */ |
683 | |
684 | if(likely(ltt_time_compare(hashed_process_data->next_good_time, |
685 | evtime) > 0)) |
686 | { |
687 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
688 | TimeWindow time_window = |
67f72973 |
689 | lttvwindow_get_time_window(resourceview_data->tab); |
598026ba |
690 | |
691 | #ifdef EXTRA_CHECK |
692 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
693 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
694 | return; |
695 | #endif //EXTRA_CHECK |
67f72973 |
696 | Drawing_t *drawing = resourceview_data->drawing; |
598026ba |
697 | guint width = drawing->width; |
698 | guint x; |
699 | convert_time_to_pixels( |
700 | time_window, |
701 | evtime, |
702 | width, |
703 | &x); |
704 | |
705 | /* Draw collision indicator */ |
706 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
707 | gdk_draw_point(hashed_process_data->pixmap, |
708 | drawing->gc, |
709 | x, |
710 | COLLISION_POSITION(hashed_process_data->height)); |
711 | hashed_process_data->x.middle_marked = TRUE; |
712 | } |
d3d99fde |
713 | } |
714 | else { |
598026ba |
715 | TimeWindow time_window = |
67f72973 |
716 | lttvwindow_get_time_window(resourceview_data->tab); |
598026ba |
717 | |
718 | #ifdef EXTRA_CHECK |
719 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
720 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
721 | return; |
722 | #endif //EXTRA_CHECK |
67f72973 |
723 | Drawing_t *drawing = resourceview_data->drawing; |
598026ba |
724 | guint width = drawing->width; |
725 | guint x; |
726 | |
727 | convert_time_to_pixels( |
728 | time_window, |
729 | evtime, |
730 | width, |
731 | &x); |
732 | |
733 | |
734 | /* Jump over draw if we are at the same x position */ |
735 | if(unlikely(x == hashed_process_data->x.middle && |
736 | hashed_process_data->x.middle_used)) |
737 | { |
738 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
739 | /* Draw collision indicator */ |
740 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
741 | gdk_draw_point(hashed_process_data->pixmap, |
742 | drawing->gc, |
743 | x, |
744 | COLLISION_POSITION(hashed_process_data->height)); |
745 | hashed_process_data->x.middle_marked = TRUE; |
746 | } |
747 | /* jump */ |
d3d99fde |
748 | } |
749 | else { |
598026ba |
750 | |
751 | DrawContext draw_context; |
752 | /* Now create the drawing context that will be used to draw |
753 | * items related to the last state. */ |
754 | draw_context.drawable = hashed_process_data->pixmap; |
755 | draw_context.gc = drawing->gc; |
756 | draw_context.pango_layout = drawing->pango_layout; |
757 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
758 | draw_context.drawinfo.end.x = x; |
759 | |
760 | draw_context.drawinfo.y.over = 1; |
761 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
762 | draw_context.drawinfo.y.under = hashed_process_data->height; |
763 | |
764 | draw_context.drawinfo.start.offset.over = 0; |
765 | draw_context.drawinfo.start.offset.middle = 0; |
766 | draw_context.drawinfo.start.offset.under = 0; |
767 | draw_context.drawinfo.end.offset.over = 0; |
768 | draw_context.drawinfo.end.offset.middle = 0; |
769 | draw_context.drawinfo.end.offset.under = 0; |
770 | |
771 | { |
772 | /* Draw the line */ |
773 | PropertiesLine prop_line; |
d3d99fde |
774 | prop_line.line_width = STATE_LINE_WIDTH; |
775 | prop_line.style = GDK_LINE_SOLID; |
776 | prop_line.y = MIDDLE; |
777 | cpu_set_line_color(&prop_line, tfs->cpu_state); |
598026ba |
778 | draw_line((void*)&prop_line, (void*)&draw_context); |
779 | } |
780 | /* become the last x position */ |
781 | hashed_process_data->x.middle = x; |
782 | hashed_process_data->x.middle_used = TRUE; |
783 | hashed_process_data->x.middle_marked = FALSE; |
784 | |
785 | /* Calculate the next good time */ |
786 | convert_pixels_to_time(width, x+1, time_window, |
787 | &hashed_process_data->next_good_time); |
788 | } |
789 | } |
790 | |
791 | return 0; |
792 | } |
9e01e6d4 |
793 | |
8743690d |
794 | int before_execmode_hook_irq(void *hook_data, void *call_data) |
795 | { |
dd455fb8 |
796 | LttvTraceHook *th = (LttvTraceHook*)hook_data; |
797 | EventsRequest *events_request = (EventsRequest*)th->hook_data; |
67f72973 |
798 | ControlFlowData *resourceview_data = events_request->viewer_data; |
8743690d |
799 | |
800 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
801 | |
802 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
803 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
804 | |
805 | LttEvent *e; |
806 | e = ltt_tracefile_get_event(tfc->tf); |
807 | |
808 | LttTime evtime = ltt_event_time(e); |
809 | |
ca5c76ed |
810 | LttTrace *trace = tfc->t_context->t; |
811 | |
8743690d |
812 | /* we are in a execmode, before the state update. We must draw the |
813 | * items corresponding to the state before it changes : now is the right |
814 | * time to do it. |
815 | */ |
816 | /* For the pid */ |
817 | |
818 | guint64 irq; |
819 | guint cpu = tfs->cpu; |
820 | |
ca5c76ed |
821 | 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))); |
822 | 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))); |
823 | if(ev_id_entry == e->event_id) { |
824 | irq = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 0)); |
8743690d |
825 | } |
ca5c76ed |
826 | else if(ev_id_exit == e->event_id) { |
8743690d |
827 | irq = ts->cpu_states[cpu].last_irq; |
828 | } |
829 | else { |
830 | return 0; |
831 | } |
832 | |
8743690d |
833 | guint trace_num = ts->parent.index; |
834 | |
8743690d |
835 | /* Well, the process_out existed : we must get it in the process hash |
836 | * or add it, and draw its items. |
837 | */ |
838 | /* Add process to process list (if not present) */ |
839 | guint pl_height = 0; |
840 | HashedResourceData *hashed_process_data = NULL; |
67f72973 |
841 | ProcessList *process_list = resourceview_data->process_list; |
842 | |
843 | hashed_process_data = resourcelist_obtain_irq(resourceview_data, trace_num, irq); |
671c625b |
844 | // TODO: fix this, it's ugly and slow: |
845 | GQuark name; |
846 | { |
847 | gchar *str; |
848 | str = g_strdup_printf("IRQ %llu [%s]", irq, (char*)g_quark_to_string(ts->irq_names[irq])); |
849 | name = g_quark_from_string(str); |
850 | g_free(str); |
851 | } |
852 | gtk_tree_store_set(resourceview_data->process_list->list_store, &hashed_process_data->y_iter, NAME_COLUMN, g_quark_to_string(name), -1); |
8743690d |
853 | |
854 | /* Now, the process is in the state hash and our own process hash. |
855 | * We definitely can draw the items related to the ending state. |
856 | */ |
857 | |
858 | if(likely(ltt_time_compare(hashed_process_data->next_good_time, |
859 | evtime) > 0)) |
860 | { |
861 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
862 | TimeWindow time_window = |
67f72973 |
863 | lttvwindow_get_time_window(resourceview_data->tab); |
8743690d |
864 | |
865 | #ifdef EXTRA_CHECK |
866 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
867 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
868 | return; |
869 | #endif //EXTRA_CHECK |
67f72973 |
870 | Drawing_t *drawing = resourceview_data->drawing; |
8743690d |
871 | guint width = drawing->width; |
872 | guint x; |
873 | convert_time_to_pixels( |
874 | time_window, |
875 | evtime, |
876 | width, |
877 | &x); |
878 | |
879 | /* Draw collision indicator */ |
880 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
881 | gdk_draw_point(hashed_process_data->pixmap, |
882 | drawing->gc, |
883 | x, |
884 | COLLISION_POSITION(hashed_process_data->height)); |
885 | hashed_process_data->x.middle_marked = TRUE; |
886 | } |
887 | } |
888 | else { |
889 | TimeWindow time_window = |
67f72973 |
890 | lttvwindow_get_time_window(resourceview_data->tab); |
8743690d |
891 | |
892 | #ifdef EXTRA_CHECK |
893 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
894 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
895 | return; |
896 | #endif //EXTRA_CHECK |
67f72973 |
897 | Drawing_t *drawing = resourceview_data->drawing; |
8743690d |
898 | guint width = drawing->width; |
899 | guint x; |
900 | |
901 | convert_time_to_pixels( |
902 | time_window, |
903 | evtime, |
904 | width, |
905 | &x); |
906 | |
907 | |
908 | /* Jump over draw if we are at the same x position */ |
909 | if(unlikely(x == hashed_process_data->x.middle && |
910 | hashed_process_data->x.middle_used)) |
911 | { |
912 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
913 | /* Draw collision indicator */ |
914 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
915 | gdk_draw_point(hashed_process_data->pixmap, |
916 | drawing->gc, |
917 | x, |
918 | COLLISION_POSITION(hashed_process_data->height)); |
919 | hashed_process_data->x.middle_marked = TRUE; |
920 | } |
921 | /* jump */ |
922 | } |
923 | else { |
924 | |
925 | DrawContext draw_context; |
926 | /* Now create the drawing context that will be used to draw |
927 | * items related to the last state. */ |
928 | draw_context.drawable = hashed_process_data->pixmap; |
929 | draw_context.gc = drawing->gc; |
930 | draw_context.pango_layout = drawing->pango_layout; |
931 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
932 | draw_context.drawinfo.end.x = x; |
933 | |
934 | draw_context.drawinfo.y.over = 1; |
935 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
936 | draw_context.drawinfo.y.under = hashed_process_data->height; |
937 | |
938 | draw_context.drawinfo.start.offset.over = 0; |
939 | draw_context.drawinfo.start.offset.middle = 0; |
940 | draw_context.drawinfo.start.offset.under = 0; |
941 | draw_context.drawinfo.end.offset.over = 0; |
942 | draw_context.drawinfo.end.offset.middle = 0; |
943 | draw_context.drawinfo.end.offset.under = 0; |
944 | |
945 | { |
946 | /* Draw the line */ |
947 | PropertiesLine prop_line; |
948 | prop_line.line_width = STATE_LINE_WIDTH; |
949 | prop_line.style = GDK_LINE_SOLID; |
950 | prop_line.y = MIDDLE; |
951 | irq_set_line_color(&prop_line, &ts->irq_states[irq]); |
952 | draw_line((void*)&prop_line, (void*)&draw_context); |
953 | } |
954 | /* become the last x position */ |
955 | hashed_process_data->x.middle = x; |
956 | hashed_process_data->x.middle_used = TRUE; |
957 | hashed_process_data->x.middle_marked = FALSE; |
958 | |
959 | /* Calculate the next good time */ |
960 | convert_pixels_to_time(width, x+1, time_window, |
961 | &hashed_process_data->next_good_time); |
962 | } |
963 | } |
964 | |
965 | return 0; |
966 | } |
967 | |
0305fe77 |
968 | int before_execmode_hook_soft_irq(void *hook_data, void *call_data) |
969 | { |
970 | LttvTraceHook *th = (LttvTraceHook*)hook_data; |
971 | EventsRequest *events_request = (EventsRequest*)th->hook_data; |
972 | ControlFlowData *resourceview_data = events_request->viewer_data; |
973 | |
974 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
975 | |
976 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
977 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
978 | |
979 | LttEvent *e; |
980 | e = ltt_tracefile_get_event(tfc->tf); |
981 | |
982 | LttTime evtime = ltt_event_time(e); |
983 | |
984 | LttTrace *trace = tfc->t_context->t; |
985 | |
986 | /* we are in a execmode, before the state update. We must draw the |
987 | * items corresponding to the state before it changes : now is the right |
988 | * time to do it. |
989 | */ |
990 | /* For the pid */ |
991 | |
992 | guint64 softirq; |
993 | guint cpu = tfs->cpu; |
994 | |
995 | 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))); |
996 | 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))); |
997 | if(ev_id_entry == e->event_id) { |
998 | softirq = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 0)); |
999 | } |
1000 | else if(ev_id_exit == e->event_id) { |
1001 | softirq = ts->cpu_states[cpu].last_soft_irq; |
1002 | } |
1003 | else { |
1004 | return 0; |
1005 | } |
1006 | |
1007 | guint trace_num = ts->parent.index; |
1008 | |
1009 | /* Well, the process_out existed : we must get it in the process hash |
1010 | * or add it, and draw its items. |
1011 | */ |
1012 | /* Add process to process list (if not present) */ |
1013 | guint pl_height = 0; |
1014 | HashedResourceData *hashed_process_data = NULL; |
1015 | ProcessList *process_list = resourceview_data->process_list; |
1016 | |
1017 | hashed_process_data = resourcelist_obtain_soft_irq(resourceview_data, trace_num, softirq); |
1018 | |
1019 | /* Now, the process is in the state hash and our own process hash. |
1020 | * We definitely can draw the items related to the ending state. |
1021 | */ |
1022 | |
1023 | if(likely(ltt_time_compare(hashed_process_data->next_good_time, |
1024 | evtime) > 0)) |
1025 | { |
1026 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
1027 | TimeWindow time_window = |
1028 | lttvwindow_get_time_window(resourceview_data->tab); |
1029 | |
1030 | #ifdef EXTRA_CHECK |
1031 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
1032 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
1033 | return; |
1034 | #endif //EXTRA_CHECK |
1035 | Drawing_t *drawing = resourceview_data->drawing; |
1036 | guint width = drawing->width; |
1037 | guint x; |
1038 | convert_time_to_pixels( |
1039 | time_window, |
1040 | evtime, |
1041 | width, |
1042 | &x); |
1043 | |
1044 | /* Draw collision indicator */ |
1045 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
1046 | gdk_draw_point(hashed_process_data->pixmap, |
1047 | drawing->gc, |
1048 | x, |
1049 | COLLISION_POSITION(hashed_process_data->height)); |
1050 | hashed_process_data->x.middle_marked = TRUE; |
1051 | } |
1052 | } |
1053 | else { |
1054 | TimeWindow time_window = |
1055 | lttvwindow_get_time_window(resourceview_data->tab); |
1056 | |
1057 | #ifdef EXTRA_CHECK |
1058 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
1059 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
1060 | return; |
1061 | #endif //EXTRA_CHECK |
1062 | Drawing_t *drawing = resourceview_data->drawing; |
1063 | guint width = drawing->width; |
1064 | guint x; |
1065 | |
1066 | convert_time_to_pixels( |
1067 | time_window, |
1068 | evtime, |
1069 | width, |
1070 | &x); |
1071 | |
1072 | |
1073 | /* Jump over draw if we are at the same x position */ |
1074 | if(unlikely(x == hashed_process_data->x.middle && |
1075 | hashed_process_data->x.middle_used)) |
1076 | { |
1077 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
1078 | /* Draw collision indicator */ |
1079 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
1080 | gdk_draw_point(hashed_process_data->pixmap, |
1081 | drawing->gc, |
1082 | x, |
1083 | COLLISION_POSITION(hashed_process_data->height)); |
1084 | hashed_process_data->x.middle_marked = TRUE; |
1085 | } |
1086 | /* jump */ |
1087 | } |
1088 | else { |
1089 | |
1090 | DrawContext draw_context; |
1091 | /* Now create the drawing context that will be used to draw |
1092 | * items related to the last state. */ |
1093 | draw_context.drawable = hashed_process_data->pixmap; |
1094 | draw_context.gc = drawing->gc; |
1095 | draw_context.pango_layout = drawing->pango_layout; |
1096 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
1097 | draw_context.drawinfo.end.x = x; |
1098 | |
1099 | draw_context.drawinfo.y.over = 1; |
1100 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
1101 | draw_context.drawinfo.y.under = hashed_process_data->height; |
1102 | |
1103 | draw_context.drawinfo.start.offset.over = 0; |
1104 | draw_context.drawinfo.start.offset.middle = 0; |
1105 | draw_context.drawinfo.start.offset.under = 0; |
1106 | draw_context.drawinfo.end.offset.over = 0; |
1107 | draw_context.drawinfo.end.offset.middle = 0; |
1108 | draw_context.drawinfo.end.offset.under = 0; |
1109 | |
1110 | { |
1111 | /* Draw the line */ |
1112 | PropertiesLine prop_line; |
1113 | prop_line.line_width = STATE_LINE_WIDTH; |
1114 | prop_line.style = GDK_LINE_SOLID; |
1115 | prop_line.y = MIDDLE; |
1116 | soft_irq_set_line_color(&prop_line, &ts->soft_irq_states[softirq]); |
1117 | draw_line((void*)&prop_line, (void*)&draw_context); |
1118 | } |
1119 | /* become the last x position */ |
1120 | hashed_process_data->x.middle = x; |
1121 | hashed_process_data->x.middle_used = TRUE; |
1122 | hashed_process_data->x.middle_marked = FALSE; |
1123 | |
1124 | /* Calculate the next good time */ |
1125 | convert_pixels_to_time(width, x+1, time_window, |
1126 | &hashed_process_data->next_good_time); |
1127 | } |
1128 | } |
1129 | |
1130 | return 0; |
1131 | } |
1132 | |
1133 | |
20d16f82 |
1134 | int before_bdev_event_hook(void *hook_data, void *call_data) |
1135 | { |
dd455fb8 |
1136 | LttvTraceHook *th = (LttvTraceHook*)hook_data; |
1137 | EventsRequest *events_request = (EventsRequest*)th->hook_data; |
67f72973 |
1138 | ControlFlowData *resourceview_data = events_request->viewer_data; |
20d16f82 |
1139 | |
1140 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
1141 | |
1142 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
1143 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
1144 | |
1145 | LttEvent *e; |
1146 | e = ltt_tracefile_get_event(tfc->tf); |
1147 | |
1148 | LttTime evtime = ltt_event_time(e); |
1149 | |
20d16f82 |
1150 | /* we are in a execmode, before the state update. We must draw the |
1151 | * items corresponding to the state before it changes : now is the right |
1152 | * time to do it. |
1153 | */ |
1154 | /* For the pid */ |
1155 | |
1156 | guint cpu = tfs->cpu; |
ca5c76ed |
1157 | guint8 major = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 0)); |
1158 | guint8 minor = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 1)); |
1159 | guint oper = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 2)); |
20d16f82 |
1160 | gint devcode_gint = MKDEV(major,minor); |
1161 | |
20d16f82 |
1162 | guint trace_num = ts->parent.index; |
1163 | |
1164 | LttvBdevState *bdev = g_hash_table_lookup(ts->bdev_states, &devcode_gint); |
23e59a12 |
1165 | /* the result of the lookup might be NULL. that's ok, the rest of the function |
1166 | should understand it was not found and that its state is unknown */ |
20d16f82 |
1167 | |
20d16f82 |
1168 | /* Well, the process_out existed : we must get it in the process hash |
1169 | * or add it, and draw its items. |
1170 | */ |
1171 | /* Add process to process list (if not present) */ |
1172 | guint pl_height = 0; |
1173 | HashedResourceData *hashed_process_data = NULL; |
67f72973 |
1174 | ProcessList *process_list = resourceview_data->process_list; |
20d16f82 |
1175 | // LttTime birth = process->creation_time; |
1176 | |
1177 | // if(likely(process_list->current_hash_data[trace_num][cpu] != NULL)) { |
1178 | // hashed_process_data = process_list->current_hash_data[trace_num][cpu]; |
1179 | // } else { |
67f72973 |
1180 | hashed_process_data = resourcelist_obtain_bdev(resourceview_data, trace_num, devcode_gint); |
1181 | ////hashed_process_data = processlist_get_process_data(process_list, resourceq, trace_num); |
20d16f82 |
1182 | // hashed_process_data = processlist_get_process_data(process_list, |
1183 | // pid, |
1184 | // process->cpu, |
1185 | // &birth, |
1186 | // trace_num); |
67f72973 |
1187 | // |
20d16f82 |
1188 | /* Set the current process */ |
1189 | // process_list->current_hash_data[trace_num][process->cpu] = |
1190 | // hashed_process_data; |
1191 | // } |
1192 | |
1193 | /* Now, the process is in the state hash and our own process hash. |
1194 | * We definitely can draw the items related to the ending state. |
1195 | */ |
1196 | |
1197 | if(likely(ltt_time_compare(hashed_process_data->next_good_time, |
1198 | evtime) > 0)) |
1199 | { |
1200 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
1201 | TimeWindow time_window = |
67f72973 |
1202 | lttvwindow_get_time_window(resourceview_data->tab); |
20d16f82 |
1203 | |
1204 | #ifdef EXTRA_CHECK |
1205 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
1206 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
1207 | return; |
1208 | #endif //EXTRA_CHECK |
67f72973 |
1209 | Drawing_t *drawing = resourceview_data->drawing; |
20d16f82 |
1210 | guint width = drawing->width; |
1211 | guint x; |
1212 | convert_time_to_pixels( |
1213 | time_window, |
1214 | evtime, |
1215 | width, |
1216 | &x); |
1217 | |
1218 | /* Draw collision indicator */ |
1219 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
1220 | gdk_draw_point(hashed_process_data->pixmap, |
1221 | drawing->gc, |
1222 | x, |
1223 | COLLISION_POSITION(hashed_process_data->height)); |
1224 | hashed_process_data->x.middle_marked = TRUE; |
1225 | } |
1226 | } |
1227 | else { |
1228 | TimeWindow time_window = |
67f72973 |
1229 | lttvwindow_get_time_window(resourceview_data->tab); |
20d16f82 |
1230 | |
1231 | #ifdef EXTRA_CHECK |
1232 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
1233 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
1234 | return; |
1235 | #endif //EXTRA_CHECK |
67f72973 |
1236 | Drawing_t *drawing = resourceview_data->drawing; |
20d16f82 |
1237 | guint width = drawing->width; |
1238 | guint x; |
1239 | |
1240 | convert_time_to_pixels( |
1241 | time_window, |
1242 | evtime, |
1243 | width, |
1244 | &x); |
1245 | |
1246 | |
1247 | /* Jump over draw if we are at the same x position */ |
1248 | if(unlikely(x == hashed_process_data->x.middle && |
1249 | hashed_process_data->x.middle_used)) |
1250 | { |
1251 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
1252 | /* Draw collision indicator */ |
1253 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
1254 | gdk_draw_point(hashed_process_data->pixmap, |
1255 | drawing->gc, |
1256 | x, |
1257 | COLLISION_POSITION(hashed_process_data->height)); |
1258 | hashed_process_data->x.middle_marked = TRUE; |
1259 | } |
1260 | /* jump */ |
1261 | } |
1262 | else { |
1263 | |
1264 | DrawContext draw_context; |
1265 | /* Now create the drawing context that will be used to draw |
1266 | * items related to the last state. */ |
1267 | draw_context.drawable = hashed_process_data->pixmap; |
1268 | draw_context.gc = drawing->gc; |
1269 | draw_context.pango_layout = drawing->pango_layout; |
1270 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
1271 | draw_context.drawinfo.end.x = x; |
1272 | |
1273 | draw_context.drawinfo.y.over = 1; |
1274 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
1275 | draw_context.drawinfo.y.under = hashed_process_data->height; |
1276 | |
1277 | draw_context.drawinfo.start.offset.over = 0; |
1278 | draw_context.drawinfo.start.offset.middle = 0; |
1279 | draw_context.drawinfo.start.offset.under = 0; |
1280 | draw_context.drawinfo.end.offset.over = 0; |
1281 | draw_context.drawinfo.end.offset.middle = 0; |
1282 | draw_context.drawinfo.end.offset.under = 0; |
1283 | |
1284 | { |
1285 | /* Draw the line */ |
1286 | PropertiesLine prop_line; |
1287 | prop_line.line_width = STATE_LINE_WIDTH; |
1288 | prop_line.style = GDK_LINE_SOLID; |
1289 | prop_line.y = MIDDLE; |
1290 | bdev_set_line_color(&prop_line, bdev); |
1291 | draw_line((void*)&prop_line, (void*)&draw_context); |
1292 | } |
1293 | /* become the last x position */ |
1294 | hashed_process_data->x.middle = x; |
1295 | hashed_process_data->x.middle_used = TRUE; |
1296 | hashed_process_data->x.middle_marked = FALSE; |
1297 | |
1298 | /* Calculate the next good time */ |
1299 | convert_pixels_to_time(width, x+1, time_window, |
1300 | &hashed_process_data->next_good_time); |
1301 | } |
1302 | } |
1303 | |
1304 | return 0; |
1305 | } |
1306 | |
9e01e6d4 |
1307 | gint update_time_window_hook(void *hook_data, void *call_data) |
1308 | { |
67f72973 |
1309 | ControlFlowData *resourceview_data = (ControlFlowData*) hook_data; |
1310 | Drawing_t *drawing = resourceview_data->drawing; |
1311 | ProcessList *process_list = resourceview_data->process_list; |
9e01e6d4 |
1312 | |
1313 | const TimeWindowNotifyData *time_window_nofify_data = |
1314 | ((const TimeWindowNotifyData *)call_data); |
1315 | |
1316 | TimeWindow *old_time_window = |
1317 | time_window_nofify_data->old_time_window; |
1318 | TimeWindow *new_time_window = |
1319 | time_window_nofify_data->new_time_window; |
1320 | |
1321 | /* Update the ruler */ |
67f72973 |
1322 | drawing_update_ruler(resourceview_data->drawing, |
9e01e6d4 |
1323 | new_time_window); |
1324 | |
1325 | |
1326 | /* Two cases : zoom in/out or scrolling */ |
1327 | |
1328 | /* In order to make sure we can reuse the old drawing, the scale must |
1329 | * be the same and the new time interval being partly located in the |
1330 | * currently shown time interval. (reuse is only for scrolling) |
1331 | */ |
1332 | |
1333 | g_info("Old time window HOOK : %lu, %lu to %lu, %lu", |
1334 | old_time_window->start_time.tv_sec, |
1335 | old_time_window->start_time.tv_nsec, |
1336 | old_time_window->time_width.tv_sec, |
1337 | old_time_window->time_width.tv_nsec); |
1338 | |
1339 | g_info("New time window HOOK : %lu, %lu to %lu, %lu", |
1340 | new_time_window->start_time.tv_sec, |
1341 | new_time_window->start_time.tv_nsec, |
1342 | new_time_window->time_width.tv_sec, |
1343 | new_time_window->time_width.tv_nsec); |
1344 | |
1345 | if( new_time_window->time_width.tv_sec == old_time_window->time_width.tv_sec |
1346 | && new_time_window->time_width.tv_nsec == old_time_window->time_width.tv_nsec) |
1347 | { |
1348 | /* Same scale (scrolling) */ |
1349 | g_info("scrolling"); |
1350 | LttTime *ns = &new_time_window->start_time; |
1351 | LttTime *nw = &new_time_window->time_width; |
1352 | LttTime *os = &old_time_window->start_time; |
1353 | LttTime *ow = &old_time_window->time_width; |
1354 | LttTime old_end = old_time_window->end_time; |
1355 | LttTime new_end = new_time_window->end_time; |
1356 | //if(ns<os+w<ns+w) |
1357 | //if(ns<os+w && os+w<ns+w) |
1358 | //if(ns<old_end && os<ns) |
1359 | if(ltt_time_compare(*ns, old_end) == -1 |
1360 | && ltt_time_compare(*os, *ns) == -1) |
1361 | { |
1362 | g_info("scrolling near right"); |
1363 | /* Scroll right, keep right part of the screen */ |
1364 | guint x = 0; |
67f72973 |
1365 | guint width = resourceview_data->drawing->width; |
9e01e6d4 |
1366 | convert_time_to_pixels( |
1367 | *old_time_window, |
1368 | *ns, |
1369 | width, |
1370 | &x); |
1371 | |
1372 | /* Copy old data to new location */ |
1373 | copy_pixmap_region(process_list, |
1374 | NULL, |
67f72973 |
1375 | resourceview_data->drawing->drawing_area->style->black_gc, |
9e01e6d4 |
1376 | NULL, |
1377 | x, 0, |
1378 | 0, 0, |
67f72973 |
1379 | resourceview_data->drawing->width-x+SAFETY, -1); |
9e01e6d4 |
1380 | |
1381 | if(drawing->damage_begin == drawing->damage_end) |
67f72973 |
1382 | drawing->damage_begin = resourceview_data->drawing->width-x; |
9e01e6d4 |
1383 | else |
1384 | drawing->damage_begin = 0; |
1385 | |
67f72973 |
1386 | drawing->damage_end = resourceview_data->drawing->width; |
9e01e6d4 |
1387 | |
1388 | /* Clear the data request background, but not SAFETY */ |
1389 | rectangle_pixmap(process_list, |
67f72973 |
1390 | resourceview_data->drawing->drawing_area->style->black_gc, |
9e01e6d4 |
1391 | TRUE, |
1392 | drawing->damage_begin+SAFETY, 0, |
1393 | drawing->damage_end - drawing->damage_begin, // do not overlap |
1394 | -1); |
1395 | gtk_widget_queue_draw(drawing->drawing_area); |
9e01e6d4 |
1396 | |
1397 | /* Get new data for the rest. */ |
67f72973 |
1398 | drawing_data_request(resourceview_data->drawing, |
9e01e6d4 |
1399 | drawing->damage_begin, 0, |
1400 | drawing->damage_end - drawing->damage_begin, |
67f72973 |
1401 | resourceview_data->drawing->height); |
9e01e6d4 |
1402 | } else { |
9e01e6d4 |
1403 | if(ltt_time_compare(*ns,*os) == -1 |
1404 | && ltt_time_compare(*os,new_end) == -1) |
1405 | { |
1406 | g_info("scrolling near left"); |
1407 | /* Scroll left, keep left part of the screen */ |
1408 | guint x = 0; |
67f72973 |
1409 | guint width = resourceview_data->drawing->width; |
9e01e6d4 |
1410 | convert_time_to_pixels( |
1411 | *new_time_window, |
1412 | *os, |
1413 | width, |
1414 | &x); |
1415 | |
1416 | /* Copy old data to new location */ |
1417 | copy_pixmap_region (process_list, |
1418 | NULL, |
67f72973 |
1419 | resourceview_data->drawing->drawing_area->style->black_gc, |
9e01e6d4 |
1420 | NULL, |
1421 | 0, 0, |
1422 | x, 0, |
1423 | -1, -1); |
1424 | |
1425 | if(drawing->damage_begin == drawing->damage_end) |
1426 | drawing->damage_end = x; |
1427 | else |
1428 | drawing->damage_end = |
67f72973 |
1429 | resourceview_data->drawing->width; |
9e01e6d4 |
1430 | |
1431 | drawing->damage_begin = 0; |
1432 | |
1433 | rectangle_pixmap (process_list, |
67f72973 |
1434 | resourceview_data->drawing->drawing_area->style->black_gc, |
9e01e6d4 |
1435 | TRUE, |
1436 | drawing->damage_begin, 0, |
1437 | drawing->damage_end - drawing->damage_begin, // do not overlap |
1438 | -1); |
1439 | |
1440 | gtk_widget_queue_draw(drawing->drawing_area); |
9e01e6d4 |
1441 | |
1442 | /* Get new data for the rest. */ |
67f72973 |
1443 | drawing_data_request(resourceview_data->drawing, |
9e01e6d4 |
1444 | drawing->damage_begin, 0, |
1445 | drawing->damage_end - drawing->damage_begin, |
67f72973 |
1446 | resourceview_data->drawing->height); |
9e01e6d4 |
1447 | |
1448 | } else { |
1449 | if(ltt_time_compare(*ns,*os) == 0) |
1450 | { |
1451 | g_info("not scrolling"); |
1452 | } else { |
1453 | g_info("scrolling far"); |
1454 | /* Cannot reuse any part of the screen : far jump */ |
1455 | |
1456 | |
1457 | rectangle_pixmap (process_list, |
67f72973 |
1458 | resourceview_data->drawing->drawing_area->style->black_gc, |
9e01e6d4 |
1459 | TRUE, |
1460 | 0, 0, |
67f72973 |
1461 | resourceview_data->drawing->width+SAFETY, // do not overlap |
9e01e6d4 |
1462 | -1); |
1463 | |
9e01e6d4 |
1464 | gtk_widget_queue_draw(drawing->drawing_area); |
1465 | |
1466 | drawing->damage_begin = 0; |
67f72973 |
1467 | drawing->damage_end = resourceview_data->drawing->width; |
9e01e6d4 |
1468 | |
67f72973 |
1469 | drawing_data_request(resourceview_data->drawing, |
9e01e6d4 |
1470 | 0, 0, |
67f72973 |
1471 | resourceview_data->drawing->width, |
1472 | resourceview_data->drawing->height); |
9e01e6d4 |
1473 | |
1474 | } |
1475 | } |
1476 | } |
1477 | } else { |
1478 | /* Different scale (zoom) */ |
1479 | g_info("zoom"); |
1480 | |
1481 | rectangle_pixmap (process_list, |
67f72973 |
1482 | resourceview_data->drawing->drawing_area->style->black_gc, |
9e01e6d4 |
1483 | TRUE, |
1484 | 0, 0, |
67f72973 |
1485 | resourceview_data->drawing->width+SAFETY, // do not overlap |
9e01e6d4 |
1486 | -1); |
1487 | |
9e01e6d4 |
1488 | gtk_widget_queue_draw(drawing->drawing_area); |
1489 | |
1490 | drawing->damage_begin = 0; |
67f72973 |
1491 | drawing->damage_end = resourceview_data->drawing->width; |
9e01e6d4 |
1492 | |
67f72973 |
1493 | drawing_data_request(resourceview_data->drawing, |
9e01e6d4 |
1494 | 0, 0, |
67f72973 |
1495 | resourceview_data->drawing->width, |
1496 | resourceview_data->drawing->height); |
9e01e6d4 |
1497 | } |
1498 | |
1499 | /* Update directly when scrolling */ |
67f72973 |
1500 | gdk_window_process_updates(resourceview_data->drawing->drawing_area->window, |
9e01e6d4 |
1501 | TRUE); |
1502 | |
1503 | return 0; |
1504 | } |
1505 | |
1506 | gint traceset_notify(void *hook_data, void *call_data) |
1507 | { |
67f72973 |
1508 | ControlFlowData *resourceview_data = (ControlFlowData*) hook_data; |
1509 | Drawing_t *drawing = resourceview_data->drawing; |
9e01e6d4 |
1510 | |
1511 | if(unlikely(drawing->gc == NULL)) { |
1512 | return FALSE; |
1513 | } |
1514 | if(drawing->dotted_gc == NULL) { |
1515 | return FALSE; |
1516 | } |
1517 | |
67f72973 |
1518 | drawing_clear(resourceview_data->drawing); |
1519 | processlist_clear(resourceview_data->process_list); |
9e01e6d4 |
1520 | gtk_widget_set_size_request( |
67f72973 |
1521 | resourceview_data->drawing->drawing_area, |
1522 | -1, processlist_get_height(resourceview_data->process_list)); |
1523 | redraw_notify(resourceview_data, NULL); |
9e01e6d4 |
1524 | |
67f72973 |
1525 | request_background_data(resourceview_data); |
9e01e6d4 |
1526 | |
1527 | return FALSE; |
1528 | } |
1529 | |
1530 | gint redraw_notify(void *hook_data, void *call_data) |
1531 | { |
67f72973 |
1532 | ControlFlowData *resourceview_data = (ControlFlowData*) hook_data; |
1533 | Drawing_t *drawing = resourceview_data->drawing; |
9e01e6d4 |
1534 | GtkWidget *widget = drawing->drawing_area; |
1535 | |
1536 | drawing->damage_begin = 0; |
1537 | drawing->damage_end = drawing->width; |
1538 | |
1539 | /* fun feature, to be separated someday... */ |
67f72973 |
1540 | drawing_clear(resourceview_data->drawing); |
1541 | processlist_clear(resourceview_data->process_list); |
9e01e6d4 |
1542 | gtk_widget_set_size_request( |
67f72973 |
1543 | resourceview_data->drawing->drawing_area, |
1544 | -1, processlist_get_height(resourceview_data->process_list)); |
9e01e6d4 |
1545 | // Clear the images |
67f72973 |
1546 | rectangle_pixmap (resourceview_data->process_list, |
9e01e6d4 |
1547 | widget->style->black_gc, |
1548 | TRUE, |
1549 | 0, 0, |
1550 | drawing->alloc_width, |
1551 | -1); |
1552 | |
1553 | gtk_widget_queue_draw(drawing->drawing_area); |
1554 | |
1555 | if(drawing->damage_begin < drawing->damage_end) |
1556 | { |
1557 | drawing_data_request(drawing, |
1558 | drawing->damage_begin, |
1559 | 0, |
1560 | drawing->damage_end-drawing->damage_begin, |
1561 | drawing->height); |
1562 | } |
1563 | |
9e01e6d4 |
1564 | return FALSE; |
1565 | |
1566 | } |
1567 | |
1568 | |
1569 | gint continue_notify(void *hook_data, void *call_data) |
1570 | { |
67f72973 |
1571 | ControlFlowData *resourceview_data = (ControlFlowData*) hook_data; |
1572 | Drawing_t *drawing = resourceview_data->drawing; |
9e01e6d4 |
1573 | |
1574 | if(drawing->damage_begin < drawing->damage_end) |
1575 | { |
1576 | drawing_data_request(drawing, |
1577 | drawing->damage_begin, |
1578 | 0, |
1579 | drawing->damage_end-drawing->damage_begin, |
1580 | drawing->height); |
1581 | } |
1582 | |
1583 | return FALSE; |
1584 | } |
1585 | |
1586 | |
1587 | gint update_current_time_hook(void *hook_data, void *call_data) |
1588 | { |
67f72973 |
1589 | ControlFlowData *resourceview_data = (ControlFlowData*)hook_data; |
1590 | Drawing_t *drawing = resourceview_data->drawing; |
9e01e6d4 |
1591 | |
1592 | LttTime current_time = *((LttTime*)call_data); |
1593 | |
1594 | TimeWindow time_window = |
67f72973 |
1595 | lttvwindow_get_time_window(resourceview_data->tab); |
9e01e6d4 |
1596 | |
1597 | LttTime time_begin = time_window.start_time; |
1598 | LttTime width = time_window.time_width; |
1599 | LttTime half_width; |
1600 | { |
1601 | guint64 time_ll = ltt_time_to_uint64(width); |
1602 | time_ll = time_ll >> 1; /* divide by two */ |
1603 | half_width = ltt_time_from_uint64(time_ll); |
1604 | } |
1605 | LttTime time_end = ltt_time_add(time_begin, width); |
1606 | |
1607 | LttvTracesetContext * tsc = |
67f72973 |
1608 | lttvwindow_get_traceset_context(resourceview_data->tab); |
9e01e6d4 |
1609 | |
1610 | LttTime trace_start = tsc->time_span.start_time; |
1611 | LttTime trace_end = tsc->time_span.end_time; |
1612 | |
1613 | g_info("New current time HOOK : %lu, %lu", current_time.tv_sec, |
1614 | current_time.tv_nsec); |
9e01e6d4 |
1615 | |
1616 | /* If current time is inside time interval, just move the highlight |
1617 | * bar */ |
1618 | |
1619 | /* Else, we have to change the time interval. We have to tell it |
1620 | * to the main window. */ |
1621 | /* The time interval change will take care of placing the current |
1622 | * time at the center of the visible area, or nearest possible if we are |
1623 | * at one end of the trace. */ |
1624 | |
1625 | |
1626 | if(ltt_time_compare(current_time, time_begin) < 0) |
1627 | { |
1628 | TimeWindow new_time_window; |
1629 | |
1630 | if(ltt_time_compare(current_time, |
1631 | ltt_time_add(trace_start,half_width)) < 0) |
1632 | time_begin = trace_start; |
1633 | else |
1634 | time_begin = ltt_time_sub(current_time,half_width); |
1635 | |
1636 | new_time_window.start_time = time_begin; |
1637 | new_time_window.time_width = width; |
1638 | new_time_window.time_width_double = ltt_time_to_double(width); |
1639 | new_time_window.end_time = ltt_time_add(time_begin, width); |
1640 | |
67f72973 |
1641 | lttvwindow_report_time_window(resourceview_data->tab, new_time_window); |
9e01e6d4 |
1642 | } |
1643 | else if(ltt_time_compare(current_time, time_end) > 0) |
1644 | { |
1645 | TimeWindow new_time_window; |
1646 | |
1647 | if(ltt_time_compare(current_time, ltt_time_sub(trace_end, half_width)) > 0) |
1648 | time_begin = ltt_time_sub(trace_end,width); |
1649 | else |
1650 | time_begin = ltt_time_sub(current_time,half_width); |
1651 | |
1652 | new_time_window.start_time = time_begin; |
1653 | new_time_window.time_width = width; |
1654 | new_time_window.time_width_double = ltt_time_to_double(width); |
1655 | new_time_window.end_time = ltt_time_add(time_begin, width); |
1656 | |
67f72973 |
1657 | lttvwindow_report_time_window(resourceview_data->tab, new_time_window); |
9e01e6d4 |
1658 | |
1659 | } |
67f72973 |
1660 | gtk_widget_queue_draw(resourceview_data->drawing->drawing_area); |
9e01e6d4 |
1661 | |
1662 | /* Update directly when scrolling */ |
67f72973 |
1663 | gdk_window_process_updates(resourceview_data->drawing->drawing_area->window, |
9e01e6d4 |
1664 | TRUE); |
1665 | |
1666 | return 0; |
1667 | } |
1668 | |
1669 | typedef struct _ClosureData { |
1670 | EventsRequest *events_request; |
1671 | LttvTracesetState *tss; |
1672 | LttTime end_time; |
1673 | guint x_end; |
1674 | } ClosureData; |
1675 | |
58a9b31b |
1676 | /* Draw line until end of the screen */ |
9e01e6d4 |
1677 | |
1678 | void draw_closure(gpointer key, gpointer value, gpointer user_data) |
1679 | { |
67f72973 |
1680 | ResourceUniqueNumeric *process_info = (ResourceUniqueNumeric*)key; |
44ffb95f |
1681 | HashedResourceData *hashed_process_data = (HashedResourceData*)value; |
1682 | ClosureData *closure_data = (ClosureData*)user_data; |
1683 | |
1684 | EventsRequest *events_request = closure_data->events_request; |
67f72973 |
1685 | ControlFlowData *resourceview_data = events_request->viewer_data; |
44ffb95f |
1686 | |
1687 | LttvTracesetState *tss = closure_data->tss; |
1688 | LttvTracesetContext *tsc = (LttvTracesetContext*)tss; |
1689 | |
1690 | LttTime evtime = closure_data->end_time; |
1691 | |
1692 | gboolean dodraw = TRUE; |
1693 | |
67f72973 |
1694 | if(hashed_process_data->type == RV_RESOURCE_MACHINE) |
1695 | return; |
1696 | |
44ffb95f |
1697 | { |
1698 | /* For the process */ |
1699 | /* First, check if the current process is in the state computation |
1700 | * process list. If it is there, that means we must add it right now and |
1701 | * draw items from the beginning of the read for it. If it is not |
1702 | * present, it's a new process and it was not present : it will |
1703 | * be added after the state update. */ |
1704 | #ifdef EXTRA_CHECK |
1705 | g_assert(lttv_traceset_number(tsc->ts) > 0); |
1706 | #endif //EXTRA_CHECK |
1707 | LttvTraceContext *tc = tsc->traces[process_info->trace_num]; |
1708 | LttvTraceState *ts = (LttvTraceState*)tc; |
1709 | |
67f72973 |
1710 | /* Only draw for processes that are currently in the trace states */ |
44ffb95f |
1711 | |
67f72973 |
1712 | ProcessList *process_list = resourceview_data->process_list; |
44ffb95f |
1713 | #ifdef EXTRA_CHECK |
67f72973 |
1714 | /* Should be alike when background info is ready */ |
1715 | if(resourceview_data->background_info_waiting==0) |
44ffb95f |
1716 | g_assert(ltt_time_compare(process->creation_time, |
1717 | process_info->birth) == 0); |
1718 | #endif //EXTRA_CHECK |
1719 | |
67f72973 |
1720 | /* Now, the process is in the state hash and our own process hash. |
1721 | * We definitely can draw the items related to the ending state. |
1722 | */ |
1723 | |
1724 | if(unlikely(ltt_time_compare(hashed_process_data->next_good_time, |
1725 | evtime) <= 0)) |
1726 | { |
1727 | TimeWindow time_window = |
1728 | lttvwindow_get_time_window(resourceview_data->tab); |
44ffb95f |
1729 | |
1730 | #ifdef EXTRA_CHECK |
67f72973 |
1731 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
1732 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
1733 | return; |
44ffb95f |
1734 | #endif //EXTRA_CHECK |
67f72973 |
1735 | Drawing_t *drawing = resourceview_data->drawing; |
1736 | guint width = drawing->width; |
1737 | |
1738 | guint x = closure_data->x_end; |
1739 | |
1740 | DrawContext draw_context; |
1741 | |
1742 | /* Now create the drawing context that will be used to draw |
1743 | * items related to the last state. */ |
1744 | draw_context.drawable = hashed_process_data->pixmap; |
1745 | draw_context.gc = drawing->gc; |
1746 | draw_context.pango_layout = drawing->pango_layout; |
1747 | draw_context.drawinfo.end.x = x; |
1748 | |
1749 | draw_context.drawinfo.y.over = 1; |
1750 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
1751 | draw_context.drawinfo.y.under = hashed_process_data->height; |
1752 | |
1753 | draw_context.drawinfo.start.offset.over = 0; |
1754 | draw_context.drawinfo.start.offset.middle = 0; |
1755 | draw_context.drawinfo.start.offset.under = 0; |
1756 | draw_context.drawinfo.end.offset.over = 0; |
1757 | draw_context.drawinfo.end.offset.middle = 0; |
1758 | draw_context.drawinfo.end.offset.under = 0; |
44ffb95f |
1759 | #if 0 |
67f72973 |
1760 | /* Jump over draw if we are at the same x position */ |
1761 | if(x == hashed_process_data->x.over) |
1762 | { |
1763 | /* jump */ |
1764 | } else { |
1765 | draw_context.drawinfo.start.x = hashed_process_data->x.over; |
1766 | /* Draw the line */ |
1767 | PropertiesLine prop_line = prepare_execmode_line(process); |
1768 | draw_line((void*)&prop_line, (void*)&draw_context); |
44ffb95f |
1769 | |
67f72973 |
1770 | hashed_process_data->x.over = x; |
1771 | } |
44ffb95f |
1772 | #endif //0 |
1773 | |
67f72973 |
1774 | if(unlikely(x == hashed_process_data->x.middle && |
1775 | hashed_process_data->x.middle_used)) { |
44ffb95f |
1776 | #if 0 /* do not mark closure : not missing information */ |
67f72973 |
1777 | if(hashed_process_data->x.middle_marked == FALSE) { |
1778 | /* Draw collision indicator */ |
1779 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
1780 | gdk_draw_point(drawing->pixmap, |
1781 | drawing->gc, |
1782 | x, |
1783 | y+(height/2)-3); |
1784 | hashed_process_data->x.middle_marked = TRUE; |
1785 | } |
44ffb95f |
1786 | #endif //0 |
67f72973 |
1787 | /* Jump */ |
1788 | } else { |
1789 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
1790 | /* Draw the line */ |
1791 | if(dodraw) { |
1792 | PropertiesLine prop_line; |
1793 | prop_line.line_width = STATE_LINE_WIDTH; |
1794 | prop_line.style = GDK_LINE_SOLID; |
1795 | prop_line.y = MIDDLE; |
1796 | if(hashed_process_data->type == RV_RESOURCE_CPU) |
1797 | cpu_set_line_color(&prop_line, &ts->cpu_states[process_info->id]); |
1798 | else if(hashed_process_data->type == RV_RESOURCE_IRQ) |
1799 | irq_set_line_color(&prop_line, &ts->irq_states[process_info->id]); |
0305fe77 |
1800 | else if(hashed_process_data->type == RV_RESOURCE_SOFT_IRQ) |
1801 | soft_irq_set_line_color(&prop_line, &ts->soft_irq_states[process_info->id]); |
67f72973 |
1802 | else if(hashed_process_data->type == RV_RESOURCE_BDEV) { |
1803 | gint devcode_gint = process_info->id; |
1804 | LttvBdevState *bdev = g_hash_table_lookup(ts->bdev_states, &devcode_gint); |
1805 | // the lookup may return null; bdev_set_line_color must act appropriately |
1806 | bdev_set_line_color(&prop_line, bdev); |
44ffb95f |
1807 | } |
67f72973 |
1808 | |
1809 | draw_line((void*)&prop_line, (void*)&draw_context); |
1810 | } |
44ffb95f |
1811 | |
67f72973 |
1812 | /* become the last x position */ |
1813 | if(likely(x != hashed_process_data->x.middle)) { |
1814 | hashed_process_data->x.middle = x; |
1815 | /* but don't use the pixel */ |
1816 | hashed_process_data->x.middle_used = FALSE; |
44ffb95f |
1817 | |
67f72973 |
1818 | /* Calculate the next good time */ |
1819 | convert_pixels_to_time(width, x+1, time_window, |
1820 | &hashed_process_data->next_good_time); |
44ffb95f |
1821 | } |
1822 | } |
67f72973 |
1823 | } |
44ffb95f |
1824 | } |
9e01e6d4 |
1825 | } |
1826 | |
1827 | int before_chunk(void *hook_data, void *call_data) |
1828 | { |
1829 | EventsRequest *events_request = (EventsRequest*)hook_data; |
1830 | LttvTracesetState *tss = (LttvTracesetState*)call_data; |
1831 | ControlFlowData *cfd = (ControlFlowData*)events_request->viewer_data; |
1832 | #if 0 |
67f72973 |
1833 | /* Deactivate sort */ |
9e01e6d4 |
1834 | gtk_tree_sortable_set_sort_column_id( |
1835 | GTK_TREE_SORTABLE(cfd->process_list->list_store), |
1836 | TRACE_COLUMN, |
1837 | GTK_SORT_ASCENDING); |
1838 | #endif //0 |
1839 | drawing_chunk_begin(events_request, tss); |
1840 | |
1841 | return 0; |
1842 | } |
1843 | |
1844 | int before_request(void *hook_data, void *call_data) |
1845 | { |
1846 | EventsRequest *events_request = (EventsRequest*)hook_data; |
1847 | LttvTracesetState *tss = (LttvTracesetState*)call_data; |
1848 | |
1849 | drawing_data_request_begin(events_request, tss); |
1850 | |
1851 | return 0; |
1852 | } |
1853 | |
1854 | |
1855 | /* |
1856 | * after request is necessary in addition of after chunk in order to draw |
1857 | * lines until the end of the screen. after chunk just draws lines until |
1858 | * the last event. |
1859 | * |
1860 | * for each process |
1861 | * draw closing line |
1862 | * expose |
1863 | */ |
1864 | int after_request(void *hook_data, void *call_data) |
1865 | { |
67f72973 |
1866 | guint i; |
1867 | EventsRequest *events_request = (EventsRequest*)hook_data; |
1868 | ControlFlowData *resourceview_data = events_request->viewer_data; |
1869 | LttvTracesetState *tss = (LttvTracesetState*)call_data; |
1870 | |
1871 | ProcessList *process_list = resourceview_data->process_list; |
1872 | LttTime end_time = events_request->end_time; |
1873 | |
1874 | ClosureData closure_data; |
1875 | closure_data.events_request = (EventsRequest*)hook_data; |
1876 | closure_data.tss = tss; |
1877 | closure_data.end_time = end_time; |
1878 | |
1879 | TimeWindow time_window = |
1880 | lttvwindow_get_time_window(resourceview_data->tab); |
1881 | guint width = resourceview_data->drawing->width; |
1882 | convert_time_to_pixels( |
1883 | time_window, |
1884 | end_time, |
1885 | width, |
1886 | &closure_data.x_end); |
1887 | |
1888 | |
1889 | /* Draw last items */ |
1890 | for(i=0; i<RV_RESOURCE_COUNT; i++) { |
1891 | g_hash_table_foreach(resourcelist_get_resource_hash_table(resourceview_data, i), draw_closure, |
1892 | (void*)&closure_data); |
1893 | } |
1894 | |
1895 | /* Request expose */ |
1896 | drawing_request_expose(events_request, tss, end_time); |
9e01e6d4 |
1897 | return 0; |
1898 | } |
1899 | |
1900 | /* |
1901 | * for each process |
1902 | * draw closing line |
1903 | * expose |
1904 | */ |
1905 | int after_chunk(void *hook_data, void *call_data) |
1906 | { |
1907 | EventsRequest *events_request = (EventsRequest*)hook_data; |
67f72973 |
1908 | ControlFlowData *resourceview_data = events_request->viewer_data; |
9e01e6d4 |
1909 | LttvTracesetState *tss = (LttvTracesetState*)call_data; |
1910 | LttvTracesetContext *tsc = (LttvTracesetContext*)call_data; |
1911 | LttvTracefileContext *tfc = lttv_traceset_context_get_current_tfc(tsc); |
1912 | LttTime end_time; |
1913 | |
67f72973 |
1914 | ProcessList *process_list = resourceview_data->process_list; |
9e01e6d4 |
1915 | guint i; |
1916 | LttvTraceset *traceset = tsc->ts; |
1917 | guint nb_trace = lttv_traceset_number(traceset); |
1918 | |
1919 | /* Only execute when called for the first trace's events request */ |
1920 | if(!process_list->current_hash_data) return; |
1921 | |
1922 | for(i = 0 ; i < nb_trace ; i++) { |
1923 | g_free(process_list->current_hash_data[i]); |
1924 | } |
1925 | g_free(process_list->current_hash_data); |
1926 | process_list->current_hash_data = NULL; |
1927 | |
1928 | if(tfc != NULL) |
1929 | end_time = LTT_TIME_MIN(tfc->timestamp, events_request->end_time); |
1930 | else /* end of traceset, or position now out of request : end */ |
1931 | end_time = events_request->end_time; |
1932 | |
1933 | ClosureData closure_data; |
1934 | closure_data.events_request = (EventsRequest*)hook_data; |
1935 | closure_data.tss = tss; |
1936 | closure_data.end_time = end_time; |
1937 | |
1938 | TimeWindow time_window = |
67f72973 |
1939 | lttvwindow_get_time_window(resourceview_data->tab); |
1940 | guint width = resourceview_data->drawing->width; |
9e01e6d4 |
1941 | convert_time_to_pixels( |
1942 | time_window, |
1943 | end_time, |
1944 | width, |
1945 | &closure_data.x_end); |
1946 | |
1947 | /* Draw last items */ |
67f72973 |
1948 | for(i=0; i<RV_RESOURCE_COUNT; i++) { |
1949 | g_hash_table_foreach(resourcelist_get_resource_hash_table(resourceview_data, i), draw_closure, |
9e01e6d4 |
1950 | (void*)&closure_data); |
67f72973 |
1951 | } |
9e01e6d4 |
1952 | #if 0 |
1953 | /* Reactivate sort */ |
1954 | gtk_tree_sortable_set_sort_column_id( |
67f72973 |
1955 | GTK_TREE_SORTABLE(resourceview_data->process_list->list_store), |
9e01e6d4 |
1956 | GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, |
1957 | GTK_SORT_ASCENDING); |
1958 | |
67f72973 |
1959 | update_index_to_pixmap(resourceview_data->process_list); |
9e01e6d4 |
1960 | /* Request a full expose : drawing scrambled */ |
67f72973 |
1961 | gtk_widget_queue_draw(resourceview_data->drawing->drawing_area); |
9e01e6d4 |
1962 | #endif //0 |
1963 | /* Request expose (updates damages zone also) */ |
1964 | drawing_request_expose(events_request, tss, end_time); |
1965 | |
1966 | return 0; |
1967 | } |
1968 | |
1969 | /* after_statedump_end |
1970 | * |
1971 | * @param hook_data ControlFlowData structure of the viewer. |
1972 | * @param call_data Event context. |
1973 | * |
1974 | * This function adds items to be drawn in a queue for each process. |
1975 | * |
1976 | */ |
1977 | int before_statedump_end(void *hook_data, void *call_data) |
1978 | { |
67f72973 |
1979 | gint i; |
1980 | |
dd455fb8 |
1981 | LttvTraceHook *th = (LttvTraceHook*)hook_data; |
1982 | EventsRequest *events_request = (EventsRequest*)th->hook_data; |
67f72973 |
1983 | ControlFlowData *resourceview_data = events_request->viewer_data; |
9e01e6d4 |
1984 | |
1985 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
1986 | |
1987 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
1988 | |
1989 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
1990 | |
1991 | LttvTracesetState *tss = (LttvTracesetState*)tfc->t_context->ts_context; |
67f72973 |
1992 | ProcessList *process_list = resourceview_data->process_list; |
9e01e6d4 |
1993 | |
1994 | LttEvent *e; |
1995 | e = ltt_tracefile_get_event(tfc->tf); |
1996 | |
67f72973 |
1997 | LttvFilter *filter = resourceview_data->filter; |
9e01e6d4 |
1998 | if(filter != NULL && filter->head != NULL) |
1999 | if(!lttv_filter_tree_parse(filter->head,e,tfc->tf, |
2000 | tfc->t_context->t,tfc,NULL,NULL)) |
2001 | return FALSE; |
2002 | |
2003 | LttTime evtime = ltt_event_time(e); |
2004 | |
2005 | ClosureData closure_data; |
2006 | closure_data.events_request = events_request; |
2007 | closure_data.tss = tss; |
2008 | closure_data.end_time = evtime; |
2009 | |
2010 | TimeWindow time_window = |
67f72973 |
2011 | lttvwindow_get_time_window(resourceview_data->tab); |
2012 | guint width = resourceview_data->drawing->width; |
9e01e6d4 |
2013 | convert_time_to_pixels( |
2014 | time_window, |
2015 | evtime, |
2016 | width, |
2017 | &closure_data.x_end); |
2018 | |
2019 | /* Draw last items */ |
67f72973 |
2020 | |
2021 | for(i=0; i<RV_RESOURCE_COUNT; i++) { |
2022 | g_hash_table_foreach(resourcelist_get_resource_hash_table(resourceview_data, i), draw_closure, |
9e01e6d4 |
2023 | (void*)&closure_data); |
67f72973 |
2024 | } |
9e01e6d4 |
2025 | #if 0 |
2026 | /* Reactivate sort */ |
2027 | gtk_tree_sortable_set_sort_column_id( |
67f72973 |
2028 | GTK_TREE_SORTABLE(resourceview_data->process_list->list_store), |
9e01e6d4 |
2029 | GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, |
2030 | GTK_SORT_ASCENDING); |
2031 | |
67f72973 |
2032 | update_index_to_pixmap(resourceview_data->process_list); |
9e01e6d4 |
2033 | /* Request a full expose : drawing scrambled */ |
67f72973 |
2034 | gtk_widget_queue_draw(resourceview_data->drawing->drawing_area); |
9e01e6d4 |
2035 | #endif //0 |
2036 | /* Request expose (updates damages zone also) */ |
2037 | drawing_request_expose(events_request, tss, evtime); |
2038 | |
2039 | return 0; |
2040 | } |