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