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 if (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 ((info
->name
== LTT_EVENT_SOFT_IRQ_ENTRY
60 || info
->name
== LTT_EVENT_SOFT_IRQ_EXIT
61 || info
->name
== LTT_EVENT_SOFT_IRQ_RAISE
)
62 && f
->name
== LTT_FIELD_SOFT_IRQ_ID
) {
63 g_string_append_printf(s
, " [%s]",
64 g_quark_to_string(ts
->soft_irq_names
[value
]));
66 /* TODO : implement hash table.
67 else if (info->name == LTT_EVENT_KPROBE
68 && f->name = LTT_FIELD_IP) {
69 g_string_append_printf(s, " [%s]",
70 g_quark_to_string(ts->kprobe_symbols[value]));
76 void lttv_print_field(LttEvent
*e
, struct marker_field
*f
, GString
*s
,
77 gboolean field_names
, LttvTracefileState
*tfs
)
85 case LTT_TYPE_SIGNED_INT
:
89 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
91 value
= ltt_event_get_long_int(e
,f
);
92 //g_string_append_printf(s, "%lld", value);
93 g_string_append_printf(s
, f
->fmt
->str
, value
);
94 //g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f));
95 print_enum_events(e
, f
, value
, s
, tfs
);
98 case LTT_TYPE_UNSIGNED_INT
:
102 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
104 value
= ltt_event_get_long_unsigned(e
,f
);
105 //g_string_append_printf(s, "%llu", value);
106 g_string_append_printf(s
, f
->fmt
->str
, value
);
107 print_enum_events(e
, f
, value
, s
, tfs
);
108 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
115 unsigned car
= ltt_event_get_unsigned(e
,f
);
117 name
= ltt_field_name(f
);
119 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
123 name
= ltt_field_name(f
);
125 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
127 //g_string_append_printf(s, "%c", car);
128 g_string_append_printf(s
, type
->fmt
, car
);
130 g_string_append_printf(s
, "\\%x", car
);
136 name
= ltt_field_name(f
);
138 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
140 //g_string_append_printf(s, "%g", ltt_event_get_double(e,f));
141 g_string_append_printf(s
, type
->fmt
, ltt_event_get_double(e
,f
));
145 case LTT_TYPE_POINTER
:
149 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
151 g_string_append_printf(s
, "0x%" PRIx64
, ltt_event_get_long_unsigned(e
,f
));
152 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
155 case LTT_TYPE_STRING
:
159 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
161 g_string_append_printf(s
, "\"%s\"", ltt_event_get_string(e
,f
));
167 GQuark value
= ltt_enum_string_get(type
, ltt_event_get_unsigned(e
,f
));
169 name
= ltt_field_name(f
);
171 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
174 g_string_append_printf(s
, "%s", g_quark_to_string(value
));
176 g_string_append_printf(s
, "%lld", ltt_event_get_long_int(e
,f
));
183 name
= ltt_field_name(f
);
185 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
187 // g_string_append_printf(s, "{ ");
189 g_string_append_printf(s
, type
->header
);//tested, works fine.
192 nb
= ltt_event_field_element_number(e
,f
);
193 for(i
= 0 ; i
< nb
; i
++) {
194 LttField
*child
= ltt_event_field_element_select(e
,f
,i
);
195 lttv_print_field(e
, child
, s
, field_names
, i
);
197 g_string_append_printf(s
,type
->separator
);
199 //g_string_append_printf(s, " }");
201 g_string_append_printf(s
, type
->footer
);//tested, works fine.
206 name
= ltt_field_name(f
);
208 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
210 // g_string_append_printf(s, "{ ");
212 g_string_append_printf(s
, type
->header
);
214 nb
= ltt_type_member_number(type
);
215 for(i
= 0 ; i
< nb
; i
++) {
217 element
= ltt_field_member(f
,i
);
218 lttv_print_field(e
, element
, s
, field_names
, i
);
220 g_string_append_printf(s
,type
->separator
);
222 //g_string_append_printf(s, " }");
224 g_string_append_printf(s
, type
->footer
);
229 name
= ltt_field_name(f
);
231 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
233 // g_string_append_printf(s, "{ ");
234 g_string_append_printf(s
, type
->header
);
236 nb
= ltt_type_member_number(type
);
237 for(i
= 0 ; i
< nb
; i
++) {
239 element
= ltt_field_member(f
,i
);
240 lttv_print_field(e
, element
, s
, field_names
, i
);
242 g_string_append_printf(s
, type
->separator
);
244 // g_string_append_printf(s, " }");
245 g_string_append_printf(s
, type
->footer
);
248 case LTT_TYPE_COMPACT
:
249 g_error("compact type printing not implemented");
256 void lttv_event_to_string(LttEvent
*e
, GString
*s
,
257 gboolean mandatory_fields
, gboolean field_names
, LttvTracefileState
*tfs
)
259 struct marker_field
*field
;
260 struct marker_info
*info
;
264 guint cpu
= tfs
->cpu
;
265 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
266 LttvProcessState
*process
= ts
->running_process
[cpu
];
268 s
= g_string_set_size(s
,0);
270 info
= marker_get_info_from_id(tfs
->parent
.tf
->mdata
, e
->event_id
);
272 if(mandatory_fields
) {
273 time
= ltt_event_time(e
);
274 g_string_append_printf(s
,"%s.%s: %ld.%09ld (%s/%s_%u)",
275 g_quark_to_string(ltt_tracefile_name(tfs
->parent
.tf
)),
276 g_quark_to_string(info
->name
),
277 (long)time
.tv_sec
, time
.tv_nsec
,
279 ltt_trace_name(ltt_tracefile_get_trace(tfs
->parent
.tf
))),
280 g_quark_to_string(ltt_tracefile_name(tfs
->parent
.tf
)),
282 /* Print the process id and the state/interrupt type of the process */
283 g_string_append_printf(s
,", %u, %u, %s, %s, %u, 0x%" PRIx64
", %s",
286 g_quark_to_string(process
->name
),
287 g_quark_to_string(process
->brand
),
288 process
->ppid
, process
->current_function
,
289 g_quark_to_string(process
->state
->t
));
292 if(marker_get_num_fields(info
) == 0) return;
293 g_string_append_printf(s
, " ");
294 g_string_append_printf(s
, "{ ");
295 for (field
= marker_get_field(info
, 0);
296 field
!= marker_get_field(info
, marker_get_num_fields(info
));
298 if(field
!= marker_get_field(info
, 0))
299 g_string_append_printf(s
, ", ");
300 lttv_print_field(e
, field
, s
, field_names
, tfs
);
302 g_string_append_printf(s
, " }");
309 static void destroy()
313 LTTV_MODULE("print", "Print events", \
314 "Produce a detailed text printout of events", \