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