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>
43 #include <ltt/trace.h>
44 #include <ltt/facility.h>
47 #include<ltt/ltt-private.h>
51 void lttv_print_field(LttEvent
*e
, LttField
*f
, GString
*s
,
52 gboolean field_names
, guint element_index
) {
60 type
= ltt_field_type(f
);
62 switch(ltt_type_class(type
)) {
69 name
= ltt_field_name(f
);
71 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
74 //g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f));
75 g_string_append_printf(s
, type
->fmt
, ltt_event_get_long_int(e
,f
));
85 name
= ltt_field_name(f
);
87 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
89 // g_string_append_printf(s, "%llu", ltt_event_get_long_unsigned(e,f));
90 g_string_append_printf(s
, type
->fmt
, ltt_event_get_long_unsigned(e
,f
));
96 unsigned car
= ltt_event_get_unsigned(e
,f
);
98 name
= ltt_field_name(f
);
100 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
104 name
= ltt_field_name(f
);
106 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
108 //g_string_append_printf(s, "%c", car);
109 g_string_append_printf(s
, type
->fmt
, car
);
111 g_string_append_printf(s
, "\\%x", car
);
117 name
= ltt_field_name(f
);
119 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
121 //g_string_append_printf(s, "%g", ltt_event_get_double(e,f));
122 g_string_append_printf(s
, type
->fmt
, ltt_event_get_double(e
,f
));
127 name
= ltt_field_name(f
);
129 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
131 // g_string_append_printf(s, "0x%llx", ltt_event_get_long_unsigned(e,f));
132 g_string_append_printf(s
, type
->fmt
, ltt_event_get_long_unsigned(e
,f
));
137 name
= ltt_field_name(f
);
139 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
141 g_string_append_printf(s
, "\"%s\"", ltt_event_get_string(e
,f
));
146 GQuark value
= ltt_enum_string_get(type
, ltt_event_get_unsigned(e
,f
));
148 name
= ltt_field_name(f
);
150 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
153 g_string_append_printf(s
, "%s", g_quark_to_string(value
));
155 g_string_append_printf(s
, "%lld", ltt_event_get_long_int(e
,f
));
162 name
= ltt_field_name(f
);
164 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
166 // g_string_append_printf(s, "{ ");
168 g_string_append_printf(s
, type
->header
);//tested, works fine.
171 nb
= ltt_event_field_element_number(e
,f
);
172 for(i
= 0 ; i
< nb
; i
++) {
173 LttField
*child
= ltt_event_field_element_select(e
,f
,i
);
174 lttv_print_field(e
, child
, s
, field_names
, i
);
176 g_string_append_printf(s
,type
->separator
);
178 //g_string_append_printf(s, " }");
180 g_string_append_printf(s
, type
->footer
);//tested, works fine.
185 name
= ltt_field_name(f
);
187 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
189 // g_string_append_printf(s, "{ ");
191 g_string_append_printf(s
, type
->header
);
193 nb
= ltt_type_member_number(type
);
194 for(i
= 0 ; i
< nb
; i
++) {
196 element
= ltt_field_member(f
,i
);
197 lttv_print_field(e
, element
, s
, field_names
, i
);
199 g_string_append_printf(s
,type
->separator
);
201 //g_string_append_printf(s, " }");
203 g_string_append_printf(s
, type
->footer
);
208 name
= ltt_field_name(f
);
210 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
212 // g_string_append_printf(s, "{ ");
213 g_string_append_printf(s
, type
->header
);
215 nb
= ltt_type_member_number(type
);
216 for(i
= 0 ; i
< nb
; i
++) {
218 element
= ltt_field_member(f
,i
);
219 lttv_print_field(e
, element
, s
, field_names
, i
);
221 g_string_append_printf(s
, type
->separator
);
223 // g_string_append_printf(s, " }");
224 g_string_append_printf(s
, type
->footer
);
231 void lttv_event_to_string(LttEvent
*e
, GString
*s
,
232 gboolean mandatory_fields
, gboolean field_names
, LttvTracefileState
*tfs
)
234 LttFacility
*facility
;
236 LttEventType
*event_type
;
242 guint cpu
= tfs
->cpu
;
243 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
244 LttvProcessState
*process
= ts
->running_process
[cpu
];
250 s
= g_string_set_size(s
,0);
252 facility
= ltt_event_facility(e
);
253 event_type
= ltt_event_eventtype(e
);
255 if(mandatory_fields
) {
256 time
= ltt_event_time(e
);
257 g_string_append_printf(s
,"%s.%s: %ld.%09ld (%s%s_%u)",
258 g_quark_to_string(ltt_facility_name(facility
)),
259 g_quark_to_string(ltt_eventtype_name(event_type
)),
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
));
273 event_type
= ltt_event_eventtype(e
);
275 num_fields
= ltt_eventtype_num_fields(event_type
);
276 if(num_fields
== 0) return;
277 g_string_append_printf(s
, " ");
278 g_string_append_printf(s
, "{ ");
279 for(i
=0; i
<num_fields
; i
++) {
280 field
= ltt_eventtype_field(event_type
, i
);
281 lttv_print_field(e
, field
, s
, field_names
, i
);
282 //should add ',' here
284 g_string_append_printf(s
,", ");//tested: works fine
286 g_string_append_printf(s
, " }");
293 static void destroy()
297 LTTV_MODULE("print", "Print events", \
298 "Produce a detailed text printout of events", \