f0d936c0 |
1 | /***************************************************************************** |
2 | * Hooks to be called by the main window * |
3 | *****************************************************************************/ |
4 | |
f0d936c0 |
5 | |
189a5d08 |
6 | #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format) |
7 | #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format) |
8 | |
cf6cb7e0 |
9 | //#define PANGO_ENABLE_BACKEND |
558aa013 |
10 | #include <gtk/gtk.h> |
11 | #include <gdk/gdk.h> |
5f16133f |
12 | #include <glib.h> |
80a52ff8 |
13 | #include <assert.h> |
50439712 |
14 | #include <string.h> |
5f16133f |
15 | |
cf6cb7e0 |
16 | //#include <pango/pango.h> |
17 | |
80a52ff8 |
18 | #include <ltt/event.h> |
4ba42155 |
19 | #include <ltt/time.h> |
50439712 |
20 | #include <ltt/type.h> |
80a52ff8 |
21 | |
558aa013 |
22 | #include <lttv/hook.h> |
23 | #include <lttv/common.h> |
80a52ff8 |
24 | #include <lttv/state.h> |
1b238973 |
25 | #include <lttv/gtkTraceSet.h> |
80a52ff8 |
26 | |
f0d936c0 |
27 | |
1ab818de |
28 | #include "Event_Hooks.h" |
f0d936c0 |
29 | #include "CFV.h" |
5f16133f |
30 | #include "Process_List.h" |
1ab3d149 |
31 | #include "Drawing.h" |
f7afe191 |
32 | #include "CFV-private.h" |
5f16133f |
33 | |
80a52ff8 |
34 | |
1a31868c |
35 | #define MAX_PATH_LEN 256 |
36 | |
f0d936c0 |
37 | |
38 | /** |
39 | * Event Viewer's constructor hook |
40 | * |
41 | * This constructor is given as a parameter to the menuitem and toolbar button |
42 | * registration. It creates the list. |
14963be0 |
43 | * @param mw A pointer to the parent window. |
f0d936c0 |
44 | * @return The widget created. |
45 | */ |
46 | GtkWidget * |
14963be0 |
47 | h_guicontrolflow(MainWindow *mw, LttvTracesetSelector * s, char * key) |
f0d936c0 |
48 | { |
14963be0 |
49 | g_info("h_guicontrolflow, %p, %p, %s", mw, s, key); |
68997a22 |
50 | ControlFlowData *control_flow_data = guicontrolflow() ; |
a56a1ba4 |
51 | |
14963be0 |
52 | control_flow_data->mw = mw; |
68997a22 |
53 | TimeWindow *time_window = guicontrolflow_get_time_window(control_flow_data); |
a56a1ba4 |
54 | time_window->start_time.tv_sec = 0; |
55 | time_window->start_time.tv_nsec = 0; |
56 | time_window->time_width.tv_sec = 0; |
57 | time_window->time_width.tv_nsec = 0; |
58 | |
68997a22 |
59 | LttTime *current_time = guicontrolflow_get_current_time(control_flow_data); |
a56a1ba4 |
60 | current_time->tv_sec = 0; |
61 | current_time->tv_nsec = 0; |
62 | |
63 | //g_critical("time width1 : %u",time_window->time_width); |
64 | |
14963be0 |
65 | get_time_window(mw, |
a56a1ba4 |
66 | time_window); |
14963be0 |
67 | get_current_time(mw, |
a56a1ba4 |
68 | current_time); |
69 | |
70 | //g_critical("time width2 : %u",time_window->time_width); |
71 | // Unreg done in the GuiControlFlow_Destructor |
68997a22 |
72 | reg_update_time_window(update_time_window_hook, control_flow_data, |
14963be0 |
73 | mw); |
68997a22 |
74 | reg_update_current_time(update_current_time_hook, control_flow_data, |
14963be0 |
75 | mw); |
68997a22 |
76 | return guicontrolflow_get_widget(control_flow_data) ; |
a56a1ba4 |
77 | |
f0d936c0 |
78 | } |
79 | |
3cff8cc1 |
80 | int event_selected_hook(void *hook_data, void *call_data) |
f0d936c0 |
81 | { |
68997a22 |
82 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
14963be0 |
83 | guint *event_number = (guint*) call_data; |
f0d936c0 |
84 | |
14963be0 |
85 | g_critical("DEBUG : event selected by main window : %u", *event_number); |
a56a1ba4 |
86 | |
14963be0 |
87 | // control_flow_data->currently_Selected_Event = *event_number; |
68997a22 |
88 | // control_flow_data->Selected_Event = TRUE ; |
a56a1ba4 |
89 | |
68997a22 |
90 | // tree_v_set_cursor(control_flow_data); |
f0d936c0 |
91 | |
92 | } |
93 | |
f0d936c0 |
94 | /* Hook called before drawing. Gets the initial context at the beginning of the |
14963be0 |
95 | * drawing interval and copy it to the context in event_request. |
f0d936c0 |
96 | */ |
4c69e0cc |
97 | int draw_before_hook(void *hook_data, void *call_data) |
f0d936c0 |
98 | { |
14963be0 |
99 | EventRequest *event_request = (EventRequest*)hook_data; |
a56a1ba4 |
100 | //EventsContext Events_Context = (EventsContext*)call_data; |
101 | |
14963be0 |
102 | //event_request->Events_Context = Events_Context; |
f0d936c0 |
103 | |
a56a1ba4 |
104 | return 0; |
f0d936c0 |
105 | } |
106 | |
107 | /* |
108 | * The draw event hook is called by the reading API to have a |
109 | * particular event drawn on the screen. |
110 | * @param hook_data ControlFlowData structure of the viewer. |
111 | * @param call_data Event context. |
112 | * |
113 | * This function basically draw lines and icons. Two types of lines are drawn : |
114 | * one small (3 pixels?) representing the state of the process and the second |
115 | * type is thicker (10 pixels?) representing on which CPU a process is running |
116 | * (and this only in running state). |
117 | * |
118 | * Extremums of the lines : |
119 | * x_min : time of the last event context for this process kept in memory. |
120 | * x_max : time of the current event. |
121 | * y : middle of the process in the process list. The process is found in the |
122 | * list, therefore is it's position in pixels. |
123 | * |
124 | * The choice of lines'color is defined by the context of the last event for this |
125 | * process. |
126 | */ |
4c69e0cc |
127 | int draw_event_hook(void *hook_data, void *call_data) |
f0d936c0 |
128 | { |
14963be0 |
129 | EventRequest *event_request = (EventRequest*)hook_data; |
130 | ControlFlowData *control_flow_data = event_request->control_flow_data; |
e9a9c513 |
131 | |
a56a1ba4 |
132 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
e9a9c513 |
133 | |
134 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
135 | |
a56a1ba4 |
136 | |
e9a9c513 |
137 | LttEvent *e; |
e9a9c513 |
138 | e = tfc->e; |
139 | |
a56a1ba4 |
140 | if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0) |
141 | { |
142 | g_critical("schedchange!"); |
143 | |
144 | /* Add process to process list (if not present) and get drawing "y" from |
145 | * process position */ |
146 | guint pid_out, pid_in; |
147 | LttvProcessState *process_out, *process_in; |
148 | LttTime birth; |
149 | guint y_in = 0, y_out = 0, height = 0, pl_height = 0; |
150 | |
151 | ProcessList *process_list = |
14963be0 |
152 | guicontrolflow_get_process_list(event_request->control_flow_data); |
a56a1ba4 |
153 | |
154 | |
155 | LttField *f = ltt_event_field(e); |
156 | LttField *element; |
157 | element = ltt_field_member(f,0); |
158 | pid_out = ltt_event_get_long_unsigned(e,element); |
159 | element = ltt_field_member(f,1); |
160 | pid_in = ltt_event_get_long_unsigned(e,element); |
161 | g_critical("out : %u in : %u", pid_out, pid_in); |
162 | |
163 | |
164 | /* Find process pid_out in the list... */ |
165 | process_out = lttv_state_find_process(tfs, pid_out); |
166 | g_critical("out : %s",g_quark_to_string(process_out->state->s)); |
167 | |
168 | birth = process_out->creation_time; |
169 | gchar *name = strdup(g_quark_to_string(process_out->name)); |
14963be0 |
170 | HashedProcessData *hashed_process_data_out = NULL; |
a56a1ba4 |
171 | |
172 | if(processlist_get_process_pixels(process_list, |
173 | pid_out, |
174 | &birth, |
175 | &y_out, |
176 | &height, |
14963be0 |
177 | &hashed_process_data_out) == 1) |
a56a1ba4 |
178 | { |
179 | /* Process not present */ |
180 | processlist_add(process_list, |
181 | pid_out, |
182 | &birth, |
183 | name, |
184 | &pl_height, |
14963be0 |
185 | &hashed_process_data_out); |
a56a1ba4 |
186 | processlist_get_process_pixels(process_list, |
187 | pid_out, |
188 | &birth, |
189 | &y_out, |
190 | &height, |
14963be0 |
191 | &hashed_process_data_out); |
501d5405 |
192 | drawing_insert_square( event_request->control_flow_data->drawing, y_out, height); |
a56a1ba4 |
193 | } |
194 | |
195 | g_free(name); |
196 | |
197 | /* Find process pid_in in the list... */ |
198 | process_in = lttv_state_find_process(tfs, pid_in); |
199 | g_critical("in : %s",g_quark_to_string(process_in->state->s)); |
200 | |
201 | birth = process_in->creation_time; |
202 | name = strdup(g_quark_to_string(process_in->name)); |
14963be0 |
203 | HashedProcessData *hashed_process_data_in = NULL; |
a56a1ba4 |
204 | |
205 | if(processlist_get_process_pixels(process_list, |
206 | pid_in, |
207 | &birth, |
208 | &y_in, |
209 | &height, |
14963be0 |
210 | &hashed_process_data_in) == 1) |
a56a1ba4 |
211 | { |
212 | /* Process not present */ |
213 | processlist_add(process_list, |
214 | pid_in, |
215 | &birth, |
216 | name, |
217 | &pl_height, |
14963be0 |
218 | &hashed_process_data_in); |
a56a1ba4 |
219 | processlist_get_process_pixels(process_list, |
220 | pid_in, |
221 | &birth, |
222 | &y_in, |
223 | &height, |
14963be0 |
224 | &hashed_process_data_in); |
a56a1ba4 |
225 | |
501d5405 |
226 | drawing_insert_square( event_request->control_flow_data->drawing, y_in, height); |
a56a1ba4 |
227 | } |
228 | g_free(name); |
229 | |
230 | |
231 | /* Find pixels corresponding to time of the event. If the time does |
232 | * not fit in the window, show a warning, not supposed to happend. */ |
233 | guint x = 0; |
501d5405 |
234 | guint width = control_flow_data->drawing->drawing_area->allocation.width; |
a56a1ba4 |
235 | |
236 | LttTime time = ltt_event_time(e); |
237 | |
ba90bc77 |
238 | LttTime window_end = ltt_time_add(control_flow_data->time_window.time_width, |
239 | control_flow_data->time_window.start_time); |
a56a1ba4 |
240 | |
241 | |
242 | convert_time_to_pixels( |
ba90bc77 |
243 | control_flow_data->time_window.start_time, |
a56a1ba4 |
244 | window_end, |
245 | time, |
246 | width, |
247 | &x); |
248 | |
249 | assert(x <= width); |
250 | |
251 | /* draw what represents the event for outgoing process. */ |
252 | |
14963be0 |
253 | DrawContext *draw_context_out = hashed_process_data_out->draw_context; |
68997a22 |
254 | draw_context_out->current->modify_over->x = x; |
255 | draw_context_out->current->modify_over->y = y_out; |
501d5405 |
256 | draw_context_out->drawable = control_flow_data->drawing->pixmap; |
257 | draw_context_out->pango_layout = control_flow_data->drawing->pango_layout; |
258 | GtkWidget *widget = control_flow_data->drawing->drawing_area; |
a56a1ba4 |
259 | //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)]; |
501d5405 |
260 | draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap); |
a56a1ba4 |
261 | gdk_gc_copy(draw_context_out->gc, widget->style->black_gc); |
262 | //draw_context_out->gc = widget->style->black_gc; |
263 | |
264 | //draw_arc((void*)&prop_arc, (void*)draw_context_out); |
501d5405 |
265 | //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap); |
a56a1ba4 |
266 | |
267 | GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 }; |
268 | GdkColor colorbg_out = { 0, 0xffff, 0xffff, 0xffff }; |
269 | PropertiesText prop_text_out; |
270 | prop_text_out.foreground = &colorfg_out; |
271 | prop_text_out.background = &colorbg_out; |
272 | prop_text_out.size = 10; |
273 | prop_text_out.position = OVER; |
274 | |
275 | /* Print status of the process : U, WF, WC, E, W, R */ |
276 | if(process_out->state->s == LTTV_STATE_UNNAMED) |
68997a22 |
277 | prop_text_out.text = "U"; |
a56a1ba4 |
278 | else if(process_out->state->s == LTTV_STATE_WAIT_FORK) |
68997a22 |
279 | prop_text_out.text = "WF"; |
a56a1ba4 |
280 | else if(process_out->state->s == LTTV_STATE_WAIT_CPU) |
68997a22 |
281 | prop_text_out.text = "WC"; |
a56a1ba4 |
282 | else if(process_out->state->s == LTTV_STATE_EXIT) |
68997a22 |
283 | prop_text_out.text = "E"; |
a56a1ba4 |
284 | else if(process_out->state->s == LTTV_STATE_WAIT) |
68997a22 |
285 | prop_text_out.text = "W"; |
a56a1ba4 |
286 | else if(process_out->state->s == LTTV_STATE_RUN) |
68997a22 |
287 | prop_text_out.text = "R"; |
a56a1ba4 |
288 | else |
68997a22 |
289 | prop_text_out.text = "U"; |
a56a1ba4 |
290 | |
291 | draw_text((void*)&prop_text_out, (void*)draw_context_out); |
292 | gdk_gc_unref(draw_context_out->gc); |
293 | |
294 | /* Draw the line of the out process */ |
68997a22 |
295 | if(draw_context_out->previous->middle->x == -1) |
a56a1ba4 |
296 | { |
14963be0 |
297 | draw_context_out->previous->middle->x = event_request->x_begin; |
298 | g_critical("out middle x_beg : %u",event_request->x_begin); |
a56a1ba4 |
299 | } |
300 | |
68997a22 |
301 | draw_context_out->current->middle->x = x; |
302 | draw_context_out->current->middle->y = y_out + height/2; |
303 | draw_context_out->previous->middle->y = y_out + height/2; |
501d5405 |
304 | draw_context_out->drawable = control_flow_data->drawing->pixmap; |
305 | draw_context_out->pango_layout = control_flow_data->drawing->pango_layout; |
a56a1ba4 |
306 | //draw_context_out->gc = widget->style->black_gc; |
501d5405 |
307 | draw_context_out->gc = gdk_gc_new(control_flow_data->drawing->pixmap); |
a56a1ba4 |
308 | gdk_gc_copy(draw_context_out->gc, widget->style->black_gc); |
309 | |
310 | PropertiesLine prop_line_out; |
311 | prop_line_out.color = g_new(GdkColor,1); |
312 | prop_line_out.line_width = 4; |
313 | prop_line_out.style = GDK_LINE_SOLID; |
314 | prop_line_out.position = MIDDLE; |
315 | |
316 | /* color of line : status of the process */ |
317 | if(process_out->state->s == LTTV_STATE_UNNAMED) |
318 | { |
319 | prop_line_out.color->red = 0x0000; |
320 | prop_line_out.color->green = 0x0000; |
321 | prop_line_out.color->blue = 0x0000; |
322 | } |
323 | else if(process_out->state->s == LTTV_STATE_WAIT_FORK) |
324 | { |
325 | prop_line_out.color->red = 0x0fff; |
326 | prop_line_out.color->green = 0x0000; |
327 | prop_line_out.color->blue = 0x0fff; |
328 | } |
329 | else if(process_out->state->s == LTTV_STATE_WAIT_CPU) |
330 | { |
331 | prop_line_out.color->red = 0x0fff; |
332 | prop_line_out.color->green = 0x0fff; |
333 | prop_line_out.color->blue = 0x0000; |
334 | } |
335 | else if(process_out->state->s == LTTV_STATE_EXIT) |
336 | { |
337 | prop_line_out.color->red = 0xffff; |
338 | prop_line_out.color->green = 0x0000; |
339 | prop_line_out.color->blue = 0xffff; |
340 | } |
341 | else if(process_out->state->s == LTTV_STATE_WAIT) |
342 | { |
343 | prop_line_out.color->red = 0xffff; |
344 | prop_line_out.color->green = 0x0000; |
345 | prop_line_out.color->blue = 0x0000; |
346 | } |
347 | else if(process_out->state->s == LTTV_STATE_RUN) |
348 | { |
349 | prop_line_out.color->red = 0x0000; |
350 | prop_line_out.color->green = 0xffff; |
351 | prop_line_out.color->blue = 0x0000; |
352 | } |
353 | else |
354 | { |
355 | prop_line_out.color->red = 0x0000; |
356 | prop_line_out.color->green = 0x0000; |
357 | prop_line_out.color->blue = 0x0000; |
358 | } |
359 | |
360 | draw_line((void*)&prop_line_out, (void*)draw_context_out); |
361 | g_free(prop_line_out.color); |
362 | gdk_gc_unref(draw_context_out->gc); |
363 | /* Note : finishing line will have to be added when trace read over. */ |
364 | |
365 | /* Finally, update the drawing context of the pid_in. */ |
366 | |
14963be0 |
367 | DrawContext *draw_context_in = hashed_process_data_in->draw_context; |
68997a22 |
368 | draw_context_in->current->modify_over->x = x; |
369 | draw_context_in->current->modify_over->y = y_in; |
501d5405 |
370 | draw_context_in->drawable = control_flow_data->drawing->pixmap; |
371 | draw_context_in->pango_layout = control_flow_data->drawing->pango_layout; |
372 | widget = control_flow_data->drawing->drawing_area; |
a56a1ba4 |
373 | //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)]; |
374 | //draw_context_in->gc = widget->style->black_gc; |
501d5405 |
375 | draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap); |
a56a1ba4 |
376 | gdk_gc_copy(draw_context_in->gc, widget->style->black_gc); |
377 | |
378 | //draw_arc((void*)&prop_arc, (void*)draw_context_in); |
501d5405 |
379 | //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap); |
a56a1ba4 |
380 | |
381 | GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 }; |
382 | GdkColor colorbg_in = { 0, 0xffff, 0xffff, 0xffff }; |
383 | PropertiesText prop_text_in; |
384 | prop_text_in.foreground = &colorfg_in; |
385 | prop_text_in.background = &colorbg_in; |
386 | prop_text_in.size = 10; |
387 | prop_text_in.position = OVER; |
388 | |
389 | /* Print status of the process : U, WF, WC, E, W, R */ |
390 | if(process_in->state->s == LTTV_STATE_UNNAMED) |
68997a22 |
391 | prop_text_in.text = "U"; |
a56a1ba4 |
392 | else if(process_in->state->s == LTTV_STATE_WAIT_FORK) |
68997a22 |
393 | prop_text_in.text = "WF"; |
a56a1ba4 |
394 | else if(process_in->state->s == LTTV_STATE_WAIT_CPU) |
68997a22 |
395 | prop_text_in.text = "WC"; |
a56a1ba4 |
396 | else if(process_in->state->s == LTTV_STATE_EXIT) |
68997a22 |
397 | prop_text_in.text = "E"; |
a56a1ba4 |
398 | else if(process_in->state->s == LTTV_STATE_WAIT) |
68997a22 |
399 | prop_text_in.text = "W"; |
a56a1ba4 |
400 | else if(process_in->state->s == LTTV_STATE_RUN) |
68997a22 |
401 | prop_text_in.text = "R"; |
a56a1ba4 |
402 | else |
68997a22 |
403 | prop_text_in.text = "U"; |
a56a1ba4 |
404 | |
405 | draw_text((void*)&prop_text_in, (void*)draw_context_in); |
406 | gdk_gc_unref(draw_context_in->gc); |
407 | |
408 | /* Draw the line of the in process */ |
68997a22 |
409 | if(draw_context_in->previous->middle->x == -1) |
a56a1ba4 |
410 | { |
14963be0 |
411 | draw_context_in->previous->middle->x = event_request->x_begin; |
412 | g_critical("in middle x_beg : %u",event_request->x_begin); |
a56a1ba4 |
413 | } |
414 | |
68997a22 |
415 | draw_context_in->current->middle->x = x; |
416 | draw_context_in->previous->middle->y = y_in + height/2; |
417 | draw_context_in->current->middle->y = y_in + height/2; |
501d5405 |
418 | draw_context_in->drawable = control_flow_data->drawing->pixmap; |
419 | draw_context_in->pango_layout = control_flow_data->drawing->pango_layout; |
a56a1ba4 |
420 | //draw_context_in->gc = widget->style->black_gc; |
501d5405 |
421 | draw_context_in->gc = gdk_gc_new(control_flow_data->drawing->pixmap); |
a56a1ba4 |
422 | gdk_gc_copy(draw_context_in->gc, widget->style->black_gc); |
423 | |
424 | PropertiesLine prop_line_in; |
425 | prop_line_in.color = g_new(GdkColor,1); |
426 | prop_line_in.line_width = 4; |
427 | prop_line_in.style = GDK_LINE_SOLID; |
428 | prop_line_in.position = MIDDLE; |
429 | |
430 | /* color of line : status of the process */ |
431 | if(process_in->state->s == LTTV_STATE_UNNAMED) |
432 | { |
433 | prop_line_in.color->red = 0x0000; |
434 | prop_line_in.color->green = 0x0000; |
435 | prop_line_in.color->blue = 0x0000; |
436 | } |
437 | else if(process_in->state->s == LTTV_STATE_WAIT_FORK) |
438 | { |
439 | prop_line_in.color->red = 0x0fff; |
440 | prop_line_in.color->green = 0x0000; |
441 | prop_line_in.color->blue = 0x0fff; |
442 | } |
443 | else if(process_in->state->s == LTTV_STATE_WAIT_CPU) |
444 | { |
445 | prop_line_in.color->red = 0x0fff; |
446 | prop_line_in.color->green = 0x0fff; |
447 | prop_line_in.color->blue = 0x0000; |
448 | } |
449 | else if(process_in->state->s == LTTV_STATE_EXIT) |
450 | { |
451 | prop_line_in.color->red = 0xffff; |
452 | prop_line_in.color->green = 0x0000; |
453 | prop_line_in.color->blue = 0xffff; |
454 | } |
455 | else if(process_in->state->s == LTTV_STATE_WAIT) |
456 | { |
457 | prop_line_in.color->red = 0xffff; |
458 | prop_line_in.color->green = 0x0000; |
459 | prop_line_in.color->blue = 0x0000; |
460 | } |
461 | else if(process_in->state->s == LTTV_STATE_RUN) |
462 | { |
463 | prop_line_in.color->red = 0x0000; |
464 | prop_line_in.color->green = 0xffff; |
465 | prop_line_in.color->blue = 0x0000; |
466 | } |
467 | else |
468 | { |
469 | prop_line_in.color->red = 0x0000; |
470 | prop_line_in.color->green = 0x0000; |
471 | prop_line_in.color->blue = 0x0000; |
472 | } |
473 | |
474 | draw_line((void*)&prop_line_in, (void*)draw_context_in); |
475 | g_free(prop_line_in.color); |
476 | gdk_gc_unref(draw_context_in->gc); |
477 | } |
478 | |
479 | return 0; |
480 | |
481 | /* Temp dump */ |
80a52ff8 |
482 | #ifdef DONTSHOW |
a56a1ba4 |
483 | GString *string = g_string_new("");; |
484 | gboolean field_names = TRUE, state = TRUE; |
80a52ff8 |
485 | |
e9a9c513 |
486 | lttv_event_to_string(e, tfc->tf, string, TRUE, field_names, tfs); |
487 | g_string_append_printf(string,"\n"); |
488 | |
489 | if(state) { |
490 | g_string_append_printf(string, " %s", |
491 | g_quark_to_string(tfs->process->state->s)); |
492 | } |
493 | |
494 | g_info("%s",string->str); |
495 | |
a56a1ba4 |
496 | g_string_free(string, TRUE); |
497 | |
498 | /* End of text dump */ |
80a52ff8 |
499 | #endif //DONTSHOW |
50439712 |
500 | |
f0d936c0 |
501 | } |
502 | |
503 | |
4c69e0cc |
504 | int draw_after_hook(void *hook_data, void *call_data) |
f0d936c0 |
505 | { |
14963be0 |
506 | EventRequest *event_request = (EventRequest*)hook_data; |
507 | ControlFlowData *control_flow_data = event_request->control_flow_data; |
50439712 |
508 | |
a56a1ba4 |
509 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
50439712 |
510 | |
511 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
512 | |
a56a1ba4 |
513 | |
50439712 |
514 | LttEvent *e; |
515 | e = tfc->e; |
516 | |
a56a1ba4 |
517 | if(strcmp(ltt_eventtype_name(ltt_event_eventtype(e)),"schedchange") == 0) |
518 | { |
519 | g_critical("schedchange!"); |
520 | |
521 | /* Add process to process list (if not present) and get drawing "y" from |
522 | * process position */ |
523 | guint pid_out, pid_in; |
524 | LttvProcessState *process_out, *process_in; |
525 | LttTime birth; |
526 | guint y_in = 0, y_out = 0, height = 0, pl_height = 0; |
527 | |
528 | ProcessList *process_list = |
14963be0 |
529 | guicontrolflow_get_process_list(event_request->control_flow_data); |
a56a1ba4 |
530 | |
531 | |
532 | LttField *f = ltt_event_field(e); |
533 | LttField *element; |
534 | element = ltt_field_member(f,0); |
535 | pid_out = ltt_event_get_long_unsigned(e,element); |
536 | element = ltt_field_member(f,1); |
537 | pid_in = ltt_event_get_long_unsigned(e,element); |
538 | g_critical("out : %u in : %u", pid_out, pid_in); |
539 | |
540 | |
541 | /* Find process pid_out in the list... */ |
542 | process_out = lttv_state_find_process(tfs, pid_out); |
543 | g_critical("out : %s",g_quark_to_string(process_out->state->s)); |
544 | |
545 | birth = process_out->creation_time; |
546 | gchar *name = strdup(g_quark_to_string(process_out->name)); |
14963be0 |
547 | HashedProcessData *hashed_process_data_out = NULL; |
a56a1ba4 |
548 | |
549 | if(processlist_get_process_pixels(process_list, |
550 | pid_out, |
551 | &birth, |
552 | &y_out, |
553 | &height, |
14963be0 |
554 | &hashed_process_data_out) == 1) |
a56a1ba4 |
555 | { |
556 | /* Process not present */ |
557 | processlist_add(process_list, |
558 | pid_out, |
559 | &birth, |
560 | name, |
561 | &pl_height, |
14963be0 |
562 | &hashed_process_data_out); |
a56a1ba4 |
563 | processlist_get_process_pixels(process_list, |
564 | pid_out, |
565 | &birth, |
566 | &y_out, |
567 | &height, |
14963be0 |
568 | &hashed_process_data_out); |
501d5405 |
569 | drawing_insert_square( event_request->control_flow_data->drawing, y_out, height); |
a56a1ba4 |
570 | } |
571 | |
572 | g_free(name); |
573 | |
574 | /* Find process pid_in in the list... */ |
575 | process_in = lttv_state_find_process(tfs, pid_in); |
576 | g_critical("in : %s",g_quark_to_string(process_in->state->s)); |
577 | |
578 | birth = process_in->creation_time; |
579 | name = strdup(g_quark_to_string(process_in->name)); |
14963be0 |
580 | HashedProcessData *hashed_process_data_in = NULL; |
a56a1ba4 |
581 | |
582 | if(processlist_get_process_pixels(process_list, |
583 | pid_in, |
584 | &birth, |
585 | &y_in, |
586 | &height, |
14963be0 |
587 | &hashed_process_data_in) == 1) |
a56a1ba4 |
588 | { |
589 | /* Process not present */ |
590 | processlist_add(process_list, |
591 | pid_in, |
592 | &birth, |
593 | name, |
594 | &pl_height, |
14963be0 |
595 | &hashed_process_data_in); |
a56a1ba4 |
596 | processlist_get_process_pixels(process_list, |
597 | pid_in, |
598 | &birth, |
599 | &y_in, |
600 | &height, |
14963be0 |
601 | &hashed_process_data_in); |
a56a1ba4 |
602 | |
501d5405 |
603 | drawing_insert_square( event_request->control_flow_data->drawing, y_in, height); |
a56a1ba4 |
604 | } |
605 | g_free(name); |
606 | |
607 | |
608 | /* Find pixels corresponding to time of the event. If the time does |
609 | * not fit in the window, show a warning, not supposed to happend. */ |
610 | //guint x = 0; |
501d5405 |
611 | //guint width = control_flow_data->drawing->drawing_area->allocation.width; |
a56a1ba4 |
612 | |
613 | //LttTime time = ltt_event_time(e); |
614 | |
ba90bc77 |
615 | //LttTime window_end = ltt_time_add(control_flow_data->time_window.time_width, |
616 | // control_flow_data->time_window.start_time); |
a56a1ba4 |
617 | |
618 | |
619 | //convert_time_to_pixels( |
ba90bc77 |
620 | // control_flow_data->time_window.start_time, |
a56a1ba4 |
621 | // window_end, |
622 | // time, |
623 | // width, |
624 | // &x); |
625 | |
626 | //assert(x <= width); |
627 | |
628 | /* draw what represents the event for outgoing process. */ |
629 | |
14963be0 |
630 | DrawContext *draw_context_out = hashed_process_data_out->draw_context; |
68997a22 |
631 | //draw_context_out->current->modify_over->x = x; |
632 | draw_context_out->current->modify_over->y = y_out; |
501d5405 |
633 | draw_context_out->drawable = control_flow_data->drawing->pixmap; |
634 | draw_context_out->pango_layout = control_flow_data->drawing->pango_layout; |
635 | GtkWidget *widget = control_flow_data->drawing->drawing_area; |
a56a1ba4 |
636 | //draw_context_out->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)]; |
637 | draw_context_out->gc = widget->style->black_gc; |
638 | |
639 | //draw_arc((void*)&prop_arc, (void*)draw_context_out); |
501d5405 |
640 | //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap); |
a56a1ba4 |
641 | |
642 | GdkColor colorfg_out = { 0, 0xffff, 0x0000, 0x0000 }; |
643 | GdkColor colorbg_out = { 0, 0xffff, 0xffff, 0xffff }; |
644 | PropertiesText prop_text_out; |
645 | prop_text_out.foreground = &colorfg_out; |
646 | prop_text_out.background = &colorbg_out; |
647 | prop_text_out.size = 10; |
648 | prop_text_out.position = OVER; |
649 | |
650 | /* Print status of the process : U, WF, WC, E, W, R */ |
651 | if(process_out->state->s == LTTV_STATE_UNNAMED) |
68997a22 |
652 | prop_text_out.text = "U"; |
a56a1ba4 |
653 | else if(process_out->state->s == LTTV_STATE_WAIT_FORK) |
68997a22 |
654 | prop_text_out.text = "WF"; |
a56a1ba4 |
655 | else if(process_out->state->s == LTTV_STATE_WAIT_CPU) |
68997a22 |
656 | prop_text_out.text = "WC"; |
a56a1ba4 |
657 | else if(process_out->state->s == LTTV_STATE_EXIT) |
68997a22 |
658 | prop_text_out.text = "E"; |
a56a1ba4 |
659 | else if(process_out->state->s == LTTV_STATE_WAIT) |
68997a22 |
660 | prop_text_out.text = "W"; |
a56a1ba4 |
661 | else if(process_out->state->s == LTTV_STATE_RUN) |
68997a22 |
662 | prop_text_out.text = "R"; |
a56a1ba4 |
663 | else |
68997a22 |
664 | prop_text_out.text = "U"; |
a56a1ba4 |
665 | |
666 | draw_text((void*)&prop_text_out, (void*)draw_context_out); |
667 | |
68997a22 |
668 | draw_context_out->current->middle->y = y_out+height/2; |
669 | draw_context_out->current->status = process_out->state->s; |
a56a1ba4 |
670 | |
68997a22 |
671 | /* for pid_out : remove previous, Prev = current, new current (default) */ |
672 | g_free(draw_context_out->previous->modify_under); |
673 | g_free(draw_context_out->previous->modify_middle); |
674 | g_free(draw_context_out->previous->modify_over); |
675 | g_free(draw_context_out->previous->under); |
676 | g_free(draw_context_out->previous->middle); |
677 | g_free(draw_context_out->previous->over); |
678 | g_free(draw_context_out->previous); |
679 | |
680 | draw_context_out->previous = draw_context_out->current; |
a56a1ba4 |
681 | |
68997a22 |
682 | draw_context_out->current = g_new(DrawInfo,1); |
683 | draw_context_out->current->over = g_new(ItemInfo,1); |
684 | draw_context_out->current->over->x = -1; |
685 | draw_context_out->current->over->y = -1; |
686 | draw_context_out->current->middle = g_new(ItemInfo,1); |
687 | draw_context_out->current->middle->x = -1; |
688 | draw_context_out->current->middle->y = -1; |
689 | draw_context_out->current->under = g_new(ItemInfo,1); |
690 | draw_context_out->current->under->x = -1; |
691 | draw_context_out->current->under->y = -1; |
692 | draw_context_out->current->modify_over = g_new(ItemInfo,1); |
693 | draw_context_out->current->modify_over->x = -1; |
694 | draw_context_out->current->modify_over->y = -1; |
695 | draw_context_out->current->modify_middle = g_new(ItemInfo,1); |
696 | draw_context_out->current->modify_middle->x = -1; |
697 | draw_context_out->current->modify_middle->y = -1; |
698 | draw_context_out->current->modify_under = g_new(ItemInfo,1); |
699 | draw_context_out->current->modify_under->x = -1; |
700 | draw_context_out->current->modify_under->y = -1; |
701 | draw_context_out->current->status = LTTV_STATE_UNNAMED; |
a56a1ba4 |
702 | |
703 | /* Finally, update the drawing context of the pid_in. */ |
704 | |
14963be0 |
705 | DrawContext *draw_context_in = hashed_process_data_in->draw_context; |
68997a22 |
706 | //draw_context_in->current->modify_over->x = x; |
707 | draw_context_in->current->modify_over->y = y_in; |
501d5405 |
708 | draw_context_in->drawable = control_flow_data->drawing->pixmap; |
709 | draw_context_in->pango_layout = control_flow_data->drawing->pango_layout; |
710 | widget = control_flow_data->drawing->drawing_area; |
a56a1ba4 |
711 | //draw_context_in->gc = widget->style->fg_gc[GTK_WIDGET_STATE (widget)]; |
712 | draw_context_in->gc = widget->style->black_gc; |
713 | |
714 | //draw_arc((void*)&prop_arc, (void*)draw_context_in); |
501d5405 |
715 | //test_draw_item(control_flow_data->drawing, control_flow_data->drawing->pixmap); |
a56a1ba4 |
716 | |
717 | GdkColor colorfg_in = { 0, 0x0000, 0xffff, 0x0000 }; |
718 | GdkColor colorbg_in = { 0, 0xffff, 0xffff, 0xffff }; |
719 | PropertiesText prop_text_in; |
720 | prop_text_in.foreground = &colorfg_in; |
721 | prop_text_in.background = &colorbg_in; |
722 | prop_text_in.size = 10; |
723 | prop_text_in.position = OVER; |
724 | |
725 | /* Print status of the process : U, WF, WC, E, W, R */ |
726 | if(process_in->state->s == LTTV_STATE_UNNAMED) |
68997a22 |
727 | prop_text_in.text = "U"; |
a56a1ba4 |
728 | else if(process_in->state->s == LTTV_STATE_WAIT_FORK) |
68997a22 |
729 | prop_text_in.text = "WF"; |
a56a1ba4 |
730 | else if(process_in->state->s == LTTV_STATE_WAIT_CPU) |
68997a22 |
731 | prop_text_in.text = "WC"; |
a56a1ba4 |
732 | else if(process_in->state->s == LTTV_STATE_EXIT) |
68997a22 |
733 | prop_text_in.text = "E"; |
a56a1ba4 |
734 | else if(process_in->state->s == LTTV_STATE_WAIT) |
68997a22 |
735 | prop_text_in.text = "W"; |
a56a1ba4 |
736 | else if(process_in->state->s == LTTV_STATE_RUN) |
68997a22 |
737 | prop_text_in.text = "R"; |
a56a1ba4 |
738 | else |
68997a22 |
739 | prop_text_in.text = "U"; |
a56a1ba4 |
740 | |
741 | draw_text((void*)&prop_text_in, (void*)draw_context_in); |
742 | |
68997a22 |
743 | draw_context_in->current->middle->y = y_in+height/2; |
744 | draw_context_in->current->status = process_in->state->s; |
745 | |
746 | /* for pid_in : remove previous, Prev = current, new current (default) */ |
747 | g_free(draw_context_in->previous->modify_under); |
748 | g_free(draw_context_in->previous->modify_middle); |
749 | g_free(draw_context_in->previous->modify_over); |
750 | g_free(draw_context_in->previous->under); |
751 | g_free(draw_context_in->previous->middle); |
752 | g_free(draw_context_in->previous->over); |
753 | g_free(draw_context_in->previous); |
754 | |
755 | draw_context_in->previous = draw_context_in->current; |
a56a1ba4 |
756 | |
68997a22 |
757 | draw_context_in->current = g_new(DrawInfo,1); |
758 | draw_context_in->current->over = g_new(ItemInfo,1); |
759 | draw_context_in->current->over->x = -1; |
760 | draw_context_in->current->over->y = -1; |
761 | draw_context_in->current->middle = g_new(ItemInfo,1); |
762 | draw_context_in->current->middle->x = -1; |
763 | draw_context_in->current->middle->y = -1; |
764 | draw_context_in->current->under = g_new(ItemInfo,1); |
765 | draw_context_in->current->under->x = -1; |
766 | draw_context_in->current->under->y = -1; |
767 | draw_context_in->current->modify_over = g_new(ItemInfo,1); |
768 | draw_context_in->current->modify_over->x = -1; |
769 | draw_context_in->current->modify_over->y = -1; |
770 | draw_context_in->current->modify_middle = g_new(ItemInfo,1); |
771 | draw_context_in->current->modify_middle->x = -1; |
772 | draw_context_in->current->modify_middle->y = -1; |
773 | draw_context_in->current->modify_under = g_new(ItemInfo,1); |
774 | draw_context_in->current->modify_under->x = -1; |
775 | draw_context_in->current->modify_under->y = -1; |
776 | draw_context_in->current->status = LTTV_STATE_UNNAMED; |
a56a1ba4 |
777 | |
778 | } |
779 | |
780 | return 0; |
f0d936c0 |
781 | } |
f7afe191 |
782 | |
783 | |
784 | |
785 | |
1b238973 |
786 | gint update_time_window_hook(void *hook_data, void *call_data) |
f7afe191 |
787 | { |
a56a1ba4 |
788 | ControlFlowData *control_flow_data = (ControlFlowData*) hook_data; |
14963be0 |
789 | TimeWindow *old_time_window = |
a56a1ba4 |
790 | guicontrolflow_get_time_window(control_flow_data); |
14963be0 |
791 | TimeWindow *new_time_window = ((TimeWindow*)call_data); |
a56a1ba4 |
792 | |
793 | /* Two cases : zoom in/out or scrolling */ |
794 | |
795 | /* In order to make sure we can reuse the old drawing, the scale must |
796 | * be the same and the new time interval being partly located in the |
797 | * currently shown time interval. (reuse is only for scrolling) |
798 | */ |
799 | |
800 | g_info("Old time window HOOK : %u, %u to %u, %u", |
14963be0 |
801 | old_time_window->start_time.tv_sec, |
802 | old_time_window->start_time.tv_nsec, |
803 | old_time_window->time_width.tv_sec, |
804 | old_time_window->time_width.tv_nsec); |
a56a1ba4 |
805 | |
806 | g_info("New time window HOOK : %u, %u to %u, %u", |
14963be0 |
807 | new_time_window->start_time.tv_sec, |
808 | new_time_window->start_time.tv_nsec, |
809 | new_time_window->time_width.tv_sec, |
810 | new_time_window->time_width.tv_nsec); |
a56a1ba4 |
811 | |
14963be0 |
812 | if( new_time_window->time_width.tv_sec == old_time_window->time_width.tv_sec |
813 | && new_time_window->time_width.tv_nsec == old_time_window->time_width.tv_nsec) |
a56a1ba4 |
814 | { |
815 | /* Same scale (scrolling) */ |
816 | g_info("scrolling"); |
14963be0 |
817 | LttTime *ns = &new_time_window->start_time; |
818 | LttTime *os = &old_time_window->start_time; |
819 | LttTime old_end = ltt_time_add(old_time_window->start_time, |
820 | old_time_window->time_width); |
821 | LttTime new_end = ltt_time_add(new_time_window->start_time, |
822 | new_time_window->time_width); |
a56a1ba4 |
823 | //if(ns<os+w<ns+w) |
824 | //if(ns<os+w && os+w<ns+w) |
825 | //if(ns<old_end && os<ns) |
826 | if(ltt_time_compare(*ns, old_end) == -1 |
827 | && ltt_time_compare(*os, *ns) == -1) |
828 | { |
829 | g_info("scrolling near right"); |
830 | /* Scroll right, keep right part of the screen */ |
831 | guint x = 0; |
501d5405 |
832 | guint width = control_flow_data->drawing->drawing_area->allocation.width; |
a56a1ba4 |
833 | convert_time_to_pixels( |
834 | *os, |
835 | old_end, |
836 | *ns, |
837 | width, |
838 | &x); |
839 | |
840 | /* Copy old data to new location */ |
501d5405 |
841 | gdk_draw_drawable (control_flow_data->drawing->pixmap, |
842 | control_flow_data->drawing->drawing_area->style->white_gc, |
843 | control_flow_data->drawing->pixmap, |
a56a1ba4 |
844 | x, 0, |
845 | 0, 0, |
846 | -1, -1); |
847 | |
848 | convert_time_to_pixels( |
849 | *ns, |
850 | new_end, |
851 | old_end, |
852 | width, |
853 | &x); |
854 | |
14963be0 |
855 | *old_time_window = *new_time_window; |
a56a1ba4 |
856 | /* Clear the data request background, but not SAFETY */ |
501d5405 |
857 | gdk_draw_rectangle (control_flow_data->drawing->pixmap, |
858 | control_flow_data->drawing->drawing_area->style->white_gc, |
a56a1ba4 |
859 | TRUE, |
860 | x+SAFETY, 0, |
501d5405 |
861 | control_flow_data->drawing->width - x, // do not overlap |
862 | control_flow_data->drawing->height+SAFETY); |
a56a1ba4 |
863 | /* Get new data for the rest. */ |
501d5405 |
864 | drawing_data_request(control_flow_data->drawing, |
865 | &control_flow_data->drawing->pixmap, |
a56a1ba4 |
866 | x, 0, |
501d5405 |
867 | control_flow_data->drawing->width - x, |
868 | control_flow_data->drawing->height); |
a56a1ba4 |
869 | |
501d5405 |
870 | drawing_refresh(control_flow_data->drawing, |
a56a1ba4 |
871 | 0, 0, |
501d5405 |
872 | control_flow_data->drawing->width, |
873 | control_flow_data->drawing->height); |
a56a1ba4 |
874 | |
875 | |
876 | } else { |
877 | //if(ns<os<ns+w) |
878 | //if(ns<os && os<ns+w) |
879 | //if(ns<os && os<new_end) |
880 | if(ltt_time_compare(*ns,*os) == -1 |
881 | && ltt_time_compare(*os,new_end) == -1) |
882 | { |
883 | g_info("scrolling near left"); |
884 | /* Scroll left, keep left part of the screen */ |
885 | guint x = 0; |
501d5405 |
886 | guint width = control_flow_data->drawing->drawing_area->allocation.width; |
a56a1ba4 |
887 | convert_time_to_pixels( |
888 | *ns, |
889 | new_end, |
890 | *os, |
891 | width, |
892 | &x); |
893 | |
894 | /* Copy old data to new location */ |
501d5405 |
895 | gdk_draw_drawable (control_flow_data->drawing->pixmap, |
896 | control_flow_data->drawing->drawing_area->style->white_gc, |
897 | control_flow_data->drawing->pixmap, |
a56a1ba4 |
898 | 0, 0, |
899 | x, 0, |
900 | -1, -1); |
901 | |
14963be0 |
902 | *old_time_window = *new_time_window; |
a56a1ba4 |
903 | |
904 | /* Clean the data request background */ |
501d5405 |
905 | gdk_draw_rectangle (control_flow_data->drawing->pixmap, |
906 | control_flow_data->drawing->drawing_area->style->white_gc, |
a56a1ba4 |
907 | TRUE, |
908 | 0, 0, |
909 | x, // do not overlap |
501d5405 |
910 | control_flow_data->drawing->height+SAFETY); |
a56a1ba4 |
911 | /* Get new data for the rest. */ |
501d5405 |
912 | drawing_data_request(control_flow_data->drawing, |
913 | &control_flow_data->drawing->pixmap, |
a56a1ba4 |
914 | 0, 0, |
915 | x, |
501d5405 |
916 | control_flow_data->drawing->height); |
a56a1ba4 |
917 | |
501d5405 |
918 | drawing_refresh(control_flow_data->drawing, |
a56a1ba4 |
919 | 0, 0, |
501d5405 |
920 | control_flow_data->drawing->width, |
921 | control_flow_data->drawing->height); |
a56a1ba4 |
922 | |
923 | } else { |
924 | g_info("scrolling far"); |
925 | /* Cannot reuse any part of the screen : far jump */ |
14963be0 |
926 | *old_time_window = *new_time_window; |
a56a1ba4 |
927 | |
928 | |
501d5405 |
929 | gdk_draw_rectangle (control_flow_data->drawing->pixmap, |
930 | control_flow_data->drawing->drawing_area->style->white_gc, |
a56a1ba4 |
931 | TRUE, |
932 | 0, 0, |
501d5405 |
933 | control_flow_data->drawing->width+SAFETY, // do not overlap |
934 | control_flow_data->drawing->height+SAFETY); |
a56a1ba4 |
935 | |
501d5405 |
936 | drawing_data_request(control_flow_data->drawing, |
937 | &control_flow_data->drawing->pixmap, |
a56a1ba4 |
938 | 0, 0, |
501d5405 |
939 | control_flow_data->drawing->width, |
940 | control_flow_data->drawing->height); |
a56a1ba4 |
941 | |
501d5405 |
942 | drawing_refresh(control_flow_data->drawing, |
a56a1ba4 |
943 | 0, 0, |
501d5405 |
944 | control_flow_data->drawing->width, |
945 | control_flow_data->drawing->height); |
a56a1ba4 |
946 | } |
947 | } |
948 | } else { |
949 | /* Different scale (zoom) */ |
950 | g_info("zoom"); |
951 | |
14963be0 |
952 | *old_time_window = *new_time_window; |
a56a1ba4 |
953 | |
501d5405 |
954 | gdk_draw_rectangle (control_flow_data->drawing->pixmap, |
955 | control_flow_data->drawing->drawing_area->style->white_gc, |
a56a1ba4 |
956 | TRUE, |
957 | 0, 0, |
501d5405 |
958 | control_flow_data->drawing->width+SAFETY, // do not overlap |
959 | control_flow_data->drawing->height+SAFETY); |
a56a1ba4 |
960 | |
961 | |
501d5405 |
962 | drawing_data_request(control_flow_data->drawing, |
963 | &control_flow_data->drawing->pixmap, |
a56a1ba4 |
964 | 0, 0, |
501d5405 |
965 | control_flow_data->drawing->width, |
966 | control_flow_data->drawing->height); |
a56a1ba4 |
967 | |
501d5405 |
968 | drawing_refresh(control_flow_data->drawing, |
a56a1ba4 |
969 | 0, 0, |
501d5405 |
970 | control_flow_data->drawing->width, |
971 | control_flow_data->drawing->height); |
a56a1ba4 |
972 | } |
973 | |
974 | return 0; |
f7afe191 |
975 | } |
976 | |
1b238973 |
977 | gint update_current_time_hook(void *hook_data, void *call_data) |
f7afe191 |
978 | { |
14963be0 |
979 | ControlFlowData *control_flow_data = (ControlFlowData*)hook_data; |
a56a1ba4 |
980 | |
981 | LttTime* current_time = |
982 | guicontrolflow_get_current_time(control_flow_data); |
983 | *current_time = *((LttTime*)call_data); |
984 | |
985 | TimeWindow time_window; |
986 | |
ba90bc77 |
987 | LttTime time_begin = control_flow_data->time_window.start_time; |
988 | LttTime width = control_flow_data->time_window.time_width; |
a56a1ba4 |
989 | LttTime half_width = ltt_time_div(width,2.0); |
990 | LttTime time_end = ltt_time_add(time_begin, width); |
991 | |
992 | LttvTracesetContext * tsc = |
ba90bc77 |
993 | get_traceset_context(control_flow_data->mw); |
a56a1ba4 |
994 | |
995 | LttTime trace_start = tsc->Time_Span->startTime; |
996 | LttTime trace_end = tsc->Time_Span->endTime; |
997 | |
68997a22 |
998 | g_info("New current time HOOK : %u, %u", current_time->tv_sec, |
a56a1ba4 |
999 | current_time->tv_nsec); |
1000 | |
1001 | |
1002 | |
1003 | /* If current time is inside time interval, just move the highlight |
1004 | * bar */ |
1005 | |
1006 | /* Else, we have to change the time interval. We have to tell it |
1007 | * to the main window. */ |
1008 | /* The time interval change will take care of placing the current |
1009 | * time at the center of the visible area, or nearest possible if we are |
1010 | * at one end of the trace. */ |
1011 | |
1012 | |
1013 | if(ltt_time_compare(*current_time, time_begin) == -1) |
1014 | { |
1015 | if(ltt_time_compare(*current_time, |
1016 | ltt_time_add(trace_start,half_width)) == -1) |
1017 | time_begin = trace_start; |
1018 | else |
1019 | time_begin = ltt_time_sub(*current_time,half_width); |
1020 | |
1021 | time_window.start_time = time_begin; |
1022 | time_window.time_width = width; |
1023 | |
ba90bc77 |
1024 | set_time_window(control_flow_data->mw, &time_window); |
a56a1ba4 |
1025 | } |
1026 | else if(ltt_time_compare(*current_time, time_end) == 1) |
1027 | { |
1028 | if(ltt_time_compare(*current_time, ltt_time_sub(trace_end, half_width)) == 1) |
1029 | time_begin = ltt_time_sub(trace_end,width); |
1030 | else |
1031 | time_begin = ltt_time_sub(*current_time,half_width); |
1032 | |
1033 | time_window.start_time = time_begin; |
1034 | time_window.time_width = width; |
1035 | |
ba90bc77 |
1036 | set_time_window(control_flow_data->mw, &time_window); |
a56a1ba4 |
1037 | |
1038 | } |
501d5405 |
1039 | gtk_widget_queue_draw(control_flow_data->drawing->drawing_area); |
a56a1ba4 |
1040 | |
1041 | return 0; |
f7afe191 |
1042 | } |
1043 | |
8b90e648 |
1044 | typedef struct _ClosureData { |
a56a1ba4 |
1045 | EventRequest *event_request; |
1046 | LttvTraceState *ts; |
8b90e648 |
1047 | } ClosureData; |
a56a1ba4 |
1048 | |
8b90e648 |
1049 | |
1050 | void draw_closure(gpointer key, gpointer value, gpointer user_data) |
1051 | { |
a56a1ba4 |
1052 | ProcessInfo *process_info = (ProcessInfo*)key; |
1053 | HashedProcessData *hashed_process_data = (HashedProcessData*)value; |
1054 | ClosureData *closure_data = (ClosureData*)user_data; |
1055 | |
1056 | ControlFlowData *control_flow_data = |
68997a22 |
1057 | closure_data->event_request->control_flow_data; |
a56a1ba4 |
1058 | |
501d5405 |
1059 | GtkWidget *widget = control_flow_data->drawing->drawing_area; |
a56a1ba4 |
1060 | |
1061 | /* Get y position of process */ |
1062 | gint y=0, height=0; |
1063 | |
ba90bc77 |
1064 | processlist_get_pixels_from_data( control_flow_data->process_list, |
a56a1ba4 |
1065 | process_info, |
1066 | hashed_process_data, |
1067 | &y, |
1068 | &height); |
1069 | /* Get last state of process */ |
1070 | LttvTraceContext *tc = |
1071 | (LttvTraceContext *)closure_data->ts; |
8b90e648 |
1072 | |
1073 | LttvTraceState *ts = closure_data->ts; |
a56a1ba4 |
1074 | LttvProcessState *process; |
1075 | |
1076 | process = lttv_state_find_process((LttvTracefileState*)ts, process_info->pid); |
1077 | |
1078 | /* Draw the closing line */ |
1079 | DrawContext *draw_context = hashed_process_data->draw_context; |
68997a22 |
1080 | if(draw_context->previous->middle->x == -1) |
a56a1ba4 |
1081 | { |
68997a22 |
1082 | draw_context->previous->middle->x = closure_data->event_request->x_begin; |
a56a1ba4 |
1083 | g_critical("out middle x_beg : %u",closure_data->event_request->x_begin); |
1084 | } |
1085 | |
68997a22 |
1086 | draw_context->current->middle->x = closure_data->event_request->x_end; |
1087 | draw_context->current->middle->y = y + height/2; |
1088 | draw_context->previous->middle->y = y + height/2; |
501d5405 |
1089 | draw_context->drawable = control_flow_data->drawing->pixmap; |
1090 | draw_context->pango_layout = control_flow_data->drawing->pango_layout; |
a56a1ba4 |
1091 | //draw_context->gc = widget->style->black_gc; |
501d5405 |
1092 | draw_context->gc = gdk_gc_new(control_flow_data->drawing->pixmap); |
a56a1ba4 |
1093 | gdk_gc_copy(draw_context->gc, widget->style->black_gc); |
1094 | |
1095 | PropertiesLine prop_line; |
1096 | prop_line.color = g_new(GdkColor,1); |
1097 | prop_line.line_width = 6; |
1098 | prop_line.style = GDK_LINE_SOLID; |
1099 | prop_line.position = MIDDLE; |
1100 | |
1101 | /* color of line : status of the process */ |
1102 | if(process->state->s == LTTV_STATE_UNNAMED) |
1103 | { |
1104 | prop_line.color->red = 0x0000; |
1105 | prop_line.color->green = 0x0000; |
1106 | prop_line.color->blue = 0x0000; |
1107 | } |
1108 | else if(process->state->s == LTTV_STATE_WAIT_FORK) |
1109 | { |
1110 | prop_line.color->red = 0x0fff; |
1111 | prop_line.color->green = 0x0000; |
1112 | prop_line.color->blue = 0x0fff; |
1113 | } |
1114 | else if(process->state->s == LTTV_STATE_WAIT_CPU) |
1115 | { |
1116 | prop_line.color->red = 0x0fff; |
1117 | prop_line.color->green = 0x0fff; |
1118 | prop_line.color->blue = 0x0000; |
1119 | } |
1120 | else if(process->state->s == LTTV_STATE_EXIT) |
1121 | { |
1122 | prop_line.color->red = 0xffff; |
1123 | prop_line.color->green = 0x0000; |
1124 | prop_line.color->blue = 0xffff; |
1125 | } |
1126 | else if(process->state->s == LTTV_STATE_WAIT) |
1127 | { |
1128 | prop_line.color->red = 0xffff; |
1129 | prop_line.color->green = 0x0000; |
1130 | prop_line.color->blue = 0x0000; |
1131 | } |
1132 | else if(process->state->s == LTTV_STATE_RUN) |
1133 | { |
1134 | prop_line.color->red = 0x0000; |
1135 | prop_line.color->green = 0xffff; |
1136 | prop_line.color->blue = 0x0000; |
1137 | } |
1138 | else |
1139 | { |
1140 | prop_line.color->red = 0x0000; |
1141 | prop_line.color->green = 0x0000; |
1142 | prop_line.color->blue = 0x0000; |
1143 | } |
1144 | |
1145 | draw_line((void*)&prop_line, (void*)draw_context); |
1146 | g_free(prop_line.color); |
1147 | gdk_gc_unref(draw_context->gc); |
1148 | |
1149 | /* Reset draw_context of the process for next request */ |
1150 | |
1151 | hashed_process_data->draw_context->drawable = NULL; |
1152 | hashed_process_data->draw_context->gc = NULL; |
1153 | hashed_process_data->draw_context->pango_layout = NULL; |
68997a22 |
1154 | hashed_process_data->draw_context->current->over->x = -1; |
1155 | hashed_process_data->draw_context->current->over->y = -1; |
1156 | hashed_process_data->draw_context->current->middle->x = -1; |
1157 | hashed_process_data->draw_context->current->middle->y = -1; |
1158 | hashed_process_data->draw_context->current->under->x = -1; |
1159 | hashed_process_data->draw_context->current->under->y = -1; |
1160 | hashed_process_data->draw_context->current->modify_over->x = -1; |
1161 | hashed_process_data->draw_context->current->modify_over->y = -1; |
1162 | hashed_process_data->draw_context->current->modify_middle->x = -1; |
1163 | hashed_process_data->draw_context->current->modify_middle->y = -1; |
1164 | hashed_process_data->draw_context->current->modify_under->x = -1; |
1165 | hashed_process_data->draw_context->current->modify_under->y = -1; |
1166 | hashed_process_data->draw_context->current->status = LTTV_STATE_UNNAMED; |
1167 | hashed_process_data->draw_context->previous->over->x = -1; |
1168 | hashed_process_data->draw_context->previous->over->y = -1; |
1169 | hashed_process_data->draw_context->previous->middle->x = -1; |
1170 | hashed_process_data->draw_context->previous->middle->y = -1; |
1171 | hashed_process_data->draw_context->previous->under->x = -1; |
1172 | hashed_process_data->draw_context->previous->under->y = -1; |
1173 | hashed_process_data->draw_context->previous->modify_over->x = -1; |
1174 | hashed_process_data->draw_context->previous->modify_over->y = -1; |
1175 | hashed_process_data->draw_context->previous->modify_middle->x = -1; |
1176 | hashed_process_data->draw_context->previous->modify_middle->y = -1; |
1177 | hashed_process_data->draw_context->previous->modify_under->x = -1; |
1178 | hashed_process_data->draw_context->previous->modify_under->y = -1; |
1179 | hashed_process_data->draw_context->previous->status = LTTV_STATE_UNNAMED; |
a56a1ba4 |
1180 | |
8b90e648 |
1181 | |
1182 | } |
1183 | |
1184 | /* |
1185 | * for each process |
a56a1ba4 |
1186 | * draw closing line |
1187 | * new default prev and current |
8b90e648 |
1188 | */ |
1189 | int after_data_request(void *hook_data, void *call_data) |
1190 | { |
14963be0 |
1191 | EventRequest *event_request = (EventRequest*)hook_data; |
1192 | ControlFlowData *control_flow_data = event_request->control_flow_data; |
a56a1ba4 |
1193 | |
1194 | ProcessList *process_list = |
14963be0 |
1195 | guicontrolflow_get_process_list(event_request->control_flow_data); |
a56a1ba4 |
1196 | |
1197 | ClosureData closure_data; |
1198 | closure_data.event_request = (EventRequest*)hook_data; |
1199 | closure_data.ts = (LttvTraceState*)call_data; |
1200 | |
14963be0 |
1201 | g_hash_table_foreach(process_list->process_hash, draw_closure, |
a56a1ba4 |
1202 | (void*)&closure_data); |
1203 | |
8b90e648 |
1204 | } |
1205 | |