8e680509 |
1 | |
e8548639 |
2 | |
8e680509 |
3 | /* This file is part of the Linux Trace Toolkit viewer |
4 | * Copyright (C) 2003-2004 Michel Dagenais |
5 | * 2005 Mathieu Desnoyers |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License Version 2 as |
9 | * published by the Free Software Foundation; |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
19 | * MA 02111-1307, USA. |
20 | */ |
21 | |
22 | /* print.c |
23 | * |
5290ec02 |
24 | * Event printing routines. |
25 | */ |
8e680509 |
26 | |
27 | #ifdef HAVE_CONFIG_H |
28 | #include <config.h> |
29 | #endif |
30 | |
31 | #include <lttv/lttv.h> |
32 | #include <lttv/option.h> |
33 | #include <lttv/module.h> |
34 | #include <lttv/hook.h> |
35 | #include <lttv/attribute.h> |
36 | #include <lttv/iattribute.h> |
37 | #include <lttv/stats.h> |
38 | #include <lttv/filter.h> |
39 | #include <lttv/print.h> |
40 | #include <ltt/ltt.h> |
41 | #include <ltt/event.h> |
42 | #include <ltt/type.h> |
43 | #include <ltt/trace.h> |
44 | #include <ltt/facility.h> |
45 | #include <stdio.h> |
73e6c609 |
46 | #include <ctype.h> |
e8548639 |
47 | #include<ltt/ltt-private.h> |
48 | #include <string.h> |
49 | |
8e680509 |
50 | |
51 | void lttv_print_field(LttEvent *e, LttField *f, GString *s, |
73e6c609 |
52 | gboolean field_names, guint element_index) { |
8e680509 |
53 | |
54 | LttType *type; |
55 | |
8e680509 |
56 | GQuark name; |
57 | |
58 | int nb, i; |
59 | |
60 | type = ltt_field_type(f); |
e8548639 |
61 | |
8e680509 |
62 | switch(ltt_type_class(type)) { |
1b960bd4 |
63 | case LTT_SHORT: |
8e680509 |
64 | case LTT_INT: |
65 | case LTT_LONG: |
66 | case LTT_SSIZE_T: |
1b960bd4 |
67 | case LTT_INT_FIXED: |
73e6c609 |
68 | if(field_names) { |
69 | name = ltt_field_name(f); |
70 | if(name) |
71 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
72 | } |
e8548639 |
73 | |
74 | //g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f)); |
75 | g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f)); |
76 | break; |
8e680509 |
77 | |
1b960bd4 |
78 | case LTT_USHORT: |
8e680509 |
79 | case LTT_UINT: |
80 | case LTT_ULONG: |
81 | case LTT_SIZE_T: |
82 | case LTT_OFF_T: |
1b960bd4 |
83 | case LTT_UINT_FIXED: |
73e6c609 |
84 | if(field_names) { |
85 | name = ltt_field_name(f); |
86 | if(name) |
87 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
88 | } |
e8548639 |
89 | // g_string_append_printf(s, "%llu", ltt_event_get_long_unsigned(e,f)); |
90 | g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f)); |
1b960bd4 |
91 | break; |
92 | |
93 | case LTT_CHAR: |
1b960bd4 |
94 | case LTT_UCHAR: |
73e6c609 |
95 | { |
96 | unsigned car = ltt_event_get_unsigned(e,f); |
97 | if(field_names) { |
98 | name = ltt_field_name(f); |
99 | if(name) |
100 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
101 | } |
102 | if(isprint(car)) { |
103 | if(field_names) { |
104 | name = ltt_field_name(f); |
105 | if(name) |
106 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
107 | } |
e8548639 |
108 | //g_string_append_printf(s, "%c", car); |
109 | g_string_append_printf(s, type->fmt, car); |
73e6c609 |
110 | } else { |
111 | g_string_append_printf(s, "\\%x", car); |
112 | } |
113 | } |
8e680509 |
114 | break; |
8e680509 |
115 | case LTT_FLOAT: |
e8548639 |
116 | if(field_names) { |
73e6c609 |
117 | name = ltt_field_name(f); |
118 | if(name) |
119 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
120 | } |
e8548639 |
121 | //g_string_append_printf(s, "%g", ltt_event_get_double(e,f)); |
122 | g_string_append_printf(s, type->fmt, ltt_event_get_double(e,f)); |
8e680509 |
123 | break; |
124 | |
125 | case LTT_POINTER: |
73e6c609 |
126 | if(field_names) { |
127 | name = ltt_field_name(f); |
128 | if(name) |
129 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
130 | } |
e8548639 |
131 | // g_string_append_printf(s, "0x%llx", ltt_event_get_long_unsigned(e,f)); |
132 | g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f)); |
8e680509 |
133 | break; |
134 | |
135 | case LTT_STRING: |
73e6c609 |
136 | if(field_names) { |
137 | name = ltt_field_name(f); |
138 | if(name) |
139 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
140 | } |
1b960bd4 |
141 | g_string_append_printf(s, "\"%s\"", ltt_event_get_string(e,f)); |
8e680509 |
142 | break; |
143 | |
144 | case LTT_ENUM: |
1b960bd4 |
145 | { |
146 | GQuark value = ltt_enum_string_get(type, ltt_event_get_unsigned(e,f)); |
73e6c609 |
147 | if(field_names) { |
148 | name = ltt_field_name(f); |
149 | if(name) |
150 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
151 | } |
1b960bd4 |
152 | if(value) |
153 | g_string_append_printf(s, "%s", g_quark_to_string(value)); |
154 | else |
155 | g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f)); |
156 | } |
8e680509 |
157 | break; |
158 | |
159 | case LTT_ARRAY: |
160 | case LTT_SEQUENCE: |
73e6c609 |
161 | if(field_names) { |
162 | name = ltt_field_name(f); |
163 | if(name) |
164 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
165 | } |
e8548639 |
166 | // g_string_append_printf(s, "{ "); |
167 | //Insert header |
168 | g_string_append_printf(s, type->header);//tested, works fine. |
169 | |
170 | |
8e680509 |
171 | nb = ltt_event_field_element_number(e,f); |
8e680509 |
172 | for(i = 0 ; i < nb ; i++) { |
2312de30 |
173 | LttField *child = ltt_event_field_element_select(e,f,i); |
73e6c609 |
174 | lttv_print_field(e, child, s, field_names, i); |
e8548639 |
175 | if(i<nb-1) |
176 | g_string_append_printf(s,type->separator); |
8e680509 |
177 | } |
e8548639 |
178 | //g_string_append_printf(s, " }"); |
179 | //Insert footer |
180 | g_string_append_printf(s, type->footer);//tested, works fine. |
8e680509 |
181 | break; |
182 | |
183 | case LTT_STRUCT: |
73e6c609 |
184 | if(field_names) { |
185 | name = ltt_field_name(f); |
186 | if(name) |
187 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
188 | } |
e8548639 |
189 | // g_string_append_printf(s, "{ "); |
190 | //Insert header |
191 | g_string_append_printf(s, type->header); |
192 | |
8e680509 |
193 | nb = ltt_type_member_number(type); |
194 | for(i = 0 ; i < nb ; i++) { |
2312de30 |
195 | LttField *element; |
8e680509 |
196 | element = ltt_field_member(f,i); |
73e6c609 |
197 | lttv_print_field(e, element, s, field_names, i); |
e8548639 |
198 | if(i < nb-1) |
199 | g_string_append_printf(s,type->separator); |
8e680509 |
200 | } |
e8548639 |
201 | //g_string_append_printf(s, " }"); |
202 | //Insert footer |
203 | g_string_append_printf(s, type->footer); |
8e680509 |
204 | break; |
205 | |
206 | case LTT_UNION: |
73e6c609 |
207 | if(field_names) { |
208 | name = ltt_field_name(f); |
209 | if(name) |
210 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
211 | } |
e8548639 |
212 | // g_string_append_printf(s, "{ "); |
213 | g_string_append_printf(s, type->header); |
214 | |
8e680509 |
215 | nb = ltt_type_member_number(type); |
216 | for(i = 0 ; i < nb ; i++) { |
2312de30 |
217 | LttField *element; |
8e680509 |
218 | element = ltt_field_member(f,i); |
73e6c609 |
219 | lttv_print_field(e, element, s, field_names, i); |
e8548639 |
220 | if(i<nb-1) |
221 | g_string_append_printf(s, type->separator); |
8e680509 |
222 | } |
e8548639 |
223 | // g_string_append_printf(s, " }"); |
224 | g_string_append_printf(s, type->footer); |
8e680509 |
225 | break; |
2312de30 |
226 | case LTT_NONE: |
227 | break; |
8e680509 |
228 | } |
229 | } |
230 | |
8e680509 |
231 | void lttv_event_to_string(LttEvent *e, GString *s, |
232 | gboolean mandatory_fields, gboolean field_names, LttvTracefileState *tfs) |
233 | { |
234 | LttFacility *facility; |
235 | |
236 | LttEventType *event_type; |
237 | |
238 | LttField *field; |
239 | |
240 | LttTime time; |
241 | |
ae3d0f50 |
242 | guint cpu = tfs->cpu; |
8e680509 |
243 | LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; |
244 | LttvProcessState *process = ts->running_process[cpu]; |
245 | |
2312de30 |
246 | GQuark name; |
247 | |
76373d36 |
248 | guint i, num_fields; |
249 | |
0292757b |
250 | s = g_string_set_size(s,0); |
8e680509 |
251 | |
252 | facility = ltt_event_facility(e); |
253 | event_type = ltt_event_eventtype(e); |
8e680509 |
254 | |
255 | if(mandatory_fields) { |
256 | time = ltt_event_time(e); |
d41c66bf |
257 | g_string_append_printf(s,"%s.%s: %ld.%09ld (%s%s_%u)", |
8e680509 |
258 | g_quark_to_string(ltt_facility_name(facility)), |
259 | g_quark_to_string(ltt_eventtype_name(event_type)), |
260 | (long)time.tv_sec, time.tv_nsec, |
d41c66bf |
261 | g_quark_to_string( |
262 | ltt_trace_name(ltt_tracefile_get_trace(tfs->parent.tf))), |
8e680509 |
263 | g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)), |
264 | cpu); |
265 | /* Print the process id and the state/interrupt type of the process */ |
fcc08e1e |
266 | g_string_append_printf(s,", %u, %u, %s, %s, %u, 0x%llX, %s", process->pid, |
267 | process->tgid, |
73e6c609 |
268 | g_quark_to_string(process->name), |
7b5f6cf1 |
269 | g_quark_to_string(process->brand), |
73e6c609 |
270 | process->ppid, process->current_function, |
271 | g_quark_to_string(process->state->t)); |
8e680509 |
272 | } |
41b471e6 |
273 | event_type = ltt_event_eventtype(e); |
76373d36 |
274 | |
41b471e6 |
275 | num_fields = ltt_eventtype_num_fields(event_type); |
743e50fd |
276 | if(num_fields == 0) return; |
277 | g_string_append_printf(s, " "); |
278 | g_string_append_printf(s, "{ "); |
76373d36 |
279 | for(i=0; i<num_fields; i++) { |
2312de30 |
280 | field = ltt_eventtype_field(event_type, i); |
73e6c609 |
281 | lttv_print_field(e, field, s, field_names, i); |
e8548639 |
282 | //should add ',' here |
283 | if(i<num_fields-1) |
284 | g_string_append_printf(s,", ");//tested: works fine |
76373d36 |
285 | } |
743e50fd |
286 | g_string_append_printf(s, " }"); |
8e680509 |
287 | } |
288 | |
289 | static void init() |
290 | { |
291 | } |
292 | |
293 | static void destroy() |
294 | { |
295 | } |
296 | |
297 | LTTV_MODULE("print", "Print events", \ |
73e6c609 |
298 | "Produce a detailed text printout of events", \ |
299 | init, destroy) |
8e680509 |
300 | |