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