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