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