lttvwindow: prepare for new infrastructure
[lttv.git] / ltt / branches / poly / lttv / lttv / print.c
1
2
3 /* This file is part of the Linux Trace Toolkit viewer
4 * Copyright (C) 2003-2004 Michel Dagenais
5 * 2005 Mathieu Desnoyers
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License Version 2 as
9 * published by the Free Software Foundation;
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
20 */
21
22 /* print.c
23 *
24 * Event printing routines.
25 */
26
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30
31 #include <lttv/lttv.h>
32 #include <lttv/option.h>
33 #include <lttv/module.h>
34 #include <lttv/hook.h>
35 #include <lttv/attribute.h>
36 #include <lttv/iattribute.h>
37 #include <lttv/stats.h>
38 #include <lttv/filter.h>
39 #include <lttv/print.h>
40 #include <ltt/ltt.h>
41 #include <ltt/event.h>
42 #include <ltt/trace.h>
43 #include <stdio.h>
44 #include <ctype.h>
45 #include<ltt/ltt-private.h>
46 #include <string.h>
47
48
49 void lttv_print_field(LttEvent *e, LttField *f, GString *s,
50 gboolean field_names, guint element_index) {
51
52 LttType *type;
53
54 GQuark name;
55
56 int nb, i;
57
58 type = ltt_field_type(f);
59
60 switch(ltt_type_class(type)) {
61 case LTT_SHORT:
62 case LTT_INT:
63 case LTT_LONG:
64 case LTT_SSIZE_T:
65 case LTT_INT_FIXED:
66 if(field_names) {
67 name = ltt_field_name(f);
68 if(name)
69 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
70 }
71
72 //g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f));
73 g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f));
74 break;
75
76 case LTT_USHORT:
77 case LTT_UINT:
78 case LTT_ULONG:
79 case LTT_SIZE_T:
80 case LTT_OFF_T:
81 case LTT_UINT_FIXED:
82 if(field_names) {
83 name = ltt_field_name(f);
84 if(name)
85 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
86 }
87 // g_string_append_printf(s, "%llu", ltt_event_get_long_unsigned(e,f));
88 g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
89 break;
90
91 case LTT_CHAR:
92 case LTT_UCHAR:
93 {
94 unsigned car = ltt_event_get_unsigned(e,f);
95 if(field_names) {
96 name = ltt_field_name(f);
97 if(name)
98 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
99 }
100 if(isprint(car)) {
101 if(field_names) {
102 name = ltt_field_name(f);
103 if(name)
104 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
105 }
106 //g_string_append_printf(s, "%c", car);
107 g_string_append_printf(s, type->fmt, car);
108 } else {
109 g_string_append_printf(s, "\\%x", car);
110 }
111 }
112 break;
113 case LTT_FLOAT:
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, "%g", ltt_event_get_double(e,f));
120 g_string_append_printf(s, type->fmt, ltt_event_get_double(e,f));
121 break;
122
123 case LTT_POINTER:
124 if(field_names) {
125 name = ltt_field_name(f);
126 if(name)
127 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
128 }
129 // g_string_append_printf(s, "0x%llx", ltt_event_get_long_unsigned(e,f));
130 g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
131 break;
132
133 case LTT_STRING:
134 if(field_names) {
135 name = ltt_field_name(f);
136 if(name)
137 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
138 }
139 g_string_append_printf(s, "\"%s\"", ltt_event_get_string(e,f));
140 break;
141
142 case LTT_ENUM:
143 {
144 GQuark value = ltt_enum_string_get(type, ltt_event_get_unsigned(e,f));
145 if(field_names) {
146 name = ltt_field_name(f);
147 if(name)
148 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
149 }
150 if(value)
151 g_string_append_printf(s, "%s", g_quark_to_string(value));
152 else
153 g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f));
154 }
155 break;
156
157 case LTT_ARRAY:
158 case LTT_SEQUENCE:
159 if(field_names) {
160 name = ltt_field_name(f);
161 if(name)
162 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
163 }
164 // g_string_append_printf(s, "{ ");
165 //Insert header
166 g_string_append_printf(s, type->header);//tested, works fine.
167
168
169 nb = ltt_event_field_element_number(e,f);
170 for(i = 0 ; i < nb ; i++) {
171 LttField *child = ltt_event_field_element_select(e,f,i);
172 lttv_print_field(e, child, s, field_names, i);
173 if(i<nb-1)
174 g_string_append_printf(s,type->separator);
175 }
176 //g_string_append_printf(s, " }");
177 //Insert footer
178 g_string_append_printf(s, type->footer);//tested, works fine.
179 break;
180
181 case LTT_STRUCT:
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);
190
191 nb = ltt_type_member_number(type);
192 for(i = 0 ; i < nb ; i++) {
193 LttField *element;
194 element = ltt_field_member(f,i);
195 lttv_print_field(e, element, 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);
202 break;
203
204 case LTT_UNION:
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 g_string_append_printf(s, type->header);
212
213 nb = ltt_type_member_number(type);
214 for(i = 0 ; i < nb ; i++) {
215 LttField *element;
216 element = ltt_field_member(f,i);
217 lttv_print_field(e, element, s, field_names, i);
218 if(i<nb-1)
219 g_string_append_printf(s, type->separator);
220 }
221 // g_string_append_printf(s, " }");
222 g_string_append_printf(s, type->footer);
223 break;
224 case LTT_NONE:
225 break;
226 }
227 }
228
229 void lttv_event_to_string(LttEvent *e, GString *s,
230 gboolean mandatory_fields, gboolean field_names, LttvTracefileState *tfs)
231 {
232 LttFacility *facility;
233
234 LttEventType *event_type;
235
236 LttField *field;
237
238 LttTime time;
239
240 guint cpu = tfs->cpu;
241 LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context;
242 LttvProcessState *process = ts->running_process[cpu];
243
244 GQuark name;
245
246 guint i, num_fields;
247
248 s = g_string_set_size(s,0);
249
250 facility = ltt_event_facility(e);
251 event_type = ltt_event_eventtype(e);
252
253 if(mandatory_fields) {
254 time = ltt_event_time(e);
255 g_string_append_printf(s,"%s.%s: %ld.%09ld (%s%s_%u)",
256 g_quark_to_string(ltt_facility_name(facility)),
257 g_quark_to_string(ltt_eventtype_name(event_type)),
258 (long)time.tv_sec, time.tv_nsec,
259 g_quark_to_string(
260 ltt_trace_name(ltt_tracefile_get_trace(tfs->parent.tf))),
261 g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)),
262 cpu);
263 /* Print the process id and the state/interrupt type of the process */
264 g_string_append_printf(s,", %u, %u, %s, %s, %u, 0x%llX, %s", process->pid,
265 process->tgid,
266 g_quark_to_string(process->name),
267 g_quark_to_string(process->brand),
268 process->ppid, process->current_function,
269 g_quark_to_string(process->state->t));
270 }
271 event_type = ltt_event_eventtype(e);
272
273 num_fields = ltt_eventtype_num_fields(event_type);
274 if(num_fields == 0) return;
275 g_string_append_printf(s, " ");
276 g_string_append_printf(s, "{ ");
277 for(i=0; i<num_fields; i++) {
278 field = ltt_eventtype_field(event_type, i);
279 lttv_print_field(e, field, s, field_names, i);
280 //should add ',' here
281 if(i<num_fields-1)
282 g_string_append_printf(s,", ");//tested: works fine
283 }
284 g_string_append_printf(s, " }");
285 }
286
287 static void init()
288 {
289 }
290
291 static void destroy()
292 {
293 }
294
295 LTTV_MODULE("print", "Print events", \
296 "Produce a detailed text printout of events", \
297 init, destroy)
298
This page took 0.048233 seconds and 5 git commands to generate.