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
6 #include <lttv/option.h>
7 #include <lttv/module.h>
9 #include <lttv/attribute.h>
10 #include <lttv/iattribute.h>
11 #include <lttv/state.h>
27 void init(int argc
, char **argv
)
29 LttvAttributeValue
*value
;
31 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
34 lttv_option_add("output", 'o',
35 "output file where the text is written",
37 LTTV_OPT_STRING
, &a_file_name
, NULL
, NULL
);
39 a_field_names
= FALSE
;
40 lttv_option_add("field_names", 'l',
41 "write the field names for each event",
43 LTTV_OPT_NONE
, &a_field_names
, NULL
, NULL
);
46 lttv_option_add("process_state", 's',
47 "write the pid and state for each event",
49 LTTV_OPT_NONE
, &a_state
, NULL
, NULL
);
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
);
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
);
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
);
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
);
75 lttv_option_remove("output");
77 lttv_option_remove("field_names");
79 lttv_option_remove("process_state");
81 lttv_hooks_remove(before_event
, write_event
, NULL
);
83 lttv_hooks_remove(before_trace
, write_trace_header
, NULL
);
85 lttv_hooks_remove(before_trace
, write_traceset_header
, NULL
);
87 lttv_hooks_remove(before_trace
, write_traceset_footer
, NULL
);
91 /* Insert the hooks before and after each trace and tracefile, and for each
92 event. Print a global header. */
96 static GString
*a_string
;
98 static static gboolean
write_traceset_header(void *hook_data
, void *call_data
)
100 LttvTracesetContext
*tc
= (LttvTracesetContext
*)call_data
;
102 if(a_file_name
== NULL
) a_file
= stdout
;
103 else a_file
= fopen(a_file_name
, "w");
105 if(a_file
== NULL
) g_error("cannot open file %s", a_file_name
);
107 /* Print the trace set header */
108 fprintf(a_file
,"Trace set contains %d traces\n\n",
109 lttv_traceset_number(tc
->ta
);
115 static static gboolean
write_traceset_footer(void *hook_data
, void *call_data
)
117 LttvTracesetContext
*tc
= (LttvTracesetContext
*)call_data
;
119 if(a_file_name
!= NULL
) a_file
= fclose(a_file
);
121 fprintf(a_file
,"End trace set\n\n");
127 static gboolean
write_trace_header(void *hook_data
, void *call_data
)
129 LttvTraceContext
*tc
= (LttvTraceContext
*)call_data
;
131 LttSystemDescription
*system
= ltt_trace_system_description(tc
->t
);
133 fprintf(a_file
," Trace from %s in %s\n%s\n\n", system
->node_name
,
134 system
->domain_name
, system
->description
);
139 static int write_event_content(void *hook_data
, void *call_data
)
141 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
143 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
149 lttv_event_to_string(e
, tfc
->tf
, a_string
, TRUE
, a_field_names
);
152 g_string_append_printf(a_string
, " %s",
153 g_quark_to_string(tfs
->process
->state
->s
);
161 void lttv_event_to_string(LttEvent
*e
, LttTracefile
*tf
, g_string
*s
,
162 gboolean mandatory_fields
, gboolean field_names
)
164 LttFacility
*facility
;
166 LttEventType
*event_type
;
174 g_string_set_size(s
,0);
176 facility
= lttv_event_facility(e
);
177 eventtype
= ltt_event_eventtype(e
);
178 field
= ltt_event_field(e
);
180 if(mandatory_fields
) {
181 time
= ltt_event_time(e
);
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
));
187 print_field(e
,f
,s
, field_names
);
191 void print_field(LttEvent
*e
, LttField
*f
, g_string
*s
, gboolean field_names
) {
201 type
= ltt_field_type(f
);
202 switch(ltt_type_class(type
)) {
204 g_string_append_printf(s
, " %ld", ltt_event_get_long_int(e
,f
));
208 g_string_append_printf(s
, " %lu", ltt_event_get_long_unsigned(e
,f
));
212 g_string_append_printf(s
, " %g", ltt_event_get_double(e
,f
));
216 g_string_append_printf(s
, " \"%s\"", ltt_event_get_string(e
,f
));
220 g_string_append_printf(s
, " %s", ltt_enum_string_get(type
,
221 event_get_unsigned(e
,f
));
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
);
233 g_string_append_printf(s
, " }");
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
);
242 ltt_type_member_type(type
, &name
);
243 g_string_append_printf(s
, " %s = ", field_names
);
245 print_field(e
,element
,s
);
247 g_string_append_printf(s
, " }");