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