1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
5 >A typical module
</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 Text Module Tutorial"
16 TITLE=
"Linux Trace Toolkit Viewer Text Module Tutorial"
20 HREF=
"x33.html"></HEAD
31 SUMMARY=
"Header navigation table"
40 >Linux Trace Toolkit Viewer Developer Guide
</TH
56 >Chapter
1. Linux Trace Toolkit Viewer Text Module Tutorial
</TD
77 >1.2. A typical module
</A
80 > A typical module must have a init() and destroy() function. Please refer to
81 lttv/modules/text/textDump.c for the detail of these functions.
84 > The init() function is called when the library is loaded and destroy()
85 inversely. It adds options to the command line by calling
"lttv_option_add" from
89 > The module communicates with the main lttv program through the use of global
90 attributes. Use lttv/attribute.h, lttv/iattribute.h and lttv/lttv.h, and then
91 LTTV_IATTRIBUTE(lttv_global_attributes()) to get the pointer to these
95 > You can then add your hooks (functions that follows the prototype of a hook, as
96 defined in lttv/hook.h) in the different hook lists defined in lttv/lttv.h. Note
97 that hooks have an assigned priority. This is necessary to inform the trace
98 reader that a specific hook needs to be called, for example, before or after the
99 state update done for an event by the state module. For that specific example, a
100 hook could use the LTTV_PRIO_STATE-
5 to get called before the state update and a
101 second hook could use the LTTV_PRIO_STATE+
5 to get called after the state
102 update. This is especially important for graphical module, which is the subject
103 of a the chapter named
"Linux Trace Toolkit Viewer Graphical Module Tutorial".
106 > You should also take a look at lttv/state.c, where by_id hooks are used. When
107 you only need some specific events, you should use this interface. It makes the
108 event filtering sooner in the dispatch chain : you hook doesn't have to be
109 called for each event, only the ones selected. That improves the performances a
113 > Note that you should use the lttv_trace_find_hook method from
114 lttv/tracecontext.h to connect the hook to the right facility/event type. See
115 state.c for an example. A problem that may arise is that the LttvTraceHook
116 structure must be passed as hook_data when registering the hook. In fact, it is
117 not necessary for it to be directly passed as the hook_data parameter. As long
118 as the hook function can access the LttvTraceHook fields necessary to parse the
119 LttEvent, there is no problem. In a complex viewer where you need a pointer to
120 your own data structure, just keep a pointer to the LttvTraceHook structure
121 inside your own data structure, and give to pointer to your data structure in
122 parameter as the hook_data.
125 > Then, you should use the macro LTTV_MODULE, defined in lttv/module.h. It allows
126 you to specify the module name, a short and a long description, the init and
127 destroy functions and the module dependencies. That permits to the module
128 backend to load the right dependencies when needed.
131 > A typical text module will depend on batchAnalysis for the batch computation of a
132 trace, and simply register before and after trace hooks, as weel as the most
133 important one : a event hook.
141 SUMMARY=
"Footer navigation table"
180 >Linux Trace Toolkit Viewer Text Module Tutorial
</TD