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