3 /* This file is part of the Linux Trace Toolkit viewer
4 * Copyright (C) 2003-2004 Michel Dagenais
5 * 2005 Mathieu Desnoyers
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License Version 2 as
9 * published by the Free Software Foundation;
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24 * Event printing routines.
31 #include <lttv/lttv.h>
32 #include <lttv/option.h>
33 #include <lttv/module.h>
34 #include <lttv/hook.h>
35 #include <lttv/attribute.h>
36 #include <lttv/iattribute.h>
37 #include <lttv/stats.h>
38 #include <lttv/filter.h>
39 #include <lttv/print.h>
41 #include <ltt/event.h>
42 #include <ltt/trace.h>
45 #include<ltt/ltt-private.h>
49 void lttv_print_field(LttEvent
*e
, LttField
*f
, GString
*s
,
50 gboolean field_names
, guint element_index
) {
58 type
= ltt_field_type(f
);
60 switch(ltt_type_class(type
)) {
67 name
= ltt_field_name(f
);
69 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
72 //g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f));
73 g_string_append_printf(s
, type
->fmt
, ltt_event_get_long_int(e
,f
));
83 name
= ltt_field_name(f
);
85 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
87 // g_string_append_printf(s, "%llu", ltt_event_get_long_unsigned(e,f));
88 g_string_append_printf(s
, type
->fmt
, ltt_event_get_long_unsigned(e
,f
));
94 unsigned car
= ltt_event_get_unsigned(e
,f
);
96 name
= ltt_field_name(f
);
98 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
102 name
= ltt_field_name(f
);
104 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
106 //g_string_append_printf(s, "%c", car);
107 g_string_append_printf(s
, type
->fmt
, car
);
109 g_string_append_printf(s
, "\\%x", car
);
115 name
= ltt_field_name(f
);
117 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
119 //g_string_append_printf(s, "%g", ltt_event_get_double(e,f));
120 g_string_append_printf(s
, type
->fmt
, ltt_event_get_double(e
,f
));
125 name
= ltt_field_name(f
);
127 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
129 // g_string_append_printf(s, "0x%llx", ltt_event_get_long_unsigned(e,f));
130 g_string_append_printf(s
, type
->fmt
, ltt_event_get_long_unsigned(e
,f
));
135 name
= ltt_field_name(f
);
137 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
139 g_string_append_printf(s
, "\"%s\"", ltt_event_get_string(e
,f
));
144 GQuark value
= ltt_enum_string_get(type
, ltt_event_get_unsigned(e
,f
));
146 name
= ltt_field_name(f
);
148 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
151 g_string_append_printf(s
, "%s", g_quark_to_string(value
));
153 g_string_append_printf(s
, "%lld", ltt_event_get_long_int(e
,f
));
160 name
= ltt_field_name(f
);
162 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
164 // g_string_append_printf(s, "{ ");
166 g_string_append_printf(s
, type
->header
);//tested, works fine.
169 nb
= ltt_event_field_element_number(e
,f
);
170 for(i
= 0 ; i
< nb
; i
++) {
171 LttField
*child
= ltt_event_field_element_select(e
,f
,i
);
172 lttv_print_field(e
, child
, s
, field_names
, i
);
174 g_string_append_printf(s
,type
->separator
);
176 //g_string_append_printf(s, " }");
178 g_string_append_printf(s
, type
->footer
);//tested, works fine.
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
);
191 nb
= ltt_type_member_number(type
);
192 for(i
= 0 ; i
< nb
; i
++) {
194 element
= ltt_field_member(f
,i
);
195 lttv_print_field(e
, element
, 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
);
206 name
= ltt_field_name(f
);
208 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
210 // g_string_append_printf(s, "{ ");
211 g_string_append_printf(s
, type
->header
);
213 nb
= ltt_type_member_number(type
);
214 for(i
= 0 ; i
< nb
; i
++) {
216 element
= ltt_field_member(f
,i
);
217 lttv_print_field(e
, element
, s
, field_names
, i
);
219 g_string_append_printf(s
, type
->separator
);
221 // g_string_append_printf(s, " }");
222 g_string_append_printf(s
, type
->footer
);
229 void lttv_event_to_string(LttEvent
*e
, GString
*s
,
230 gboolean mandatory_fields
, gboolean field_names
, LttvTracefileState
*tfs
)
232 LttFacility
*facility
;
234 LttEventType
*event_type
;
240 guint cpu
= tfs
->cpu
;
241 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
242 LttvProcessState
*process
= ts
->running_process
[cpu
];
248 s
= g_string_set_size(s
,0);
250 facility
= ltt_event_facility(e
);
251 event_type
= ltt_event_eventtype(e
);
253 if(mandatory_fields
) {
254 time
= ltt_event_time(e
);
255 g_string_append_printf(s
,"%s.%s: %ld.%09ld (%s%s_%u)",
256 g_quark_to_string(ltt_facility_name(facility
)),
257 g_quark_to_string(ltt_eventtype_name(event_type
)),
258 (long)time
.tv_sec
, time
.tv_nsec
,
260 ltt_trace_name(ltt_tracefile_get_trace(tfs
->parent
.tf
))),
261 g_quark_to_string(ltt_tracefile_name(tfs
->parent
.tf
)),
263 /* Print the process id and the state/interrupt type of the process */
264 g_string_append_printf(s
,", %u, %u, %s, %s, %u, 0x%llX, %s", process
->pid
,
266 g_quark_to_string(process
->name
),
267 g_quark_to_string(process
->brand
),
268 process
->ppid
, process
->current_function
,
269 g_quark_to_string(process
->state
->t
));
271 event_type
= ltt_event_eventtype(e
);
273 num_fields
= ltt_eventtype_num_fields(event_type
);
274 if(num_fields
== 0) return;
275 g_string_append_printf(s
, " ");
276 g_string_append_printf(s
, "{ ");
277 for(i
=0; i
<num_fields
; i
++) {
278 field
= ltt_eventtype_field(event_type
, i
);
279 lttv_print_field(e
, field
, s
, field_names
, i
);
280 //should add ',' here
282 g_string_append_printf(s
,", ");//tested: works fine
284 g_string_append_printf(s
, " }");
291 static void destroy()
295 LTTV_MODULE("print", "Print events", \
296 "Produce a detailed text printout of events", \