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