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