ce0214a6 |
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 | |
f0d936c0 |
20 | /***************************************************************************** |
21 | * Hooks to be called by the main window * |
22 | *****************************************************************************/ |
23 | |
f0d936c0 |
24 | |
b9a010a2 |
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 | * |
e92eabaf |
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. |
b9a010a2 |
31 | * |
e92eabaf |
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. |
b9a010a2 |
34 | * |
e92eabaf |
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 |
b9a010a2 |
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 |
e92eabaf |
40 | * corresponding to it is over, which happens to be at the next before_schedchange |
b9a010a2 |
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 | |
4e4d11b3 |
48 | #ifdef HAVE_CONFIG_H |
49 | #include <config.h> |
50 | #endif |
b9a010a2 |
51 | |
cf6cb7e0 |
52 | //#define PANGO_ENABLE_BACKEND |
558aa013 |
53 | #include <gtk/gtk.h> |
54 | #include <gdk/gdk.h> |
5f16133f |
55 | #include <glib.h> |
80a52ff8 |
56 | #include <assert.h> |
50439712 |
57 | #include <string.h> |
319e9d81 |
58 | #include <stdio.h> |
5f16133f |
59 | |
cf6cb7e0 |
60 | //#include <pango/pango.h> |
61 | |
80a52ff8 |
62 | #include <ltt/event.h> |
4ba42155 |
63 | #include <ltt/time.h> |
50439712 |
64 | #include <ltt/type.h> |
2c82c4dc |
65 | #include <ltt/trace.h> |
80a52ff8 |
66 | |
2a2fa4f0 |
67 | #include <lttv/lttv.h> |
558aa013 |
68 | #include <lttv/hook.h> |
80a52ff8 |
69 | #include <lttv/state.h> |
2d262115 |
70 | #include <lttvwindow/lttvwindow.h> |
6395d57c |
71 | #include <lttvwindow/lttvwindowtraces.h> |
0de51231 |
72 | #include <lttvwindow/support.h> |
80a52ff8 |
73 | |
f0d936c0 |
74 | |
a117e3f7 |
75 | #include "eventhooks.h" |
76 | #include "cfv.h" |
77 | #include "processlist.h" |
78 | #include "drawing.h" |
5f16133f |
79 | |
80a52ff8 |
80 | |
1a31868c |
81 | #define MAX_PATH_LEN 256 |
82 | |
0de51231 |
83 | extern GSList *g_legend_list; |
84 | |
b9a010a2 |
85 | |
6395d57c |
86 | /* Action to do when background computation completed. |
87 | * |
e800cf84 |
88 | * Wait for all the awaited computations to be over. |
6395d57c |
89 | */ |
90 | |
703b25fa |
91 | static gint background_ready(void *hook_data, void *call_data) |
6395d57c |
92 | { |
93 | ControlFlowData *control_flow_data = (ControlFlowData *)hook_data; |
94 | LttvTrace *trace = (LttvTrace*)call_data; |
95 | |
e800cf84 |
96 | control_flow_data->background_info_waiting--; |
97 | |
98 | if(control_flow_data->background_info_waiting == 0) { |
4a24fa1f |
99 | g_message("control flow viewer : background computation data ready."); |
6395d57c |
100 | |
e800cf84 |
101 | drawing_clear(control_flow_data->drawing); |
102 | processlist_clear(control_flow_data->process_list); |
07390ec1 |
103 | gtk_widget_set_size_request( |
104 | control_flow_data->drawing->drawing_area, |
105 | -1, processlist_get_height(control_flow_data->process_list)); |
e800cf84 |
106 | redraw_notify(control_flow_data, NULL); |
b9a010a2 |
107 | } |
6395d57c |
108 | |
109 | return 0; |
110 | } |
111 | |
112 | |
113 | /* Request background computation. Verify if it is in progress or ready first. |
e800cf84 |
114 | * Only for each trace in the tab's traceset. |
6395d57c |
115 | */ |
3f7f592e |
116 | static void request_background_data(ControlFlowData *control_flow_data) |
6395d57c |
117 | { |
e800cf84 |
118 | LttvTracesetContext * tsc = |
119 | lttvwindow_get_traceset_context(control_flow_data->tab); |
120 | gint num_traces = lttv_traceset_number(tsc->ts); |
6395d57c |
121 | gint i; |
122 | LttvTrace *trace; |
123 | |
124 | LttvHooks *background_ready_hook = |
125 | lttv_hooks_new(); |
126 | lttv_hooks_add(background_ready_hook, background_ready, control_flow_data, |
127 | LTTV_PRIO_DEFAULT); |
e800cf84 |
128 | control_flow_data->background_info_waiting = 0; |
6395d57c |
129 | |
130 | for(i=0;i<num_traces;i++) { |
e800cf84 |
131 | trace = lttv_traceset_get(tsc->ts, i); |
6395d57c |
132 | |
133 | if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace)==FALSE) { |
134 | |
135 | if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"), |
136 | trace) == FALSE) { |
137 | /* We first remove requests that could have been done for the same |
138 | * information. Happens when two viewers ask for it before servicing |
139 | * starts. |
140 | */ |
93ac601b |
141 | if(!lttvwindowtraces_background_request_find(trace, "state")) |
b5e17af5 |
142 | lttvwindowtraces_background_request_queue( |
143 | main_window_get_widget(control_flow_data->tab), trace, "state"); |
6395d57c |
144 | lttvwindowtraces_background_notify_queue(control_flow_data, |
145 | trace, |
146 | ltt_time_infinite, |
147 | NULL, |
148 | background_ready_hook); |
e800cf84 |
149 | control_flow_data->background_info_waiting++; |
6395d57c |
150 | } else { /* in progress */ |
151 | |
152 | lttvwindowtraces_background_notify_current(control_flow_data, |
153 | trace, |
154 | ltt_time_infinite, |
155 | NULL, |
156 | background_ready_hook); |
e800cf84 |
157 | control_flow_data->background_info_waiting++; |
6395d57c |
158 | } |
4368b993 |
159 | } else { |
160 | /* Data ready. Be its nature, this viewer doesn't need to have |
618fbcc1 |
161 | * its data ready hook called there, because a background |
4368b993 |
162 | * request is always linked with a redraw. |
163 | */ |
6395d57c |
164 | } |
4368b993 |
165 | |
6395d57c |
166 | } |
167 | |
168 | lttv_hooks_destroy(background_ready_hook); |
169 | } |
170 | |
171 | |
172 | |
173 | |
f0d936c0 |
174 | /** |
175 | * Event Viewer's constructor hook |
176 | * |
177 | * This constructor is given as a parameter to the menuitem and toolbar button |
178 | * registration. It creates the list. |
ca0f8a8e |
179 | * @param tab A pointer to the parent tab. |
f0d936c0 |
180 | * @return The widget created. |
181 | */ |
182 | GtkWidget * |
d47b33d2 |
183 | h_guicontrolflow(Tab *tab) |
f0d936c0 |
184 | { |
d47b33d2 |
185 | g_info("h_guicontrolflow, %p", tab); |
6cec4cd2 |
186 | ControlFlowData *control_flow_data = guicontrolflow(tab) ; |
a56a1ba4 |
187 | |
ca0f8a8e |
188 | control_flow_data->tab = tab; |
a56a1ba4 |
189 | |
a56a1ba4 |
190 | // Unreg done in the GuiControlFlow_Destructor |
6395d57c |
191 | lttvwindow_register_traceset_notify(tab, |
192 | traceset_notify, |
193 | control_flow_data); |
194 | |
ca0f8a8e |
195 | lttvwindow_register_time_window_notify(tab, |
224446ce |
196 | update_time_window_hook, |
197 | control_flow_data); |
ca0f8a8e |
198 | lttvwindow_register_current_time_notify(tab, |
224446ce |
199 | update_current_time_hook, |
200 | control_flow_data); |
ca0f8a8e |
201 | lttvwindow_register_redraw_notify(tab, |
202 | redraw_notify, |
203 | control_flow_data); |
204 | lttvwindow_register_continue_notify(tab, |
205 | continue_notify, |
206 | control_flow_data); |
667ca2a0 |
207 | request_background_data(control_flow_data); |
6395d57c |
208 | |
ca0f8a8e |
209 | |
68997a22 |
210 | return guicontrolflow_get_widget(control_flow_data) ; |
a56a1ba4 |
211 | |
f0d936c0 |
212 | } |
213 | |
0de51231 |
214 | void legend_destructor(GtkWindow *legend) |
215 | { |
216 | g_legend_list = g_slist_remove(g_legend_list, legend); |
217 | } |
218 | |
219 | /* Create a popup legend */ |
220 | GtkWidget * |
221 | h_legend(Tab *tab) |
222 | { |
223 | g_info("h_legend, %p", tab); |
224 | |
225 | GtkWindow *legend = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
226 | |
227 | g_legend_list = g_slist_append( |
228 | g_legend_list, |
229 | legend); |
230 | |
231 | g_object_set_data_full( |
232 | G_OBJECT(legend), |
233 | "legend", |
234 | legend, |
235 | (GDestroyNotify)legend_destructor); |
236 | |
237 | gtk_window_set_title(legend, "Control Flow View Legend"); |
238 | |
239 | GtkWidget *pixmap = create_pixmap(GTK_WIDGET(legend), "lttv-color-list.png"); |
240 | |
241 | // GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixmap( |
242 | // GDK_PIXMAP(pixmap), NULL)); |
243 | |
244 | gtk_container_add(GTK_CONTAINER(legend), GTK_WIDGET(pixmap)); |
245 | |
246 | gtk_widget_show(GTK_WIDGET(pixmap)); |
247 | gtk_widget_show(GTK_WIDGET(legend)); |
248 | |
249 | |
250 | return NULL; /* This is a popup window */ |
251 | } |
252 | |
253 | |
3cff8cc1 |
254 | int event_selected_hook(void *hook_data, void *call_data) |
f0d936c0 |
255 | { |
68997a22 |
256 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
14963be0 |
257 | guint *event_number = (guint*) call_data; |
f0d936c0 |
258 | |
2a2fa4f0 |
259 | g_debug("DEBUG : event selected by main window : %u", *event_number); |
a56a1ba4 |
260 | |
2eef04b5 |
261 | return 0; |
f0d936c0 |
262 | } |
263 | |
9a1ec01b |
264 | /* Function that selects the color of status&exemode line */ |
6550d711 |
265 | static inline PropertiesLine prepare_s_e_line(LttvProcessState *process) |
9a1ec01b |
266 | { |
267 | PropertiesLine prop_line; |
268 | prop_line.line_width = 2; |
269 | prop_line.style = GDK_LINE_SOLID; |
270 | prop_line.y = MIDDLE; |
271 | //GdkColormap *colormap = gdk_colormap_get_system(); |
272 | |
9a1ec01b |
273 | if(process->state->s == LTTV_STATE_RUN) { |
274 | if(process->state->t == LTTV_STATE_USER_MODE) |
275 | prop_line.color = drawing_colors[COL_RUN_USER_MODE]; |
276 | else if(process->state->t == LTTV_STATE_SYSCALL) |
277 | prop_line.color = drawing_colors[COL_RUN_SYSCALL]; |
278 | else if(process->state->t == LTTV_STATE_TRAP) |
279 | prop_line.color = drawing_colors[COL_RUN_TRAP]; |
280 | else if(process->state->t == LTTV_STATE_IRQ) |
281 | prop_line.color = drawing_colors[COL_RUN_IRQ]; |
faf074a3 |
282 | else if(process->state->t == LTTV_STATE_SOFT_IRQ) |
283 | prop_line.color = drawing_colors[COL_RUN_SOFT_IRQ]; |
9a1ec01b |
284 | else if(process->state->t == LTTV_STATE_MODE_UNKNOWN) |
285 | prop_line.color = drawing_colors[COL_MODE_UNKNOWN]; |
286 | else |
287 | g_assert(FALSE); /* RUNNING MODE UNKNOWN */ |
288 | } else if(process->state->s == LTTV_STATE_WAIT) { |
289 | /* We don't show if we wait while in user mode, trap, irq or syscall */ |
290 | prop_line.color = drawing_colors[COL_WAIT]; |
291 | } else if(process->state->s == LTTV_STATE_WAIT_CPU) { |
292 | /* We don't show if we wait for CPU while in user mode, trap, irq |
293 | * or syscall */ |
294 | prop_line.color = drawing_colors[COL_WAIT_CPU]; |
295 | } else if(process->state->s == LTTV_STATE_ZOMBIE) { |
296 | prop_line.color = drawing_colors[COL_ZOMBIE]; |
297 | } else if(process->state->s == LTTV_STATE_WAIT_FORK) { |
298 | prop_line.color = drawing_colors[COL_WAIT_FORK]; |
299 | } else if(process->state->s == LTTV_STATE_EXIT) { |
300 | prop_line.color = drawing_colors[COL_EXIT]; |
301 | } else if(process->state->s == LTTV_STATE_UNNAMED) { |
302 | prop_line.color = drawing_colors[COL_UNNAMED]; |
b3fd4c02 |
303 | } else { |
304 | g_critical("unknown state : %s", g_quark_to_string(process->state->s)); |
9a1ec01b |
305 | g_assert(FALSE); /* UNKNOWN STATE */ |
b3fd4c02 |
306 | } |
9a1ec01b |
307 | |
308 | return prop_line; |
309 | |
310 | } |
311 | |
c8bba5fa |
312 | |
e92eabaf |
313 | /* before_schedchange_hook |
b9a010a2 |
314 | * |
f0d936c0 |
315 | * This function basically draw lines and icons. Two types of lines are drawn : |
316 | * one small (3 pixels?) representing the state of the process and the second |
317 | * type is thicker (10 pixels?) representing on which CPU a process is running |
318 | * (and this only in running state). |
319 | * |
320 | * Extremums of the lines : |
321 | * x_min : time of the last event context for this process kept in memory. |
322 | * x_max : time of the current event. |
323 | * y : middle of the process in the process list. The process is found in the |
324 | * list, therefore is it's position in pixels. |
325 | * |
326 | * The choice of lines'color is defined by the context of the last event for this |
327 | * process. |
328 | */ |
b9a010a2 |
329 | |
330 | |
e92eabaf |
331 | int before_schedchange_hook(void *hook_data, void *call_data) |
f0d936c0 |
332 | { |
2c82c4dc |
333 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
334 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
b9a010a2 |
335 | ControlFlowData *control_flow_data = events_request->viewer_data; |
336 | |
337 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
338 | |
339 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
348c6ba8 |
340 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
b9a010a2 |
341 | |
342 | LttEvent *e; |
2c82c4dc |
343 | e = ltt_tracefile_get_event(tfc->tf); |
b9a010a2 |
344 | |
345 | LttTime evtime = ltt_event_time(e); |
fd22065b |
346 | |
10a1069a |
347 | /* we are in a schedchange, before the state update. We must draw the |
348 | * items corresponding to the state before it changes : now is the right |
349 | * time to do it. |
350 | */ |
b9a010a2 |
351 | |
10a1069a |
352 | guint pid_out; |
353 | guint pid_in; |
354 | { |
2c82c4dc |
355 | pid_out = ltt_event_get_long_unsigned(e, thf->f1); |
356 | pid_in = ltt_event_get_long_unsigned(e, thf->f2); |
10a1069a |
357 | } |
358 | |
359 | { |
360 | /* For the pid_out */ |
361 | /* First, check if the current process is in the state computation |
362 | * process list. If it is there, that means we must add it right now and |
363 | * draw items from the beginning of the read for it. If it is not |
364 | * present, it's a new process and it was not present : it will |
365 | * be added after the state update. */ |
348c6ba8 |
366 | guint cpu = ltt_tracefile_num(tfc->tf); |
367 | LttvProcessState *process = ts->running_process[cpu]; |
40debf7b |
368 | /* unknown state, bad current pid */ |
348c6ba8 |
369 | if(process->pid != pid_out) |
800aa029 |
370 | process = lttv_state_find_process(ts, |
371 | ltt_tracefile_num(tfc->tf), pid_out); |
b9a010a2 |
372 | |
10a1069a |
373 | if(process != NULL) { |
374 | /* Well, the process_out existed : we must get it in the process hash |
375 | * or add it, and draw its items. |
376 | */ |
377 | /* Add process to process list (if not present) */ |
1c736ed5 |
378 | guint pl_height = 0; |
10a1069a |
379 | HashedProcessData *hashed_process_data = NULL; |
5c230fc4 |
380 | ProcessList *process_list = control_flow_data->process_list; |
10a1069a |
381 | LttTime birth = process->creation_time; |
b9a010a2 |
382 | |
ac4e21cf |
383 | hashed_process_data = processlist_get_process_data(process_list, |
10a1069a |
384 | pid_out, |
348c6ba8 |
385 | process->cpu, |
10a1069a |
386 | &birth, |
ac4e21cf |
387 | tfc->t_context->index); |
388 | if(hashed_process_data == NULL) |
10a1069a |
389 | { |
390 | g_assert(pid_out == 0 || pid_out != process->ppid); |
391 | /* Process not present */ |
4e86ae2e |
392 | ProcessInfo *process_info; |
1c736ed5 |
393 | Drawing_t *drawing = control_flow_data->drawing; |
10a1069a |
394 | processlist_add(process_list, |
1c736ed5 |
395 | drawing, |
10a1069a |
396 | pid_out, |
348c6ba8 |
397 | process->cpu, |
10a1069a |
398 | process->ppid, |
399 | &birth, |
400 | tfc->t_context->index, |
f4b88a7d |
401 | process->name, |
10a1069a |
402 | &pl_height, |
4e86ae2e |
403 | &process_info, |
10a1069a |
404 | &hashed_process_data); |
1c736ed5 |
405 | gtk_widget_set_size_request(drawing->drawing_area, |
406 | -1, |
407 | pl_height); |
408 | gtk_widget_queue_draw(drawing->drawing_area); |
409 | |
10a1069a |
410 | } |
ac4e21cf |
411 | |
10a1069a |
412 | /* Now, the process is in the state hash and our own process hash. |
413 | * We definitely can draw the items related to the ending state. |
414 | */ |
e800cf84 |
415 | |
b2743953 |
416 | if(ltt_time_compare(hashed_process_data->next_good_time, |
417 | evtime) > 0) |
10a1069a |
418 | { |
b2743953 |
419 | if(hashed_process_data->x.middle_marked == FALSE) { |
ac4e21cf |
420 | |
fd22065b |
421 | TimeWindow time_window = |
422 | lttvwindow_get_time_window(control_flow_data->tab); |
423 | #ifdef EXTRA_CHECK |
424 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
425 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
426 | return; |
427 | #endif //EXTRA_CHECK |
d6fef890 |
428 | Drawing_t *drawing = control_flow_data->drawing; |
96947fcf |
429 | guint width = drawing->width; |
b2743953 |
430 | guint x; |
431 | convert_time_to_pixels( |
432 | time_window, |
433 | evtime, |
434 | width, |
435 | &x); |
436 | |
437 | /* Draw collision indicator */ |
438 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
1c736ed5 |
439 | gdk_draw_point(hashed_process_data->pixmap, |
b2743953 |
440 | drawing->gc, |
441 | x, |
1c736ed5 |
442 | (hashed_process_data->height/2)-3); |
b2743953 |
443 | hashed_process_data->x.middle_marked = TRUE; |
444 | } |
445 | } else { |
ac4e21cf |
446 | TimeWindow time_window = |
447 | lttvwindow_get_time_window(control_flow_data->tab); |
fd22065b |
448 | #ifdef EXTRA_CHECK |
ac4e21cf |
449 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
450 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
451 | return; |
fd22065b |
452 | #endif //EXTRA_CHECK |
d6fef890 |
453 | Drawing_t *drawing = control_flow_data->drawing; |
96947fcf |
454 | guint width = drawing->width; |
10a1069a |
455 | guint x; |
10a1069a |
456 | convert_time_to_pixels( |
a18124ff |
457 | time_window, |
4b7dc462 |
458 | evtime, |
459 | width, |
460 | &x); |
10a1069a |
461 | |
10a1069a |
462 | |
4b7dc462 |
463 | /* Jump over draw if we are at the same x position */ |
e72908ed |
464 | if(x == hashed_process_data->x.middle && |
465 | hashed_process_data->x.middle_used) |
e800cf84 |
466 | { |
e72908ed |
467 | if(hashed_process_data->x.middle_marked == FALSE) { |
468 | /* Draw collision indicator */ |
469 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
1c736ed5 |
470 | gdk_draw_point(hashed_process_data->pixmap, |
e72908ed |
471 | drawing->gc, |
472 | x, |
1c736ed5 |
473 | (hashed_process_data->height/2)-3); |
de4ea1ad |
474 | hashed_process_data->x.middle_marked = TRUE; |
e72908ed |
475 | } |
4b7dc462 |
476 | /* jump */ |
477 | } else { |
478 | DrawContext draw_context; |
10a1069a |
479 | |
4b7dc462 |
480 | /* Now create the drawing context that will be used to draw |
481 | * items related to the last state. */ |
1c736ed5 |
482 | draw_context.drawable = hashed_process_data->pixmap; |
4b7dc462 |
483 | draw_context.gc = drawing->gc; |
484 | draw_context.pango_layout = drawing->pango_layout; |
485 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
486 | draw_context.drawinfo.end.x = x; |
487 | |
1c736ed5 |
488 | draw_context.drawinfo.y.over = 1; |
489 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
490 | draw_context.drawinfo.y.under = hashed_process_data->height; |
4b7dc462 |
491 | |
492 | draw_context.drawinfo.start.offset.over = 0; |
493 | draw_context.drawinfo.start.offset.middle = 0; |
494 | draw_context.drawinfo.start.offset.under = 0; |
495 | draw_context.drawinfo.end.offset.over = 0; |
496 | draw_context.drawinfo.end.offset.middle = 0; |
497 | draw_context.drawinfo.end.offset.under = 0; |
498 | |
499 | { |
500 | /* Draw the line */ |
9a1ec01b |
501 | PropertiesLine prop_line = prepare_s_e_line(process); |
4b7dc462 |
502 | draw_line((void*)&prop_line, (void*)&draw_context); |
503 | |
504 | } |
505 | /* become the last x position */ |
506 | hashed_process_data->x.middle = x; |
e72908ed |
507 | hashed_process_data->x.middle_used = TRUE; |
508 | hashed_process_data->x.middle_marked = FALSE; |
b2743953 |
509 | |
510 | /* Calculate the next good time */ |
511 | convert_pixels_to_time(width, x+1, time_window, |
512 | &hashed_process_data->next_good_time); |
e800cf84 |
513 | } |
514 | } |
515 | } |
10a1069a |
516 | } |
e800cf84 |
517 | |
10a1069a |
518 | { |
519 | /* For the pid_in */ |
520 | /* First, check if the current process is in the state computation |
521 | * process list. If it is there, that means we must add it right now and |
522 | * draw items from the beginning of the read for it. If it is not |
523 | * present, it's a new process and it was not present : it will |
524 | * be added after the state update. */ |
525 | LttvProcessState *process; |
800aa029 |
526 | process = lttv_state_find_process(ts, |
527 | ltt_tracefile_num(tfc->tf), pid_in); |
10a1069a |
528 | |
529 | if(process != NULL) { |
800aa029 |
530 | /* Well, the process existed : we must get it in the process hash |
10a1069a |
531 | * or add it, and draw its items. |
532 | */ |
533 | /* Add process to process list (if not present) */ |
1c736ed5 |
534 | guint pl_height = 0; |
10a1069a |
535 | HashedProcessData *hashed_process_data = NULL; |
5c230fc4 |
536 | ProcessList *process_list = control_flow_data->process_list; |
10a1069a |
537 | LttTime birth = process->creation_time; |
e800cf84 |
538 | |
ac4e21cf |
539 | hashed_process_data = processlist_get_process_data(process_list, |
10a1069a |
540 | pid_in, |
8e680509 |
541 | ltt_tracefile_num(tfc->tf), |
10a1069a |
542 | &birth, |
ac4e21cf |
543 | tfc->t_context->index); |
544 | if(hashed_process_data == NULL) |
10a1069a |
545 | { |
546 | g_assert(pid_in == 0 || pid_in != process->ppid); |
547 | /* Process not present */ |
4e86ae2e |
548 | ProcessInfo *process_info; |
1c736ed5 |
549 | Drawing_t *drawing = control_flow_data->drawing; |
10a1069a |
550 | processlist_add(process_list, |
1c736ed5 |
551 | drawing, |
10a1069a |
552 | pid_in, |
8e680509 |
553 | ltt_tracefile_num(tfc->tf), |
10a1069a |
554 | process->ppid, |
555 | &birth, |
556 | tfc->t_context->index, |
f4b88a7d |
557 | process->name, |
10a1069a |
558 | &pl_height, |
4e86ae2e |
559 | &process_info, |
10a1069a |
560 | &hashed_process_data); |
1c736ed5 |
561 | gtk_widget_set_size_request(drawing->drawing_area, |
562 | -1, |
563 | pl_height); |
564 | gtk_widget_queue_draw(drawing->drawing_area); |
565 | |
10a1069a |
566 | } |
40debf7b |
567 | //We could set the current process and hash here, but will be done |
568 | //by after schedchange hook |
10a1069a |
569 | |
570 | /* Now, the process is in the state hash and our own process hash. |
571 | * We definitely can draw the items related to the ending state. |
572 | */ |
b9a010a2 |
573 | |
b2743953 |
574 | if(ltt_time_compare(hashed_process_data->next_good_time, |
575 | evtime) > 0) |
10a1069a |
576 | { |
b2743953 |
577 | if(hashed_process_data->x.middle_marked == FALSE) { |
ac4e21cf |
578 | |
fd22065b |
579 | TimeWindow time_window = |
580 | lttvwindow_get_time_window(control_flow_data->tab); |
581 | #ifdef EXTRA_CHECK |
582 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
583 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
584 | return; |
585 | #endif //EXTRA_CHECK |
d6fef890 |
586 | Drawing_t *drawing = control_flow_data->drawing; |
96947fcf |
587 | guint width = drawing->width; |
b2743953 |
588 | guint x; |
589 | convert_time_to_pixels( |
590 | time_window, |
591 | evtime, |
592 | width, |
593 | &x); |
594 | |
595 | /* Draw collision indicator */ |
596 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
1c736ed5 |
597 | gdk_draw_point(hashed_process_data->pixmap, |
b2743953 |
598 | drawing->gc, |
599 | x, |
1c736ed5 |
600 | (hashed_process_data->height/2)-3); |
b2743953 |
601 | hashed_process_data->x.middle_marked = TRUE; |
602 | } |
603 | } else { |
fd22065b |
604 | TimeWindow time_window = |
605 | lttvwindow_get_time_window(control_flow_data->tab); |
606 | #ifdef EXTRA_CHECK |
607 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
608 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
609 | return; |
610 | #endif //EXTRA_CHECK |
d6fef890 |
611 | Drawing_t *drawing = control_flow_data->drawing; |
96947fcf |
612 | guint width = drawing->width; |
10a1069a |
613 | guint x; |
10a1069a |
614 | |
615 | convert_time_to_pixels( |
a18124ff |
616 | time_window, |
4b7dc462 |
617 | evtime, |
618 | width, |
619 | &x); |
10a1069a |
620 | |
10a1069a |
621 | |
4b7dc462 |
622 | /* Jump over draw if we are at the same x position */ |
e72908ed |
623 | if(x == hashed_process_data->x.middle && |
624 | hashed_process_data->x.middle_used) |
4b7dc462 |
625 | { |
e72908ed |
626 | if(hashed_process_data->x.middle_marked == FALSE) { |
627 | /* Draw collision indicator */ |
628 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
1c736ed5 |
629 | gdk_draw_point(hashed_process_data->pixmap, |
e72908ed |
630 | drawing->gc, |
631 | x, |
1c736ed5 |
632 | (hashed_process_data->height/2)-3); |
de4ea1ad |
633 | hashed_process_data->x.middle_marked = TRUE; |
e72908ed |
634 | } |
4b7dc462 |
635 | /* jump */ |
636 | } else { |
637 | DrawContext draw_context; |
10a1069a |
638 | |
4b7dc462 |
639 | /* Now create the drawing context that will be used to draw |
640 | * items related to the last state. */ |
1c736ed5 |
641 | draw_context.drawable = hashed_process_data->pixmap; |
4b7dc462 |
642 | draw_context.gc = drawing->gc; |
643 | draw_context.pango_layout = drawing->pango_layout; |
644 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
645 | draw_context.drawinfo.end.x = x; |
10a1069a |
646 | |
1c736ed5 |
647 | draw_context.drawinfo.y.over = 1; |
648 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
649 | draw_context.drawinfo.y.under = hashed_process_data->height; |
10a1069a |
650 | |
4b7dc462 |
651 | draw_context.drawinfo.start.offset.over = 0; |
652 | draw_context.drawinfo.start.offset.middle = 0; |
653 | draw_context.drawinfo.start.offset.under = 0; |
654 | draw_context.drawinfo.end.offset.over = 0; |
655 | draw_context.drawinfo.end.offset.middle = 0; |
656 | draw_context.drawinfo.end.offset.under = 0; |
657 | |
658 | { |
659 | /* Draw the line */ |
9a1ec01b |
660 | PropertiesLine prop_line = prepare_s_e_line(process); |
4b7dc462 |
661 | draw_line((void*)&prop_line, (void*)&draw_context); |
662 | } |
663 | |
664 | |
665 | /* become the last x position */ |
666 | hashed_process_data->x.middle = x; |
e72908ed |
667 | hashed_process_data->x.middle_used = TRUE; |
668 | hashed_process_data->x.middle_marked = FALSE; |
b2743953 |
669 | |
670 | /* Calculate the next good time */ |
671 | convert_pixels_to_time(width, x+1, time_window, |
672 | &hashed_process_data->next_good_time); |
4b7dc462 |
673 | } |
c8bba5fa |
674 | } |
8e680509 |
675 | } else |
676 | g_warning("Cannot find pin_in in schedchange %u", pid_in); |
b9a010a2 |
677 | } |
b9a010a2 |
678 | return 0; |
679 | |
680 | |
b9a010a2 |
681 | |
a56a1ba4 |
682 | |
51705146 |
683 | /* Text dump */ |
80a52ff8 |
684 | #ifdef DONTSHOW |
a56a1ba4 |
685 | GString *string = g_string_new("");; |
686 | gboolean field_names = TRUE, state = TRUE; |
80a52ff8 |
687 | |
e9a9c513 |
688 | lttv_event_to_string(e, tfc->tf, string, TRUE, field_names, tfs); |
689 | g_string_append_printf(string,"\n"); |
690 | |
691 | if(state) { |
692 | g_string_append_printf(string, " %s", |
693 | g_quark_to_string(tfs->process->state->s)); |
694 | } |
695 | |
696 | g_info("%s",string->str); |
697 | |
a56a1ba4 |
698 | g_string_free(string, TRUE); |
699 | |
700 | /* End of text dump */ |
80a52ff8 |
701 | #endif //DONTSHOW |
50439712 |
702 | |
f0d936c0 |
703 | } |
704 | |
e92eabaf |
705 | /* after_schedchange_hook |
b9a010a2 |
706 | * |
707 | * The draw after hook is called by the reading API to have a |
708 | * particular event drawn on the screen. |
709 | * @param hook_data ControlFlowData structure of the viewer. |
710 | * @param call_data Event context. |
711 | * |
712 | * This function adds items to be drawn in a queue for each process. |
713 | * |
714 | */ |
e92eabaf |
715 | int after_schedchange_hook(void *hook_data, void *call_data) |
f0d936c0 |
716 | { |
2c82c4dc |
717 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
718 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
ca0f8a8e |
719 | ControlFlowData *control_flow_data = events_request->viewer_data; |
50439712 |
720 | |
a56a1ba4 |
721 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
50439712 |
722 | |
723 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
724 | |
348c6ba8 |
725 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
726 | |
b9a010a2 |
727 | LttEvent *e; |
2c82c4dc |
728 | e = ltt_tracefile_get_event(tfc->tf); |
b9a010a2 |
729 | |
730 | LttTime evtime = ltt_event_time(e); |
b9a010a2 |
731 | |
10a1069a |
732 | /* Add process to process list (if not present) */ |
2eef04b5 |
733 | LttvProcessState *process_in; |
10a1069a |
734 | LttTime birth; |
1c736ed5 |
735 | guint pl_height = 0; |
10a1069a |
736 | HashedProcessData *hashed_process_data_in = NULL; |
b9a010a2 |
737 | |
5c230fc4 |
738 | ProcessList *process_list = control_flow_data->process_list; |
10a1069a |
739 | |
740 | guint pid_in; |
741 | { |
742 | guint pid_out; |
2c82c4dc |
743 | pid_out = ltt_event_get_long_unsigned(e, thf->f1); |
744 | pid_in = ltt_event_get_long_unsigned(e, thf->f2); |
10a1069a |
745 | } |
b9a010a2 |
746 | |
747 | |
10a1069a |
748 | /* Find process pid_in in the list... */ |
348c6ba8 |
749 | //process_in = lttv_state_find_process(ts, ANY_CPU, pid_in); |
750 | //process_in = tfs->process; |
751 | guint cpu = ltt_tracefile_num(tfc->tf); |
752 | process_in = ts->running_process[cpu]; |
10a1069a |
753 | /* It should exist, because we are after the state update. */ |
96947fcf |
754 | #ifdef EXTRA_CHECK |
10a1069a |
755 | g_assert(process_in != NULL); |
96947fcf |
756 | #endif //EXTRA_CHECK |
10a1069a |
757 | birth = process_in->creation_time; |
b9a010a2 |
758 | |
ac4e21cf |
759 | hashed_process_data_in = processlist_get_process_data(process_list, |
10a1069a |
760 | pid_in, |
348c6ba8 |
761 | process_in->cpu, |
10a1069a |
762 | &birth, |
ac4e21cf |
763 | tfc->t_context->index); |
764 | if(hashed_process_data_in == NULL) |
10a1069a |
765 | { |
766 | g_assert(pid_in == 0 || pid_in != process_in->ppid); |
4e86ae2e |
767 | ProcessInfo *process_info; |
1c736ed5 |
768 | Drawing_t *drawing = control_flow_data->drawing; |
10a1069a |
769 | /* Process not present */ |
770 | processlist_add(process_list, |
1c736ed5 |
771 | drawing, |
10a1069a |
772 | pid_in, |
348c6ba8 |
773 | process_in->cpu, |
10a1069a |
774 | process_in->ppid, |
775 | &birth, |
776 | tfc->t_context->index, |
f4b88a7d |
777 | process_in->name, |
10a1069a |
778 | &pl_height, |
4e86ae2e |
779 | &process_info, |
10a1069a |
780 | &hashed_process_data_in); |
1c736ed5 |
781 | gtk_widget_set_size_request(drawing->drawing_area, |
782 | -1, |
783 | pl_height); |
784 | gtk_widget_queue_draw(drawing->drawing_area); |
b9a010a2 |
785 | } |
40debf7b |
786 | /* Set the current process */ |
348c6ba8 |
787 | process_list->current_hash_data[process_in->cpu] = |
40debf7b |
788 | hashed_process_data_in; |
10a1069a |
789 | |
b2743953 |
790 | if(ltt_time_compare(hashed_process_data_in->next_good_time, |
791 | evtime) <= 0) |
792 | { |
fd22065b |
793 | TimeWindow time_window = |
794 | lttvwindow_get_time_window(control_flow_data->tab); |
795 | |
796 | #ifdef EXTRA_CHECK |
797 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
798 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
799 | return; |
800 | #endif //EXTRA_CHECK |
d6fef890 |
801 | Drawing_t *drawing = control_flow_data->drawing; |
802 | guint width = drawing->width; |
b2743953 |
803 | guint new_x; |
804 | |
805 | convert_time_to_pixels( |
806 | time_window, |
807 | evtime, |
808 | width, |
809 | &new_x); |
e72908ed |
810 | |
b2743953 |
811 | if(hashed_process_data_in->x.middle != new_x) { |
812 | hashed_process_data_in->x.middle = new_x; |
813 | hashed_process_data_in->x.middle_used = FALSE; |
814 | hashed_process_data_in->x.middle_marked = FALSE; |
815 | } |
816 | } |
b9a010a2 |
817 | return 0; |
4a24fa1f |
818 | } |
b9a010a2 |
819 | |
820 | |
821 | |
e72908ed |
822 | |
4a24fa1f |
823 | /* before_execmode_hook |
824 | * |
825 | * This function basically draw lines and icons. Two types of lines are drawn : |
826 | * one small (3 pixels?) representing the state of the process and the second |
827 | * type is thicker (10 pixels?) representing on which CPU a process is running |
828 | * (and this only in running state). |
829 | * |
830 | * Extremums of the lines : |
831 | * x_min : time of the last event context for this process kept in memory. |
832 | * x_max : time of the current event. |
833 | * y : middle of the process in the process list. The process is found in the |
834 | * list, therefore is it's position in pixels. |
835 | * |
836 | * The choice of lines'color is defined by the context of the last event for this |
837 | * process. |
838 | */ |
839 | |
e72908ed |
840 | |
4a24fa1f |
841 | int before_execmode_hook(void *hook_data, void *call_data) |
842 | { |
843 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
844 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
b9a010a2 |
845 | ControlFlowData *control_flow_data = events_request->viewer_data; |
846 | |
847 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
848 | |
849 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
b9a010a2 |
850 | |
4a24fa1f |
851 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
852 | |
50439712 |
853 | LttEvent *e; |
4a24fa1f |
854 | e = ltt_tracefile_get_event(tfc->tf); |
50439712 |
855 | |
9444deae |
856 | LttTime evtime = ltt_event_time(e); |
9444deae |
857 | |
4a24fa1f |
858 | /* we are in a execmode, before the state update. We must draw the |
859 | * items corresponding to the state before it changes : now is the right |
860 | * time to do it. |
861 | */ |
862 | /* For the pid */ |
863 | //LttvProcessState *process = tfs->process; |
864 | guint cpu = ltt_tracefile_num(tfc->tf); |
865 | LttvProcessState *process = ts->running_process[cpu]; |
866 | g_assert(process != NULL); |
23093869 |
867 | |
10a1069a |
868 | guint pid = process->pid; |
23093869 |
869 | |
10a1069a |
870 | /* Well, the process_out existed : we must get it in the process hash |
871 | * or add it, and draw its items. |
872 | */ |
873 | /* Add process to process list (if not present) */ |
1c736ed5 |
874 | guint pl_height = 0; |
10a1069a |
875 | HashedProcessData *hashed_process_data = NULL; |
5c230fc4 |
876 | ProcessList *process_list = control_flow_data->process_list; |
10a1069a |
877 | LttTime birth = process->creation_time; |
40debf7b |
878 | |
348c6ba8 |
879 | if(likely(process_list->current_hash_data[cpu] != NULL)) { |
880 | hashed_process_data = process_list->current_hash_data[cpu]; |
40debf7b |
881 | } else { |
ac4e21cf |
882 | hashed_process_data = processlist_get_process_data(process_list, |
40debf7b |
883 | pid, |
348c6ba8 |
884 | process->cpu, |
40debf7b |
885 | &birth, |
ac4e21cf |
886 | tfc->t_context->index); |
1d1df11d |
887 | if(unlikely(hashed_process_data == NULL)) |
40debf7b |
888 | { |
889 | g_assert(pid == 0 || pid != process->ppid); |
890 | ProcessInfo *process_info; |
891 | /* Process not present */ |
1c736ed5 |
892 | Drawing_t *drawing = control_flow_data->drawing; |
40debf7b |
893 | processlist_add(process_list, |
1c736ed5 |
894 | drawing, |
40debf7b |
895 | pid, |
348c6ba8 |
896 | process->cpu, |
40debf7b |
897 | process->ppid, |
898 | &birth, |
899 | tfc->t_context->index, |
f4b88a7d |
900 | process->name, |
40debf7b |
901 | &pl_height, |
902 | &process_info, |
903 | &hashed_process_data); |
1c736ed5 |
904 | gtk_widget_set_size_request(drawing->drawing_area, |
905 | -1, |
906 | pl_height); |
907 | gtk_widget_queue_draw(drawing->drawing_area); |
40debf7b |
908 | } |
909 | /* Set the current process */ |
348c6ba8 |
910 | process_list->current_hash_data[process->cpu] = |
40debf7b |
911 | hashed_process_data; |
10a1069a |
912 | } |
23093869 |
913 | |
10a1069a |
914 | /* Now, the process is in the state hash and our own process hash. |
915 | * We definitely can draw the items related to the ending state. |
916 | */ |
b2743953 |
917 | |
1d1df11d |
918 | if(likely(ltt_time_compare(hashed_process_data->next_good_time, |
919 | evtime) > 0)) |
10a1069a |
920 | { |
1d1df11d |
921 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
fd22065b |
922 | TimeWindow time_window = |
923 | lttvwindow_get_time_window(control_flow_data->tab); |
924 | |
925 | #ifdef EXTRA_CHECK |
926 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
927 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
928 | return; |
929 | #endif //EXTRA_CHECK |
d6fef890 |
930 | Drawing_t *drawing = control_flow_data->drawing; |
96947fcf |
931 | guint width = drawing->width; |
b2743953 |
932 | guint x; |
933 | convert_time_to_pixels( |
934 | time_window, |
935 | evtime, |
936 | width, |
937 | &x); |
938 | |
939 | /* Draw collision indicator */ |
940 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
1c736ed5 |
941 | gdk_draw_point(hashed_process_data->pixmap, |
b2743953 |
942 | drawing->gc, |
943 | x, |
1c736ed5 |
944 | (hashed_process_data->height/2)-3); |
b2743953 |
945 | hashed_process_data->x.middle_marked = TRUE; |
946 | } |
947 | } else { |
fd22065b |
948 | TimeWindow time_window = |
949 | lttvwindow_get_time_window(control_flow_data->tab); |
950 | |
951 | #ifdef EXTRA_CHECK |
952 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
953 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
954 | return; |
955 | #endif //EXTRA_CHECK |
d6fef890 |
956 | Drawing_t *drawing = control_flow_data->drawing; |
96947fcf |
957 | guint width = drawing->width; |
10a1069a |
958 | guint x; |
dbd243b1 |
959 | |
10a1069a |
960 | convert_time_to_pixels( |
a18124ff |
961 | time_window, |
10a1069a |
962 | evtime, |
963 | width, |
964 | &x); |
dbd243b1 |
965 | |
23093869 |
966 | |
4b7dc462 |
967 | /* Jump over draw if we are at the same x position */ |
1d1df11d |
968 | if(unlikely(x == hashed_process_data->x.middle && |
969 | hashed_process_data->x.middle_used)) |
10a1069a |
970 | { |
1d1df11d |
971 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
e72908ed |
972 | /* Draw collision indicator */ |
973 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
1c736ed5 |
974 | gdk_draw_point(hashed_process_data->pixmap, |
e72908ed |
975 | drawing->gc, |
976 | x, |
1c736ed5 |
977 | (hashed_process_data->height/2)-3); |
de4ea1ad |
978 | hashed_process_data->x.middle_marked = TRUE; |
e72908ed |
979 | } |
4b7dc462 |
980 | /* jump */ |
981 | } else { |
982 | |
983 | DrawContext draw_context; |
984 | /* Now create the drawing context that will be used to draw |
985 | * items related to the last state. */ |
1c736ed5 |
986 | draw_context.drawable = hashed_process_data->pixmap; |
4b7dc462 |
987 | draw_context.gc = drawing->gc; |
988 | draw_context.pango_layout = drawing->pango_layout; |
9a1ec01b |
989 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
4b7dc462 |
990 | draw_context.drawinfo.end.x = x; |
991 | |
1c736ed5 |
992 | draw_context.drawinfo.y.over = 1; |
993 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
994 | draw_context.drawinfo.y.under = hashed_process_data->height; |
4b7dc462 |
995 | |
996 | draw_context.drawinfo.start.offset.over = 0; |
997 | draw_context.drawinfo.start.offset.middle = 0; |
998 | draw_context.drawinfo.start.offset.under = 0; |
999 | draw_context.drawinfo.end.offset.over = 0; |
1000 | draw_context.drawinfo.end.offset.middle = 0; |
1001 | draw_context.drawinfo.end.offset.under = 0; |
1002 | |
1003 | { |
1004 | /* Draw the line */ |
9a1ec01b |
1005 | PropertiesLine prop_line = prepare_s_e_line(process); |
4b7dc462 |
1006 | draw_line((void*)&prop_line, (void*)&draw_context); |
23093869 |
1007 | |
4b7dc462 |
1008 | } |
1009 | /* become the last x position */ |
9a1ec01b |
1010 | hashed_process_data->x.middle = x; |
e72908ed |
1011 | hashed_process_data->x.middle_used = TRUE; |
1012 | hashed_process_data->x.middle_marked = FALSE; |
b2743953 |
1013 | |
1014 | /* Calculate the next good time */ |
1015 | convert_pixels_to_time(width, x+1, time_window, |
1016 | &hashed_process_data->next_good_time); |
23093869 |
1017 | } |
1018 | } |
1019 | |
1020 | return 0; |
1021 | } |
1022 | |
4a24fa1f |
1023 | /* before_process_exit_hook |
23093869 |
1024 | * |
4a24fa1f |
1025 | * Draw lines for process event. |
1026 | * |
23093869 |
1027 | * @param hook_data ControlFlowData structure of the viewer. |
1028 | * @param call_data Event context. |
1029 | * |
1030 | * This function adds items to be drawn in a queue for each process. |
1031 | * |
1032 | */ |
8869ac08 |
1033 | |
1034 | |
4a24fa1f |
1035 | int before_process_exit_hook(void *hook_data, void *call_data) |
1036 | { |
2c82c4dc |
1037 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
1038 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
4a24fa1f |
1039 | |
23093869 |
1040 | ControlFlowData *control_flow_data = events_request->viewer_data; |
1041 | |
1042 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
1043 | |
1044 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
23093869 |
1045 | |
4a24fa1f |
1046 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
1047 | |
23093869 |
1048 | LttEvent *e; |
2c82c4dc |
1049 | e = ltt_tracefile_get_event(tfc->tf); |
23093869 |
1050 | |
1051 | LttTime evtime = ltt_event_time(e); |
23093869 |
1052 | |
10a1069a |
1053 | /* Add process to process list (if not present) */ |
4a24fa1f |
1054 | //LttvProcessState *process = tfs->process; |
1055 | guint cpu = ltt_tracefile_num(tfc->tf); |
1056 | LttvProcessState *process = ts->running_process[cpu]; |
1057 | guint pid = process->pid; |
10a1069a |
1058 | LttTime birth; |
1c736ed5 |
1059 | guint pl_height = 0; |
10a1069a |
1060 | HashedProcessData *hashed_process_data = NULL; |
23093869 |
1061 | |
5c230fc4 |
1062 | ProcessList *process_list = control_flow_data->process_list; |
4a24fa1f |
1063 | |
10a1069a |
1064 | g_assert(process != NULL); |
23093869 |
1065 | |
10a1069a |
1066 | birth = process->creation_time; |
23093869 |
1067 | |
4a24fa1f |
1068 | if(likely(process_list->current_hash_data[cpu] != NULL)) { |
1069 | hashed_process_data = process_list->current_hash_data[cpu]; |
40debf7b |
1070 | } else { |
ac4e21cf |
1071 | hashed_process_data = processlist_get_process_data(process_list, |
4a24fa1f |
1072 | pid, |
1073 | process->cpu, |
1074 | &birth, |
1075 | tfc->t_context->index); |
1d1df11d |
1076 | if(unlikely(hashed_process_data == NULL)) |
40debf7b |
1077 | { |
1078 | g_assert(pid == 0 || pid != process->ppid); |
1079 | /* Process not present */ |
1c736ed5 |
1080 | Drawing_t *drawing = control_flow_data->drawing; |
40debf7b |
1081 | ProcessInfo *process_info; |
1082 | processlist_add(process_list, |
1c736ed5 |
1083 | drawing, |
40debf7b |
1084 | pid, |
4a24fa1f |
1085 | process->cpu, |
40debf7b |
1086 | process->ppid, |
1087 | &birth, |
1088 | tfc->t_context->index, |
4a24fa1f |
1089 | process->name, |
40debf7b |
1090 | &pl_height, |
1091 | &process_info, |
1092 | &hashed_process_data); |
4a24fa1f |
1093 | gtk_widget_set_size_request(drawing->drawing_area, |
1094 | -1, |
1095 | pl_height); |
1096 | gtk_widget_queue_draw(drawing->drawing_area); |
40debf7b |
1097 | } |
23093869 |
1098 | } |
40debf7b |
1099 | |
4a24fa1f |
1100 | /* Now, the process is in the state hash and our own process hash. |
1101 | * We definitely can draw the items related to the ending state. |
1102 | */ |
1103 | |
1104 | if(likely(ltt_time_compare(hashed_process_data->next_good_time, |
1105 | evtime) > 0)) |
b2743953 |
1106 | { |
4a24fa1f |
1107 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
1108 | TimeWindow time_window = |
1109 | lttvwindow_get_time_window(control_flow_data->tab); |
1110 | |
1111 | #ifdef EXTRA_CHECK |
1112 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
1113 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
1114 | return; |
1115 | #endif //EXTRA_CHECK |
1116 | Drawing_t *drawing = control_flow_data->drawing; |
1117 | guint width = drawing->width; |
1118 | guint x; |
1119 | convert_time_to_pixels( |
1120 | time_window, |
1121 | evtime, |
1122 | width, |
1123 | &x); |
1124 | |
1125 | /* Draw collision indicator */ |
1126 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
1127 | gdk_draw_point(hashed_process_data->pixmap, |
1128 | drawing->gc, |
1129 | x, |
1130 | (hashed_process_data->height/2)-3); |
1131 | hashed_process_data->x.middle_marked = TRUE; |
1132 | } |
1133 | } else { |
fd22065b |
1134 | TimeWindow time_window = |
1135 | lttvwindow_get_time_window(control_flow_data->tab); |
1136 | |
1137 | #ifdef EXTRA_CHECK |
1138 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
1139 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
1140 | return; |
1141 | #endif //EXTRA_CHECK |
d6fef890 |
1142 | Drawing_t *drawing = control_flow_data->drawing; |
1143 | guint width = drawing->width; |
4a24fa1f |
1144 | guint x; |
1145 | |
2c82c4dc |
1146 | convert_time_to_pixels( |
1147 | time_window, |
1148 | evtime, |
1149 | width, |
1150 | &x); |
1151 | |
b2743953 |
1152 | |
2c82c4dc |
1153 | /* Jump over draw if we are at the same x position */ |
1154 | if(unlikely(x == hashed_process_data->x.middle && |
1155 | hashed_process_data->x.middle_used)) |
1156 | { |
1157 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
b2743953 |
1158 | /* Draw collision indicator */ |
1159 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
1c736ed5 |
1160 | gdk_draw_point(hashed_process_data->pixmap, |
b2743953 |
1161 | drawing->gc, |
1162 | x, |
1c736ed5 |
1163 | (hashed_process_data->height/2)-3); |
b2743953 |
1164 | hashed_process_data->x.middle_marked = TRUE; |
1165 | } |
2c82c4dc |
1166 | /* jump */ |
b2743953 |
1167 | } else { |
2c82c4dc |
1168 | DrawContext draw_context; |
fd22065b |
1169 | |
2c82c4dc |
1170 | /* Now create the drawing context that will be used to draw |
1171 | * items related to the last state. */ |
1172 | draw_context.drawable = hashed_process_data->pixmap; |
1173 | draw_context.gc = drawing->gc; |
1174 | draw_context.pango_layout = drawing->pango_layout; |
1175 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
1176 | draw_context.drawinfo.end.x = x; |
dbd243b1 |
1177 | |
2c82c4dc |
1178 | draw_context.drawinfo.y.over = 1; |
1179 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
1180 | draw_context.drawinfo.y.under = hashed_process_data->height; |
dbd243b1 |
1181 | |
2c82c4dc |
1182 | draw_context.drawinfo.start.offset.over = 0; |
1183 | draw_context.drawinfo.start.offset.middle = 0; |
1184 | draw_context.drawinfo.start.offset.under = 0; |
1185 | draw_context.drawinfo.end.offset.over = 0; |
1186 | draw_context.drawinfo.end.offset.middle = 0; |
1187 | draw_context.drawinfo.end.offset.under = 0; |
dbd243b1 |
1188 | |
2c82c4dc |
1189 | { |
1190 | /* Draw the line */ |
1191 | PropertiesLine prop_line = prepare_s_e_line(process); |
1192 | draw_line((void*)&prop_line, (void*)&draw_context); |
dbd243b1 |
1193 | |
2c82c4dc |
1194 | } |
1195 | /* become the last x position */ |
1196 | hashed_process_data->x.middle = x; |
1197 | hashed_process_data->x.middle_used = TRUE; |
1198 | hashed_process_data->x.middle_marked = FALSE; |
dbd243b1 |
1199 | |
2c82c4dc |
1200 | /* Calculate the next good time */ |
1201 | convert_pixels_to_time(width, x+1, time_window, |
1202 | &hashed_process_data->next_good_time); |
1203 | } |
1204 | } |
1205 | |
1206 | return 0; |
1207 | |
1208 | } |
1209 | |
1210 | |
1211 | |
1212 | /* before_process_release_hook |
1213 | * |
1214 | * Draw lines for process event. |
1215 | * |
1216 | * @param hook_data ControlFlowData structure of the viewer. |
1217 | * @param call_data Event context. |
1218 | * |
1219 | * This function adds items to be drawn in a queue for each process. |
1220 | * |
1221 | */ |
1222 | |
1223 | |
1224 | int before_process_release_hook(void *hook_data, void *call_data) |
1225 | { |
1226 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
1227 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
1228 | |
1229 | ControlFlowData *control_flow_data = events_request->viewer_data; |
1230 | |
1231 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
1232 | |
1233 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
1234 | |
348c6ba8 |
1235 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
1236 | |
2c82c4dc |
1237 | LttEvent *e; |
1238 | e = ltt_tracefile_get_event(tfc->tf); |
1239 | |
1240 | LttTime evtime = ltt_event_time(e); |
1241 | |
1242 | |
1243 | guint pid; |
1244 | { |
1245 | pid = ltt_event_get_long_unsigned(e, thf->f1); |
1246 | } |
1247 | |
1248 | /* Add process to process list (if not present) */ |
1249 | /* Don't care about the process if it's not in the state hash already : |
1250 | * that means a process that has never done anything in the trace and |
1251 | * unknown suddently gets destroyed : no state meaningful to show. */ |
348c6ba8 |
1252 | LttvProcessState *process = lttv_state_find_process(ts, ANY_CPU, pid); |
2c82c4dc |
1253 | |
1254 | if(process != NULL) { |
1255 | LttTime birth; |
1256 | guint pl_height = 0; |
1257 | HashedProcessData *hashed_process_data = NULL; |
1258 | |
1259 | ProcessList *process_list = control_flow_data->process_list; |
1260 | |
1261 | birth = process->creation_time; |
1262 | |
1263 | /* Cannot use current process : this event happens on another process, |
1264 | * action done by the parent. */ |
1265 | hashed_process_data = processlist_get_process_data(process_list, |
1266 | pid, |
348c6ba8 |
1267 | process->cpu, |
2c82c4dc |
1268 | &birth, |
1269 | tfc->t_context->index); |
1270 | if(unlikely(hashed_process_data == NULL)) |
1271 | { |
1272 | g_assert(pid == 0 || pid != process->ppid); |
1273 | /* Process not present */ |
1274 | Drawing_t *drawing = control_flow_data->drawing; |
2c82c4dc |
1275 | ProcessInfo *process_info; |
1276 | processlist_add(process_list, |
1277 | drawing, |
1278 | pid, |
348c6ba8 |
1279 | process->cpu, |
2c82c4dc |
1280 | process->ppid, |
1281 | &birth, |
1282 | tfc->t_context->index, |
f4b88a7d |
1283 | process->name, |
2c82c4dc |
1284 | &pl_height, |
1285 | &process_info, |
1286 | &hashed_process_data); |
1287 | gtk_widget_set_size_request(drawing->drawing_area, |
1288 | -1, |
1289 | pl_height); |
1290 | gtk_widget_queue_draw(drawing->drawing_area); |
1291 | } |
1292 | |
1293 | /* Now, the process is in the state hash and our own process hash. |
1294 | * We definitely can draw the items related to the ending state. |
1295 | */ |
1296 | |
1297 | if(likely(ltt_time_compare(hashed_process_data->next_good_time, |
1298 | evtime) > 0)) |
1299 | { |
1300 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
1301 | TimeWindow time_window = |
1302 | lttvwindow_get_time_window(control_flow_data->tab); |
1303 | |
1304 | #ifdef EXTRA_CHECK |
1305 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
1306 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
1307 | return; |
1308 | #endif //EXTRA_CHECK |
1309 | Drawing_t *drawing = control_flow_data->drawing; |
1310 | guint width = drawing->width; |
1311 | guint x; |
1312 | convert_time_to_pixels( |
1313 | time_window, |
1314 | evtime, |
1315 | width, |
1316 | &x); |
1317 | |
1318 | /* Draw collision indicator */ |
1319 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
1320 | gdk_draw_point(hashed_process_data->pixmap, |
1321 | drawing->gc, |
1322 | x, |
1323 | (hashed_process_data->height/2)-3); |
1324 | hashed_process_data->x.middle_marked = TRUE; |
1325 | } |
1326 | } else { |
1327 | TimeWindow time_window = |
1328 | lttvwindow_get_time_window(control_flow_data->tab); |
1329 | |
1330 | #ifdef EXTRA_CHECK |
1331 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
4a24fa1f |
1332 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
1333 | return; |
2da61677 |
1334 | #endif //EXTRA_CHECK |
4a24fa1f |
1335 | Drawing_t *drawing = control_flow_data->drawing; |
1336 | guint width = drawing->width; |
1337 | guint x; |
1338 | |
1339 | convert_time_to_pixels( |
1340 | time_window, |
1341 | evtime, |
1342 | width, |
1343 | &x); |
1344 | |
2da61677 |
1345 | |
4a24fa1f |
1346 | /* Jump over draw if we are at the same x position */ |
1347 | if(unlikely(x == hashed_process_data->x.middle && |
1348 | hashed_process_data->x.middle_used)) |
1349 | { |
1350 | if(unlikely(hashed_process_data->x.middle_marked == FALSE)) { |
2da61677 |
1351 | /* Draw collision indicator */ |
1352 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
1353 | gdk_draw_point(hashed_process_data->pixmap, |
1354 | drawing->gc, |
1355 | x, |
1356 | (hashed_process_data->height/2)-3); |
1357 | hashed_process_data->x.middle_marked = TRUE; |
1358 | } |
4a24fa1f |
1359 | /* jump */ |
2da61677 |
1360 | } else { |
4a24fa1f |
1361 | DrawContext draw_context; |
2da61677 |
1362 | |
4a24fa1f |
1363 | /* Now create the drawing context that will be used to draw |
1364 | * items related to the last state. */ |
1365 | draw_context.drawable = hashed_process_data->pixmap; |
1366 | draw_context.gc = drawing->gc; |
1367 | draw_context.pango_layout = drawing->pango_layout; |
1368 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
1369 | draw_context.drawinfo.end.x = x; |
2da61677 |
1370 | |
4a24fa1f |
1371 | draw_context.drawinfo.y.over = 1; |
1372 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
1373 | draw_context.drawinfo.y.under = hashed_process_data->height; |
2da61677 |
1374 | |
4a24fa1f |
1375 | draw_context.drawinfo.start.offset.over = 0; |
1376 | draw_context.drawinfo.start.offset.middle = 0; |
1377 | draw_context.drawinfo.start.offset.under = 0; |
1378 | draw_context.drawinfo.end.offset.over = 0; |
1379 | draw_context.drawinfo.end.offset.middle = 0; |
1380 | draw_context.drawinfo.end.offset.under = 0; |
2da61677 |
1381 | |
4a24fa1f |
1382 | { |
1383 | /* Draw the line */ |
1384 | PropertiesLine prop_line = prepare_s_e_line(process); |
1385 | draw_line((void*)&prop_line, (void*)&draw_context); |
2da61677 |
1386 | |
2da61677 |
1387 | } |
4a24fa1f |
1388 | /* become the last x position */ |
1389 | hashed_process_data->x.middle = x; |
1390 | hashed_process_data->x.middle_used = TRUE; |
1391 | hashed_process_data->x.middle_marked = FALSE; |
1392 | |
1393 | /* Calculate the next good time */ |
1394 | convert_pixels_to_time(width, x+1, time_window, |
1395 | &hashed_process_data->next_good_time); |
2da61677 |
1396 | } |
1397 | } |
dbd243b1 |
1398 | } |
dbd243b1 |
1399 | |
4a24fa1f |
1400 | return 0; |
dbd243b1 |
1401 | } |
1402 | |
4a24fa1f |
1403 | |
2c82c4dc |
1404 | |
1405 | |
1406 | |
1407 | /* after_process_fork_hook |
1408 | * |
1409 | * Create the processlist entry for the child process. Put the last |
1410 | * position in x at the current time value. |
1411 | * |
1412 | * @param hook_data ControlFlowData structure of the viewer. |
1413 | * @param call_data Event context. |
1414 | * |
1415 | * This function adds items to be drawn in a queue for each process. |
1416 | * |
1417 | */ |
1418 | int after_process_fork_hook(void *hook_data, void *call_data) |
1419 | { |
1420 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
1421 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
1422 | ControlFlowData *control_flow_data = events_request->viewer_data; |
1423 | |
1424 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
1425 | |
1426 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
1427 | |
348c6ba8 |
1428 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
1429 | |
2c82c4dc |
1430 | LttEvent *e; |
1431 | e = ltt_tracefile_get_event(tfc->tf); |
1432 | |
1433 | LttTime evtime = ltt_event_time(e); |
1434 | |
1435 | guint child_pid; |
1436 | { |
1437 | child_pid = ltt_event_get_long_unsigned(e, thf->f2); |
1438 | } |
1439 | |
1440 | /* Add process to process list (if not present) */ |
1441 | LttvProcessState *process_child; |
1442 | LttTime birth; |
1443 | guint pl_height = 0; |
1444 | HashedProcessData *hashed_process_data_child = NULL; |
1445 | |
1446 | ProcessList *process_list = control_flow_data->process_list; |
1447 | |
1448 | /* Find child in the list... */ |
348c6ba8 |
1449 | process_child = lttv_state_find_process(ts, ANY_CPU, child_pid); |
2c82c4dc |
1450 | /* It should exist, because we are after the state update. */ |
1451 | g_assert(process_child != NULL); |
1452 | |
1453 | birth = process_child->creation_time; |
1454 | |
1455 | /* Cannot use current process, because this action is done by the parent |
1456 | * on its child. */ |
1457 | hashed_process_data_child = processlist_get_process_data(process_list, |
1458 | child_pid, |
348c6ba8 |
1459 | process_child->cpu, |
2c82c4dc |
1460 | &birth, |
1461 | tfc->t_context->index); |
1462 | if(likely(hashed_process_data_child == NULL)) |
1463 | { |
1464 | g_assert(child_pid == 0 || child_pid != process_child->ppid); |
1465 | /* Process not present */ |
1466 | Drawing_t *drawing = control_flow_data->drawing; |
2c82c4dc |
1467 | ProcessInfo *process_info; |
1468 | processlist_add(process_list, |
1469 | drawing, |
1470 | child_pid, |
348c6ba8 |
1471 | process_child->cpu, |
2c82c4dc |
1472 | process_child->ppid, |
1473 | &birth, |
1474 | tfc->t_context->index, |
f4b88a7d |
1475 | process_child->name, |
2c82c4dc |
1476 | &pl_height, |
1477 | &process_info, |
1478 | &hashed_process_data_child); |
1479 | gtk_widget_set_size_request(drawing->drawing_area, |
1480 | -1, |
1481 | pl_height); |
1482 | gtk_widget_queue_draw(drawing->drawing_area); |
1483 | } |
1484 | |
1485 | |
1486 | if(likely(ltt_time_compare(hashed_process_data_child->next_good_time, |
1487 | evtime) <= 0)) |
1488 | { |
1489 | TimeWindow time_window = |
1490 | lttvwindow_get_time_window(control_flow_data->tab); |
1491 | |
1492 | #ifdef EXTRA_CHECK |
1493 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
1494 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
1495 | return; |
1496 | #endif //EXTRA_CHECK |
1497 | Drawing_t *drawing = control_flow_data->drawing; |
1498 | guint width = drawing->width; |
1499 | guint new_x; |
1500 | convert_time_to_pixels( |
1501 | time_window, |
1502 | evtime, |
1503 | width, |
1504 | &new_x); |
1505 | |
1506 | if(likely(hashed_process_data_child->x.over != new_x)) { |
1507 | hashed_process_data_child->x.over = new_x; |
1508 | hashed_process_data_child->x.over_used = FALSE; |
1509 | hashed_process_data_child->x.over_marked = FALSE; |
1510 | } |
1511 | if(likely(hashed_process_data_child->x.middle != new_x)) { |
1512 | hashed_process_data_child->x.middle = new_x; |
1513 | hashed_process_data_child->x.middle_used = FALSE; |
1514 | hashed_process_data_child->x.middle_marked = FALSE; |
1515 | } |
1516 | if(likely(hashed_process_data_child->x.under != new_x)) { |
1517 | hashed_process_data_child->x.under = new_x; |
1518 | hashed_process_data_child->x.under_used = FALSE; |
1519 | hashed_process_data_child->x.under_marked = FALSE; |
1520 | } |
1521 | } |
1522 | return 0; |
1523 | } |
1524 | |
1525 | |
1526 | |
1527 | /* after_process_exit_hook |
1528 | * |
1529 | * Create the processlist entry for the child process. Put the last |
1530 | * position in x at the current time value. |
1531 | * |
1532 | * @param hook_data ControlFlowData structure of the viewer. |
1533 | * @param call_data Event context. |
1534 | * |
1535 | * This function adds items to be drawn in a queue for each process. |
1536 | * |
1537 | */ |
1538 | int after_process_exit_hook(void *hook_data, void *call_data) |
1539 | { |
1540 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
1541 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
1542 | ControlFlowData *control_flow_data = events_request->viewer_data; |
1543 | |
1544 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
1545 | |
1546 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
1547 | |
348c6ba8 |
1548 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
1549 | |
2c82c4dc |
1550 | LttEvent *e; |
1551 | e = ltt_tracefile_get_event(tfc->tf); |
1552 | |
1553 | LttTime evtime = ltt_event_time(e); |
1554 | |
1555 | /* Add process to process list (if not present) */ |
348c6ba8 |
1556 | //LttvProcessState *process = tfs->process; |
1557 | guint cpu = ltt_tracefile_num(tfc->tf); |
1558 | LttvProcessState *process = ts->running_process[cpu]; |
1559 | |
1560 | /* It should exist, because we are after the state update. */ |
1561 | g_assert(process != NULL); |
1562 | |
2c82c4dc |
1563 | guint pid = process->pid; |
1564 | LttTime birth; |
1565 | guint pl_height = 0; |
1566 | HashedProcessData *hashed_process_data = NULL; |
1567 | |
1568 | ProcessList *process_list = control_flow_data->process_list; |
1569 | |
2c82c4dc |
1570 | birth = process->creation_time; |
1571 | |
348c6ba8 |
1572 | if(likely(process_list->current_hash_data[cpu] != NULL) ){ |
1573 | hashed_process_data = process_list->current_hash_data[cpu]; |
2c82c4dc |
1574 | } else { |
1575 | hashed_process_data = processlist_get_process_data(process_list, |
1576 | pid, |
348c6ba8 |
1577 | process->cpu, |
2c82c4dc |
1578 | &birth, |
1579 | tfc->t_context->index); |
1580 | if(unlikely(hashed_process_data == NULL)) |
1581 | { |
1582 | g_assert(pid == 0 || pid != process->ppid); |
1583 | /* Process not present */ |
1584 | Drawing_t *drawing = control_flow_data->drawing; |
2c82c4dc |
1585 | ProcessInfo *process_info; |
1586 | processlist_add(process_list, |
1587 | drawing, |
1588 | pid, |
348c6ba8 |
1589 | process->cpu, |
2c82c4dc |
1590 | process->ppid, |
1591 | &birth, |
1592 | tfc->t_context->index, |
f4b88a7d |
1593 | process->name, |
2c82c4dc |
1594 | &pl_height, |
1595 | &process_info, |
1596 | &hashed_process_data); |
1597 | gtk_widget_set_size_request(drawing->drawing_area, |
1598 | -1, |
1599 | pl_height); |
1600 | gtk_widget_queue_draw(drawing->drawing_area); |
1601 | } |
1602 | |
1603 | /* Set the current process */ |
348c6ba8 |
1604 | process_list->current_hash_data[process->cpu] = |
2c82c4dc |
1605 | hashed_process_data; |
1606 | } |
1607 | |
1608 | if(unlikely(ltt_time_compare(hashed_process_data->next_good_time, |
1609 | evtime) <= 0)) |
1610 | { |
1611 | TimeWindow time_window = |
1612 | lttvwindow_get_time_window(control_flow_data->tab); |
dbd243b1 |
1613 | |
2c82c4dc |
1614 | #ifdef EXTRA_CHECK |
1615 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
1616 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
1617 | return; |
1618 | #endif //EXTRA_CHECK |
1619 | Drawing_t *drawing = control_flow_data->drawing; |
1620 | guint width = drawing->width; |
1621 | guint new_x; |
1622 | convert_time_to_pixels( |
1623 | time_window, |
1624 | evtime, |
1625 | width, |
1626 | &new_x); |
1627 | if(unlikely(hashed_process_data->x.middle != new_x)) { |
1628 | hashed_process_data->x.middle = new_x; |
1629 | hashed_process_data->x.middle_used = FALSE; |
1630 | hashed_process_data->x.middle_marked = FALSE; |
1631 | } |
1632 | } |
dbd243b1 |
1633 | |
2c82c4dc |
1634 | return 0; |
1635 | } |
dbd243b1 |
1636 | |
1637 | |
f4b88a7d |
1638 | /* Get the filename of the process to print */ |
1639 | int after_fs_exec_hook(void *hook_data, void *call_data) |
1640 | { |
1641 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
1642 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
1643 | ControlFlowData *control_flow_data = events_request->viewer_data; |
1644 | |
1645 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
1646 | |
1647 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
1648 | |
1649 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
1650 | |
1651 | guint cpu = ltt_tracefile_num(tfc->tf); |
1652 | LttvProcessState *process = ts->running_process[cpu]; |
1653 | g_assert(process != NULL); |
1654 | |
1655 | guint pid = process->pid; |
1656 | |
1657 | /* Well, the process_out existed : we must get it in the process hash |
1658 | * or add it, and draw its items. |
1659 | */ |
1660 | /* Add process to process list (if not present) */ |
1661 | guint pl_height = 0; |
1662 | HashedProcessData *hashed_process_data = NULL; |
1663 | ProcessList *process_list = control_flow_data->process_list; |
1664 | LttTime birth = process->creation_time; |
1665 | |
1666 | if(likely(process_list->current_hash_data[cpu] != NULL)) { |
1667 | hashed_process_data = process_list->current_hash_data[cpu]; |
1668 | } else { |
1669 | hashed_process_data = processlist_get_process_data(process_list, |
1670 | pid, |
1671 | process->cpu, |
1672 | &birth, |
1673 | tfc->t_context->index); |
1674 | if(unlikely(hashed_process_data == NULL)) |
1675 | { |
1676 | g_assert(pid == 0 || pid != process->ppid); |
1677 | ProcessInfo *process_info; |
1678 | /* Process not present */ |
1679 | Drawing_t *drawing = control_flow_data->drawing; |
1680 | processlist_add(process_list, |
1681 | drawing, |
1682 | pid, |
1683 | process->cpu, |
1684 | process->ppid, |
1685 | &birth, |
1686 | tfc->t_context->index, |
1687 | process->name, |
1688 | &pl_height, |
1689 | &process_info, |
1690 | &hashed_process_data); |
1691 | gtk_widget_set_size_request(drawing->drawing_area, |
1692 | -1, |
1693 | pl_height); |
1694 | gtk_widget_queue_draw(drawing->drawing_area); |
1695 | } |
1696 | /* Set the current process */ |
1697 | process_list->current_hash_data[process->cpu] = |
1698 | hashed_process_data; |
1699 | } |
1700 | |
1701 | processlist_set_name(process_list, process->name, hashed_process_data); |
1702 | |
1703 | return 0; |
1704 | |
1705 | } |
1706 | |
b3fd4c02 |
1707 | /* after_event_enum_process_hook |
1708 | * |
1709 | * DOES EXACTLY THE SAME AS after_schedchange_hook, for the "in" process. |
1710 | * Create the processlist entry for the child process. Put the last |
1711 | * position in x at the current time value. |
1712 | * |
1713 | * @param hook_data ControlFlowData structure of the viewer. |
1714 | * @param call_data Event context. |
1715 | * |
1716 | * This function adds items to be drawn in a queue for each process. |
1717 | * |
1718 | */ |
1719 | int after_event_enum_process_hook(void *hook_data, void *call_data) |
1720 | { |
1721 | LttvTraceHookByFacility *thf = (LttvTraceHookByFacility*)hook_data; |
1722 | EventsRequest *events_request = (EventsRequest*)thf->hook_data; |
1723 | ControlFlowData *control_flow_data = events_request->viewer_data; |
1724 | |
1725 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
1726 | |
1727 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
1728 | |
1729 | LttvTraceState *ts = (LttvTraceState *)tfc->t_context; |
1730 | |
1731 | LttEvent *e; |
1732 | e = ltt_tracefile_get_event(tfc->tf); |
1733 | |
1734 | LttTime evtime = ltt_event_time(e); |
1735 | |
1736 | /* Add process to process list (if not present) */ |
1737 | LttvProcessState *process_in; |
1738 | LttTime birth; |
1739 | guint pl_height = 0; |
1740 | HashedProcessData *hashed_process_data_in = NULL; |
1741 | |
1742 | ProcessList *process_list = control_flow_data->process_list; |
1743 | |
1744 | guint pid_in; |
1745 | { |
1746 | pid_in = ltt_event_get_long_unsigned(e, thf->f1); |
1747 | } |
1748 | |
1749 | |
1750 | /* Find process pid_in in the list... */ |
1751 | process_in = lttv_state_find_process(ts, ANY_CPU, pid_in); |
1752 | //process_in = tfs->process; |
1753 | //guint cpu = ltt_tracefile_num(tfc->tf); |
1754 | //process_in = ts->running_process[cpu]; |
1755 | /* It should exist, because we are after the state update. */ |
1756 | #ifdef EXTRA_CHECK |
1757 | //g_assert(process_in != NULL); |
1758 | #endif //EXTRA_CHECK |
1759 | birth = process_in->creation_time; |
1760 | |
1761 | hashed_process_data_in = processlist_get_process_data(process_list, |
1762 | pid_in, |
1763 | process_in->cpu, |
1764 | &birth, |
1765 | tfc->t_context->index); |
1766 | if(hashed_process_data_in == NULL) |
1767 | { |
1768 | if(pid_in != 0 && pid_in == process_in->ppid) |
1769 | g_critical("TEST %u , %u", pid_in, process_in->ppid); |
1770 | g_assert(pid_in == 0 || pid_in != process_in->ppid); |
1771 | ProcessInfo *process_info; |
1772 | Drawing_t *drawing = control_flow_data->drawing; |
1773 | /* Process not present */ |
1774 | processlist_add(process_list, |
1775 | drawing, |
1776 | pid_in, |
1777 | process_in->cpu, |
1778 | process_in->ppid, |
1779 | &birth, |
1780 | tfc->t_context->index, |
1781 | process_in->name, |
1782 | &pl_height, |
1783 | &process_info, |
1784 | &hashed_process_data_in); |
1785 | gtk_widget_set_size_request(drawing->drawing_area, |
1786 | -1, |
1787 | pl_height); |
1788 | gtk_widget_queue_draw(drawing->drawing_area); |
1789 | } |
1790 | /* Set the current process */ |
1791 | process_list->current_hash_data[process_in->cpu] = |
1792 | hashed_process_data_in; |
1793 | |
1794 | if(ltt_time_compare(hashed_process_data_in->next_good_time, |
1795 | evtime) <= 0) |
1796 | { |
1797 | TimeWindow time_window = |
1798 | lttvwindow_get_time_window(control_flow_data->tab); |
1799 | |
1800 | #ifdef EXTRA_CHECK |
1801 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
1802 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
1803 | return; |
1804 | #endif //EXTRA_CHECK |
1805 | Drawing_t *drawing = control_flow_data->drawing; |
1806 | guint width = drawing->width; |
1807 | guint new_x; |
1808 | |
1809 | convert_time_to_pixels( |
1810 | time_window, |
1811 | evtime, |
1812 | width, |
1813 | &new_x); |
f4b88a7d |
1814 | |
b3fd4c02 |
1815 | if(hashed_process_data_in->x.middle != new_x) { |
1816 | hashed_process_data_in->x.middle = new_x; |
1817 | hashed_process_data_in->x.middle_used = FALSE; |
1818 | hashed_process_data_in->x.middle_marked = FALSE; |
1819 | } |
1820 | } |
1821 | return 0; |
1822 | } |
f4b88a7d |
1823 | |
1824 | |
1b238973 |
1825 | gint update_time_window_hook(void *hook_data, void *call_data) |
f7afe191 |
1826 | { |
a56a1ba4 |
1827 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
a43d67ba |
1828 | Drawing_t *drawing = control_flow_data->drawing; |
1c736ed5 |
1829 | ProcessList *process_list = control_flow_data->process_list; |
a43d67ba |
1830 | |
224446ce |
1831 | const TimeWindowNotifyData *time_window_nofify_data = |
1832 | ((const TimeWindowNotifyData *)call_data); |
1833 | |
14963be0 |
1834 | TimeWindow *old_time_window = |
224446ce |
1835 | time_window_nofify_data->old_time_window; |
1836 | TimeWindow *new_time_window = |
1837 | time_window_nofify_data->new_time_window; |
a56a1ba4 |
1838 | |
3cb8b205 |
1839 | /* Update the ruler */ |
1840 | drawing_update_ruler(control_flow_data->drawing, |
1841 | new_time_window); |
1842 | |
1843 | |
a56a1ba4 |
1844 | /* Two cases : zoom in/out or scrolling */ |
1845 | |
1846 | /* In order to make sure we can reuse the old drawing, the scale must |
1847 | * be the same and the new time interval being partly located in the |
1848 | * currently shown time interval. (reuse is only for scrolling) |
1849 | */ |
1850 | |
2eef04b5 |
1851 | g_info("Old time window HOOK : %lu, %lu to %lu, %lu", |
14963be0 |
1852 | old_time_window->start_time.tv_sec, |
1853 | old_time_window->start_time.tv_nsec, |
1854 | old_time_window->time_width.tv_sec, |
1855 | old_time_window->time_width.tv_nsec); |
a56a1ba4 |
1856 | |
2eef04b5 |
1857 | g_info("New time window HOOK : %lu, %lu to %lu, %lu", |
14963be0 |
1858 | new_time_window->start_time.tv_sec, |
1859 | new_time_window->start_time.tv_nsec, |
1860 | new_time_window->time_width.tv_sec, |
1861 | new_time_window->time_width.tv_nsec); |
a56a1ba4 |
1862 | |
14963be0 |
1863 | if( new_time_window->time_width.tv_sec == old_time_window->time_width.tv_sec |
1864 | && new_time_window->time_width.tv_nsec == old_time_window->time_width.tv_nsec) |
a56a1ba4 |
1865 | { |
1866 | /* Same scale (scrolling) */ |
1867 | g_info("scrolling"); |
14963be0 |
1868 | LttTime *ns = &new_time_window->start_time; |
20640e70 |
1869 | LttTime *nw = &new_time_window->time_width; |
14963be0 |
1870 | LttTime *os = &old_time_window->start_time; |
20640e70 |
1871 | LttTime *ow = &old_time_window->time_width; |
6f26fc38 |
1872 | LttTime old_end = old_time_window->end_time; |
1873 | LttTime new_end = new_time_window->end_time; |
a56a1ba4 |
1874 | //if(ns<os+w<ns+w) |
1875 | //if(ns<os+w && os+w<ns+w) |
1876 | //if(ns<old_end && os<ns) |
1877 | if(ltt_time_compare(*ns, old_end) == -1 |
1878 | && ltt_time_compare(*os, *ns) == -1) |
1879 | { |
1880 | g_info("scrolling near right"); |
1881 | /* Scroll right, keep right part of the screen */ |
1882 | guint x = 0; |
51705146 |
1883 | guint width = control_flow_data->drawing->width; |
a56a1ba4 |
1884 | convert_time_to_pixels( |
a18124ff |
1885 | *old_time_window, |
a56a1ba4 |
1886 | *ns, |
1887 | width, |
1888 | &x); |
1889 | |
1890 | /* Copy old data to new location */ |
1c736ed5 |
1891 | copy_pixmap_region(process_list, |
1892 | NULL, |
1893 | control_flow_data->drawing->drawing_area->style->black_gc, |
1894 | NULL, |
1895 | x, 0, |
1896 | 0, 0, |
1897 | control_flow_data->drawing->width-x+SAFETY, -1); |
1898 | |
6395d57c |
1899 | if(drawing->damage_begin == drawing->damage_end) |
1900 | drawing->damage_begin = control_flow_data->drawing->width-x; |
1901 | else |
1902 | drawing->damage_begin = 0; |
1903 | |
1904 | drawing->damage_end = control_flow_data->drawing->width; |
1905 | |
a56a1ba4 |
1906 | /* Clear the data request background, but not SAFETY */ |
1c736ed5 |
1907 | rectangle_pixmap(process_list, |
cfe526b1 |
1908 | control_flow_data->drawing->drawing_area->style->black_gc, |
a56a1ba4 |
1909 | TRUE, |
6395d57c |
1910 | drawing->damage_begin+SAFETY, 0, |
1911 | drawing->damage_end - drawing->damage_begin, // do not overlap |
1c736ed5 |
1912 | -1); |
7abb23ad |
1913 | gtk_widget_queue_draw(drawing->drawing_area); |
1914 | //gtk_widget_queue_draw_area (drawing->drawing_area, |
1915 | // 0,0, |
1916 | // control_flow_data->drawing->width, |
1917 | // control_flow_data->drawing->height); |
a43d67ba |
1918 | |
a56a1ba4 |
1919 | /* Get new data for the rest. */ |
501d5405 |
1920 | drawing_data_request(control_flow_data->drawing, |
6395d57c |
1921 | drawing->damage_begin, 0, |
1922 | drawing->damage_end - drawing->damage_begin, |
501d5405 |
1923 | control_flow_data->drawing->height); |
a56a1ba4 |
1924 | } else { |
1925 | //if(ns<os<ns+w) |
1926 | //if(ns<os && os<ns+w) |
1927 | //if(ns<os && os<new_end) |
1928 | if(ltt_time_compare(*ns,*os) == -1 |
1929 | && ltt_time_compare(*os,new_end) == -1) |
1930 | { |
1931 | g_info("scrolling near left"); |
1932 | /* Scroll left, keep left part of the screen */ |
1933 | guint x = 0; |
51705146 |
1934 | guint width = control_flow_data->drawing->width; |
a56a1ba4 |
1935 | convert_time_to_pixels( |
a18124ff |
1936 | *new_time_window, |
a56a1ba4 |
1937 | *os, |
1938 | width, |
1939 | &x); |
6395d57c |
1940 | |
a56a1ba4 |
1941 | /* Copy old data to new location */ |
1c736ed5 |
1942 | copy_pixmap_region (process_list, |
1943 | NULL, |
cfe526b1 |
1944 | control_flow_data->drawing->drawing_area->style->black_gc, |
1c736ed5 |
1945 | NULL, |
a56a1ba4 |
1946 | 0, 0, |
1947 | x, 0, |
1948 | -1, -1); |
1949 | |
6395d57c |
1950 | if(drawing->damage_begin == drawing->damage_end) |
1951 | drawing->damage_end = x; |
1952 | else |
1953 | drawing->damage_end = |
51705146 |
1954 | control_flow_data->drawing->width; |
6395d57c |
1955 | |
1956 | drawing->damage_begin = 0; |
1957 | |
1c736ed5 |
1958 | rectangle_pixmap (process_list, |
cfe526b1 |
1959 | control_flow_data->drawing->drawing_area->style->black_gc, |
a56a1ba4 |
1960 | TRUE, |
6395d57c |
1961 | drawing->damage_begin, 0, |
1962 | drawing->damage_end - drawing->damage_begin, // do not overlap |
1c736ed5 |
1963 | -1); |
a43d67ba |
1964 | |
7abb23ad |
1965 | gtk_widget_queue_draw(drawing->drawing_area); |
1966 | //gtk_widget_queue_draw_area (drawing->drawing_area, |
1967 | // 0,0, |
1968 | // control_flow_data->drawing->width, |
1969 | // control_flow_data->drawing->height); |
a43d67ba |
1970 | |
6395d57c |
1971 | |
a56a1ba4 |
1972 | /* Get new data for the rest. */ |
501d5405 |
1973 | drawing_data_request(control_flow_data->drawing, |
6395d57c |
1974 | drawing->damage_begin, 0, |
1975 | drawing->damage_end - drawing->damage_begin, |
501d5405 |
1976 | control_flow_data->drawing->height); |
a56a1ba4 |
1977 | |
a56a1ba4 |
1978 | } else { |
a43d67ba |
1979 | if(ltt_time_compare(*ns,*os) == 0) |
1980 | { |
1981 | g_info("not scrolling"); |
1982 | } else { |
1983 | g_info("scrolling far"); |
1984 | /* Cannot reuse any part of the screen : far jump */ |
1985 | |
1986 | |
1c736ed5 |
1987 | rectangle_pixmap (process_list, |
a43d67ba |
1988 | control_flow_data->drawing->drawing_area->style->black_gc, |
1989 | TRUE, |
a56a1ba4 |
1990 | 0, 0, |
a43d67ba |
1991 | control_flow_data->drawing->width+SAFETY, // do not overlap |
1c736ed5 |
1992 | -1); |
a43d67ba |
1993 | |
7abb23ad |
1994 | //gtk_widget_queue_draw_area (drawing->drawing_area, |
1995 | // 0,0, |
1996 | // control_flow_data->drawing->width, |
1997 | // control_flow_data->drawing->height); |
1998 | gtk_widget_queue_draw(drawing->drawing_area); |
a43d67ba |
1999 | |
6395d57c |
2000 | drawing->damage_begin = 0; |
2001 | drawing->damage_end = control_flow_data->drawing->width; |
2002 | |
a43d67ba |
2003 | drawing_data_request(control_flow_data->drawing, |
a43d67ba |
2004 | 0, 0, |
2005 | control_flow_data->drawing->width, |
2006 | control_flow_data->drawing->height); |
2007 | |
2008 | } |
a56a1ba4 |
2009 | } |
2010 | } |
2011 | } else { |
2012 | /* Different scale (zoom) */ |
2013 | g_info("zoom"); |
2014 | |
1c736ed5 |
2015 | rectangle_pixmap (process_list, |
cfe526b1 |
2016 | control_flow_data->drawing->drawing_area->style->black_gc, |
a56a1ba4 |
2017 | TRUE, |
2018 | 0, 0, |
501d5405 |
2019 | control_flow_data->drawing->width+SAFETY, // do not overlap |
1c736ed5 |
2020 | -1); |
a56a1ba4 |
2021 | |
7abb23ad |
2022 | //gtk_widget_queue_draw_area (drawing->drawing_area, |
2023 | // 0,0, |
2024 | // control_flow_data->drawing->width, |
2025 | // control_flow_data->drawing->height); |
2026 | gtk_widget_queue_draw(drawing->drawing_area); |
a56a1ba4 |
2027 | |
6395d57c |
2028 | drawing->damage_begin = 0; |
2029 | drawing->damage_end = control_flow_data->drawing->width; |
2030 | |
501d5405 |
2031 | drawing_data_request(control_flow_data->drawing, |
a56a1ba4 |
2032 | 0, 0, |
501d5405 |
2033 | control_flow_data->drawing->width, |
2034 | control_flow_data->drawing->height); |
a56a1ba4 |
2035 | } |
2036 | |
15f77e3b |
2037 | /* Update directly when scrolling */ |
2038 | gdk_window_process_updates(control_flow_data->drawing->drawing_area->window, |
2039 | TRUE); |
3cb8b205 |
2040 | |
a56a1ba4 |
2041 | return 0; |
f7afe191 |
2042 | } |
2043 | |
6395d57c |
2044 | gint traceset_notify(void *hook_data, void *call_data) |
2045 | { |
2046 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
2047 | Drawing_t *drawing = control_flow_data->drawing; |
6395d57c |
2048 | |
6cec4cd2 |
2049 | if(unlikely(drawing->gc == NULL)) { |
2050 | return FALSE; |
2051 | } |
2052 | if(drawing->dotted_gc == NULL) { |
2053 | return FALSE; |
2054 | } |
6395d57c |
2055 | |
b9a010a2 |
2056 | drawing_clear(control_flow_data->drawing); |
2057 | processlist_clear(control_flow_data->process_list); |
07390ec1 |
2058 | gtk_widget_set_size_request( |
2059 | control_flow_data->drawing->drawing_area, |
2060 | -1, processlist_get_height(control_flow_data->process_list)); |
d9267eec |
2061 | redraw_notify(control_flow_data, NULL); |
6395d57c |
2062 | |
d9267eec |
2063 | request_background_data(control_flow_data); |
6395d57c |
2064 | |
2065 | return FALSE; |
2066 | } |
2067 | |
ca0f8a8e |
2068 | gint redraw_notify(void *hook_data, void *call_data) |
2069 | { |
2070 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
2071 | Drawing_t *drawing = control_flow_data->drawing; |
2072 | GtkWidget *widget = drawing->drawing_area; |
2073 | |
2074 | drawing->damage_begin = 0; |
51705146 |
2075 | drawing->damage_end = drawing->width; |
ca0f8a8e |
2076 | |
49217bd4 |
2077 | /* fun feature, to be separated someday... */ |
2078 | drawing_clear(control_flow_data->drawing); |
2079 | processlist_clear(control_flow_data->process_list); |
07390ec1 |
2080 | gtk_widget_set_size_request( |
2081 | control_flow_data->drawing->drawing_area, |
2082 | -1, processlist_get_height(control_flow_data->process_list)); |
1c736ed5 |
2083 | // Clear the images |
2084 | rectangle_pixmap (control_flow_data->process_list, |
ca0f8a8e |
2085 | widget->style->black_gc, |
2086 | TRUE, |
2087 | 0, 0, |
f3b7430d |
2088 | drawing->alloc_width, |
1c736ed5 |
2089 | -1); |
ca0f8a8e |
2090 | |
f3b7430d |
2091 | gtk_widget_queue_draw(drawing->drawing_area); |
4a24fa1f |
2092 | |
ca0f8a8e |
2093 | if(drawing->damage_begin < drawing->damage_end) |
2094 | { |
2095 | drawing_data_request(drawing, |
ca0f8a8e |
2096 | drawing->damage_begin, |
2097 | 0, |
2098 | drawing->damage_end-drawing->damage_begin, |
51705146 |
2099 | drawing->height); |
ca0f8a8e |
2100 | } |
2101 | |
7abb23ad |
2102 | //gtk_widget_queue_draw_area(drawing->drawing_area, |
2103 | // 0,0, |
2104 | // drawing->width, |
2105 | // drawing->height); |
ca0f8a8e |
2106 | return FALSE; |
2107 | |
2108 | } |
2109 | |
2110 | |
2111 | gint continue_notify(void *hook_data, void *call_data) |
a43d67ba |
2112 | { |
2113 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
ca0f8a8e |
2114 | Drawing_t *drawing = control_flow_data->drawing; |
a43d67ba |
2115 | |
6395d57c |
2116 | //g_assert(widget->allocation.width == drawing->damage_end); |
ca0f8a8e |
2117 | |
2118 | if(drawing->damage_begin < drawing->damage_end) |
2119 | { |
2120 | drawing_data_request(drawing, |
ca0f8a8e |
2121 | drawing->damage_begin, |
2122 | 0, |
2123 | drawing->damage_end-drawing->damage_begin, |
51705146 |
2124 | drawing->height); |
ca0f8a8e |
2125 | } |
2126 | |
2127 | return FALSE; |
2128 | } |
2129 | |
2130 | |
1b238973 |
2131 | gint update_current_time_hook(void *hook_data, void *call_data) |
f7afe191 |
2132 | { |
14963be0 |
2133 | ControlFlowData *control_flow_data = (ControlFlowData*)hook_data; |
a43d67ba |
2134 | Drawing_t *drawing = control_flow_data->drawing; |
a56a1ba4 |
2135 | |
224446ce |
2136 | LttTime current_time = *((LttTime*)call_data); |
a56a1ba4 |
2137 | |
ca0f8a8e |
2138 | TimeWindow time_window = |
2139 | lttvwindow_get_time_window(control_flow_data->tab); |
a56a1ba4 |
2140 | |
ca0f8a8e |
2141 | LttTime time_begin = time_window.start_time; |
2142 | LttTime width = time_window.time_width; |
90ef7e4a |
2143 | LttTime half_width; |
2144 | { |
2145 | guint64 time_ll = ltt_time_to_uint64(width); |
2146 | time_ll = time_ll >> 1; /* divide by two */ |
2147 | half_width = ltt_time_from_uint64(time_ll); |
2148 | } |
a56a1ba4 |
2149 | LttTime time_end = ltt_time_add(time_begin, width); |
2150 | |
2151 | LttvTracesetContext * tsc = |
ca0f8a8e |
2152 | lttvwindow_get_traceset_context(control_flow_data->tab); |
a56a1ba4 |
2153 | |
ca0f8a8e |
2154 | LttTime trace_start = tsc->time_span.start_time; |
2155 | LttTime trace_end = tsc->time_span.end_time; |
a56a1ba4 |
2156 | |
2eef04b5 |
2157 | g_info("New current time HOOK : %lu, %lu", current_time.tv_sec, |
224446ce |
2158 | current_time.tv_nsec); |
a56a1ba4 |
2159 | |
2160 | |
2161 | |
2162 | /* If current time is inside time interval, just move the highlight |
2163 | * bar */ |
2164 | |
2165 | /* Else, we have to change the time interval. We have to tell it |
2166 | * to the main window. */ |
2167 | /* The time interval change will take care of placing the current |
2168 | * time at the center of the visible area, or nearest possible if we are |
2169 | * at one end of the trace. */ |
2170 | |
2171 | |
dbc0ef8a |
2172 | if(ltt_time_compare(current_time, time_begin) < 0) |
a56a1ba4 |
2173 | { |
224446ce |
2174 | TimeWindow new_time_window; |
2175 | |
2176 | if(ltt_time_compare(current_time, |
dbc0ef8a |
2177 | ltt_time_add(trace_start,half_width)) < 0) |
a56a1ba4 |
2178 | time_begin = trace_start; |
2179 | else |
224446ce |
2180 | time_begin = ltt_time_sub(current_time,half_width); |
a56a1ba4 |
2181 | |
224446ce |
2182 | new_time_window.start_time = time_begin; |
2183 | new_time_window.time_width = width; |
a18124ff |
2184 | new_time_window.time_width_double = ltt_time_to_double(width); |
6f26fc38 |
2185 | new_time_window.end_time = ltt_time_add(time_begin, width); |
a56a1ba4 |
2186 | |
e800cf84 |
2187 | lttvwindow_report_time_window(control_flow_data->tab, new_time_window); |
a56a1ba4 |
2188 | } |
dbc0ef8a |
2189 | else if(ltt_time_compare(current_time, time_end) > 0) |
a56a1ba4 |
2190 | { |
224446ce |
2191 | TimeWindow new_time_window; |
2192 | |
dbc0ef8a |
2193 | if(ltt_time_compare(current_time, ltt_time_sub(trace_end, half_width)) > 0) |
a56a1ba4 |
2194 | time_begin = ltt_time_sub(trace_end,width); |
2195 | else |
224446ce |
2196 | time_begin = ltt_time_sub(current_time,half_width); |
a56a1ba4 |
2197 | |
224446ce |
2198 | new_time_window.start_time = time_begin; |
2199 | new_time_window.time_width = width; |
a18124ff |
2200 | new_time_window.time_width_double = ltt_time_to_double(width); |
6f26fc38 |
2201 | new_time_window.end_time = ltt_time_add(time_begin, width); |
a56a1ba4 |
2202 | |
e800cf84 |
2203 | lttvwindow_report_time_window(control_flow_data->tab, new_time_window); |
a56a1ba4 |
2204 | |
2205 | } |
7abb23ad |
2206 | gtk_widget_queue_draw(control_flow_data->drawing->drawing_area); |
a56a1ba4 |
2207 | |
15f77e3b |
2208 | /* Update directly when scrolling */ |
2209 | gdk_window_process_updates(control_flow_data->drawing->drawing_area->window, |
2210 | TRUE); |
2211 | |
a56a1ba4 |
2212 | return 0; |
f7afe191 |
2213 | } |
2214 | |
8b90e648 |
2215 | typedef struct _ClosureData { |
ca0f8a8e |
2216 | EventsRequest *events_request; |
d0cd7f09 |
2217 | LttvTracesetState *tss; |
b9a010a2 |
2218 | LttTime end_time; |
bc8d270b |
2219 | guint x_end; |
8b90e648 |
2220 | } ClosureData; |
a56a1ba4 |
2221 | |
8b90e648 |
2222 | |
e800cf84 |
2223 | void draw_closure(gpointer key, gpointer value, gpointer user_data) |
2224 | { |
a56a1ba4 |
2225 | ProcessInfo *process_info = (ProcessInfo*)key; |
2226 | HashedProcessData *hashed_process_data = (HashedProcessData*)value; |
2227 | ClosureData *closure_data = (ClosureData*)user_data; |
2228 | |
e800cf84 |
2229 | EventsRequest *events_request = closure_data->events_request; |
2230 | ControlFlowData *control_flow_data = events_request->viewer_data; |
a56a1ba4 |
2231 | |
e800cf84 |
2232 | LttvTracesetState *tss = closure_data->tss; |
d6fef890 |
2233 | LttvTracesetContext *tsc = (LttvTracesetContext*)tss; |
a56a1ba4 |
2234 | |
e800cf84 |
2235 | LttTime evtime = closure_data->end_time; |
d0cd7f09 |
2236 | |
e800cf84 |
2237 | { |
2238 | /* For the process */ |
2239 | /* First, check if the current process is in the state computation |
2240 | * process list. If it is there, that means we must add it right now and |
2241 | * draw items from the beginning of the read for it. If it is not |
2242 | * present, it's a new process and it was not present : it will |
2243 | * be added after the state update. */ |
31b6868d |
2244 | #ifdef EXTRA_CHECK |
e800cf84 |
2245 | g_assert(lttv_traceset_number(tsc->ts) > 0); |
31b6868d |
2246 | #endif //EXTRA_CHECK |
2c82c4dc |
2247 | LttvTraceContext *tc = tsc->traces[process_info->trace_num]; |
348c6ba8 |
2248 | LttvTraceState *ts = (LttvTraceState*)tc; |
2c82c4dc |
2249 | |
348c6ba8 |
2250 | #if 0 |
2c82c4dc |
2251 | //FIXME : optimize data structures. |
2252 | LttvTracefileState *tfs; |
2253 | LttvTracefileContext *tfc; |
2254 | guint i; |
2255 | for(i=0;i<tc->tracefiles->len;i++) { |
2256 | tfc = g_array_index(tc->tracefiles, LttvTracefileContext*, i); |
2257 | if(ltt_tracefile_name(tfc->tf) == LTT_NAME_CPU |
2258 | && ltt_tracefile_num(tfc->tf) == process_info->cpu) |
2259 | break; |
2260 | |
2261 | } |
2262 | g_assert(i<tc->tracefiles->len); |
2263 | tfs = LTTV_TRACEFILE_STATE(tfc); |
348c6ba8 |
2264 | #endif //0 |
2c82c4dc |
2265 | // LttvTracefileState *tfs = |
2266 | // (LttvTracefileState*)tsc->traces[process_info->trace_num]-> |
2267 | // tracefiles[process_info->cpu]; |
2da61677 |
2268 | |
e800cf84 |
2269 | LttvProcessState *process; |
348c6ba8 |
2270 | process = lttv_state_find_process(ts, process_info->cpu, |
e025a729 |
2271 | process_info->pid); |
a56a1ba4 |
2272 | |
1d1df11d |
2273 | if(unlikely(process != NULL)) { |
e800cf84 |
2274 | |
2275 | /* Only draw for processes that are currently in the trace states */ |
ad2e83ba |
2276 | |
5c230fc4 |
2277 | ProcessList *process_list = control_flow_data->process_list; |
1d1df11d |
2278 | #ifdef EXTRA_CHECK |
e800cf84 |
2279 | /* Should be alike when background info is ready */ |
2280 | if(control_flow_data->background_info_waiting==0) |
2281 | g_assert(ltt_time_compare(process->creation_time, |
2282 | process_info->birth) == 0); |
1d1df11d |
2283 | #endif //EXTRA_CHECK |
e800cf84 |
2284 | |
2285 | /* Now, the process is in the state hash and our own process hash. |
2286 | * We definitely can draw the items related to the ending state. |
2287 | */ |
2288 | |
1d1df11d |
2289 | if(unlikely(ltt_time_compare(hashed_process_data->next_good_time, |
2290 | evtime) <= 0)) |
e800cf84 |
2291 | { |
fd22065b |
2292 | TimeWindow time_window = |
2293 | lttvwindow_get_time_window(control_flow_data->tab); |
2294 | |
2295 | #ifdef EXTRA_CHECK |
2296 | if(ltt_time_compare(evtime, time_window.start_time) == -1 |
2297 | || ltt_time_compare(evtime, time_window.end_time) == 1) |
2298 | return; |
2299 | #endif //EXTRA_CHECK |
d6fef890 |
2300 | Drawing_t *drawing = control_flow_data->drawing; |
96947fcf |
2301 | guint width = drawing->width; |
a56a1ba4 |
2302 | |
bc8d270b |
2303 | guint x = closure_data->x_end; |
8b90e648 |
2304 | |
4b7dc462 |
2305 | DrawContext draw_context; |
2306 | |
e800cf84 |
2307 | /* Now create the drawing context that will be used to draw |
2308 | * items related to the last state. */ |
1c736ed5 |
2309 | draw_context.drawable = hashed_process_data->pixmap; |
e800cf84 |
2310 | draw_context.gc = drawing->gc; |
2311 | draw_context.pango_layout = drawing->pango_layout; |
e800cf84 |
2312 | draw_context.drawinfo.end.x = x; |
2313 | |
1c736ed5 |
2314 | draw_context.drawinfo.y.over = 1; |
2315 | draw_context.drawinfo.y.middle = (hashed_process_data->height/2); |
2316 | draw_context.drawinfo.y.under = hashed_process_data->height; |
e800cf84 |
2317 | |
2318 | draw_context.drawinfo.start.offset.over = 0; |
2319 | draw_context.drawinfo.start.offset.middle = 0; |
2320 | draw_context.drawinfo.start.offset.under = 0; |
2321 | draw_context.drawinfo.end.offset.over = 0; |
2322 | draw_context.drawinfo.end.offset.middle = 0; |
2323 | draw_context.drawinfo.end.offset.under = 0; |
9a1ec01b |
2324 | #if 0 |
4b7dc462 |
2325 | /* Jump over draw if we are at the same x position */ |
2326 | if(x == hashed_process_data->x.over) |
e800cf84 |
2327 | { |
4b7dc462 |
2328 | /* jump */ |
2329 | } else { |
23093869 |
2330 | draw_context.drawinfo.start.x = hashed_process_data->x.over; |
2331 | /* Draw the line */ |
2332 | PropertiesLine prop_line = prepare_execmode_line(process); |
2333 | draw_line((void*)&prop_line, (void*)&draw_context); |
2334 | |
4b7dc462 |
2335 | hashed_process_data->x.over = x; |
23093869 |
2336 | } |
9a1ec01b |
2337 | #endif //0 |
4b7dc462 |
2338 | |
1d1df11d |
2339 | if(unlikely(x == hashed_process_data->x.middle && |
2340 | hashed_process_data->x.middle_used)) { |
b2743953 |
2341 | #if 0 /* do not mark closure : not missing information */ |
e72908ed |
2342 | if(hashed_process_data->x.middle_marked == FALSE) { |
2343 | /* Draw collision indicator */ |
2344 | gdk_gc_set_foreground(drawing->gc, &drawing_colors[COL_WHITE]); |
2345 | gdk_draw_point(drawing->pixmap, |
2346 | drawing->gc, |
2347 | x, |
2c6618bc |
2348 | y+(height/2)-3); |
de4ea1ad |
2349 | hashed_process_data->x.middle_marked = TRUE; |
e72908ed |
2350 | } |
b2743953 |
2351 | #endif //0 |
4b7dc462 |
2352 | /* Jump */ |
2353 | } else { |
23093869 |
2354 | draw_context.drawinfo.start.x = hashed_process_data->x.middle; |
e800cf84 |
2355 | /* Draw the line */ |
9a1ec01b |
2356 | PropertiesLine prop_line = prepare_s_e_line(process); |
e800cf84 |
2357 | draw_line((void*)&prop_line, (void*)&draw_context); |
2358 | |
4b7dc462 |
2359 | /* become the last x position */ |
1d1df11d |
2360 | if(likely(x != hashed_process_data->x.middle)) { |
e72908ed |
2361 | hashed_process_data->x.middle = x; |
2362 | /* but don't use the pixel */ |
2363 | hashed_process_data->x.middle_used = FALSE; |
b2743953 |
2364 | |
2365 | /* Calculate the next good time */ |
2366 | convert_pixels_to_time(width, x+1, time_window, |
2367 | &hashed_process_data->next_good_time); |
e72908ed |
2368 | } |
e800cf84 |
2369 | } |
e800cf84 |
2370 | } |
2371 | } |
2372 | } |
2373 | return; |
8b90e648 |
2374 | } |
2375 | |
b9a010a2 |
2376 | int before_chunk(void *hook_data, void *call_data) |
2377 | { |
2378 | EventsRequest *events_request = (EventsRequest*)hook_data; |
16b9cadb |
2379 | LttvTracesetState *tss = (LttvTracesetState*)call_data; |
7c0125e0 |
2380 | ControlFlowData *cfd = (ControlFlowData*)events_request->viewer_data; |
cd3892fe |
2381 | #if 0 |
7c0125e0 |
2382 | /* Desactivate sort */ |
2383 | gtk_tree_sortable_set_sort_column_id( |
2384 | GTK_TREE_SORTABLE(cfd->process_list->list_store), |
2385 | TRACE_COLUMN, |
2386 | GTK_SORT_ASCENDING); |
cd3892fe |
2387 | #endif //0 |
b9a010a2 |
2388 | drawing_chunk_begin(events_request, tss); |
2389 | |
2390 | return 0; |
2391 | } |
2392 | |
2393 | int before_request(void *hook_data, void *call_data) |
ca0f8a8e |
2394 | { |
2395 | EventsRequest *events_request = (EventsRequest*)hook_data; |
16b9cadb |
2396 | LttvTracesetState *tss = (LttvTracesetState*)call_data; |
7c0125e0 |
2397 | |
ca0f8a8e |
2398 | drawing_data_request_begin(events_request, tss); |
2399 | |
2400 | return 0; |
2401 | } |
2402 | |
2403 | |
8b90e648 |
2404 | /* |
b9a010a2 |
2405 | * after request is necessary in addition of after chunk in order to draw |
2406 | * lines until the end of the screen. after chunk just draws lines until |
2407 | * the last event. |
2408 | * |
8b90e648 |
2409 | * for each process |
a56a1ba4 |
2410 | * draw closing line |
b9a010a2 |
2411 | * expose |
8b90e648 |
2412 | */ |
b9a010a2 |
2413 | int after_request(void *hook_data, void *call_data) |
8b90e648 |
2414 | { |
ca0f8a8e |
2415 | EventsRequest *events_request = (EventsRequest*)hook_data; |
2416 | ControlFlowData *control_flow_data = events_request->viewer_data; |
16b9cadb |
2417 | LttvTracesetState *tss = (LttvTracesetState*)call_data; |
a56a1ba4 |
2418 | |
5c230fc4 |
2419 | ProcessList *process_list = control_flow_data->process_list; |
b9a010a2 |
2420 | LttTime end_time = events_request->end_time; |
2421 | |
2422 | ClosureData closure_data; |
2423 | closure_data.events_request = (EventsRequest*)hook_data; |
2424 | closure_data.tss = tss; |
2425 | closure_data.end_time = end_time; |
2426 | |
bc8d270b |
2427 | TimeWindow time_window = |
2428 | lttvwindow_get_time_window(control_flow_data->tab); |
2429 | guint width = control_flow_data->drawing->width; |
2430 | convert_time_to_pixels( |
2431 | time_window, |
2432 | end_time, |
2433 | width, |
2434 | &closure_data.x_end); |
2435 | |
2436 | |
b9a010a2 |
2437 | /* Draw last items */ |
2438 | g_hash_table_foreach(process_list->process_hash, draw_closure, |
2439 | (void*)&closure_data); |
7c0125e0 |
2440 | |
b9a010a2 |
2441 | |
2442 | /* Request expose */ |
2443 | drawing_request_expose(events_request, tss, end_time); |
2444 | return 0; |
2445 | } |
2446 | |
2447 | /* |
2448 | * for each process |
2449 | * draw closing line |
e800cf84 |
2450 | * expose |
b9a010a2 |
2451 | */ |
2452 | int after_chunk(void *hook_data, void *call_data) |
2453 | { |
2454 | EventsRequest *events_request = (EventsRequest*)hook_data; |
2455 | ControlFlowData *control_flow_data = events_request->viewer_data; |
16b9cadb |
2456 | LttvTracesetState *tss = (LttvTracesetState*)call_data; |
2457 | LttvTracesetContext *tsc = (LttvTracesetContext*)call_data; |
b9a010a2 |
2458 | LttvTracefileContext *tfc = lttv_traceset_context_get_current_tfc(tsc); |
2459 | LttTime end_time; |
2460 | |
5c230fc4 |
2461 | ProcessList *process_list = control_flow_data->process_list; |
b9a010a2 |
2462 | |
40debf7b |
2463 | g_free(process_list->current_hash_data); |
2464 | process_list->current_hash_data = NULL; |
2465 | |
e800cf84 |
2466 | if(tfc != NULL) |
2467 | end_time = LTT_TIME_MIN(tfc->timestamp, events_request->end_time); |
0c5dbe3b |
2468 | else /* end of traceset, or position now out of request : end */ |
2469 | end_time = events_request->end_time; |
2470 | |
a56a1ba4 |
2471 | ClosureData closure_data; |
ca0f8a8e |
2472 | closure_data.events_request = (EventsRequest*)hook_data; |
2473 | closure_data.tss = tss; |
b9a010a2 |
2474 | closure_data.end_time = end_time; |
a56a1ba4 |
2475 | |
bc8d270b |
2476 | TimeWindow time_window = |
2477 | lttvwindow_get_time_window(control_flow_data->tab); |
2478 | guint width = control_flow_data->drawing->width; |
2479 | convert_time_to_pixels( |
2480 | time_window, |
2481 | end_time, |
2482 | width, |
2483 | &closure_data.x_end); |
2484 | |
b9a010a2 |
2485 | /* Draw last items */ |
14963be0 |
2486 | g_hash_table_foreach(process_list->process_hash, draw_closure, |
a56a1ba4 |
2487 | (void*)&closure_data); |
cd3892fe |
2488 | #if 0 |
7c0125e0 |
2489 | /* Reactivate sort */ |
2490 | gtk_tree_sortable_set_sort_column_id( |
2491 | GTK_TREE_SORTABLE(control_flow_data->process_list->list_store), |
2492 | GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, |
2493 | GTK_SORT_ASCENDING); |
2494 | |
2495 | update_index_to_pixmap(control_flow_data->process_list); |
cd3892fe |
2496 | /* Request a full expose : drawing scrambled */ |
2497 | gtk_widget_queue_draw(control_flow_data->drawing->drawing_area); |
2498 | #endif //0 |
2499 | /* Request expose (updates damages zone also) */ |
b9a010a2 |
2500 | drawing_request_expose(events_request, tss, end_time); |
ca0f8a8e |
2501 | |
2502 | return 0; |
8b90e648 |
2503 | } |
2504 | |