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