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