2 /* This file is part of the Linux Trace Toolkit viewer
3 * Copyright (C) 2003-2004 Michel Dagenais
4 * 2005 Mathieu Desnoyers
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License Version 2 as
8 * published by the Free Software Foundation;
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 * Event printing routines.
30 #include <lttv/lttv.h>
31 #include <lttv/option.h>
32 #include <lttv/module.h>
33 #include <lttv/hook.h>
34 #include <lttv/attribute.h>
35 #include <lttv/iattribute.h>
36 #include <lttv/stats.h>
37 #include <lttv/filter.h>
38 #include <lttv/print.h>
40 #include <ltt/event.h>
42 #include <ltt/trace.h>
43 #include <ltt/facility.h>
47 void lttv_print_field(LttEvent
*e
, LttField
*f
, GString
*s
,
48 gboolean field_names
) {
56 type
= ltt_field_type(f
);
57 switch(ltt_type_class(type
)) {
63 g_string_append_printf(s
, "%lld", ltt_event_get_long_int(e
,f
));
72 g_string_append_printf(s
, "%llu", ltt_event_get_long_unsigned(e
,f
));
76 g_string_append_printf(s
, "%c", ltt_event_get_int(e
,f
));
79 g_string_append_printf(s
, "%c", ltt_event_get_unsigned(e
,f
));
82 g_string_append_printf(s
, "%g", ltt_event_get_double(e
,f
));
86 g_string_append_printf(s
, "0x%llx", ltt_event_get_long_unsigned(e
,f
));
90 g_string_append_printf(s
, "\"%s\"", ltt_event_get_string(e
,f
));
95 GQuark value
= ltt_enum_string_get(type
, ltt_event_get_unsigned(e
,f
));
98 g_string_append_printf(s
, "%s", g_quark_to_string(value
));
100 g_string_append_printf(s
, "%lld", ltt_event_get_long_int(e
,f
));
106 g_string_append_printf(s
, "{ ");
107 nb
= ltt_event_field_element_number(e
,f
);
108 for(i
= 0 ; i
< nb
; i
++) {
109 LttField
*child
= ltt_event_field_element_select(e
,f
,i
);
110 lttv_print_field(e
, child
, s
, field_names
);
111 if(i
!= nb
-1) g_string_append_printf(s
, ", ");
113 g_string_append_printf(s
, " }");
117 g_string_append_printf(s
, "{ ");
118 nb
= ltt_type_member_number(type
);
119 for(i
= 0 ; i
< nb
; i
++) {
121 element
= ltt_field_member(f
,i
);
123 name
= ltt_field_name(element
);
124 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
126 lttv_print_field(e
, element
, s
, field_names
);
127 if(i
!= nb
-1) g_string_append_printf(s
, ", ");
129 g_string_append_printf(s
, " }");
133 g_string_append_printf(s
, "{ ");
134 nb
= ltt_type_member_number(type
);
135 for(i
= 0 ; i
< nb
; i
++) {
137 element
= ltt_field_member(f
,i
);
139 name
= ltt_field_name(element
);
140 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
142 lttv_print_field(e
, element
, s
, field_names
);
143 if(i
!= nb
-1) g_string_append_printf(s
, ", ");
145 g_string_append_printf(s
, " }");
153 void lttv_event_to_string(LttEvent
*e
, GString
*s
,
154 gboolean mandatory_fields
, gboolean field_names
, LttvTracefileState
*tfs
)
156 LttFacility
*facility
;
158 LttEventType
*event_type
;
164 guint cpu
= tfs
->cpu
;
165 LttvTraceState
*ts
= (LttvTraceState
*)tfs
->parent
.t_context
;
166 LttvProcessState
*process
= ts
->running_process
[cpu
];
172 g_string_set_size(s
,0);
174 facility
= ltt_event_facility(e
);
175 event_type
= ltt_event_eventtype(e
);
177 if(mandatory_fields
) {
178 time
= ltt_event_time(e
);
179 g_string_append_printf(s
,"%s.%s: %ld.%09ld (%s_%u)",
180 g_quark_to_string(ltt_facility_name(facility
)),
181 g_quark_to_string(ltt_eventtype_name(event_type
)),
182 (long)time
.tv_sec
, time
.tv_nsec
,
183 g_quark_to_string(ltt_tracefile_name(tfs
->parent
.tf
)),
185 /* Print the process id and the state/interrupt type of the process */
186 g_string_append_printf(s
,", %u, %u, %s", process
->pid
,
188 g_quark_to_string(process
->state
->t
));
190 event_type
= ltt_event_eventtype(e
);
192 num_fields
= ltt_eventtype_num_fields(event_type
);
193 if(num_fields
== 0) return;
194 g_string_append_printf(s
, " ");
195 g_string_append_printf(s
, "{ ");
196 for(i
=0; i
<num_fields
; i
++) {
197 field
= ltt_eventtype_field(event_type
, i
);
199 name
= ltt_field_name(field
);
201 g_string_append_printf(s
, "%s = ", g_quark_to_string(name
));
203 lttv_print_field(e
, field
, s
, field_names
);
204 if(i
!= num_fields
-1) g_string_append_printf(s
, ", ");
206 g_string_append_printf(s
, " }");
213 static void destroy()
217 LTTV_MODULE("print", "Print events", \
218 "Produce a detailed text printout of events", \