9c312311 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Michel Dagenais |
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 | |
dc877563 |
19 | #ifndef PROCESSTRACE_H |
20 | #define PROCESSTRACE_H |
21 | |
ffd54a90 |
22 | #include <lttv/traceset.h> |
dc877563 |
23 | #include <lttv/attribute.h> |
24 | #include <lttv/hook.h> |
25 | #include <ltt/ltt.h> |
26 | |
27 | /* This is the generic part of trace processing. All events within a |
28 | certain time interval are accessed and processing hooks are called for |
29 | each. The events are examined in monotonically increasing time to more |
30 | closely follow the traced system behavior. |
31 | |
32 | Hooks are called at several different places during the processing: |
33 | before traceset, after traceset, check trace, before trace, after trace, |
34 | check tracefile, before tracefile, after tracefile, |
35 | check_event, before_event, before_event_by_id, |
36 | after_event, after_event_by_id. |
37 | |
38 | In each case the "check" hooks are called first to determine if further |
39 | processing of the trace, tracefile or event is wanted. Then, the before |
40 | hooks and the after hooks are called. The before hooks for a traceset |
41 | are called before those for the contained traces, which are called before |
42 | those for the contained tracefiles. The after hooks are called in reverse |
43 | order. The event hooks are called after all the before_tracefile hooks |
44 | and before all the after_tracefile hooks. |
45 | |
46 | The hooks receive two arguments, the hook_data and call_data. The hook_data |
47 | is specified when the hook is registered and typically links to the |
48 | object registering the hook (e.g. a graphical events viewer). The call_data |
49 | must contain all the context related to the call. The traceset hooks receive |
50 | the LttvTracesetContext provided by the caller. The trace hooks receive |
51 | the LttvTraceContext from the traces array in the LttvTracesetContext. |
52 | The tracefile and event hooks receive the LttvTracefileContext from |
53 | the tracefiles array in the LttvTraceContext. The LttEvent and LttTime |
54 | fields in the tracefile context are set to the current event and current |
55 | event time before calling the event hooks. No other context field is |
56 | modified. |
57 | |
58 | The contexts in the traces and tracefiles arrays must be allocated by |
59 | the caller, either before the call or during the before hooks of the |
60 | enclosing traceset or trace. The order in the traces array must |
61 | correspond to the lttv_traceset_get function. The order in the tracefiles |
62 | arrays must correspond to the ltt_trace_control_tracefile_get and |
63 | ltt_trace_per_cpu_tracefile_get functions. The traceset, trace and |
64 | tracefile contexts may be subtyped as needed. Indeed, both the contexts |
65 | and the hooks are defined by the caller. */ |
66 | |
ffd54a90 |
67 | |
68 | typedef struct _LttvTracesetContext LttvTracesetContext; |
69 | typedef struct _LttvTracesetContextClass LttvTracesetContextClass; |
70 | |
71 | typedef struct _LttvTraceContext LttvTraceContext; |
72 | typedef struct _LttvTraceContextClass LttvTraceContextClass; |
73 | |
74 | typedef struct _LttvTracefileContext LttvTracefileContext; |
75 | typedef struct _LttvTracefileContextClass LttvTracefileContextClass; |
76 | |
dc877563 |
77 | #define LTTV_TRACESET_CONTEXT_TYPE (lttv_traceset_context_get_type ()) |
78 | #define LTTV_TRACESET_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACESET_CONTEXT_TYPE, LttvTracesetContext)) |
79 | #define LTTV_TRACESET_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACESET_CONTEXT_TYPE, LttvTracesetContextClass)) |
80 | #define LTTV_IS_TRACESET_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACESET_CONTEXT_TYPE)) |
81 | #define LTTV_IS_TRACESET_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACESET_CONTEXT_TYPE)) |
82 | #define LTTV_TRACESET_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACESET_CONTEXT_TYPE, LttvTracesetContextClass)) |
83 | |
dc877563 |
84 | struct _LttvTracesetContext { |
85 | GObject parent; |
86 | |
87 | LttvTraceset *ts; |
88 | LttvHooks *before; |
89 | LttvHooks *after; |
90 | LttvTraceContext **traces; |
91 | LttvAttribute *a; |
308711e5 |
92 | LttvAttribute *ts_a; |
f7afe191 |
93 | TimeInterval *Time_Span; |
dc877563 |
94 | }; |
95 | |
96 | struct _LttvTracesetContextClass { |
97 | GObjectClass parent; |
98 | |
99 | void (*init) (LttvTracesetContext *self, LttvTraceset *ts); |
100 | void (*fini) (LttvTracesetContext *self); |
101 | LttvTracesetContext* (*new_traceset_context) (LttvTracesetContext *self); |
102 | LttvTraceContext* (*new_trace_context) (LttvTracesetContext *self); |
103 | LttvTracefileContext* (*new_tracefile_context) (LttvTracesetContext *self); |
104 | }; |
105 | |
106 | GType lttv_traceset_context_get_type (void); |
107 | |
108 | void lttv_context_init(LttvTracesetContext *self, LttvTraceset *ts); |
109 | |
110 | void lttv_context_fini(LttvTracesetContext *self); |
111 | |
112 | LttvTracesetContext * |
113 | lttv_context_new_traceset_context(LttvTracesetContext *self); |
114 | |
115 | LttvTraceContext * |
116 | lttv_context_new_trace_context(LttvTracesetContext *self); |
117 | |
118 | LttvTracefileContext * |
119 | lttv_context_new_tracefile_context(LttvTracesetContext *self); |
120 | |
121 | |
122 | #define LTTV_TRACE_CONTEXT_TYPE (lttv_trace_context_get_type ()) |
123 | #define LTTV_TRACE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContext)) |
124 | #define LTTV_TRACE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContextClass)) |
125 | #define LTTV_IS_TRACE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACE_CONTEXT_TYPE)) |
126 | #define LTTV_IS_TRACE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACE_CONTEXT_TYPE)) |
127 | #define LTTV_TRACE_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContextClass)) |
128 | |
dc877563 |
129 | struct _LttvTraceContext { |
130 | GObject parent; |
131 | |
132 | LttvTracesetContext *ts_context; |
133 | guint index; /* in ts_context->traces */ |
ffd54a90 |
134 | LttTrace *t; |
308711e5 |
135 | LttvTrace *vt; |
dc877563 |
136 | LttvHooks *check; |
137 | LttvHooks *before; |
138 | LttvHooks *after; |
139 | LttvTracefileContext **control_tracefiles; |
140 | LttvTracefileContext **per_cpu_tracefiles; |
141 | LttvAttribute *a; |
308711e5 |
142 | LttvAttribute *t_a; |
dc877563 |
143 | }; |
144 | |
145 | struct _LttvTraceContextClass { |
146 | GObjectClass parent; |
147 | }; |
148 | |
149 | GType lttv_trace_context_get_type (void); |
150 | |
151 | #define LTTV_TRACEFILE_CONTEXT_TYPE (lttv_tracefile_context_get_type ()) |
152 | #define LTTV_TRACEFILE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContext)) |
153 | #define LTTV_TRACEFILE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContextClass)) |
154 | #define LTTV_IS_TRACEFILE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACEFILE_CONTEXT_TYPE)) |
155 | #define LTTV_IS_TRACEFILE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACEFILE_CONTEXT_TYPE)) |
156 | #define LTTV_TRACEFILE_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContextClass)) |
157 | |
dc877563 |
158 | struct _LttvTracefileContext { |
159 | GObject parent; |
160 | |
161 | LttvTraceContext *t_context; |
162 | gboolean control; |
163 | guint index; /* in ts_context->control/per_cpu_tracefiles */ |
ffd54a90 |
164 | LttTracefile *tf; |
dc877563 |
165 | LttvHooks *check; |
166 | LttvHooks *before; |
167 | LttvHooks *after; |
ffd54a90 |
168 | LttEvent *e; |
dc877563 |
169 | LttvHooks *check_event; |
170 | LttvHooks *before_event; |
171 | LttvHooksById *before_event_by_id; |
172 | LttvHooks *after_event; |
173 | LttvHooksById *after_event_by_id; |
ffd54a90 |
174 | LttTime timestamp; |
dc877563 |
175 | LttvAttribute *a; |
176 | }; |
177 | |
178 | struct _LttvTracefileContextClass { |
179 | GObjectClass parent; |
180 | }; |
181 | |
182 | GType lttv_tracefile_context_get_type (void); |
183 | |
308711e5 |
184 | void lttv_process_traceset(LttvTracesetContext *self, LttTime end, |
185 | unsigned maxNumEvents); |
186 | |
187 | void lttv_process_traceset_seek_time(LttvTracesetContext *self, LttTime start); |
188 | |
189 | void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start); |
dc877563 |
190 | |
191 | void lttv_traceset_context_add_hooks(LttvTracesetContext *self, |
192 | LttvHooks *before_traceset, |
193 | LttvHooks *after_traceset, |
194 | LttvHooks *check_trace, |
195 | LttvHooks *before_trace, |
196 | LttvHooks *after_trace, |
ffd54a90 |
197 | LttvHooks *check_tracefile, |
198 | LttvHooks *before_tracefile, |
199 | LttvHooks *after_tracefile, |
dc877563 |
200 | LttvHooks *check_event, |
201 | LttvHooks *before_event, |
ffd54a90 |
202 | LttvHooks *after_event); |
dc877563 |
203 | |
204 | void lttv_traceset_context_remove_hooks(LttvTracesetContext *self, |
205 | LttvHooks *before_traceset, |
206 | LttvHooks *after_traceset, |
207 | LttvHooks *check_trace, |
208 | LttvHooks *before_trace, |
209 | LttvHooks *after_trace, |
ffd54a90 |
210 | LttvHooks *check_tracefile, |
211 | LttvHooks *before_tracefile, |
212 | LttvHooks *after_tracefile, |
dc877563 |
213 | LttvHooks *check_event, |
214 | LttvHooks *before_event, |
ffd54a90 |
215 | LttvHooks *after_event); |
dc877563 |
216 | |
a8c0f09d |
217 | void lttv_trace_context_add_hooks(LttvTraceContext *self, |
218 | LttvHooks *check_trace, |
219 | LttvHooks *before_trace, |
220 | LttvHooks *after_trace); |
221 | |
222 | void lttv_trace_context_remove_hooks(LttvTraceContext *self, |
223 | LttvHooks *check_trace, |
224 | LttvHooks *before_trace, |
225 | LttvHooks *after_trace); |
226 | |
227 | void lttv_tracefile_context_add_hooks(LttvTracefileContext *self, |
228 | LttvHooks *check_tracefile, |
229 | LttvHooks *before_tracefile, |
230 | LttvHooks *after_tracefile, |
231 | LttvHooks *check_event, |
232 | LttvHooks *before_event, |
233 | LttvHooks *after_event); |
234 | |
235 | void lttv_tracefile_context_remove_hooks(LttvTracefileContext *self, |
236 | LttvHooks *check_tracefile, |
237 | LttvHooks *before_tracefile, |
238 | LttvHooks *after_tracefile, |
239 | LttvHooks *check_event, |
240 | LttvHooks *before_event, |
241 | LttvHooks *after_event); |
242 | |
243 | void lttv_tracefile_context_add_hooks_by_id(LttvTracefileContext *self, |
244 | unsigned i, |
245 | LttvHooks *before_event_by_id, |
246 | LttvHooks *after_event_by_id); |
247 | |
248 | void lttv_tracefile_context_remove_hooks_by_id(LttvTracefileContext *self, |
249 | unsigned i); |
250 | |
b445142a |
251 | typedef struct _LttvTraceHook { |
252 | LttvHook h; |
253 | guint id; |
254 | LttField *f1; |
255 | LttField *f2; |
256 | LttField *f3; |
257 | } LttvTraceHook; |
258 | |
259 | |
260 | /* Search in the trace for the id of the named event type within the named |
261 | facility. Then, find the three (if non null) named fields. All that |
262 | information is then used to fill the LttvTraceHook structure. This |
263 | is useful to find the specific id for an event within a trace, for |
264 | registering a hook using this structure as event data; |
265 | it already contains the (up to three) needed fields handles. */ |
266 | |
267 | void lttv_trace_find_hook(LttTrace *t, char *facility, char *event_type, |
268 | char *field1, char *field2, char *field3, LttvHook h, LttvTraceHook *th); |
269 | |
dc877563 |
270 | #endif // PROCESSTRACE_H |