1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Mathieu Desnoyers and XangXiu Yang
3 * 2005 Mathieu Desnoyers
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License Version 2 as
7 * published by the Free Software Foundation;
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 //*! \defgroup GuiEvents libGuiEvents: The GUI Events display plugin */
25 * \brief Graphical plugin for showing events.
27 * This plugin lists all the events contained in the current time interval
30 * This plugin adds a Events Viewer functionnality to Linux TraceToolkit
31 * GUI when this plugin is loaded. The init and destroy functions add the
32 * viewer's insertion menu item and toolbar icon by calling viewer.h's
33 * API functions. Then, when a viewer's object is created, the constructor
34 * creates ans register through API functions what is needed to interact
35 * with the lttvwindow.
37 * Authors : Mathieu Desnoyers and XangXiu Yang, June to December 2003
38 * Inspired from original LTT, made by Karim Yaghmour
40 * Mostly rewritten by Mathieu Desnoyers, August 2005.
56 #include <ltt/event.h>
58 #include <ltt/trace.h>
59 #include <ltt/facility.h>
60 #include <lttv/module.h>
61 #include <lttv/hook.h>
62 #include <lttv/tracecontext.h>
63 #include <lttv/state.h>
64 #include <lttv/filter.h>
65 #include <lttv/print.h>
66 #include <lttvwindow/lttvwindow.h>
67 #include <lttvwindow/lttvwindowtraces.h>
68 #include <lttvwindow/lttv_plugin_tab.h>
70 #include "hGuiEventsInsert.xpm"
72 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
75 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
78 #define abs(a) (((a)<0)?(-a):(a))
79 #define max(a,b) ((a)>(b)?(a):(b))
80 #define min(a,b) ((a)<(b)?(a):(b))
82 /** Array containing instanced objects. Used when module is unloaded */
83 static GSList *g_event_viewer_data_list = NULL ;
85 typedef enum _ScrollDirection{
94 typedef struct _EventViewerData {
98 LttvHooks * event_hooks;
100 /* previous value is used to determine if it is a page up/down or
101 * step up/down, in which case we move of a certain amount of events (one or
102 * the number of events shown on the screen) instead of changing begin time.
104 double previous_value;
106 //scroll window containing Tree View
107 GtkWidget * scroll_win;
109 /* Model containing list data */
110 GtkListStore *store_m;
112 GPtrArray *pos; /* Array of LttvTracesetContextPosition * */
114 GtkWidget *top_widget;
116 /* Widget to display the data in a columned list */
118 GtkAdjustment *vtree_adjust_c ;
119 GtkWidget *button; /* a button of the header, used to get the header_height */
122 /* Vertical scrollbar and its adjustment */
123 GtkWidget *vscroll_vc;
124 GtkAdjustment *vadjust_c;
126 /* Selection handler */
127 GtkTreeSelection *select_c;
129 gint num_visible_events;
131 LttvTracesetContextPosition *currently_selected_position;
132 gboolean update_cursor; /* Speed optimisation : do not update cursor when
134 gboolean report_position; /* do not report position when in current_time
137 LttvTracesetContextPosition *first_event; /* Time of the first event shown */
138 LttvTracesetContextPosition *last_event; /* Time of the first event shown */
140 LttvTracesetContextPosition *current_time_get_first;
142 LttvFilter *main_win_filter;
144 gint background_info_waiting;
146 guint32 last_tree_update_time; /* To filter out repeat keys */
148 guint num_events; /* Number of events processed */
152 /** hook functions for update time interval, current time ... */
153 gboolean update_current_time(void * hook_data, void * call_data);
154 gboolean update_current_position(void * hook_data, void * call_data);
155 //gboolean show_event_detail(void * hook_data, void * call_data);
156 gboolean traceset_changed(void * hook_data, void * call_data);
157 gboolean filter_changed(void * hook_data, void * call_data);
159 static void request_background_data(EventViewerData *event_viewer_data);
161 //! Event Viewer's constructor hook
162 GtkWidget *h_gui_events(LttvPlugin *plugin);
163 //! Event Viewer's constructor
164 EventViewerData *gui_events(LttvPluginTab *ptab);
165 //! Event Viewer's destructor
166 void gui_events_destructor(EventViewerData *event_viewer_data);
167 void gui_events_free(EventViewerData *event_viewer_data);
170 header_size_allocate(GtkWidget *widget,
171 GtkAllocation *allocation,
174 void tree_v_set_cursor(EventViewerData *event_viewer_data);
175 void tree_v_get_cursor(EventViewerData *event_viewer_data);
177 /* Prototype for selection handler callback */
178 static void tree_selection_changed_cb (GtkTreeSelection *selection,
180 static void v_scroll_cb (GtkAdjustment *adjustment, gpointer data);
181 static void tree_v_size_allocate_cb (GtkWidget *widget, GtkAllocation *alloc,
183 static void tree_v_size_request_cb (GtkWidget *widget,
184 GtkRequisition *requisition, gpointer data);
185 static void tree_v_cursor_changed_cb (GtkWidget *widget, gpointer data);
186 static void tree_v_move_cursor_cb (GtkWidget *widget, GtkMovementStep arg1,
187 gint arg2, gpointer data);
188 static gboolean tree_v_scroll_handler (GtkWidget *widget, GdkEventScroll *event, gpointer data);
189 static gboolean key_handler(GtkWidget *widget, GdkEventKey *event,
192 static gint redraw_notify(void *hook_data, void *call_data);
194 static void get_events(double time, EventViewerData *event_viewer_data);
196 int event_hook(void *hook_data, void *call_data);
198 /* Enumeration of the columns */
202 TRACEFILE_NAME_COLUMN,
215 * Event Viewer's constructor hook
217 * This constructor is given as a parameter to the menuitem and toolbar button
218 * registration. It creates the list.
219 * @param parent_window A pointer to the parent window.
220 * @return The widget created.
223 h_gui_events(LttvPlugin *plugin)
225 LttvPluginTab *ptab = LTTV_PLUGIN_TAB(plugin);
226 EventViewerData* event_viewer_data = gui_events(ptab) ;
227 if(event_viewer_data)
228 return event_viewer_data->top_widget;
234 * Event Viewer's constructor
236 * This constructor is used to create EventViewerData data structure.
237 * @return The Event viewer data created.
240 gui_events(LttvPluginTab *ptab)
243 GtkTreeViewColumn *column;
244 GtkCellRenderer *renderer;
245 EventViewerData* event_viewer_data = g_new(EventViewerData,1) ;
246 Tab *tab = ptab->tab;
247 event_viewer_data->tab = tab;
248 event_viewer_data->ptab = ptab;
250 LttvTracesetContext * tsc =
251 lttvwindow_get_traceset_context(event_viewer_data->tab);
254 event_viewer_data->event_hooks = lttv_hooks_new();
255 lttv_hooks_add(event_viewer_data->event_hooks,
260 lttvwindow_register_current_time_notify(tab,
261 update_current_time,event_viewer_data);
262 lttvwindow_register_current_position_notify(tab,
263 update_current_position,event_viewer_data);
264 lttvwindow_register_traceset_notify(tab,
265 traceset_changed,event_viewer_data);
266 lttvwindow_register_filter_notify(tab,
267 filter_changed, event_viewer_data);
268 lttvwindow_register_redraw_notify(tab,
269 redraw_notify, event_viewer_data);
272 event_viewer_data->scroll_win = gtk_scrolled_window_new (NULL, NULL);
273 gtk_widget_show (event_viewer_data->scroll_win);
274 gtk_scrolled_window_set_policy(
275 GTK_SCROLLED_WINDOW(event_viewer_data->scroll_win),
276 GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
278 event_viewer_data->currently_selected_position =
279 lttv_traceset_context_position_new(tsc);
280 event_viewer_data->first_event =
281 lttv_traceset_context_position_new(tsc);
282 event_viewer_data->last_event =
283 lttv_traceset_context_position_new(tsc);
285 event_viewer_data->main_win_filter = lttvwindow_get_filter(tab);
287 event_viewer_data->update_cursor = TRUE;
288 event_viewer_data->report_position = TRUE;
290 event_viewer_data->last_tree_update_time = 0;
292 /* Create a model for storing the data list */
293 event_viewer_data->store_m = gtk_list_store_new (
294 N_COLUMNS, /* Total number of columns */
295 G_TYPE_STRING, /* Trace name */
296 G_TYPE_STRING, /* Tracefile name */
297 G_TYPE_UINT, /* CPUID */
298 G_TYPE_STRING, /* Event */
299 G_TYPE_STRING, /* Facility */
300 G_TYPE_UINT, /* Time s */
301 G_TYPE_UINT, /* Time ns */
302 G_TYPE_INT, /* PID */
303 G_TYPE_STRING, /* Event's description */
304 G_TYPE_POINTER);/* Position (not shown) */
306 event_viewer_data->pos = g_ptr_array_sized_new(10);
308 /* Create the viewer widget for the columned list */
309 event_viewer_data->tree_v =
310 gtk_tree_view_new_with_model (GTK_TREE_MODEL (event_viewer_data->store_m));
312 g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "size-allocate",
313 G_CALLBACK (tree_v_size_allocate_cb),
315 g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "size-request",
316 G_CALLBACK (tree_v_size_request_cb),
319 g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "cursor-changed",
320 G_CALLBACK (tree_v_cursor_changed_cb),
323 g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "move-cursor",
324 G_CALLBACK (tree_v_move_cursor_cb),
327 g_signal_connect (G_OBJECT(event_viewer_data->tree_v), "key-press-event",
328 G_CALLBACK(key_handler),
331 g_signal_connect (G_OBJECT(event_viewer_data->tree_v), "scroll-event",
332 G_CALLBACK(tree_v_scroll_handler),
335 // Use on each column!
336 //gtk_tree_view_column_set_sizing(event_viewer_data->tree_v,
337 //GTK_TREE_VIEW_COLUMN_FIXED);
339 /* The view now holds a reference. We can get rid of our own
341 g_object_unref (G_OBJECT (event_viewer_data->store_m));
344 /* Create a column, associating the "text" attribute of the
345 * cell_renderer to the first column of the model */
346 /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */
347 renderer = gtk_cell_renderer_text_new ();
348 column = gtk_tree_view_column_new_with_attributes ("Trace",
350 "text", TRACE_NAME_COLUMN,
352 gtk_tree_view_column_set_alignment (column, 0.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),
357 event_viewer_data->button = column->button;
359 g_signal_connect (G_OBJECT(event_viewer_data->button),
361 G_CALLBACK(header_size_allocate),
362 (gpointer)event_viewer_data);
366 renderer = gtk_cell_renderer_text_new ();
367 column = gtk_tree_view_column_new_with_attributes ("Tracefile",
369 "text", TRACEFILE_NAME_COLUMN,
371 gtk_tree_view_column_set_alignment (column, 0.0);
372 gtk_tree_view_column_set_fixed_width (column, 120);
373 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v),
377 renderer = gtk_cell_renderer_text_new ();
378 column = gtk_tree_view_column_new_with_attributes ("CPUID",
380 "text", CPUID_COLUMN,
382 gtk_tree_view_column_set_alignment (column, 0.0);
383 gtk_tree_view_column_set_fixed_width (column, 45);
384 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v),
387 renderer = gtk_cell_renderer_text_new ();
388 column = gtk_tree_view_column_new_with_attributes ("Event",
390 "text", EVENT_COLUMN,
392 gtk_tree_view_column_set_alignment (column, 0.0);
393 gtk_tree_view_column_set_fixed_width (column, 120);
394 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v),
397 renderer = gtk_cell_renderer_text_new ();
398 column = gtk_tree_view_column_new_with_attributes ("Facility",
400 "text", FACILITY_COLUMN,
402 gtk_tree_view_column_set_alignment (column, 0.0);
403 gtk_tree_view_column_set_fixed_width (column, 120);
404 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v),
407 renderer = gtk_cell_renderer_text_new ();
408 column = gtk_tree_view_column_new_with_attributes ("Time (s)",
410 "text", TIME_S_COLUMN,
412 gtk_tree_view_column_set_alignment (column, 1.0);
413 gtk_tree_view_column_set_fixed_width (column, 120);
414 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v),
417 renderer = gtk_cell_renderer_text_new ();
418 column = gtk_tree_view_column_new_with_attributes ("Time (ns)",
420 "text", TIME_NS_COLUMN,
422 gtk_tree_view_column_set_alignment (column, 1.0);
423 gtk_tree_view_column_set_fixed_width (column, 120);
424 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v),
428 renderer = gtk_cell_renderer_text_new ();
429 column = gtk_tree_view_column_new_with_attributes ("PID",
433 gtk_tree_view_column_set_alignment (column, 1.0);
434 gtk_tree_view_column_set_fixed_width (column, 45);
435 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v),
438 renderer = gtk_cell_renderer_text_new ();
439 column = gtk_tree_view_column_new_with_attributes ("Event Description",
441 "text", EVENT_DESCR_COLUMN,
443 gtk_tree_view_column_set_alignment (column, 0.0);
444 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v),
448 /* Setup the selection handler */
449 event_viewer_data->select_c =
450 gtk_tree_view_get_selection (GTK_TREE_VIEW (event_viewer_data->tree_v));
451 gtk_tree_selection_set_mode (event_viewer_data->select_c,
452 GTK_SELECTION_SINGLE);
453 g_signal_connect (G_OBJECT (event_viewer_data->select_c), "changed",
454 G_CALLBACK (tree_selection_changed_cb),
457 gtk_container_add (GTK_CONTAINER (event_viewer_data->scroll_win),
458 event_viewer_data->tree_v);
460 event_viewer_data->hbox_v = gtk_hbox_new(0, 0);
461 event_viewer_data->top_widget = event_viewer_data->hbox_v;
462 gtk_box_pack_start(GTK_BOX(event_viewer_data->hbox_v),
463 event_viewer_data->scroll_win, TRUE, TRUE, 0);
465 gtk_container_set_border_width(GTK_CONTAINER(event_viewer_data->hbox_v), 1);
467 /* Create vertical scrollbar and pack it */
468 event_viewer_data->vscroll_vc = gtk_vscrollbar_new(NULL);
469 gtk_range_set_update_policy (GTK_RANGE(event_viewer_data->vscroll_vc),
470 GTK_UPDATE_CONTINUOUS);
471 // Changed by MD : more user friendly :)
472 //GTK_UPDATE_DISCONTINUOUS);
473 gtk_box_pack_start(GTK_BOX(event_viewer_data->hbox_v),
474 event_viewer_data->vscroll_vc, FALSE, TRUE, 0);
476 /* Get the vertical scrollbar's adjustment */
477 event_viewer_data->vadjust_c =
478 gtk_range_get_adjustment(GTK_RANGE(event_viewer_data->vscroll_vc));
479 event_viewer_data->vtree_adjust_c = gtk_tree_view_get_vadjustment(
480 GTK_TREE_VIEW (event_viewer_data->tree_v));
482 g_signal_connect (G_OBJECT (event_viewer_data->vadjust_c), "value-changed",
483 G_CALLBACK (v_scroll_cb),
485 /* Set the upper bound to the last event number */
486 event_viewer_data->previous_value = 0;
487 event_viewer_data->vadjust_c->lower = 0.0;
488 //event_viewer_data->vadjust_c->upper = event_viewer_data->number_of_events;
489 event_viewer_data->vadjust_c->value = 0.0;
490 event_viewer_data->vadjust_c->step_increment = 1.0;
491 event_viewer_data->vadjust_c->page_increment = 2.0;
492 // event_viewer_data->vtree_adjust_c->upper;
493 event_viewer_data->vadjust_c->page_size = 2.0;
494 // event_viewer_data->vtree_adjust_c->upper;
495 /* Raw event trace */
496 gtk_widget_show(event_viewer_data->hbox_v);
497 gtk_widget_show(event_viewer_data->tree_v);
498 gtk_widget_show(event_viewer_data->vscroll_vc);
500 /* Add the object's information to the module's array */
501 g_event_viewer_data_list = g_slist_append(g_event_viewer_data_list,
504 event_viewer_data->num_visible_events = 1;
506 //get the life span of the traceset and set the upper of the scroll bar
508 TimeInterval time_span = tsc->time_span;
509 end = ltt_time_sub(time_span.end_time, time_span.start_time);
511 event_viewer_data->vadjust_c->upper =
512 ltt_time_to_double(end);
514 /* Set the Selected Event */
515 // tree_v_set_cursor(event_viewer_data);
517 // event_viewer_data->current_time_updated = FALSE;
519 g_object_set_data_full(
520 G_OBJECT(event_viewer_data->hbox_v),
523 (GDestroyNotify)gui_events_free);
525 event_viewer_data->background_info_waiting = 0;
527 request_background_data(event_viewer_data);
530 return event_viewer_data;
535 static gint background_ready(void *hook_data, void *call_data)
537 EventViewerData *event_viewer_data = (EventViewerData *)hook_data;
538 LttvTrace *trace = (LttvTrace*)call_data;
540 event_viewer_data->background_info_waiting--;
542 if(event_viewer_data->background_info_waiting == 0) {
543 g_message("event viewer : background computation data ready.");
545 redraw_notify(event_viewer_data, NULL);
552 static void request_background_data(EventViewerData *event_viewer_data)
554 LttvTracesetContext * tsc =
555 lttvwindow_get_traceset_context(event_viewer_data->tab);
556 gint num_traces = lttv_traceset_number(tsc->ts);
559 LttvTraceState *tstate;
561 LttvHooks *background_ready_hook =
563 lttv_hooks_add(background_ready_hook, background_ready, event_viewer_data,
565 event_viewer_data->background_info_waiting = 0;
567 for(i=0;i<num_traces;i++) {
568 trace = lttv_traceset_get(tsc->ts, i);
569 tstate = LTTV_TRACE_STATE(tsc->traces[i]);
571 if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace)==FALSE
572 && !tstate->has_precomputed_states) {
574 if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"),
576 /* We first remove requests that could have been done for the same
577 * information. Happens when two viewers ask for it before servicing
580 if(!lttvwindowtraces_background_request_find(trace, "state"))
581 lttvwindowtraces_background_request_queue(
582 main_window_get_widget(event_viewer_data->tab), trace, "state");
583 lttvwindowtraces_background_notify_queue(event_viewer_data,
587 background_ready_hook);
588 event_viewer_data->background_info_waiting++;
589 } else { /* in progress */
591 lttvwindowtraces_background_notify_current(event_viewer_data,
595 background_ready_hook);
596 event_viewer_data->background_info_waiting++;
599 /* Data ready. By its nature, this viewer doesn't need to have
600 * its data ready hook called htere, because a background
601 * request is always linked with a redraw.
607 lttv_hooks_destroy(background_ready_hook);
612 header_size_allocate(GtkWidget *widget,
613 GtkAllocation *allocation,
616 EventViewerData *event_viewer_data = (EventViewerData*)user_data;
618 event_viewer_data->header_height = allocation->height;
624 void tree_v_set_cursor(EventViewerData *event_viewer_data)
628 g_debug("set cursor cb");
631 if(event_viewer_data->currently_selected_event != -1)
633 path = gtk_tree_path_new_from_indices(
634 event_viewer_data->currently_selected_event,
637 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
639 gtk_tree_path_free(path);
644 void tree_v_get_cursor(EventViewerData *event_viewer_data)
649 g_debug("get cursor cb");
653 gtk_tree_view_get_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
655 indices = gtk_tree_path_get_indices(path);
658 event_viewer_data->currently_selected_event = indices[0];
660 event_viewer_data->currently_selected_event = -1;
662 gtk_tree_path_free(path);
666 /* Filter out the key repeats that come too fast */
667 static gboolean key_handler(GtkWidget *widget, GdkEventKey *event,
670 EventViewerData *evd = (EventViewerData *)user_data;
672 g_debug("event time : %u , last time : %u", event->time,
673 evd->last_tree_update_time);
675 if(guint32_before(event->time, evd->last_tree_update_time))
681 void tree_v_move_cursor_cb (GtkWidget *widget,
682 GtkMovementStep arg1,
686 GtkTreePath *path; // = gtk_tree_path_new();
689 EventViewerData *event_viewer_data = (EventViewerData*)data;
691 g_debug("move cursor cb");
692 //gtk_tree_view_get_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
696 /* No prior cursor, put it at beginning of page
697 * and let the execution do */
698 // path = gtk_tree_path_new_from_indices(0, -1);
699 // gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
700 // path, NULL, FALSE);
703 //indices = gtk_tree_path_get_indices(path);
705 //value = gtk_adjustment_get_value(event_viewer_data->vadjust_c);
707 /* If events request pending, do nothing*/
708 if(lttvwindow_events_request_pending(event_viewer_data->tab)) return;
710 /* If no prior position... */
713 lttv_traceset_context_position_get_time(
714 event_viewer_data->currently_selected_position),
715 ltt_time_infinite) == 0) {
717 path = gtk_tree_path_new_from_indices(0, -1);
718 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
721 gtk_tree_path_free(path);
727 g_debug("tree view move cursor : arg1 is %u and arg2 is %d",
731 case GTK_MOVEMENT_DISPLAY_LINES:
733 /* Move one line down */
734 if(event_viewer_data->pos->len > 0) {
735 LttvTracesetContextPosition *end_pos =
736 (LttvTracesetContextPosition*)g_ptr_array_index(
737 event_viewer_data->pos,
738 event_viewer_data->pos->len-1);
739 if(lttv_traceset_context_pos_pos_compare(end_pos,
740 event_viewer_data->currently_selected_position) == 0) {
741 /* Must get down one event and select the last one */
742 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(
743 GTK_TREE_VIEW(event_viewer_data->tree_v)));
744 event_viewer_data->update_cursor = FALSE;
745 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
746 gtk_adjustment_get_value(event_viewer_data->vadjust_c) + 1);
747 event_viewer_data->update_cursor = TRUE;
748 if(event_viewer_data->pos->len > 0) {
749 path = gtk_tree_path_new_from_indices(
750 max(0, event_viewer_data->pos->len - 1), -1);
752 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
754 gtk_tree_path_free(path);
759 /* Must get down one event and select the last one */
760 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(
761 GTK_TREE_VIEW(event_viewer_data->tree_v)));
762 event_viewer_data->update_cursor = FALSE;
763 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
764 gtk_adjustment_get_value(event_viewer_data->vadjust_c) + 1);
765 event_viewer_data->update_cursor = TRUE;
766 if(event_viewer_data->pos->len > 0) {
767 path = gtk_tree_path_new_from_indices(
768 max(0, event_viewer_data->pos->len - 1), -1);
770 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
772 gtk_tree_path_free(path);
778 if(event_viewer_data->pos->len > 0) {
779 /* Move one line up */
780 LttvTracesetContextPosition *begin_pos =
781 (LttvTracesetContextPosition*)g_ptr_array_index(
782 event_viewer_data->pos,
784 if(lttv_traceset_context_pos_pos_compare(begin_pos,
785 event_viewer_data->currently_selected_position) == 0) {
786 /* Must get up one event and select the first one */
787 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(
788 GTK_TREE_VIEW(event_viewer_data->tree_v)));
789 event_viewer_data->update_cursor = FALSE;
790 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
791 gtk_adjustment_get_value(event_viewer_data->vadjust_c) - 1);
792 event_viewer_data->update_cursor = TRUE;
793 if(event_viewer_data->pos->len > 0) {
794 path = gtk_tree_path_new_from_indices(
797 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
799 gtk_tree_path_free(path);
804 /* Must get up one event and select the first one */
805 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(
806 GTK_TREE_VIEW(event_viewer_data->tree_v)));
807 event_viewer_data->update_cursor = FALSE;
808 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
809 gtk_adjustment_get_value(event_viewer_data->vadjust_c) - 1);
810 event_viewer_data->update_cursor = TRUE;
811 if(event_viewer_data->pos->len > 0) {
812 path = gtk_tree_path_new_from_indices(
815 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
817 gtk_tree_path_free(path);
823 case GTK_MOVEMENT_PAGES:
825 /* Move one page down */
826 if(event_viewer_data->pos->len > 0) {
827 LttvTracesetContextPosition *end_pos =
828 (LttvTracesetContextPosition*)g_ptr_array_index(
829 event_viewer_data->pos,
830 event_viewer_data->pos->len-1);
831 if(lttv_traceset_context_pos_pos_compare(end_pos,
832 event_viewer_data->currently_selected_position) == 0) {
833 /* Must get down one page and select the last one */
834 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(
835 GTK_TREE_VIEW(event_viewer_data->tree_v)));
836 event_viewer_data->update_cursor = FALSE;
837 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
838 gtk_adjustment_get_value(event_viewer_data->vadjust_c) + 2);
839 event_viewer_data->update_cursor = TRUE;
840 if(event_viewer_data->pos->len > 0) {
841 path = gtk_tree_path_new_from_indices(
842 event_viewer_data->pos->len - 1, -1);
844 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
846 gtk_tree_path_free(path);
851 /* Must get down one page and select the last one */
852 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(
853 GTK_TREE_VIEW(event_viewer_data->tree_v)));
854 event_viewer_data->update_cursor = FALSE;
855 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
856 gtk_adjustment_get_value(event_viewer_data->vadjust_c) + 2);
857 event_viewer_data->update_cursor = TRUE;
858 if(event_viewer_data->pos->len > 0) {
859 path = gtk_tree_path_new_from_indices(
860 event_viewer_data->pos->len - 1, -1);
862 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
864 gtk_tree_path_free(path);
869 /* Move one page up */
870 if(event_viewer_data->pos->len > 0) {
871 LttvTracesetContextPosition *begin_pos =
872 (LttvTracesetContextPosition*)g_ptr_array_index(
873 event_viewer_data->pos,
875 if(lttv_traceset_context_pos_pos_compare(begin_pos,
876 event_viewer_data->currently_selected_position) == 0) {
877 /* Must get up one page and select the first one */
878 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(
879 GTK_TREE_VIEW(event_viewer_data->tree_v)));
880 event_viewer_data->update_cursor = FALSE;
881 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
882 gtk_adjustment_get_value(event_viewer_data->vadjust_c) - 2);
883 event_viewer_data->update_cursor = TRUE;
884 if(event_viewer_data->pos->len > 0) {
885 path = gtk_tree_path_new_from_indices(
888 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
890 gtk_tree_path_free(path);
895 /* Must get up one page and select the first one */
896 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(
897 GTK_TREE_VIEW(event_viewer_data->tree_v)));
898 event_viewer_data->update_cursor = FALSE;
899 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
900 gtk_adjustment_get_value(event_viewer_data->vadjust_c) - 2);
901 event_viewer_data->update_cursor = TRUE;
902 if(event_viewer_data->pos->len > 0) {
903 path = gtk_tree_path_new_from_indices(
906 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
908 gtk_tree_path_free(path);
918 //gtk_tree_path_free(path);
921 if(arg1 == GTK_MOVEMENT_DISPLAY_LINES)
926 /* move one line down */
927 if(indices[0]) // Do we need an empty field here (before first)?
929 if(value + event_viewer_data->num_visible_events <=
930 event_viewer_data->number_of_events -1)
932 event_viewer_data->currently_selected_event += 1;
933 // gtk_adjustment_set_value(event_viewer_data->vadjust_c, value+1);
934 //gtk_tree_path_free(path);
935 //path = gtk_tree_path_new_from_indices(event_viewer_data->num_visible_events-1, -1);
936 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
937 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
941 /* Move one line up */
946 event_viewer_data->currently_selected_event -= 1;
947 // gtk_adjustment_set_value(event_viewer_data->vadjust_c, value-1);
948 //gtk_tree_path_free(path);
949 //path = gtk_tree_path_new_from_indices(0, -1);
950 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
951 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
957 if(arg1 == GTK_MOVEMENT_PAGES)
962 if(event_viewer_data->num_visible_events == 1)
964 /* move one page down */
965 if(value + event_viewer_data->num_visible_events-1 <=
966 event_viewer_data->number_of_events )
968 event_viewer_data->currently_selected_event +=
969 event_viewer_data->num_visible_events-1;
970 // gtk_adjustment_set_value(event_viewer_data->vadjust_c,
971 // value+(event_viewer_data->num_visible_events-1));
972 //gtk_tree_path_free(path);
973 //path = gtk_tree_path_new_from_indices(0, -1);
974 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
975 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
978 /* Move one page up */
979 if(event_viewer_data->num_visible_events == 1)
982 if(indices[0] < event_viewer_data->num_visible_events - 2 )
984 if(value - (event_viewer_data->num_visible_events-1) >= 0)
986 event_viewer_data->currently_selected_event -=
987 event_viewer_data->num_visible_events-1;
989 // gtk_adjustment_set_value(event_viewer_data->vadjust_c,
990 // value-(event_viewer_data->num_visible_events-1));
991 //gtk_tree_path_free(path);
992 //path = gtk_tree_path_new_from_indices(0, -1);
993 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
994 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
997 /* Go to first Event */
998 event_viewer_data->currently_selected_event == 0 ;
999 // gtk_adjustment_set_value(event_viewer_data->vadjust_c,
1001 //gtk_tree_path_free(path);
1002 //path = gtk_tree_path_new_from_indices(0, -1);
1003 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
1004 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
1011 if(arg1 == GTK_MOVEMENT_BUFFER_ENDS)
1013 /* Move to the ends of the buffer */
1016 /* move end of buffer */
1017 event_viewer_data->currently_selected_event =
1018 event_viewer_data->number_of_events-1 ;
1019 // gtk_adjustment_set_value(event_viewer_data->vadjust_c,
1020 // event_viewer_data->number_of_events -
1021 // event_viewer_data->num_visible_events);
1022 //gtk_tree_path_free(path);
1023 //path = gtk_tree_path_new_from_indices(event_viewer_data->num_visible_events-1, -1);
1024 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
1025 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
1027 /* Move beginning of buffer */
1028 event_viewer_data->currently_selected_event = 0 ;
1029 // gtk_adjustment_set_value(event_viewer_data->vadjust_c, 0);
1030 //gtk_tree_path_free(path);
1031 //path = gtk_tree_path_new_from_indices(0, -1);
1032 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
1033 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
1040 gboolean tree_v_scroll_handler (GtkWidget *widget, GdkEventScroll *event, gpointer data)
1042 EventViewerData *event_viewer_data = (EventViewerData*) data;
1043 Tab *tab = event_viewer_data->tab;
1045 switch(event->direction) {
1047 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
1048 gtk_adjustment_get_value(event_viewer_data->vadjust_c) - 1);
1050 case GDK_SCROLL_DOWN:
1051 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
1052 gtk_adjustment_get_value(event_viewer_data->vadjust_c) + 1);
1055 g_error("Only scroll up and down expected");
1060 void tree_v_cursor_changed_cb (GtkWidget *widget, gpointer data)
1062 EventViewerData *event_viewer_data = (EventViewerData*) data;
1063 Tab *tab = event_viewer_data->tab;
1065 GtkTreeModel* model = GTK_TREE_MODEL(event_viewer_data->store_m);
1067 LttvTracesetContextPosition *pos;
1069 g_debug("cursor changed cb");
1071 /* On cursor change, modify the currently selected event by calling
1072 * the right API function */
1073 if(event_viewer_data->report_position) {
1074 if(event_viewer_data->pos->len > 0) {
1075 gtk_tree_view_get_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
1078 if(gtk_tree_model_get_iter(model,&iter,path)){
1079 gtk_tree_model_get(model, &iter, POSITION_COLUMN, &pos, -1);
1081 if(lttv_traceset_context_pos_pos_compare(pos,
1082 event_viewer_data->currently_selected_position) != 0)
1083 lttvwindow_report_current_position(tab, pos);
1085 g_warning("Can not get iter\n");
1087 gtk_tree_path_free(path);
1094 static void tree_selection_changed_cb (GtkTreeSelection *selection,
1097 g_debug("tree sel changed cb");
1098 EventViewerData *event_viewer_data = (EventViewerData*) data;
1100 /* Set the cursor to currently selected event */
1101 GtkTreeModel* model = GTK_TREE_MODEL(event_viewer_data->store_m);
1103 LttvTracesetContextPosition *pos;
1105 GtkTreePath *tree_path;
1107 for(i=0;i<event_viewer_data->num_visible_events;i++) {
1108 tree_path = gtk_tree_path_new_from_indices(
1111 if(gtk_tree_model_get_iter(model,&iter,tree_path)){
1112 gtk_tree_model_get(model, &iter, POSITION_COLUMN, &pos, -1);
1114 if(lttv_traceset_context_pos_pos_compare(pos,
1115 event_viewer_data->currently_selected_position) == 0) {
1117 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
1118 tree_path, NULL, FALSE);
1123 g_warning("Can not get iter\n");
1125 gtk_tree_path_free(tree_path);
1131 static gint key_snooper(GtkWidget *grab_widget, GdkEventKey *event,
1138 /* This callback may be recalled after a step up/down, but we don't want to lose
1139 * the exact position : what we do is that we only set the value if it has
1140 * changed : a step up/down that doesn't change the time value of the first
1141 * event won't trigger a scrollbar change. */
1143 void v_scroll_cb (GtkAdjustment *adjustment, gpointer data)
1145 EventViewerData *event_viewer_data = (EventViewerData*)data;
1146 LttvTracesetStats *tss =
1147 lttvwindow_get_traceset_stats(event_viewer_data->tab);
1148 LttvTracesetContext *tsc = (LttvTracesetContext*)tss;
1149 g_debug("SCROLL begin");
1150 g_debug("SCROLL values : %g , %g, %g",
1151 adjustment->value, event_viewer_data->previous_value,
1152 (adjustment->value - event_viewer_data->previous_value));
1154 LttTime new_time_off = ltt_time_from_double(adjustment->value);
1155 LttTime old_time_off = ltt_time_from_double(event_viewer_data->previous_value);
1156 g_debug("SCROLL time values %lu.%lu, %lu.%lu", new_time_off.tv_sec,
1157 new_time_off.tv_nsec, old_time_off.tv_sec, old_time_off.tv_nsec);
1158 /* If same value : nothing to update */
1159 if(ltt_time_compare(new_time_off, old_time_off) == 0)
1162 //LttTime old_time = event_viewer_data->first_event;
1165 //gint snoop = gtk_key_snooper_install(key_snooper, NULL);
1167 get_events(adjustment->value, event_viewer_data);
1169 //gtk_key_snooper_remove(snoop);
1171 LttTime time = ltt_time_sub(event_viewer_data->first_event,
1172 tsc->time_span.start_time);
1173 double value = ltt_time_to_double(time);
1174 gtk_adjustment_set_value(event_viewer_data->vadjust_c, value);
1176 if(event_viewer_data->currently_selected_event != -1) {
1178 tree_path = gtk_tree_path_new_from_indices(
1179 event_viewer_data->currently_selected_event,
1182 // gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), tree_path,
1184 gtk_tree_path_free(tree_path);
1187 g_debug("SCROLL end");
1190 static __inline gint get_cell_height(GtkTreeView *TreeView)
1193 GtkTreeViewColumn *column = gtk_tree_view_get_column(TreeView, 0);
1195 gtk_tree_view_column_cell_get_size(column, NULL, NULL, NULL, NULL, &height);
1197 gint vertical_separator;
1198 gtk_widget_style_get (GTK_WIDGET (TreeView),
1199 "vertical-separator", &vertical_separator,
1202 height += vertical_separator;
1207 void tree_v_size_allocate_cb (GtkWidget *widget, GtkAllocation *alloc, gpointer data)
1209 EventViewerData *event_viewer_data = (EventViewerData*)data;
1210 gint cell_height = get_cell_height(GTK_TREE_VIEW(event_viewer_data->tree_v));
1211 gint last_num_visible_events = event_viewer_data->num_visible_events;
1212 gdouble exact_num_visible;
1214 exact_num_visible = ( alloc->height -
1215 event_viewer_data->header_height )
1216 / (double)cell_height ;
1218 event_viewer_data->num_visible_events = ceil(exact_num_visible) ;
1221 event_viewer_data->vadjust_c->page_increment =
1222 floor(exact_num_visible);
1223 event_viewer_data->vadjust_c->page_size =
1224 floor(exact_num_visible);
1227 g_debug("size allocate : last_num_visible_events : %d,\
1228 num_visible_events : %d",
1229 last_num_visible_events,
1230 event_viewer_data->num_visible_events);
1231 if(event_viewer_data->num_visible_events != last_num_visible_events)
1233 get_events(event_viewer_data->vadjust_c->value, event_viewer_data);
1239 void tree_v_size_request_cb (GtkWidget *widget, GtkRequisition *requisition, gpointer data)
1242 EventViewerData *event_viewer_data = (EventViewerData*)data;
1243 gint cell_height = get_cell_height(GTK_TREE_VIEW(event_viewer_data->tree_v));
1245 h = cell_height + event_viewer_data->header_height;
1246 requisition->height = h;
1251 gboolean show_event_detail(void * hook_data, void * call_data)
1253 EventViewerData *event_viewer_data = (EventViewerData*) hook_data;
1254 LttvTracesetContext * tsc = lttvwindow_get_traceset_context(event_viewer_data->tab);
1256 if(event_viewer_data->event_fields_queue_tmp->length == 0 &&
1257 event_viewer_data->event_fields_queue->length == 0){
1258 event_viewer_data->shown = FALSE;
1262 if(event_viewer_data->shown == FALSE){
1263 event_viewer_data->shown = TRUE;
1264 update_raw_data_array(event_viewer_data,
1265 event_viewer_data->event_fields_queue_tmp->length);
1267 get_data(event_viewer_data->vadjust_c->value,
1268 event_viewer_data->num_visible_events,
1271 remove_context_hooks(event_viewer_data,tsc);
1278 static gboolean events_check_handler(guint count, gboolean *stop_flag)
1280 if(count % CHECK_GDK_INTERVAL == 0) {
1281 gtk_main_iteration_do(FALSE);
1286 } else return FALSE;
1289 static void get_events(double new_value, EventViewerData *event_viewer_data)
1291 GtkTreePath *tree_path;
1292 LttvTracesetStats *tss =
1293 lttvwindow_get_traceset_stats(event_viewer_data->tab);
1294 LttvTracesetContext *tsc = (LttvTracesetContext*)tss;
1296 gboolean seek_by_time;
1298 if(lttvwindow_preempt_count > 0) return;
1300 double value = new_value - event_viewer_data->previous_value;
1302 /* Set stop button status for foreground processing */
1303 event_viewer_data->tab->stop_foreground = FALSE;
1304 lttvwindow_events_request_disable();
1306 /* See where we have to scroll... */
1307 ScrollDirection direction;
1308 gint relative_position;
1311 if(value >= -1.0) direction = SCROLL_STEP_UP;
1313 if(value >= -2.0) direction = SCROLL_PAGE_UP;
1314 else direction = SCROLL_JUMP;
1316 } else if(value > 0.8) {
1317 if(value <= 1.0) direction = SCROLL_STEP_DOWN;
1319 if(value <= 2.0) direction = SCROLL_PAGE_DOWN;
1320 else direction = SCROLL_JUMP;
1322 } else direction = SCROLL_NONE; /* 0.0 */
1326 case SCROLL_STEP_UP:
1327 g_debug("get_events : SCROLL_STEP_UP");
1328 relative_position = -1;
1331 case SCROLL_STEP_DOWN:
1332 g_debug("get_events : SCROLL_STEP_DOWN");
1333 relative_position = 1;
1336 case SCROLL_PAGE_UP:
1337 g_debug("get_events : SCROLL_PAGE_UP");
1338 relative_position = -(event_viewer_data->num_visible_events);
1341 case SCROLL_PAGE_DOWN:
1342 g_debug("get_events : SCROLL_PAGE_DOWN");
1343 relative_position = event_viewer_data->num_visible_events;
1347 g_debug("get_events : SCROLL_JUMP");
1351 g_debug("get_events : SCROLL_NONE");
1352 relative_position = 0;
1357 LttTime time = ltt_time_from_double(new_value);
1358 time = ltt_time_add(tsc->time_span.start_time, time);
1362 LttvTracesetContextPosition *pos =
1363 lttv_traceset_context_position_new(tsc);
1365 /* Remember the beginning position */
1366 if(event_viewer_data->pos->len > 0) {
1367 LttvTracesetContextPosition *first_pos =
1368 (LttvTracesetContextPosition*)g_ptr_array_index(
1369 event_viewer_data->pos,
1371 lttv_traceset_context_position_copy(pos, first_pos);
1373 if(relative_position >= 0) {
1374 LttTime first_event_time =
1375 lttv_traceset_context_position_get_time(
1377 lttv_state_traceset_seek_time_closest((LttvTracesetState*)tsc,
1379 lttv_process_traceset_middle(tsc, ltt_time_infinite,
1383 } else if(relative_position < 0) {
1384 g_assert(lttv_process_traceset_seek_position(tsc, pos) == 0);
1387 /* There is nothing in the list : simply seek to the time value. */
1388 lttv_state_traceset_seek_time_closest((LttvTracesetState*)tsc,
1390 lttv_process_traceset_middle(tsc, time, G_MAXUINT,
1394 /* Note that, as we mess with the tsc position, this function CANNOT be called
1395 * from a hook inside the lttv_process_traceset_middle. */
1396 /* As the lttvwindow API keeps a sync_position inside the tsc to go back at
1397 * the right spot after being interrupted, it's ok to change the tsc position,
1398 * as long as we do not touch the sync_position. */
1400 /* Get the beginning position of the read (with seek backward or seek forward)
1402 if(relative_position > 0) {
1404 count += lttv_process_traceset_seek_n_forward(tsc, relative_position,
1405 event_viewer_data->main_win_filter, events_check_handler,
1406 &event_viewer_data->tab->stop_foreground);
1407 } else if(relative_position < 0) {
1410 /* Get an idea of currently shown event dispersion */
1411 LttTime first_event_time =
1412 lttv_traceset_context_position_get_time(event_viewer_data->first_event);
1413 LttTime last_event_time =
1414 lttv_traceset_context_position_get_time(event_viewer_data->last_event);
1415 LttTime time_diff = ltt_time_sub(last_event_time, first_event_time);
1416 if(ltt_time_compare(time_diff, ltt_time_zero) == 0)
1417 time_diff = seek_back_default_offset;
1419 count = lttv_process_traceset_seek_n_backward(tsc,
1420 abs(relative_position),
1422 (seek_time_fct)lttv_state_traceset_seek_time_closest,
1423 event_viewer_data->main_win_filter,
1424 events_check_handler,
1425 &event_viewer_data->tab->stop_foreground);
1426 } /* else 0 : do nothing : we are already at the beginning position */
1428 lttv_traceset_context_position_destroy(pos);
1430 /* Save the first event position */
1431 lttv_traceset_context_position_save(tsc, event_viewer_data->first_event);
1433 time = lttv_traceset_context_position_get_time(
1434 event_viewer_data->first_event);
1435 //if(ltt_time_compare(time, tsc->time_span.end_time) > 0)
1436 // time = tsc->time_span.end_time;
1438 LttTime time_val = ltt_time_sub(time,
1439 tsc->time_span.start_time);
1440 event_viewer_data->previous_value = ltt_time_to_double(time_val);
1442 lttv_state_traceset_seek_time_closest((LttvTracesetState*)tsc, time);
1443 lttv_process_traceset_middle(tsc, ltt_time_infinite, G_MAXUINT,
1444 event_viewer_data->first_event);
1448 lttv_state_traceset_seek_time_closest((LttvTracesetState*)tsc,
1450 lttv_process_traceset_middle(tsc, time, G_MAXUINT,
1452 LttTime time_val = ltt_time_sub(time,
1453 tsc->time_span.start_time);
1454 event_viewer_data->previous_value = ltt_time_to_double(time_val);
1455 lttv_traceset_context_position_save(tsc, event_viewer_data->first_event);
1458 /* Clear the model (don't forget to free the TCS positions!) */
1459 gtk_list_store_clear(event_viewer_data->store_m);
1460 for(i=0;i<event_viewer_data->pos->len;i++) {
1461 LttvTracesetContextPosition *cur_pos =
1462 (LttvTracesetContextPosition*)g_ptr_array_index(event_viewer_data->pos,
1464 lttv_traceset_context_position_destroy(cur_pos);
1466 g_ptr_array_set_size(event_viewer_data->pos, 0);
1470 * I make the choice not to use the mainwindow lttvwindow API here : the idle
1471 * loop might have a too low priority, and we want good update while
1472 * scrolling. However, we call the gdk loop to get events periodically so the
1473 * processing can be stopped.
1476 lttv_process_traceset_begin(tsc,
1477 NULL, NULL, NULL, event_viewer_data->event_hooks, NULL);
1479 event_viewer_data->num_events = 0;
1481 lttv_process_traceset_middle(tsc, ltt_time_infinite, G_MAXUINT, NULL);
1483 lttv_process_traceset_end(tsc,
1484 NULL, NULL, NULL, event_viewer_data->event_hooks, NULL);
1486 /* Get the end position */
1487 if(event_viewer_data->pos->len > 0) {
1488 LttvTracesetContextPosition *cur_pos =
1489 (LttvTracesetContextPosition*)g_ptr_array_index(event_viewer_data->pos,
1490 event_viewer_data->pos->len - 1);
1491 lttv_traceset_context_position_copy(event_viewer_data->last_event,
1494 lttv_traceset_context_position_save(tsc, event_viewer_data->last_event);
1496 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
1497 event_viewer_data->previous_value);
1499 //g_signal_emit_by_name(G_OBJECT (event_viewer_data->select_c),
1502 event_viewer_data->last_tree_update_time =
1503 gdk_x11_get_server_time(
1504 gtk_widget_get_parent_window(event_viewer_data->tree_v));
1506 lttvwindow_events_request_enable();
1513 int event_hook(void *hook_data, void *call_data)
1515 EventViewerData *event_viewer_data = (EventViewerData*)hook_data;
1516 LttvTracefileContext *tfc = (LttvTracefileContext*)call_data;
1517 LttvTracefileState *tfs = (LttvTracefileState*)call_data;
1518 LttEvent *e = ltt_tracefile_get_event(tfc->tf);
1520 if(event_viewer_data->num_events % CHECK_GDK_INTERVAL == 0) {
1521 gtk_main_iteration_do(FALSE);
1522 if(event_viewer_data->tab->stop_foreground)
1525 event_viewer_data->num_events++;
1527 LttvFilter *filter = event_viewer_data->main_win_filter;
1528 if(filter != NULL && filter->head != NULL)
1529 if(!lttv_filter_tree_parse(filter->head,e,tfc->tf,
1530 tfc->t_context->t,tfc))
1533 LttFacility *facility = ltt_event_facility(e);
1534 LttEventType *event_type = ltt_event_eventtype(e);
1535 LttTime time = ltt_event_time(e);
1537 guint cpu = tfs->cpu;
1538 LttvTraceState *ts = (LttvTraceState*)tfc->t_context;
1539 LttvProcessState *process = ts->running_process[cpu];
1543 GString *desc = g_string_new("");
1545 LttvTracesetContextPosition *pos =
1546 lttv_traceset_context_position_new(tfc->t_context->ts_context);
1548 lttv_traceset_context_position_save(tfc->t_context->ts_context, pos);
1550 lttv_event_to_string(e, desc, TRUE, TRUE, (LttvTracefileState*)tfc);
1552 g_info("detail : %s", desc->str);
1554 gtk_list_store_append (event_viewer_data->store_m, &iter);
1555 gtk_list_store_set (event_viewer_data->store_m, &iter,
1556 TRACE_NAME_COLUMN, g_quark_to_string(ltt_trace_name(tfc->t_context->t)),
1557 TRACEFILE_NAME_COLUMN, g_quark_to_string(ltt_tracefile_name(tfc->tf)),
1559 FACILITY_COLUMN, g_quark_to_string(ltt_facility_name(facility)),
1560 EVENT_COLUMN, g_quark_to_string(ltt_eventtype_name(event_type)),
1561 TIME_S_COLUMN, time.tv_sec,
1562 TIME_NS_COLUMN, time.tv_nsec,
1563 PID_COLUMN, process->pid,
1564 EVENT_DESCR_COLUMN, desc->str,
1565 POSITION_COLUMN, pos,
1568 g_ptr_array_add(event_viewer_data->pos, pos);
1570 g_string_free(desc, TRUE);
1572 if(event_viewer_data->update_cursor) {
1573 if(lttv_traceset_context_pos_pos_compare(pos,
1574 event_viewer_data->currently_selected_position) == 0) {
1575 GtkTreePath *path = gtk_tree_path_new_from_indices(
1576 event_viewer_data->pos->len - 1, -1);
1578 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
1580 gtk_tree_path_free(path);
1585 if(event_viewer_data->pos->len >= event_viewer_data->num_visible_events )
1593 static void event_update_selection(EventViewerData *event_viewer_data)
1596 GPtrArray *positions = event_viewer_data->pos;
1597 g_info("event_update_selection");
1599 for(i=0;i<positions->len;i++) {
1600 LttvTracesetContextPosition *cur_pos =
1601 (LttvTracesetContextPosition*)g_ptr_array_index(positions, i);
1602 if(lttv_traceset_context_pos_pos_compare(cur_pos,
1603 event_viewer_data->currently_selected_position) == 0) {
1604 GtkTreePath *path = gtk_tree_path_new_from_indices(i, -1);
1606 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
1608 gtk_tree_path_free(path);
1614 static int current_time_get_first_event_hook(void *hook_data, void *call_data)
1616 EventViewerData *event_viewer_data = (EventViewerData*)hook_data;
1617 LttvTracefileContext *tfc = (LttvTracefileContext*)call_data;
1618 LttEvent *e = ltt_tracefile_get_event(tfc->tf);
1620 LttvFilter *filter = event_viewer_data->main_win_filter;
1621 if(filter != NULL && filter->head != NULL)
1622 if(!lttv_filter_tree_parse(filter->head,e,tfc->tf,
1623 tfc->t_context->t,tfc))
1626 lttv_traceset_context_position_save(tfc->t_context->ts_context,
1627 event_viewer_data->current_time_get_first);
1632 gboolean update_current_time(void * hook_data, void * call_data)
1634 g_info("update_current_time");
1635 EventViewerData *event_viewer_data = (EventViewerData*) hook_data;
1636 const LttTime * current_time = (LttTime*)call_data;
1637 LttvTracesetContext * tsc =
1638 lttvwindow_get_traceset_context(event_viewer_data->tab);
1641 /* If the currently selected event time != current time, set the first event
1642 * with this time as currently selected. */
1643 LttTime pos_time = lttv_traceset_context_position_get_time(
1644 event_viewer_data->currently_selected_position);
1645 if(ltt_time_compare(pos_time, *current_time) != 0) {
1647 lttv_state_traceset_seek_time_closest((LttvTracesetState*)tsc,
1649 lttv_process_traceset_middle(tsc, *current_time, G_MAXUINT,
1652 /* Get the first event that passes in the filter */
1653 event_viewer_data->current_time_get_first =
1654 lttv_traceset_context_position_new(tsc);
1655 LttvHooks *hooks = lttv_hooks_new();
1656 lttv_hooks_add(hooks,
1657 current_time_get_first_event_hook,
1661 lttv_process_traceset_begin(tsc,
1662 NULL, NULL, NULL, hooks, NULL);
1664 lttv_process_traceset_middle(tsc, ltt_time_infinite, G_MAXUINT, NULL);
1666 lttv_process_traceset_end(tsc,
1667 NULL, NULL, NULL, hooks, NULL);
1669 lttv_hooks_destroy(hooks);
1671 lttv_traceset_context_position_copy(
1672 event_viewer_data->currently_selected_position,
1673 event_viewer_data->current_time_get_first);
1674 lttv_traceset_context_position_destroy(
1675 event_viewer_data->current_time_get_first);
1676 pos_time = lttv_traceset_context_position_get_time(
1677 event_viewer_data->currently_selected_position);
1680 LttTime time = ltt_time_sub(pos_time, tsc->time_span.start_time);
1681 double new_value = ltt_time_to_double(time);
1683 event_viewer_data->report_position = FALSE;
1684 /* Change the viewed area if does not match */
1685 if(lttv_traceset_context_pos_pos_compare(
1686 event_viewer_data->currently_selected_position,
1687 event_viewer_data->first_event) < 0
1689 lttv_traceset_context_pos_pos_compare(
1690 event_viewer_data->currently_selected_position,
1691 event_viewer_data->last_event) > 0) {
1692 gtk_adjustment_set_value(event_viewer_data->vadjust_c, new_value);
1694 /* Simply update the current time : it is in the list */
1695 event_update_selection(event_viewer_data);
1697 event_viewer_data->report_position = TRUE;
1702 gboolean update_current_position(void * hook_data, void * call_data)
1704 g_info("update_current_position");
1705 EventViewerData *event_viewer_data = (EventViewerData*) hook_data;
1706 const LttvTracesetContextPosition *current_pos =
1707 (LttvTracesetContextPosition*)call_data;
1708 LttvTracesetContext * tsc =
1709 lttvwindow_get_traceset_context(event_viewer_data->tab);
1711 if(lttv_traceset_context_pos_pos_compare(
1712 event_viewer_data->currently_selected_position, current_pos) != 0) {
1713 lttv_traceset_context_position_copy(
1714 event_viewer_data->currently_selected_position, current_pos);
1716 /* Change the viewed area if does not match */
1717 if(lttv_traceset_context_pos_pos_compare(
1718 event_viewer_data->currently_selected_position,
1719 event_viewer_data->first_event) < 0
1721 lttv_traceset_context_pos_pos_compare(
1722 event_viewer_data->currently_selected_position,
1723 event_viewer_data->last_event) > 0) {
1724 LttTime time = lttv_traceset_context_position_get_time(current_pos);
1725 time = ltt_time_sub(time, tsc->time_span.start_time);
1726 double new_value = ltt_time_to_double(time);
1727 gtk_adjustment_set_value(event_viewer_data->vadjust_c, new_value);
1729 /* Simply update the current time : it is in the list */
1730 event_update_selection(event_viewer_data);
1741 gboolean traceset_changed(void * hook_data, void * call_data)
1743 EventViewerData *event_viewer_data = (EventViewerData*) hook_data;
1744 LttvTracesetContext * tsc =
1745 lttvwindow_get_traceset_context(event_viewer_data->tab);
1746 TimeInterval time_span = tsc->time_span;
1749 gtk_list_store_clear(event_viewer_data->store_m);
1750 g_ptr_array_set_size(event_viewer_data->pos, 0);
1752 end = ltt_time_sub(time_span.end_time, time_span.start_time);
1753 event_viewer_data->vadjust_c->upper = ltt_time_to_double(end);
1755 /* Reset the positions */
1756 lttv_traceset_context_position_destroy(
1757 event_viewer_data->currently_selected_position);
1758 lttv_traceset_context_position_destroy(
1759 event_viewer_data->first_event);
1760 lttv_traceset_context_position_destroy(
1761 event_viewer_data->last_event);
1763 event_viewer_data->currently_selected_position =
1764 lttv_traceset_context_position_new(tsc);
1765 event_viewer_data->first_event =
1766 lttv_traceset_context_position_new(tsc);
1767 event_viewer_data->last_event =
1768 lttv_traceset_context_position_new(tsc);
1770 get_events(event_viewer_data->vadjust_c->value, event_viewer_data);
1771 // event_viewer_data->vadjust_c->value = 0;
1773 request_background_data(event_viewer_data);
1778 gboolean filter_changed(void * hook_data, void * call_data)
1780 EventViewerData *event_viewer_data = (EventViewerData*) hook_data;
1781 LttvTracesetContext * tsc =
1782 lttvwindow_get_traceset_context(event_viewer_data->tab);
1784 event_viewer_data->main_win_filter =
1785 (LttvFilter*)call_data;
1786 get_events(event_viewer_data->vadjust_c->value, event_viewer_data);
1792 gint redraw_notify(void *hook_data, void *call_data)
1794 EventViewerData *event_viewer_data = (EventViewerData*) hook_data;
1796 get_events(event_viewer_data->vadjust_c->value, event_viewer_data);
1800 void gui_events_free(EventViewerData *event_viewer_data)
1802 Tab *tab = event_viewer_data->tab;
1805 if(event_viewer_data){
1806 lttv_hooks_remove(event_viewer_data->event_hooks,event_hook);
1807 lttv_hooks_destroy(event_viewer_data->event_hooks);
1809 for(i=0;i<event_viewer_data->pos->len;i++) {
1810 LttvTracesetContextPosition *cur_pos =
1811 (LttvTracesetContextPosition*)g_ptr_array_index(event_viewer_data->pos,
1813 lttv_traceset_context_position_destroy(cur_pos);
1815 lttv_traceset_context_position_destroy(
1816 event_viewer_data->currently_selected_position);
1817 lttv_traceset_context_position_destroy(
1818 event_viewer_data->first_event);
1819 lttv_traceset_context_position_destroy(
1820 event_viewer_data->last_event);
1821 g_ptr_array_free(event_viewer_data->pos, TRUE);
1823 lttvwindow_unregister_current_time_notify(tab,
1824 update_current_time, event_viewer_data);
1825 lttvwindow_unregister_current_position_notify(tab,
1826 update_current_position, event_viewer_data);
1827 //lttvwindow_unregister_show_notify(tab,
1828 // show_event_detail, event_viewer_data);
1829 lttvwindow_unregister_traceset_notify(tab,
1830 traceset_changed, event_viewer_data);
1831 lttvwindow_unregister_filter_notify(tab,
1832 filter_changed, event_viewer_data);
1833 lttvwindow_unregister_redraw_notify(tab,
1834 redraw_notify, event_viewer_data);
1836 lttvwindowtraces_background_notify_remove(event_viewer_data);
1838 g_event_viewer_data_list = g_slist_remove(g_event_viewer_data_list,
1840 g_free(event_viewer_data);
1846 void gui_events_destructor(EventViewerData *event_viewer_data)
1848 /* May already been done by GTK window closing */
1849 if(GTK_IS_WIDGET(event_viewer_data->hbox_v)){
1850 gtk_widget_destroy(event_viewer_data->hbox_v);
1857 * plugin's init function
1859 * This function initializes the Event Viewer functionnality through the
1862 static void init() {
1864 lttvwindow_register_constructor("guievents",
1866 "Insert Event Viewer",
1867 hGuiEventsInsert_xpm,
1868 "Insert Event Viewer",
1872 void event_destroy_walk(gpointer data, gpointer user_data)
1874 gui_events_destructor((EventViewerData*)data);
1878 * plugin's destroy function
1880 * This function releases the memory reserved by the module and unregisters
1881 * everything that has been registered in the gtkTraceSet API.
1883 static void destroy() {
1885 g_slist_foreach(g_event_viewer_data_list, event_destroy_walk, NULL );
1886 g_slist_free(g_event_viewer_data_list);
1888 lttvwindow_unregister_constructor(h_gui_events);
1895 LTTV_MODULE("guievents", "Detailed events view", \
1896 "Graphical module to display a detailed event list", \
1897 init, destroy, "lttvwindow", "print")