custom
[lttv.git] / ltt / branches / poly / lttv / lttv / print.c
CommitLineData
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>
45
46
47void lttv_print_field(LttEvent *e, LttField *f, GString *s,
48 gboolean field_names) {
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:
63 g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f));
8e680509 64 break;
65
1b960bd4 66 case LTT_USHORT:
8e680509 67 case LTT_UINT:
68 case LTT_ULONG:
69 case LTT_SIZE_T:
70 case LTT_OFF_T:
1b960bd4 71 case LTT_UINT_FIXED:
72 g_string_append_printf(s, "%llu", ltt_event_get_long_unsigned(e,f));
73 break;
74
75 case LTT_CHAR:
76 g_string_append_printf(s, "%c", ltt_event_get_int(e,f));
77 break;
78 case LTT_UCHAR:
79 g_string_append_printf(s, "%c", ltt_event_get_unsigned(e,f));
8e680509 80 break;
8e680509 81 case LTT_FLOAT:
1b960bd4 82 g_string_append_printf(s, "%g", ltt_event_get_double(e,f));
8e680509 83 break;
84
85 case LTT_POINTER:
1b960bd4 86 g_string_append_printf(s, "0x%llx", ltt_event_get_long_unsigned(e,f));
8e680509 87 break;
88
89 case LTT_STRING:
1b960bd4 90 g_string_append_printf(s, "\"%s\"", ltt_event_get_string(e,f));
8e680509 91 break;
92
93 case LTT_ENUM:
1b960bd4 94 {
95 GQuark value = ltt_enum_string_get(type, ltt_event_get_unsigned(e,f));
96
97 if(value)
98 g_string_append_printf(s, "%s", g_quark_to_string(value));
99 else
100 g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f));
101 }
8e680509 102 break;
103
104 case LTT_ARRAY:
105 case LTT_SEQUENCE:
1b960bd4 106 g_string_append_printf(s, "{ ");
8e680509 107 nb = ltt_event_field_element_number(e,f);
8e680509 108 for(i = 0 ; i < nb ; i++) {
2312de30 109 LttField *child = ltt_event_field_element_select(e,f,i);
110 lttv_print_field(e, child, s, field_names);
1b960bd4 111 if(i != nb-1) g_string_append_printf(s, ", ");
8e680509 112 }
113 g_string_append_printf(s, " }");
114 break;
115
116 case LTT_STRUCT:
1b960bd4 117 g_string_append_printf(s, "{ ");
8e680509 118 nb = ltt_type_member_number(type);
119 for(i = 0 ; i < nb ; i++) {
2312de30 120 LttField *element;
8e680509 121 element = ltt_field_member(f,i);
122 if(field_names) {
2312de30 123 name = ltt_field_name(element);
1b960bd4 124 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
8e680509 125 }
126 lttv_print_field(e, element, s, field_names);
1b960bd4 127 if(i != nb-1) g_string_append_printf(s, ", ");
8e680509 128 }
129 g_string_append_printf(s, " }");
130 break;
131
132 case LTT_UNION:
1b960bd4 133 g_string_append_printf(s, "{ ");
8e680509 134 nb = ltt_type_member_number(type);
135 for(i = 0 ; i < nb ; i++) {
2312de30 136 LttField *element;
8e680509 137 element = ltt_field_member(f,i);
138 if(field_names) {
2312de30 139 name = ltt_field_name(element);
1b960bd4 140 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
8e680509 141 }
142 lttv_print_field(e, element, s, field_names);
1b960bd4 143 if(i != nb-1) g_string_append_printf(s, ", ");
8e680509 144 }
145 g_string_append_printf(s, " }");
146 break;
2312de30 147 case LTT_NONE:
148 break;
8e680509 149 }
150}
151
152
153void lttv_event_to_string(LttEvent *e, GString *s,
154 gboolean mandatory_fields, gboolean field_names, LttvTracefileState *tfs)
155{
156 LttFacility *facility;
157
158 LttEventType *event_type;
159
160 LttField *field;
161
162 LttTime time;
163
ae3d0f50 164 guint cpu = tfs->cpu;
8e680509 165 LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context;
166 LttvProcessState *process = ts->running_process[cpu];
167
2312de30 168 GQuark name;
169
76373d36 170 guint i, num_fields;
171
8e680509 172 g_string_set_size(s,0);
173
174 facility = ltt_event_facility(e);
175 event_type = ltt_event_eventtype(e);
8e680509 176
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)),
184 cpu);
185 /* Print the process id and the state/interrupt type of the process */
ab45fb16 186 g_string_append_printf(s,", %u, %s, %u, 0x%llX, %s", process->pid,
187 g_quark_to_string(process->name),
61716b3e 188 process->ppid, process->current_function,
8e680509 189 g_quark_to_string(process->state->t));
190 }
41b471e6 191 event_type = ltt_event_eventtype(e);
76373d36 192
41b471e6 193 num_fields = ltt_eventtype_num_fields(event_type);
743e50fd 194 if(num_fields == 0) return;
195 g_string_append_printf(s, " ");
196 g_string_append_printf(s, "{ ");
76373d36 197 for(i=0; i<num_fields; i++) {
2312de30 198 field = ltt_eventtype_field(event_type, i);
199 if(field_names) {
200 name = ltt_field_name(field);
201 if(name)
202 g_string_append_printf(s, "%s = ", g_quark_to_string(name));
203 }
8e680509 204 lttv_print_field(e, field, s, field_names);
743e50fd 205 if(i != num_fields-1) g_string_append_printf(s, ", ");
76373d36 206 }
743e50fd 207 g_string_append_printf(s, " }");
8e680509 208}
209
210static void init()
211{
212}
213
214static void destroy()
215{
216}
217
218LTTV_MODULE("print", "Print events", \
219 "Produce a detailed text printout of events", \
220 init, destroy)
221
This page took 0.040376 seconds and 4 git commands to generate.