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