e6a3b6bd |
1 | /* This file is part of the Linux Trace Toolkit trace reading library |
2 | * Copyright (C) 2004 Mathieu Desnoyers |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License Version 2.1 as published by the Free Software Foundation. |
7 | * |
8 | * This library 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 GNU |
11 | * Lesser General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU Lesser General Public |
14 | * License along with this library; if not, write to the |
15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
16 | * Boston, MA 02111-1307, USA. |
17 | */ |
18 | |
19 | /* This is a header that contains macro helpers to give an object-oriented |
20 | * access to the Trace context, state and statistics. |
21 | */ |
22 | |
23 | |
24 | #include <ltt/trace.h> |
25 | #include <lttv/tracecontext.h> |
26 | #include <lttv/state.h> |
27 | #include <lttv/stats.h> |
28 | |
29 | /************ TracesetContext get methods ***************/ |
30 | |
31 | /* LTTV_TRACESET_CONTEXT_GET_TRACE_CONTEXT |
32 | * |
33 | * Input : LttvTracesetContext *tsc |
34 | * int trace number (0 .. num_traces -1) |
35 | * returns : (LttvTraceContext *) |
36 | */ |
37 | #define LTTV_TRACESET_CONTEXT_GET_TRACE_CONTEXT(tsc, trace_num)\ |
38 | (tsc->traces[trace_num]) |
39 | |
40 | /* LTTV_TRACESET_CONTEXT_GET_NUM_TRACES |
41 | * |
42 | * Input : LttvTracesetContext *tsc |
43 | * returns : (guint) the number of traces |
44 | */ |
45 | #define LTTV_TRACESET_CONTEXT_GET_NUM_TRACES(tsc)\ |
46 | (lttv_traceset_number(tsc->ts)) |
47 | |
48 | /* LTTV_TRACESET_CONTEXT_GET_TRACESET_STATS |
49 | * |
50 | * Input : LttvTracesetContext *tsc |
51 | * returns : (LttvTracesetStats*) |
52 | */ |
53 | #define LTTV_TRACESET_CONTEXT_GET_TRACESET_STATS(tsc)\ |
54 | ((LttvTracesetStats*)tsc) |
55 | |
56 | |
57 | /************ TraceContext get methods ***************/ |
58 | |
59 | /* LTTV_TRACE_CONTEXT_GET_TRACESET_CONTEXT |
60 | * |
61 | * Input : LttvTraceContext *tc |
62 | * returns : (LttvTracesetContext *) |
63 | */ |
64 | #define LTTV_TRACE_CONTEXT_GET_TRACESET_CONTEXT(tc)\ |
65 | (tc->ts_context) |
66 | |
67 | |
68 | /* LTTV_TRACE_CONTEXT_GET_TRACE_STATE |
69 | * |
70 | * Input : LttvTraceContext *tc |
71 | * returns : (LttvTraceState *) |
72 | */ |
73 | #define LTTV_TRACE_CONTEXT_GET_TRACE_STATE(tc)\ |
74 | ((LttvTraceState*)tc) |
75 | |
76 | /* LTTV_TRACE_CONTEXT_GET_TRACE_STATS |
77 | * |
78 | * Input : LttvTraceContext *tc |
79 | * returns : (LttvTraceStats *) |
80 | */ |
81 | #define LTTV_TRACE_CONTEXT_GET_TRACE_STATS(tc)\ |
82 | ((LttvTraceStats*)tc) |
83 | |
84 | /* LTTV_TRACE_CONTEXT_GET_CPU_TRACEFILE_CONTEXT |
85 | * |
86 | * Input : LttvTraceContext *tc |
87 | * guint cpu_index (0 .. number_cpu-1) |
88 | * returns : (LttvTracefileContext*) |
89 | */ |
90 | #define LTTV_TRACE_CONTEXT_GET_CPU_TRACEFILE_CONTEXT(tc, cpu_index)\ |
91 | ( tc->tracefiles[cpu_index + ltt_trace_control_tracefile_number(tc->t)] ) |
92 | |
93 | /* LTTV_TRACE_CONTEXT_GET_NUMBER_CPU |
94 | * |
95 | * input : LttvTraceContext *tc |
96 | * returns : (guint) number_cpu |
97 | */ |
98 | #define LTTV_TRACE_CONTEXT_GET_NUMBER_CPU(tc)\ |
99 | ( ltt_trace_per_cpu_tracefile_number(tc->t) ) |
100 | |
101 | |
102 | /* LTTV_TRACE_CONTEXT_GET_CONTROL_TRACEFILE_CONTEXT |
103 | * |
104 | * Input : LttvTraceContext *tc |
105 | * guint control_index (0 .. number_control-1) |
106 | * returns : (LttvTracefileContext*) |
107 | */ |
108 | #define LTTV_TRACE_CONTEXT_GET_CONTROL_TRACEFILE_CONTEXT(tc, control_index)\ |
109 | (tc->tracefiles[control_index]) |
110 | |
111 | /* LTTV_TRACE_CONTEXT_GET_NUMBER_CONTROL |
112 | * |
113 | * Input : LttvTraceContext *tc |
114 | * returns : (guint) number_control |
115 | */ |
116 | #define LTTV_TRACE_CONTEXT_GET_NUMBER_CONTROL(tc)\ |
117 | ( ltt_trace_control_tracefile_number(tc->t) ) |
118 | |
119 | /* LTTV_TRACE_CONTEXT_GET_TRACE |
120 | * |
121 | * Input : LttvTraceContext *tc |
122 | * returns : (LttvTrace*) |
123 | * |
124 | * NOTE : see traceset.h for LttvTrace methods |
125 | */ |
126 | #define LTTV_TRACE_CONTEXT_GET_TRACE(tc)\ |
127 | (tc->vt) |
128 | |
129 | |
130 | |
131 | |
132 | |
133 | /************ TracefileContext get methods ***************/ |
134 | |
135 | /* LTTV_TRACEFILE_CONTEXT_GET_TRACE_CONTEXT |
136 | * |
137 | * Input : LttvTracefileContext *tfc |
138 | * returns : (LttvTraceContext*) |
139 | */ |
140 | #define LTTV_TRACEFILE_CONTEXT_GET_TRACE_CONTEXT(tfc)\ |
141 | (tfc->t_context) |
142 | |
143 | /* LTTV_TRACEFILE_CONTEXT_GET_EVENT |
144 | * |
145 | * Input : LttvTracefileContext *tfc |
146 | * returns : (LttEvent *) |
147 | */ |
148 | #define LTTV_TRACEFILE_CONTEXT_GET_EVENT(tfc)\ |
149 | (tfc->e) |
150 | |
151 | /* LTTV_TRACEFILE_CONTEXT_GET_TRACEFILE_STATE |
152 | * |
153 | * Input : LttvTracefileContext *tfc |
154 | * returns : (LttvTracefileState *) |
155 | */ |
156 | #define LTTV_TRACEFILE_CONTEXT_GET_TRACEFILE_STATE(tfc)\ |
157 | ((LttvTracefileState*)tfc) |
158 | |
159 | /* LTTV_TRACEFILE_CONTEXT_GET_TRACEFILE_STATS |
160 | * |
161 | * Input : LttvTracefileContext *tfc |
162 | * returns : (LttvTracefileStats *) |
163 | */ |
164 | #define LTTV_TRACEFILE_CONTEXT_GET_TRACEFILE_STATS(tfc)\ |
165 | ((LttvTracefileStats*)tfc) |
166 | |
167 | /* LTTV_TRACEFILE_CONTEXT_GET_TRACEFILE_INDEX |
168 | * |
169 | * Returns the tracefile index. |
170 | * |
171 | * It checks if it's a control tracefile or a cpu tracefile and returns the |
172 | * cpu_index or control_index, depending of the case. |
173 | * |
174 | * Input : LttvTracefileContext *tfc |
175 | * returns : (guint) cpu_index or control_index. |
176 | */ |
177 | #define LTTV_TRACEFILE_CONTEXT_GET_TRACEFILE_INDEX(tfc)\ |
178 | (tfc->control?\ |
179 | tfc->index:\ |
180 | tfc->index-ltt_trace_control_tracefile_number(tfc->t_context->t)) |
181 | |
182 | |
183 | |
184 | /************ TraceState get methods ***************/ |
185 | |
186 | /* LTTV_TRACE_STATE_GET_TRACE_CONTEXT |
187 | * |
188 | * Input : LttvTraceState *tse |
189 | * returns : (LttvTraceContext*) |
190 | * |
191 | */ |
192 | #define LTTV_TRACE_STATE_GET_TRACE_CONTEXT(tse)\ |
193 | ((LttvTraceContext*)tse) |
194 | |
195 | /* LTTV_TRACE_STATE_GET_EVENTTYPE_NAME |
196 | * |
197 | * Input : LttvTraceState *tse |
198 | * guint eventtype_number |
199 | * returns : (GQuark) |
200 | * |
201 | * NOTE : use g_quark_to_string to convert a GQuark into a static char * |
202 | */ |
203 | #define LTTV_TRACE_STATE_GET_EVENTTYPE_NAME(tse, eventtype_number)\ |
204 | (tse->eventtype_names[eventtype_number]) |
205 | |
206 | /* LTTV_TRACE_STATE_GET_SYSCALL_NAME |
207 | * |
208 | * Input : LttvTraceState *tse |
209 | * guint syscall_number |
210 | * returns : (GQuark) |
211 | * |
212 | * NOTE : use g_quark_to_string to convert a GQuark into a static char * |
213 | */ |
214 | #define LTTV_TRACE_STATE_GET_EVENTTYPE_NAME(tse, syscall_number)\ |
215 | (tse->syscall_names[syscall_number]) |
216 | |
217 | /* LTTV_TRACE_STATE_GET_TRAP_NAME |
218 | * |
219 | * Input : LttvTraceState *tse |
220 | * guint trap_number |
221 | * returns : (GQuark) |
222 | * |
223 | * NOTE : use g_quark_to_string to convert a GQuark into a static char * |
224 | */ |
225 | #define LTTV_TRACE_STATE_GET_TRAP_NAME(tse, trap_number)\ |
226 | (tse->trap_names[trap_number]) |
227 | |
228 | /* LTTV_TRACE_STATE_GET_IRQ_NAME |
229 | * |
230 | * Input : LttvTraceState *tse |
231 | * guint irq_number |
232 | * returns : (GQuark) |
233 | * |
234 | * NOTE : use g_quark_to_string to convert a GQuark into a static char * |
235 | */ |
236 | #define LTTV_TRACE_STATE_GET_TRAP_NAME(tse, irq_number)\ |
237 | (tse->irq_names[irq_number]) |
238 | |
239 | |
240 | /* LTTV_TRACE_STATE_GET_PROCESS_STATE |
241 | * |
242 | * Input : LttvTraceState *tse |
243 | * guint pid |
244 | * guint cpu_index (0 .. number_cpu-1) |
245 | * returns : (LttvProcessState *) |
246 | * |
247 | * NOTE : if pid is 0, the special process corresponding to the CPU that |
248 | * corresponds to the tracefile will be returned. |
249 | * if pid is different than 0, the process returned may be running |
250 | * on any cpu of the trace. |
251 | */ |
252 | #define LTTV_TRACE_STATE_GET_PROCESS_STATE(tse, pid, cpu_index)\ |
253 | (lttv_state_find_process( \ |
254 | (LttvTraceFileState*)tse->parent->tracefiles[\ |
255 | cpu_index+\ |
256 | ltt_trace_control_tracefile_number((LttvTraceContext*)tse->t)], pid)) |
257 | |
258 | |
259 | /* LTTV_TRACE_STATE_GET_NUMBER_CPU |
260 | * |
261 | * input : LttvTraceState *tse |
262 | * returns : (guint) number_cpu |
263 | */ |
264 | #define LTTV_TRACE_STATE_GET_NUMBER_CPU(tse)\ |
265 | ( ltt_trace_per_cpu_tracefile_number((LttvTraceState*)tse->t) ) |
266 | |
267 | |
268 | |
269 | |
270 | /************ TracefileState get methods ***************/ |
271 | |
272 | /* LTTV_TRACEFILE_STATE_GET_TRACEFILE_CONTEXT |
273 | * |
274 | * Input : LttvTracefileState *tfse |
275 | * returns : (LttvTracefileContext*) |
276 | * |
277 | */ |
278 | #define LTTV_TRACEFILE_STATE_GET_TRACEFILE_CONTEXT(tfse)\ |
279 | ((LttvTracefileContext*)tfse) |
280 | |
281 | |
282 | /* LTTV_TRACEFILE_STATE_GET_CURRENT_PROCESS_STATE |
283 | * |
284 | * Returns the state of the current process. |
285 | * |
286 | * Input : LttvTracefileState *tfse |
287 | * returns : (LttvProcessState *) |
288 | */ |
289 | #define LTTV_TRACEFILE_STATE_GET_CURRENT_PROCESS_STATE(tfse)\ |
290 | (tfse->process) |
291 | |
292 | /* LTTV_TRACEFILE_STATE_GET_CPU_NAME |
293 | * |
294 | * Input : LttvTracefileState *tfse |
295 | * returns : (GQuark) |
296 | * |
297 | * NOTE : use g_quark_to_string to convert a GQuark into a static char * |
298 | */ |
299 | #define LTTV_TRACEFILE_STATE_GET_CPU_NAME(tfse)\ |
300 | (tfse->cpu_name) |
301 | |
302 | |
303 | /* LTTV_TRACEFILE_STATE_GET_PROCESS_STATE |
304 | * |
305 | * Input : LttvTracefileState *tfse |
306 | * guint pid |
307 | * returns : (LttvProcessState *) |
308 | * |
309 | * NOTE : if pid is 0, the special process corresponding to the CPU that |
310 | * corresponds to the tracefile will be returned. |
311 | * if pid is different than 0, the process returned may be running |
312 | * on any cpu of the trace. |
313 | */ |
314 | #define LTTV_TRACEFILE_STATE_GET_PROCESS_STATE(tfse, pid)\ |
315 | (lttv_state_find_process(tfse, pid)) |
316 | |
317 | |
318 | |
319 | |
320 | |
321 | /************ ProcessState get methods ***************/ |
322 | /* Use direct access to LttvProcessState members for other attributes */ |
323 | /* see struct _LttvProcessState definition in state.h */ |
324 | |
325 | /* LTTV_PROCESS_STATE_GET_CURRENT_EXECUTION_STATE |
326 | * |
327 | * Input : LttvProcessState *pse |
328 | * returns : (LttvExecutionState*) |
329 | */ |
330 | #define LTTV_PROCESS_STATE_GET_EXECUTION_STATE(pse)\ |
331 | (pse->state) |
332 | |
333 | /* LTTV_PROCESS_STATE_GET_NESTED_EXECUTION_STATE |
334 | * |
335 | * Input : LttvProcessState *pse |
336 | * guint nest_number (0 to num_nest-1) |
337 | * returns : (LttvExecutionState*) |
338 | */ |
339 | #define LTTV_PROCESS_STATE_GET_NESTED_EXECUTION_STATE(pse, num_nest)\ |
340 | ((LttvExecutionState*)pse->execution_stack[num_nest]) |
341 | |
342 | |
343 | /* LTTV_PROCESS_STATE_GET_NUM_NESTED_EXECUTION_STATES |
344 | * |
345 | * Returns the number of nested execution states currently on the stack. |
346 | * |
347 | * Input : LttvProcessState *pse |
348 | * returns : (guint) |
349 | */ |
350 | #define LTTV_PROCESS_STATE_GET_NUM_NESTED_EXECUTION_STATES(pse)\ |
351 | (pse->execution_stack->len) |
352 | |
353 | |
354 | /************ ExecutionState get methods ***************/ |
355 | /* Use direct access to LttvExecutionState members to access attributes */ |
356 | /* see struct _LttvExecutionState definition in state.h */ |
357 | |
358 | |
359 | |
360 | |
361 | |
362 | |
363 | /* Statistics */ |
364 | |
365 | |
366 | |
367 | |