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; |
2a2fa4f0 |
94 | GTree *pqueue; |
a43d67ba |
95 | LttEvent *e; /* Last event read by lttv_process_traceset_middle */ |
dc877563 |
96 | }; |
97 | |
98 | struct _LttvTracesetContextClass { |
99 | GObjectClass parent; |
100 | |
101 | void (*init) (LttvTracesetContext *self, LttvTraceset *ts); |
102 | void (*fini) (LttvTracesetContext *self); |
103 | LttvTracesetContext* (*new_traceset_context) (LttvTracesetContext *self); |
104 | LttvTraceContext* (*new_trace_context) (LttvTracesetContext *self); |
105 | LttvTracefileContext* (*new_tracefile_context) (LttvTracesetContext *self); |
106 | }; |
107 | |
108 | GType lttv_traceset_context_get_type (void); |
109 | |
110 | void lttv_context_init(LttvTracesetContext *self, LttvTraceset *ts); |
111 | |
112 | void lttv_context_fini(LttvTracesetContext *self); |
113 | |
114 | LttvTracesetContext * |
115 | lttv_context_new_traceset_context(LttvTracesetContext *self); |
116 | |
117 | LttvTraceContext * |
118 | lttv_context_new_trace_context(LttvTracesetContext *self); |
119 | |
120 | LttvTracefileContext * |
121 | lttv_context_new_tracefile_context(LttvTracesetContext *self); |
122 | |
123 | |
124 | #define LTTV_TRACE_CONTEXT_TYPE (lttv_trace_context_get_type ()) |
125 | #define LTTV_TRACE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContext)) |
126 | #define LTTV_TRACE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContextClass)) |
127 | #define LTTV_IS_TRACE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACE_CONTEXT_TYPE)) |
128 | #define LTTV_IS_TRACE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACE_CONTEXT_TYPE)) |
129 | #define LTTV_TRACE_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContextClass)) |
130 | |
dc877563 |
131 | struct _LttvTraceContext { |
132 | GObject parent; |
133 | |
134 | LttvTracesetContext *ts_context; |
135 | guint index; /* in ts_context->traces */ |
ffd54a90 |
136 | LttTrace *t; |
308711e5 |
137 | LttvTrace *vt; |
dc877563 |
138 | LttvHooks *check; |
139 | LttvHooks *before; |
140 | LttvHooks *after; |
dbb7bb09 |
141 | LttvTracefileContext **tracefiles; |
dc877563 |
142 | LttvAttribute *a; |
308711e5 |
143 | LttvAttribute *t_a; |
dc877563 |
144 | }; |
145 | |
146 | struct _LttvTraceContextClass { |
147 | GObjectClass parent; |
148 | }; |
149 | |
150 | GType lttv_trace_context_get_type (void); |
151 | |
152 | #define LTTV_TRACEFILE_CONTEXT_TYPE (lttv_tracefile_context_get_type ()) |
153 | #define LTTV_TRACEFILE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContext)) |
154 | #define LTTV_TRACEFILE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContextClass)) |
155 | #define LTTV_IS_TRACEFILE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACEFILE_CONTEXT_TYPE)) |
156 | #define LTTV_IS_TRACEFILE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACEFILE_CONTEXT_TYPE)) |
157 | #define LTTV_TRACEFILE_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContextClass)) |
158 | |
dc877563 |
159 | struct _LttvTracefileContext { |
160 | GObject parent; |
161 | |
162 | LttvTraceContext *t_context; |
163 | gboolean control; |
dbb7bb09 |
164 | guint index; /* in ts_context->tracefiles */ |
ffd54a90 |
165 | LttTracefile *tf; |
dc877563 |
166 | LttvHooks *check; |
167 | LttvHooks *before; |
168 | LttvHooks *after; |
ffd54a90 |
169 | LttEvent *e; |
dc877563 |
170 | LttvHooks *check_event; |
171 | LttvHooks *before_event; |
172 | LttvHooksById *before_event_by_id; |
173 | LttvHooks *after_event; |
174 | LttvHooksById *after_event_by_id; |
ffd54a90 |
175 | LttTime timestamp; |
dc877563 |
176 | LttvAttribute *a; |
177 | }; |
178 | |
179 | struct _LttvTracefileContextClass { |
180 | GObjectClass parent; |
181 | }; |
182 | |
183 | GType lttv_tracefile_context_get_type (void); |
184 | |
2a2fa4f0 |
185 | /* Run through the events in a traceset in sorted order calling all the |
186 | hooks appropriately. It starts at the current time and runs until end or |
187 | nb_events are processed. */ |
188 | |
308711e5 |
189 | void lttv_process_traceset(LttvTracesetContext *self, LttTime end, |
2a2fa4f0 |
190 | unsigned nb_events); |
191 | |
192 | /* Process traceset can also be done in smaller pieces calling begin, middle |
193 | repeatedly, and end. The middle function return the number of events |
194 | processed. It may be larger than nb_events if several events have the |
195 | same timestamp. It will be smaller than nb_events if the end time |
196 | is reached. */ |
197 | |
198 | void lttv_process_traceset_begin(LttvTracesetContext *self, LttTime end); |
199 | |
200 | guint lttv_process_traceset_middle(LttvTracesetContext *self, LttTime end, |
201 | unsigned nb_events); |
202 | |
203 | void lttv_process_traceset_end(LttvTracesetContext *self); |
204 | |
308711e5 |
205 | |
206 | void lttv_process_traceset_seek_time(LttvTracesetContext *self, LttTime start); |
207 | |
208 | void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start); |
dc877563 |
209 | |
210 | void lttv_traceset_context_add_hooks(LttvTracesetContext *self, |
211 | LttvHooks *before_traceset, |
212 | LttvHooks *after_traceset, |
213 | LttvHooks *check_trace, |
214 | LttvHooks *before_trace, |
215 | LttvHooks *after_trace, |
ffd54a90 |
216 | LttvHooks *check_tracefile, |
217 | LttvHooks *before_tracefile, |
218 | LttvHooks *after_tracefile, |
dc877563 |
219 | LttvHooks *check_event, |
220 | LttvHooks *before_event, |
ffd54a90 |
221 | LttvHooks *after_event); |
dc877563 |
222 | |
223 | void lttv_traceset_context_remove_hooks(LttvTracesetContext *self, |
224 | LttvHooks *before_traceset, |
225 | LttvHooks *after_traceset, |
226 | LttvHooks *check_trace, |
227 | LttvHooks *before_trace, |
228 | LttvHooks *after_trace, |
ffd54a90 |
229 | LttvHooks *check_tracefile, |
230 | LttvHooks *before_tracefile, |
231 | LttvHooks *after_tracefile, |
dc877563 |
232 | LttvHooks *check_event, |
233 | LttvHooks *before_event, |
ffd54a90 |
234 | LttvHooks *after_event); |
dc877563 |
235 | |
a8c0f09d |
236 | void lttv_trace_context_add_hooks(LttvTraceContext *self, |
237 | LttvHooks *check_trace, |
238 | LttvHooks *before_trace, |
239 | LttvHooks *after_trace); |
240 | |
241 | void lttv_trace_context_remove_hooks(LttvTraceContext *self, |
242 | LttvHooks *check_trace, |
243 | LttvHooks *before_trace, |
244 | LttvHooks *after_trace); |
245 | |
246 | void lttv_tracefile_context_add_hooks(LttvTracefileContext *self, |
247 | LttvHooks *check_tracefile, |
248 | LttvHooks *before_tracefile, |
249 | LttvHooks *after_tracefile, |
250 | LttvHooks *check_event, |
251 | LttvHooks *before_event, |
252 | LttvHooks *after_event); |
253 | |
254 | void lttv_tracefile_context_remove_hooks(LttvTracefileContext *self, |
255 | LttvHooks *check_tracefile, |
256 | LttvHooks *before_tracefile, |
257 | LttvHooks *after_tracefile, |
258 | LttvHooks *check_event, |
259 | LttvHooks *before_event, |
260 | LttvHooks *after_event); |
261 | |
262 | void lttv_tracefile_context_add_hooks_by_id(LttvTracefileContext *self, |
263 | unsigned i, |
264 | LttvHooks *before_event_by_id, |
265 | LttvHooks *after_event_by_id); |
266 | |
267 | void lttv_tracefile_context_remove_hooks_by_id(LttvTracefileContext *self, |
268 | unsigned i); |
269 | |
b445142a |
270 | typedef struct _LttvTraceHook { |
271 | LttvHook h; |
272 | guint id; |
273 | LttField *f1; |
274 | LttField *f2; |
275 | LttField *f3; |
276 | } LttvTraceHook; |
277 | |
278 | |
279 | /* Search in the trace for the id of the named event type within the named |
280 | facility. Then, find the three (if non null) named fields. All that |
281 | information is then used to fill the LttvTraceHook structure. This |
282 | is useful to find the specific id for an event within a trace, for |
283 | registering a hook using this structure as event data; |
284 | it already contains the (up to three) needed fields handles. */ |
285 | |
286 | void lttv_trace_find_hook(LttTrace *t, char *facility, char *event_type, |
287 | char *field1, char *field2, char *field3, LttvHook h, LttvTraceHook *th); |
288 | |
dc877563 |
289 | #endif // PROCESSTRACE_H |