warning fixes
[lttv.git] / trunk / lttv / lttv / lttv / print.c
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 *
22 * Event printing routines.
23 */
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>
40 #include <ltt/trace.h>
41 #include <stdio.h>
42 #include <ctype.h>
43 #include <ltt/ltt-private.h>
44 #include <string.h>
45 #include <inttypes.h>
46
47 static inline void print_enum_events(LttEvent *e, struct marker_field *f,
48 guint64 value, GString *s, LttvTracefileState *tfs)
49 {
50 struct marker_info *info = marker_get_info_from_id(tfs->parent.tf->mdata,
51 e->event_id);
52 LttvTraceState *ts = (LttvTraceState*)(tfs->parent.t_context);
53
54 //TODO optimize with old quarks.
55 if (info->name == g_quark_from_static_string("kernel_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 == g_quark_from_static_string("kernel_softirq_entry")
60 || info->name == g_quark_from_static_string("kernel_softirq_exit")
61 || info->name == g_quark_from_static_string("kernel_softirq_raise")) &&
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]));
65 }
66
67 }
68
69 void lttv_print_field(LttEvent *e, struct marker_field *f, GString *s,
70 gboolean field_names, LttvTracefileState *tfs)
71 {
72 GQuark name;
73 guint64 value;
74
75 //int nb, i;
76
77 switch(f->type) {
78 case LTT_TYPE_SIGNED_INT:
79 if(field_names) {
80 name = f->name;
81 if(name)
82 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
83 }
84 value = ltt_event_get_long_int(e,f);
85 //g_string_append_printf(s, "%lld", value);
86 g_string_append_printf(s, f->fmt->str, value);
87 //g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f));
88 print_enum_events(e, f, value, s, tfs);
89 break;
90
91 case LTT_TYPE_UNSIGNED_INT:
92 if(field_names) {
93 name = f->name;
94 if(name)
95 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
96 }
97 value = ltt_event_get_long_unsigned(e,f);
98 //g_string_append_printf(s, "%llu", value);
99 g_string_append_printf(s, f->fmt->str, value);
100 print_enum_events(e, f, value, s, tfs);
101 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
102 break;
103
104 #if 0
105 case LTT_CHAR:
106 case LTT_UCHAR:
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 }
120 //g_string_append_printf(s, "%c", car);
121 g_string_append_printf(s, type->fmt, car);
122 } else {
123 g_string_append_printf(s, "\\%x", car);
124 }
125 }
126 break;
127 case LTT_FLOAT:
128 if(field_names) {
129 name = ltt_field_name(f);
130 if(name)
131 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
132 }
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));
135 break;
136 #endif
137
138 case LTT_TYPE_POINTER:
139 if(field_names) {
140 name = f->name;
141 if(name)
142 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
143 }
144 g_string_append_printf(s, "0x%" PRIx64, ltt_event_get_long_unsigned(e,f));
145 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
146 break;
147
148 case LTT_TYPE_STRING:
149 if(field_names) {
150 name = f->name;
151 if(name)
152 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
153 }
154 g_string_append_printf(s, "\"%s\"", ltt_event_get_string(e,f));
155 break;
156
157 #if 0
158 case LTT_ENUM:
159 {
160 GQuark value = ltt_enum_string_get(type, ltt_event_get_unsigned(e,f));
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 }
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 }
171 break;
172
173 case LTT_ARRAY:
174 case LTT_SEQUENCE:
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 }
180 // g_string_append_printf(s, "{ ");
181 //Insert header
182 g_string_append_printf(s, type->header);//tested, works fine.
183
184
185 nb = ltt_event_field_element_number(e,f);
186 for(i = 0 ; i < nb ; i++) {
187 LttField *child = ltt_event_field_element_select(e,f,i);
188 lttv_print_field(e, child, s, field_names, i);
189 if(i<nb-1)
190 g_string_append_printf(s,type->separator);
191 }
192 //g_string_append_printf(s, " }");
193 //Insert footer
194 g_string_append_printf(s, type->footer);//tested, works fine.
195 break;
196
197 case LTT_STRUCT:
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 }
203 // g_string_append_printf(s, "{ ");
204 //Insert header
205 g_string_append_printf(s, type->header);
206
207 nb = ltt_type_member_number(type);
208 for(i = 0 ; i < nb ; i++) {
209 LttField *element;
210 element = ltt_field_member(f,i);
211 lttv_print_field(e, element, s, field_names, i);
212 if(i < nb-1)
213 g_string_append_printf(s,type->separator);
214 }
215 //g_string_append_printf(s, " }");
216 //Insert footer
217 g_string_append_printf(s, type->footer);
218 break;
219
220 case LTT_UNION:
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 }
226 // g_string_append_printf(s, "{ ");
227 g_string_append_printf(s, type->header);
228
229 nb = ltt_type_member_number(type);
230 for(i = 0 ; i < nb ; i++) {
231 LttField *element;
232 element = ltt_field_member(f,i);
233 lttv_print_field(e, element, s, field_names, i);
234 if(i<nb-1)
235 g_string_append_printf(s, type->separator);
236 }
237 // g_string_append_printf(s, " }");
238 g_string_append_printf(s, type->footer);
239 break;
240 #endif
241 case LTT_TYPE_COMPACT:
242 g_error("compact type printing not implemented");
243 break;
244 case LTT_TYPE_NONE:
245 break;
246 }
247 }
248
249 void lttv_event_to_string(LttEvent *e, GString *s,
250 gboolean mandatory_fields, gboolean field_names, LttvTracefileState *tfs)
251 {
252 struct marker_field *field;
253 struct marker_info *info;
254
255 LttTime time;
256
257 guint cpu = tfs->cpu;
258 LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context;
259 LttvProcessState *process = ts->running_process[cpu];
260
261 s = g_string_set_size(s,0);
262
263 info = marker_get_info_from_id(tfs->parent.tf->mdata, e->event_id);
264
265 if(mandatory_fields) {
266 time = ltt_event_time(e);
267 g_string_append_printf(s,"%s: %ld.%09ld (%s%s_%u)",
268 g_quark_to_string(info->name),
269 (long)time.tv_sec, time.tv_nsec,
270 g_quark_to_string(
271 ltt_trace_name(ltt_tracefile_get_trace(tfs->parent.tf))),
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 */
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));
282 }
283
284 if(marker_get_num_fields(info) == 0) return;
285 g_string_append_printf(s, " ");
286 g_string_append_printf(s, "{ ");
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, ", ");
292 lttv_print_field(e, field, s, field_names, tfs);
293 }
294 g_string_append_printf(s, " }");
295 }
296
297 static void init()
298 {
299 }
300
301 static void destroy()
302 {
303 }
304
305 LTTV_MODULE("print", "Print events", \
306 "Produce a detailed text printout of events", \
307 init, destroy)
308
This page took 0.034833 seconds and 4 git commands to generate.