update compat
[lttv.git] / tags / lttv-0.10.0-pre15-12082008 / lttv / lttv / print.c
CommitLineData
5750899b 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
46static 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]));
58 } else if ((info->name == g_quark_from_static_string("kernel_softirq_entry")
59 || info->name == g_quark_from_static_string("kernel_softirq_exit")
60 || info->name == g_quark_from_static_string("kernel_softirq_raise")) &&
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]));
64 }
65
66}
67
68void lttv_print_field(LttEvent *e, struct marker_field *f, GString *s,
69 gboolean field_names, LttvTracefileState *tfs)
70{
71 GQuark name;
72 guint64 value;
73
74 //int nb, i;
75
76 switch(f->type) {
77 case LTT_TYPE_SIGNED_INT:
78 if(field_names) {
79 name = f->name;
80 if(name)
81 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
82 }
83 value = ltt_event_get_long_int(e,f);
84 //g_string_append_printf(s, "%lld", value);
85 g_string_append_printf(s, f->fmt->str, value);
86 //g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f));
87 print_enum_events(e, f, value, s, tfs);
88 break;
89
90 case LTT_TYPE_UNSIGNED_INT:
91 if(field_names) {
92 name = f->name;
93 if(name)
94 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
95 }
96 value = ltt_event_get_long_unsigned(e,f);
97 //g_string_append_printf(s, "%llu", value);
98 g_string_append_printf(s, f->fmt->str, value);
99 print_enum_events(e, f, value, s, tfs);
100 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
101 break;
102
103#if 0
104 case LTT_CHAR:
105 case LTT_UCHAR:
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 }
119 //g_string_append_printf(s, "%c", car);
120 g_string_append_printf(s, type->fmt, car);
121 } else {
122 g_string_append_printf(s, "\\%x", car);
123 }
124 }
125 break;
126 case LTT_FLOAT:
127 if(field_names) {
128 name = ltt_field_name(f);
129 if(name)
130 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
131 }
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));
134 break;
135#endif
136
137 case LTT_TYPE_POINTER:
138 if(field_names) {
139 name = f->name;
140 if(name)
141 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
142 }
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));
145 break;
146
147 case LTT_TYPE_STRING:
148 if(field_names) {
149 name = f->name;
150 if(name)
151 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
152 }
153 g_string_append_printf(s, "\"%s\"", ltt_event_get_string(e,f));
154 break;
155
156#if 0
157 case LTT_ENUM:
158 {
159 GQuark value = ltt_enum_string_get(type, ltt_event_get_unsigned(e,f));
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 }
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 }
170 break;
171
172 case LTT_ARRAY:
173 case LTT_SEQUENCE:
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 }
179 // g_string_append_printf(s, "{ ");
180 //Insert header
181 g_string_append_printf(s, type->header);//tested, works fine.
182
183
184 nb = ltt_event_field_element_number(e,f);
185 for(i = 0 ; i < nb ; i++) {
186 LttField *child = ltt_event_field_element_select(e,f,i);
187 lttv_print_field(e, child, s, field_names, i);
188 if(i<nb-1)
189 g_string_append_printf(s,type->separator);
190 }
191 //g_string_append_printf(s, " }");
192 //Insert footer
193 g_string_append_printf(s, type->footer);//tested, works fine.
194 break;
195
196 case LTT_STRUCT:
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 }
202 // g_string_append_printf(s, "{ ");
203 //Insert header
204 g_string_append_printf(s, type->header);
205
206 nb = ltt_type_member_number(type);
207 for(i = 0 ; i < nb ; i++) {
208 LttField *element;
209 element = ltt_field_member(f,i);
210 lttv_print_field(e, element, s, field_names, i);
211 if(i < nb-1)
212 g_string_append_printf(s,type->separator);
213 }
214 //g_string_append_printf(s, " }");
215 //Insert footer
216 g_string_append_printf(s, type->footer);
217 break;
218
219 case LTT_UNION:
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 }
225 // g_string_append_printf(s, "{ ");
226 g_string_append_printf(s, type->header);
227
228 nb = ltt_type_member_number(type);
229 for(i = 0 ; i < nb ; i++) {
230 LttField *element;
231 element = ltt_field_member(f,i);
232 lttv_print_field(e, element, s, field_names, i);
233 if(i<nb-1)
234 g_string_append_printf(s, type->separator);
235 }
236 // g_string_append_printf(s, " }");
237 g_string_append_printf(s, type->footer);
238 break;
239#endif
240 case LTT_TYPE_COMPACT:
241 g_error("compact type printing not implemented");
242 break;
243 case LTT_TYPE_NONE:
244 break;
245 }
246}
247
248void lttv_event_to_string(LttEvent *e, GString *s,
249 gboolean mandatory_fields, gboolean field_names, LttvTracefileState *tfs)
250{
251 struct marker_field *field;
252 struct marker_info *info;
253
254 LttTime time;
255
256 guint cpu = tfs->cpu;
257 LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context;
258 LttvProcessState *process = ts->running_process[cpu];
259 LttTrace *trace = ts->parent.t;
260
261 s = g_string_set_size(s,0);
262
263 info = marker_get_info_from_id(trace, 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%llX, %s", process->pid,
276 process->tgid,
277 g_quark_to_string(process->name),
278 g_quark_to_string(process->brand),
279 process->ppid, process->current_function,
280 g_quark_to_string(process->state->t));
281 }
282
283 if(marker_get_num_fields(info) == 0) return;
284 g_string_append_printf(s, " ");
285 g_string_append_printf(s, "{ ");
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, ", ");
291 lttv_print_field(e, field, s, field_names, tfs);
292 }
293 g_string_append_printf(s, " }");
294}
295
296static void init()
297{
298}
299
300static void destroy()
301{
302}
303
304LTTV_MODULE("print", "Print events", \
305 "Produce a detailed text printout of events", \
306 init, destroy)
307
This page took 0.033462 seconds and 4 git commands to generate.