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