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