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