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 struct marker_info
*info
= marker_get_info_from_id(tfs
->parent
.tf
->mdata
,
52 LttvTraceState
*ts
= (LttvTraceState
*)(tfs
->parent
.t_context
);
54 //TODO optimize with old quarks.
55 if (info
->name
== g_quark_from_static_string("kernel_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
== g_quark_from_static_string("kernel_softirq_entry")
60 || info
->name
== g_quark_from_static_string("kernel_softirq_exit")
61 || info
->name
== g_quark_from_static_string("kernel_softirq_raise")) &&
62 f
->name
== g_quark_from_static_string("softirq_id")) {
63 g_string_append_printf(s
, " [%s]",
64 g_quark_to_string(ts
->soft_irq_names
[value
]));
69 void lttv_print_field(LttEvent
*e
, struct marker_field
*f
, GString
*s
,
70 gboolean field_names
, LttvTracefileState
*tfs
)
78 case LTT_TYPE_SIGNED_INT
:
82 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
84 value
= ltt_event_get_long_int(e
,f
);
85 //g_string_append_printf(s, "%lld", value);
86 g_string_append_printf(s
, f
->fmt
->str
, value
);
87 //g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f));
88 print_enum_events(e
, f
, value
, s
, tfs
);
91 case LTT_TYPE_UNSIGNED_INT
:
95 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
97 value
= ltt_event_get_long_unsigned(e
,f
);
98 //g_string_append_printf(s, "%llu", value);
99 g_string_append_printf(s
, f
->fmt
->str
, value
);
100 print_enum_events(e
, f
, value
, s
, tfs
);
101 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
108 unsigned car
= ltt_event_get_unsigned(e
,f
);
110 name
= ltt_field_name(f
);
112 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
116 name
= ltt_field_name(f
);
118 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
120 //g_string_append_printf(s, "%c", car);
121 g_string_append_printf(s
, type
->fmt
, car
);
123 g_string_append_printf(s
, "\\%x", car
);
129 name
= ltt_field_name(f
);
131 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
133 //g_string_append_printf(s, "%g", ltt_event_get_double(e,f));
134 g_string_append_printf(s
, type
->fmt
, ltt_event_get_double(e
,f
));
138 case LTT_TYPE_POINTER
:
142 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
144 g_string_append_printf(s
, "0x%" PRIx64
, ltt_event_get_long_unsigned(e
,f
));
145 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
148 case LTT_TYPE_STRING
:
152 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
154 g_string_append_printf(s
, "\"%s\"", ltt_event_get_string(e
,f
));
160 GQuark value
= ltt_enum_string_get(type
, ltt_event_get_unsigned(e
,f
));
162 name
= ltt_field_name(f
);
164 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
167 g_string_append_printf(s
, "%s", g_quark_to_string(value
));
169 g_string_append_printf(s
, "%lld", ltt_event_get_long_int(e
,f
));
176 name
= ltt_field_name(f
);
178 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
180 // g_string_append_printf(s, "{ ");
182 g_string_append_printf(s
, type
->header
);//tested, works fine.
185 nb
= ltt_event_field_element_number(e
,f
);
186 for(i
= 0 ; i
< nb
; i
++) {
187 LttField
*child
= ltt_event_field_element_select(e
,f
,i
);
188 lttv_print_field(e
, child
, s
, field_names
, i
);
190 g_string_append_printf(s
,type
->separator
);
192 //g_string_append_printf(s, " }");
194 g_string_append_printf(s
, type
->footer
);//tested, works fine.
199 name
= ltt_field_name(f
);
201 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
203 // g_string_append_printf(s, "{ ");
205 g_string_append_printf(s
, type
->header
);
207 nb
= ltt_type_member_number(type
);
208 for(i
= 0 ; i
< nb
; i
++) {
210 element
= ltt_field_member(f
,i
);
211 lttv_print_field(e
, element
, s
, field_names
, i
);
213 g_string_append_printf(s
,type
->separator
);
215 //g_string_append_printf(s, " }");
217 g_string_append_printf(s
, type
->footer
);
222 name
= ltt_field_name(f
);
224 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
226 // g_string_append_printf(s, "{ ");
227 g_string_append_printf(s
, type
->header
);
229 nb
= ltt_type_member_number(type
);
230 for(i
= 0 ; i
< nb
; i
++) {
232 element
= ltt_field_member(f
,i
);
233 lttv_print_field(e
, element
, s
, field_names
, i
);
235 g_string_append_printf(s
, type
->separator
);
237 // g_string_append_printf(s, " }");
238 g_string_append_printf(s
, type
->footer
);
241 case LTT_TYPE_COMPACT
:
242 g_error("compact type printing not implemented");
249 void lttv_event_to_string(LttEvent
*e
, GString
*s
,
250 gboolean mandatory_fields
, gboolean field_names
, LttvTracefileState
*tfs
)
252 struct marker_field
*field
;
253 struct marker_info
*info
;
257 guint cpu
= tfs
->cpu
;
258 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
259 LttvProcessState
*process
= ts
->running_process
[cpu
];
261 s
= g_string_set_size(s
,0);
263 info
= marker_get_info_from_id(tfs
->parent
.tf
->mdata
, e
->event_id
);
265 if(mandatory_fields
) {
266 time
= ltt_event_time(e
);
267 g_string_append_printf(s
,"%s: %ld.%09ld (%s/%s_%u)",
268 g_quark_to_string(info
->name
),
269 (long)time
.tv_sec
, time
.tv_nsec
,
271 ltt_trace_name(ltt_tracefile_get_trace(tfs
->parent
.tf
))),
272 g_quark_to_string(ltt_tracefile_name(tfs
->parent
.tf
)),
274 /* Print the process id and the state/interrupt type of the process */
275 g_string_append_printf(s
,", %u, %u, %s, %s, %u, 0x%" PRIx64
", %s",
278 g_quark_to_string(process
->name
),
279 g_quark_to_string(process
->brand
),
280 process
->ppid
, process
->current_function
,
281 g_quark_to_string(process
->state
->t
));
284 if(marker_get_num_fields(info
) == 0) return;
285 g_string_append_printf(s
, " ");
286 g_string_append_printf(s
, "{ ");
287 for (field
= marker_get_field(info
, 0);
288 field
!= marker_get_field(info
, marker_get_num_fields(info
));
290 if(field
!= marker_get_field(info
, 0))
291 g_string_append_printf(s
, ", ");
292 lttv_print_field(e
, field
, s
, field_names
, tfs
);
294 g_string_append_printf(s
, " }");
301 static void destroy()
305 LTTV_MODULE("print", "Print events", \
306 "Produce a detailed text printout of events", \