1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
5 >How to handle events and use the graphical trace reading service
</TITLE
8 CONTENT=
"Modular DocBook HTML Stylesheet Version 1.79"><LINK
10 TITLE=
"Linux Trace Toolkit Viewer Developer Guide"
11 HREF=
"index.html"><LINK
13 TITLE=
"Linux Trace Toolkit Viewer Graphical Module Tutorial"
16 TITLE=
"How to request background computation"
17 HREF=
"x81.html"></HEAD
28 SUMMARY=
"Header navigation table"
37 >Linux Trace Toolkit Viewer Developer Guide
</TH
53 >Chapter
3. Linux Trace Toolkit Viewer Graphical Module Tutorial
</TD
70 >3.5. How to handle events and use the graphical trace reading service
</A
73 > The events that are delivered by the main window are defined in
74 lttvwindow/lttvwindow.h. Let's describe them and their use in details. Remember
75 that you can refer to the control flow viewer module as an example.
83 >3.5.1. Module Related API
</A
86 > A viewer plugin is, before anything, a plugin. As a dynamically loadable
87 module, it thus has an init and a destroy function called whenever it is
88 loaded/initialized and unloaded/destroyed. A graphical module depends on
89 lttvwindow for construction of its viewer instances. In order to achieve
90 this, it must register its constructor function to the main window along
91 with button description or text menu entry description. A module keeps
92 a list of every viewer that currently sits in memory so it can destroy
93 them before the module gets unloaded/destroyed.
96 > The contructor registration to the main windows adds button and menu
97 entry to each main window, thus allowing instanciation of viewers.
106 >3.5.2. Main Window
</A
109 > The main window is a container that offers menus, buttons and a
110 notebook. Some of those menus and buttons are part of the core of the
111 main window, others are dynamically added and removed when modules are
115 > The notebook contains as much tabs as wanted. Each tab is linked with
116 a set of traces (traceset). Each trace contains many tracefiles (one
117 per cpu). A trace corresponds to a kernel being traced. A traceset
118 corresponds to many traces read together. The time span of a traceset
119 goes from the earliest start of all the traces to the latest end of all
123 > Inside each tab are added the viewers. When they interact with the main
124 window through the lttvwindow API, they affect the other viewers located
125 in the same tab as they are.
128 > The insertion of many viewers in a tab permits a quick look at all the
129 information wanted in a glance. The main window does merge the read
130 requests from all the viewers in the same tab in a way that every viewer
131 will get exactly the events it asked for, while the event reading loop
132 and state update are shared. It improves performance of events delivery
142 >3.5.3. Viewer Instance Related API
</A
145 > The lifetime of a viewer is as follows. The viewer constructor function
146 is called each time an instance view is created (one subwindow of this
147 viewer type is created by the user either by clicking on the menu item
148 or the button corresponding to the viewer). Thereafter, the viewer gets
149 hooks called for different purposes by the window containing it. These
150 hooks are detailed below. It also has to deal with GTK Events. Finally,
151 it can be destructed by having its top level widget unreferenced by the
152 main window or by any GTK Event causing a
"destroy-event" signal on the
153 its top widget. Another possible way for it do be destroyed is if the
154 module gets unloaded. The module unload function will have to emit a
155 "destroy" signal on each top level widget of all instances of its viewers.
164 >3.5.4. Notices from Main Window
</A
175 >This is the time interval visible on the viewer's tab. Every
176 viewer that cares about being synchronised by respect to the
177 time with other viewers should register to this notification.
178 They should redraw all or part of their display when this
185 >This notification is called whenever a trace is added/removed
186 from the traceset. As it affects all the data displayed by the
187 viewer, it sould redraw itself totally.
</P
193 >This feature has not been implemented yet.
</P
199 >Being able to zoom nearer a specific time or highlight a specific
200 time on every viewer in synchronicity implies that the viewer
201 has to shown a visual sign over the drawing or select an event
202 when it receives this notice. It should also inform the main
203 window with the appropriate report API function when a user
204 selects a specific time as being the current time.
</P
210 >This notice links the positions of the horizontal dividors
211 between the graphic display zone of every viewer and their Y axis,
212 typically showing processes, cpus, ...
</P
223 >3.5.5. Reporting Changes to the Main Window
</A
226 > In most cases, the enclosing window knows about updates such as described
227 in the Notification section higher. There are a few cases, however, where
228 updates are caused by actions known by a view instance. For example,
229 clicking in a view may update the current time; all viewers within
230 the same window must be told about the new current time to change the
231 currently highlighted time point. A viewer reports such events by calling
232 lttvwindow_report_current_time on its lttvwindow. The lttvwindow will
233 consequently call current_time_notify for each of its contained viewers.
236 > Available report methods are :
242 > lttvwindow_report_time_window : reports the new time window.
247 > lttvwindow_report_current_time : reports the new current time.
252 > lttvwindow_report_dividor : reports the new horizontal dividor's position.
265 >3.5.6. Requesting Events to Main Window
</A
268 > Events can be requested by passing a EventsRequest structure to the main
269 window. They will be delivered later when the next g_idle functions
270 will be called. Event delivery is done by calling the event hook for
271 this event ID, or the main event hooks. A pointer to the EventsRequest
272 structure is passed as hook_data to the event hooks of the viewers.
275 > EventsRequest consists in
281 > a pointer to the viewer specific data structure
286 > a start timestamp or position
291 > a stop_flag, ending the read process when set to TRUE
296 > a end timestamp and/or position and/or number of events to read
301 > hook lists to call for traceset/trace/tracefile begin and end, and for each
302 event (event hooks and event_by_id hooks).
309 > The main window will deliver events for every EventRequests it has
310 pending through an algorithm that guarantee that all events requested,
311 and only them, will be delivered to the viewer between the call of the
312 tracefile_begin hooks and the call of the tracefile_end hooks.
315 > If a viewer wants to stop the event request at a certain point inside the
316 event hooks, it has to set the stop_flag to TRUE and return TRUE from the
317 hook function. Then return value will stop the process traceset. Then,
318 the main window will look for the stop_flag and remove the EventRequests
319 from its lists, calling the process_traceset_end for this request (it
320 removes hooks from the context and calls the after hooks).
323 > It no stop_flag is risen, the end timestamp, end position or number
324 of events to read has to be reached to determine the end of the
325 request. Otherwise, the end of traceset does determine it.
334 >3.5.7. GTK Events
</A
342 >3.5.7.1. Events and Signals
</A
345 > GTK is quite different from the other graphical toolkits around
346 there. The main difference resides in that there are many X Windows
347 inside one GtkWindow, instead of just one. That means that X events are
348 delivered by the glib main loop directly to the widget corresponding to
349 the GdkWindow affected by the X event.
352 > Event delivery to a widget emits a signal on that widget. Then, if a
353 handler is connected to this widget's signal, it will be executed. There
354 are default handlers for signals, connected at class instantiation
355 time. There is also the possibility to connect other handlers to these
356 signals, which is what should be done in most cases when a viewer needs
357 to interact with X in any way.
360 > Signal emission and propagation is described there :
367 > http://www.gtk.org/tutorial/sec-signalemissionandpropagation.html
374 > For further information on the GTK main loop (now a wrapper over glib main loop)
382 > http://developer.gnome.org/doc/API/
2.0/gtk/gtk-General.html
387 > http://developer.gnome.org/doc/API/
2.0/glib/glib-The-Main-Event-Loop.html
394 > For documentation on event handling in GTK/GDK, see :
401 > http://developer.gnome.org/doc/API/
2.0/gdk/gdk-Events.html
406 > http://developer.gnome.org/doc/API/
2.0/gdk/gdk-Event-Structures.html
413 > Signals can be connected to handlers, emitted, propagated, blocked,
421 > http://developer.gnome.org/doc/API/
2.0/gobject/gobject-Signals.html
434 >3.5.7.2. The
"expose_event"</A
437 > Provides the exposed region in the GdkEventExpose structure.
440 > There are two ways of dealing with exposures. The first one is to directly
441 draw on the screen and the second one is to draw in a pixmap buffer,
442 and then to update the screen when necessary.
445 > In the first case, the expose event will be responsible for registering
446 hooks to process_traceset and require time intervals to the main
447 window. So, in this scenario, if a part of the screen is damaged, the
448 trace has to be read to redraw the screen.
451 > In the second case, with a pixmap buffer, the expose handler is only
452 responsible of showing the pixmap buffer on the screen. If the pixmap
453 buffer has never been filled with a drawing, the expose handler may ask
457 > The interest of using events request to the main window instead of reading
458 the events directly from the trace comes from the fact that the main
459 window does merge requests from the different viewers in the same tab so
460 that the read loop and the state update is shared. As viewers will, in
461 the common scenario, request the same events, only one pass through the
462 trace that will call the right hooks for the right intervals will be done.
465 > When the traceset read is over for a events request, the traceset_end
466 hook is called. It has the responsibility of finishing the drawing if
467 some parts still need to be drawn and to show it on the screen (if the
468 viewer uses a pixmap buffer).
471 > It can add dotted lines and such visual effects to enhance the user's
482 SUMMARY=
"Footer navigation table"
517 >How to request background computation
</TD