8e680509 |
1 | |
2 | /* This file is part of the Linux Trace Toolkit viewer |
3 | * Copyright (C) 2003-2004 Michel Dagenais |
4 | * 2005 Mathieu Desnoyers |
5 | * |
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; |
9 | * |
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. |
14 | * |
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, |
18 | * MA 02111-1307, USA. |
19 | */ |
20 | |
21 | /* print.c |
22 | * |
5290ec02 |
23 | * Event printing routines. |
24 | */ |
8e680509 |
25 | |
26 | #ifdef HAVE_CONFIG_H |
27 | #include <config.h> |
28 | #endif |
29 | |
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> |
39 | #include <ltt/ltt.h> |
40 | #include <ltt/event.h> |
41 | #include <ltt/type.h> |
42 | #include <ltt/trace.h> |
43 | #include <ltt/facility.h> |
44 | #include <stdio.h> |
73e6c609 |
45 | #include <ctype.h> |
8e680509 |
46 | |
47 | void lttv_print_field(LttEvent *e, LttField *f, GString *s, |
73e6c609 |
48 | gboolean field_names, guint element_index) { |
8e680509 |
49 | |
50 | LttType *type; |
51 | |
8e680509 |
52 | GQuark name; |
53 | |
54 | int nb, i; |
55 | |
56 | type = ltt_field_type(f); |
57 | switch(ltt_type_class(type)) { |
1b960bd4 |
58 | case LTT_SHORT: |
8e680509 |
59 | case LTT_INT: |
60 | case LTT_LONG: |
61 | case LTT_SSIZE_T: |
1b960bd4 |
62 | case LTT_INT_FIXED: |
73e6c609 |
63 | if(element_index > 0) |
64 | g_string_append_printf(s, ", "); |
65 | if(field_names) { |
66 | name = ltt_field_name(f); |
67 | if(name) |
68 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
69 | } |
1b960bd4 |
70 | g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f)); |
8e680509 |
71 | break; |
72 | |
1b960bd4 |
73 | case LTT_USHORT: |
8e680509 |
74 | case LTT_UINT: |
75 | case LTT_ULONG: |
76 | case LTT_SIZE_T: |
77 | case LTT_OFF_T: |
1b960bd4 |
78 | case LTT_UINT_FIXED: |
73e6c609 |
79 | if(element_index > 0) |
80 | g_string_append_printf(s, ", "); |
81 | if(field_names) { |
82 | name = ltt_field_name(f); |
83 | if(name) |
84 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
85 | } |
1b960bd4 |
86 | g_string_append_printf(s, "%llu", ltt_event_get_long_unsigned(e,f)); |
87 | break; |
88 | |
89 | case LTT_CHAR: |
1b960bd4 |
90 | case LTT_UCHAR: |
73e6c609 |
91 | { |
92 | unsigned car = ltt_event_get_unsigned(e,f); |
93 | if(field_names) { |
94 | name = ltt_field_name(f); |
95 | if(name) |
96 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
97 | } |
98 | if(isprint(car)) { |
99 | if(field_names) { |
100 | name = ltt_field_name(f); |
101 | if(name) |
102 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
103 | } |
104 | g_string_append_printf(s, "%c", car); |
105 | } else { |
106 | g_string_append_printf(s, "\\%x", car); |
107 | } |
108 | } |
8e680509 |
109 | break; |
8e680509 |
110 | case LTT_FLOAT: |
73e6c609 |
111 | if(element_index > 0) |
112 | g_string_append_printf(s, ", "); |
113 | if(field_names) { |
114 | name = ltt_field_name(f); |
115 | if(name) |
116 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
117 | } |
1b960bd4 |
118 | g_string_append_printf(s, "%g", ltt_event_get_double(e,f)); |
8e680509 |
119 | break; |
120 | |
121 | case LTT_POINTER: |
73e6c609 |
122 | if(element_index > 0) |
123 | g_string_append_printf(s, ", "); |
124 | if(field_names) { |
125 | name = ltt_field_name(f); |
126 | if(name) |
127 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
128 | } |
1b960bd4 |
129 | g_string_append_printf(s, "0x%llx", ltt_event_get_long_unsigned(e,f)); |
8e680509 |
130 | break; |
131 | |
132 | case LTT_STRING: |
73e6c609 |
133 | if(element_index > 0) |
134 | g_string_append_printf(s, ", "); |
135 | if(field_names) { |
136 | name = ltt_field_name(f); |
137 | if(name) |
138 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
139 | } |
1b960bd4 |
140 | g_string_append_printf(s, "\"%s\"", ltt_event_get_string(e,f)); |
8e680509 |
141 | break; |
142 | |
143 | case LTT_ENUM: |
1b960bd4 |
144 | { |
145 | GQuark value = ltt_enum_string_get(type, ltt_event_get_unsigned(e,f)); |
146 | |
73e6c609 |
147 | if(element_index > 0) |
148 | g_string_append_printf(s, ", "); |
149 | if(field_names) { |
150 | name = ltt_field_name(f); |
151 | if(name) |
152 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
153 | } |
1b960bd4 |
154 | if(value) |
155 | g_string_append_printf(s, "%s", g_quark_to_string(value)); |
156 | else |
157 | g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f)); |
158 | } |
8e680509 |
159 | break; |
160 | |
161 | case LTT_ARRAY: |
162 | case LTT_SEQUENCE: |
73e6c609 |
163 | if(element_index > 0) |
164 | g_string_append_printf(s, ", "); |
165 | if(field_names) { |
166 | name = ltt_field_name(f); |
167 | if(name) |
168 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
169 | } |
1b960bd4 |
170 | g_string_append_printf(s, "{ "); |
8e680509 |
171 | nb = ltt_event_field_element_number(e,f); |
8e680509 |
172 | for(i = 0 ; i < nb ; i++) { |
2312de30 |
173 | LttField *child = ltt_event_field_element_select(e,f,i); |
73e6c609 |
174 | lttv_print_field(e, child, s, field_names, i); |
8e680509 |
175 | } |
176 | g_string_append_printf(s, " }"); |
177 | break; |
178 | |
179 | case LTT_STRUCT: |
73e6c609 |
180 | if(element_index > 0) |
181 | g_string_append_printf(s, ", "); |
182 | if(field_names) { |
183 | name = ltt_field_name(f); |
184 | if(name) |
185 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
186 | } |
1b960bd4 |
187 | g_string_append_printf(s, "{ "); |
8e680509 |
188 | nb = ltt_type_member_number(type); |
189 | for(i = 0 ; i < nb ; i++) { |
2312de30 |
190 | LttField *element; |
8e680509 |
191 | element = ltt_field_member(f,i); |
73e6c609 |
192 | lttv_print_field(e, element, s, field_names, i); |
8e680509 |
193 | } |
194 | g_string_append_printf(s, " }"); |
195 | break; |
196 | |
197 | case LTT_UNION: |
73e6c609 |
198 | if(element_index > 0) |
199 | g_string_append_printf(s, ", "); |
200 | if(field_names) { |
201 | name = ltt_field_name(f); |
202 | if(name) |
203 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); |
204 | } |
1b960bd4 |
205 | g_string_append_printf(s, "{ "); |
8e680509 |
206 | nb = ltt_type_member_number(type); |
207 | for(i = 0 ; i < nb ; i++) { |
2312de30 |
208 | LttField *element; |
8e680509 |
209 | element = ltt_field_member(f,i); |
73e6c609 |
210 | lttv_print_field(e, element, s, field_names, i); |
8e680509 |
211 | } |
212 | g_string_append_printf(s, " }"); |
213 | break; |
2312de30 |
214 | case LTT_NONE: |
215 | break; |
8e680509 |
216 | } |
217 | } |
218 | |
219 | |
220 | void lttv_event_to_string(LttEvent *e, GString *s, |
221 | gboolean mandatory_fields, gboolean field_names, LttvTracefileState *tfs) |
222 | { |
223 | LttFacility *facility; |
224 | |
225 | LttEventType *event_type; |
226 | |
227 | LttField *field; |
228 | |
229 | LttTime time; |
230 | |
ae3d0f50 |
231 | guint cpu = tfs->cpu; |
8e680509 |
232 | LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; |
233 | LttvProcessState *process = ts->running_process[cpu]; |
234 | |
2312de30 |
235 | GQuark name; |
236 | |
76373d36 |
237 | guint i, num_fields; |
238 | |
0292757b |
239 | s = g_string_set_size(s,0); |
8e680509 |
240 | |
241 | facility = ltt_event_facility(e); |
242 | event_type = ltt_event_eventtype(e); |
8e680509 |
243 | |
244 | if(mandatory_fields) { |
245 | time = ltt_event_time(e); |
246 | g_string_append_printf(s,"%s.%s: %ld.%09ld (%s_%u)", |
247 | g_quark_to_string(ltt_facility_name(facility)), |
248 | g_quark_to_string(ltt_eventtype_name(event_type)), |
249 | (long)time.tv_sec, time.tv_nsec, |
250 | g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)), |
251 | cpu); |
252 | /* Print the process id and the state/interrupt type of the process */ |
fcc08e1e |
253 | g_string_append_printf(s,", %u, %u, %s, %s, %u, 0x%llX, %s", process->pid, |
254 | process->tgid, |
73e6c609 |
255 | g_quark_to_string(process->name), |
7b5f6cf1 |
256 | g_quark_to_string(process->brand), |
73e6c609 |
257 | process->ppid, process->current_function, |
258 | g_quark_to_string(process->state->t)); |
8e680509 |
259 | } |
41b471e6 |
260 | event_type = ltt_event_eventtype(e); |
76373d36 |
261 | |
41b471e6 |
262 | num_fields = ltt_eventtype_num_fields(event_type); |
743e50fd |
263 | if(num_fields == 0) return; |
264 | g_string_append_printf(s, " "); |
265 | g_string_append_printf(s, "{ "); |
76373d36 |
266 | for(i=0; i<num_fields; i++) { |
2312de30 |
267 | field = ltt_eventtype_field(event_type, i); |
73e6c609 |
268 | lttv_print_field(e, field, s, field_names, i); |
76373d36 |
269 | } |
743e50fd |
270 | g_string_append_printf(s, " }"); |
8e680509 |
271 | } |
272 | |
273 | static void init() |
274 | { |
275 | } |
276 | |
277 | static void destroy() |
278 | { |
279 | } |
280 | |
281 | LTTV_MODULE("print", "Print events", \ |
73e6c609 |
282 | "Produce a detailed text printout of events", \ |
283 | init, destroy) |
8e680509 |
284 | |