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 | * |
23 | * Event printing routines. */ |
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> |
40 | #include <ltt/type.h> |
41 | #include <ltt/trace.h> |
42 | #include <ltt/facility.h> |
43 | #include <stdio.h> |
44 | |
45 | |
46 | void lttv_print_field(LttEvent *e, LttField *f, GString *s, |
47 | gboolean field_names) { |
48 | |
49 | LttType *type; |
50 | |
51 | LttField *element; |
52 | |
53 | GQuark name; |
54 | |
55 | int nb, i; |
56 | |
57 | type = ltt_field_type(f); |
58 | switch(ltt_type_class(type)) { |
59 | case LTT_INT: |
60 | case LTT_LONG: |
61 | case LTT_SSIZE_T: |
62 | g_string_append_printf(s, " %lld", ltt_event_get_long_int(e,f)); |
63 | break; |
64 | |
65 | case LTT_UINT: |
66 | case LTT_ULONG: |
67 | case LTT_SIZE_T: |
68 | case LTT_OFF_T: |
69 | g_string_append_printf(s, " %llu", ltt_event_get_long_unsigned(e,f)); |
70 | break; |
71 | |
72 | case LTT_FLOAT: |
73 | g_string_append_printf(s, " %g", ltt_event_get_double(e,f)); |
74 | break; |
75 | |
76 | case LTT_POINTER: |
77 | g_string_append_printf(s, " 0x%llx", ltt_event_get_long_unsigned(e,f)); |
78 | break; |
79 | |
80 | case LTT_STRING: |
81 | g_string_append_printf(s, " \"%s\"", ltt_event_get_string(e,f)); |
82 | break; |
83 | |
84 | case LTT_ENUM: |
85 | g_string_append_printf(s, " %s", |
86 | g_quark_to_string(ltt_enum_string_get(type, |
87 | ltt_event_get_unsigned(e,f)-1))); |
88 | break; |
89 | |
90 | case LTT_ARRAY: |
91 | case LTT_SEQUENCE: |
92 | g_string_append_printf(s, " {"); |
93 | nb = ltt_event_field_element_number(e,f); |
94 | element = ltt_field_element(f); |
95 | for(i = 0 ; i < nb ; i++) { |
96 | ltt_event_field_element_select(e,f,i); |
97 | lttv_print_field(e, element, s, field_names); |
98 | } |
99 | g_string_append_printf(s, " }"); |
100 | break; |
101 | |
102 | case LTT_STRUCT: |
103 | g_string_append_printf(s, " {"); |
104 | nb = ltt_type_member_number(type); |
105 | for(i = 0 ; i < nb ; i++) { |
106 | element = ltt_field_member(f,i); |
107 | if(field_names) { |
108 | ltt_type_member_type(type, i, &name); |
109 | g_string_append_printf(s, " %s = ", g_quark_to_string(name)); |
110 | } |
111 | lttv_print_field(e, element, s, field_names); |
112 | } |
113 | g_string_append_printf(s, " }"); |
114 | break; |
115 | |
116 | case LTT_UNION: |
117 | g_string_append_printf(s, " {"); |
118 | nb = ltt_type_member_number(type); |
119 | for(i = 0 ; i < nb ; i++) { |
120 | element = ltt_field_member(f,i); |
121 | if(field_names) { |
122 | ltt_type_member_type(type, i, &name); |
123 | g_string_append_printf(s, " %s = ", g_quark_to_string(name)); |
124 | } |
125 | lttv_print_field(e, element, s, field_names); |
126 | } |
127 | g_string_append_printf(s, " }"); |
128 | break; |
129 | |
130 | } |
131 | } |
132 | |
133 | |
134 | void lttv_event_to_string(LttEvent *e, GString *s, |
135 | gboolean mandatory_fields, gboolean field_names, LttvTracefileState *tfs) |
136 | { |
137 | LttFacility *facility; |
138 | |
139 | LttEventType *event_type; |
140 | |
141 | LttField *field; |
142 | |
143 | LttTime time; |
144 | |
145 | guint cpu = ltt_tracefile_num(tfs->parent.tf); |
146 | LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; |
147 | LttvProcessState *process = ts->running_process[cpu]; |
148 | |
149 | g_string_set_size(s,0); |
150 | |
151 | facility = ltt_event_facility(e); |
152 | event_type = ltt_event_eventtype(e); |
153 | field = ltt_event_field(e); |
154 | |
155 | if(mandatory_fields) { |
156 | time = ltt_event_time(e); |
157 | g_string_append_printf(s,"%s.%s: %ld.%09ld (%s_%u)", |
158 | g_quark_to_string(ltt_facility_name(facility)), |
159 | g_quark_to_string(ltt_eventtype_name(event_type)), |
160 | (long)time.tv_sec, time.tv_nsec, |
161 | g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)), |
162 | cpu); |
163 | /* Print the process id and the state/interrupt type of the process */ |
164 | g_string_append_printf(s,", %u, %u, %s", process->pid, |
165 | process->ppid, |
166 | g_quark_to_string(process->state->t)); |
167 | } |
168 | |
169 | if(field) |
170 | lttv_print_field(e, field, s, field_names); |
171 | } |
172 | |
173 | static void init() |
174 | { |
175 | } |
176 | |
177 | static void destroy() |
178 | { |
179 | } |
180 | |
181 | LTTV_MODULE("print", "Print events", \ |
182 | "Produce a detailed text printout of events", \ |
183 | init, destroy) |
184 | |