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])); |
65 | } |
66 | /* TODO : implement hash table. |
67 | else if (info->name == LTT_EVENT_KPROBE |
68 | && f->name = LTT_FIELD_IP) { |
69 | g_string_append_printf(s, " [%s]", |
70 | g_quark_to_string(ts->kprobe_symbols[value])); |
71 | } |
72 | */ |
cf453ac7 |
73 | } |
74 | } |
8e680509 |
75 | |
95868736 |
76 | void lttv_print_field(LttEvent *e, struct marker_field *f, GString *s, |
cf453ac7 |
77 | gboolean field_names, LttvTracefileState *tfs) |
95868736 |
78 | { |
8e680509 |
79 | GQuark name; |
cf453ac7 |
80 | guint64 value; |
8e680509 |
81 | |
95868736 |
82 | //int nb, i; |
8e680509 |
83 | |
95868736 |
84 | switch(f->type) { |
85 | case LTT_TYPE_SIGNED_INT: |
73e6c609 |
86 | if(field_names) { |
95868736 |
87 | name = f->name; |
73e6c609 |
88 | if(name) |
89 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
90 | } |
cf453ac7 |
91 | value = ltt_event_get_long_int(e,f); |
4d683428 |
92 | //g_string_append_printf(s, "%lld", value); |
93 | g_string_append_printf(s, f->fmt->str, value); |
95868736 |
94 | //g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f)); |
cf453ac7 |
95 | print_enum_events(e, f, value, s, tfs); |
95868736 |
96 | break; |
8e680509 |
97 | |
95868736 |
98 | case LTT_TYPE_UNSIGNED_INT: |
73e6c609 |
99 | if(field_names) { |
95868736 |
100 | name = f->name; |
73e6c609 |
101 | if(name) |
102 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
103 | } |
cf453ac7 |
104 | value = ltt_event_get_long_unsigned(e,f); |
4d683428 |
105 | //g_string_append_printf(s, "%llu", value); |
106 | g_string_append_printf(s, f->fmt->str, value); |
cf453ac7 |
107 | print_enum_events(e, f, value, s, tfs); |
95868736 |
108 | //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f)); |
1b960bd4 |
109 | break; |
110 | |
95868736 |
111 | #if 0 |
1b960bd4 |
112 | case LTT_CHAR: |
1b960bd4 |
113 | case LTT_UCHAR: |
73e6c609 |
114 | { |
115 | unsigned car = ltt_event_get_unsigned(e,f); |
116 | if(field_names) { |
117 | name = ltt_field_name(f); |
118 | if(name) |
119 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
120 | } |
121 | if(isprint(car)) { |
122 | if(field_names) { |
123 | name = ltt_field_name(f); |
124 | if(name) |
125 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
126 | } |
e8548639 |
127 | //g_string_append_printf(s, "%c", car); |
128 | g_string_append_printf(s, type->fmt, car); |
73e6c609 |
129 | } else { |
130 | g_string_append_printf(s, "\\%x", car); |
131 | } |
132 | } |
8e680509 |
133 | break; |
8e680509 |
134 | case LTT_FLOAT: |
e8548639 |
135 | if(field_names) { |
73e6c609 |
136 | name = ltt_field_name(f); |
137 | if(name) |
138 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
139 | } |
e8548639 |
140 | //g_string_append_printf(s, "%g", ltt_event_get_double(e,f)); |
141 | g_string_append_printf(s, type->fmt, ltt_event_get_double(e,f)); |
8e680509 |
142 | break; |
91346f59 |
143 | #endif |
8e680509 |
144 | |
91346f59 |
145 | case LTT_TYPE_POINTER: |
73e6c609 |
146 | if(field_names) { |
91346f59 |
147 | name = f->name; |
73e6c609 |
148 | if(name) |
149 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
150 | } |
43ed82b5 |
151 | g_string_append_printf(s, "0x%" PRIx64, ltt_event_get_long_unsigned(e,f)); |
91346f59 |
152 | //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f)); |
8e680509 |
153 | break; |
154 | |
95868736 |
155 | case LTT_TYPE_STRING: |
73e6c609 |
156 | if(field_names) { |
95868736 |
157 | name = f->name; |
73e6c609 |
158 | if(name) |
159 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
160 | } |
1b960bd4 |
161 | g_string_append_printf(s, "\"%s\"", ltt_event_get_string(e,f)); |
8e680509 |
162 | break; |
163 | |
95868736 |
164 | #if 0 |
8e680509 |
165 | case LTT_ENUM: |
1b960bd4 |
166 | { |
167 | GQuark value = ltt_enum_string_get(type, ltt_event_get_unsigned(e,f)); |
73e6c609 |
168 | if(field_names) { |
169 | name = ltt_field_name(f); |
170 | if(name) |
171 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
172 | } |
1b960bd4 |
173 | if(value) |
174 | g_string_append_printf(s, "%s", g_quark_to_string(value)); |
175 | else |
176 | g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f)); |
177 | } |
8e680509 |
178 | break; |
179 | |
180 | case LTT_ARRAY: |
181 | case LTT_SEQUENCE: |
73e6c609 |
182 | if(field_names) { |
183 | name = ltt_field_name(f); |
184 | if(name) |
185 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
186 | } |
e8548639 |
187 | // g_string_append_printf(s, "{ "); |
188 | //Insert header |
189 | g_string_append_printf(s, type->header);//tested, works fine. |
190 | |
191 | |
8e680509 |
192 | nb = ltt_event_field_element_number(e,f); |
8e680509 |
193 | for(i = 0 ; i < nb ; i++) { |
2312de30 |
194 | LttField *child = ltt_event_field_element_select(e,f,i); |
73e6c609 |
195 | lttv_print_field(e, child, s, field_names, i); |
e8548639 |
196 | if(i<nb-1) |
197 | g_string_append_printf(s,type->separator); |
8e680509 |
198 | } |
e8548639 |
199 | //g_string_append_printf(s, " }"); |
200 | //Insert footer |
201 | g_string_append_printf(s, type->footer);//tested, works fine. |
8e680509 |
202 | break; |
203 | |
204 | case LTT_STRUCT: |
73e6c609 |
205 | if(field_names) { |
206 | name = ltt_field_name(f); |
207 | if(name) |
208 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
209 | } |
e8548639 |
210 | // g_string_append_printf(s, "{ "); |
211 | //Insert header |
212 | g_string_append_printf(s, type->header); |
213 | |
8e680509 |
214 | nb = ltt_type_member_number(type); |
215 | for(i = 0 ; i < nb ; i++) { |
2312de30 |
216 | LttField *element; |
8e680509 |
217 | element = ltt_field_member(f,i); |
73e6c609 |
218 | lttv_print_field(e, element, s, field_names, i); |
e8548639 |
219 | if(i < nb-1) |
220 | g_string_append_printf(s,type->separator); |
8e680509 |
221 | } |
e8548639 |
222 | //g_string_append_printf(s, " }"); |
223 | //Insert footer |
224 | g_string_append_printf(s, type->footer); |
8e680509 |
225 | break; |
226 | |
227 | case LTT_UNION: |
73e6c609 |
228 | if(field_names) { |
229 | name = ltt_field_name(f); |
230 | if(name) |
231 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
232 | } |
e8548639 |
233 | // g_string_append_printf(s, "{ "); |
234 | g_string_append_printf(s, type->header); |
235 | |
8e680509 |
236 | nb = ltt_type_member_number(type); |
237 | for(i = 0 ; i < nb ; i++) { |
2312de30 |
238 | LttField *element; |
8e680509 |
239 | element = ltt_field_member(f,i); |
73e6c609 |
240 | lttv_print_field(e, element, s, field_names, i); |
e8548639 |
241 | if(i<nb-1) |
242 | g_string_append_printf(s, type->separator); |
8e680509 |
243 | } |
e8548639 |
244 | // g_string_append_printf(s, " }"); |
245 | g_string_append_printf(s, type->footer); |
8e680509 |
246 | break; |
95868736 |
247 | #endif |
248 | case LTT_TYPE_COMPACT: |
5d87b1b7 |
249 | g_error("compact type printing not implemented"); |
250 | break; |
95868736 |
251 | case LTT_TYPE_NONE: |
2312de30 |
252 | break; |
8e680509 |
253 | } |
254 | } |
255 | |
8e680509 |
256 | void lttv_event_to_string(LttEvent *e, GString *s, |
257 | gboolean mandatory_fields, gboolean field_names, LttvTracefileState *tfs) |
258 | { |
95868736 |
259 | struct marker_field *field; |
260 | struct marker_info *info; |
8e680509 |
261 | |
262 | LttTime time; |
263 | |
ae3d0f50 |
264 | guint cpu = tfs->cpu; |
8e680509 |
265 | LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; |
266 | LttvProcessState *process = ts->running_process[cpu]; |
76373d36 |
267 | |
0292757b |
268 | s = g_string_set_size(s,0); |
8e680509 |
269 | |
750eb11a |
270 | info = marker_get_info_from_id(tfs->parent.tf->mdata, e->event_id); |
8e680509 |
271 | |
272 | if(mandatory_fields) { |
273 | time = ltt_event_time(e); |
6471e71f |
274 | g_string_append_printf(s,"%s.%s: %ld.%09ld (%s/%s_%u)", |
275 | g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)), |
95868736 |
276 | g_quark_to_string(info->name), |
8e680509 |
277 | (long)time.tv_sec, time.tv_nsec, |
d41c66bf |
278 | g_quark_to_string( |
279 | ltt_trace_name(ltt_tracefile_get_trace(tfs->parent.tf))), |
8e680509 |
280 | g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)), |
281 | cpu); |
282 | /* Print the process id and the state/interrupt type of the process */ |
43ed82b5 |
283 | g_string_append_printf(s,", %u, %u, %s, %s, %u, 0x%" PRIx64", %s", |
284 | process->pid, |
285 | process->tgid, |
286 | g_quark_to_string(process->name), |
287 | g_quark_to_string(process->brand), |
288 | process->ppid, process->current_function, |
289 | g_quark_to_string(process->state->t)); |
8e680509 |
290 | } |
76373d36 |
291 | |
95868736 |
292 | if(marker_get_num_fields(info) == 0) return; |
743e50fd |
293 | g_string_append_printf(s, " "); |
294 | g_string_append_printf(s, "{ "); |
95868736 |
295 | for (field = marker_get_field(info, 0); |
296 | field != marker_get_field(info, marker_get_num_fields(info)); |
297 | field++) { |
298 | if(field != marker_get_field(info, 0)) |
299 | g_string_append_printf(s, ", "); |
cf453ac7 |
300 | lttv_print_field(e, field, s, field_names, tfs); |
76373d36 |
301 | } |
743e50fd |
302 | g_string_append_printf(s, " }"); |
8e680509 |
303 | } |
304 | |
305 | static void init() |
306 | { |
307 | } |
308 | |
309 | static void destroy() |
310 | { |
311 | } |
312 | |
313 | LTTV_MODULE("print", "Print events", \ |
73e6c609 |
314 | "Produce a detailed text printout of events", \ |
315 | init, destroy) |
8e680509 |
316 | |