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