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
);
54 if (tf
->name
== LTT_CHANNEL_KERNEL
&&
55 info
->name
== LTT_EVENT_SYSCALL_ENTRY
&&
56 f
->name
== LTT_FIELD_SYSCALL_ID
) {
57 g_string_append_printf(s
, " [%s]",
58 g_quark_to_string(ts
->syscall_names
[value
]));
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
) {
64 g_string_append_printf(s
, " [%s]",
65 g_quark_to_string(ts
->soft_irq_names
[value
]));
70 void lttv_print_field(LttEvent
*e
, struct marker_field
*f
, GString
*s
,
71 gboolean field_names
, LttvTracefileState
*tfs
)
79 case LTT_TYPE_SIGNED_INT
:
83 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
85 value
= ltt_event_get_long_int(e
,f
);
86 //g_string_append_printf(s, "%lld", value);
87 g_string_append_printf(s
, f
->fmt
->str
, value
);
88 //g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f));
89 print_enum_events(e
, f
, value
, s
, tfs
);
92 case LTT_TYPE_UNSIGNED_INT
:
96 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
98 value
= ltt_event_get_long_unsigned(e
,f
);
99 //g_string_append_printf(s, "%llu", value);
100 g_string_append_printf(s
, f
->fmt
->str
, value
);
101 print_enum_events(e
, f
, value
, s
, tfs
);
102 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
109 unsigned car
= ltt_event_get_unsigned(e
,f
);
111 name
= ltt_field_name(f
);
113 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
117 name
= ltt_field_name(f
);
119 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
121 //g_string_append_printf(s, "%c", car);
122 g_string_append_printf(s
, type
->fmt
, car
);
124 g_string_append_printf(s
, "\\%x", car
);
130 name
= ltt_field_name(f
);
132 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
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
));
139 case LTT_TYPE_POINTER
:
143 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
145 g_string_append_printf(s
, "0x%" PRIx64
, ltt_event_get_long_unsigned(e
,f
));
146 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
149 case LTT_TYPE_STRING
:
153 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
155 g_string_append_printf(s
, "\"%s\"", ltt_event_get_string(e
,f
));
161 GQuark value
= ltt_enum_string_get(type
, ltt_event_get_unsigned(e
,f
));
163 name
= ltt_field_name(f
);
165 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
168 g_string_append_printf(s
, "%s", g_quark_to_string(value
));
170 g_string_append_printf(s
, "%lld", ltt_event_get_long_int(e
,f
));
177 name
= ltt_field_name(f
);
179 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
181 // g_string_append_printf(s, "{ ");
183 g_string_append_printf(s
, type
->header
);//tested, works fine.
186 nb
= ltt_event_field_element_number(e
,f
);
187 for(i
= 0 ; i
< nb
; i
++) {
188 LttField
*child
= ltt_event_field_element_select(e
,f
,i
);
189 lttv_print_field(e
, child
, s
, field_names
, i
);
191 g_string_append_printf(s
,type
->separator
);
193 //g_string_append_printf(s, " }");
195 g_string_append_printf(s
, type
->footer
);//tested, works fine.
200 name
= ltt_field_name(f
);
202 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
204 // g_string_append_printf(s, "{ ");
206 g_string_append_printf(s
, type
->header
);
208 nb
= ltt_type_member_number(type
);
209 for(i
= 0 ; i
< nb
; i
++) {
211 element
= ltt_field_member(f
,i
);
212 lttv_print_field(e
, element
, s
, field_names
, i
);
214 g_string_append_printf(s
,type
->separator
);
216 //g_string_append_printf(s, " }");
218 g_string_append_printf(s
, type
->footer
);
223 name
= ltt_field_name(f
);
225 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
227 // g_string_append_printf(s, "{ ");
228 g_string_append_printf(s
, type
->header
);
230 nb
= ltt_type_member_number(type
);
231 for(i
= 0 ; i
< nb
; i
++) {
233 element
= ltt_field_member(f
,i
);
234 lttv_print_field(e
, element
, s
, field_names
, i
);
236 g_string_append_printf(s
, type
->separator
);
238 // g_string_append_printf(s, " }");
239 g_string_append_printf(s
, type
->footer
);
242 case LTT_TYPE_COMPACT
:
243 g_error("compact type printing not implemented");
250 void lttv_event_to_string(LttEvent
*e
, GString
*s
,
251 gboolean mandatory_fields
, gboolean field_names
, LttvTracefileState
*tfs
)
253 struct marker_field
*field
;
254 struct marker_info
*info
;
258 guint cpu
= tfs
->cpu
;
259 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
260 LttvProcessState
*process
= ts
->running_process
[cpu
];
262 s
= g_string_set_size(s
,0);
264 info
= marker_get_info_from_id(tfs
->parent
.tf
->mdata
, e
->event_id
);
266 if(mandatory_fields
) {
267 time
= ltt_event_time(e
);
268 g_string_append_printf(s
,"%s.%s: %ld.%09ld (%s/%s_%u)",
269 g_quark_to_string(ltt_tracefile_name(tfs
->parent
.tf
)),
270 g_quark_to_string(info
->name
),
271 (long)time
.tv_sec
, time
.tv_nsec
,
273 ltt_trace_name(ltt_tracefile_get_trace(tfs
->parent
.tf
))),
274 g_quark_to_string(ltt_tracefile_name(tfs
->parent
.tf
)),
276 /* Print the process id and the state/interrupt type of the process */
277 g_string_append_printf(s
,", %u, %u, %s, %s, %u, 0x%" PRIx64
", %s",
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
));
286 if(marker_get_num_fields(info
) == 0) return;
287 g_string_append_printf(s
, " ");
288 g_string_append_printf(s
, "{ ");
289 for (field
= marker_get_field(info
, 0);
290 field
!= marker_get_field(info
, marker_get_num_fields(info
));
292 if(field
!= marker_get_field(info
, 0))
293 g_string_append_printf(s
, ", ");
294 lttv_print_field(e
, field
, s
, field_names
, tfs
);
296 g_string_append_printf(s
, " }");
303 static void destroy()
307 LTTV_MODULE("print", "Print events", \
308 "Produce a detailed text printout of events", \