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