Commit | Line | Data |
---|---|---|
8e680509 | 1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Michel Dagenais | |
3 | * 2005 Mathieu Desnoyers | |
4 | * | |
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; | |
8 | * | |
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. | |
13 | * | |
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, | |
17 | * MA 02111-1307, USA. | |
18 | */ | |
19 | ||
20 | /* print.c | |
21 | * | |
5290ec02 | 22 | * Event printing routines. |
23 | */ | |
8e680509 | 24 | |
25 | #ifdef HAVE_CONFIG_H | |
26 | #include <config.h> | |
27 | #endif | |
28 | ||
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> | |
38 | #include <ltt/ltt.h> | |
39 | #include <ltt/event.h> | |
8e680509 | 40 | #include <ltt/trace.h> |
8e680509 | 41 | #include <stdio.h> |
73e6c609 | 42 | #include <ctype.h> |
95868736 | 43 | #include <ltt/ltt-private.h> |
e8548639 | 44 | #include <string.h> |
43ed82b5 | 45 | #include <inttypes.h> |
e8548639 | 46 | |
cf453ac7 | 47 | static inline void print_enum_events(LttEvent *e, struct marker_field *f, |
48 | guint64 value, GString *s, LttvTracefileState *tfs) | |
49 | { | |
3e88e9ce | 50 | LttTracefile *tf = tfs->parent.tf; |
51 | struct marker_info *info = marker_get_info_from_id(tf->mdata, e->event_id); | |
cf453ac7 | 52 | LttvTraceState *ts = (LttvTraceState*)(tfs->parent.t_context); |
1cd9058f | 53 | LttvNameTables *nt = ts->name_tables; |
cf453ac7 | 54 | |
4858a3ed | 55 | if (tf->name == LTT_CHANNEL_KERNEL) { |
56 | if (info->name == LTT_EVENT_SYSCALL_ENTRY | |
57 | && f->name == LTT_FIELD_SYSCALL_ID) { | |
58 | g_string_append_printf(s, " [%s]", | |
1cd9058f | 59 | g_quark_to_string(nt->syscall_names[value])); |
4858a3ed | 60 | } else if ((info->name == LTT_EVENT_SOFT_IRQ_ENTRY |
61 | || info->name == LTT_EVENT_SOFT_IRQ_EXIT | |
62 | || info->name == LTT_EVENT_SOFT_IRQ_RAISE) | |
63 | && f->name == LTT_FIELD_SOFT_IRQ_ID) { | |
64 | g_string_append_printf(s, " [%s]", | |
1cd9058f | 65 | g_quark_to_string(nt->soft_irq_names[value])); |
2d0d580c | 66 | } else if (info->name == LTT_EVENT_KPROBE |
67 | && f->name == LTT_FIELD_IP) { | |
e9a5b514 | 68 | #if (__WORDSIZE == 32) |
1cd9058f | 69 | GQuark symbol = (GQuark)g_hash_table_lookup(nt->kprobe_hash, |
9ee1ff6a | 70 | (gconstpointer)&value); |
71 | #else | |
1cd9058f | 72 | GQuark symbol = (GQuark)g_hash_table_lookup(nt->kprobe_hash, |
2d0d580c | 73 | (gconstpointer)value); |
9ee1ff6a | 74 | #endif |
2d0d580c | 75 | if (symbol) |
76 | g_string_append_printf(s, " [%s]", g_quark_to_string(symbol)); | |
4858a3ed | 77 | } |
cf453ac7 | 78 | } |
79 | } | |
8e680509 | 80 | |
95868736 | 81 | void lttv_print_field(LttEvent *e, struct marker_field *f, GString *s, |
cf453ac7 | 82 | gboolean field_names, LttvTracefileState *tfs) |
95868736 | 83 | { |
8e680509 | 84 | GQuark name; |
cf453ac7 | 85 | guint64 value; |
8e680509 | 86 | |
95868736 | 87 | //int nb, i; |
8e680509 | 88 | |
95868736 | 89 | switch(f->type) { |
90 | case LTT_TYPE_SIGNED_INT: | |
73e6c609 | 91 | if(field_names) { |
95868736 | 92 | name = f->name; |
73e6c609 | 93 | if(name) |
94 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); | |
95 | } | |
cf453ac7 | 96 | value = ltt_event_get_long_int(e,f); |
4d683428 | 97 | //g_string_append_printf(s, "%lld", value); |
98 | g_string_append_printf(s, f->fmt->str, value); | |
95868736 | 99 | //g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f)); |
cf453ac7 | 100 | print_enum_events(e, f, value, s, tfs); |
95868736 | 101 | break; |
8e680509 | 102 | |
95868736 | 103 | case LTT_TYPE_UNSIGNED_INT: |
73e6c609 | 104 | if(field_names) { |
95868736 | 105 | name = f->name; |
73e6c609 | 106 | if(name) |
107 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); | |
108 | } | |
cf453ac7 | 109 | value = ltt_event_get_long_unsigned(e,f); |
4d683428 | 110 | //g_string_append_printf(s, "%llu", value); |
111 | g_string_append_printf(s, f->fmt->str, value); | |
cf453ac7 | 112 | print_enum_events(e, f, value, s, tfs); |
95868736 | 113 | //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f)); |
1b960bd4 | 114 | break; |
115 | ||
95868736 | 116 | #if 0 |
1b960bd4 | 117 | case LTT_CHAR: |
1b960bd4 | 118 | case LTT_UCHAR: |
73e6c609 | 119 | { |
120 | unsigned car = ltt_event_get_unsigned(e,f); | |
121 | if(field_names) { | |
122 | name = ltt_field_name(f); | |
123 | if(name) | |
124 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); | |
125 | } | |
126 | if(isprint(car)) { | |
127 | if(field_names) { | |
128 | name = ltt_field_name(f); | |
129 | if(name) | |
130 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); | |
131 | } | |
e8548639 | 132 | //g_string_append_printf(s, "%c", car); |
133 | g_string_append_printf(s, type->fmt, car); | |
73e6c609 | 134 | } else { |
135 | g_string_append_printf(s, "\\%x", car); | |
136 | } | |
137 | } | |
8e680509 | 138 | break; |
8e680509 | 139 | case LTT_FLOAT: |
e8548639 | 140 | if(field_names) { |
73e6c609 | 141 | name = ltt_field_name(f); |
142 | if(name) | |
143 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); | |
144 | } | |
e8548639 | 145 | //g_string_append_printf(s, "%g", ltt_event_get_double(e,f)); |
146 | g_string_append_printf(s, type->fmt, ltt_event_get_double(e,f)); | |
8e680509 | 147 | break; |
91346f59 | 148 | #endif |
8e680509 | 149 | |
91346f59 | 150 | case LTT_TYPE_POINTER: |
73e6c609 | 151 | if(field_names) { |
91346f59 | 152 | name = f->name; |
73e6c609 | 153 | if(name) |
154 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); | |
155 | } | |
43ed82b5 | 156 | g_string_append_printf(s, "0x%" PRIx64, ltt_event_get_long_unsigned(e,f)); |
91346f59 | 157 | //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f)); |
8e680509 | 158 | break; |
159 | ||
95868736 | 160 | case LTT_TYPE_STRING: |
73e6c609 | 161 | if(field_names) { |
95868736 | 162 | name = f->name; |
73e6c609 | 163 | if(name) |
164 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); | |
165 | } | |
1b960bd4 | 166 | g_string_append_printf(s, "\"%s\"", ltt_event_get_string(e,f)); |
8e680509 | 167 | break; |
168 | ||
95868736 | 169 | #if 0 |
8e680509 | 170 | case LTT_ENUM: |
1b960bd4 | 171 | { |
172 | GQuark value = ltt_enum_string_get(type, ltt_event_get_unsigned(e,f)); | |
73e6c609 | 173 | if(field_names) { |
174 | name = ltt_field_name(f); | |
175 | if(name) | |
176 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); | |
177 | } | |
1b960bd4 | 178 | if(value) |
179 | g_string_append_printf(s, "%s", g_quark_to_string(value)); | |
180 | else | |
181 | g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f)); | |
182 | } | |
8e680509 | 183 | break; |
184 | ||
185 | case LTT_ARRAY: | |
186 | case LTT_SEQUENCE: | |
73e6c609 | 187 | if(field_names) { |
188 | name = ltt_field_name(f); | |
189 | if(name) | |
190 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); | |
191 | } | |
e8548639 | 192 | // g_string_append_printf(s, "{ "); |
193 | //Insert header | |
194 | g_string_append_printf(s, type->header);//tested, works fine. | |
195 | ||
196 | ||
8e680509 | 197 | nb = ltt_event_field_element_number(e,f); |
8e680509 | 198 | for(i = 0 ; i < nb ; i++) { |
2312de30 | 199 | LttField *child = ltt_event_field_element_select(e,f,i); |
73e6c609 | 200 | lttv_print_field(e, child, s, field_names, i); |
e8548639 | 201 | if(i<nb-1) |
202 | g_string_append_printf(s,type->separator); | |
8e680509 | 203 | } |
e8548639 | 204 | //g_string_append_printf(s, " }"); |
205 | //Insert footer | |
206 | g_string_append_printf(s, type->footer);//tested, works fine. | |
8e680509 | 207 | break; |
208 | ||
209 | case LTT_STRUCT: | |
73e6c609 | 210 | if(field_names) { |
211 | name = ltt_field_name(f); | |
212 | if(name) | |
213 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); | |
214 | } | |
e8548639 | 215 | // g_string_append_printf(s, "{ "); |
216 | //Insert header | |
217 | g_string_append_printf(s, type->header); | |
218 | ||
8e680509 | 219 | nb = ltt_type_member_number(type); |
220 | for(i = 0 ; i < nb ; i++) { | |
2312de30 | 221 | LttField *element; |
8e680509 | 222 | element = ltt_field_member(f,i); |
73e6c609 | 223 | lttv_print_field(e, element, s, field_names, i); |
e8548639 | 224 | if(i < nb-1) |
225 | g_string_append_printf(s,type->separator); | |
8e680509 | 226 | } |
e8548639 | 227 | //g_string_append_printf(s, " }"); |
228 | //Insert footer | |
229 | g_string_append_printf(s, type->footer); | |
8e680509 | 230 | break; |
231 | ||
232 | case LTT_UNION: | |
73e6c609 | 233 | if(field_names) { |
234 | name = ltt_field_name(f); | |
235 | if(name) | |
236 | g_string_append_printf(s, "%s = ", g_quark_to_string(name)); | |
237 | } | |
e8548639 | 238 | // g_string_append_printf(s, "{ "); |
239 | g_string_append_printf(s, type->header); | |
240 | ||
8e680509 | 241 | nb = ltt_type_member_number(type); |
242 | for(i = 0 ; i < nb ; i++) { | |
2312de30 | 243 | LttField *element; |
8e680509 | 244 | element = ltt_field_member(f,i); |
73e6c609 | 245 | lttv_print_field(e, element, s, field_names, i); |
e8548639 | 246 | if(i<nb-1) |
247 | g_string_append_printf(s, type->separator); | |
8e680509 | 248 | } |
e8548639 | 249 | // g_string_append_printf(s, " }"); |
250 | g_string_append_printf(s, type->footer); | |
8e680509 | 251 | break; |
95868736 | 252 | #endif |
253 | case LTT_TYPE_COMPACT: | |
5d87b1b7 | 254 | g_error("compact type printing not implemented"); |
255 | break; | |
95868736 | 256 | case LTT_TYPE_NONE: |
2312de30 | 257 | break; |
8e680509 | 258 | } |
259 | } | |
260 | ||
8e680509 | 261 | void lttv_event_to_string(LttEvent *e, GString *s, |
262 | gboolean mandatory_fields, gboolean field_names, LttvTracefileState *tfs) | |
263 | { | |
95868736 | 264 | struct marker_field *field; |
265 | struct marker_info *info; | |
8e680509 | 266 | |
267 | LttTime time; | |
268 | ||
ae3d0f50 | 269 | guint cpu = tfs->cpu; |
8e680509 | 270 | LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; |
271 | LttvProcessState *process = ts->running_process[cpu]; | |
76373d36 | 272 | |
0292757b | 273 | s = g_string_set_size(s,0); |
8e680509 | 274 | |
750eb11a | 275 | info = marker_get_info_from_id(tfs->parent.tf->mdata, e->event_id); |
8e680509 | 276 | |
277 | if(mandatory_fields) { | |
278 | time = ltt_event_time(e); | |
6471e71f | 279 | g_string_append_printf(s,"%s.%s: %ld.%09ld (%s/%s_%u)", |
14bc9b7c BP |
280 | g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)), |
281 | g_quark_to_string(info->name), (long)time.tv_sec, time.tv_nsec, | |
282 | g_quark_to_string( | |
283 | ltt_trace_name(ltt_tracefile_get_trace(tfs->parent.tf))), | |
284 | g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)), cpu); | |
8e680509 | 285 | /* Print the process id and the state/interrupt type of the process */ |
43ed82b5 | 286 | g_string_append_printf(s,", %u, %u, %s, %s, %u, 0x%" PRIx64", %s", |
14bc9b7c BP |
287 | process->pid, |
288 | process->tgid, | |
289 | g_quark_to_string(process->name), | |
290 | g_quark_to_string(process->brand), | |
291 | process->ppid, | |
292 | process->current_function, | |
293 | g_quark_to_string(process->state->t)); | |
8e680509 | 294 | } |
76373d36 | 295 | |
95868736 | 296 | if(marker_get_num_fields(info) == 0) return; |
743e50fd | 297 | g_string_append_printf(s, " "); |
298 | g_string_append_printf(s, "{ "); | |
95868736 | 299 | for (field = marker_get_field(info, 0); |
300 | field != marker_get_field(info, marker_get_num_fields(info)); | |
301 | field++) { | |
302 | if(field != marker_get_field(info, 0)) | |
303 | g_string_append_printf(s, ", "); | |
cf453ac7 | 304 | lttv_print_field(e, field, s, field_names, tfs); |
76373d36 | 305 | } |
743e50fd | 306 | g_string_append_printf(s, " }"); |
8e680509 | 307 | } |
308 | ||
309 | static void init() | |
310 | { | |
311 | } | |
312 | ||
313 | static void destroy() | |
314 | { | |
315 | } | |
316 | ||
317 | LTTV_MODULE("print", "Print events", \ | |
73e6c609 | 318 | "Produce a detailed text printout of events", \ |
319 | init, destroy) | |
8e680509 | 320 |