process list pid problem : everything is zero
[lttv.git] / ltt / branches / poly / lttv / modules / guiControlFlow / Event_Hooks.c
1 /*****************************************************************************
2 * Hooks to be called by the main window *
3 *****************************************************************************/
4
5
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
9 //#define PANGO_ENABLE_BACKEND
10 #include <gtk/gtk.h>
11 #include <gdk/gdk.h>
12 #include <glib.h>
13
14 //#include <pango/pango.h>
15
16 #include <lttv/hook.h>
17 #include <lttv/common.h>
18
19 #include "Event_Hooks.h"
20 #include "CFV.h"
21 #include "Process_List.h"
22 #include "Drawing.h"
23 #include "CFV-private.h"
24
25 #define MAX_PATH_LEN 256
26
27 //FIXME : remove this include when tests finished.
28 #include <string.h>
29
30 void test_draw_item(Drawing_t *Drawing,
31 GdkPixmap *Pixmap)
32 {
33 PropertiesIcon properties_icon;
34 DrawContext draw_context;
35
36 DrawInfo current, previous;
37 ItemInfo over, middle, under, modify_over, modify_middle, modify_under;
38
39 int i,j;
40
41 for(i=0; i<1024;i=i+15)
42 {
43 for(j=0;j<768;j=j+15)
44 {
45 over.x = i;
46 over.y = j;
47 over.ts = NULL;
48 over.tfs = NULL;
49
50 current.modify_over = &over;
51
52 draw_context.drawable = Pixmap;
53 draw_context.gc = Drawing->Drawing_Area_V->style->black_gc;
54
55 draw_context.Current = &current;
56 draw_context.Previous = NULL;
57
58 properties_icon.icon_name = g_new(char, MAX_PATH_LEN);
59 strncpy(properties_icon.icon_name,
60 "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm",
61 MAX_PATH_LEN);
62 properties_icon.width = -1;
63 properties_icon.height = -1;
64 properties_icon.position = OVER;
65 draw_icon(&properties_icon, &draw_context);
66 g_free(properties_icon.icon_name);
67 }
68 }
69
70 }
71
72 /* NOTE : no drawing data should be sent there, since the drawing widget
73 * has not been initialized */
74 void send_test_drawing(ProcessList *Process_List,
75 Drawing_t *Drawing,
76 GdkPixmap *Pixmap,
77 gint x, gint y, // y not used here?
78 gint width,
79 gint height) // height won't be used here ?
80 {
81 int i,j;
82 ProcessInfo Process_Info = {10000, 12000, 55600};
83 //ProcessInfo Process_Info = {156, 14000, 55500};
84 GtkTreeRowReference *got_RowRef;
85 PangoContext *context;
86 PangoLayout *layout;
87 PangoFontDescription *FontDesc;// = pango_font_description_new();
88 gint Font_Size;
89
90 //icon
91 //GdkBitmap *mask = g_new(GdkBitmap, 1);
92 //GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1);
93 GdkGC * gc;
94 // rectangle
95 GdkColor color = { 0, 0xffff, 0x0000, 0x0000 };
96
97 gc = gdk_gc_new(Pixmap);
98 /* Sent text data */
99 layout = gtk_widget_create_pango_layout(Drawing->Drawing_Area_V,
100 NULL);
101 context = pango_layout_get_context(layout);
102 FontDesc = pango_context_get_font_description(context);
103 Font_Size = pango_font_description_get_size(FontDesc);
104 pango_font_description_set_size(FontDesc, Font_Size-3*PANGO_SCALE);
105
106
107
108
109 LttTime birth;
110 birth.tv_sec = 12000;
111 birth.tv_nsec = 55500;
112 g_info("we have : x : %u, y : %u, width : %u, height : %u", x, y, width, height);
113 processlist_get_process_pixels(Process_List,
114 1,
115 &birth,
116 &y,
117 &height);
118
119 g_info("we draw : x : %u, y : %u, width : %u, height : %u", x, y, width, height);
120 drawing_draw_line(
121 Drawing, Pixmap, x,
122 y+(height/2), x + width, y+(height/2),
123 Drawing->Drawing_Area_V->style->black_gc);
124
125 pango_layout_set_text(layout, "Test", -1);
126 gdk_draw_layout(Pixmap, Drawing->Drawing_Area_V->style->black_gc,
127 0, y+height, layout);
128
129 birth.tv_sec = 14000;
130 birth.tv_nsec = 55500;
131
132 processlist_get_process_pixels(Process_List,
133 156,
134 &birth,
135 &y,
136 &height);
137
138
139 drawing_draw_line(
140 Drawing, Pixmap, x,
141 y+(height/2), x + width, y+(height/2),
142 Drawing->Drawing_Area_V->style->black_gc);
143
144 g_info("y : %u, height : %u", y, height);
145
146
147
148 birth.tv_sec = 12000;
149 birth.tv_nsec = 55700;
150
151 processlist_get_process_pixels(Process_List,
152 10,
153 &birth,
154 &y,
155 &height);
156
157 /* Draw rectangle (background color) */
158 gdk_gc_copy(gc, Drawing->Drawing_Area_V->style->black_gc);
159 gdk_gc_set_rgb_fg_color(gc, &color);
160 gdk_draw_rectangle(Pixmap, gc,
161 TRUE,
162 x, y, width, height);
163
164 drawing_draw_line(
165 Drawing, Pixmap, x,
166 y+(height/2), x + width, y+(height/2),
167 Drawing->Drawing_Area_V->style->black_gc);
168
169
170 /* Draw arc */
171 gdk_draw_arc(Pixmap, Drawing->Drawing_Area_V->style->black_gc,
172 TRUE, 100, y, height/2, height/2, 0, 360*64);
173
174 g_info("y : %u, height : %u", y, height);
175
176 for(i=0; i<10; i++)
177 {
178 birth.tv_sec = i*12000;
179 birth.tv_nsec = i*55700;
180
181 processlist_get_process_pixels(Process_List,
182 i,
183 &birth,
184 &y,
185 &height);
186
187
188 drawing_draw_line(
189 Drawing, Pixmap, x,
190 y+(height/2), x + width, y+(height/2),
191 Drawing->Drawing_Area_V->style->black_gc);
192
193 g_critical("y : %u, height : %u", y, height);
194
195 }
196
197 birth.tv_sec = 12000;
198 birth.tv_nsec = 55600;
199
200 processlist_get_process_pixels(Process_List,
201 10,
202 &birth,
203 &y,
204 &height);
205
206
207 drawing_draw_line(
208 Drawing, Pixmap, x,
209 y+(height/2), x + width, y+(height/2),
210 Drawing->Drawing_Area_V->style->black_gc);
211
212 g_info("y : %u, height : %u", y, height);
213
214
215 /* IMPORTANT : This action uses the cpu heavily! */
216 //icon_pixmap = gdk_pixmap_create_from_xpm(Pixmap, &mask, NULL,
217 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/move_message.xpm");
218 // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm");
219
220 // gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, mask);
221
222 // for(i=x;i<x+width;i=i+15)
223 // {
224 // for(j=0;j<height*20;j=j+15)
225 // {
226
227 /* Draw icon */
228 //gdk_gc_copy(gc, Drawing->Drawing_Area_V->style->black_gc);
229 // gdk_gc_set_clip_origin(Drawing->Drawing_Area_V->style->black_gc, i, j);
230 // gdk_draw_drawable(Pixmap,
231 // Drawing->Drawing_Area_V->style->black_gc,
232 // icon_pixmap,
233 // 0, 0, i, j, -1, -1);
234
235 // }
236 // }
237
238 test_draw_item(Drawing,Pixmap);
239
240 //gdk_gc_set_clip_origin(Drawing->Drawing_Area_V->style->black_gc, 0, 0);
241 //gdk_gc_set_clip_mask(Drawing->Drawing_Area_V->style->black_gc, NULL);
242
243 //g_free(icon_pixmap);
244 //g_free(mask);
245
246
247
248
249
250
251 pango_font_description_set_size(FontDesc, Font_Size);
252 g_object_unref(layout);
253 g_free(gc);
254 }
255
256 void send_test_process(ProcessList *Process_List, Drawing_t *Drawing)
257 {
258 guint height, y;
259 int i;
260 ProcessInfo Process_Info = {10000, 12000, 55600};
261 //ProcessInfo Process_Info = {156, 14000, 55500};
262 GtkTreeRowReference *got_RowRef;
263
264 LttTime birth;
265
266 if(Process_List->Test_Process_Sent) return;
267
268 birth.tv_sec = 12000;
269 birth.tv_nsec = 55500;
270
271 processlist_add(Process_List,
272 1,
273 &birth,
274 &y);
275 processlist_get_process_pixels(Process_List,
276 1,
277 &birth,
278 &y,
279 &height);
280 drawing_insert_square( Drawing, y, height);
281
282 //g_critical("y : %u, height : %u", y, height);
283
284 birth.tv_sec = 14000;
285 birth.tv_nsec = 55500;
286
287 processlist_add(Process_List,
288 156,
289 &birth,
290 &y);
291 processlist_get_process_pixels(Process_List,
292 156,
293 &birth,
294 &y,
295 &height);
296 drawing_insert_square( Drawing, y, height);
297
298 //g_critical("y : %u, height : %u", y, height);
299
300 birth.tv_sec = 12000;
301 birth.tv_nsec = 55700;
302
303 processlist_add(Process_List,
304 10,
305 &birth,
306 &height);
307 processlist_get_process_pixels(Process_List,
308 10,
309 &birth,
310 &y,
311 &height);
312 drawing_insert_square( Drawing, y, height);
313
314 //g_critical("y : %u, height : %u", y, height);
315
316 //drawing_insert_square( Drawing, height, 5);
317
318 for(i=0; i<10; i++)
319 {
320 birth.tv_sec = i*12000;
321 birth.tv_nsec = i*55700;
322
323 processlist_add(Process_List,
324 i,
325 &birth,
326 &height);
327 processlist_get_process_pixels(Process_List,
328 i,
329 &birth,
330 &y,
331 &height);
332 drawing_insert_square( Drawing, y, height);
333
334 // g_critical("y : %u, height : %u", y, height);
335
336 }
337 //g_critical("height : %u", height);
338
339 birth.tv_sec = 12000;
340 birth.tv_nsec = 55600;
341
342 processlist_add(Process_List,
343 10,
344 &birth,
345 &y);
346 processlist_get_process_pixels(Process_List,
347 10,
348 &birth,
349 &y,
350 &height);
351 drawing_insert_square( Drawing, y, height);
352
353 //g_critical("y : %u, height : %u", y, height);
354
355 processlist_add(Process_List,
356 10000,
357 &birth,
358 &height);
359 processlist_get_process_pixels(Process_List,
360 10000,
361 &birth,
362 &y,
363 &height);
364 drawing_insert_square( Drawing, y, height);
365
366 //g_critical("y : %u, height : %u", y, height);
367
368 //drawing_insert_square( Drawing, height, 5);
369 //g_critical("height : %u", height);
370
371
372 processlist_get_process_pixels(Process_List,
373 10000,
374 &birth,
375 &y, &height);
376 processlist_remove( Process_List,
377 10000,
378 &birth);
379
380 drawing_remove_square( Drawing, y, height);
381
382 if(got_RowRef =
383 (GtkTreeRowReference*)g_hash_table_lookup(
384 Process_List->Process_Hash,
385 &Process_Info))
386 {
387 g_critical("key found");
388 g_critical("position in the list : %s",
389 gtk_tree_path_to_string (
390 gtk_tree_row_reference_get_path(
391 (GtkTreeRowReference*)got_RowRef)
392 ));
393
394 }
395
396 Process_List->Test_Process_Sent = TRUE;
397
398 }
399
400
401
402 /**
403 * Event Viewer's constructor hook
404 *
405 * This constructor is given as a parameter to the menuitem and toolbar button
406 * registration. It creates the list.
407 * @param pmParentWindow A pointer to the parent window.
408 * @return The widget created.
409 */
410 GtkWidget *
411 h_guicontrolflow(MainWindow *pmParentWindow, LttvTracesetSelector * s, char * key)
412 {
413 g_info("h_guicontrolflow, %p, %p, %s", pmParentWindow, s, key);
414 ControlFlowData *Control_Flow_Data = guicontrolflow() ;
415
416 Control_Flow_Data->Parent_Window = pmParentWindow;
417 TimeWindow *time_window = guicontrolflow_get_time_window(Control_Flow_Data);
418 time_window->start_time.tv_sec = 0;
419 time_window->start_time.tv_nsec = 0;
420 time_window->time_width.tv_sec = 0;
421 time_window->time_width.tv_nsec = 0;
422
423 LttTime *current_time = guicontrolflow_get_current_time(Control_Flow_Data);
424 current_time->tv_sec = 0;
425 current_time->tv_nsec = 0;
426
427 //g_critical("time width1 : %u",time_window->time_width);
428
429 get_time_window(pmParentWindow,
430 time_window);
431 get_current_time(pmParentWindow,
432 current_time);
433
434 //g_critical("time width2 : %u",time_window->time_width);
435 // Unreg done in the GuiControlFlow_Destructor
436 reg_update_time_window(update_time_window_hook, Control_Flow_Data,
437 pmParentWindow);
438 reg_update_current_time(update_current_time_hook, Control_Flow_Data,
439 pmParentWindow);
440 return guicontrolflow_get_widget(Control_Flow_Data) ;
441
442 }
443
444 int event_selected_hook(void *hook_data, void *call_data)
445 {
446 ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
447 guint *Event_Number = (guint*) call_data;
448
449 g_critical("DEBUG : event selected by main window : %u", *Event_Number);
450
451 // Control_Flow_Data->Currently_Selected_Event = *Event_Number;
452 // Control_Flow_Data->Selected_Event = TRUE ;
453
454 // tree_v_set_cursor(Control_Flow_Data);
455
456 }
457
458 /* Hook called before drawing. Gets the initial context at the beginning of the
459 * drawing interval and copy it to the context in Event_Request.
460 */
461 int draw_before_hook(void *hook_data, void *call_data)
462 {
463 EventRequest *Event_Request = (EventRequest*)hook_data;
464 //EventsContext Events_Context = (EventsContext*)call_data;
465
466 //Event_Request->Events_Context = Events_Context;
467
468 return 0;
469 }
470
471 /*
472 * The draw event hook is called by the reading API to have a
473 * particular event drawn on the screen.
474 * @param hook_data ControlFlowData structure of the viewer.
475 * @param call_data Event context.
476 *
477 * This function basically draw lines and icons. Two types of lines are drawn :
478 * one small (3 pixels?) representing the state of the process and the second
479 * type is thicker (10 pixels?) representing on which CPU a process is running
480 * (and this only in running state).
481 *
482 * Extremums of the lines :
483 * x_min : time of the last event context for this process kept in memory.
484 * x_max : time of the current event.
485 * y : middle of the process in the process list. The process is found in the
486 * list, therefore is it's position in pixels.
487 *
488 * The choice of lines'color is defined by the context of the last event for this
489 * process.
490 */
491 int draw_event_hook(void *hook_data, void *call_data)
492 {
493 EventRequest *Event_Request = (EventRequest*)hook_data;
494
495 //static int i=0;
496
497 //i++;
498 //g_critical("%i", i);
499
500 /* Text dumping if the information */
501 GString *string = g_string_new("");;
502 gboolean field_names = TRUE, state = TRUE;
503 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
504
505 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
506
507 LttEvent *e;
508
509 e = tfc->e;
510
511 lttv_event_to_string(e, tfc->tf, string, TRUE, field_names, tfs);
512 g_string_append_printf(string,"\n");
513
514 if(state) {
515 g_string_append_printf(string, " %s",
516 g_quark_to_string(tfs->process->state->s));
517 }
518
519 g_info("%s",string->str);
520
521 g_string_free(string, TRUE);
522
523 /* End of text dump */
524
525 /* Add process to process list (if not present) and get drawing "y" from
526 * process position */
527 guint pid = tfs->process->pid;
528 LttTime birth = tfs->process->creation_time;
529 guint y = 0, height = 0;
530 ProcessList *process_list =
531 guicontrolflow_get_process_list(Event_Request->Control_Flow_Data);
532
533 if(processlist_get_process_pixels(process_list,
534 pid,
535 &birth,
536 &y,
537 &height) == 1)
538 {
539 /* Process not present */
540 processlist_add(process_list,
541 pid,
542 &birth,
543 &y);
544 drawing_insert_square( Event_Request->Control_Flow_Data->Drawing, y, height);
545 }
546
547 /* Find pixels corresponding to time of the event. If the time does
548 * not fit in the window, show a warning, not supposed to happend. */
549
550
551 /* Finally, draw what represents the event. */
552
553
554 return 0;
555 }
556
557
558 int draw_after_hook(void *hook_data, void *call_data)
559 {
560 EventRequest *Event_Request = (EventRequest*)hook_data;
561
562 g_free(Event_Request);
563 return 0;
564 }
565
566
567
568
569 void update_time_window_hook(void *hook_data, void *call_data)
570 {
571 ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
572 TimeWindow* Time_Window =
573 guicontrolflow_get_time_window(Control_Flow_Data);
574 TimeWindow *New_Time_Window = ((TimeWindow*)call_data);
575
576 // As the time interval change will mostly be used for
577 // zoom in and out, it's not useful to keep old drawing
578 // sections, as scale will be changed.
579
580
581 *Time_Window = *New_Time_Window;
582 g_info("New time window HOOK : %u, %u to %u, %u",
583 Time_Window->start_time.tv_sec,
584 Time_Window->start_time.tv_nsec,
585 Time_Window->time_width.tv_sec,
586 Time_Window->time_width.tv_nsec);
587
588 drawing_data_request(Control_Flow_Data->Drawing,
589 &Control_Flow_Data->Drawing->Pixmap,
590 0, 0,
591 Control_Flow_Data->Drawing->width,
592 Control_Flow_Data->Drawing->height);
593
594 drawing_refresh(Control_Flow_Data->Drawing,
595 0, 0,
596 Control_Flow_Data->Drawing->width,
597 Control_Flow_Data->Drawing->height);
598
599 }
600
601 void update_current_time_hook(void *hook_data, void *call_data)
602 {
603 ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data;
604 LttTime* Current_Time =
605 guicontrolflow_get_current_time(Control_Flow_Data);
606 *Current_Time = *((LttTime*)call_data);
607 g_info("New Current time HOOK : %u, %u", Current_Time->tv_sec,
608 Current_Time->tv_nsec);
609
610 /* If current time is inside time interval, just move the highlight
611 * bar */
612
613 /* Else, we have to change the time interval. We have to tell it
614 * to the main window. */
615 /* The time interval change will take care of placing the current
616 * time at the center of the visible area */
617
618 }
619
This page took 0.042804 seconds and 4 git commands to generate.