exclude sample modules from compiling.
[lttv.git] / ltt / branches / poly / lttv / textDump.c
... / ...
CommitLineData
1/* The text dump facility needs to print headers before the trace set and
2 before each trace, to print each event, and to print statistics
3 after each trace. */
4
5static gboolean
6 a_field_names,
7 a_state;
8
9static char
10 *a_file_name;
11
12static LttvHooks
13 *before_traceset,
14 *after_traceset,
15 *before_trace,
16 *before_event;
17
18
19void init(int argc, char **argv)
20{
21 LttvAttribute_value *value;
22
23 LttvIAttributes *attributes = LTTV_IATTRIBUTES(lttv_global_attributes());
24
25 a_file_name = NULL;
26 lttv_option_add("output", 'o',
27 "output file where the text is written",
28 "file name",
29 LTTV_OPT_STRING, &a_file_name, NULL, NULL);
30
31 a_field_names = FALSE;
32 lttv_option_add("field_names", 'l',
33 "write the field names for each event",
34 "",
35 LTTV_OPT_NONE, &a_field_names, NULL, NULL);
36
37 a_state = FALSE;
38 lttv_option_add("process_state", 's',
39 "write the pid and state for each event",
40 "",
41 LTTV_OPT_NONE, &a_state, NULL, NULL);
42
43 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
44 LTTV_POINTER, &value));
45 g_assert((before_event = *(value->v_pointer)) != NULL);
46 lttv_hooks_add(before_event, write_event_content, NULL);
47
48 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
49 LTTV_POINTER, &value));
50 g_assert((before_trace = *(value->v_pointer)) != NULL);
51 lttv_hooks_add(before_trace, write_trace_header, NULL);
52
53 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
54 LTTV_POINTER, &value));
55 g_assert((before_traceset = *(value->v_pointer)) != NULL);
56 lttv_hooks_add(before_traceset, write_traceset_header, NULL);
57
58 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
59 LTTV_POINTER, &value));
60 g_assert((after_traceset = *(value->v_pointer)) != NULL);
61 lttv_hooks_add(after_traceset, write_traceset_footer, NULL);
62}
63
64
65void destroy()
66{
67 lttv_option_remove("output");
68
69 lttv_option_remove("field_names");
70
71 lttv_option_remove("process_state");
72
73 lttv_hooks_remove(before_event, write_event, NULL);
74
75 lttv_hooks_remove(before_trace, write_trace_header, NULL);
76
77 lttv_hooks_remove(before_trace, write_traceset_header, NULL);
78
79 lttv_hooks_remove(before_trace, write_traceset_footer, NULL);
80}
81
82
83/* Insert the hooks before and after each trace and tracefile, and for each
84 event. Print a global header. */
85
86static FILE *a_file;
87
88static GString *a_string;
89
90static static gboolean write_traceset_header(void *hook_data, void *call_data)
91{
92 LttvTracesetContext *tc = (LttvTracesetContext *)call_data;
93
94 if(a_file_name == NULL) a_file = stdout;
95 else a_file = fopen(a_file_name, "w");
96
97 if(a_file == NULL) g_error("cannot open file %s", a_file_name);
98
99 /* Print the trace set header */
100 fprintf(a_file,"Trace set contains %d traces\n\n",
101 lttv_traceset_number(tc->ta);
102
103 return FALSE;
104}
105
106
107static static gboolean write_traceset_footer(void *hook_data, void *call_data)
108{
109 LttvTracesetContext *tc = (LttvTracesetContext *)call_data;
110
111 if(a_file_name != NULL) a_file = fclose(a_file);
112
113 fprintf(a_file,"End trace set\n\n");
114
115 return FALSE;
116}
117
118
119static gboolean write_trace_header(void *hook_data, void *call_data)
120{
121 LttvTraceContext *tc = (LttvTraceContext *)call_data;
122
123 LttSystemDescription *system = ltt_trace_system_description(tc->t);
124
125 fprintf(a_file," Trace from %s in %s\n%s\n\n", system->node_name,
126 system->domain_name, system->description);
127 return FALSE;
128}
129
130
131static int write_event_content(void *hook_data, void *call_data)
132{
133 LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
134
135 LttvTracefileState *tfs = (LttvTracefileState *)call_data;
136
137 LttEvent *e;
138
139 e = tfc->e;
140
141 lttv_event_to_string(e, tfc->tf, a_string, TRUE, a_field_names);
142
143 if(a_state) {
144 g_string_append_printf(a_string, " %s",
145 g_quark_to_string(tfs->process->state->s);
146 }
147
148 fputs(s, c->fd);
149 return FALSE;
150}
151
152
153void lttv_event_to_string(LttEvent *e, LttTracefile *tf, g_string *s,
154 gboolean mandatory_fields, gboolean field_names)
155{
156 LttFacility *facility;
157
158 LttEventType *event_type;
159
160 LttType *type;
161
162 LttField *field;
163
164 LttTime time;
165
166 g_string_set_size(s,0);
167
168 facility = lttv_event_facility(e);
169 eventtype = ltt_event_eventtype(e);
170 field = ltt_event_field(e);
171
172 if(mandatory_fields) {
173 time = ltt_event_time(e);
174 g_string_append_printf(s,"%s.%s: %ld.%ld (%s)",ltt_facility_name(facility),
175 ltt_eventtype_name(eventtype), (long)time.tv_sec, time.tv_nsec,
176 ltt_tracefile_name(tf));
177 }
178
179 print_field(e,f,s, field_names);
180}
181
182
183void print_field(LttEvent *e, LttField *f, g_string *s, gboolean field_names) {
184
185 LttType *type;
186
187 LttField *element;
188
189 char *name;
190
191 int nb, i;
192
193 type = ltt_field_type(f);
194 switch(ltt_type_class(type)) {
195 case LTT_INT:
196 g_string_append_printf(s, " %ld", ltt_event_get_long_int(e,f));
197 break;
198
199 case LTT_UINT:
200 g_string_append_printf(s, " %lu", ltt_event_get_long_unsigned(e,f));
201 break;
202
203 case LTT_FLOAT:
204 g_string_append_printf(s, " %g", ltt_event_get_double(e,f));
205 break;
206
207 case LTT_STRING:
208 g_string_append_printf(s, " \"%s\"", ltt_event_get_string(e,f));
209 break;
210
211 case LTT_ENUM:
212 g_string_append_printf(s, " %s", ltt_enum_string_get(type,
213 event_get_unsigned(e,f));
214 break;
215
216 case LTT_ARRAY:
217 case LTT_SEQUENCE:
218 g_string_append_printf(s, " {");
219 nb = ltt_event_field_element_number(e,f);
220 element = ltt_field_element(f);
221 for(i = 0 ; i < nb ; i++) {
222 ltt_event_field_element_select(e,f,i);
223 print_field(e,element,s);
224 }
225 g_string_append_printf(s, " }");
226 break;
227
228 case LTT_STRUCT:
229 g_string_append_printf(s, " {");
230 nb = ltt_type_member_number(type);
231 for(i = 0 ; i < nb ; i++) {
232 element = ltt_field_member(f,i);
233 if(name) {
234 ltt_type_member_type(type, &name);
235 g_string_append_printf(s, " %s = ", field_names);
236 }
237 print_field(e,element,s);
238 }
239 g_string_append_printf(s, " }");
240 break;
241 }
242}
243
244
245
246
This page took 0.022047 seconds and 4 git commands to generate.