1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
3 * 2005 Mathieu Desnoyers
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;
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.
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,
22 * Event printing routines.
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>
39 #include <ltt/event.h>
40 #include <ltt/trace.h>
43 #include <ltt/ltt-private.h>
47 static inline void print_enum_events(LttEvent
*e
, struct marker_field
*f
,
48 guint64 value
, GString
*s
, LttvTracefileState
*tfs
)
50 LttTracefile
*tf
= tfs
->parent
.tf
;
51 struct marker_info
*info
= marker_get_info_from_id(tf
->mdata
, e
->event_id
);
52 LttvTraceState
*ts
= (LttvTraceState
*)(tfs
->parent
.t_context
);
53 LttvNameTables
*nt
= ts
->name_tables
;
55 if (tf
->name
== LTT_CHANNEL_KERNEL
) {
56 if (info
->name
== LTT_EVENT_SYSCALL_ENTRY
57 && f
->name
== LTT_FIELD_SYSCALL_ID
) {
58 g_string_append_printf(s
, " [%s]",
59 g_quark_to_string(nt
->syscall_names
[value
]));
60 } else if ((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
) {
64 g_string_append_printf(s
, " [%s]",
65 g_quark_to_string(nt
->soft_irq_names
[value
]));
66 } else if (info
->name
== LTT_EVENT_KPROBE
67 && f
->name
== LTT_FIELD_IP
) {
68 #if (__WORDSIZE == 32)
69 GQuark symbol
= (GQuark
)g_hash_table_lookup(nt
->kprobe_hash
,
70 (gconstpointer
)&value
);
72 GQuark symbol
= (GQuark
)(unsigned long)g_hash_table_lookup(nt
->kprobe_hash
,
73 (gconstpointer
)value
);
76 g_string_append_printf(s
, " [%s]", g_quark_to_string(symbol
));
81 void lttv_print_field(LttEvent
*e
, struct marker_field
*f
, GString
*s
,
82 gboolean field_names
, LttvTracefileState
*tfs
)
90 case LTT_TYPE_SIGNED_INT
:
94 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
96 value
= ltt_event_get_long_int(e
,f
);
97 //g_string_append_printf(s, "%lld", value);
98 g_string_append_printf(s
, f
->fmt
->str
, value
);
99 //g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f));
100 print_enum_events(e
, f
, value
, s
, tfs
);
103 case LTT_TYPE_UNSIGNED_INT
:
107 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
109 value
= ltt_event_get_long_unsigned(e
,f
);
110 //g_string_append_printf(s, "%llu", value);
111 g_string_append_printf(s
, f
->fmt
->str
, value
);
112 print_enum_events(e
, f
, value
, s
, tfs
);
113 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
120 unsigned car
= ltt_event_get_unsigned(e
,f
);
122 name
= ltt_field_name(f
);
124 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
128 name
= ltt_field_name(f
);
130 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
132 //g_string_append_printf(s, "%c", car);
133 g_string_append_printf(s
, type
->fmt
, car
);
135 g_string_append_printf(s
, "\\%x", car
);
141 name
= ltt_field_name(f
);
143 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
145 //g_string_append_printf(s, "%g", ltt_event_get_double(e,f));
146 g_string_append_printf(s
, type
->fmt
, ltt_event_get_double(e
,f
));
150 case LTT_TYPE_POINTER
:
154 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
156 g_string_append_printf(s
, "0x%" PRIx64
, ltt_event_get_long_unsigned(e
,f
));
157 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
160 case LTT_TYPE_STRING
:
164 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
166 g_string_append_printf(s
, "\"%s\"", ltt_event_get_string(e
,f
));
172 GQuark value
= ltt_enum_string_get(type
, ltt_event_get_unsigned(e
,f
));
174 name
= ltt_field_name(f
);
176 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
179 g_string_append_printf(s
, "%s", g_quark_to_string(value
));
181 g_string_append_printf(s
, "%lld", ltt_event_get_long_int(e
,f
));
188 name
= ltt_field_name(f
);
190 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
192 // g_string_append_printf(s, "{ ");
194 g_string_append_printf(s
, type
->header
);//tested, works fine.
197 nb
= ltt_event_field_element_number(e
,f
);
198 for(i
= 0 ; i
< nb
; i
++) {
199 LttField
*child
= ltt_event_field_element_select(e
,f
,i
);
200 lttv_print_field(e
, child
, s
, field_names
, i
);
202 g_string_append_printf(s
,type
->separator
);
204 //g_string_append_printf(s, " }");
206 g_string_append_printf(s
, type
->footer
);//tested, works fine.
211 name
= ltt_field_name(f
);
213 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
215 // g_string_append_printf(s, "{ ");
217 g_string_append_printf(s
, type
->header
);
219 nb
= ltt_type_member_number(type
);
220 for(i
= 0 ; i
< nb
; i
++) {
222 element
= ltt_field_member(f
,i
);
223 lttv_print_field(e
, element
, s
, field_names
, i
);
225 g_string_append_printf(s
,type
->separator
);
227 //g_string_append_printf(s, " }");
229 g_string_append_printf(s
, type
->footer
);
234 name
= ltt_field_name(f
);
236 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
238 // g_string_append_printf(s, "{ ");
239 g_string_append_printf(s
, type
->header
);
241 nb
= ltt_type_member_number(type
);
242 for(i
= 0 ; i
< nb
; i
++) {
244 element
= ltt_field_member(f
,i
);
245 lttv_print_field(e
, element
, s
, field_names
, i
);
247 g_string_append_printf(s
, type
->separator
);
249 // g_string_append_printf(s, " }");
250 g_string_append_printf(s
, type
->footer
);
253 case LTT_TYPE_COMPACT
:
254 g_error("compact type printing not implemented");
261 void lttv_event_to_string(LttEvent
*e
, GString
*s
, gboolean mandatory_fields
,
262 gboolean field_names
, LttvTracefileState
*tfs
)
264 struct marker_field
*field
;
265 struct marker_info
*info
;
269 guint cpu
= tfs
->cpu
;
270 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
271 LttvProcessState
*process
= ts
->running_process
[cpu
];
273 s
= g_string_set_size(s
,0);
275 info
= marker_get_info_from_id(tfs
->parent
.tf
->mdata
, e
->event_id
);
277 if(mandatory_fields
) {
278 time
= ltt_event_time(e
);
279 g_string_append_printf(s
,"%s.%s: %ld.%09ld (%s/%s_%u)",
280 g_quark_to_string(ltt_tracefile_name(tfs
->parent
.tf
)),
281 g_quark_to_string(info
->name
), (long)time
.tv_sec
, time
.tv_nsec
,
283 ltt_trace_name(ltt_tracefile_get_trace(tfs
->parent
.tf
))),
284 g_quark_to_string(ltt_tracefile_name(tfs
->parent
.tf
)), cpu
);
285 /* Print the process id and the state/interrupt type of the process */
286 g_string_append_printf(s
,", %u, %u, %s, %s, %u, 0x%" PRIx64
", %s",
289 g_quark_to_string(process
->name
),
290 g_quark_to_string(process
->brand
),
292 process
->current_function
,
293 g_quark_to_string(process
->state
->t
));
296 if(marker_get_num_fields(info
) == 0) return;
297 g_string_append_printf(s
, " ");
298 g_string_append_printf(s
, "{ ");
299 for (field
= marker_get_field(info
, 0);
300 field
!= marker_get_field(info
, marker_get_num_fields(info
));
302 if(field
!= marker_get_field(info
, 0))
303 g_string_append_printf(s
, ", ");
304 lttv_print_field(e
, field
, s
, field_names
, tfs
);
306 g_string_append_printf(s
, " }");
313 static void destroy()
317 LTTV_MODULE("print", "Print events", \
318 "Produce a detailed text printout of events", \