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>
46 static inline void print_enum_events(LttEvent
*e
, struct marker_field
*f
,
47 guint64 value
, GString
*s
, LttvTracefileState
*tfs
)
49 LttTrace
*trace
= ltt_tracefile_get_trace(e
->tracefile
);
50 struct marker_info
*info
= marker_get_info_from_id(trace
, e
->event_id
);
51 LttvTraceState
*ts
= (LttvTraceState
*)(tfs
->parent
.t_context
);
53 //TODO optimize with old quarks.
54 if (info
->name
== g_quark_from_static_string("kernel_arch_syscall_entry") &&
55 f
->name
== LTT_FIELD_SYSCALL_ID
) {
56 g_string_append_printf(s
, " [%s]",
57 g_quark_to_string(ts
->syscall_names
[value
]));
61 void lttv_print_field(LttEvent
*e
, struct marker_field
*f
, GString
*s
,
62 gboolean field_names
, LttvTracefileState
*tfs
)
70 case LTT_TYPE_SIGNED_INT
:
74 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
76 value
= ltt_event_get_long_int(e
,f
);
77 g_string_append_printf(s
, "%lld", value
);
78 //g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f));
79 print_enum_events(e
, f
, value
, s
, tfs
);
82 case LTT_TYPE_UNSIGNED_INT
:
86 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
88 value
= ltt_event_get_long_unsigned(e
,f
);
89 g_string_append_printf(s
, "%llu", value
);
90 print_enum_events(e
, f
, value
, s
, tfs
);
91 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
98 unsigned car
= ltt_event_get_unsigned(e
,f
);
100 name
= ltt_field_name(f
);
102 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
106 name
= ltt_field_name(f
);
108 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
110 //g_string_append_printf(s, "%c", car);
111 g_string_append_printf(s
, type
->fmt
, car
);
113 g_string_append_printf(s
, "\\%x", car
);
119 name
= ltt_field_name(f
);
121 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
123 //g_string_append_printf(s, "%g", ltt_event_get_double(e,f));
124 g_string_append_printf(s
, type
->fmt
, ltt_event_get_double(e
,f
));
128 case LTT_TYPE_POINTER
:
132 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
134 g_string_append_printf(s
, "0x%llx", ltt_event_get_long_unsigned(e
,f
));
135 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
138 case LTT_TYPE_STRING
:
142 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
144 g_string_append_printf(s
, "\"%s\"", ltt_event_get_string(e
,f
));
150 GQuark value
= ltt_enum_string_get(type
, ltt_event_get_unsigned(e
,f
));
152 name
= ltt_field_name(f
);
154 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
157 g_string_append_printf(s
, "%s", g_quark_to_string(value
));
159 g_string_append_printf(s
, "%lld", ltt_event_get_long_int(e
,f
));
166 name
= ltt_field_name(f
);
168 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
170 // g_string_append_printf(s, "{ ");
172 g_string_append_printf(s
, type
->header
);//tested, works fine.
175 nb
= ltt_event_field_element_number(e
,f
);
176 for(i
= 0 ; i
< nb
; i
++) {
177 LttField
*child
= ltt_event_field_element_select(e
,f
,i
);
178 lttv_print_field(e
, child
, s
, field_names
, i
);
180 g_string_append_printf(s
,type
->separator
);
182 //g_string_append_printf(s, " }");
184 g_string_append_printf(s
, type
->footer
);//tested, works fine.
189 name
= ltt_field_name(f
);
191 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
193 // g_string_append_printf(s, "{ ");
195 g_string_append_printf(s
, type
->header
);
197 nb
= ltt_type_member_number(type
);
198 for(i
= 0 ; i
< nb
; i
++) {
200 element
= ltt_field_member(f
,i
);
201 lttv_print_field(e
, element
, s
, field_names
, i
);
203 g_string_append_printf(s
,type
->separator
);
205 //g_string_append_printf(s, " }");
207 g_string_append_printf(s
, type
->footer
);
212 name
= ltt_field_name(f
);
214 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
216 // 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, " }");
228 g_string_append_printf(s
, type
->footer
);
231 case LTT_TYPE_COMPACT
:
232 g_error("compact type printing not implemented");
239 void lttv_event_to_string(LttEvent
*e
, GString
*s
,
240 gboolean mandatory_fields
, gboolean field_names
, LttvTracefileState
*tfs
)
242 struct marker_field
*field
;
243 struct marker_info
*info
;
247 guint cpu
= tfs
->cpu
;
248 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
249 LttvProcessState
*process
= ts
->running_process
[cpu
];
250 LttTrace
*trace
= ts
->parent
.t
;
252 s
= g_string_set_size(s
,0);
254 info
= marker_get_info_from_id(trace
, e
->event_id
);
256 if(mandatory_fields
) {
257 time
= ltt_event_time(e
);
258 g_string_append_printf(s
,"%s: %ld.%09ld (%s%s_%u)",
259 g_quark_to_string(info
->name
),
260 (long)time
.tv_sec
, time
.tv_nsec
,
262 ltt_trace_name(ltt_tracefile_get_trace(tfs
->parent
.tf
))),
263 g_quark_to_string(ltt_tracefile_name(tfs
->parent
.tf
)),
265 /* Print the process id and the state/interrupt type of the process */
266 g_string_append_printf(s
,", %u, %u, %s, %s, %u, 0x%llX, %s", process
->pid
,
268 g_quark_to_string(process
->name
),
269 g_quark_to_string(process
->brand
),
270 process
->ppid
, process
->current_function
,
271 g_quark_to_string(process
->state
->t
));
274 if(marker_get_num_fields(info
) == 0) return;
275 g_string_append_printf(s
, " ");
276 g_string_append_printf(s
, "{ ");
277 for (field
= marker_get_field(info
, 0);
278 field
!= marker_get_field(info
, marker_get_num_fields(info
));
280 if(field
!= marker_get_field(info
, 0))
281 g_string_append_printf(s
, ", ");
282 lttv_print_field(e
, field
, s
, field_names
, tfs
);
284 g_string_append_printf(s
, " }");
291 static void destroy()
295 LTTV_MODULE("print", "Print events", \
296 "Produce a detailed text printout of events", \