f1cca3c775fff7b8f86505c4240e2fa311a396ef
[lttv.git] /
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
4 *
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;
8 *
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.
13 *
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,
17 * MA 02111-1307, USA.
18 */
19
20
21 //*! \defgroup GuiEvents libGuiEvents: The GUI Events display plugin */
22 /*\@{*/
23
24 /*! \file GuiEvents.c
25 * \brief Graphical plugin for showing events.
26 *
27 * This plugin lists all the events contained in the current time interval
28 * in a list.
29 *
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.
36 *
37 * Authors : Mathieu Desnoyers and XangXiu Yang, June to December 2003
38 * Inspired from original LTT, made by Karim Yaghmour
39 *
40 * Mostly rewritten by Mathieu Desnoyers, August 2005.
41 */
42
43 #ifdef HAVE_CONFIG_H
44 #include <config.h>
45 #endif
46
47 #include <math.h>
48
49 #include <glib.h>
50 #include <gtk/gtk.h>
51 #include <gdk/gdk.h>
52 #include <gdk/gdkx.h>
53 #include <string.h>
54
55 #include <ltt/ltt.h>
56 #include <ltt/event.h>
57 #include <ltt/trace.h>
58 #include <lttv/module.h>
59 #include <lttv/hook.h>
60 #include <lttv/tracecontext.h>
61 #include <lttv/state.h>
62 #include <lttv/filter.h>
63 #include <lttv/print.h>
64 #include <lttvwindow/lttvwindow.h>
65 #include <lttvwindow/lttvwindowtraces.h>
66 #include <lttvwindow/lttv_plugin_tab.h>
67 #include <lttvwindow/support.h>
68 #include "lttv_plugin_evd.h"
69
70 #include "events.h"
71 #include "hGuiEventsInsert.xpm"
72
73 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
74
75 #ifndef g_debug
76 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
77 #endif
78
79 #define abs(a) (((a)<0)?(-a):(a))
80 #define max(a,b) ((a)>(b)?(a):(b))
81 #define min(a,b) ((a)<(b)?(a):(b))
82
83 /** Array containing instanced objects. Used when module is unloaded */
84 static GSList *g_event_viewer_data_list = NULL ;
85
86 typedef enum _ScrollDirection{
87 SCROLL_STEP_UP,
88 SCROLL_STEP_DOWN,
89 SCROLL_PAGE_UP,
90 SCROLL_PAGE_DOWN,
91 SCROLL_JUMP,
92 SCROLL_NONE
93 } ScrollDirection;
94
95 /** hook functions for update time interval, current time ... */
96 gboolean update_current_time(void * hook_data, void * call_data);
97 gboolean update_current_position(void * hook_data, void * call_data);
98 //gboolean show_event_detail(void * hook_data, void * call_data);
99 gboolean traceset_changed(void * hook_data, void * call_data);
100 gboolean filter_changed(void * hook_data, void * call_data);
101
102 static void request_background_data(EventViewerData *event_viewer_data);
103
104 //! Event Viewer's constructor hook
105 GtkWidget *h_gui_events(LttvPlugin *plugin);
106 //! Event Viewer's constructor
107 EventViewerData *gui_events(LttvPluginTab *ptab);
108 //! Event Viewer's destructor
109 void gui_events_destructor(gpointer data);
110 void gui_events_free(gpointer data);
111
112 static gboolean
113 header_size_allocate(GtkWidget *widget,
114 GtkAllocation *allocation,
115 gpointer user_data);
116
117 void tree_v_set_cursor(EventViewerData *event_viewer_data);
118 void tree_v_get_cursor(EventViewerData *event_viewer_data);
119
120 /* Prototype for selection handler callback */
121 static void tree_selection_changed_cb (GtkTreeSelection *selection,
122 gpointer data);
123 static void v_scroll_cb (GtkAdjustment *adjustment, gpointer data);
124 static void tree_v_size_allocate_cb (GtkWidget *widget, GtkAllocation *alloc,
125 gpointer data);
126 static void tree_v_size_request_cb (GtkWidget *widget,
127 GtkRequisition *requisition, gpointer data);
128 static void tree_v_cursor_changed_cb (GtkWidget *widget, gpointer data);
129 static void tree_v_move_cursor_cb (GtkWidget *widget, GtkMovementStep arg1,
130 gint arg2, gpointer data);
131 static void filter_button (GtkToolButton *toolbutton,
132 gpointer user_data);
133 static gboolean tree_v_scroll_handler (GtkWidget *widget, GdkEventScroll *event, gpointer data);
134 static gboolean key_handler(GtkWidget *widget, GdkEventKey *event,
135 gpointer user_data);
136
137 static void get_events(double time, EventViewerData *event_viewer_data);
138
139 int event_hook(void *hook_data, void *call_data);
140
141 /* Enumeration of the columns */
142 enum
143 {
144 TRACE_NAME_COLUMN,
145 TRACEFILE_NAME_COLUMN,
146 CPUID_COLUMN,
147 EVENT_COLUMN,
148 TIME_S_COLUMN,
149 TIME_NS_COLUMN,
150 PID_COLUMN,
151 EVENT_DESCR_COLUMN,
152 POSITION_COLUMN,
153 N_COLUMNS
154 };
155
156 /**
157 * Event Viewer's constructor hook
158 *
159 * This constructor is given as a parameter to the menuitem and toolbar button
160 * registration. It creates the list.
161 * @param parent_window A pointer to the parent window.
162 * @return The widget created.
163 */
164 GtkWidget *
165 h_gui_events(LttvPlugin *plugin)
166 {
167 LttvPluginTab *ptab = LTTV_PLUGIN_TAB(plugin);
168 EventViewerData* event_viewer_data = gui_events(ptab) ;
169 if(event_viewer_data)
170 return event_viewer_data->top_widget;
171 else return NULL;
172
173 }
174
175 /**
176 * Event Viewer's constructor
177 *
178 * This constructor is used to create EventViewerData data structure.
179 * @return The Event viewer data created.
180 */
181 EventViewerData *
182 gui_events(LttvPluginTab *ptab)
183 {
184 LttTime end;
185 GtkTreeViewColumn *column;
186 GtkCellRenderer *renderer;
187 EventViewerData* event_viewer_data = g_new(EventViewerData,1);
188 LttvPluginEVD *plugin_evd = g_object_new(LTTV_TYPE_PLUGIN_EVD, NULL);
189 GtkTooltips *tooltips = gtk_tooltips_new();
190 plugin_evd->evd = event_viewer_data;
191 Tab *tab = ptab->tab;
192 event_viewer_data->tab = tab;
193 event_viewer_data->ptab = ptab;
194 GtkWidget *tmp_toolbar_icon;
195
196 LttvTracesetContext * tsc =
197 lttvwindow_get_traceset_context(event_viewer_data->tab);
198
199
200 event_viewer_data->event_hooks = lttv_hooks_new();
201 lttv_hooks_add(event_viewer_data->event_hooks,
202 event_hook,
203 event_viewer_data,
204 LTTV_PRIO_DEFAULT);
205
206 lttvwindow_register_current_time_notify(tab,
207 update_current_time,event_viewer_data);
208 lttvwindow_register_current_position_notify(tab,
209 update_current_position,event_viewer_data);
210 lttvwindow_register_traceset_notify(tab,
211 traceset_changed,event_viewer_data);
212 lttvwindow_register_filter_notify(tab,
213 filter_changed, event_viewer_data);
214 lttvwindow_register_redraw_notify(tab,
215 evd_redraw_notify, event_viewer_data);
216
217
218 event_viewer_data->scroll_win = gtk_scrolled_window_new (NULL, NULL);
219 gtk_widget_show (event_viewer_data->scroll_win);
220 gtk_scrolled_window_set_policy(
221 GTK_SCROLLED_WINDOW(event_viewer_data->scroll_win),
222 GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
223
224 event_viewer_data->currently_selected_position =
225 lttv_traceset_context_position_new(tsc);
226 event_viewer_data->first_event =
227 lttv_traceset_context_position_new(tsc);
228 event_viewer_data->last_event =
229 lttv_traceset_context_position_new(tsc);
230
231 event_viewer_data->main_win_filter = lttvwindow_get_filter(tab);
232
233 event_viewer_data->update_cursor = TRUE;
234 event_viewer_data->report_position = TRUE;
235
236 event_viewer_data->last_tree_update_time = 0;
237
238 event_viewer_data->init_done = 0;
239
240 /* Create a model for storing the data list */
241 event_viewer_data->store_m = gtk_list_store_new (
242 N_COLUMNS, /* Total number of columns */
243 G_TYPE_STRING, /* Trace name */
244 G_TYPE_STRING, /* Tracefile name */
245 G_TYPE_UINT, /* CPUID */
246 G_TYPE_STRING, /* Event */
247 G_TYPE_UINT, /* Time s */
248 G_TYPE_UINT, /* Time ns */
249 G_TYPE_INT, /* PID */
250 G_TYPE_STRING, /* Event's description */
251 G_TYPE_POINTER);/* Position (not shown) */
252
253 event_viewer_data->pos = g_ptr_array_sized_new(10);
254
255 /* Create the viewer widget for the columned list */
256 event_viewer_data->tree_v =
257 gtk_tree_view_new_with_model (GTK_TREE_MODEL (event_viewer_data->store_m));
258
259 g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "size-allocate",
260 G_CALLBACK (tree_v_size_allocate_cb),
261 event_viewer_data);
262 g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "size-request",
263 G_CALLBACK (tree_v_size_request_cb),
264 event_viewer_data);
265
266 g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "cursor-changed",
267 G_CALLBACK (tree_v_cursor_changed_cb),
268 event_viewer_data);
269
270 g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "move-cursor",
271 G_CALLBACK (tree_v_move_cursor_cb),
272 event_viewer_data);
273
274 g_signal_connect (G_OBJECT(event_viewer_data->tree_v), "key-press-event",
275 G_CALLBACK(key_handler),
276 event_viewer_data);
277
278 g_signal_connect (G_OBJECT(event_viewer_data->tree_v), "scroll-event",
279 G_CALLBACK(tree_v_scroll_handler),
280 event_viewer_data);
281
282
283
284 // Use on each column!
285 //gtk_tree_view_column_set_sizing(event_viewer_data->tree_v,
286 //GTK_TREE_VIEW_COLUMN_FIXED);
287
288 /* The view now holds a reference. We can get rid of our own
289 * reference */
290 g_object_unref (G_OBJECT (event_viewer_data->store_m));
291
292
293 /* Create a column, associating the "text" attribute of the
294 * cell_renderer to the first column of the model */
295 /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */
296 renderer = gtk_cell_renderer_text_new ();
297 column = gtk_tree_view_column_new_with_attributes ("Trace",
298 renderer,
299 "text", TRACE_NAME_COLUMN,
300 NULL);
301 gtk_tree_view_column_set_alignment (column, 0.0);
302 gtk_tree_view_column_set_fixed_width (column, 120);
303 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v),
304 column);
305
306 event_viewer_data->button = column->button;
307
308 g_signal_connect (G_OBJECT(event_viewer_data->button),
309 "size-allocate",
310 G_CALLBACK(header_size_allocate),
311 (gpointer)event_viewer_data);
312
313
314
315 renderer = gtk_cell_renderer_text_new ();
316 column = gtk_tree_view_column_new_with_attributes ("Tracefile",
317 renderer,
318 "text", TRACEFILE_NAME_COLUMN,
319 NULL);
320 gtk_tree_view_column_set_alignment (column, 0.0);
321 gtk_tree_view_column_set_fixed_width (column, 120);
322 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v),
323 column);
324
325
326 renderer = gtk_cell_renderer_text_new ();
327 column = gtk_tree_view_column_new_with_attributes ("CPUID",
328 renderer,
329 "text", CPUID_COLUMN,
330 NULL);
331 gtk_tree_view_column_set_alignment (column, 0.0);
332 gtk_tree_view_column_set_fixed_width (column, 45);
333 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v),
334 column);
335
336 renderer = gtk_cell_renderer_text_new ();
337 column = gtk_tree_view_column_new_with_attributes ("Event",
338 renderer,
339 "text", EVENT_COLUMN,
340 NULL);
341 gtk_tree_view_column_set_alignment (column, 0.0);
342 gtk_tree_view_column_set_fixed_width (column, 120);
343 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v),
344 column);
345
346 renderer = gtk_cell_renderer_text_new ();
347 column = gtk_tree_view_column_new_with_attributes ("Time (s)",
348 renderer,
349 "text", TIME_S_COLUMN,
350 NULL);
351 gtk_tree_view_column_set_alignment (column, 1.0);
352 gtk_tree_view_column_set_fixed_width (column, 120);
353 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v),
354 column);
355
356 renderer = gtk_cell_renderer_text_new ();
357 column = gtk_tree_view_column_new_with_attributes ("Time (ns)",
358 renderer,
359 "text", TIME_NS_COLUMN,
360 NULL);
361 gtk_tree_view_column_set_alignment (column, 1.0);
362 gtk_tree_view_column_set_fixed_width (column, 120);
363 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v),
364 column);
365
366
367 renderer = gtk_cell_renderer_text_new ();
368 column = gtk_tree_view_column_new_with_attributes ("PID",
369 renderer,
370 "text", PID_COLUMN,
371 NULL);
372 gtk_tree_view_column_set_alignment (column, 1.0);
373 gtk_tree_view_column_set_fixed_width (column, 45);
374 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v),
375 column);
376
377 renderer = gtk_cell_renderer_text_new ();
378 column = gtk_tree_view_column_new_with_attributes ("Event Description",
379 renderer,
380 "text", EVENT_DESCR_COLUMN,
381 NULL);
382 gtk_tree_view_column_set_alignment (column, 0.0);
383 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v),
384 column);
385
386
387 /* Setup the selection handler */
388 event_viewer_data->select_c =
389 gtk_tree_view_get_selection (GTK_TREE_VIEW (event_viewer_data->tree_v));
390 gtk_tree_selection_set_mode (event_viewer_data->select_c,
391 GTK_SELECTION_SINGLE);
392 g_signal_connect (G_OBJECT (event_viewer_data->select_c), "changed",
393 G_CALLBACK (tree_selection_changed_cb),
394 event_viewer_data);
395
396 gtk_container_add (GTK_CONTAINER (event_viewer_data->scroll_win),
397 event_viewer_data->tree_v);
398
399 event_viewer_data->hbox_v = gtk_hbox_new(0, 0);
400 event_viewer_data->top_widget = event_viewer_data->hbox_v;
401 plugin_evd->parent.top_widget = event_viewer_data->hbox_v;
402
403 event_viewer_data->toolbar = gtk_toolbar_new();
404 gtk_toolbar_set_orientation(GTK_TOOLBAR(event_viewer_data->toolbar),
405 GTK_ORIENTATION_VERTICAL);
406
407 tmp_toolbar_icon = create_pixmap (main_window_get_widget(tab),
408 "guifilter16x16.png");
409 gtk_widget_show(tmp_toolbar_icon);
410 event_viewer_data->button_filter = gtk_tool_button_new(tmp_toolbar_icon,
411 "Filter");
412 g_signal_connect (G_OBJECT(event_viewer_data->button_filter),
413 "clicked",
414 G_CALLBACK (filter_button),
415 (gpointer)plugin_evd);
416 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(event_viewer_data->button_filter),
417 tooltips, "Open the filter window", NULL);
418 gtk_toolbar_insert(GTK_TOOLBAR(event_viewer_data->toolbar),
419 event_viewer_data->button_filter,
420 0);
421 gtk_toolbar_set_style(GTK_TOOLBAR(event_viewer_data->toolbar),
422 GTK_TOOLBAR_ICONS);
423 gtk_box_pack_start(GTK_BOX(event_viewer_data->hbox_v),
424 event_viewer_data->toolbar, FALSE, FALSE, 0);
425 event_viewer_data->filter = NULL;
426
427 gtk_box_pack_start(GTK_BOX(event_viewer_data->hbox_v),
428 event_viewer_data->scroll_win, TRUE, TRUE, 0);
429
430 gtk_container_set_border_width(GTK_CONTAINER(event_viewer_data->hbox_v), 1);
431
432 /* Create vertical scrollbar and pack it */
433 event_viewer_data->vscroll_vc = gtk_vscrollbar_new(NULL);
434 gtk_range_set_update_policy (GTK_RANGE(event_viewer_data->vscroll_vc),
435 GTK_UPDATE_CONTINUOUS);
436 // Changed by MD : more user friendly :)
437 //GTK_UPDATE_DISCONTINUOUS);
438 gtk_box_pack_start(GTK_BOX(event_viewer_data->hbox_v),
439 event_viewer_data->vscroll_vc, FALSE, TRUE, 0);
440
441 /* Get the vertical scrollbar's adjustment */
442 event_viewer_data->vadjust_c =
443 gtk_range_get_adjustment(GTK_RANGE(event_viewer_data->vscroll_vc));
444 event_viewer_data->vtree_adjust_c = gtk_tree_view_get_vadjustment(
445 GTK_TREE_VIEW (event_viewer_data->tree_v));
446
447 g_signal_connect (G_OBJECT (event_viewer_data->vadjust_c), "value-changed",
448 G_CALLBACK (v_scroll_cb),
449 event_viewer_data);
450 /* Set the upper bound to the last event number */
451 event_viewer_data->previous_value = 0;
452 event_viewer_data->vadjust_c->lower = 0.0;
453 //event_viewer_data->vadjust_c->upper = event_viewer_data->number_of_events;
454 LttTime time = lttvwindow_get_current_time(tab);
455 time = ltt_time_sub(time, tsc->time_span.start_time);
456 event_viewer_data->vadjust_c->value = ltt_time_to_double(time);
457 event_viewer_data->vadjust_c->value = 0.0;
458 event_viewer_data->vadjust_c->step_increment = 1.0;
459 event_viewer_data->vadjust_c->page_increment = 2.0;
460 // event_viewer_data->vtree_adjust_c->upper;
461 event_viewer_data->vadjust_c->page_size = 2.0;
462 // event_viewer_data->vtree_adjust_c->upper;
463 /* Raw event trace */
464 gtk_widget_show(GTK_WIDGET(event_viewer_data->button_filter));
465 gtk_widget_show(event_viewer_data->toolbar);
466 gtk_widget_show(event_viewer_data->hbox_v);
467 gtk_widget_show(event_viewer_data->tree_v);
468 gtk_widget_show(event_viewer_data->vscroll_vc);
469
470 /* Add the object's information to the module's array */
471 g_event_viewer_data_list = g_slist_append(g_event_viewer_data_list,
472 plugin_evd);
473
474 event_viewer_data->num_visible_events = 1;
475
476 //get the life span of the traceset and set the upper of the scroll bar
477
478 TimeInterval time_span = tsc->time_span;
479 end = ltt_time_sub(time_span.end_time, time_span.start_time);
480
481 event_viewer_data->vadjust_c->upper =
482 ltt_time_to_double(end);
483
484 /* Set the Selected Event */
485 // tree_v_set_cursor(event_viewer_data);
486
487 // event_viewer_data->current_time_updated = FALSE;
488 //
489 g_object_set_data_full(
490 G_OBJECT(event_viewer_data->hbox_v),
491 "plugin_data",
492 plugin_evd,
493 (GDestroyNotify)gui_events_free);
494
495 g_object_set_data(
496 G_OBJECT(event_viewer_data->hbox_v),
497 "event_viewer_data",
498 event_viewer_data);
499
500 event_viewer_data->background_info_waiting = 0;
501
502
503 request_background_data(event_viewer_data);
504
505 return event_viewer_data;
506 }
507
508
509
510 static gint background_ready(void *hook_data, void *call_data)
511 {
512 EventViewerData *event_viewer_data = (EventViewerData *)hook_data;
513 LttvTrace *trace = (LttvTrace*)call_data;
514
515 event_viewer_data->background_info_waiting--;
516
517 if(event_viewer_data->background_info_waiting == 0) {
518 g_message("event viewer : background computation data ready.");
519
520 evd_redraw_notify(event_viewer_data, NULL);
521 }
522
523 return 0;
524 }
525
526
527 static void request_background_data(EventViewerData *event_viewer_data)
528 {
529 LttvTracesetContext * tsc =
530 lttvwindow_get_traceset_context(event_viewer_data->tab);
531 gint num_traces = lttv_traceset_number(tsc->ts);
532 gint i;
533 LttvTrace *trace;
534 LttvTraceState *tstate;
535
536 LttvHooks *background_ready_hook =
537 lttv_hooks_new();
538 lttv_hooks_add(background_ready_hook, background_ready, event_viewer_data,
539 LTTV_PRIO_DEFAULT);
540 event_viewer_data->background_info_waiting = 0;
541
542 for(i=0;i<num_traces;i++) {
543 trace = lttv_traceset_get(tsc->ts, i);
544 tstate = LTTV_TRACE_STATE(tsc->traces[i]);
545
546 if(lttvwindowtraces_get_ready(g_quark_from_string("state"),trace)==FALSE
547 && !tstate->has_precomputed_states) {
548
549 if(lttvwindowtraces_get_in_progress(g_quark_from_string("state"),
550 trace) == FALSE) {
551 /* We first remove requests that could have been done for the same
552 * information. Happens when two viewers ask for it before servicing
553 * starts.
554 */
555 if(!lttvwindowtraces_background_request_find(trace, "state"))
556 lttvwindowtraces_background_request_queue(
557 main_window_get_widget(event_viewer_data->tab), trace, "state");
558 lttvwindowtraces_background_notify_queue(event_viewer_data,
559 trace,
560 ltt_time_infinite,
561 NULL,
562 background_ready_hook);
563 event_viewer_data->background_info_waiting++;
564 } else { /* in progress */
565
566 lttvwindowtraces_background_notify_current(event_viewer_data,
567 trace,
568 ltt_time_infinite,
569 NULL,
570 background_ready_hook);
571 event_viewer_data->background_info_waiting++;
572 }
573 } else {
574 /* Data ready. By its nature, this viewer doesn't need to have
575 * its data ready hook called there, because a background
576 * request is always linked with a redraw.
577 */
578 }
579
580 }
581
582 lttv_hooks_destroy(background_ready_hook);
583
584 }
585
586 static gboolean
587 header_size_allocate(GtkWidget *widget,
588 GtkAllocation *allocation,
589 gpointer user_data)
590 {
591 EventViewerData *event_viewer_data = (EventViewerData*)user_data;
592
593 event_viewer_data->header_height = allocation->height;
594
595 return 0;
596 }
597
598
599 void tree_v_set_cursor(EventViewerData *event_viewer_data)
600 {
601 GtkTreePath *path;
602
603 g_debug("set cursor cb");
604
605 #if 0
606 if(event_viewer_data->currently_selected_event != -1)
607 {
608 path = gtk_tree_path_new_from_indices(
609 event_viewer_data->currently_selected_event,
610 -1);
611
612 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
613 path, NULL, FALSE);
614 gtk_tree_path_free(path);
615 }
616 #endif //0
617 }
618
619 void tree_v_get_cursor(EventViewerData *event_viewer_data)
620 {
621 GtkTreePath *path;
622 gint *indices;
623
624 g_debug("get cursor cb");
625
626
627 #if 0
628 gtk_tree_view_get_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
629 &path, NULL);
630 indices = gtk_tree_path_get_indices(path);
631
632 if(indices != NULL)
633 event_viewer_data->currently_selected_event = indices[0];
634 else
635 event_viewer_data->currently_selected_event = -1;
636
637 gtk_tree_path_free(path);
638 #endif //0
639 }
640
641 /* Filter out the key repeats that come too fast */
642 static gboolean key_handler(GtkWidget *widget, GdkEventKey *event,
643 gpointer user_data)
644 {
645 EventViewerData *evd = (EventViewerData *)user_data;
646
647 g_debug("event time : %u , last time : %u", event->time,
648 evd->last_tree_update_time);
649
650 if(guint32_before(event->time, evd->last_tree_update_time))
651 return TRUE;
652 else
653 return FALSE;
654 }
655
656 void tree_v_move_cursor_cb (GtkWidget *widget,
657 GtkMovementStep arg1,
658 gint arg2,
659 gpointer data)
660 {
661 GtkTreePath *path; // = gtk_tree_path_new();
662 gint *indices;
663 gdouble value;
664 EventViewerData *event_viewer_data = (EventViewerData*)data;
665
666 g_debug("move cursor cb");
667 //gtk_tree_view_get_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
668 // &path, NULL);
669 //if(path == NULL)
670 //{
671 /* No prior cursor, put it at beginning of page
672 * and let the execution do */
673 // path = gtk_tree_path_new_from_indices(0, -1);
674 // gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
675 // path, NULL, FALSE);
676 //}
677
678 //indices = gtk_tree_path_get_indices(path);
679
680 //value = gtk_adjustment_get_value(event_viewer_data->vadjust_c);
681
682 /* If events request pending, do nothing*/
683 if(lttvwindow_events_request_pending(event_viewer_data->tab)) return;
684
685 /* If no prior position... */
686 #if 0
687 if(ltt_time_compare(
688 lttv_traceset_context_position_get_time(
689 event_viewer_data->currently_selected_position),
690 ltt_time_infinite) == 0) {
691
692 path = gtk_tree_path_new_from_indices(0, -1);
693 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
694 path, NULL, FALSE);
695
696 gtk_tree_path_free(path);
697 return;
698
699 }
700 #endif //0
701
702 g_debug("tree view move cursor : arg1 is %u and arg2 is %d",
703 (guint)arg1, arg2);
704
705 switch(arg1) {
706 case GTK_MOVEMENT_DISPLAY_LINES:
707 if(arg2 == 1) {
708 /* Move one line down */
709 if(event_viewer_data->pos->len > 0) {
710 LttvTracesetContextPosition *end_pos =
711 (LttvTracesetContextPosition*)g_ptr_array_index(
712 event_viewer_data->pos,
713 event_viewer_data->pos->len-1);
714 if(lttv_traceset_context_pos_pos_compare(end_pos,
715 event_viewer_data->currently_selected_position) == 0) {
716 /* Must get down one event and select the last one */
717 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(
718 GTK_TREE_VIEW(event_viewer_data->tree_v)));
719 event_viewer_data->update_cursor = FALSE;
720 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
721 gtk_adjustment_get_value(event_viewer_data->vadjust_c) + 1);
722 event_viewer_data->update_cursor = TRUE;
723 if(event_viewer_data->pos->len > 0) {
724 path = gtk_tree_path_new_from_indices(
725 max(0, event_viewer_data->pos->len - 1), -1);
726 if(path) {
727 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
728 path, NULL, FALSE);
729 gtk_tree_path_free(path);
730 }
731 }
732 }
733 } else {
734 /* Must get down one event and select the last one */
735 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(
736 GTK_TREE_VIEW(event_viewer_data->tree_v)));
737 event_viewer_data->update_cursor = FALSE;
738 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
739 gtk_adjustment_get_value(event_viewer_data->vadjust_c) + 1);
740 event_viewer_data->update_cursor = TRUE;
741 if(event_viewer_data->pos->len > 0) {
742 path = gtk_tree_path_new_from_indices(
743 max(0, event_viewer_data->pos->len - 1), -1);
744 if(path) {
745 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
746 path, NULL, FALSE);
747 gtk_tree_path_free(path);
748 }
749 }
750 }
751
752 } else {
753 if(event_viewer_data->pos->len > 0) {
754 /* Move one line up */
755 LttvTracesetContextPosition *begin_pos =
756 (LttvTracesetContextPosition*)g_ptr_array_index(
757 event_viewer_data->pos,
758 0);
759 if(lttv_traceset_context_pos_pos_compare(begin_pos,
760 event_viewer_data->currently_selected_position) == 0) {
761 /* Must get up one event and select the first one */
762 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(
763 GTK_TREE_VIEW(event_viewer_data->tree_v)));
764 event_viewer_data->update_cursor = FALSE;
765 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
766 gtk_adjustment_get_value(event_viewer_data->vadjust_c) - 1);
767 event_viewer_data->update_cursor = TRUE;
768 if(event_viewer_data->pos->len > 0) {
769 path = gtk_tree_path_new_from_indices(
770 0, -1);
771 if(path) {
772 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
773 path, NULL, FALSE);
774 gtk_tree_path_free(path);
775 }
776 }
777 }
778 } else {
779 /* Must get up one event and select the first one */
780 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(
781 GTK_TREE_VIEW(event_viewer_data->tree_v)));
782 event_viewer_data->update_cursor = FALSE;
783 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
784 gtk_adjustment_get_value(event_viewer_data->vadjust_c) - 1);
785 event_viewer_data->update_cursor = TRUE;
786 if(event_viewer_data->pos->len > 0) {
787 path = gtk_tree_path_new_from_indices(
788 0, -1);
789 if(path) {
790 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
791 path, NULL, FALSE);
792 gtk_tree_path_free(path);
793 }
794 }
795 }
796 }
797 break;
798 case GTK_MOVEMENT_PAGES:
799 if(arg2 == 1) {
800 /* Move one page down */
801 if(event_viewer_data->pos->len > 0) {
802 LttvTracesetContextPosition *end_pos =
803 (LttvTracesetContextPosition*)g_ptr_array_index(
804 event_viewer_data->pos,
805 event_viewer_data->pos->len-1);
806 if(lttv_traceset_context_pos_pos_compare(end_pos,
807 event_viewer_data->currently_selected_position) == 0) {
808 /* Must get down one page and select the last one */
809 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(
810 GTK_TREE_VIEW(event_viewer_data->tree_v)));
811 event_viewer_data->update_cursor = FALSE;
812 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
813 gtk_adjustment_get_value(event_viewer_data->vadjust_c) + 2);
814 event_viewer_data->update_cursor = TRUE;
815 if(event_viewer_data->pos->len > 0) {
816 path = gtk_tree_path_new_from_indices(
817 event_viewer_data->pos->len - 1, -1);
818 if(path) {
819 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
820 path, NULL, FALSE);
821 gtk_tree_path_free(path);
822 }
823 }
824 }
825 } else {
826 /* Must get down one page and select the last one */
827 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(
828 GTK_TREE_VIEW(event_viewer_data->tree_v)));
829 event_viewer_data->update_cursor = FALSE;
830 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
831 gtk_adjustment_get_value(event_viewer_data->vadjust_c) + 2);
832 event_viewer_data->update_cursor = TRUE;
833 if(event_viewer_data->pos->len > 0) {
834 path = gtk_tree_path_new_from_indices(
835 event_viewer_data->pos->len - 1, -1);
836 if(path) {
837 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
838 path, NULL, FALSE);
839 gtk_tree_path_free(path);
840 }
841 }
842 }
843 } else {
844 /* Move one page up */
845 if(event_viewer_data->pos->len > 0) {
846 LttvTracesetContextPosition *begin_pos =
847 (LttvTracesetContextPosition*)g_ptr_array_index(
848 event_viewer_data->pos,
849 0);
850 if(lttv_traceset_context_pos_pos_compare(begin_pos,
851 event_viewer_data->currently_selected_position) == 0) {
852 /* Must get up one page and select the first one */
853 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(
854 GTK_TREE_VIEW(event_viewer_data->tree_v)));
855 event_viewer_data->update_cursor = FALSE;
856 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
857 gtk_adjustment_get_value(event_viewer_data->vadjust_c) - 2);
858 event_viewer_data->update_cursor = TRUE;
859 if(event_viewer_data->pos->len > 0) {
860 path = gtk_tree_path_new_from_indices(
861 0, -1);
862 if(path) {
863 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
864 path, NULL, FALSE);
865 gtk_tree_path_free(path);
866 }
867 }
868 }
869 } else {
870 /* Must get up one page and select the first one */
871 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(
872 GTK_TREE_VIEW(event_viewer_data->tree_v)));
873 event_viewer_data->update_cursor = FALSE;
874 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
875 gtk_adjustment_get_value(event_viewer_data->vadjust_c) - 2);
876 event_viewer_data->update_cursor = TRUE;
877 if(event_viewer_data->pos->len > 0) {
878 path = gtk_tree_path_new_from_indices(
879 0, -1);
880 if(path) {
881 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
882 path, NULL, FALSE);
883 gtk_tree_path_free(path);
884 }
885 }
886 }
887 }
888 break;
889 default:
890 break;
891 }
892
893 //gtk_tree_path_free(path);
894
895 #if 0
896 if(arg1 == GTK_MOVEMENT_DISPLAY_LINES)
897 {
898 /* Move one line */
899 if(arg2 == 1)
900 {
901 /* move one line down */
902 if(indices[0]) // Do we need an empty field here (before first)?
903 {
904 if(value + event_viewer_data->num_visible_events <=
905 event_viewer_data->number_of_events -1)
906 {
907 event_viewer_data->currently_selected_event += 1;
908 // gtk_adjustment_set_value(event_viewer_data->vadjust_c, value+1);
909 //gtk_tree_path_free(path);
910 //path = gtk_tree_path_new_from_indices(event_viewer_data->num_visible_events-1, -1);
911 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
912 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
913 }
914 }
915 } else {
916 /* Move one line up */
917 if(indices[0] == 0)
918 {
919 if(value - 1 >= 0 )
920 {
921 event_viewer_data->currently_selected_event -= 1;
922 // gtk_adjustment_set_value(event_viewer_data->vadjust_c, value-1);
923 //gtk_tree_path_free(path);
924 //path = gtk_tree_path_new_from_indices(0, -1);
925 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
926 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
927 }
928 }
929 }
930 }
931
932 if(arg1 == GTK_MOVEMENT_PAGES)
933 {
934 /* Move one page */
935 if(arg2 == 1)
936 {
937 if(event_viewer_data->num_visible_events == 1)
938 value += 1 ;
939 /* move one page down */
940 if(value + event_viewer_data->num_visible_events-1 <=
941 event_viewer_data->number_of_events )
942 {
943 event_viewer_data->currently_selected_event +=
944 event_viewer_data->num_visible_events-1;
945 // gtk_adjustment_set_value(event_viewer_data->vadjust_c,
946 // value+(event_viewer_data->num_visible_events-1));
947 //gtk_tree_path_free(path);
948 //path = gtk_tree_path_new_from_indices(0, -1);
949 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
950 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
951 }
952 } else {
953 /* Move one page up */
954 if(event_viewer_data->num_visible_events == 1)
955 value -= 1 ;
956
957 if(indices[0] < event_viewer_data->num_visible_events - 2 )
958 {
959 if(value - (event_viewer_data->num_visible_events-1) >= 0)
960 {
961 event_viewer_data->currently_selected_event -=
962 event_viewer_data->num_visible_events-1;
963
964 // gtk_adjustment_set_value(event_viewer_data->vadjust_c,
965 // value-(event_viewer_data->num_visible_events-1));
966 //gtk_tree_path_free(path);
967 //path = gtk_tree_path_new_from_indices(0, -1);
968 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
969 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
970
971 } else {
972 /* Go to first Event */
973 event_viewer_data->currently_selected_event == 0 ;
974 // gtk_adjustment_set_value(event_viewer_data->vadjust_c,
975 // 0);
976 //gtk_tree_path_free(path);
977 //path = gtk_tree_path_new_from_indices(0, -1);
978 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
979 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
980
981 }
982 }
983 }
984 }
985
986 if(arg1 == GTK_MOVEMENT_BUFFER_ENDS)
987 {
988 /* Move to the ends of the buffer */
989 if(arg2 == 1)
990 {
991 /* move end of buffer */
992 event_viewer_data->currently_selected_event =
993 event_viewer_data->number_of_events-1 ;
994 // gtk_adjustment_set_value(event_viewer_data->vadjust_c,
995 // event_viewer_data->number_of_events -
996 // event_viewer_data->num_visible_events);
997 //gtk_tree_path_free(path);
998 //path = gtk_tree_path_new_from_indices(event_viewer_data->num_visible_events-1, -1);
999 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
1000 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
1001 } else {
1002 /* Move beginning of buffer */
1003 event_viewer_data->currently_selected_event = 0 ;
1004 // gtk_adjustment_set_value(event_viewer_data->vadjust_c, 0);
1005 //gtk_tree_path_free(path);
1006 //path = gtk_tree_path_new_from_indices(0, -1);
1007 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
1008 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
1009 }
1010 }
1011 #endif //0
1012 }
1013
1014 static void filter_button (GtkToolButton *toolbutton,
1015 gpointer user_data)
1016 {
1017 LttvPluginEVD *plugin_evd = (LttvPluginEVD*)user_data;
1018 LttvAttribute *attribute;
1019 LttvAttributeValue value;
1020 gboolean ret;
1021 g_printf("Filter button clicked\n");
1022
1023 attribute = LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
1024 LTTV_IATTRIBUTE(lttv_global_attributes()),
1025 LTTV_VIEWER_CONSTRUCTORS));
1026 g_assert(attribute);
1027
1028 ret = lttv_iattribute_find_by_path(LTTV_IATTRIBUTE(attribute),
1029 "guifilter", LTTV_POINTER, &value);
1030 g_assert(ret);
1031 lttvwindow_viewer_constructor constructor =
1032 (lttvwindow_viewer_constructor)*(value.v_pointer);
1033 if(constructor) constructor(&plugin_evd->parent);
1034 else g_warning("Filter module not loaded.");
1035
1036 //FIXME : viewer returned.
1037 }
1038
1039 gboolean tree_v_scroll_handler (GtkWidget *widget, GdkEventScroll *event, gpointer data)
1040 {
1041 EventViewerData *event_viewer_data = (EventViewerData*) data;
1042 Tab *tab = event_viewer_data->tab;
1043
1044 switch(event->direction) {
1045 case GDK_SCROLL_UP:
1046 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
1047 gtk_adjustment_get_value(event_viewer_data->vadjust_c) - 1);
1048 break;
1049 case GDK_SCROLL_DOWN:
1050 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
1051 gtk_adjustment_get_value(event_viewer_data->vadjust_c) + 1);
1052 break;
1053 default:
1054 g_error("Only scroll up and down expected");
1055 }
1056 return TRUE;
1057 }
1058
1059 void tree_v_cursor_changed_cb (GtkWidget *widget, gpointer data)
1060 {
1061 EventViewerData *event_viewer_data = (EventViewerData*) data;
1062 Tab *tab = event_viewer_data->tab;
1063 GtkTreeIter iter;
1064 GtkTreeModel* model = GTK_TREE_MODEL(event_viewer_data->store_m);
1065 GtkTreePath *path;
1066 LttvTracesetContextPosition *pos;
1067
1068 g_debug("cursor changed cb");
1069
1070 /* On cursor change, modify the currently selected event by calling
1071 * the right API function */
1072 if(event_viewer_data->report_position) {
1073 if(event_viewer_data->pos->len > 0) {
1074 gtk_tree_view_get_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
1075 &path, NULL);
1076 if(path) {
1077 if(gtk_tree_model_get_iter(model,&iter,path)){
1078 gtk_tree_model_get(model, &iter, POSITION_COLUMN, &pos, -1);
1079
1080 if(lttv_traceset_context_pos_pos_compare(pos,
1081 event_viewer_data->currently_selected_position) != 0)
1082 lttvwindow_report_current_position(tab, pos);
1083 }else{
1084 g_warning("Can not get iter\n");
1085 }
1086 gtk_tree_path_free(path);
1087 }
1088 }
1089 }
1090 }
1091
1092
1093 static void tree_selection_changed_cb (GtkTreeSelection *selection,
1094 gpointer data)
1095 {
1096 g_debug("tree sel changed cb");
1097 EventViewerData *event_viewer_data = (EventViewerData*) data;
1098
1099 #if 0
1100 /* Set the cursor to currently selected event */
1101 GtkTreeModel* model = GTK_TREE_MODEL(event_viewer_data->store_m);
1102 GtkTreeIter iter;
1103 LttvTracesetContextPosition *pos;
1104 guint i;
1105 GtkTreePath *tree_path;
1106
1107 for(i=0;i<event_viewer_data->num_visible_events;i++) {
1108 tree_path = gtk_tree_path_new_from_indices(
1109 i,
1110 -1);
1111 if(gtk_tree_model_get_iter(model,&iter,tree_path)){
1112 gtk_tree_model_get(model, &iter, POSITION_COLUMN, &pos, -1);
1113
1114 if(lttv_traceset_context_pos_pos_compare(pos,
1115 event_viewer_data->currently_selected_position) == 0) {
1116 /* Match! */
1117 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
1118 tree_path, NULL, FALSE);
1119 break;
1120 }
1121
1122 }else{
1123 g_warning("Can not get iter\n");
1124 }
1125 gtk_tree_path_free(tree_path);
1126 }
1127 #endif //0
1128 }
1129
1130 #if 0
1131 static gint key_snooper(GtkWidget *grab_widget, GdkEventKey *event,
1132 gpointer func_data)
1133 {
1134 return TRUE;
1135 }
1136 #endif //0
1137
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. */
1142
1143 void v_scroll_cb (GtkAdjustment *adjustment, gpointer data)
1144 {
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));
1153
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)
1160 return;
1161
1162 //LttTime old_time = event_viewer_data->first_event;
1163
1164
1165 //gint snoop = gtk_key_snooper_install(key_snooper, NULL);
1166
1167 get_events(adjustment->value, event_viewer_data);
1168
1169 //gtk_key_snooper_remove(snoop);
1170 #if 0
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);
1175
1176 if(event_viewer_data->currently_selected_event != -1) {
1177
1178 tree_path = gtk_tree_path_new_from_indices(
1179 event_viewer_data->currently_selected_event,
1180 -1);
1181
1182 // gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), tree_path,
1183 // NULL, FALSE);
1184 gtk_tree_path_free(tree_path);
1185 }
1186 #endif //0
1187 g_debug("SCROLL end");
1188 }
1189
1190 static __inline gint get_cell_height(GtkTreeView *TreeView)
1191 {
1192 gint height;
1193 GtkTreeViewColumn *column = gtk_tree_view_get_column(TreeView, 0);
1194
1195 gtk_tree_view_column_cell_get_size(column, NULL, NULL, NULL, NULL, &height);
1196
1197 gint vertical_separator;
1198 gtk_widget_style_get (GTK_WIDGET (TreeView),
1199 "vertical-separator", &vertical_separator,
1200 NULL);
1201
1202 height += vertical_separator;
1203
1204 return height;
1205 }
1206
1207 void tree_v_size_allocate_cb (GtkWidget *widget, GtkAllocation *alloc, gpointer data)
1208 {
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;
1213
1214 exact_num_visible = ( alloc->height -
1215 event_viewer_data->header_height )
1216 / (double)cell_height ;
1217
1218 event_viewer_data->num_visible_events = ceil(exact_num_visible) ;
1219
1220 /*
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);
1225 */
1226
1227 g_debug("size allocate %p : last_num_visible_events : %d",
1228 event_viewer_data, last_num_visible_events);
1229 g_debug("num_visible_events : %d, value %lu",
1230 event_viewer_data->num_visible_events,
1231 event_viewer_data->vadjust_c->value);
1232
1233 if(event_viewer_data->num_visible_events != last_num_visible_events) {
1234 get_events(event_viewer_data->vadjust_c->value, event_viewer_data);
1235 }
1236
1237
1238 }
1239
1240 void tree_v_size_request_cb (GtkWidget *widget, GtkRequisition *requisition, gpointer data)
1241 {
1242 gint h;
1243 EventViewerData *event_viewer_data = (EventViewerData*)data;
1244 gint cell_height = get_cell_height(GTK_TREE_VIEW(event_viewer_data->tree_v));
1245
1246 h = cell_height + event_viewer_data->header_height;
1247 requisition->height = h;
1248
1249 }
1250
1251 #if 0
1252 gboolean show_event_detail(void * hook_data, void * call_data)
1253 {
1254 EventViewerData *event_viewer_data = (EventViewerData*) hook_data;
1255 LttvTracesetContext * tsc = lttvwindow_get_traceset_context(event_viewer_data->tab);
1256
1257 if(event_viewer_data->event_fields_queue_tmp->length == 0 &&
1258 event_viewer_data->event_fields_queue->length == 0){
1259 event_viewer_data->shown = FALSE;
1260 return FALSE;
1261 }
1262
1263 if(event_viewer_data->shown == FALSE){
1264 event_viewer_data->shown = TRUE;
1265 update_raw_data_array(event_viewer_data,
1266 event_viewer_data->event_fields_queue_tmp->length);
1267
1268 get_data(event_viewer_data->vadjust_c->value,
1269 event_viewer_data->num_visible_events,
1270 event_viewer_data);
1271
1272 remove_context_hooks(event_viewer_data,tsc);
1273 }
1274
1275 return FALSE;
1276 }
1277 #endif //0
1278
1279 static gboolean events_check_handler(guint count, gboolean *stop_flag,
1280 gpointer data)
1281 {
1282 EventViewerData *evd = (EventViewerData*)data;
1283 if(count % CHECK_GDK_INTERVAL == 0) {
1284 GdkEvent *event;
1285 GtkWidget *widget;
1286 while((event = gdk_event_get()) != NULL) {
1287 widget = gtk_get_event_widget(event);
1288 if(widget ==
1289 lookup_widget(main_window_get_widget(evd->tab),
1290 "StopProcessingButton")
1291 || widget == evd->vscroll_vc) {
1292 gtk_main_do_event(event);
1293 gdk_window_process_all_updates();
1294 }
1295 gdk_event_free(event);
1296 }
1297 if(*stop_flag)
1298 return TRUE;
1299 else
1300 return FALSE;
1301 } else return FALSE;
1302 }
1303
1304 static void get_events(double new_value, EventViewerData *event_viewer_data)
1305 {
1306 GtkTreePath *tree_path;
1307 LttvTracesetStats *tss =
1308 lttvwindow_get_traceset_stats(event_viewer_data->tab);
1309 LttvTracesetContext *tsc = (LttvTracesetContext*)tss;
1310 guint i;
1311 gboolean seek_by_time;
1312
1313 if(lttvwindow_preempt_count > 0) return;
1314
1315 double value = new_value - event_viewer_data->previous_value;
1316
1317 /* Set stop button status for foreground processing */
1318 event_viewer_data->tab->stop_foreground = FALSE;
1319 lttvwindow_events_request_disable();
1320
1321 /* See where we have to scroll... */
1322 ScrollDirection direction;
1323 gint relative_position;
1324
1325 if(value < -0.8) {
1326 if(value >= -1.0) direction = SCROLL_STEP_UP;
1327 else {
1328 if(value >= -2.0) direction = SCROLL_PAGE_UP;
1329 else direction = SCROLL_JUMP;
1330 }
1331 } else if(value > 0.8) {
1332 if(value <= 1.0) direction = SCROLL_STEP_DOWN;
1333 else {
1334 if(value <= 2.0) direction = SCROLL_PAGE_DOWN;
1335 else direction = SCROLL_JUMP;
1336 }
1337 } else direction = SCROLL_NONE; /* 0.0 */
1338
1339
1340 switch(direction) {
1341 case SCROLL_STEP_UP:
1342 g_debug("get_events : SCROLL_STEP_UP");
1343 relative_position = -1;
1344 seek_by_time = 0;
1345 break;
1346 case SCROLL_STEP_DOWN:
1347 g_debug("get_events : SCROLL_STEP_DOWN");
1348 relative_position = 1;
1349 seek_by_time = 0;
1350 break;
1351 case SCROLL_PAGE_UP:
1352 g_debug("get_events : SCROLL_PAGE_UP");
1353 relative_position = -(event_viewer_data->num_visible_events);
1354 seek_by_time = 0;
1355 break;
1356 case SCROLL_PAGE_DOWN:
1357 g_debug("get_events : SCROLL_PAGE_DOWN");
1358 relative_position = event_viewer_data->num_visible_events;
1359 seek_by_time = 0;
1360 break;
1361 case SCROLL_JUMP:
1362 g_debug("get_events : SCROLL_JUMP");
1363 seek_by_time = 1;
1364 break;
1365 case SCROLL_NONE:
1366 g_debug("get_events : SCROLL_NONE");
1367 relative_position = 0;
1368 seek_by_time = 0;
1369 break;
1370 }
1371
1372 LttTime time = ltt_time_from_double(new_value);
1373 time = ltt_time_add(tsc->time_span.start_time, time);
1374
1375 if(!seek_by_time) {
1376
1377 LttvTracesetContextPosition *pos =
1378 lttv_traceset_context_position_new(tsc);
1379
1380 /* Remember the beginning position */
1381 if(event_viewer_data->pos->len > 0) {
1382 LttvTracesetContextPosition *first_pos =
1383 (LttvTracesetContextPosition*)g_ptr_array_index(
1384 event_viewer_data->pos,
1385 0);
1386 lttv_traceset_context_position_copy(pos, first_pos);
1387
1388 if(relative_position >= 0) {
1389 LttTime first_event_time =
1390 lttv_traceset_context_position_get_time(
1391 pos);
1392 lttv_state_traceset_seek_time_closest((LttvTracesetState*)tsc,
1393 first_event_time);
1394 lttv_process_traceset_middle(tsc, ltt_time_infinite,
1395 G_MAXUINT,
1396 pos);
1397
1398 } else if(relative_position < 0) {
1399 g_assert(lttv_process_traceset_seek_position(tsc, pos) == 0);
1400 }
1401 } else {
1402 /* There is nothing in the list : simply seek to the time value. */
1403 lttv_state_traceset_seek_time_closest((LttvTracesetState*)tsc,
1404 time);
1405 lttv_process_traceset_middle(tsc, time, G_MAXUINT,
1406 NULL);
1407 }
1408
1409 /* Note that, as we mess with the tsc position, this function CANNOT be called
1410 * from a hook inside the lttv_process_traceset_middle. */
1411 /* As the lttvwindow API keeps a sync_position inside the tsc to go back at
1412 * the right spot after being interrupted, it's ok to change the tsc position,
1413 * as long as we do not touch the sync_position. */
1414
1415 /* Get the beginning position of the read (with seek backward or seek forward)
1416 */
1417 if(relative_position > 0) {
1418 guint count;
1419 count += lttv_process_traceset_seek_n_forward(tsc, relative_position,
1420 events_check_handler,
1421 &event_viewer_data->tab->stop_foreground,
1422 event_viewer_data->main_win_filter,
1423 event_viewer_data->filter, NULL, event_viewer_data);
1424 } else if(relative_position < 0) {
1425 guint count;
1426
1427 /* Get an idea of currently shown event dispersion */
1428 LttTime first_event_time =
1429 lttv_traceset_context_position_get_time(event_viewer_data->first_event);
1430 LttTime last_event_time =
1431 lttv_traceset_context_position_get_time(event_viewer_data->last_event);
1432 LttTime time_diff = ltt_time_sub(last_event_time, first_event_time);
1433 if(ltt_time_compare(time_diff, ltt_time_zero) == 0)
1434 time_diff = seek_back_default_offset;
1435
1436 count = lttv_process_traceset_seek_n_backward(tsc,
1437 abs(relative_position),
1438 time_diff,
1439 (seek_time_fct)lttv_state_traceset_seek_time_closest,
1440 events_check_handler,
1441 &event_viewer_data->tab->stop_foreground,
1442 event_viewer_data->main_win_filter,
1443 event_viewer_data->filter, NULL, event_viewer_data);
1444 } /* else 0 : do nothing : we are already at the beginning position */
1445
1446 lttv_traceset_context_position_destroy(pos);
1447
1448 /* Save the first event position */
1449 lttv_traceset_context_position_save(tsc, event_viewer_data->first_event);
1450
1451 time = lttv_traceset_context_position_get_time(
1452 event_viewer_data->first_event);
1453 //if(ltt_time_compare(time, tsc->time_span.end_time) > 0)
1454 // time = tsc->time_span.end_time;
1455
1456 LttTime time_val = ltt_time_sub(time,
1457 tsc->time_span.start_time);
1458 event_viewer_data->previous_value = ltt_time_to_double(time_val);
1459
1460 lttv_state_traceset_seek_time_closest((LttvTracesetState*)tsc, time);
1461 lttv_process_traceset_middle(tsc, ltt_time_infinite, G_MAXUINT,
1462 event_viewer_data->first_event);
1463
1464 } else {
1465 /* Seek by time */
1466 lttv_state_traceset_seek_time_closest((LttvTracesetState*)tsc,
1467 time);
1468 lttv_process_traceset_middle(tsc, time, G_MAXUINT,
1469 NULL);
1470 LttTime time_val = ltt_time_sub(time,
1471 tsc->time_span.start_time);
1472 event_viewer_data->previous_value = ltt_time_to_double(time_val);
1473 lttv_traceset_context_position_save(tsc, event_viewer_data->first_event);
1474 }
1475
1476 /* Clear the model (don't forget to free the TCS positions!) */
1477 gtk_list_store_clear(event_viewer_data->store_m);
1478 for(i=0;i<event_viewer_data->pos->len;i++) {
1479 LttvTracesetContextPosition *cur_pos =
1480 (LttvTracesetContextPosition*)g_ptr_array_index(event_viewer_data->pos,
1481 i);
1482 lttv_traceset_context_position_destroy(cur_pos);
1483 }
1484 g_ptr_array_set_size(event_viewer_data->pos, 0);
1485
1486
1487 /* Mathieu :
1488 * I make the choice not to use the mainwindow lttvwindow API here : the idle
1489 * loop might have a too low priority, and we want good update while
1490 * scrolling. However, we call the gdk loop to get events periodically so the
1491 * processing can be stopped.
1492 */
1493
1494 lttv_process_traceset_begin(tsc,
1495 NULL, NULL, NULL, event_viewer_data->event_hooks, NULL);
1496
1497 event_viewer_data->num_events = 0;
1498
1499 lttv_process_traceset_middle(tsc, ltt_time_infinite, G_MAXUINT, NULL);
1500
1501 lttv_process_traceset_end(tsc,
1502 NULL, NULL, NULL, event_viewer_data->event_hooks, NULL);
1503
1504 /* Get the end position */
1505 if(event_viewer_data->pos->len > 0) {
1506 LttvTracesetContextPosition *cur_pos =
1507 (LttvTracesetContextPosition*)g_ptr_array_index(event_viewer_data->pos,
1508 event_viewer_data->pos->len - 1);
1509 lttv_traceset_context_position_copy(event_viewer_data->last_event,
1510 cur_pos);
1511 } else
1512 lttv_traceset_context_position_save(tsc, event_viewer_data->last_event);
1513
1514 gtk_adjustment_set_value(event_viewer_data->vadjust_c,
1515 event_viewer_data->previous_value);
1516
1517 //g_signal_emit_by_name(G_OBJECT (event_viewer_data->select_c),
1518 // "changed");
1519
1520 event_viewer_data->last_tree_update_time =
1521 gdk_x11_get_server_time(
1522 gtk_widget_get_parent_window(event_viewer_data->tree_v));
1523
1524 lttvwindow_events_request_enable();
1525
1526 return;
1527 }
1528
1529
1530 int event_hook(void *hook_data, void *call_data)
1531 {
1532 EventViewerData *event_viewer_data = (EventViewerData*)hook_data;
1533 LttvTracefileContext *tfc = (LttvTracefileContext*)call_data;
1534 LttvTracefileState *tfs = (LttvTracefileState*)call_data;
1535 LttEvent *e = ltt_tracefile_get_event(tfc->tf);
1536
1537 if(event_viewer_data->num_events % CHECK_GDK_INTERVAL == 0) {
1538 GdkEvent *event;
1539 GtkWidget *widget;
1540 while((event = gdk_event_get()) != NULL) {
1541 widget = gtk_get_event_widget(event);
1542 if(widget ==
1543 lookup_widget(main_window_get_widget(event_viewer_data->tab),
1544 "StopProcessingButton")
1545 || widget == event_viewer_data->vscroll_vc) {
1546 gtk_main_do_event(event);
1547 gdk_window_process_all_updates();
1548 }
1549 gdk_event_free(event);
1550 }
1551 //gtk_main_iteration_do(FALSE);
1552 if(event_viewer_data->tab->stop_foreground)
1553 return TRUE;
1554 }
1555 event_viewer_data->num_events++;
1556
1557 LttvFilter *filter = event_viewer_data->main_win_filter;
1558 if(filter != NULL && filter->head != NULL)
1559 if(!lttv_filter_tree_parse(filter->head,e,tfc->tf,
1560 tfc->t_context->t,tfc,NULL,NULL))
1561 return FALSE;
1562
1563 filter = event_viewer_data->filter;
1564 if(filter != NULL && filter->head != NULL)
1565 if(!lttv_filter_tree_parse(filter->head,e,tfc->tf,
1566 tfc->t_context->t,tfc,NULL,NULL))
1567 return FALSE;
1568
1569
1570 // LttFacility *facility = ltt_event_facility(e);
1571 // LttEventType *event_type = ltt_event_eventtype(e);
1572 LttTime time = ltt_event_time(e);
1573
1574 guint cpu = tfs->cpu;
1575 LttvTraceState *ts = (LttvTraceState*)tfc->t_context;
1576 LttvProcessState *process = ts->running_process[cpu];
1577
1578 GtkTreeIter iter;
1579
1580 GString *desc = g_string_new("");
1581
1582 LttvTracesetContextPosition *pos =
1583 lttv_traceset_context_position_new(tfc->t_context->ts_context);
1584
1585 lttv_traceset_context_position_save(tfc->t_context->ts_context, pos);
1586
1587 lttv_event_to_string(e, desc, TRUE, TRUE, (LttvTracefileState*)tfc);
1588
1589 g_info("detail : %s", desc->str);
1590
1591 gtk_list_store_append (event_viewer_data->store_m, &iter);
1592 gtk_list_store_set (event_viewer_data->store_m, &iter,
1593 TRACE_NAME_COLUMN, g_quark_to_string(ltt_trace_name(tfc->t_context->t)),
1594 TRACEFILE_NAME_COLUMN, g_quark_to_string(ltt_tracefile_name(tfc->tf)),
1595 CPUID_COLUMN, cpu,
1596 EVENT_COLUMN, g_quark_to_string(marker_get_info_from_id(tfc->t_context->t, e->event_id)->name),
1597 TIME_S_COLUMN, time.tv_sec,
1598 TIME_NS_COLUMN, time.tv_nsec,
1599 PID_COLUMN, process->pid,
1600 EVENT_DESCR_COLUMN, desc->str,
1601 POSITION_COLUMN, pos,
1602 -1);
1603
1604 g_ptr_array_add(event_viewer_data->pos, pos);
1605
1606 g_string_free(desc, TRUE);
1607
1608 if(event_viewer_data->update_cursor) {
1609 if(lttv_traceset_context_pos_pos_compare(pos,
1610 event_viewer_data->currently_selected_position) == 0) {
1611 GtkTreePath *path = gtk_tree_path_new_from_indices(
1612 event_viewer_data->pos->len - 1, -1);
1613 if(path) {
1614 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
1615 path, NULL, FALSE);
1616 gtk_tree_path_free(path);
1617 }
1618 }
1619 }
1620
1621 if(event_viewer_data->pos->len >= event_viewer_data->num_visible_events )
1622 return TRUE;
1623 else
1624 return FALSE;
1625 }
1626
1627
1628
1629 static void event_update_selection(EventViewerData *event_viewer_data)
1630 {
1631 guint i;
1632 GPtrArray *positions = event_viewer_data->pos;
1633 g_info("event_update_selection");
1634
1635 for(i=0;i<positions->len;i++) {
1636 LttvTracesetContextPosition *cur_pos =
1637 (LttvTracesetContextPosition*)g_ptr_array_index(positions, i);
1638 if(lttv_traceset_context_pos_pos_compare(cur_pos,
1639 event_viewer_data->currently_selected_position) == 0) {
1640 GtkTreePath *path = gtk_tree_path_new_from_indices(i, -1);
1641 if(path) {
1642 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
1643 path, NULL, FALSE);
1644 gtk_tree_path_free(path);
1645 }
1646 }
1647 }
1648 }
1649
1650 static int current_time_get_first_event_hook(void *hook_data, void *call_data)
1651 {
1652 EventViewerData *event_viewer_data = (EventViewerData*)hook_data;
1653 LttvTracefileContext *tfc = (LttvTracefileContext*)call_data;
1654 LttEvent *e = ltt_tracefile_get_event(tfc->tf);
1655
1656 LttvFilter *filter = event_viewer_data->main_win_filter;
1657 if(filter != NULL && filter->head != NULL)
1658 if(!lttv_filter_tree_parse(filter->head,e,tfc->tf,
1659 tfc->t_context->t,tfc,NULL,NULL))
1660 return FALSE;
1661
1662 filter = event_viewer_data->filter;
1663 if(filter != NULL && filter->head != NULL)
1664 if(!lttv_filter_tree_parse(filter->head,e,tfc->tf,
1665 tfc->t_context->t,tfc,NULL,NULL))
1666 return FALSE;
1667
1668 lttv_traceset_context_position_save(tfc->t_context->ts_context,
1669 event_viewer_data->current_time_get_first);
1670 return TRUE;
1671 }
1672
1673
1674 gboolean update_current_time(void * hook_data, void * call_data)
1675 {
1676 g_info("update_current_time");
1677 EventViewerData *event_viewer_data = (EventViewerData*) hook_data;
1678 const LttTime * current_time = (LttTime*)call_data;
1679 LttvTracesetContext * tsc =
1680 lttvwindow_get_traceset_context(event_viewer_data->tab);
1681 GtkTreePath *path;
1682
1683 /* If the currently selected event time != current time, set the first event
1684 * with this time as currently selected. */
1685 LttTime pos_time = lttv_traceset_context_position_get_time(
1686 event_viewer_data->currently_selected_position);
1687 if(ltt_time_compare(pos_time, *current_time) != 0) {
1688
1689 lttv_state_traceset_seek_time_closest((LttvTracesetState*)tsc,
1690 *current_time);
1691 lttv_process_traceset_middle(tsc, *current_time, G_MAXUINT,
1692 NULL);
1693
1694 /* Get the first event that passes in the filter */
1695 event_viewer_data->current_time_get_first =
1696 lttv_traceset_context_position_new(tsc);
1697 LttvHooks *hooks = lttv_hooks_new();
1698 lttv_hooks_add(hooks,
1699 current_time_get_first_event_hook,
1700 event_viewer_data,
1701 LTTV_PRIO_DEFAULT);
1702
1703 lttv_process_traceset_begin(tsc,
1704 NULL, NULL, NULL, hooks, NULL);
1705
1706 lttv_process_traceset_middle(tsc, ltt_time_infinite, G_MAXUINT, NULL);
1707
1708 lttv_process_traceset_end(tsc,
1709 NULL, NULL, NULL, hooks, NULL);
1710
1711 lttv_hooks_destroy(hooks);
1712
1713 lttv_traceset_context_position_copy(
1714 event_viewer_data->currently_selected_position,
1715 event_viewer_data->current_time_get_first);
1716 lttv_traceset_context_position_destroy(
1717 event_viewer_data->current_time_get_first);
1718 pos_time = lttv_traceset_context_position_get_time(
1719 event_viewer_data->currently_selected_position);
1720 }
1721
1722 LttTime time = ltt_time_sub(pos_time, tsc->time_span.start_time);
1723 double new_value = ltt_time_to_double(time);
1724
1725 event_viewer_data->report_position = FALSE;
1726 /* Change the viewed area if does not match */
1727 if(lttv_traceset_context_pos_pos_compare(
1728 event_viewer_data->currently_selected_position,
1729 event_viewer_data->first_event) < 0
1730 ||
1731 lttv_traceset_context_pos_pos_compare(
1732 event_viewer_data->currently_selected_position,
1733 event_viewer_data->last_event) > 0) {
1734 gtk_adjustment_set_value(event_viewer_data->vadjust_c, new_value);
1735 } else {
1736 /* Simply update the current time : it is in the list */
1737 event_update_selection(event_viewer_data);
1738 }
1739 event_viewer_data->report_position = TRUE;
1740
1741 return FALSE;
1742 }
1743
1744 gboolean update_current_position(void * hook_data, void * call_data)
1745 {
1746 g_info("update_current_position");
1747 EventViewerData *event_viewer_data = (EventViewerData*) hook_data;
1748 const LttvTracesetContextPosition *current_pos =
1749 (LttvTracesetContextPosition*)call_data;
1750 LttvTracesetContext * tsc =
1751 lttvwindow_get_traceset_context(event_viewer_data->tab);
1752
1753 if(lttv_traceset_context_pos_pos_compare(
1754 event_viewer_data->currently_selected_position, current_pos) != 0) {
1755 lttv_traceset_context_position_copy(
1756 event_viewer_data->currently_selected_position, current_pos);
1757
1758 /* Change the viewed area if does not match */
1759 if(lttv_traceset_context_pos_pos_compare(
1760 event_viewer_data->currently_selected_position,
1761 event_viewer_data->first_event) < 0
1762 ||
1763 lttv_traceset_context_pos_pos_compare(
1764 event_viewer_data->currently_selected_position,
1765 event_viewer_data->last_event) > 0) {
1766 LttTime time = lttv_traceset_context_position_get_time(current_pos);
1767 time = ltt_time_sub(time, tsc->time_span.start_time);
1768 double new_value = ltt_time_to_double(time);
1769 gtk_adjustment_set_value(event_viewer_data->vadjust_c, new_value);
1770 } else {
1771 /* Simply update the current time : it is in the list */
1772 event_update_selection(event_viewer_data);
1773 }
1774
1775 }
1776
1777
1778 return FALSE;
1779 }
1780
1781
1782
1783 gboolean traceset_changed(void * hook_data, void * call_data)
1784 {
1785 EventViewerData *event_viewer_data = (EventViewerData*) hook_data;
1786 LttvTracesetContext * tsc =
1787 lttvwindow_get_traceset_context(event_viewer_data->tab);
1788 TimeInterval time_span = tsc->time_span;
1789
1790 LttTime end;
1791 gtk_list_store_clear(event_viewer_data->store_m);
1792 g_ptr_array_set_size(event_viewer_data->pos, 0);
1793
1794 end = ltt_time_sub(time_span.end_time, time_span.start_time);
1795 event_viewer_data->vadjust_c->upper = ltt_time_to_double(end);
1796
1797 /* Reset the positions */
1798 lttv_traceset_context_position_destroy(
1799 event_viewer_data->currently_selected_position);
1800 lttv_traceset_context_position_destroy(
1801 event_viewer_data->first_event);
1802 lttv_traceset_context_position_destroy(
1803 event_viewer_data->last_event);
1804
1805 event_viewer_data->currently_selected_position =
1806 lttv_traceset_context_position_new(tsc);
1807 event_viewer_data->first_event =
1808 lttv_traceset_context_position_new(tsc);
1809 event_viewer_data->last_event =
1810 lttv_traceset_context_position_new(tsc);
1811
1812 get_events(event_viewer_data->vadjust_c->value, event_viewer_data);
1813 // event_viewer_data->vadjust_c->value = 0;
1814
1815 request_background_data(event_viewer_data);
1816
1817 return FALSE;
1818 }
1819
1820 gboolean filter_changed(void * hook_data, void * call_data)
1821 {
1822 EventViewerData *event_viewer_data = (EventViewerData*) hook_data;
1823 LttvTracesetContext * tsc =
1824 lttvwindow_get_traceset_context(event_viewer_data->tab);
1825
1826 event_viewer_data->main_win_filter =
1827 (LttvFilter*)call_data;
1828 get_events(event_viewer_data->vadjust_c->value, event_viewer_data);
1829
1830 return FALSE;
1831 }
1832
1833
1834 gint evd_redraw_notify(void *hook_data, void *call_data)
1835 {
1836 EventViewerData *event_viewer_data = (EventViewerData*) hook_data;
1837
1838 get_events(event_viewer_data->vadjust_c->value, event_viewer_data);
1839 return 0;
1840 }
1841
1842 void gui_events_free(gpointer data)
1843 {
1844 LttvPluginEVD *plugin_evd = (LttvPluginEVD*)data;
1845 Tab *tab = plugin_evd->evd->tab;
1846 EventViewerData *event_viewer_data = plugin_evd->evd;
1847 guint i;
1848
1849 lttv_filter_destroy(plugin_evd->evd->filter);
1850
1851 if(tab != NULL){
1852 lttv_hooks_remove(event_viewer_data->event_hooks,event_hook);
1853 lttv_hooks_destroy(event_viewer_data->event_hooks);
1854
1855 for(i=0;i<event_viewer_data->pos->len;i++) {
1856 LttvTracesetContextPosition *cur_pos =
1857 (LttvTracesetContextPosition*)g_ptr_array_index(event_viewer_data->pos,
1858 i);
1859 lttv_traceset_context_position_destroy(cur_pos);
1860 }
1861 lttv_traceset_context_position_destroy(
1862 event_viewer_data->currently_selected_position);
1863 lttv_traceset_context_position_destroy(
1864 event_viewer_data->first_event);
1865 lttv_traceset_context_position_destroy(
1866 event_viewer_data->last_event);
1867 g_ptr_array_free(event_viewer_data->pos, TRUE);
1868
1869 lttvwindow_unregister_current_time_notify(tab,
1870 update_current_time, event_viewer_data);
1871 lttvwindow_unregister_current_position_notify(tab,
1872 update_current_position, event_viewer_data);
1873 //lttvwindow_unregister_show_notify(tab,
1874 // show_event_detail, event_viewer_data);
1875 lttvwindow_unregister_traceset_notify(tab,
1876 traceset_changed, event_viewer_data);
1877 lttvwindow_unregister_filter_notify(tab,
1878 filter_changed, event_viewer_data);
1879 lttvwindow_unregister_redraw_notify(tab,
1880 evd_redraw_notify, event_viewer_data);
1881
1882 }
1883 lttvwindowtraces_background_notify_remove(event_viewer_data);
1884
1885 g_event_viewer_data_list = g_slist_remove(g_event_viewer_data_list,
1886 event_viewer_data);
1887 //g_free(event_viewer_data);
1888 g_object_unref(plugin_evd);
1889 }
1890
1891
1892
1893 void gui_events_destructor(gpointer data)
1894 {
1895 LttvPluginEVD *plugin_evd = (LttvPluginEVD*)data;
1896 /* May already been done by GTK window closing */
1897 if(GTK_IS_WIDGET(plugin_evd->parent.top_widget)){
1898 gtk_widget_destroy(plugin_evd->parent.top_widget);
1899 }
1900 }
1901
1902
1903
1904 /**
1905 * plugin's init function
1906 *
1907 * This function initializes the Event Viewer functionnality through the
1908 * gtkTraceSet API.
1909 */
1910 static void init() {
1911
1912 lttvwindow_register_constructor("guievents",
1913 "/",
1914 "Insert Event Viewer",
1915 hGuiEventsInsert_xpm,
1916 "Insert Event Viewer",
1917 h_gui_events);
1918 }
1919
1920 void event_destroy_walk(gpointer data, gpointer user_data)
1921 {
1922 gui_events_destructor((LttvPluginEVD*)data);
1923 }
1924
1925 /**
1926 * plugin's destroy function
1927 *
1928 * This function releases the memory reserved by the module and unregisters
1929 * everything that has been registered in the gtkTraceSet API.
1930 */
1931 static void destroy() {
1932
1933 g_slist_foreach(g_event_viewer_data_list, event_destroy_walk, NULL );
1934 g_slist_free(g_event_viewer_data_list);
1935
1936 lttvwindow_unregister_constructor(h_gui_events);
1937
1938 }
1939
1940
1941
1942
1943 LTTV_MODULE("guievents", "Detailed events view", \
1944 "Graphical module to display a detailed event list", \
1945 init, destroy, "lttvwindow", "print")
This page took 0.061424 seconds and 3 git commands to generate.