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