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 void lttv_print_field(LttEvent
*e
, struct marker_field
*f
, GString
*s
,
55 case LTT_TYPE_SIGNED_INT
:
59 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
62 g_string_append_printf(s
, "%lld", ltt_event_get_long_int(e
,f
));
63 //g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f));
66 case LTT_TYPE_UNSIGNED_INT
:
70 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
72 g_string_append_printf(s
, "%llu", ltt_event_get_long_unsigned(e
,f
));
73 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
80 unsigned car
= ltt_event_get_unsigned(e
,f
);
82 name
= ltt_field_name(f
);
84 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
88 name
= ltt_field_name(f
);
90 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
92 //g_string_append_printf(s, "%c", car);
93 g_string_append_printf(s
, type
->fmt
, car
);
95 g_string_append_printf(s
, "\\%x", car
);
101 name
= ltt_field_name(f
);
103 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
105 //g_string_append_printf(s, "%g", ltt_event_get_double(e,f));
106 g_string_append_printf(s
, type
->fmt
, ltt_event_get_double(e
,f
));
110 case LTT_TYPE_POINTER
:
114 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
116 g_string_append_printf(s
, "0x%llx", ltt_event_get_long_unsigned(e
,f
));
117 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
120 case LTT_TYPE_STRING
:
124 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
126 g_string_append_printf(s
, "\"%s\"", ltt_event_get_string(e
,f
));
132 GQuark value
= ltt_enum_string_get(type
, ltt_event_get_unsigned(e
,f
));
134 name
= ltt_field_name(f
);
136 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
139 g_string_append_printf(s
, "%s", g_quark_to_string(value
));
141 g_string_append_printf(s
, "%lld", ltt_event_get_long_int(e
,f
));
148 name
= ltt_field_name(f
);
150 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
152 // g_string_append_printf(s, "{ ");
154 g_string_append_printf(s
, type
->header
);//tested, works fine.
157 nb
= ltt_event_field_element_number(e
,f
);
158 for(i
= 0 ; i
< nb
; i
++) {
159 LttField
*child
= ltt_event_field_element_select(e
,f
,i
);
160 lttv_print_field(e
, child
, s
, field_names
, i
);
162 g_string_append_printf(s
,type
->separator
);
164 //g_string_append_printf(s, " }");
166 g_string_append_printf(s
, type
->footer
);//tested, works fine.
171 name
= ltt_field_name(f
);
173 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
175 // g_string_append_printf(s, "{ ");
177 g_string_append_printf(s
, type
->header
);
179 nb
= ltt_type_member_number(type
);
180 for(i
= 0 ; i
< nb
; i
++) {
182 element
= ltt_field_member(f
,i
);
183 lttv_print_field(e
, element
, s
, field_names
, i
);
185 g_string_append_printf(s
,type
->separator
);
187 //g_string_append_printf(s, " }");
189 g_string_append_printf(s
, type
->footer
);
194 name
= ltt_field_name(f
);
196 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
198 // g_string_append_printf(s, "{ ");
199 g_string_append_printf(s
, type
->header
);
201 nb
= ltt_type_member_number(type
);
202 for(i
= 0 ; i
< nb
; i
++) {
204 element
= ltt_field_member(f
,i
);
205 lttv_print_field(e
, element
, s
, field_names
, i
);
207 g_string_append_printf(s
, type
->separator
);
209 // g_string_append_printf(s, " }");
210 g_string_append_printf(s
, type
->footer
);
213 case LTT_TYPE_COMPACT
:
214 g_error("compact type printing not implemented");
221 void lttv_event_to_string(LttEvent
*e
, GString
*s
,
222 gboolean mandatory_fields
, gboolean field_names
, LttvTracefileState
*tfs
)
224 struct marker_field
*field
;
225 struct marker_info
*info
;
229 guint cpu
= tfs
->cpu
;
230 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
231 LttvProcessState
*process
= ts
->running_process
[cpu
];
232 LttTrace
*trace
= ts
->parent
.t
;
234 s
= g_string_set_size(s
,0);
236 info
= marker_get_info_from_id(trace
, e
->event_id
);
238 if(mandatory_fields
) {
239 time
= ltt_event_time(e
);
240 g_string_append_printf(s
,"%s: %ld.%09ld (%s%s_%u)",
241 g_quark_to_string(info
->name
),
242 (long)time
.tv_sec
, time
.tv_nsec
,
244 ltt_trace_name(ltt_tracefile_get_trace(tfs
->parent
.tf
))),
245 g_quark_to_string(ltt_tracefile_name(tfs
->parent
.tf
)),
247 /* Print the process id and the state/interrupt type of the process */
248 g_string_append_printf(s
,", %u, %u, %s, %s, %u, 0x%llX, %s", process
->pid
,
250 g_quark_to_string(process
->name
),
251 g_quark_to_string(process
->brand
),
252 process
->ppid
, process
->current_function
,
253 g_quark_to_string(process
->state
->t
));
256 if(marker_get_num_fields(info
) == 0) return;
257 g_string_append_printf(s
, " ");
258 g_string_append_printf(s
, "{ ");
259 for (field
= marker_get_field(info
, 0);
260 field
!= marker_get_field(info
, marker_get_num_fields(info
));
262 if(field
!= marker_get_field(info
, 0))
263 g_string_append_printf(s
, ", ");
264 lttv_print_field(e
, field
, s
, field_names
);
266 g_string_append_printf(s
, " }");
273 static void destroy()
277 LTTV_MODULE("print", "Print events", \
278 "Produce a detailed text printout of events", \