header missing
[lttv.git] / ltt / branches / poly / lttv / modules / gui / detailedevents / events.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Mathieu Desnoyers and XangXiu Yang
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
19
20 //*! \defgroup GuiEvents libGuiEvents: The GUI Events display plugin */
21 /*\@{*/
22
23 /*! \file GuiEvents.c
24 * \brief Graphical plugin for showing events.
25 *
26 * This plugin lists all the events contained in the current time interval
27 * in a list.
28 *
29 * This plugin adds a Events Viewer functionnality to Linux TraceToolkit
30 * GUI when this plugin is loaded. The init and destroy functions add the
31 * viewer's insertion menu item and toolbar icon by calling viewer.h's
32 * API functions. Then, when a viewer's object is created, the constructor
33 * creates ans register through API functions what is needed to interact
34 * with the lttvwindow.
35 *
36 * Authors : Mathieu Desnoyers and XangXiu Yang, June to December 2003
37 * Inspired from original LTT, made by Karim Yaghmour
38 */
39
40 #include <math.h>
41
42 #include <glib.h>
43 #include <gtk/gtk.h>
44 #include <gdk/gdk.h>
45 #include <string.h>
46
47 #include <ltt/ltt.h>
48 #include <ltt/event.h>
49 #include <ltt/type.h>
50 #include <ltt/trace.h>
51 #include <ltt/facility.h>
52 #include <lttv/module.h>
53 #include <lttv/hook.h>
54 #include <lttv/tracecontext.h>
55 #include <lttv/state.h>
56 #include <lttv/filter.h>
57 #include <lttvwindow/lttvwindow.h>
58
59 #include "hGuiEventsInsert.xpm"
60
61 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
62 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
63
64
65 /** Array containing instanced objects. Used when module is unloaded */
66 static GSList *g_event_viewer_data_list = NULL ;
67
68 typedef struct _EventFields{
69 unsigned cpu_id;
70 char * event_name;
71 LttTime time;
72 int pid;
73 unsigned entry_length;
74 char * event_description;
75 LttEventPosition *ep;
76 } EventFields;
77
78 #define RESERVE_BIG_SIZE 1000
79 #define RESERVE_SMALL_SIZE 100
80 #define RESERVE_SMALL_SIZE_SQUARE RESERVE_SMALL_SIZE*RESERVE_SMALL_SIZE
81 #define RESERVE_SMALL_SIZE_CUBE RESERVE_SMALL_SIZE*RESERVE_SMALL_SIZE_SQUARE
82
83 static const LttTime ltt_time_backward = { 1 , 0 };
84
85 typedef enum _ScrollDirection{
86 SCROLL_STEP_UP,
87 SCROLL_STEP_DOWN,
88 SCROLL_PAGE_UP,
89 SCROLL_PAGE_DOWN,
90 SCROLL_JUMP,
91 SCROLL_NONE
92 } ScrollDirection;
93
94 typedef struct _EventViewerData {
95
96 Tab * tab;
97 LttvHooks * event_hooks;
98
99 gboolean append; // prepend or append item
100 GQueue * event_fields_queue; // buf to contain event fields
101 GQueue * event_fields_queue_tmp; // tmp buf to contain event fields
102 unsigned current_event_index;
103
104 /* previous value is used to determine if it is a page up/down or
105 * step up/down, in which case we move of a certain amount of events (one or
106 * the number of events shown on the screen) instead of changing begin time.
107 */
108 double previous_value;
109
110 gint start_event_index; // the first event shown in the window
111 gint end_event_index; // the last event shown in the window
112 gint size; // maxi number of events loaded
113
114 //scroll window containing Tree View
115 GtkWidget * scroll_win;
116
117 /* Model containing list data */
118 GtkListStore *store_m;
119
120 GtkWidget *hbox_v;
121 /* Widget to display the data in a columned list */
122 GtkWidget *tree_v;
123 GtkAdjustment *vtree_adjust_c ;
124 GtkWidget *button; /* a button of the header, used to get the header_height */
125 gint header_height;
126
127 /* Vertical scrollbar and its adjustment */
128 GtkWidget *vscroll_vc;
129 GtkAdjustment *vadjust_c;
130
131 /* Selection handler */
132 GtkTreeSelection *select_c;
133
134 gint num_visible_events;
135 gint first_event, last_event;
136
137 gint number_of_events ;
138 gint currently_selected_event;
139 gboolean selected_event ;
140
141 } EventViewerData ;
142
143 /** hook functions for update time interval, current time ... */
144 gboolean update_current_time(void * hook_data, void * call_data);
145 //gboolean show_event_detail(void * hook_data, void * call_data);
146 gboolean traceset_changed(void * hook_data, void * call_data);
147 void remove_item_from_queue(GQueue * q, gboolean fromHead);
148 void remove_all_items_from_queue(GQueue * q);
149 void add_context_hooks(EventViewerData * event_viewer_data,
150 LttvTracesetContext * tsc);
151 void remove_context_hooks(EventViewerData * event_viewer_data,
152 LttvTracesetContext * tsc);
153
154 //! Event Viewer's constructor hook
155 GtkWidget *h_gui_events(Tab *tab);
156 //! Event Viewer's constructor
157 EventViewerData *gui_events(Tab *tab);
158 //! Event Viewer's destructor
159 void gui_events_destructor(EventViewerData *event_viewer_data);
160 void gui_events_free(EventViewerData *event_viewer_data);
161
162 static gboolean
163 header_size_allocate(GtkWidget *widget,
164 GtkAllocation *allocation,
165 gpointer user_data);
166
167 void tree_v_set_cursor(EventViewerData *event_viewer_data);
168 void tree_v_get_cursor(EventViewerData *event_viewer_data);
169
170 /* Prototype for selection handler callback */
171 static void tree_selection_changed_cb (GtkTreeSelection *selection, gpointer data);
172 static void v_scroll_cb (GtkAdjustment *adjustment, gpointer data);
173 static void tree_v_size_allocate_cb (GtkWidget *widget, GtkAllocation *alloc, gpointer data);
174 static void tree_v_size_request_cb (GtkWidget *widget, GtkRequisition *requisition, gpointer data);
175 static void tree_v_cursor_changed_cb (GtkWidget *widget, gpointer data);
176 static void tree_v_move_cursor_cb (GtkWidget *widget, GtkMovementStep arg1, gint arg2, gpointer data);
177
178
179 static void get_data(double time, guint list_height,
180 EventViewerData *event_viewer_data);
181
182 static void update_raw_data_array(EventViewerData* event_viewer_data, unsigned size);
183
184 static void get_events(EventViewerData* event_viewer_data, LttTime start,
185 LttTime end, unsigned max_num_events, unsigned * real_num_events);
186
187 static gboolean parse_event(void *hook_data, void *call_data);
188
189 /* Enumeration of the columns */
190 enum
191 {
192 CPUID_COLUMN,
193 EVENT_COLUMN,
194 TIME_COLUMN,
195 PID_COLUMN,
196 ENTRY_LEN_COLUMN,
197 EVENT_DESCR_COLUMN,
198 N_COLUMNS
199 };
200
201
202 /**
203 * Event Viewer's constructor hook
204 *
205 * This constructor is given as a parameter to the menuitem and toolbar button
206 * registration. It creates the list.
207 * @param parent_window A pointer to the parent window.
208 * @return The widget created.
209 */
210 GtkWidget *
211 h_gui_events(Tab * tab)
212 {
213 EventViewerData* event_viewer_data = gui_events(tab) ;
214 if(event_viewer_data)
215 return event_viewer_data->hbox_v;
216 else return NULL;
217
218 }
219
220 /**
221 * Event Viewer's constructor
222 *
223 * This constructor is used to create EventViewerData data structure.
224 * @return The Event viewer data created.
225 */
226 EventViewerData *
227 gui_events(Tab *tab)
228 {
229 LttTime end;
230 GtkTreeViewColumn *column;
231 GtkCellRenderer *renderer;
232 EventViewerData* event_viewer_data = g_new(EventViewerData,1) ;
233
234 event_viewer_data->tab = tab;
235
236 event_viewer_data->event_hooks = lttv_hooks_new();
237 lttv_hooks_add(event_viewer_data->event_hooks, parse_event, event_viewer_data, LTTV_PRIO_DEFAULT);
238
239 event_viewer_data->event_fields_queue = g_queue_new();
240 event_viewer_data->event_fields_queue_tmp = g_queue_new();
241
242 lttvwindow_register_current_time_notify(tab,
243 update_current_time,event_viewer_data);
244 //lttvwindow_register_show_notify(tab,
245 // show_event_detail,event_viewer_data);
246 lttvwindow_register_traceset_notify(tab,
247 traceset_changed,event_viewer_data);
248
249 event_viewer_data->scroll_win = gtk_scrolled_window_new (NULL, NULL);
250 gtk_widget_show (event_viewer_data->scroll_win);
251 gtk_scrolled_window_set_policy(
252 GTK_SCROLLED_WINDOW(event_viewer_data->scroll_win),
253 GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
254
255 /* TEST DATA, TO BE READ FROM THE TRACE */
256 event_viewer_data->currently_selected_event = 0;
257 event_viewer_data->selected_event = FALSE;
258
259 /* Create a model for storing the data list */
260 event_viewer_data->store_m = gtk_list_store_new (
261 N_COLUMNS, /* Total number of columns */
262 G_TYPE_INT, /* CPUID */
263 G_TYPE_STRING, /* Event */
264 G_TYPE_UINT64, /* Time */
265 G_TYPE_INT, /* PID */
266 G_TYPE_INT, /* Entry length */
267 G_TYPE_STRING); /* Event's description */
268
269 /* Create the viewer widget for the columned list */
270 event_viewer_data->tree_v =
271 gtk_tree_view_new_with_model (GTK_TREE_MODEL (event_viewer_data->store_m));
272
273 g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "size-allocate",
274 G_CALLBACK (tree_v_size_allocate_cb),
275 event_viewer_data);
276 g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "size-request",
277 G_CALLBACK (tree_v_size_request_cb),
278 event_viewer_data);
279
280 g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "cursor-changed",
281 G_CALLBACK (tree_v_cursor_changed_cb),
282 event_viewer_data);
283
284 g_signal_connect (G_OBJECT (event_viewer_data->tree_v), "move-cursor",
285 G_CALLBACK (tree_v_move_cursor_cb),
286 event_viewer_data);
287
288 // Use on each column!
289 //gtk_tree_view_column_set_sizing(event_viewer_data->tree_v, GTK_TREE_VIEW_COLUMN_FIXED);
290
291 /* The view now holds a reference. We can get rid of our own
292 * reference */
293 g_object_unref (G_OBJECT (event_viewer_data->store_m));
294
295
296 /* Create a column, associating the "text" attribute of the
297 * cell_renderer to the first column of the model */
298 /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */
299 renderer = gtk_cell_renderer_text_new ();
300 column = gtk_tree_view_column_new_with_attributes ("CPUID",
301 renderer,
302 "text", CPUID_COLUMN,
303 NULL);
304 gtk_tree_view_column_set_alignment (column, 0.0);
305 gtk_tree_view_column_set_fixed_width (column, 45);
306 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v), column);
307
308 event_viewer_data->button = column->button;
309
310 g_signal_connect (G_OBJECT(event_viewer_data->button),
311 "size-allocate",
312 G_CALLBACK(header_size_allocate),
313 (gpointer)event_viewer_data);
314
315 renderer = gtk_cell_renderer_text_new ();
316 column = gtk_tree_view_column_new_with_attributes ("Event",
317 renderer,
318 "text", EVENT_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), column);
323
324 renderer = gtk_cell_renderer_text_new ();
325 column = gtk_tree_view_column_new_with_attributes ("Time",
326 renderer,
327 "text", TIME_COLUMN,
328 NULL);
329 gtk_tree_view_column_set_alignment (column, 1.0);
330 gtk_tree_view_column_set_fixed_width (column, 120);
331 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v), column);
332
333 renderer = gtk_cell_renderer_text_new ();
334 column = gtk_tree_view_column_new_with_attributes ("PID",
335 renderer,
336 "text", PID_COLUMN,
337 NULL);
338 gtk_tree_view_column_set_alignment (column, 1.0);
339 gtk_tree_view_column_set_fixed_width (column, 45);
340 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v), column);
341
342 renderer = gtk_cell_renderer_text_new ();
343 column = gtk_tree_view_column_new_with_attributes ("Entry Length",
344 renderer,
345 "text", ENTRY_LEN_COLUMN,
346 NULL);
347 gtk_tree_view_column_set_alignment (column, 1.0);
348 gtk_tree_view_column_set_fixed_width (column, 60);
349 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v), column);
350
351 renderer = gtk_cell_renderer_text_new ();
352 column = gtk_tree_view_column_new_with_attributes ("Event Description",
353 renderer,
354 "text", EVENT_DESCR_COLUMN,
355 NULL);
356 gtk_tree_view_column_set_alignment (column, 0.0);
357 gtk_tree_view_append_column (GTK_TREE_VIEW (event_viewer_data->tree_v), column);
358
359
360 /* Setup the selection handler */
361 event_viewer_data->select_c = gtk_tree_view_get_selection (GTK_TREE_VIEW (event_viewer_data->tree_v));
362 gtk_tree_selection_set_mode (event_viewer_data->select_c, GTK_SELECTION_SINGLE);
363 g_signal_connect (G_OBJECT (event_viewer_data->select_c), "changed",
364 G_CALLBACK (tree_selection_changed_cb),
365 event_viewer_data);
366
367 gtk_container_add (GTK_CONTAINER (event_viewer_data->scroll_win), event_viewer_data->tree_v);
368
369 event_viewer_data->hbox_v = gtk_hbox_new(0, 0);
370 gtk_box_pack_start(GTK_BOX(event_viewer_data->hbox_v), event_viewer_data->scroll_win, TRUE, TRUE, 0);
371
372 /* Create vertical scrollbar and pack it */
373 event_viewer_data->vscroll_vc = gtk_vscrollbar_new(NULL);
374 gtk_range_set_update_policy (GTK_RANGE(event_viewer_data->vscroll_vc),
375 GTK_UPDATE_CONTINUOUS);
376 // Changed by MD : more user friendly :)
377 //GTK_UPDATE_DISCONTINUOUS);
378 gtk_box_pack_start(GTK_BOX(event_viewer_data->hbox_v), event_viewer_data->vscroll_vc, FALSE, TRUE, 0);
379
380 /* Get the vertical scrollbar's adjustment */
381 event_viewer_data->vadjust_c = gtk_range_get_adjustment(GTK_RANGE(event_viewer_data->vscroll_vc));
382 event_viewer_data->vtree_adjust_c = gtk_tree_view_get_vadjustment(
383 GTK_TREE_VIEW (event_viewer_data->tree_v));
384
385 g_signal_connect (G_OBJECT (event_viewer_data->vadjust_c), "value-changed",
386 G_CALLBACK (v_scroll_cb),
387 event_viewer_data);
388 /* Set the upper bound to the last event number */
389 event_viewer_data->previous_value = 0;
390 event_viewer_data->vadjust_c->lower = 0.0;
391 //event_viewer_data->vadjust_c->upper = event_viewer_data->number_of_events;
392 event_viewer_data->vadjust_c->value = 0.0;
393 event_viewer_data->vadjust_c->step_increment = 1.0;
394 event_viewer_data->vadjust_c->page_increment = 2.0;
395 // event_viewer_data->vtree_adjust_c->upper;
396 event_viewer_data->vadjust_c->page_size = 2.0;
397 // event_viewer_data->vtree_adjust_c->upper;
398 /* Raw event trace */
399 gtk_widget_show(event_viewer_data->hbox_v);
400 gtk_widget_show(event_viewer_data->tree_v);
401 gtk_widget_show(event_viewer_data->vscroll_vc);
402
403 /* Add the object's information to the module's array */
404 g_event_viewer_data_list = g_slist_append(g_event_viewer_data_list, event_viewer_data);
405
406 event_viewer_data->first_event = -1 ;
407 event_viewer_data->last_event = 0 ;
408
409 event_viewer_data->num_visible_events = 1;
410
411 //get the life span of the traceset and set the upper of the scroll bar
412
413 LttvTracesetContext * tsc =
414 lttvwindow_get_traceset_context(event_viewer_data->tab);
415 TimeInterval time_span = tsc->time_span;
416 end = ltt_time_sub(time_span.end_time, time_span.start_time);
417
418 event_viewer_data->vadjust_c->upper =
419 ltt_time_to_double(end);
420
421 event_viewer_data->append = TRUE;
422
423 event_viewer_data->start_event_index = 0;
424 event_viewer_data->end_event_index = event_viewer_data->num_visible_events - 1;
425
426 /* Set the Selected Event */
427 // tree_v_set_cursor(event_viewer_data);
428
429 // event_viewer_data->current_time_updated = FALSE;
430 event_viewer_data->size = RESERVE_SMALL_SIZE;
431
432 g_object_set_data_full(
433 G_OBJECT(event_viewer_data->hbox_v),
434 "event_viewer_data",
435 event_viewer_data,
436 (GDestroyNotify)gui_events_free);
437
438
439 return event_viewer_data;
440 }
441
442
443
444 static gboolean
445 header_size_allocate(GtkWidget *widget,
446 GtkAllocation *allocation,
447 gpointer user_data)
448 {
449 EventViewerData *event_viewer_data = (EventViewerData*)user_data;
450
451 event_viewer_data->header_height = allocation->height;
452
453 return 0;
454 }
455
456
457 void tree_v_set_cursor(EventViewerData *event_viewer_data)
458 {
459 GtkTreePath *path;
460
461 if(event_viewer_data->selected_event && event_viewer_data->first_event != -1)
462 {
463 path = gtk_tree_path_new_from_indices(
464 event_viewer_data->currently_selected_event-
465 event_viewer_data->first_event,
466 -1);
467
468 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
469 gtk_tree_path_free(path);
470 }
471 }
472
473 void tree_v_get_cursor(EventViewerData *event_viewer_data)
474 {
475 GtkTreePath *path;
476 gint *indices;
477
478 gtk_tree_view_get_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), &path, NULL);
479 indices = gtk_tree_path_get_indices(path);
480
481 if(indices != NULL)
482 {
483 event_viewer_data->selected_event = TRUE;
484 event_viewer_data->currently_selected_event =
485 event_viewer_data->first_event + indices[0];
486
487 } else {
488 event_viewer_data->selected_event = FALSE;
489 event_viewer_data->currently_selected_event = 0;
490 }
491
492 gtk_tree_path_free(path);
493
494 }
495
496
497
498 void tree_v_move_cursor_cb (GtkWidget *widget,
499 GtkMovementStep arg1,
500 gint arg2,
501 gpointer data)
502 {
503 GtkTreePath *path; // = gtk_tree_path_new();
504 gint *indices;
505 gdouble value;
506 EventViewerData *event_viewer_data = (EventViewerData*)data;
507
508 gtk_tree_view_get_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
509 &path, NULL);
510 if(path == NULL)
511 {
512 /* No prior cursor, put it at beginning of page
513 * and let the execution do */
514 path = gtk_tree_path_new_from_indices(0, -1);
515 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v),
516 path, NULL, FALSE);
517 }
518
519 indices = gtk_tree_path_get_indices(path);
520
521 value = gtk_adjustment_get_value(event_viewer_data->vadjust_c);
522
523 if(arg1 == GTK_MOVEMENT_DISPLAY_LINES)
524 {
525 /* Move one line */
526 if(arg2 == 1)
527 {
528 /* move one line down */
529 if(indices[0] == event_viewer_data->num_visible_events - 1)
530 {
531 if(value + event_viewer_data->num_visible_events <=
532 event_viewer_data->number_of_events -1)
533 {
534 event_viewer_data->currently_selected_event += 1;
535 // gtk_adjustment_set_value(event_viewer_data->vadjust_c, value+1);
536 //gtk_tree_path_free(path);
537 //path = gtk_tree_path_new_from_indices(event_viewer_data->num_visible_events-1, -1);
538 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
539 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
540 }
541 }
542 } else {
543 /* Move one line up */
544 if(indices[0] == 0)
545 {
546 if(value - 1 >= 0 )
547 {
548 event_viewer_data->currently_selected_event -= 1;
549 // gtk_adjustment_set_value(event_viewer_data->vadjust_c, value-1);
550 //gtk_tree_path_free(path);
551 //path = gtk_tree_path_new_from_indices(0, -1);
552 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
553 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
554 }
555 }
556 }
557 }
558
559 if(arg1 == GTK_MOVEMENT_PAGES)
560 {
561 /* Move one page */
562 if(arg2 == 1)
563 {
564 if(event_viewer_data->num_visible_events == 1)
565 value += 1 ;
566 /* move one page down */
567 if(value + event_viewer_data->num_visible_events-1 <=
568 event_viewer_data->number_of_events )
569 {
570 event_viewer_data->currently_selected_event +=
571 event_viewer_data->num_visible_events-1;
572 // gtk_adjustment_set_value(event_viewer_data->vadjust_c,
573 // value+(event_viewer_data->num_visible_events-1));
574 //gtk_tree_path_free(path);
575 //path = gtk_tree_path_new_from_indices(0, -1);
576 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
577 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
578 }
579 } else {
580 /* Move one page up */
581 if(event_viewer_data->num_visible_events == 1)
582 value -= 1 ;
583
584 if(indices[0] < event_viewer_data->num_visible_events - 2 )
585 {
586 if(value - (event_viewer_data->num_visible_events-1) >= 0)
587 {
588 event_viewer_data->currently_selected_event -=
589 event_viewer_data->num_visible_events-1;
590
591 // gtk_adjustment_set_value(event_viewer_data->vadjust_c,
592 // value-(event_viewer_data->num_visible_events-1));
593 //gtk_tree_path_free(path);
594 //path = gtk_tree_path_new_from_indices(0, -1);
595 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
596 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
597
598 } else {
599 /* Go to first Event */
600 event_viewer_data->currently_selected_event == 0 ;
601 // gtk_adjustment_set_value(event_viewer_data->vadjust_c,
602 // 0);
603 //gtk_tree_path_free(path);
604 //path = gtk_tree_path_new_from_indices(0, -1);
605 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
606 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
607
608 }
609 }
610 }
611 }
612
613 if(arg1 == GTK_MOVEMENT_BUFFER_ENDS)
614 {
615 /* Move to the ends of the buffer */
616 if(arg2 == 1)
617 {
618 /* move end of buffer */
619 event_viewer_data->currently_selected_event =
620 event_viewer_data->number_of_events-1 ;
621 // gtk_adjustment_set_value(event_viewer_data->vadjust_c,
622 // event_viewer_data->number_of_events -
623 // event_viewer_data->num_visible_events);
624 //gtk_tree_path_free(path);
625 //path = gtk_tree_path_new_from_indices(event_viewer_data->num_visible_events-1, -1);
626 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
627 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
628 } else {
629 /* Move beginning of buffer */
630 event_viewer_data->currently_selected_event = 0 ;
631 // gtk_adjustment_set_value(event_viewer_data->vadjust_c, 0);
632 //gtk_tree_path_free(path);
633 //path = gtk_tree_path_new_from_indices(0, -1);
634 //gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
635 g_signal_stop_emission_by_name(G_OBJECT(widget), "move-cursor");
636 }
637 }
638
639 gtk_tree_path_free(path);
640 }
641
642 void tree_v_cursor_changed_cb (GtkWidget *widget, gpointer data)
643 {
644 EventViewerData *event_viewer_data = (EventViewerData*) data;
645 Tab *tab = event_viewer_data->tab;
646 LttTime current_time = lttvwindow_get_current_time(tab);
647 LttTime ltt_time;
648 guint64 time;
649 GtkTreeIter iter;
650 GtkTreeModel* model = GTK_TREE_MODEL(event_viewer_data->store_m);
651 GtkTreePath *path;
652
653 /* On cursor change, modify the currently selected event by calling
654 * the right API function */
655 tree_v_get_cursor(event_viewer_data);
656
657 gtk_tree_view_get_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), &path, NULL);
658 if(gtk_tree_model_get_iter(model,&iter,path)){
659 gtk_tree_model_get(model, &iter, TIME_COLUMN, &time, -1);
660 ltt_time.tv_sec = time / NANOSECONDS_PER_SECOND;
661 ltt_time.tv_nsec = time % NANOSECONDS_PER_SECOND;
662
663 if(ltt_time.tv_sec != current_time.tv_sec ||
664 ltt_time.tv_nsec != current_time.tv_nsec){
665 // event_viewer_data->current_time_updated = TRUE;
666 lttvwindow_report_current_time(tab,ltt_time);
667 }
668 }else{
669 g_warning("Can not get iter\n");
670 }
671
672 }
673
674
675 void v_scroll_cb (GtkAdjustment *adjustment, gpointer data)
676 {
677 EventViewerData *event_viewer_data = (EventViewerData*)data;
678 GtkTreePath *tree_path;
679
680 get_data(adjustment->value, event_viewer_data->num_visible_events,
681 event_viewer_data);
682
683
684 if(event_viewer_data->currently_selected_event
685 >= event_viewer_data->first_event
686 &&
687 event_viewer_data->currently_selected_event
688 <= event_viewer_data->last_event
689 &&
690 event_viewer_data->selected_event)
691 {
692
693 tree_path = gtk_tree_path_new_from_indices(
694 event_viewer_data->currently_selected_event-
695 event_viewer_data->first_event,
696 -1);
697
698 // gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), tree_path,
699 // NULL, FALSE);
700 gtk_tree_path_free(tree_path);
701 }
702 }
703
704 static __inline gint get_cell_height(GtkTreeView *TreeView)
705 {
706 gint height;
707 GtkTreeViewColumn *column = gtk_tree_view_get_column(TreeView, 0);
708
709 gtk_tree_view_column_cell_get_size(column, NULL, NULL, NULL, NULL, &height);
710
711 return height;
712 }
713
714 void tree_v_size_allocate_cb (GtkWidget *widget, GtkAllocation *alloc, gpointer data)
715 {
716 EventViewerData *event_viewer_data = (EventViewerData*)data;
717 gint cell_height = get_cell_height(GTK_TREE_VIEW(event_viewer_data->tree_v));
718 gint last_num_visible_events = event_viewer_data->num_visible_events;
719 gdouble exact_num_visible;
720
721 exact_num_visible = ( alloc->height -
722 event_viewer_data->header_height )
723 / (double)cell_height ;
724
725 event_viewer_data->num_visible_events = ceil(exact_num_visible) ;
726
727 /*
728 event_viewer_data->vadjust_c->page_increment =
729 floor(exact_num_visible);
730 event_viewer_data->vadjust_c->page_size =
731 floor(exact_num_visible);
732 */
733
734 g_debug("size allocate : last_num_visible_events : %d,\
735 num_visible_events : %d",
736 last_num_visible_events,
737 event_viewer_data->num_visible_events);
738 if(event_viewer_data->num_visible_events != last_num_visible_events)
739 {
740 get_data(event_viewer_data->vadjust_c->value,
741 event_viewer_data->num_visible_events,
742 event_viewer_data);
743 }
744
745
746 }
747
748 void tree_v_size_request_cb (GtkWidget *widget, GtkRequisition *requisition, gpointer data)
749 {
750 gint h;
751 EventViewerData *event_viewer_data = (EventViewerData*)data;
752 gint cell_height = get_cell_height(GTK_TREE_VIEW(event_viewer_data->tree_v));
753
754 h = cell_height + event_viewer_data->header_height;
755 requisition->height = h;
756
757 }
758
759 #if 0
760 gboolean show_event_detail(void * hook_data, void * call_data)
761 {
762 EventViewerData *event_viewer_data = (EventViewerData*) hook_data;
763 LttvTracesetContext * tsc = lttvwindow_get_traceset_context(event_viewer_data->tab);
764
765 if(event_viewer_data->event_fields_queue_tmp->length == 0 &&
766 event_viewer_data->event_fields_queue->length == 0){
767 event_viewer_data->shown = FALSE;
768 return FALSE;
769 }
770
771 if(event_viewer_data->shown == FALSE){
772 event_viewer_data->shown = TRUE;
773 update_raw_data_array(event_viewer_data,
774 event_viewer_data->event_fields_queue_tmp->length);
775
776 get_data(event_viewer_data->vadjust_c->value,
777 event_viewer_data->num_visible_events,
778 event_viewer_data);
779
780 remove_context_hooks(event_viewer_data,tsc);
781 }
782
783 return FALSE;
784 }
785 #endif //0
786
787
788 void insert_data_into_model(EventViewerData *event_viewer_data, int start, int end)
789 {
790 int i;
791 guint64 real_data;
792 EventFields * raw_data;
793 GList * first;
794 GtkTreeIter iter;
795
796 first = event_viewer_data->event_fields_queue->head;
797 for(i=start; i<end; i++){
798 if(i>=event_viewer_data->number_of_events) break;
799 raw_data = (EventFields*)g_list_nth_data(first, i);
800
801 // Add a new row to the model
802 real_data = raw_data->time.tv_sec;
803 real_data *= NANOSECONDS_PER_SECOND;
804 real_data += raw_data->time.tv_nsec;
805 gtk_list_store_append (event_viewer_data->store_m, &iter);
806 gtk_list_store_set (event_viewer_data->store_m, &iter,
807 CPUID_COLUMN, raw_data->cpu_id,
808 EVENT_COLUMN, raw_data->event_name,
809 TIME_COLUMN, real_data,
810 PID_COLUMN, raw_data->pid,
811 ENTRY_LEN_COLUMN, raw_data->entry_length,
812 EVENT_DESCR_COLUMN, raw_data->event_description,
813 -1);
814 }
815 }
816
817 static void get_data_wrapped(double time_value, gint list_height,
818 EventViewerData *event_viewer_data, LttEvent *ev);
819
820 static void get_data(double time_value, guint list_height,
821 EventViewerData *event_viewer_data)
822 {
823 LttEvent * ev = ltt_event_new();
824
825 get_data_wrapped(time_value, list_height,
826 event_viewer_data, ev);
827
828 ltt_event_destroy(ev);
829 }
830
831 static void get_data_wrapped(double time_value, gint list_height,
832 EventViewerData *event_viewer_data, LttEvent *ev)
833 {
834 int i;
835 GtkTreeModel *model = GTK_TREE_MODEL(event_viewer_data->store_m);
836 EventFields * event_fields;
837 ScrollDirection direction = SCROLL_NONE;
838 GList * first;
839 gint event_number = event_viewer_data->start_event_index;
840 double value = event_viewer_data->previous_value - time_value;
841 LttTime start, end, time;
842 gint backward_num, minNum, maxNum;
843 LttTracefile * tf;
844 unsigned block_num;
845 gint size = 1, count = 0;
846 gboolean need_backward_again, backward;
847 LttvTracesetContext * tsc =
848 lttvwindow_get_traceset_context(event_viewer_data->tab);
849 TimeInterval time_span = tsc->time_span;
850
851 // if(event_number > event_viewer_data->last_event ||
852 // event_number + list_height-1 < event_viewer_data->first_event ||
853 // event_viewer_data->first_event == -1)
854 {
855 /* no event can be reused, clear and start from nothing */
856 if(value < 0.0) {
857 if(value >= -1.0) direction = SCROLL_STEP_DOWN;
858 else if(value >= -2.0) direction = SCROLL_PAGE_DOWN;
859 else direction = SCROLL_JUMP;
860 } else if(value > 0.0) {
861 if(value <= 1.0) direction = SCROLL_STEP_UP;
862 else if(value <= 2.0) direction = SCROLL_PAGE_UP;
863 else direction = SCROLL_JUMP;
864 }
865 else direction = SCROLL_NONE; /* 0.0 */
866
867 if(g_queue_get_length(event_viewer_data->event_fields_queue)==0)
868 direction = SCROLL_JUMP;
869
870 switch(direction){
871 case SCROLL_STEP_UP:
872 if(direction == SCROLL_STEP_UP) g_debug("direction STEP_UP");
873 case SCROLL_PAGE_UP:
874 if(direction == SCROLL_PAGE_UP) g_debug("direction PAGE_UP");
875 if(direction == SCROLL_PAGE_UP){
876 backward = list_height>event_viewer_data->start_event_index ? TRUE : FALSE;
877 }else{
878 backward = event_viewer_data->start_event_index == 0 ? TRUE : FALSE;
879 }
880 if(backward){
881 first = event_viewer_data->event_fields_queue->head;
882 if(!first)break;
883 event_fields = (EventFields*)first->data;
884 LttTime backward_start = event_fields->time;
885
886 maxNum = RESERVE_SMALL_SIZE_CUBE;
887 event_viewer_data->append = FALSE;
888 do{
889 if(direction == SCROLL_PAGE_UP){
890 minNum = list_height - event_viewer_data->start_event_index ;
891 }else{
892 minNum = 1;
893 }
894 first = event_viewer_data->event_fields_queue->head;
895 if(!first)break;
896 event_fields = (EventFields*)first->data;
897 end = event_fields->time;
898
899 backward_start = LTT_TIME_MAX(ltt_time_sub(backward_start,
900 ltt_time_backward),
901 tsc->time_span.start_time);
902
903 event_viewer_data->current_event_index = event_viewer_data->start_event_index;
904 get_events(event_viewer_data, backward_start, end, maxNum, &size);
905 event_viewer_data->start_event_index = event_viewer_data->current_event_index;
906
907 if(size < minNum
908 && (ltt_time_compare(backward_start, tsc->time_span.start_time)>0))
909 need_backward_again = TRUE;
910 else need_backward_again = FALSE;
911 if(size == 0){
912 count++;
913 }else{
914 count = 0;
915 }
916 }while(need_backward_again);
917 }
918 if(direction == SCROLL_STEP_UP)
919 event_number = event_viewer_data->start_event_index - 1;
920 else
921 event_number = event_viewer_data->start_event_index - list_height;
922 break;
923 case SCROLL_STEP_DOWN:
924 g_debug("direction STEP_DOWN");
925 if(event_viewer_data->end_event_index == event_viewer_data->number_of_events - 1){
926 event_viewer_data->append = TRUE;
927 first = event_viewer_data->event_fields_queue->head;
928 if(!first)break;
929 event_fields = (EventFields*)g_list_nth_data(first,event_viewer_data->number_of_events - 1);
930 start = event_fields->time;
931 start.tv_nsec++;
932 end = ltt_time_infinite;
933 get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE, &size);
934 if(size == 0){
935 get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE_SQUARE,&size);
936 if(size == 0)
937 get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE_CUBE,&size);
938 }
939 if(size==0) event_number = event_viewer_data->start_event_index;
940 else event_number = event_viewer_data->number_of_events - size - list_height + 1;
941 }else event_number = event_viewer_data->start_event_index + 1;
942 break;
943 case SCROLL_PAGE_DOWN:
944 g_debug("direction PAGE_DOWN");
945 i = event_viewer_data->number_of_events - 1 - list_height;
946 if((gint)(event_viewer_data->end_event_index) >= i){
947 int remain_events = event_viewer_data->number_of_events - 1
948 - event_viewer_data->end_event_index;
949 event_viewer_data->append = TRUE;
950 first = event_viewer_data->event_fields_queue->head;
951 if(!first)break;
952 event_fields = (EventFields*)g_list_nth_data(first,event_viewer_data->number_of_events - 1);
953 start = event_fields->time;
954 start.tv_nsec++;
955 end = ltt_time_infinite;
956 get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE,&size);
957 if(size == 0){
958 get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE_SQUARE,&size);
959 if(size == 0)
960 get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE_CUBE,&size);
961 }
962 remain_events += size;
963 if(list_height <= remain_events)
964 event_number = event_viewer_data->number_of_events - remain_events - 1;
965 else
966 event_number = event_viewer_data->number_of_events - 1 - list_height;
967 }else event_number = event_viewer_data->start_event_index + list_height - 1;
968 break;
969 case SCROLL_JUMP:
970 g_debug("direction SCROLL_JUMP");
971 event_viewer_data->append = TRUE;
972 remove_all_items_from_queue(event_viewer_data->event_fields_queue);
973 end = ltt_time_infinite;
974 time = ltt_time_from_double(time_value);
975 start = ltt_time_add(time_span.start_time, time);
976 event_viewer_data->previous_value = time_value;
977 get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE,&size);
978 if(size < list_height && size > 0){
979 event_viewer_data->append = FALSE;
980 first = event_viewer_data->event_fields_queue->head;
981 if(!first)break;
982 event_fields = (EventFields*)first->data;
983 end = event_fields->time;
984 if(end.tv_nsec != 0)
985 end.tv_nsec--;
986 else {
987 g_assert(end.tv_sec != 0);
988 end.tv_sec--;
989 end.tv_nsec = NANOSECONDS_PER_SECOND-1;
990 }
991
992 gint event_num;
993 ltt_event_position_get(event_fields->ep, &block_num, &event_num, &tf);
994
995 if(event_num > list_height - size){
996 backward_num = event_num > RESERVE_SMALL_SIZE
997 ? event_num - RESERVE_SMALL_SIZE : 1;
998 ltt_event_position_set(event_fields->ep, block_num, backward_num);
999 ltt_tracefile_seek_position(tf, event_fields->ep);
1000 g_assert(ltt_tracefile_read(tf,ev) != NULL);
1001 start = ltt_event_time(ev);
1002 maxNum = RESERVE_SMALL_SIZE_CUBE;
1003 event_viewer_data->current_event_index = 0;
1004 get_events(event_viewer_data, start, end, maxNum, &size);
1005 event_viewer_data->start_event_index = event_viewer_data->current_event_index;
1006 }
1007 event_number = event_viewer_data->event_fields_queue->length - list_height;
1008 }else if(size == 0){
1009 get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE_SQUARE,&size);
1010 if(size == 0)
1011 get_events(event_viewer_data, start, end, RESERVE_SMALL_SIZE_CUBE,&size);
1012 event_number = 0;
1013 }else{
1014 event_number = 0;
1015 }
1016 break;
1017 case SCROLL_NONE:
1018 g_debug("direction SCROLL_NONE");
1019 event_number = event_viewer_data->current_event_index;
1020 break;
1021 default:
1022 break;
1023 }
1024
1025 if(event_number < 0) event_number = 0;
1026
1027 //update the value of the scroll bar
1028 if(direction != SCROLL_NONE && direction != SCROLL_JUMP){
1029 g_debug("updating scrollbar value because near.");
1030 first = event_viewer_data->event_fields_queue->head;
1031 if(first){
1032 event_fields = (EventFields*)g_list_nth_data(first,event_number);
1033 if(!event_fields) event_fields = (EventFields*)g_list_nth_data(first,0);
1034 time = ltt_time_sub(event_fields->time, time_span.start_time);
1035 event_viewer_data->vadjust_c->value = ltt_time_to_double(time);
1036 //gtk_adjustment_set_value(event_viewer_data->vadjust_c,
1037 // ltt_time_to_double(time));
1038 //g_signal_stop_emission_by_name(G_OBJECT(event_viewer_data->vadjust_c), "value-changed");
1039 event_viewer_data->previous_value = event_viewer_data->vadjust_c->value;
1040 //gtk_adjustment_value_changed(event_viewer_data->vadjust_c);
1041 }
1042 }
1043
1044
1045 event_viewer_data->start_event_index = event_number;
1046 event_viewer_data->end_event_index = event_number + list_height - 1;
1047 if(event_viewer_data->end_event_index > event_viewer_data->number_of_events - 1){
1048 event_viewer_data->end_event_index = event_viewer_data->number_of_events - 1;
1049 }
1050
1051 first = event_viewer_data->event_fields_queue->head;
1052 gtk_list_store_clear(event_viewer_data->store_m);
1053 if(!first){
1054 // event_viewer_data->previous_value = 0;
1055 // event_viewer_data->vadjust_c->value = 0.0;
1056 // gtk_widget_hide(event_viewer_data->vscroll_vc);
1057 goto LAST;
1058 }else gtk_widget_show(event_viewer_data->vscroll_vc);
1059
1060 insert_data_into_model(event_viewer_data,event_number, event_number+list_height);
1061 }
1062
1063 event_viewer_data->first_event = event_viewer_data->start_event_index ;
1064 event_viewer_data->last_event = event_viewer_data->end_event_index ;
1065
1066 LAST:
1067 return;
1068
1069 }
1070
1071 void add_test_data(EventViewerData *event_viewer_data)
1072 {
1073 GtkTreeIter iter;
1074 int i;
1075
1076 for(i=0; i<10; i++)
1077 {
1078 /* Add a new row to the model */
1079 gtk_list_store_append (event_viewer_data->store_m, &iter);
1080 gtk_list_store_set (event_viewer_data->store_m, &iter,
1081 CPUID_COLUMN, 0,
1082 EVENT_COLUMN, "event irq",
1083 TIME_COLUMN, i,
1084 PID_COLUMN, 100,
1085 ENTRY_LEN_COLUMN, 17,
1086 EVENT_DESCR_COLUMN, "Detailed information",
1087 -1);
1088 }
1089
1090 }
1091
1092 void
1093 gui_events_free(EventViewerData *event_viewer_data)
1094 {
1095 Tab *tab = event_viewer_data->tab;
1096
1097 if(event_viewer_data){
1098 lttv_hooks_remove(event_viewer_data->event_hooks,parse_event);
1099 lttv_hooks_destroy(event_viewer_data->event_hooks);
1100
1101 remove_all_items_from_queue (event_viewer_data->event_fields_queue);
1102 g_queue_free(event_viewer_data->event_fields_queue);
1103 g_queue_free(event_viewer_data->event_fields_queue_tmp);
1104
1105 lttvwindow_unregister_current_time_notify(tab,
1106 update_current_time, event_viewer_data);
1107 //lttvwindow_unregister_show_notify(tab,
1108 // show_event_detail, event_viewer_data);
1109 lttvwindow_unregister_traceset_notify(tab,
1110 traceset_changed, event_viewer_data);
1111
1112 g_event_viewer_data_list = g_slist_remove(g_event_viewer_data_list, event_viewer_data);
1113 g_free(event_viewer_data);
1114 }
1115 }
1116
1117 void
1118 gui_events_destructor(EventViewerData *event_viewer_data)
1119 {
1120
1121 /* May already been done by GTK window closing */
1122 if(GTK_IS_WIDGET(event_viewer_data->hbox_v)){
1123 gtk_widget_destroy(event_viewer_data->hbox_v);
1124 }
1125 }
1126
1127
1128 static void
1129 tree_selection_changed_cb (GtkTreeSelection *selection, gpointer data)
1130 {
1131 EventViewerData *event_viewer_data = (EventViewerData*)data;
1132 GtkTreeIter iter;
1133 GtkTreeModel *model = GTK_TREE_MODEL(event_viewer_data->store_m);
1134 gchar *event;
1135
1136 if (gtk_tree_selection_get_selected (selection, &model, &iter))
1137 {
1138 gtk_tree_model_get (model, &iter, EVENT_COLUMN, &event, -1);
1139
1140 g_free (event);
1141 }
1142 }
1143
1144
1145 #if 0
1146 /* If every module uses the filter, maybe these two
1147 * (add/remove_context_hooks functions) should be put in common place
1148 */
1149 void add_context_hooks(EventViewerData * event_viewer_data,
1150 LttvTracesetContext * tsc)
1151 {
1152 gint i, j, k, m,n, nbi, id;
1153 gint nb_tracefile, nb_facility, nb_event;
1154 LttTrace *trace;
1155 LttvTraceContext *tc;
1156 LttvTracefileContext *tfc;
1157 gboolean selected;
1158 LttFacility * fac;
1159 LttEventType * et;
1160
1161 //if there are hooks for traceset, add them here
1162
1163 nbi = lttv_traceset_number(tsc->ts);
1164 for(i = 0 ; i < nbi ; i++) {
1165 t_s = lttv_traceset_selector_trace_get(ts_s,i);
1166 selected = lttv_trace_selector_get_selected(t_s);
1167 if(!selected) continue;
1168 tc = tsc->traces[i];
1169 trace = tc->t;
1170 //if there are hooks for trace, add them here
1171
1172 nb_tracefile = ltt_trace_control_tracefile_number(trace) +
1173 ltt_trace_per_cpu_tracefile_number(trace);
1174
1175 for(j = 0 ; j < nb_tracefile ; j++) {
1176 tf_s = lttv_trace_selector_tracefile_get(t_s,j);
1177 selected = lttv_tracefile_selector_get_selected(tf_s);
1178 if(!selected) continue;
1179 tfc = tc->tracefiles[j];
1180
1181 //if there are hooks for tracefile, add them here
1182 // lttv_tracefile_context_add_hooks(tfc, NULL,NULL,NULL,NULL,
1183 // event_viewer_data->event_hooks,NULL);
1184
1185 nb_facility = ltt_trace_facility_number(trace);
1186 n = 0;
1187 for(k=0;k<nb_facility;k++){
1188 fac = ltt_trace_facility_get(trace,k);
1189 nb_event = (int) ltt_facility_eventtype_number(fac);
1190 for(m=0;m<nb_event;m++){
1191 et = ltt_facility_eventtype_get(fac,m);
1192 eventtype = lttv_tracefile_selector_eventtype_get(tf_s, n);
1193 selected = lttv_eventtype_selector_get_selected(eventtype);
1194 if(selected){
1195 id = (gint) ltt_eventtype_id(et);
1196 lttv_tracefile_context_add_hooks_by_id(tfc,id,
1197 event_viewer_data->event_hooks);
1198 }
1199 n++;
1200 }
1201 }
1202
1203 }
1204 }
1205
1206 //add hooks for process_traceset
1207 // lttv_traceset_context_add_hooks(tsc, NULL, NULL, NULL, NULL, NULL, NULL,
1208 // NULL, NULL, NULL,event_viewer_data->event_hooks,NULL);
1209 }
1210
1211
1212 void remove_context_hooks(EventViewerData * event_viewer_data,
1213 LttvTracesetContext * tsc)
1214 {
1215 gint i, j, k, m, nbi, n, id;
1216 gint nb_tracefile, nb_facility, nb_event;
1217 LttTrace *trace;
1218 LttvTraceContext *tc;
1219 LttvTracefileContext *tfc;
1220 LttvTracesetSelector * ts_s;
1221 LttvTraceSelector * t_s;
1222 LttvTracefileSelector * tf_s;
1223 gboolean selected;
1224 LttFacility * fac;
1225 LttEventType * et;
1226 LttvEventtypeSelector * eventtype;
1227
1228 ts_s = (LttvTracesetSelector*)g_object_get_data(G_OBJECT(event_viewer_data->hbox_v),
1229 event_viewer_data->filter_key);
1230
1231 //if there are hooks for traceset, remove them here
1232
1233 nbi = lttv_traceset_number(tsc->ts);
1234 for(i = 0 ; i < nbi ; i++) {
1235 t_s = lttv_traceset_selector_trace_get(ts_s,i);
1236 selected = lttv_trace_selector_get_selected(t_s);
1237 if(!selected) continue;
1238 tc = tsc->traces[i];
1239 trace = tc->t;
1240 //if there are hooks for trace, remove them here
1241
1242 nb_tracefile = ltt_trace_control_tracefile_number(trace) +
1243 ltt_trace_per_cpu_tracefile_number(trace);
1244
1245 for(j = 0 ; j < nb_tracefile ; j++) {
1246 tf_s = lttv_trace_selector_tracefile_get(t_s,j);
1247 selected = lttv_tracefile_selector_get_selected(tf_s);
1248 if(!selected) continue;
1249 tfc = tc->tracefiles[j];
1250
1251 //if there are hooks for tracefile, remove them here
1252 // lttv_tracefile_context_remove_hooks(tfc, NULL,NULL,NULL,NULL,
1253 // event_viewer_data->event_hooks,NULL);
1254
1255 nb_facility = ltt_trace_facility_number(trace);
1256 n = 0;
1257 for(k=0;k<nb_facility;k++){
1258 fac = ltt_trace_facility_get(trace,k);
1259 nb_event = (int) ltt_facility_eventtype_number(fac);
1260 for(m=0;m<nb_event;m++){
1261 et = ltt_facility_eventtype_get(fac,m);
1262 eventtype = lttv_tracefile_selector_eventtype_get(tf_s, n);
1263 selected = lttv_eventtype_selector_get_selected(eventtype);
1264 if(selected){
1265 id = (gint) ltt_eventtype_id(et);
1266 lttv_tracefile_context_remove_hooks_by_id(tfc,id);
1267 }
1268 n++;
1269 }
1270 }
1271 }
1272 }
1273 //remove hooks from context
1274 // lttv_traceset_context_remove_hooks(tsc, NULL, NULL, NULL, NULL, NULL, NULL,
1275 // NULL, NULL, NULL,event_viewer_data->event_hooks,NULL);
1276 }
1277 #endif //0
1278
1279 gboolean update_current_time(void * hook_data, void * call_data)
1280 {
1281 EventViewerData *event_viewer_data = (EventViewerData*) hook_data;
1282 const LttTime * current_time = (LttTime*)call_data;
1283 guint64 nsec = (guint64)current_time->tv_sec * NANOSECONDS_PER_SECOND
1284 + (guint64)current_time->tv_nsec;
1285 GtkTreeIter iter;
1286 guint64 time;
1287 GtkTreeModel* model = (GtkTreeModel*)event_viewer_data->store_m;
1288 GList * list;
1289 EventFields * data, *data1;
1290 GtkTreePath* path;
1291 char str_path[64];
1292 guint i;
1293 gint j;
1294 LttTime t;
1295 LttvTracesetContext * tsc =
1296 lttvwindow_get_traceset_context(event_viewer_data->tab);
1297 TimeInterval time_span = tsc->time_span;
1298
1299 if(!event_viewer_data->event_fields_queue->head) return FALSE;
1300 #if 0
1301 if(event_viewer_data->current_time_updated ){
1302 event_viewer_data->current_time_updated = FALSE;
1303 return FALSE;
1304 }
1305 #endif //0
1306 //check if the event is shown in the current viewer
1307 gint count = 0;
1308 gboolean event_shown = FALSE;
1309 if(gtk_tree_model_get_iter_first(model, &iter)){
1310 gtk_tree_model_get(model, &iter, TIME_COLUMN, &time, -1);
1311 if(time > nsec){
1312 /* Event is before the list */
1313 } else {
1314 /* Event can be in the list */
1315 if(time >= nsec){
1316 /* found */
1317 event_shown = TRUE;
1318 } else {
1319 while(gtk_tree_model_iter_next(model, &iter)) {
1320 gtk_tree_model_get(model, &iter, TIME_COLUMN, &time, -1);
1321 count++;
1322 if(time >= nsec){
1323 /* found */
1324 event_shown = TRUE;
1325 break;
1326 }
1327 }
1328 }
1329 }
1330 }
1331
1332 if(!event_shown)
1333 {
1334 //the event is not shown in the current viewer
1335 count = 0;
1336 //check if the event is in the buffer
1337 list = event_viewer_data->event_fields_queue->head;
1338 data = (EventFields*)g_list_nth_data(list,0);
1339 data1 = (EventFields*)g_list_nth_data(list,event_viewer_data->event_fields_queue->length-1);
1340 #if 0
1341 //the event is in the buffer
1342 if(ltt_time_compare(data->time, *current_time)<=0 &&
1343 ltt_time_compare(data1->time, *current_time)>=0){
1344 for(i=0;i<event_viewer_data->event_fields_queue->length;i++){
1345 data = (EventFields*)g_list_nth_data(list,i);
1346 if(ltt_time_compare(data->time, *current_time) < 0){
1347 count++;
1348 continue;
1349 }
1350 break;
1351 }
1352 if((gint)event_viewer_data->event_fields_queue->length-count
1353 < event_viewer_data->num_visible_events){
1354 j = event_viewer_data->event_fields_queue->length - event_viewer_data->num_visible_events;
1355 count -= j;
1356 data = (EventFields*)g_list_nth_data(list,j);
1357 }else{
1358 j = count;
1359 count = 0;
1360 }
1361 t = ltt_time_sub(data->time, time_span.start_time);
1362 event_viewer_data->vadjust_c->value = ltt_time_to_double(t);
1363 //gtk_adjustment_set_value(event_viewer_data->vadjust_c,
1364 // ltt_time_to_double(t));
1365 //g_signal_stop_emission_by_name(G_OBJECT(event_viewer_data->vadjust_c), "value-changed");
1366 event_viewer_data->previous_value = event_viewer_data->vadjust_c->value;
1367 insert_data_into_model(event_viewer_data,j, j+event_viewer_data->num_visible_events);
1368 //gtk_adjustment_value_changed(event_viewer_data->vadjust_c);
1369
1370 }else{//the event is not in the buffer
1371 #endif //0
1372 LttTime start = ltt_time_sub(*current_time, time_span.start_time);
1373 double position = ltt_time_to_double(start);
1374 gtk_adjustment_set_value(event_viewer_data->vadjust_c, position);
1375 //}
1376 }
1377
1378 sprintf(str_path,"%d",count);
1379 path = gtk_tree_path_new_from_string (str_path);
1380 gtk_tree_view_set_cursor(GTK_TREE_VIEW(event_viewer_data->tree_v), path, NULL, FALSE);
1381 //g_signal_stop_emission_by_name(G_OBJECT(event_viewer_data->tree_v), "cursor-changed");
1382 gtk_tree_path_free(path);
1383
1384 return FALSE;
1385 }
1386
1387 gboolean traceset_changed(void * hook_data, void * call_data)
1388 {
1389 EventViewerData *event_viewer_data = (EventViewerData*) hook_data;
1390 LttvTracesetContext * tsc =
1391 lttvwindow_get_traceset_context(event_viewer_data->tab);
1392 TimeInterval time_span = tsc->time_span;
1393
1394 LttTime end;
1395 remove_all_items_from_queue(event_viewer_data->event_fields_queue);
1396 gtk_list_store_clear(event_viewer_data->store_m);
1397 event_viewer_data->append = TRUE;
1398
1399 end = ltt_time_sub(time_span.end_time, time_span.start_time);
1400 event_viewer_data->vadjust_c->upper = ltt_time_to_double(end);
1401 g_signal_emit_by_name(event_viewer_data->vadjust_c, "value-changed");
1402 // event_viewer_data->vadjust_c->value = 0;
1403
1404 return FALSE;
1405 }
1406
1407
1408 void update_raw_data_array(EventViewerData* event_viewer_data, unsigned size)
1409 {
1410 EventFields * data;
1411 if(size > 0){
1412 int pid, tmpPid, i,j,len;
1413 GList * list, *tmpList;
1414 GArray * pid_array, * tmp_pid_array;
1415
1416 pid_array = g_array_sized_new(FALSE, TRUE, sizeof(int), 10);
1417 tmp_pid_array = g_array_sized_new(FALSE, TRUE, sizeof(int), 10);
1418
1419 //if the queue is full, remove some data, keep the size of the queue constant
1420 while(event_viewer_data->event_fields_queue->length + size > RESERVE_BIG_SIZE){
1421 remove_item_from_queue(event_viewer_data->event_fields_queue,
1422 event_viewer_data->append);
1423 }
1424
1425 //update pid if it is not known
1426 if(event_viewer_data->event_fields_queue->length > 0){
1427 list = event_viewer_data->event_fields_queue->head;
1428 tmpList = event_viewer_data->event_fields_queue_tmp->head;
1429 if(event_viewer_data->append){
1430 for(i=(gint)event_viewer_data->event_fields_queue->length-1;i>=0;i--){
1431 data = (EventFields*)g_list_nth_data(list,i);
1432 len = data->pid==0 ? -2 : data->pid;
1433 if(data->cpu_id+1 > pid_array->len){
1434 pid_array = g_array_set_size(pid_array,data->cpu_id+1);
1435 pid_array = g_array_insert_val(pid_array,data->cpu_id,len);
1436 pid_array = g_array_remove_index(pid_array,data->cpu_id+1);
1437 }else if(data->cpu_id+1 < pid_array->len){
1438 pid = g_array_index(pid_array,int,data->cpu_id);
1439 if(pid == 0){
1440 pid_array = g_array_insert_val(pid_array,data->cpu_id,len);
1441 pid_array = g_array_remove_index(pid_array,data->cpu_id+1);
1442 }
1443 }
1444 }
1445
1446 for(i=0;i<(gint)event_viewer_data->event_fields_queue_tmp->length;i++){
1447 data = (EventFields*)g_list_nth_data(tmpList,i);
1448 len = data->pid==0 ? -2 : data->pid;
1449 if(data->cpu_id+1 > tmp_pid_array->len){
1450 tmp_pid_array = g_array_set_size(tmp_pid_array,data->cpu_id+1);
1451 tmp_pid_array = g_array_insert_val(tmp_pid_array,data->cpu_id,len);
1452 tmp_pid_array = g_array_remove_index(tmp_pid_array,data->cpu_id+1);
1453 }else if(data->cpu_id+1 < tmp_pid_array->len){
1454 pid = g_array_index(tmp_pid_array,int,data->cpu_id);
1455 if(pid == 0){
1456 tmp_pid_array = g_array_insert_val(tmp_pid_array,data->cpu_id,len);
1457 tmp_pid_array = g_array_remove_index(tmp_pid_array,data->cpu_id+1);
1458 }
1459 }
1460 }
1461 }else{
1462 for(i=0;i<(gint)event_viewer_data->event_fields_queue->length;i++){
1463 data = (EventFields*)g_list_nth_data(list,i);
1464 len = data->pid==0 ? -2 : data->pid;
1465 if(data->cpu_id+1 > pid_array->len){
1466 pid_array = g_array_set_size(pid_array,data->cpu_id+1);
1467 pid_array = g_array_insert_val(pid_array,data->cpu_id,len);
1468 pid_array = g_array_remove_index(pid_array,data->cpu_id+1);
1469 }else if(data->cpu_id+1 < pid_array->len){
1470 pid = g_array_index(pid_array,int,data->cpu_id);
1471 if(pid == 0){
1472 pid_array = g_array_insert_val(pid_array,data->cpu_id,len);
1473 pid_array = g_array_remove_index(pid_array,data->cpu_id+1);
1474 }
1475 }
1476 }
1477
1478 for(i=(gint)event_viewer_data->event_fields_queue_tmp->length-1;i>=0;i--){
1479 data = (EventFields*)g_list_nth_data(tmpList,i);
1480 len = data->pid==0 ? -2 : data->pid;
1481 if(data->cpu_id+1 > tmp_pid_array->len){
1482 tmp_pid_array = g_array_set_size(tmp_pid_array,data->cpu_id+1);
1483 tmp_pid_array = g_array_insert_val(tmp_pid_array,data->cpu_id,len);
1484 tmp_pid_array = g_array_remove_index(tmp_pid_array,data->cpu_id+1);
1485 }else if(data->cpu_id+1 < tmp_pid_array->len){
1486 pid = g_array_index(tmp_pid_array,int,data->cpu_id);
1487 if(pid == 0){
1488 tmp_pid_array = g_array_insert_val(tmp_pid_array,data->cpu_id,len);
1489 tmp_pid_array = g_array_remove_index(tmp_pid_array,data->cpu_id+1);
1490 }
1491 }
1492 }
1493 }
1494
1495 len = (pid_array->len > tmp_pid_array->len) ?
1496 tmp_pid_array->len : pid_array->len;
1497 for(j=0;j<len;j++){
1498 pid = g_array_index(pid_array,int, j);
1499 tmpPid = g_array_index(tmp_pid_array,int,j);
1500 if(pid == -2)pid = 0;
1501 if(tmpPid == -2) tmpPid = 0;
1502
1503 if(pid == -1 && tmpPid != -1){
1504 for(i=0;i<(gint)event_viewer_data->event_fields_queue->length;i++){
1505 data = (EventFields*)g_list_nth_data(list,i);
1506 if(data->pid == -1 && (gint)data->cpu_id == j) data->pid = tmpPid;
1507 }
1508 }else if(pid != -1 && tmpPid == -1){
1509 for(i=0;i<(gint)event_viewer_data->event_fields_queue_tmp->length;i++){
1510 data = (EventFields*)g_list_nth_data(tmpList,i);
1511 if(data->pid == -1 && (gint)data->cpu_id == j) data->pid = pid;
1512 }
1513 }
1514 }
1515 }
1516
1517 g_array_free(pid_array,TRUE);
1518 g_array_free(tmp_pid_array, TRUE);
1519
1520 //add data from tmp queue into the queue
1521 event_viewer_data->number_of_events =
1522 event_viewer_data->event_fields_queue->length
1523 + event_viewer_data->event_fields_queue_tmp->length;
1524 if(event_viewer_data->append){
1525 if(event_viewer_data->event_fields_queue->length > 0)
1526 event_viewer_data->current_event_index = event_viewer_data->event_fields_queue->length - 1;
1527 else event_viewer_data->current_event_index = 0;
1528 while((data = g_queue_pop_head(event_viewer_data->event_fields_queue_tmp)) != NULL){
1529 g_queue_push_tail(event_viewer_data->event_fields_queue, data);
1530 }
1531 }else{
1532 event_viewer_data->current_event_index += event_viewer_data->event_fields_queue_tmp->length;
1533 while((data = g_queue_pop_tail(event_viewer_data->event_fields_queue_tmp)) != NULL){
1534 g_queue_push_head(event_viewer_data->event_fields_queue, data);
1535 }
1536 }
1537 }
1538 }
1539
1540 void get_events(EventViewerData* event_viewer_data, LttTime start,
1541 LttTime end,unsigned max_num_events, unsigned * real_num_events)
1542 {
1543 LttvTracesetContext * tsc = lttvwindow_get_traceset_context(event_viewer_data->tab);
1544 Tab *tab = event_viewer_data->tab;
1545
1546 //add_context_hooks(event_viewer_data,tsc);
1547 //seek state because we use the main window's traceset context.
1548 lttv_state_traceset_seek_time_closest(LTTV_TRACESET_STATE(tsc), start);
1549 lttv_process_traceset_middle(tsc, start, G_MAXUINT, NULL);
1550 lttv_process_traceset_begin(tsc,
1551 NULL,
1552 NULL,
1553 NULL,
1554 event_viewer_data->event_hooks,
1555 NULL);
1556 if(event_viewer_data->append == TRUE) {
1557 /* append data */
1558 lttv_process_traceset_middle(tsc, end, max_num_events, NULL);
1559 } else{
1560 guint count;
1561 LttvTracefileContext *tfc;
1562 /* prepend data */
1563 do {
1564 /* clear the temp list */
1565 while(g_queue_pop_head(event_viewer_data->event_fields_queue_tmp));
1566 /* read max_num events max */
1567 count = lttv_process_traceset_middle(tsc, end, max_num_events, NULL);
1568 /* loop if reached the max number of events to read, but not
1569 * if end of trace or end time reached.*/
1570 tfc = lttv_traceset_context_get_current_tfc(tsc);
1571 } while(max_num_events == count
1572 && (tfc != NULL && ltt_time_compare(tfc->timestamp, end) < 0));
1573
1574 }
1575
1576 //remove_context_hooks(event_viewer_data,tsc);
1577 lttv_process_traceset_end(tsc,
1578 NULL,
1579 NULL,
1580 NULL,
1581 event_viewer_data->event_hooks,
1582 NULL);
1583 int size;
1584
1585 size = event_viewer_data->event_fields_queue_tmp->length;
1586 *real_num_events = size;
1587
1588 update_raw_data_array(event_viewer_data,size);
1589
1590 #if 0
1591 EventsRequest *events_request = g_new(EventsRequest, 1);
1592 // Create the hooks
1593 LttvHooks *event = lttv_hooks_new();
1594 LttvHooks *after_request = lttv_hooks_new();
1595
1596 lttv_hooks_add(after_request,
1597 after_get_events,
1598 events_request,
1599 LTTV_PRIO_DEFAULT);
1600 lttv_hooks_add(event,
1601 parse_event,
1602 event_viewer_data,
1603 LTTV_PRIO_DEFAULT);
1604
1605 // Fill the events request
1606 events_request->owner = event_viewer_data;
1607 events_request->viewer_data = event_viewer_data;
1608 events_request->servicing = FALSE;
1609 events_request->start_time = start;
1610 events_request->start_position = NULL;
1611 events_request->stop_flag = FALSE;
1612 events_request->end_time = ltt_time_infinite;
1613 events_request->num_events = max_num_events;
1614 events_request->end_position = NULL;
1615 events_request->trace = -1; /* FIXME */
1616 events_request->hooks = NULL; /* FIXME */
1617 events_request->before_chunk_traceset = NULL;
1618 events_request->before_chunk_trace = NULL;
1619 events_request->before_chunk_tracefile = NULL;
1620 events_request->event = event;
1621 events_request->event_by_id = NULL;
1622 events_request->after_chunk_tracefile = NULL;
1623 events_request->after_chunk_trace = NULL;
1624 events_request->after_chunk_traceset = NULL;
1625 events_request->before_request = NULL;
1626 events_request->after_request = after_request;
1627
1628 g_debug("req : start : %u, %u", start.tv_sec,
1629 start.tv_nsec);
1630
1631 lttvwindow_events_request_remove_all(tab,
1632 event_viewer_data);
1633 lttvwindow_events_request(tab, events_request);
1634 #endif //0
1635 }
1636 #if 0
1637 static int after_get_events(void *hook_data, void *call_data)
1638 {
1639 EventViewerData *event_viewer_data = (EventViewerData *)hook_data;
1640 int size;
1641
1642 size = event_viewer_data->event_fields_queue_tmp->length;
1643 *real_num_events = size;
1644
1645 update_raw_data_array(event_viewer_data,size);
1646 }
1647 #endif //0
1648
1649 static void get_event_detail(LttEvent *e, LttField *f, GString * s)
1650 {
1651 LttType *type;
1652 LttField *element;
1653 char *name;
1654 int nb, i;
1655
1656 type = ltt_field_type(f);
1657 switch(ltt_type_class(type)) {
1658 case LTT_INT:
1659 g_string_append_printf(s, " %ld", ltt_event_get_long_int(e,f));
1660 break;
1661
1662 case LTT_UINT:
1663 g_string_append_printf(s, " %lu", ltt_event_get_long_unsigned(e,f));
1664 break;
1665
1666 case LTT_FLOAT:
1667 g_string_append_printf(s, " %g", ltt_event_get_double(e,f));
1668 break;
1669
1670 case LTT_STRING:
1671 g_string_append_printf(s, " \"%s\"", ltt_event_get_string(e,f));
1672 break;
1673
1674 case LTT_ENUM:
1675 g_string_append_printf(s, " %s", ltt_enum_string_get(type,
1676 ltt_event_get_unsigned(e,f)-1));
1677 break;
1678
1679 case LTT_ARRAY:
1680 case LTT_SEQUENCE:
1681 g_string_append_printf(s, " {");
1682 nb = ltt_event_field_element_number(e,f);
1683 element = ltt_field_element(f);
1684 for(i = 0 ; i < nb ; i++) {
1685 ltt_event_field_element_select(e,f,i);
1686 get_event_detail(e, element, s);
1687 }
1688 g_string_append_printf(s, " }");
1689 break;
1690
1691 case LTT_STRUCT:
1692 g_string_append_printf(s, " {");
1693 nb = ltt_type_member_number(type);
1694 for(i = 0 ; i < nb ; i++) {
1695 element = ltt_field_member(f,i);
1696 ltt_type_member_type(type, i, &name);
1697 g_string_append_printf(s, " %s = ", name);
1698 get_event_detail(e, element, s);
1699 }
1700 g_string_append_printf(s, " }");
1701 break;
1702
1703 case LTT_UNION:
1704 g_string_append_printf(s, " {");
1705 nb = ltt_type_member_number(type);
1706 for(i = 0 ; i < nb ; i++) {
1707 element = ltt_field_member(f,i);
1708 ltt_type_member_type(type, i, &name);
1709 g_string_append_printf(s, " %s = ", name);
1710 get_event_detail(e, element, s);
1711 }
1712 g_string_append_printf(s, " }");
1713 break;
1714
1715 }
1716
1717 }
1718
1719 static void get_pid(unsigned * in, unsigned * out, char * s)
1720 {
1721 char * str;
1722 str = strstr(s, "out =");
1723 if (str){
1724 str = str + 5;
1725 sscanf(str,"%d", out);
1726 }else{
1727 g_warning("Can not find out pid\n");
1728 }
1729
1730 str = strstr(s,"in =");
1731 if (str){
1732 str = str + 4;
1733 sscanf(str,"%d", in);
1734 }else{
1735 g_warning("Can not find in pid\n");
1736 }
1737 }
1738
1739 gboolean parse_event(void *hook_data, void *call_data)
1740 {
1741 EventViewerData *event_viewer_data = (EventViewerData *)hook_data;
1742 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
1743 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
1744
1745 EventFields * tmp_event_fields,*prev_event_fields = NULL, *data=NULL;
1746 LttEvent *e;
1747 LttTime time;
1748 LttField * field;
1749 unsigned in=0, out=0;
1750 int i;
1751 GString * detail_event = g_string_new("");
1752 GList * list;
1753
1754 e = tfc->e;
1755 field = ltt_event_field(e);
1756 time = ltt_event_time(e);
1757
1758 tmp_event_fields = g_new(EventFields,1);
1759 tmp_event_fields->cpu_id = ltt_event_cpu_id(e);
1760 tmp_event_fields->event_name = g_strdup(ltt_eventtype_name(ltt_event_eventtype(e)));
1761 tmp_event_fields->time = time;
1762 tmp_event_fields->ep = ltt_event_position_new();
1763
1764 if(event_viewer_data->event_fields_queue_tmp->length){
1765 list = event_viewer_data->event_fields_queue_tmp->head;
1766 for(i=event_viewer_data->event_fields_queue_tmp->length-1;i>=0;i--){
1767 data = (EventFields *)g_list_nth_data(list,i);
1768 if(data->cpu_id == tmp_event_fields->cpu_id){
1769 prev_event_fields = data;
1770 break;
1771 }
1772 }
1773 }
1774
1775 if(prev_event_fields) tmp_event_fields->pid = prev_event_fields->pid;
1776 else tmp_event_fields->pid = -1;
1777
1778 tmp_event_fields->entry_length = field == NULL ? 0 : ltt_field_size(field);
1779 if(field) get_event_detail(e, field, detail_event);
1780 tmp_event_fields->event_description = g_strdup(detail_event->str);
1781
1782 if(strcmp(tmp_event_fields->event_name, "schedchange") == 0){
1783 get_pid(&in, &out, detail_event->str);
1784 }
1785
1786
1787 if(in != 0 || out != 0){
1788 tmp_event_fields->pid = in;
1789 if(prev_event_fields && prev_event_fields->pid == -1){
1790 list = event_viewer_data->event_fields_queue_tmp->head;
1791 for(i=0;i<(gint)event_viewer_data->event_fields_queue_tmp->length;i++){
1792 data = (EventFields *)g_list_nth_data(list,i);
1793 if(data->cpu_id == tmp_event_fields->cpu_id){
1794 data->pid = out;
1795 }
1796 }
1797 }
1798 }
1799
1800 ltt_event_position(e, tmp_event_fields->ep);
1801
1802 if(event_viewer_data->event_fields_queue_tmp->length >= RESERVE_SMALL_SIZE){
1803 if(event_viewer_data->append){
1804 list = g_list_last(event_viewer_data->event_fields_queue_tmp->head);
1805 data = (EventFields *)(list->data);
1806 if(data->time.tv_sec == time.tv_sec &&
1807 data->time.tv_nsec == time.tv_nsec){
1808 g_queue_push_tail(event_viewer_data->event_fields_queue_tmp,tmp_event_fields);
1809 }else{
1810 g_free(tmp_event_fields);
1811 }
1812 }else{
1813 remove_item_from_queue(event_viewer_data->event_fields_queue_tmp,TRUE);
1814 g_queue_push_tail(event_viewer_data->event_fields_queue_tmp,tmp_event_fields);
1815 }
1816 }else{
1817 g_queue_push_tail (event_viewer_data->event_fields_queue_tmp,tmp_event_fields);
1818 }
1819
1820 g_string_free(detail_event, TRUE);
1821
1822 return FALSE;
1823 }
1824
1825 void remove_item_from_queue(GQueue * q, gboolean fromHead)
1826 {
1827 EventFields *data1, *data2 = NULL;
1828 GList * list;
1829
1830 if(fromHead){
1831 data1 = (EventFields *)g_queue_pop_head(q);
1832 list = g_list_first(q->head);
1833 if(list)
1834 data2 = (EventFields *)(list->data);
1835 }else{
1836 data1 = (EventFields *)g_queue_pop_tail(q);
1837 list = g_list_last(q->head);
1838 if(list)
1839 data2 = (EventFields *)(list->data);
1840 }
1841
1842 if(data2){
1843 if(data1->time.tv_sec == data2->time.tv_sec &&
1844 data1->time.tv_nsec == data2->time.tv_nsec){
1845 remove_item_from_queue(q, fromHead);
1846 }
1847 }
1848
1849 g_free(data1);
1850
1851 return;
1852 }
1853
1854 void remove_all_items_from_queue(GQueue *q)
1855 {
1856 EventFields *data;
1857 while((data = (EventFields *)g_queue_pop_head(q)) != NULL){
1858 g_free(data);
1859 }
1860 }
1861
1862
1863 /**
1864 * plugin's init function
1865 *
1866 * This function initializes the Event Viewer functionnality through the
1867 * gtkTraceSet API.
1868 */
1869 static void init() {
1870
1871 lttvwindow_register_constructor("guievents",
1872 "/",
1873 "Insert Event Viewer",
1874 hGuiEventsInsert_xpm,
1875 "Insert Event Viewer",
1876 h_gui_events);
1877 }
1878
1879 void event_destroy_walk(gpointer data, gpointer user_data)
1880 {
1881 gui_events_destructor((EventViewerData*)data);
1882 }
1883
1884 /**
1885 * plugin's destroy function
1886 *
1887 * This function releases the memory reserved by the module and unregisters
1888 * everything that has been registered in the gtkTraceSet API.
1889 */
1890 static void destroy() {
1891
1892 g_slist_foreach(g_event_viewer_data_list, event_destroy_walk, NULL );
1893 g_slist_free(g_event_viewer_data_list);
1894
1895 lttvwindow_unregister_constructor(h_gui_events);
1896
1897 }
1898
1899
1900 LTTV_MODULE("guievents", "Detailed events view", \
1901 "Graphical module to display a detailed event list", \
1902 init, destroy, "lttvwindow")
This page took 0.120986 seconds and 5 git commands to generate.