| 1 | //*! \defgroup GuiEvents libGuiEvents: The GUI Events display plugin */ |
| 2 | /*\@{*/ |
| 3 | |
| 4 | /*! \file GuiEvents.c |
| 5 | * \brief Graphical plugin for showing events. |
| 6 | * |
| 7 | * This plugin lists all the events contained in the current time interval |
| 8 | * in a list. |
| 9 | * |
| 10 | * This plugin adds a Events Viewer functionnality to Linux TraceToolkit |
| 11 | * GUI when this plugin is loaded. The init and destroy functions add the |
| 12 | * viewer's insertion menu item and toolbar icon by calling gtkTraceSet's |
| 13 | * API functions. Then, when a viewer's object is created, the constructor |
| 14 | * creates ans register through API functions what is needed to interact |
| 15 | * with the TraceSet window. |
| 16 | * |
| 17 | * Coding standard : |
| 18 | * pm : parameter |
| 19 | * l : local |
| 20 | * g : global |
| 21 | * s : static |
| 22 | * h : hook |
| 23 | * |
| 24 | * Author : Karim Yaghmour |
| 25 | * Integrated to LTTng by Mathieu Desnoyers, June 2003 |
| 26 | */ |
| 27 | |
| 28 | #include <math.h> |
| 29 | |
| 30 | #include <glib.h> |
| 31 | #include <gmodule.h> |
| 32 | #include <gtk/gtk.h> |
| 33 | #include <gdk/gdk.h> |
| 34 | |
| 35 | #include <lttv/module.h> |
| 36 | #include <lttv/hook.h> |
| 37 | #include <lttv/gtkTraceSet.h> |
| 38 | #include <lttv/processTrace.h> |
| 39 | #include <lttv/state.h> |
| 40 | #include <ltt/ltt.h> |
| 41 | #include <ltt/event.h> |
| 42 | #include <ltt/type.h> |
| 43 | #include <ltt/trace.h> |
| 44 | #include <string.h> |
| 45 | |
| 46 | //#include "mw_api.h" |
| 47 | #include "gtktreeprivate.h" |
| 48 | |
| 49 | #include "icons/hGuiEventsInsert.xpm" |
| 50 | |
| 51 | |
| 52 | static LttvHooks *before_event; |
| 53 | |
| 54 | /** Array containing instanced objects. Used when module is unloaded */ |
| 55 | static GSList *g_event_viewer_data_list = NULL ; |
| 56 | |
| 57 | /** hook functions for update time interval, current time ... */ |
| 58 | gboolean update_time_window(void * hook_data, void * call_data); |
| 59 | gboolean update_current_time(void * hook_data, void * call_data); |
| 60 | void remove_item_from_queue(GQueue * q, gboolean fromHead); |
| 61 | void remove_all_items_from_queue(GQueue * q); |
| 62 | |
| 63 | typedef struct _RawTraceData{ |
| 64 | unsigned cpu_id; |
| 65 | char * event_name; |
| 66 | LttTime time; |
| 67 | int pid; |
| 68 | unsigned entry_length; |
| 69 | char * event_description; |
| 70 | LttEventPosition *ep; |
| 71 | } RawTraceData; |
| 72 | |
| 73 | #define RESERVE_BIG_SIZE 1000 |
| 74 | #define RESERVE_SMALL_SIZE 100 |
| 75 | |
| 76 | typedef enum _ScrollDirection{ |
| 77 | SCROLL_STEP_UP, |
| 78 | SCROLL_STEP_DOWN, |
| 79 | SCROLL_PAGE_UP, |
| 80 | SCROLL_PAGE_DOWN, |
| 81 | SCROLL_JUMP, |
| 82 | SCROLL_NONE |
| 83 | } ScrollDirection; |
| 84 | |
| 85 | typedef struct _EventViewerData { |
| 86 | |
| 87 | MainWindow * mw; |
| 88 | TimeWindow time_window; |
| 89 | LttTime current_time; |
| 90 | LttvHooks * before_event_hooks; |
| 91 | |
| 92 | gboolean append; //prepend or append item |
| 93 | GQueue * raw_trace_data_queue; //buf to contain raw trace data |
| 94 | GQueue * raw_trace_data_queue_tmp; //tmp buf to contain raw data |
| 95 | unsigned current_event_index; |
| 96 | double previous_value; //value of the slide |
| 97 | TimeInterval time_span; |
| 98 | // LttTime trace_start; |
| 99 | // LttTime trace_end; |
| 100 | unsigned start_event_index; //the first event shown in the window |
| 101 | unsigned end_event_index; //the last event shown in the window |
| 102 | |
| 103 | //scroll window containing Tree View |
| 104 | GtkWidget * scroll_win; |
| 105 | |
| 106 | /* Model containing list data */ |
| 107 | GtkListStore *store_m; |
| 108 | |
| 109 | GtkWidget *hbox_v; |
| 110 | /* Widget to display the data in a columned list */ |
| 111 | GtkWidget *tree_v; |
| 112 | GtkAdjustment *vtree_adjust_c ; |
| 113 | |
| 114 | /* Vertical scrollbar and it's adjustment */ |
| 115 | GtkWidget *vscroll_vc; |
| 116 | GtkAdjustment *vadjust_c ; |
| 117 | |
| 118 | /* Selection handler */ |
| 119 | GtkTreeSelection *select_c; |
| 120 | |
| 121 | guint num_visible_events; |
| 122 | guint first_event, last_event; |
| 123 | |
| 124 | /* TEST DATA, TO BE READ FROM THE TRACE */ |
| 125 | gint number_of_events ; |
| 126 | guint currently_selected_event ; |
| 127 | gboolean selected_event ; |
| 128 | |
| 129 | } EventViewerData ; |
| 130 | |
| 131 | //! Event Viewer's constructor hook |
| 132 | GtkWidget *h_gui_events(MainWindow *parent_window, LttvTracesetSelector * s, char* key); |
| 133 | //! Event Viewer's constructor |
| 134 | EventViewerData *gui_events(MainWindow *parent_window, LttvTracesetSelector *s, char *key); |
| 135 | //! Event Viewer's destructor |
| 136 | void gui_events_destructor(EventViewerData *event_viewer_data); |
| 137 | void gui_events_free(EventViewerData *event_viewer_data); |
| 138 | |
| 139 | static int event_selected_hook(void *hook_data, void *call_data); |
| 140 | |
| 141 | void tree_v_set_cursor(EventViewerData *event_viewer_data); |
| 142 | void tree_v_get_cursor(EventViewerData *event_viewer_data); |
| 143 | |
| 144 | /* Prototype for selection handler callback */ |
| 145 | static void tree_selection_changed_cb (GtkTreeSelection *selection, gpointer data); |
| 146 | static void v_scroll_cb (GtkAdjustment *adjustment, gpointer data); |
| 147 | static void tree_v_size_allocate_cb (GtkWidget *widget, GtkAllocation *alloc, gpointer data); |
| 148 | static void tree_v_size_request_cb (GtkWidget *widget, GtkRequisition *requisition, gpointer data); |
| 149 | static void tree_v_cursor_changed_cb (GtkWidget *widget, gpointer data); |
| 150 | static void tree_v_move_cursor_cb (GtkWidget *widget, GtkMovementStep arg1, gint arg2, gpointer data); |
| 151 | static void tree_v_grab_focus(GtkWidget *widget, gpointer data); |
| 152 | |
| 153 | |
| 154 | static void get_test_data(double time, guint list_height, |
| 155 | EventViewerData *event_viewer_data); |
| 156 | |
| 157 | void add_test_data(EventViewerData *event_viewer_data); |
| 158 | |
| 159 | static void get_events(EventViewerData* event_viewer_data, LttTime start, |
| 160 | LttTime end, unsigned max_num_events, unsigned * real_num_events); |
| 161 | static gboolean parse_event(void *hook_data, void *call_data); |
| 162 | |
| 163 | static LttvModule *main_win_module; |
| 164 | |
| 165 | /** |
| 166 | * plugin's init function |
| 167 | * |
| 168 | * This function initializes the Event Viewer functionnality through the |
| 169 | * gtkTraceSet API. |
| 170 | */ |
| 171 | G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) { |
| 172 | |
| 173 | main_win_module = lttv_module_require(self, "mainwin", argc, argv); |
| 174 | |
| 175 | if(main_win_module == NULL){ |
| 176 | g_critical("Can't load Control Flow Viewer : missing mainwin\n"); |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | /* Register the toolbar insert button */ |
| 181 | toolbar_item_reg(hGuiEventsInsert_xpm, "Insert Event Viewer", h_gui_events); |
| 182 | |
| 183 | /* Register the menu item insert entry */ |
| 184 | menu_item_reg("/", "Insert Event Viewer", h_gui_events); |
| 185 | |
| 186 | } |
| 187 | |
| 188 | void event_destroy_walk(gpointer data, gpointer user_data) |
| 189 | { |
| 190 | gui_events_destructor((EventViewerData*)data); |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * plugin's destroy function |
| 195 | * |
| 196 | * This function releases the memory reserved by the module and unregisters |
| 197 | * everything that has been registered in the gtkTraceSet API. |
| 198 | */ |
| 199 | G_MODULE_EXPORT void destroy() { |
| 200 | int i; |
| 201 | |
| 202 | EventViewerData *event_viewer_data; |
| 203 | |
| 204 | if(g_event_viewer_data_list){ |
| 205 | g_slist_foreach(g_event_viewer_data_list, event_destroy_walk, NULL ); |
| 206 | g_slist_free(g_event_viewer_data_list); |
| 207 | } |
| 208 | |
| 209 | /* Unregister the toolbar insert button */ |
| 210 | toolbar_item_unreg(h_gui_events); |
| 211 | |
| 212 | /* Unregister the menu item insert entry */ |
| 213 | menu_item_unreg(h_gui_events); |
| 214 | } |
| 215 | |
| 216 | /* Enumeration of the columns */ |
| 217 | enum |
| 218 | { |
| 219 | CPUID_COLUMN, |
| 220 | EVENT_COLUMN, |
| 221 | TIME_COLUMN, |
| 222 | PID_COLUMN, |
| 223 | ENTRY_LEN_COLUMN, |
| 224 | EVENT_DESCR_COLUMN, |
| 225 | N_COLUMNS |
| 226 | }; |
| 227 | |
| 228 | |
| 229 | /** |
| 230 | * Event Viewer's constructor hook |
| 231 | * |
| 232 | * This constructor is given as a parameter to the menuitem and toolbar button |
| 233 | * registration. It creates the list. |
| 234 | * @param parent_window A pointer to the parent window. |
| 235 | * @return The widget created. |
| 236 | */ |
| 237 | GtkWidget * |
| 238 | h_gui_events(MainWindow * parent_window, LttvTracesetSelector * s, char* key) |
| 239 | { |
| 240 | EventViewerData* event_viewer_data = gui_events(parent_window, s, key) ; |
| 241 | |
| 242 | if(event_viewer_data) |
| 243 | return event_viewer_data->hbox_v; |
| 244 | else return NULL; |
| 245 | |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Event Viewer's constructor |
| 250 | * |
| 251 | * This constructor is used to create EventViewerData data structure. |
| 252 | * @return The Event viewer data created. |
| 253 | */ |
| 254 | EventViewerData * |
| 255 | gui_events(MainWindow *parent_window, LttvTracesetSelector * s,char* key ) |
| 256 | { |
| 257 | LttTime start, end; |
| 258 | GtkTreeViewColumn *column; |
| 259 | GtkCellRenderer *renderer; |
| 260 | EventViewerData* event_viewer_data = g_new(EventViewerData,1) ; |
| 261 | RawTraceData * data; |
| 262 | unsigned size; |
| 263 | |
| 264 | event_viewer_data->mw = parent_window; |
| 265 | get_time_window(event_viewer_data->mw, &event_viewer_data->time_window); |
| 266 | get_current_time(event_viewer_data->mw, &event_viewer_data->current_time); |
| 267 | |
| 268 | event_viewer_data->before_event_hooks = lttv_hooks_new(); |
| 269 | lttv_hooks_add(event_viewer_data->before_event_hooks, parse_event, event_viewer_data); |
| 270 | |
| 271 | event_viewer_data->raw_trace_data_queue = g_queue_new(); |
| 272 | event_viewer_data->raw_trace_data_queue_tmp = g_queue_new(); |
| 273 | |
| 274 | reg_update_time_window(update_time_window,event_viewer_data, event_viewer_data->mw); |
| 275 | reg_update_current_time(update_current_time,event_viewer_data, event_viewer_data->mw); |
| 276 | |
| 277 | event_viewer_data->scroll_win = gtk_scrolled_window_new (NULL, NULL); |
| 278 | gtk_widget_show ( event_viewer_data->scroll_win); |
| 279 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(event_viewer_data->scroll_win), |
| 280 | GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER); |
| 281 | |
| 282 | /* TEST DATA, TO BE READ FROM THE TRACE */ |
| 283 | event_viewer_data->currently_selected_event = FALSE ; |
| 284 | event_viewer_data->selected_event = 0; |
| 285 | |
| 286 | /* Create a model for storing the data list */ |
| 287 | event_viewer_data->store_m = gtk_list_store_new ( |
| 288 | N_COLUMNS, /* Total number of columns */ |
| 289 | G_TYPE_INT, /* CPUID */ |
| 290 | G_TYPE_STRING, /* Event */ |
| 291 | G_TYPE_UINT64, /* Time */ |
| 292 | G_TYPE_INT, /* PID */ |
| 293 | G_TYPE_INT, /* Entry length */ |
| 294 | G_TYPE_STRING); /* Event's description */ |
| 295 | |
| 296 | /* Create the viewer widget for the columned list */ |
| 297 | event_viewer_data->tree_v = gtk_tree_view_new_with_model (GTK_TREE_MODEL (event_viewer_data->store_m)); |
| 298 | |
| 299 | g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "size-allocate", |
| 300 | G_CALLBACK (tree_v_size_allocate_cb), |
| 301 | event_viewer_data); |
| 302 | g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "size-request", |
| 303 | G_CALLBACK (tree_v_size_request_cb), |
| 304 | event_viewer_data); |
| 305 | |
| 306 | g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "cursor-changed", |
| 307 | G_CALLBACK (tree_v_cursor_changed_cb), |
| 308 | event_viewer_data); |
| 309 | |
| 310 | g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "move-cursor", |
| 311 | G_CALLBACK (tree_v_move_cursor_cb), |
| 312 | event_viewer_data); |
| 313 | |
| 314 | g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "grab-focus", |
| 315 | G_CALLBACK (tree_v_grab_focus), |
| 316 | event_viewer_data); |
| 317 | |
| 318 | // Use on each column! |
| 319 | //gtk_tree_view_column_set_sizing(event_viewer_data->tree_v, GTK_TREE_VIEW_COLUMN_FIXED); |
| 320 | |
| 321 | /* The view now holds a reference. We can get rid of our own |
| 322 | * reference */ |
| 323 | g_object_unref (G_OBJECT (event_viewer_data->store_m)); |
| 324 | |
| 325 | |
| 326 | /* Create a column, associating the "text" attribute of the |
| 327 | * cell_renderer to the first column of the model */ |
| 328 | /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */ |
| 329 | renderer = gtk_cell_renderer_text_new (); |
| 330 | column = gtk_tree_view_column_new_with_attributes ("CPUID", |
| 331 | renderer, |
| 332 | "text", CPUID_COLUMN, |
| 333 | NULL); |
| 334 | gtk_tree_view_column_set_alignment (column, 0.0); |
| 335 | gtk_tree_view_column_set_fixed_width (column, 45); |
| 336 | gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v), column); |
| 337 | |
| 338 | renderer = gtk_cell_renderer_text_new (); |
| 339 | column = gtk_tree_view_column_new_with_attributes ("Event", |
| 340 | renderer, |
| 341 | "text", EVENT_COLUMN, |
| 342 | NULL); |
| 343 | gtk_tree_view_column_set_alignment (column, 0.0); |
| 344 | gtk_tree_view_column_set_fixed_width (column, 120); |
| 345 | gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v), column); |
| 346 | |
| 347 | renderer = gtk_cell_renderer_text_new (); |
| 348 | column = gtk_tree_view_column_new_with_attributes ("Time", |
| 349 | renderer, |
| 350 | "text", TIME_COLUMN, |
| 351 | NULL); |
| 352 | gtk_tree_view_column_set_alignment (column, 1.0); |
| 353 | gtk_tree_view_column_set_fixed_width (column, 120); |
| 354 | gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v), column); |
| 355 | |
| 356 | renderer = gtk_cell_renderer_text_new (); |
| 357 | column = gtk_tree_view_column_new_with_attributes ("PID", |
| 358 | renderer, |
| 359 | "text", PID_COLUMN, |
| 360 | NULL); |
| 361 | gtk_tree_view_column_set_alignment (column, 1.0); |
| 362 | gtk_tree_view_column_set_fixed_width (column, 45); |
| 363 | gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v), column); |
| 364 | |
| 365 | renderer = gtk_cell_renderer_text_new (); |
| 366 | column = gtk_tree_view_column_new_with_attributes ("Entry Length", |
| 367 | renderer, |
| 368 | "text", ENTRY_LEN_COLUMN, |
| 369 | NULL); |
| 370 | gtk_tree_view_column_set_alignment (column, 1.0); |
| 371 | gtk_tree_view_column_set_fixed_width (column, 60); |
| 372 | gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v), column); |
| 373 | |
| 374 | renderer = gtk_cell_renderer_text_new (); |
| 375 | column = gtk_tree_view_column_new_with_attributes ("Event's Description", |
| 376 | renderer, |
| 377 | "text", EVENT_DESCR_COLUMN, |
| 378 | NULL); |
| 379 | gtk_tree_view_column_set_alignment (column, 0.0); |
| 380 | gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v), column); |
| 381 | |
| 382 | |
| 383 | /* Setup the selection handler */ |
| 384 | event_viewer_data->select_c = gtk_tree_view_get_selection (GTK_TREE_VIEW (event_viewer_data->tree_v)); |
| 385 | gtk_tree_selection_set_mode (event_viewer_data->select_c, GTK_SELECTION_SINGLE); |
| 386 | g_signal_connect (G_OBJECT (event_viewer_data->select_c), "changed", |
| 387 | G_CALLBACK (tree_selection_changed_cb), |
| 388 | event_viewer_data); |
| 389 | |
| 390 | gtk_container_add (GTK_CONTAINER (event_viewer_data->scroll_win), event_viewer_data->tree_v); |
| 391 | |
| 392 | event_viewer_data->hbox_v = gtk_hbox_new(0, 0); |
| 393 | gtk_box_pack_start(GTK_BOX(event_viewer_data->hbox_v), event_viewer_data->scroll_win, TRUE, TRUE, 0); |
| 394 | |
| 395 | /* Create vertical scrollbar and pack it */ |
| 396 | event_viewer_data->vscroll_vc = gtk_vscrollbar_new(NULL); |
| 397 | gtk_range_set_update_policy (GTK_RANGE(event_viewer_data->vscroll_vc), |
| 398 | GTK_UPDATE_DISCONTINUOUS); |
| 399 | gtk_box_pack_start(GTK_BOX(event_viewer_data->hbox_v), event_viewer_data->vscroll_vc, FALSE, TRUE, 0); |
| 400 | |
| 401 | /* Get the vertical scrollbar's adjustment */ |
| 402 | event_viewer_data->vadjust_c = gtk_range_get_adjustment(GTK_RANGE(event_viewer_data->vscroll_vc)); |
| 403 | event_viewer_data->vtree_adjust_c = gtk_tree_view_get_vadjustment( |
| 404 | GTK_TREE_VIEW (event_viewer_data->tree_v)); |
| 405 | |
| 406 | g_signal_connect (G_OBJECT (event_viewer_data->vadjust_c), "value-changed", |
| 407 | G_CALLBACK (v_scroll_cb), |
| 408 | event_viewer_data); |
| 409 | /* Set the upper bound to the last event number */ |
| 410 | event_viewer_data->previous_value = 0; |
| 411 | event_viewer_data->vadjust_c->lower = 0.0; |
| 412 | //event_viewer_data->vadjust_c->upper = event_viewer_data->number_of_events; |
| 413 | event_viewer_data->vadjust_c->value = 0.0; |
| 414 | event_viewer_data->vadjust_c->step_increment = 1.0; |
| 415 | event_viewer_data->vadjust_c->page_increment = 2.0; |
| 416 | // event_viewer_data->vtree_adjust_c->upper; |
| 417 | event_viewer_data->vadjust_c->page_size = 2.0; |
| 418 | // event_viewer_data->vtree_adjust_c->upper; |
| 419 | /* Raw event trace */ |
| 420 | gtk_widget_show(event_viewer_data->hbox_v); |
| 421 | gtk_widget_show(event_viewer_data->tree_v); |
| 422 | gtk_widget_show(event_viewer_data->vscroll_vc); |
| 423 | |
| 424 | /* Add the object's information to the module's array */ |
| 425 | g_event_viewer_data_list = g_slist_append(g_event_viewer_data_list, event_viewer_data); |
| 426 | |
| 427 | event_viewer_data->first_event = -1 ; |
| 428 | event_viewer_data->last_event = 0 ; |
| 429 | |
| 430 | event_viewer_data->num_visible_events = 1; |
| 431 | |
| 432 | //get the life span of the traceset and set the upper of the scroll bar |
| 433 | get_traceset_time_span(event_viewer_data->mw, &event_viewer_data->time_span); |
| 434 | |
| 435 | start = ltt_time_sub(event_viewer_data->time_span.endTime, event_viewer_data->time_span.startTime); |
| 436 | event_viewer_data->vadjust_c->upper = ltt_time_to_double(start) * NANOSECONDS_PER_SECOND; |
| 437 | |
| 438 | event_viewer_data->append = TRUE; |
| 439 | |
| 440 | start.tv_sec = 0; |
| 441 | start.tv_nsec = 0; |
| 442 | end.tv_sec = G_MAXULONG; |
| 443 | end.tv_nsec = G_MAXULONG; |
| 444 | |
| 445 | get_events(event_viewer_data, start,end, RESERVE_SMALL_SIZE, &size); |
| 446 | |
| 447 | event_viewer_data->start_event_index = 0; |
| 448 | event_viewer_data->end_event_index = event_viewer_data->num_visible_events - 1; |
| 449 | |
| 450 | // Test data |
| 451 | get_test_data(event_viewer_data->vadjust_c->value, |
| 452 | event_viewer_data->num_visible_events, |
| 453 | event_viewer_data); |
| 454 | |
| 455 | /* Set the Selected Event */ |
| 456 | // tree_v_set_cursor(event_viewer_data); |
| 457 | |
| 458 | |
| 459 | g_object_set_data( |
| 460 | G_OBJECT(event_viewer_data->hbox_v), |
| 461 | key, |
| 462 | s); |
| 463 | |
| 464 | g_object_set_data_full( |
| 465 | G_OBJECT(event_viewer_data->hbox_v), |
| 466 | "event_viewer_data", |
| 467 | event_viewer_data, |
| 468 | (GDestroyNotify)gui_events_free); |
| 469 | |
| 470 | return event_viewer_data; |
| 471 | } |
| 472 | |
| 473 | void tree_v_set_cursor(EventViewerData *event_viewer_data) |
| 474 | { |
| 475 | GtkTreePath *path; |
| 476 | |
| 477 | if(event_viewer_data->selected_event && event_viewer_data->first_event != -1) |
| 478 | { |
| 479 | // gtk_adjustment_set_value(event_viewer_data->vadjust_c, |
| 480 | // event_viewer_data->currently_selected_event); |
| 481 | |
| 482 | path = gtk_tree_path_new_from_indices( |
| 483 | event_viewer_data->currently_selected_event- |
| 484 | event_viewer_data->first_event, |
| 485 | -1); |
| 486 | |
| 487 | gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE); |
| 488 | gtk_tree_path_free(path); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | void tree_v_get_cursor(EventViewerData *event_viewer_data) |
| 493 | { |
| 494 | GtkTreePath *path; |
| 495 | gint *indices; |
| 496 | |
| 497 | gtk_tree_view_get_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), &path, NULL); |
| 498 | indices = gtk_tree_path_get_indices(path); |
| 499 | |
| 500 | if(indices != NULL) |
| 501 | { |
| 502 | event_viewer_data->selected_event = TRUE; |
| 503 | event_viewer_data->currently_selected_event = |
| 504 | event_viewer_data->first_event + indices[0]; |
| 505 | |
| 506 | } else { |
| 507 | event_viewer_data->selected_event = FALSE; |
| 508 | event_viewer_data->currently_selected_event = 0; |
| 509 | } |
| 510 | |
| 511 | gtk_tree_path_free(path); |
| 512 | |
| 513 | } |
| 514 | |
| 515 | |
| 516 | |
| 517 | void tree_v_move_cursor_cb (GtkWidget *widget, GtkMovementStep arg1, gint arg2, gpointer data) |
| 518 | { |
| 519 | GtkTreePath *path; // = gtk_tree_path_new(); |
| 520 | gint *indices; |
| 521 | gdouble value; |
| 522 | EventViewerData *event_viewer_data = (EventViewerData*)data; |
| 523 | |
| 524 | gtk_tree_view_get_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), &path, NULL); |
| 525 | if(path == NULL) |
| 526 | { |
| 527 | /* No prior cursor, put it at beginning of page and let the execution do */ |
| 528 | path = gtk_tree_path_new_from_indices(0, -1); |
| 529 | gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE); |
| 530 | } |
| 531 | |
| 532 | indices = gtk_tree_path_get_indices(path); |
| 533 | |
| 534 | value = gtk_adjustment_get_value(event_viewer_data->vadjust_c); |
| 535 | |
| 536 | if(arg1 == GTK_MOVEMENT_DISPLAY_LINES) |
| 537 | { |
| 538 | /* Move one line */ |
| 539 | if(arg2 == 1) |
| 540 | { |
| 541 | /* move one line down */ |
| 542 | if(indices[0] == event_viewer_data->num_visible_events - 1) |
| 543 | { |
| 544 | if(value + event_viewer_data->num_visible_events <= |
| 545 | event_viewer_data->number_of_events -1) |
| 546 | { |
| 547 | event_viewer_data->currently_selected_event += 1; |
| 548 | // gtk_adjustment_set_value(event_viewer_data->vadjust_c, value+1); |
| 549 | //gtk_tree_path_free(path); |
| 550 | //path = gtk_tree_path_new_from_indices(event_viewer_data->num_visible_events-1, -1); |
| 551 | //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE); |
| 552 | g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor"); |
| 553 | } |
| 554 | } |
| 555 | } else { |
| 556 | /* Move one line up */ |
| 557 | if(indices[0] == 0) |
| 558 | { |
| 559 | if(value - 1 >= 0 ) |
| 560 | { |
| 561 | event_viewer_data->currently_selected_event -= 1; |
| 562 | // gtk_adjustment_set_value(event_viewer_data->vadjust_c, value-1); |
| 563 | //gtk_tree_path_free(path); |
| 564 | //path = gtk_tree_path_new_from_indices(0, -1); |
| 565 | //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE); |
| 566 | g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor"); |
| 567 | } |
| 568 | |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | } |
| 573 | |
| 574 | if(arg1 == GTK_MOVEMENT_PAGES) |
| 575 | { |
| 576 | /* Move one page */ |
| 577 | if(arg2 == 1) |
| 578 | { |
| 579 | if(event_viewer_data->num_visible_events == 1) |
| 580 | value += 1 ; |
| 581 | /* move one page down */ |
| 582 | if(value + event_viewer_data->num_visible_events-1 <= |
| 583 | event_viewer_data->number_of_events ) |
| 584 | { |
| 585 | event_viewer_data->currently_selected_event += event_viewer_data->num_visible_events-1; |
| 586 | // gtk_adjustment_set_value(event_viewer_data->vadjust_c, |
| 587 | // value+(event_viewer_data->num_visible_events-1)); |
| 588 | //gtk_tree_path_free(path); |
| 589 | //path = gtk_tree_path_new_from_indices(0, -1); |
| 590 | //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE); |
| 591 | g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor"); |
| 592 | } |
| 593 | } else { |
| 594 | /* Move one page up */ |
| 595 | if(event_viewer_data->num_visible_events == 1) |
| 596 | value -= 1 ; |
| 597 | |
| 598 | if(indices[0] < event_viewer_data->num_visible_events - 2 ) |
| 599 | { |
| 600 | if(value - (event_viewer_data->num_visible_events-1) >= 0) |
| 601 | { |
| 602 | event_viewer_data->currently_selected_event -= event_viewer_data->num_visible_events-1; |
| 603 | |
| 604 | // gtk_adjustment_set_value(event_viewer_data->vadjust_c, |
| 605 | // value-(event_viewer_data->num_visible_events-1)); |
| 606 | //gtk_tree_path_free(path); |
| 607 | //path = gtk_tree_path_new_from_indices(0, -1); |
| 608 | //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE); |
| 609 | g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor"); |
| 610 | |
| 611 | } else { |
| 612 | /* Go to first Event */ |
| 613 | event_viewer_data->currently_selected_event == 0 ; |
| 614 | // gtk_adjustment_set_value(event_viewer_data->vadjust_c, |
| 615 | // 0); |
| 616 | //gtk_tree_path_free(path); |
| 617 | //path = gtk_tree_path_new_from_indices(0, -1); |
| 618 | //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE); |
| 619 | g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor"); |
| 620 | |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | } |
| 625 | |
| 626 | } |
| 627 | |
| 628 | if(arg1 == GTK_MOVEMENT_BUFFER_ENDS) |
| 629 | { |
| 630 | /* Move to the ends of the buffer */ |
| 631 | if(arg2 == 1) |
| 632 | { |
| 633 | /* move end of buffer */ |
| 634 | event_viewer_data->currently_selected_event = event_viewer_data->number_of_events-1 ; |
| 635 | // gtk_adjustment_set_value(event_viewer_data->vadjust_c, |
| 636 | // event_viewer_data->number_of_events - |
| 637 | // event_viewer_data->num_visible_events); |
| 638 | //gtk_tree_path_free(path); |
| 639 | //path = gtk_tree_path_new_from_indices(event_viewer_data->num_visible_events-1, -1); |
| 640 | //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE); |
| 641 | g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor"); |
| 642 | } else { |
| 643 | /* Move beginning of buffer */ |
| 644 | event_viewer_data->currently_selected_event = 0 ; |
| 645 | // gtk_adjustment_set_value(event_viewer_data->vadjust_c, 0); |
| 646 | //gtk_tree_path_free(path); |
| 647 | //path = gtk_tree_path_new_from_indices(0, -1); |
| 648 | //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE); |
| 649 | g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor"); |
| 650 | } |
| 651 | |
| 652 | } |
| 653 | |
| 654 | |
| 655 | gtk_tree_path_free(path); |
| 656 | } |
| 657 | |
| 658 | void tree_v_cursor_changed_cb (GtkWidget *widget, gpointer data) |
| 659 | { |
| 660 | EventViewerData *event_viewer_data = (EventViewerData*) data; |
| 661 | LttTime ltt_time; |
| 662 | guint64 time; |
| 663 | GtkTreeIter iter; |
| 664 | GtkTreeModel* model = GTK_TREE_MODEL(event_viewer_data->store_m); |
| 665 | GtkTreePath *path; |
| 666 | |
| 667 | /* On cursor change, modify the currently selected event by calling |
| 668 | * the right API function */ |
| 669 | tree_v_get_cursor(event_viewer_data); |
| 670 | /* |
| 671 | gtk_tree_view_get_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), &path, NULL); |
| 672 | if(gtk_tree_model_get_iter(model,&iter,path)){ |
| 673 | gtk_tree_model_get(model, &iter, TIME_COLUMN, &time, -1); |
| 674 | ltt_time.tv_sec = time / NANOSECONDS_PER_SECOND; |
| 675 | ltt_time.tv_nsec = time % NANOSECONDS_PER_SECOND; |
| 676 | |
| 677 | if(ltt_time.tv_sec != event_viewer_data->current_time.tv_sec || |
| 678 | ltt_time.tv_nsec != event_viewer_data->current_time.tv_nsec) |
| 679 | set_current_time(event_viewer_data->mw,<t_time); |
| 680 | }else{ |
| 681 | g_warning("Can not get iter\n"); |
| 682 | } |
| 683 | */ |
| 684 | } |
| 685 | |
| 686 | |
| 687 | void v_scroll_cb (GtkAdjustment *adjustment, gpointer data) |
| 688 | { |
| 689 | EventViewerData *event_viewer_data = (EventViewerData*)data; |
| 690 | GtkTreePath *tree_path; |
| 691 | |
| 692 | get_test_data(adjustment->value, event_viewer_data->num_visible_events, |
| 693 | event_viewer_data); |
| 694 | |
| 695 | |
| 696 | if(event_viewer_data->currently_selected_event |
| 697 | >= event_viewer_data->first_event |
| 698 | && |
| 699 | event_viewer_data->currently_selected_event |
| 700 | <= event_viewer_data->last_event |
| 701 | && |
| 702 | event_viewer_data->selected_event) |
| 703 | { |
| 704 | |
| 705 | tree_path = gtk_tree_path_new_from_indices( |
| 706 | event_viewer_data->currently_selected_event- |
| 707 | event_viewer_data->first_event, |
| 708 | -1); |
| 709 | |
| 710 | // gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), tree_path, |
| 711 | // NULL, FALSE); |
| 712 | gtk_tree_path_free(tree_path); |
| 713 | } |
| 714 | |
| 715 | |
| 716 | } |
| 717 | |
| 718 | gint get_cell_height(GtkTreeView *TreeView) |
| 719 | { |
| 720 | gint height, width; |
| 721 | GtkTreeViewColumn *column = gtk_tree_view_get_column(TreeView, 0); |
| 722 | GList *Render_List = gtk_tree_view_column_get_cell_renderers(column); |
| 723 | GtkCellRenderer *renderer = g_list_first(Render_List)->data; |
| 724 | |
| 725 | gtk_tree_view_column_cell_get_size(column, NULL, NULL, NULL, NULL, &height); |
| 726 | |
| 727 | return height; |
| 728 | } |
| 729 | |
| 730 | void tree_v_size_allocate_cb (GtkWidget *widget, GtkAllocation *alloc, gpointer data) |
| 731 | { |
| 732 | EventViewerData *event_viewer_data = (EventViewerData*)data; |
| 733 | gint cell_height = get_cell_height(GTK_TREE_VIEW(event_viewer_data->tree_v)); |
| 734 | gint last_num_visible_events = event_viewer_data->num_visible_events; |
| 735 | gdouble exact_num_visible; |
| 736 | |
| 737 | exact_num_visible = ( alloc->height - |
| 738 | TREE_VIEW_HEADER_HEIGHT (GTK_TREE_VIEW(event_viewer_data->tree_v)) ) |
| 739 | / (double)cell_height ; |
| 740 | |
| 741 | event_viewer_data->num_visible_events = ceil(exact_num_visible) ; |
| 742 | |
| 743 | /* |
| 744 | event_viewer_data->vadjust_c->page_increment = |
| 745 | floor(exact_num_visible); |
| 746 | event_viewer_data->vadjust_c->page_size = |
| 747 | floor(exact_num_visible); |
| 748 | */ |
| 749 | |
| 750 | if(event_viewer_data->num_visible_events != last_num_visible_events) |
| 751 | { |
| 752 | get_test_data(event_viewer_data->vadjust_c->value, |
| 753 | event_viewer_data->num_visible_events, |
| 754 | event_viewer_data); |
| 755 | } |
| 756 | |
| 757 | |
| 758 | } |
| 759 | |
| 760 | void tree_v_size_request_cb (GtkWidget *widget, GtkRequisition *requisition, gpointer data) |
| 761 | { |
| 762 | gint h; |
| 763 | EventViewerData *event_viewer_data = (EventViewerData*)data; |
| 764 | gint cell_height = get_cell_height(GTK_TREE_VIEW(event_viewer_data->tree_v)); |
| 765 | |
| 766 | h = cell_height + TREE_VIEW_HEADER_HEIGHT |
| 767 | (GTK_TREE_VIEW(event_viewer_data->tree_v)); |
| 768 | requisition->height = h; |
| 769 | |
| 770 | } |
| 771 | |
| 772 | void get_test_data(double time_value, guint list_height, |
| 773 | EventViewerData *event_viewer_data) |
| 774 | { |
| 775 | GtkTreeIter iter; |
| 776 | int i; |
| 777 | GtkTreeModel *model = GTK_TREE_MODEL(event_viewer_data->store_m); |
| 778 | GtkTreePath *tree_path; |
| 779 | RawTraceData * raw_data; |
| 780 | ScrollDirection direction = SCROLL_NONE; |
| 781 | GList * first; |
| 782 | int event_number; |
| 783 | double value = event_viewer_data->previous_value - time_value; |
| 784 | LttTime start, end, time; |
| 785 | LttEvent * ev; |
| 786 | unsigned backward_num, minNum, maxNum; |
| 787 | LttTracefile * tf; |
| 788 | unsigned block_num, event_num; |
| 789 | unsigned size = 1, count = 0; |
| 790 | gboolean need_backward_again, backward; |
| 791 | GdkWindow * win; |
| 792 | GdkCursor * new; |
| 793 | GtkWidget* widget = gtk_widget_get_parent(event_viewer_data->hbox_v); |
| 794 | |
| 795 | if(widget){ |
| 796 | new = gdk_cursor_new(GDK_X_CURSOR); |
| 797 | win = gtk_widget_get_parent_window(widget); |
| 798 | gdk_window_set_cursor(win, new); |
| 799 | gdk_cursor_unref(new); |
| 800 | gdk_window_stick(win); |
| 801 | gdk_window_unstick(win); |
| 802 | } |
| 803 | |
| 804 | |
| 805 | // if(event_number > event_viewer_data->last_event || |
| 806 | // event_number + list_height-1 < event_viewer_data->first_event || |
| 807 | // event_viewer_data->first_event == -1) |
| 808 | { |
| 809 | /* no event can be reused, clear and start from nothing */ |
| 810 | if(value == -1.0) direction = SCROLL_STEP_DOWN; |
| 811 | else if(value == 1.0 ) direction = SCROLL_STEP_UP; |
| 812 | else if(value == -2.0) direction = SCROLL_PAGE_DOWN; |
| 813 | else if(value == 2.0 ) direction = SCROLL_PAGE_UP; |
| 814 | else if(value == 0.0 ) direction = SCROLL_NONE; |
| 815 | else direction = SCROLL_JUMP; |
| 816 | |
| 817 | switch(direction){ |
| 818 | case SCROLL_STEP_UP: |
| 819 | case SCROLL_PAGE_UP: |
| 820 | if(direction == SCROLL_PAGE_UP){ |
| 821 | backward = list_height>event_viewer_data->start_event_index ? TRUE : FALSE; |
| 822 | }else{ |
| 823 | backward = event_viewer_data->start_event_index == 0 ? TRUE : FALSE; |
| 824 | } |
| 825 | if(backward){ |
| 826 | event_viewer_data->append = FALSE; |
| 827 | do{ |
| 828 | if(direction == SCROLL_PAGE_UP){ |
| 829 | minNum = list_height - event_viewer_data->start_event_index ; |
| 830 | }else{ |
| 831 | minNum = 1; |
| 832 | } |
| 833 | |
| 834 | first = event_viewer_data->raw_trace_data_queue->head; |
| 835 | raw_data = (RawTraceData*)g_list_nth_data(first,0); |
| 836 | end = raw_data->time; |
| 837 | end.tv_nsec--; |
| 838 | ltt_event_position_get(raw_data->ep, &block_num, &event_num, &tf); |
| 839 | if(size !=0){ |
| 840 | if(event_num > minNum){ |
| 841 | backward_num = event_num > RESERVE_SMALL_SIZE |
| 842 | ? event_num - RESERVE_SMALL_SIZE : 1; |
| 843 | ltt_event_position_set(raw_data->ep, block_num, backward_num); |
| 844 | ltt_tracefile_seek_position(tf, raw_data->ep); |
| 845 | ev = ltt_tracefile_read(tf); |
| 846 | start = ltt_event_time(ev); |
| 847 | maxNum = G_MAXULONG; |
| 848 | }else{ |
| 849 | if(block_num > 1){ |
| 850 | ltt_event_position_set(raw_data->ep, block_num-1, 1); |
| 851 | ltt_tracefile_seek_position(tf, raw_data->ep); |
| 852 | ev = ltt_tracefile_read(tf); |
| 853 | start = ltt_event_time(ev); |
| 854 | }else{ |
| 855 | start.tv_sec = 0; |
| 856 | start.tv_nsec = 0; |
| 857 | } |
| 858 | maxNum = G_MAXULONG; |
| 859 | } |
| 860 | }else{ |
| 861 | if(block_num > count){ |
| 862 | ltt_event_position_set(raw_data->ep, block_num-count, 1); |
| 863 | ltt_tracefile_seek_position(tf, raw_data->ep); |
| 864 | ev = ltt_tracefile_read(tf); |
| 865 | start = ltt_event_time(ev); |
| 866 | }else{ |
| 867 | start.tv_sec = 0; |
| 868 | start.tv_nsec = 0; |
| 869 | } |
| 870 | maxNum = G_MAXULONG; |
| 871 | } |
| 872 | |
| 873 | event_viewer_data->current_event_index = event_viewer_data->start_event_index; |
| 874 | get_events(event_viewer_data, start, end, maxNum, &size); |
| 875 | event_viewer_data->start_event_index = event_viewer_data->current_event_index; |
| 876 | |
| 877 | if(size < minNum && (start.tv_sec !=0 || start.tv_nsec !=0)) |
| 878 | need_backward_again = TRUE; |
| 879 | else need_backward_again = FALSE; |
| 880 | if(size == 0){ |
| 881 | count++; |
| 882 | }else{ |
| 883 | count = 0; |
| 884 | } |
| 885 | }while(need_backward_again); |
| 886 | } |
| 887 | if(direction == SCROLL_STEP_UP) |
| 888 | event_number = event_viewer_data->start_event_index - 1; |
| 889 | else |
| 890 | event_number = event_viewer_data->start_event_index - list_height; |
| 891 | break; |
| 892 | case SCROLL_STEP_DOWN: |
| 893 | if(event_viewer_data->end_event_index == event_viewer_data->number_of_events - 1){ |
| 894 | event_viewer_data->append = TRUE; |
| 895 | first = event_viewer_data->raw_trace_data_queue->head; |
| 896 | raw_data = (RawTraceData*)g_list_nth_data(first,event_viewer_data->number_of_events - 1); |
| 897 | start = raw_data->time; |
| 898 | start.tv_nsec++; |
| 899 | end.tv_sec = G_MAXULONG; |
| 900 | end.tv_nsec = G_MAXULONG; |
| 901 | get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE, &size); |
| 902 | }else size = 1; |
| 903 | if(size > 0) event_number = event_viewer_data->start_event_index + 1; |
| 904 | else event_number = event_viewer_data->start_event_index; |
| 905 | break; |
| 906 | case SCROLL_PAGE_DOWN: |
| 907 | if(event_viewer_data->end_event_index >= event_viewer_data->number_of_events - 1 - list_height){ |
| 908 | event_viewer_data->append = TRUE; |
| 909 | first = event_viewer_data->raw_trace_data_queue->head; |
| 910 | raw_data = (RawTraceData*)g_list_nth_data(first,event_viewer_data->number_of_events - 1); |
| 911 | start = raw_data->time; |
| 912 | start.tv_nsec++; |
| 913 | end.tv_sec = G_MAXULONG; |
| 914 | end.tv_nsec = G_MAXULONG; |
| 915 | get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE,&size); |
| 916 | } |
| 917 | if(list_height <= event_viewer_data->number_of_events - 1 - event_viewer_data->end_event_index) |
| 918 | event_number = event_viewer_data->start_event_index + list_height - 1; |
| 919 | else |
| 920 | event_number = event_viewer_data->number_of_events - 1 - list_height; |
| 921 | break; |
| 922 | case SCROLL_JUMP: |
| 923 | event_viewer_data->append = TRUE; |
| 924 | remove_all_items_from_queue(event_viewer_data->raw_trace_data_queue); |
| 925 | end.tv_sec = G_MAXULONG; |
| 926 | end.tv_nsec = G_MAXULONG; |
| 927 | time = ltt_time_from_double(time_value / NANOSECONDS_PER_SECOND); |
| 928 | start = ltt_time_add(event_viewer_data->time_span.startTime, time); |
| 929 | event_viewer_data->previous_value = time_value; |
| 930 | get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE,&size); |
| 931 | if(size < list_height){ |
| 932 | event_viewer_data->append = FALSE; |
| 933 | first = event_viewer_data->raw_trace_data_queue->head; |
| 934 | raw_data = (RawTraceData*)g_list_nth_data(first,0); |
| 935 | end = raw_data->time; |
| 936 | end.tv_nsec--; |
| 937 | ltt_event_position_get(raw_data->ep, &block_num, &event_num, &tf); |
| 938 | |
| 939 | if(event_num > list_height - size){ |
| 940 | backward_num = event_num > RESERVE_SMALL_SIZE |
| 941 | ? event_num - RESERVE_SMALL_SIZE : 1; |
| 942 | ltt_event_position_set(raw_data->ep, block_num, backward_num); |
| 943 | ltt_tracefile_seek_position(tf, raw_data->ep); |
| 944 | ev = ltt_tracefile_read(tf); |
| 945 | start = ltt_event_time(ev); |
| 946 | maxNum = G_MAXULONG; |
| 947 | event_viewer_data->current_event_index = 0; |
| 948 | get_events(event_viewer_data, start, end, maxNum, &size); |
| 949 | event_viewer_data->start_event_index = event_viewer_data->current_event_index; |
| 950 | } |
| 951 | event_number = event_viewer_data->raw_trace_data_queue->length - list_height; |
| 952 | }else{ |
| 953 | event_number = 0; |
| 954 | } |
| 955 | break; |
| 956 | case SCROLL_NONE: |
| 957 | event_number = event_viewer_data->current_event_index; |
| 958 | break; |
| 959 | default: |
| 960 | break; |
| 961 | } |
| 962 | |
| 963 | //update the value of the scroll bar |
| 964 | if(direction != SCROLL_NONE && direction != SCROLL_JUMP){ |
| 965 | first = event_viewer_data->raw_trace_data_queue->head; |
| 966 | raw_data = (RawTraceData*)g_list_nth_data(first,event_number); |
| 967 | time = ltt_time_sub(raw_data->time, event_viewer_data->time_span.startTime); |
| 968 | event_viewer_data->vadjust_c->value = ltt_time_to_double(time) * NANOSECONDS_PER_SECOND; |
| 969 | g_signal_stop_emission_by_name(G_OBJECT(event_viewer_data->vadjust_c), "value-changed"); |
| 970 | event_viewer_data->previous_value = event_viewer_data->vadjust_c->value; |
| 971 | } |
| 972 | |
| 973 | |
| 974 | event_viewer_data->start_event_index = event_number; |
| 975 | event_viewer_data->end_event_index = event_number + list_height - 1; |
| 976 | |
| 977 | first = event_viewer_data->raw_trace_data_queue->head; |
| 978 | gtk_list_store_clear(event_viewer_data->store_m); |
| 979 | for(i=event_number; i<event_number+list_height; i++) |
| 980 | { |
| 981 | guint64 real_data; |
| 982 | |
| 983 | if(i>=event_viewer_data->number_of_events) break; |
| 984 | |
| 985 | raw_data = (RawTraceData*)g_list_nth_data(first, i); |
| 986 | |
| 987 | // Add a new row to the model |
| 988 | real_data = raw_data->time.tv_sec; |
| 989 | real_data *= NANOSECONDS_PER_SECOND; |
| 990 | real_data += raw_data->time.tv_nsec; |
| 991 | gtk_list_store_append (event_viewer_data->store_m, &iter); |
| 992 | gtk_list_store_set (event_viewer_data->store_m, &iter, |
| 993 | CPUID_COLUMN, raw_data->cpu_id, |
| 994 | EVENT_COLUMN, raw_data->event_name, |
| 995 | TIME_COLUMN, real_data, |
| 996 | PID_COLUMN, raw_data->pid, |
| 997 | ENTRY_LEN_COLUMN, raw_data->entry_length, |
| 998 | EVENT_DESCR_COLUMN, raw_data->event_description, |
| 999 | -1); |
| 1000 | /* |
| 1001 | gtk_list_store_append (event_viewer_data->store_m, &iter); |
| 1002 | gtk_list_store_set (event_viewer_data->store_m, &iter, |
| 1003 | CPUID_COLUMN, 0, |
| 1004 | EVENT_COLUMN, "event irq", |
| 1005 | TIME_COLUMN, i, |
| 1006 | PID_COLUMN, 100, |
| 1007 | ENTRY_LEN_COLUMN, 17, |
| 1008 | EVENT_DESCR_COLUMN, "Detailed information", |
| 1009 | -1); |
| 1010 | */ |
| 1011 | } |
| 1012 | } |
| 1013 | #ifdef DEBUG //do not use this, it's slower and broken |
| 1014 | // } else { |
| 1015 | /* Some events will be reused */ |
| 1016 | if(event_number < event_viewer_data->first_event) |
| 1017 | { |
| 1018 | /* scrolling up, prepend events */ |
| 1019 | tree_path = gtk_tree_path_new_from_indices |
| 1020 | (event_number+list_height-1 - |
| 1021 | event_viewer_data->first_event + 1, |
| 1022 | -1); |
| 1023 | for(i=0; i<event_viewer_data->last_event-(event_number+list_height-1); |
| 1024 | i++) |
| 1025 | { |
| 1026 | /* Remove the last events from the list */ |
| 1027 | if(gtk_tree_model_get_iter(model, &iter, tree_path)) |
| 1028 | gtk_list_store_remove(event_viewer_data->store_m, &iter); |
| 1029 | } |
| 1030 | |
| 1031 | for(i=event_viewer_data->first_event-1; i>=event_number; i--) |
| 1032 | { |
| 1033 | if(i>=event_viewer_data->number_of_events) break; |
| 1034 | /* Prepend new events */ |
| 1035 | gtk_list_store_prepend (event_viewer_data->store_m, &iter); |
| 1036 | gtk_list_store_set (event_viewer_data->store_m, &iter, |
| 1037 | CPUID_COLUMN, 0, |
| 1038 | EVENT_COLUMN, "event irq", |
| 1039 | TIME_COLUMN, i, |
| 1040 | PID_COLUMN, 100, |
| 1041 | ENTRY_LEN_COLUMN, 17, |
| 1042 | EVENT_DESCR_COLUMN, "Detailed information", |
| 1043 | -1); |
| 1044 | } |
| 1045 | } else { |
| 1046 | /* Scrolling down, append events */ |
| 1047 | for(i=event_viewer_data->first_event; i<event_number; i++) |
| 1048 | { |
| 1049 | /* Remove these events from the list */ |
| 1050 | gtk_tree_model_get_iter_first(model, &iter); |
| 1051 | gtk_list_store_remove(event_viewer_data->store_m, &iter); |
| 1052 | } |
| 1053 | for(i=event_viewer_data->last_event+1; i<event_number+list_height; i++) |
| 1054 | { |
| 1055 | if(i>=event_viewer_data->number_of_events) break; |
| 1056 | /* Append new events */ |
| 1057 | gtk_list_store_append (event_viewer_data->store_m, &iter); |
| 1058 | gtk_list_store_set (event_viewer_data->store_m, &iter, |
| 1059 | CPUID_COLUMN, 0, |
| 1060 | EVENT_COLUMN, "event irq", |
| 1061 | TIME_COLUMN, i, |
| 1062 | PID_COLUMN, 100, |
| 1063 | ENTRY_LEN_COLUMN, 17, |
| 1064 | EVENT_DESCR_COLUMN, "Detailed information", |
| 1065 | -1); |
| 1066 | } |
| 1067 | |
| 1068 | } |
| 1069 | //} |
| 1070 | #endif //DEBUG |
| 1071 | event_viewer_data->first_event = event_viewer_data->start_event_index ; |
| 1072 | event_viewer_data->last_event = event_viewer_data->end_event_index ; |
| 1073 | |
| 1074 | if(widget) |
| 1075 | gdk_window_set_cursor(win, NULL); |
| 1076 | |
| 1077 | } |
| 1078 | |
| 1079 | |
| 1080 | void add_test_data(EventViewerData *event_viewer_data) |
| 1081 | { |
| 1082 | GtkTreeIter iter; |
| 1083 | int i; |
| 1084 | |
| 1085 | for(i=0; i<10; i++) |
| 1086 | { |
| 1087 | /* Add a new row to the model */ |
| 1088 | gtk_list_store_append (event_viewer_data->store_m, &iter); |
| 1089 | gtk_list_store_set (event_viewer_data->store_m, &iter, |
| 1090 | CPUID_COLUMN, 0, |
| 1091 | EVENT_COLUMN, "event irq", |
| 1092 | TIME_COLUMN, i, |
| 1093 | PID_COLUMN, 100, |
| 1094 | ENTRY_LEN_COLUMN, 17, |
| 1095 | EVENT_DESCR_COLUMN, "Detailed information", |
| 1096 | -1); |
| 1097 | } |
| 1098 | |
| 1099 | } |
| 1100 | |
| 1101 | void |
| 1102 | gui_events_free(EventViewerData *event_viewer_data) |
| 1103 | { |
| 1104 | if(event_viewer_data){ |
| 1105 | lttv_hooks_remove(event_viewer_data->before_event_hooks,parse_event); |
| 1106 | lttv_hooks_destroy(event_viewer_data->before_event_hooks); |
| 1107 | |
| 1108 | remove_all_items_from_queue (event_viewer_data->raw_trace_data_queue); |
| 1109 | g_queue_free(event_viewer_data->raw_trace_data_queue); |
| 1110 | g_queue_free(event_viewer_data->raw_trace_data_queue_tmp); |
| 1111 | |
| 1112 | unreg_update_time_window(update_time_window,event_viewer_data, event_viewer_data->mw); |
| 1113 | unreg_update_current_time(update_current_time,event_viewer_data, event_viewer_data->mw); |
| 1114 | |
| 1115 | g_event_viewer_data_list = g_slist_remove(g_event_viewer_data_list, event_viewer_data); |
| 1116 | g_free(event_viewer_data); |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | void |
| 1121 | gui_events_destructor(EventViewerData *event_viewer_data) |
| 1122 | { |
| 1123 | guint index; |
| 1124 | |
| 1125 | /* May already been done by GTK window closing */ |
| 1126 | if(GTK_IS_WIDGET(event_viewer_data->hbox_v)){ |
| 1127 | gtk_widget_destroy(event_viewer_data->hbox_v); |
| 1128 | event_viewer_data = NULL; |
| 1129 | } |
| 1130 | |
| 1131 | /* Destroy the Tree View */ |
| 1132 | //gtk_widget_destroy(event_viewer_data->tree_v); |
| 1133 | |
| 1134 | /* Clear raw event list */ |
| 1135 | //gtk_list_store_clear(event_viewer_data->store_m); |
| 1136 | //gtk_widget_destroy(GTK_WIDGET(event_viewer_data->store_m)); |
| 1137 | |
| 1138 | //gui_events_free(event_viewer_data); |
| 1139 | } |
| 1140 | |
| 1141 | //FIXME : call hGuiEvents_Destructor for corresponding data upon widget destroy |
| 1142 | |
| 1143 | static void |
| 1144 | tree_selection_changed_cb (GtkTreeSelection *selection, gpointer data) |
| 1145 | { |
| 1146 | EventViewerData *event_viewer_data = (EventViewerData*)data; |
| 1147 | GtkTreeIter iter; |
| 1148 | GtkTreeModel *model = GTK_TREE_MODEL(event_viewer_data->store_m); |
| 1149 | gchar *event; |
| 1150 | |
| 1151 | if (gtk_tree_selection_get_selected (selection, &model, &iter)) |
| 1152 | { |
| 1153 | gtk_tree_model_get (model, &iter, EVENT_COLUMN, &event, -1); |
| 1154 | |
| 1155 | g_free (event); |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | |
| 1160 | int event_selected_hook(void *hook_data, void *call_data) |
| 1161 | { |
| 1162 | EventViewerData *event_viewer_data = (EventViewerData*) hook_data; |
| 1163 | guint *event_number = (guint*) call_data; |
| 1164 | |
| 1165 | event_viewer_data->currently_selected_event = *event_number; |
| 1166 | event_viewer_data->selected_event = TRUE ; |
| 1167 | |
| 1168 | tree_v_set_cursor(event_viewer_data); |
| 1169 | |
| 1170 | } |
| 1171 | |
| 1172 | |
| 1173 | gboolean update_time_window(void * hook_data, void * call_data) |
| 1174 | { |
| 1175 | EventViewerData *event_viewer_data = (EventViewerData*) hook_data; |
| 1176 | event_viewer_data->time_window = *(TimeWindow*)call_data; |
| 1177 | |
| 1178 | return FALSE; |
| 1179 | } |
| 1180 | |
| 1181 | gboolean update_current_time(void * hook_data, void * call_data) |
| 1182 | { |
| 1183 | EventViewerData *event_viewer_data = (EventViewerData*) hook_data; |
| 1184 | event_viewer_data->current_time = *(LttTime*)call_data; |
| 1185 | guint64 nsec = event_viewer_data->current_time.tv_sec * NANOSECONDS_PER_SECOND |
| 1186 | + event_viewer_data->current_time.tv_nsec; |
| 1187 | GtkTreeIter iter; |
| 1188 | guint64 time; |
| 1189 | int count = 0; |
| 1190 | GtkTreeModel* model = (GtkTreeModel*)event_viewer_data->store_m; |
| 1191 | |
| 1192 | |
| 1193 | if(gtk_tree_model_get_iter_first(model, &iter)){ |
| 1194 | while(1){ |
| 1195 | gtk_tree_model_get(model, &iter, TIME_COLUMN, &time, -1); |
| 1196 | if(time < nsec){ |
| 1197 | if(!gtk_tree_model_iter_next(model, &iter)){ |
| 1198 | return TRUE; |
| 1199 | } |
| 1200 | count++; |
| 1201 | }else{ |
| 1202 | break; |
| 1203 | } |
| 1204 | } |
| 1205 | // event_selected_hook(event_viewer_data, &count); |
| 1206 | } |
| 1207 | |
| 1208 | return FALSE; |
| 1209 | } |
| 1210 | |
| 1211 | void tree_v_grab_focus(GtkWidget *widget, gpointer data){ |
| 1212 | EventViewerData *event_viewer_data = (EventViewerData *)data; |
| 1213 | MainWindow * mw = event_viewer_data->mw; |
| 1214 | set_focused_pane(mw, gtk_widget_get_parent(event_viewer_data->hbox_v)); |
| 1215 | } |
| 1216 | |
| 1217 | void get_events(EventViewerData* event_viewer_data, LttTime start, |
| 1218 | LttTime end,unsigned max_num_events, unsigned * real_num_events) |
| 1219 | { |
| 1220 | int size; |
| 1221 | RawTraceData * data; |
| 1222 | context_add_hooks_api(event_viewer_data->mw, NULL, NULL, NULL, NULL, NULL, NULL, |
| 1223 | NULL, NULL, NULL,event_viewer_data->before_event_hooks,NULL); |
| 1224 | process_traceset_api(event_viewer_data->mw, start, end, max_num_events); |
| 1225 | context_remove_hooks_api(event_viewer_data->mw, NULL, NULL, NULL, NULL, NULL, NULL, |
| 1226 | NULL, NULL, NULL,event_viewer_data->before_event_hooks,NULL); |
| 1227 | |
| 1228 | size = event_viewer_data->raw_trace_data_queue_tmp->length; |
| 1229 | *real_num_events = size; |
| 1230 | if(size > 0){ |
| 1231 | int pid, tmpPid, i; |
| 1232 | GList * list, *tmpList; |
| 1233 | |
| 1234 | //if the queue is full, remove some data, keep the size of the queue constant |
| 1235 | while(event_viewer_data->raw_trace_data_queue->length + size > RESERVE_BIG_SIZE){ |
| 1236 | remove_item_from_queue(event_viewer_data->raw_trace_data_queue, |
| 1237 | event_viewer_data->append); |
| 1238 | } |
| 1239 | |
| 1240 | //update pid if it is not known |
| 1241 | if(event_viewer_data->raw_trace_data_queue->length > 0){ |
| 1242 | list = event_viewer_data->raw_trace_data_queue->head; |
| 1243 | tmpList = event_viewer_data->raw_trace_data_queue_tmp->head; |
| 1244 | if(event_viewer_data->append){ |
| 1245 | data = (RawTraceData*)g_list_nth_data(list, event_viewer_data->raw_trace_data_queue->length-1); |
| 1246 | pid = data->pid; |
| 1247 | data = (RawTraceData*)g_list_nth_data(tmpList, 0); |
| 1248 | tmpPid = data->pid; |
| 1249 | }else{ |
| 1250 | data = (RawTraceData*)g_list_nth_data(list, 0); |
| 1251 | pid = data->pid; |
| 1252 | data = (RawTraceData*)g_list_nth_data(tmpList, event_viewer_data->raw_trace_data_queue_tmp->length-1); |
| 1253 | tmpPid = data->pid; |
| 1254 | } |
| 1255 | |
| 1256 | if(pid == -1 && tmpPid != -1){ |
| 1257 | for(i=0;i<event_viewer_data->raw_trace_data_queue->length;i++){ |
| 1258 | data = (RawTraceData*)g_list_nth_data(list,i); |
| 1259 | if(data->pid == -1) data->pid = tmpPid; |
| 1260 | } |
| 1261 | }else if(pid != -1 && tmpPid == -1){ |
| 1262 | for(i=0;i<event_viewer_data->raw_trace_data_queue_tmp->length;i++){ |
| 1263 | data = (RawTraceData*)g_list_nth_data(tmpList,i); |
| 1264 | if(data->pid == -1) data->pid = pid; |
| 1265 | } |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | //add data from tmp queue into the queue |
| 1270 | event_viewer_data->number_of_events = event_viewer_data->raw_trace_data_queue->length |
| 1271 | + event_viewer_data->raw_trace_data_queue_tmp->length; |
| 1272 | if(event_viewer_data->append){ |
| 1273 | if(event_viewer_data->raw_trace_data_queue->length > 0) |
| 1274 | event_viewer_data->current_event_index = event_viewer_data->raw_trace_data_queue->length - 1; |
| 1275 | else event_viewer_data->current_event_index = 0; |
| 1276 | while((data = g_queue_pop_head(event_viewer_data->raw_trace_data_queue_tmp)) != NULL){ |
| 1277 | g_queue_push_tail(event_viewer_data->raw_trace_data_queue, data); |
| 1278 | } |
| 1279 | }else{ |
| 1280 | event_viewer_data->current_event_index += event_viewer_data->raw_trace_data_queue_tmp->length; |
| 1281 | while((data = g_queue_pop_tail(event_viewer_data->raw_trace_data_queue_tmp)) != NULL){ |
| 1282 | g_queue_push_head(event_viewer_data->raw_trace_data_queue, data); |
| 1283 | } |
| 1284 | } |
| 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | static void get_event_detail(LttEvent *e, LttField *f, GString * s) |
| 1289 | { |
| 1290 | LttType *type; |
| 1291 | LttField *element; |
| 1292 | char *name; |
| 1293 | int nb, i; |
| 1294 | |
| 1295 | type = ltt_field_type(f); |
| 1296 | switch(ltt_type_class(type)) { |
| 1297 | case LTT_INT: |
| 1298 | g_string_append_printf(s, " %ld", ltt_event_get_long_int(e,f)); |
| 1299 | break; |
| 1300 | |
| 1301 | case LTT_UINT: |
| 1302 | g_string_append_printf(s, " %lu", ltt_event_get_long_unsigned(e,f)); |
| 1303 | break; |
| 1304 | |
| 1305 | case LTT_FLOAT: |
| 1306 | g_string_append_printf(s, " %g", ltt_event_get_double(e,f)); |
| 1307 | break; |
| 1308 | |
| 1309 | case LTT_STRING: |
| 1310 | g_string_append_printf(s, " \"%s\"", ltt_event_get_string(e,f)); |
| 1311 | break; |
| 1312 | |
| 1313 | case LTT_ENUM: |
| 1314 | g_string_append_printf(s, " %s", ltt_enum_string_get(type, |
| 1315 | ltt_event_get_unsigned(e,f)-1)); |
| 1316 | break; |
| 1317 | |
| 1318 | case LTT_ARRAY: |
| 1319 | case LTT_SEQUENCE: |
| 1320 | g_string_append_printf(s, " {"); |
| 1321 | nb = ltt_event_field_element_number(e,f); |
| 1322 | element = ltt_field_element(f); |
| 1323 | for(i = 0 ; i < nb ; i++) { |
| 1324 | ltt_event_field_element_select(e,f,i); |
| 1325 | get_event_detail(e, element, s); |
| 1326 | } |
| 1327 | g_string_append_printf(s, " }"); |
| 1328 | break; |
| 1329 | |
| 1330 | case LTT_STRUCT: |
| 1331 | g_string_append_printf(s, " {"); |
| 1332 | nb = ltt_type_member_number(type); |
| 1333 | for(i = 0 ; i < nb ; i++) { |
| 1334 | element = ltt_field_member(f,i); |
| 1335 | ltt_type_member_type(type, i, &name); |
| 1336 | g_string_append_printf(s, " %s = ", name); |
| 1337 | get_event_detail(e, element, s); |
| 1338 | } |
| 1339 | g_string_append_printf(s, " }"); |
| 1340 | break; |
| 1341 | } |
| 1342 | |
| 1343 | } |
| 1344 | |
| 1345 | static void get_pid(unsigned * in, unsigned * out, char * s) |
| 1346 | { |
| 1347 | char * str; |
| 1348 | str = strstr(s, "out ="); |
| 1349 | if (str){ |
| 1350 | str = str + 5; |
| 1351 | sscanf(str,"%d", out); |
| 1352 | }else{ |
| 1353 | g_warning("Can not find out pid\n"); |
| 1354 | } |
| 1355 | |
| 1356 | str = strstr(s,"in ="); |
| 1357 | if (str){ |
| 1358 | str = str + 4; |
| 1359 | sscanf(str,"%d", in); |
| 1360 | }else{ |
| 1361 | g_warning("Can not find in pid\n"); |
| 1362 | } |
| 1363 | } |
| 1364 | |
| 1365 | gboolean parse_event(void *hook_data, void *call_data) |
| 1366 | { |
| 1367 | EventViewerData *event_viewer_data = (EventViewerData *)hook_data; |
| 1368 | LttvTracefileContext *tfc = (LttvTracefileContext *)call_data; |
| 1369 | LttvTracefileState *tfs = (LttvTracefileState *)call_data; |
| 1370 | |
| 1371 | RawTraceData * tmp_raw_trace_data,*prev_raw_trace_data = NULL, *data=NULL; |
| 1372 | LttEvent *e; |
| 1373 | LttTime time; |
| 1374 | LttField * field; |
| 1375 | unsigned in=0, out=0; |
| 1376 | int i; |
| 1377 | GString * detail_event = g_string_new(""); |
| 1378 | GList * list; |
| 1379 | |
| 1380 | e = tfc->e; |
| 1381 | field = ltt_event_field(e); |
| 1382 | time = ltt_event_time(e); |
| 1383 | |
| 1384 | if(event_viewer_data->raw_trace_data_queue_tmp->length){ |
| 1385 | list = g_list_last(event_viewer_data->raw_trace_data_queue_tmp->head); |
| 1386 | prev_raw_trace_data = (RawTraceData *)(list->data); |
| 1387 | } |
| 1388 | |
| 1389 | tmp_raw_trace_data = g_new(RawTraceData,1); |
| 1390 | tmp_raw_trace_data->cpu_id = ltt_event_cpu_id(e); |
| 1391 | tmp_raw_trace_data->event_name = g_strdup(ltt_eventtype_name(ltt_event_eventtype(e))); |
| 1392 | tmp_raw_trace_data->time = time; |
| 1393 | tmp_raw_trace_data->ep = ltt_event_position_new(); |
| 1394 | |
| 1395 | if(prev_raw_trace_data) tmp_raw_trace_data->pid = prev_raw_trace_data->pid; |
| 1396 | else tmp_raw_trace_data->pid = -1; |
| 1397 | |
| 1398 | tmp_raw_trace_data->entry_length = field == NULL ? 0 : ltt_field_size(field); |
| 1399 | if(field) get_event_detail(e, field, detail_event); |
| 1400 | tmp_raw_trace_data->event_description = g_strdup(detail_event->str); |
| 1401 | |
| 1402 | if(strcmp(tmp_raw_trace_data->event_name, "schedchange") == 0){ |
| 1403 | get_pid(&in, &out, detail_event->str); |
| 1404 | } |
| 1405 | |
| 1406 | |
| 1407 | if(in != 0 || out != 0){ |
| 1408 | tmp_raw_trace_data->pid = in; |
| 1409 | if(prev_raw_trace_data && prev_raw_trace_data->pid == -1){ |
| 1410 | list = event_viewer_data->raw_trace_data_queue_tmp->head; |
| 1411 | for(i=0;i<event_viewer_data->raw_trace_data_queue_tmp->length;i++){ |
| 1412 | data = (RawTraceData *)g_list_nth_data(list,i); |
| 1413 | data->pid = out; |
| 1414 | } |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | ltt_event_position(e, tmp_raw_trace_data->ep); |
| 1419 | |
| 1420 | if(event_viewer_data->raw_trace_data_queue_tmp->length >= RESERVE_SMALL_SIZE){ |
| 1421 | if(event_viewer_data->append){ |
| 1422 | list = g_list_last(event_viewer_data->raw_trace_data_queue_tmp->head); |
| 1423 | data = (RawTraceData *)(list->data); |
| 1424 | if(data->time.tv_sec == time.tv_sec && |
| 1425 | data->time.tv_nsec == time.tv_nsec){ |
| 1426 | g_queue_push_tail(event_viewer_data->raw_trace_data_queue_tmp,tmp_raw_trace_data); |
| 1427 | }else{ |
| 1428 | g_free(tmp_raw_trace_data); |
| 1429 | } |
| 1430 | }else{ |
| 1431 | remove_item_from_queue(event_viewer_data->raw_trace_data_queue_tmp,TRUE); |
| 1432 | g_queue_push_tail(event_viewer_data->raw_trace_data_queue_tmp,tmp_raw_trace_data); |
| 1433 | } |
| 1434 | }else{ |
| 1435 | g_queue_push_tail (event_viewer_data->raw_trace_data_queue_tmp,tmp_raw_trace_data); |
| 1436 | } |
| 1437 | |
| 1438 | g_string_free(detail_event, TRUE); |
| 1439 | |
| 1440 | return FALSE; |
| 1441 | } |
| 1442 | |
| 1443 | void remove_item_from_queue(GQueue * q, gboolean fromHead) |
| 1444 | { |
| 1445 | RawTraceData *data1, *data2 = NULL; |
| 1446 | GList * list; |
| 1447 | |
| 1448 | if(fromHead){ |
| 1449 | data1 = (RawTraceData *)g_queue_pop_head(q); |
| 1450 | list = g_list_first(q->head); |
| 1451 | if(list) |
| 1452 | data2 = (RawTraceData *)(list->data); |
| 1453 | }else{ |
| 1454 | data1 = (RawTraceData *)g_queue_pop_tail(q); |
| 1455 | list = g_list_last(q->head); |
| 1456 | if(list) |
| 1457 | data2 = (RawTraceData *)(list->data); |
| 1458 | } |
| 1459 | |
| 1460 | if(data2){ |
| 1461 | if(data1->time.tv_sec == data2->time.tv_sec && |
| 1462 | data1->time.tv_nsec == data2->time.tv_nsec){ |
| 1463 | remove_item_from_queue(q, fromHead); |
| 1464 | } |
| 1465 | } |
| 1466 | |
| 1467 | g_free(data1); |
| 1468 | |
| 1469 | return; |
| 1470 | } |
| 1471 | |
| 1472 | void remove_all_items_from_queue(GQueue *q) |
| 1473 | { |
| 1474 | RawTraceData *data; |
| 1475 | while((data = (RawTraceData *)g_queue_pop_head(q)) != NULL){ |
| 1476 | g_free(data); |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | |