remove files unneeded for lttv
[lttv.git] / lttv / lttv / lttv / print.c
CommitLineData
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 47static 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);
53
4858a3ed 54 if (tf->name == LTT_CHANNEL_KERNEL) {
55 if (info->name == LTT_EVENT_SYSCALL_ENTRY
56 && f->name == LTT_FIELD_SYSCALL_ID) {
57 g_string_append_printf(s, " [%s]",
58 g_quark_to_string(ts->syscall_names[value]));
59 } else if ((info->name == LTT_EVENT_SOFT_IRQ_ENTRY
60 || info->name == LTT_EVENT_SOFT_IRQ_EXIT
61 || info->name == LTT_EVENT_SOFT_IRQ_RAISE)
62 && f->name == LTT_FIELD_SOFT_IRQ_ID) {
63 g_string_append_printf(s, " [%s]",
64 g_quark_to_string(ts->soft_irq_names[value]));
2d0d580c 65 } else if (info->name == LTT_EVENT_KPROBE
66 && f->name == LTT_FIELD_IP) {
9ee1ff6a 67#if (__SIZEOF_LONG__ == 4)
68 GQuark symbol = (GQuark)g_hash_table_lookup(ts->kprobe_hash,
69 (gconstpointer)&value);
70#else
71 GQuark symbol = (GQuark)g_hash_table_lookup(ts->kprobe_hash,
2d0d580c 72 (gconstpointer)value);
9ee1ff6a 73#endif
2d0d580c 74 if (symbol)
75 g_string_append_printf(s, " [%s]", g_quark_to_string(symbol));
4858a3ed 76 }
cf453ac7 77 }
78}
8e680509 79
95868736 80void lttv_print_field(LttEvent *e, struct marker_field *f, GString *s,
cf453ac7 81 gboolean field_names, LttvTracefileState *tfs)
95868736 82{
8e680509 83 GQuark name;
cf453ac7 84 guint64 value;
8e680509 85
95868736 86 //int nb, i;
8e680509 87
95868736 88 switch(f->type) {
89 case LTT_TYPE_SIGNED_INT:
73e6c609 90 if(field_names) {
95868736 91 name = f->name;
73e6c609 92 if(name)
93 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
94 }
cf453ac7 95 value = ltt_event_get_long_int(e,f);
4d683428 96 //g_string_append_printf(s, "%lld", value);
97 g_string_append_printf(s, f->fmt->str, value);
95868736 98 //g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f));
cf453ac7 99 print_enum_events(e, f, value, s, tfs);
95868736 100 break;
8e680509 101
95868736 102 case LTT_TYPE_UNSIGNED_INT:
73e6c609 103 if(field_names) {
95868736 104 name = f->name;
73e6c609 105 if(name)
106 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
107 }
cf453ac7 108 value = ltt_event_get_long_unsigned(e,f);
4d683428 109 //g_string_append_printf(s, "%llu", value);
110 g_string_append_printf(s, f->fmt->str, value);
cf453ac7 111 print_enum_events(e, f, value, s, tfs);
95868736 112 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
1b960bd4 113 break;
114
95868736 115#if 0
1b960bd4 116 case LTT_CHAR:
1b960bd4 117 case LTT_UCHAR:
73e6c609 118 {
119 unsigned car = ltt_event_get_unsigned(e,f);
120 if(field_names) {
121 name = ltt_field_name(f);
122 if(name)
123 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
124 }
125 if(isprint(car)) {
126 if(field_names) {
127 name = ltt_field_name(f);
128 if(name)
129 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
130 }
e8548639 131 //g_string_append_printf(s, "%c", car);
132 g_string_append_printf(s, type->fmt, car);
73e6c609 133 } else {
134 g_string_append_printf(s, "\\%x", car);
135 }
136 }
8e680509 137 break;
8e680509 138 case LTT_FLOAT:
e8548639 139 if(field_names) {
73e6c609 140 name = ltt_field_name(f);
141 if(name)
142 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
143 }
e8548639 144 //g_string_append_printf(s, "%g", ltt_event_get_double(e,f));
145 g_string_append_printf(s, type->fmt, ltt_event_get_double(e,f));
8e680509 146 break;
91346f59 147#endif
8e680509 148
91346f59 149 case LTT_TYPE_POINTER:
73e6c609 150 if(field_names) {
91346f59 151 name = f->name;
73e6c609 152 if(name)
153 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
154 }
43ed82b5 155 g_string_append_printf(s, "0x%" PRIx64, ltt_event_get_long_unsigned(e,f));
91346f59 156 //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f));
8e680509 157 break;
158
95868736 159 case LTT_TYPE_STRING:
73e6c609 160 if(field_names) {
95868736 161 name = f->name;
73e6c609 162 if(name)
163 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
164 }
1b960bd4 165 g_string_append_printf(s, "\"%s\"", ltt_event_get_string(e,f));
8e680509 166 break;
167
95868736 168#if 0
8e680509 169 case LTT_ENUM:
1b960bd4 170 {
171 GQuark value = ltt_enum_string_get(type, ltt_event_get_unsigned(e,f));
73e6c609 172 if(field_names) {
173 name = ltt_field_name(f);
174 if(name)
175 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
176 }
1b960bd4 177 if(value)
178 g_string_append_printf(s, "%s", g_quark_to_string(value));
179 else
180 g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f));
181 }
8e680509 182 break;
183
184 case LTT_ARRAY:
185 case LTT_SEQUENCE:
73e6c609 186 if(field_names) {
187 name = ltt_field_name(f);
188 if(name)
189 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
190 }
e8548639 191 // g_string_append_printf(s, "{ ");
192 //Insert header
193 g_string_append_printf(s, type->header);//tested, works fine.
194
195
8e680509 196 nb = ltt_event_field_element_number(e,f);
8e680509 197 for(i = 0 ; i < nb ; i++) {
2312de30 198 LttField *child = ltt_event_field_element_select(e,f,i);
73e6c609 199 lttv_print_field(e, child, s, field_names, i);
e8548639 200 if(i<nb-1)
201 g_string_append_printf(s,type->separator);
8e680509 202 }
e8548639 203 //g_string_append_printf(s, " }");
204 //Insert footer
205 g_string_append_printf(s, type->footer);//tested, works fine.
8e680509 206 break;
207
208 case LTT_STRUCT:
73e6c609 209 if(field_names) {
210 name = ltt_field_name(f);
211 if(name)
212 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
213 }
e8548639 214 // g_string_append_printf(s, "{ ");
215 //Insert header
216 g_string_append_printf(s, type->header);
217
8e680509 218 nb = ltt_type_member_number(type);
219 for(i = 0 ; i < nb ; i++) {
2312de30 220 LttField *element;
8e680509 221 element = ltt_field_member(f,i);
73e6c609 222 lttv_print_field(e, element, s, field_names, i);
e8548639 223 if(i < nb-1)
224 g_string_append_printf(s,type->separator);
8e680509 225 }
e8548639 226 //g_string_append_printf(s, " }");
227 //Insert footer
228 g_string_append_printf(s, type->footer);
8e680509 229 break;
230
231 case LTT_UNION:
73e6c609 232 if(field_names) {
233 name = ltt_field_name(f);
234 if(name)
235 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
236 }
e8548639 237 // g_string_append_printf(s, "{ ");
238 g_string_append_printf(s, type->header);
239
8e680509 240 nb = ltt_type_member_number(type);
241 for(i = 0 ; i < nb ; i++) {
2312de30 242 LttField *element;
8e680509 243 element = ltt_field_member(f,i);
73e6c609 244 lttv_print_field(e, element, s, field_names, i);
e8548639 245 if(i<nb-1)
246 g_string_append_printf(s, type->separator);
8e680509 247 }
e8548639 248 // g_string_append_printf(s, " }");
249 g_string_append_printf(s, type->footer);
8e680509 250 break;
95868736 251#endif
252 case LTT_TYPE_COMPACT:
5d87b1b7 253 g_error("compact type printing not implemented");
254 break;
95868736 255 case LTT_TYPE_NONE:
2312de30 256 break;
8e680509 257 }
258}
259
8e680509 260void lttv_event_to_string(LttEvent *e, GString *s,
261 gboolean mandatory_fields, gboolean field_names, LttvTracefileState *tfs)
262{
95868736 263 struct marker_field *field;
264 struct marker_info *info;
8e680509 265
266 LttTime time;
267
ae3d0f50 268 guint cpu = tfs->cpu;
8e680509 269 LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context;
270 LttvProcessState *process = ts->running_process[cpu];
76373d36 271
0292757b 272 s = g_string_set_size(s,0);
8e680509 273
750eb11a 274 info = marker_get_info_from_id(tfs->parent.tf->mdata, e->event_id);
8e680509 275
276 if(mandatory_fields) {
277 time = ltt_event_time(e);
6471e71f 278 g_string_append_printf(s,"%s.%s: %ld.%09ld (%s/%s_%u)",
279 g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)),
95868736 280 g_quark_to_string(info->name),
8e680509 281 (long)time.tv_sec, time.tv_nsec,
d41c66bf 282 g_quark_to_string(
283 ltt_trace_name(ltt_tracefile_get_trace(tfs->parent.tf))),
8e680509 284 g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)),
285 cpu);
286 /* Print the process id and the state/interrupt type of the process */
43ed82b5 287 g_string_append_printf(s,", %u, %u, %s, %s, %u, 0x%" PRIx64", %s",
288 process->pid,
289 process->tgid,
290 g_quark_to_string(process->name),
291 g_quark_to_string(process->brand),
292 process->ppid, 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
309static void init()
310{
311}
312
313static void destroy()
314{
315}
316
317LTTV_MODULE("print", "Print events", \
73e6c609 318 "Produce a detailed text printout of events", \
319 init, destroy)
8e680509 320
This page took 0.061436 seconds and 4 git commands to generate.