| 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 | |
| 26 | /* NOTE : no drawing data should be sent there, since the drawing widget |
| 27 | * has not been initialized */ |
| 28 | void send_test_drawing(ProcessList *Process_List, |
| 29 | Drawing_t *Drawing, |
| 30 | GdkPixmap *Pixmap, |
| 31 | gint x, gint y, // y not used here? |
| 32 | gint width, |
| 33 | gint height) // height won't be used here ? |
| 34 | { |
| 35 | int i; |
| 36 | ProcessInfo Process_Info = {10000, 12000, 55600}; |
| 37 | //ProcessInfo Process_Info = {156, 14000, 55500}; |
| 38 | GtkTreeRowReference *got_RowRef; |
| 39 | PangoContext *context; |
| 40 | PangoLayout *layout; |
| 41 | PangoFontDescription *FontDesc;// = pango_font_description_new(); |
| 42 | gint Font_Size; |
| 43 | |
| 44 | //icon |
| 45 | GdkBitmap *mask = g_new(GdkBitmap, 1); |
| 46 | GdkPixmap *icon_pixmap = g_new(GdkPixmap, 1); |
| 47 | GdkGC * gc = gdk_gc_new(Pixmap); |
| 48 | |
| 49 | // rectangle |
| 50 | GdkColor color = { 0, 0xffff, 0x0000, 0x0000 }; |
| 51 | |
| 52 | /* Sent text data */ |
| 53 | layout = gtk_widget_create_pango_layout(Drawing->Drawing_Area_V, |
| 54 | NULL); |
| 55 | context = pango_layout_get_context(layout); |
| 56 | FontDesc = pango_context_get_font_description(context); |
| 57 | Font_Size = pango_font_description_get_size(FontDesc); |
| 58 | pango_font_description_set_size(FontDesc, Font_Size-3*PANGO_SCALE); |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | LttTime birth; |
| 64 | birth.tv_sec = 12000; |
| 65 | birth.tv_nsec = 55500; |
| 66 | g_info("we have : x : %u, y : %u, width : %u, height : %u", x, y, width, height); |
| 67 | processlist_get_process_pixels(Process_List, |
| 68 | 1, |
| 69 | &birth, |
| 70 | &y, |
| 71 | &height); |
| 72 | |
| 73 | g_info("we draw : x : %u, y : %u, width : %u, height : %u", x, y, width, height); |
| 74 | drawing_draw_line( |
| 75 | Drawing, Pixmap, x, |
| 76 | y+(height/2), x + width, y+(height/2), |
| 77 | Drawing->Drawing_Area_V->style->black_gc); |
| 78 | |
| 79 | pango_layout_set_text(layout, "Test", -1); |
| 80 | gdk_draw_layout(Pixmap, Drawing->Drawing_Area_V->style->black_gc, |
| 81 | 0, y+height, layout); |
| 82 | |
| 83 | birth.tv_sec = 14000; |
| 84 | birth.tv_nsec = 55500; |
| 85 | |
| 86 | processlist_get_process_pixels(Process_List, |
| 87 | 156, |
| 88 | &birth, |
| 89 | &y, |
| 90 | &height); |
| 91 | |
| 92 | |
| 93 | drawing_draw_line( |
| 94 | Drawing, Pixmap, x, |
| 95 | y+(height/2), x + width, y+(height/2), |
| 96 | Drawing->Drawing_Area_V->style->black_gc); |
| 97 | |
| 98 | |
| 99 | /* Draw icon */ |
| 100 | icon_pixmap = gdk_pixmap_create_from_xpm(Pixmap, &mask, NULL, |
| 101 | // "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/move_message.xpm"); |
| 102 | "/home/compudj/local/share/LinuxTraceToolkit/pixmaps/mini-display.xpm"); |
| 103 | gdk_gc_copy(gc, Drawing->Drawing_Area_V->style->black_gc); |
| 104 | gdk_gc_set_clip_mask(gc, mask); |
| 105 | gdk_draw_drawable(Pixmap, |
| 106 | gc, |
| 107 | icon_pixmap, |
| 108 | 0, 0, 0, 0, -1, -1); |
| 109 | |
| 110 | g_free(icon_pixmap); |
| 111 | g_free(mask); |
| 112 | |
| 113 | g_info("y : %u, height : %u", y, height); |
| 114 | |
| 115 | |
| 116 | |
| 117 | birth.tv_sec = 12000; |
| 118 | birth.tv_nsec = 55700; |
| 119 | |
| 120 | processlist_get_process_pixels(Process_List, |
| 121 | 10, |
| 122 | &birth, |
| 123 | &y, |
| 124 | &height); |
| 125 | |
| 126 | /* Draw rectangle (background color) */ |
| 127 | gdk_gc_copy(gc, Drawing->Drawing_Area_V->style->black_gc); |
| 128 | gdk_gc_set_rgb_fg_color(gc, &color); |
| 129 | gdk_draw_rectangle(Pixmap, gc, |
| 130 | TRUE, |
| 131 | x, y, width, height); |
| 132 | |
| 133 | drawing_draw_line( |
| 134 | Drawing, Pixmap, x, |
| 135 | y+(height/2), x + width, y+(height/2), |
| 136 | Drawing->Drawing_Area_V->style->black_gc); |
| 137 | |
| 138 | |
| 139 | /* Draw arc */ |
| 140 | gdk_draw_arc(Pixmap, Drawing->Drawing_Area_V->style->black_gc, |
| 141 | TRUE, 100, y, 5, 5, 0, 360*64); |
| 142 | |
| 143 | g_info("y : %u, height : %u", y, height); |
| 144 | |
| 145 | for(i=0; i<10; i++) |
| 146 | { |
| 147 | birth.tv_sec = i*12000; |
| 148 | birth.tv_nsec = i*55700; |
| 149 | |
| 150 | processlist_get_process_pixels(Process_List, |
| 151 | i, |
| 152 | &birth, |
| 153 | &y, |
| 154 | &height); |
| 155 | |
| 156 | |
| 157 | drawing_draw_line( |
| 158 | Drawing, Pixmap, x, |
| 159 | y+(height/2), x + width, y+(height/2), |
| 160 | Drawing->Drawing_Area_V->style->black_gc); |
| 161 | |
| 162 | g_critical("y : %u, height : %u", y, height); |
| 163 | |
| 164 | } |
| 165 | |
| 166 | birth.tv_sec = 12000; |
| 167 | birth.tv_nsec = 55600; |
| 168 | |
| 169 | processlist_get_process_pixels(Process_List, |
| 170 | 10, |
| 171 | &birth, |
| 172 | &y, |
| 173 | &height); |
| 174 | |
| 175 | |
| 176 | drawing_draw_line( |
| 177 | Drawing, Pixmap, x, |
| 178 | y+(height/2), x + width, y+(height/2), |
| 179 | Drawing->Drawing_Area_V->style->black_gc); |
| 180 | |
| 181 | g_info("y : %u, height : %u", y, height); |
| 182 | |
| 183 | |
| 184 | pango_font_description_set_size(FontDesc, Font_Size); |
| 185 | g_free(gc); |
| 186 | g_free(layout); |
| 187 | //g_free(context); |
| 188 | } |
| 189 | |
| 190 | void send_test_process(ProcessList *Process_List, Drawing_t *Drawing) |
| 191 | { |
| 192 | guint height, y; |
| 193 | int i; |
| 194 | ProcessInfo Process_Info = {10000, 12000, 55600}; |
| 195 | //ProcessInfo Process_Info = {156, 14000, 55500}; |
| 196 | GtkTreeRowReference *got_RowRef; |
| 197 | |
| 198 | LttTime birth; |
| 199 | |
| 200 | if(Process_List->Test_Process_Sent) return; |
| 201 | |
| 202 | birth.tv_sec = 12000; |
| 203 | birth.tv_nsec = 55500; |
| 204 | |
| 205 | processlist_add(Process_List, |
| 206 | 1, |
| 207 | &birth, |
| 208 | &y); |
| 209 | processlist_get_process_pixels(Process_List, |
| 210 | 1, |
| 211 | &birth, |
| 212 | &y, |
| 213 | &height); |
| 214 | drawing_insert_square( Drawing, y, height); |
| 215 | |
| 216 | //g_critical("y : %u, height : %u", y, height); |
| 217 | |
| 218 | birth.tv_sec = 14000; |
| 219 | birth.tv_nsec = 55500; |
| 220 | |
| 221 | processlist_add(Process_List, |
| 222 | 156, |
| 223 | &birth, |
| 224 | &y); |
| 225 | processlist_get_process_pixels(Process_List, |
| 226 | 156, |
| 227 | &birth, |
| 228 | &y, |
| 229 | &height); |
| 230 | drawing_insert_square( Drawing, y, height); |
| 231 | |
| 232 | //g_critical("y : %u, height : %u", y, height); |
| 233 | |
| 234 | birth.tv_sec = 12000; |
| 235 | birth.tv_nsec = 55700; |
| 236 | |
| 237 | processlist_add(Process_List, |
| 238 | 10, |
| 239 | &birth, |
| 240 | &height); |
| 241 | processlist_get_process_pixels(Process_List, |
| 242 | 10, |
| 243 | &birth, |
| 244 | &y, |
| 245 | &height); |
| 246 | drawing_insert_square( Drawing, y, height); |
| 247 | |
| 248 | //g_critical("y : %u, height : %u", y, height); |
| 249 | |
| 250 | //drawing_insert_square( Drawing, height, 5); |
| 251 | |
| 252 | for(i=0; i<10; i++) |
| 253 | { |
| 254 | birth.tv_sec = i*12000; |
| 255 | birth.tv_nsec = i*55700; |
| 256 | |
| 257 | processlist_add(Process_List, |
| 258 | i, |
| 259 | &birth, |
| 260 | &height); |
| 261 | processlist_get_process_pixels(Process_List, |
| 262 | i, |
| 263 | &birth, |
| 264 | &y, |
| 265 | &height); |
| 266 | drawing_insert_square( Drawing, y, height); |
| 267 | |
| 268 | // g_critical("y : %u, height : %u", y, height); |
| 269 | |
| 270 | } |
| 271 | //g_critical("height : %u", height); |
| 272 | |
| 273 | birth.tv_sec = 12000; |
| 274 | birth.tv_nsec = 55600; |
| 275 | |
| 276 | processlist_add(Process_List, |
| 277 | 10, |
| 278 | &birth, |
| 279 | &y); |
| 280 | processlist_get_process_pixels(Process_List, |
| 281 | 10, |
| 282 | &birth, |
| 283 | &y, |
| 284 | &height); |
| 285 | drawing_insert_square( Drawing, y, height); |
| 286 | |
| 287 | //g_critical("y : %u, height : %u", y, height); |
| 288 | |
| 289 | processlist_add(Process_List, |
| 290 | 10000, |
| 291 | &birth, |
| 292 | &height); |
| 293 | processlist_get_process_pixels(Process_List, |
| 294 | 10000, |
| 295 | &birth, |
| 296 | &y, |
| 297 | &height); |
| 298 | drawing_insert_square( Drawing, y, height); |
| 299 | |
| 300 | //g_critical("y : %u, height : %u", y, height); |
| 301 | |
| 302 | //drawing_insert_square( Drawing, height, 5); |
| 303 | //g_critical("height : %u", height); |
| 304 | |
| 305 | |
| 306 | processlist_get_process_pixels(Process_List, |
| 307 | 10000, |
| 308 | &birth, |
| 309 | &y, &height); |
| 310 | processlist_remove( Process_List, |
| 311 | 10000, |
| 312 | &birth); |
| 313 | |
| 314 | drawing_remove_square( Drawing, y, height); |
| 315 | |
| 316 | if(got_RowRef = |
| 317 | (GtkTreeRowReference*)g_hash_table_lookup( |
| 318 | Process_List->Process_Hash, |
| 319 | &Process_Info)) |
| 320 | { |
| 321 | g_critical("key found"); |
| 322 | g_critical("position in the list : %s", |
| 323 | gtk_tree_path_to_string ( |
| 324 | gtk_tree_row_reference_get_path( |
| 325 | (GtkTreeRowReference*)got_RowRef) |
| 326 | )); |
| 327 | |
| 328 | } |
| 329 | |
| 330 | Process_List->Test_Process_Sent = TRUE; |
| 331 | |
| 332 | } |
| 333 | |
| 334 | |
| 335 | |
| 336 | /** |
| 337 | * Event Viewer's constructor hook |
| 338 | * |
| 339 | * This constructor is given as a parameter to the menuitem and toolbar button |
| 340 | * registration. It creates the list. |
| 341 | * @param pmParentWindow A pointer to the parent window. |
| 342 | * @return The widget created. |
| 343 | */ |
| 344 | GtkWidget * |
| 345 | h_guicontrolflow(MainWindow *pmParentWindow, LttvTracesetSelector * s, char * key) |
| 346 | { |
| 347 | g_info("h_guicontrolflow, %p, %p, %s", pmParentWindow, s, key); |
| 348 | ControlFlowData *Control_Flow_Data = guicontrolflow() ; |
| 349 | |
| 350 | Control_Flow_Data->Parent_Window = pmParentWindow; |
| 351 | |
| 352 | get_time_window(pmParentWindow, |
| 353 | guicontrolflow_get_time_window(Control_Flow_Data)); |
| 354 | get_current_time(pmParentWindow, |
| 355 | guicontrolflow_get_current_time(Control_Flow_Data)); |
| 356 | |
| 357 | // Unreg done in the GuiControlFlow_Destructor |
| 358 | reg_update_time_window(update_time_window_hook, Control_Flow_Data, |
| 359 | pmParentWindow); |
| 360 | reg_update_current_time(update_current_time_hook, Control_Flow_Data, |
| 361 | pmParentWindow); |
| 362 | return guicontrolflow_get_widget(Control_Flow_Data) ; |
| 363 | |
| 364 | } |
| 365 | |
| 366 | int event_selected_hook(void *hook_data, void *call_data) |
| 367 | { |
| 368 | ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data; |
| 369 | guint *Event_Number = (guint*) call_data; |
| 370 | |
| 371 | g_critical("DEBUG : event selected by main window : %u", *Event_Number); |
| 372 | |
| 373 | // Control_Flow_Data->Currently_Selected_Event = *Event_Number; |
| 374 | // Control_Flow_Data->Selected_Event = TRUE ; |
| 375 | |
| 376 | // tree_v_set_cursor(Control_Flow_Data); |
| 377 | |
| 378 | } |
| 379 | |
| 380 | #ifdef DEBUG |
| 381 | /* Hook called before drawing. Gets the initial context at the beginning of the |
| 382 | * drawing interval and copy it to the context in Event_Request. |
| 383 | */ |
| 384 | int draw_before_hook(void *hook_data, void *call_data) |
| 385 | { |
| 386 | EventRequest *Event_Request = (EventRequest*)hook_data; |
| 387 | EventsContext Events_Context = (EventsContext*)call_data; |
| 388 | |
| 389 | Event_Request->Events_Context = Events_Context; |
| 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | /* |
| 395 | * The draw event hook is called by the reading API to have a |
| 396 | * particular event drawn on the screen. |
| 397 | * @param hook_data ControlFlowData structure of the viewer. |
| 398 | * @param call_data Event context. |
| 399 | * |
| 400 | * This function basically draw lines and icons. Two types of lines are drawn : |
| 401 | * one small (3 pixels?) representing the state of the process and the second |
| 402 | * type is thicker (10 pixels?) representing on which CPU a process is running |
| 403 | * (and this only in running state). |
| 404 | * |
| 405 | * Extremums of the lines : |
| 406 | * x_min : time of the last event context for this process kept in memory. |
| 407 | * x_max : time of the current event. |
| 408 | * y : middle of the process in the process list. The process is found in the |
| 409 | * list, therefore is it's position in pixels. |
| 410 | * |
| 411 | * The choice of lines'color is defined by the context of the last event for this |
| 412 | * process. |
| 413 | */ |
| 414 | int draw_event_hook(void *hook_data, void *call_data) |
| 415 | { |
| 416 | EventRequest *Event_Request = (EventRequest*)hook_data; |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | |
| 422 | int draw_after_hook(void *hook_data, void *call_data) |
| 423 | { |
| 424 | EventRequest *Event_Request = (EventRequest*)hook_data; |
| 425 | |
| 426 | g_free(Event_Request); |
| 427 | return 0; |
| 428 | } |
| 429 | #endif |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | void update_time_window_hook(void *hook_data, void *call_data) |
| 435 | { |
| 436 | ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data; |
| 437 | TimeWindow* Time_Window = |
| 438 | guicontrolflow_get_time_window(Control_Flow_Data); |
| 439 | TimeWindow *New_Time_Window = ((TimeWindow*)call_data); |
| 440 | |
| 441 | // As the time interval change will mostly be used for |
| 442 | // zoom in and out, it's not useful to keep old drawing |
| 443 | // sections, as scale will be changed. |
| 444 | |
| 445 | |
| 446 | *Time_Window = *New_Time_Window; |
| 447 | g_info("New time window HOOK : %u, %u to %u, %u", |
| 448 | Time_Window->start_time.tv_sec, |
| 449 | Time_Window->start_time.tv_nsec, |
| 450 | Time_Window->time_width.tv_sec, |
| 451 | Time_Window->time_width.tv_nsec); |
| 452 | |
| 453 | drawing_data_request(Control_Flow_Data->Drawing, |
| 454 | &Control_Flow_Data->Drawing->Pixmap, |
| 455 | 0, 0, |
| 456 | Control_Flow_Data->Drawing->width, |
| 457 | Control_Flow_Data->Drawing->height); |
| 458 | |
| 459 | drawing_refresh(Control_Flow_Data->Drawing, |
| 460 | 0, 0, |
| 461 | Control_Flow_Data->Drawing->width, |
| 462 | Control_Flow_Data->Drawing->height); |
| 463 | |
| 464 | } |
| 465 | |
| 466 | void update_current_time_hook(void *hook_data, void *call_data) |
| 467 | { |
| 468 | ControlFlowData *Control_Flow_Data = (ControlFlowData*) hook_data; |
| 469 | LttTime* Current_Time = |
| 470 | guicontrolflow_get_current_time(Control_Flow_Data); |
| 471 | *Current_Time = *((LttTime*)call_data); |
| 472 | g_info("New Current time HOOK : %u, %u", Current_Time->tv_sec, |
| 473 | Current_Time->tv_nsec); |
| 474 | |
| 475 | /* If current time is inside time interval, just move the highlight |
| 476 | * bar */ |
| 477 | |
| 478 | /* Else, we have to change the time interval. We have to tell it |
| 479 | * to the main window. */ |
| 480 | /* The time interval change will take care of placing the current |
| 481 | * time at the center of the visible area */ |
| 482 | |
| 483 | } |
| 484 | |