lttvwindow: prepare for new infrastructure
[lttv.git] / ltt / branches / poly / lttv / lttv / print.c
CommitLineData
8e680509 1
e8548639 2
8e680509 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 *
5290ec02 24 * Event printing routines.
25 */
8e680509 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>
8e680509 42#include <ltt/trace.h>
8e680509 43#include <stdio.h>
73e6c609 44#include <ctype.h>
e8548639 45#include<ltt/ltt-private.h>
46#include <string.h>
47
8e680509 48
49void lttv_print_field(LttEvent *e, LttField *f, GString *s,
73e6c609 50 gboolean field_names, guint element_index) {
8e680509 51
52 LttType *type;
53
8e680509 54 GQuark name;
55
56 int nb, i;
57
58 type = ltt_field_type(f);
e8548639 59
8e680509 60 switch(ltt_type_class(type)) {
1b960bd4 61 case LTT_SHORT:
8e680509 62 case LTT_INT:
63 case LTT_LONG:
64 case LTT_SSIZE_T:
1b960bd4 65 case LTT_INT_FIXED:
73e6c609 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 }
e8548639 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;
8e680509 75
1b960bd4 76 case LTT_USHORT:
8e680509 77 case LTT_UINT:
78 case LTT_ULONG:
79 case LTT_SIZE_T:
80 case LTT_OFF_T:
1b960bd4 81 case LTT_UINT_FIXED:
73e6c609 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 }
e8548639 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));
1b960bd4 89 break;
90
91 case LTT_CHAR:
1b960bd4 92 case LTT_UCHAR:
73e6c609 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 }
e8548639 106 //g_string_append_printf(s, "%c", car);
107 g_string_append_printf(s, type->fmt, car);
73e6c609 108 } else {
109 g_string_append_printf(s, "\\%x", car);
110 }
111 }
8e680509 112 break;
8e680509 113 case LTT_FLOAT:
e8548639 114 if(field_names) {
73e6c609 115 name = ltt_field_name(f);
116 if(name)
117 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
118 }
e8548639 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));
8e680509 121 break;
122
123 case LTT_POINTER:
73e6c609 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 }
e8548639 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));
8e680509 131 break;
132
133 case LTT_STRING:
73e6c609 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 }
1b960bd4 139 g_string_append_printf(s, "\"%s\"", ltt_event_get_string(e,f));
8e680509 140 break;
141
142 case LTT_ENUM:
1b960bd4 143 {
144 GQuark value = ltt_enum_string_get(type, ltt_event_get_unsigned(e,f));
73e6c609 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 }
1b960bd4 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 }
8e680509 155 break;
156
157 case LTT_ARRAY:
158 case LTT_SEQUENCE:
73e6c609 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 }
e8548639 164 // g_string_append_printf(s, "{ ");
165 //Insert header
166 g_string_append_printf(s, type->header);//tested, works fine.
167
168
8e680509 169 nb = ltt_event_field_element_number(e,f);
8e680509 170 for(i = 0 ; i < nb ; i++) {
2312de30 171 LttField *child = ltt_event_field_element_select(e,f,i);
73e6c609 172 lttv_print_field(e, child, s, field_names, i);
e8548639 173 if(i<nb-1)
174 g_string_append_printf(s,type->separator);
8e680509 175 }
e8548639 176 //g_string_append_printf(s, " }");
177 //Insert footer
178 g_string_append_printf(s, type->footer);//tested, works fine.
8e680509 179 break;
180
181 case LTT_STRUCT:
73e6c609 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 }
e8548639 187 // g_string_append_printf(s, "{ ");
188 //Insert header
189 g_string_append_printf(s, type->header);
190
8e680509 191 nb = ltt_type_member_number(type);
192 for(i = 0 ; i < nb ; i++) {
2312de30 193 LttField *element;
8e680509 194 element = ltt_field_member(f,i);
73e6c609 195 lttv_print_field(e, element, s, field_names, i);
e8548639 196 if(i < nb-1)
197 g_string_append_printf(s,type->separator);
8e680509 198 }
e8548639 199 //g_string_append_printf(s, " }");
200 //Insert footer
201 g_string_append_printf(s, type->footer);
8e680509 202 break;
203
204 case LTT_UNION:
73e6c609 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 }
e8548639 210 // g_string_append_printf(s, "{ ");
211 g_string_append_printf(s, type->header);
212
8e680509 213 nb = ltt_type_member_number(type);
214 for(i = 0 ; i < nb ; i++) {
2312de30 215 LttField *element;
8e680509 216 element = ltt_field_member(f,i);
73e6c609 217 lttv_print_field(e, element, s, field_names, i);
e8548639 218 if(i<nb-1)
219 g_string_append_printf(s, type->separator);
8e680509 220 }
e8548639 221 // g_string_append_printf(s, " }");
222 g_string_append_printf(s, type->footer);
8e680509 223 break;
2312de30 224 case LTT_NONE:
225 break;
8e680509 226 }
227}
228
8e680509 229void 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
ae3d0f50 240 guint cpu = tfs->cpu;
8e680509 241 LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context;
242 LttvProcessState *process = ts->running_process[cpu];
243
2312de30 244 GQuark name;
245
76373d36 246 guint i, num_fields;
247
0292757b 248 s = g_string_set_size(s,0);
8e680509 249
250 facility = ltt_event_facility(e);
251 event_type = ltt_event_eventtype(e);
8e680509 252
253 if(mandatory_fields) {
254 time = ltt_event_time(e);
d41c66bf 255 g_string_append_printf(s,"%s.%s: %ld.%09ld (%s%s_%u)",
8e680509 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,
d41c66bf 259 g_quark_to_string(
260 ltt_trace_name(ltt_tracefile_get_trace(tfs->parent.tf))),
8e680509 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 */
fcc08e1e 264 g_string_append_printf(s,", %u, %u, %s, %s, %u, 0x%llX, %s", process->pid,
265 process->tgid,
73e6c609 266 g_quark_to_string(process->name),
7b5f6cf1 267 g_quark_to_string(process->brand),
73e6c609 268 process->ppid, process->current_function,
269 g_quark_to_string(process->state->t));
8e680509 270 }
41b471e6 271 event_type = ltt_event_eventtype(e);
76373d36 272
41b471e6 273 num_fields = ltt_eventtype_num_fields(event_type);
743e50fd 274 if(num_fields == 0) return;
275 g_string_append_printf(s, " ");
276 g_string_append_printf(s, "{ ");
76373d36 277 for(i=0; i<num_fields; i++) {
2312de30 278 field = ltt_eventtype_field(event_type, i);
73e6c609 279 lttv_print_field(e, field, s, field_names, i);
e8548639 280 //should add ',' here
281 if(i<num_fields-1)
282 g_string_append_printf(s,", ");//tested: works fine
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.048811 seconds and 4 git commands to generate.