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
19 void init(int argc
, char **argv
)
21 LttvAttribute_value
*value
;
23 LttvIAttributes
*attributes
= LTTV_IATTRIBUTES(lttv_global_attributes());
26 lttv_option_add("output", 'o',
27 "output file where the text is written",
29 LTTV_OPT_STRING
, &a_file_name
, NULL
, NULL
);
31 a_field_names
= FALSE
;
32 lttv_option_add("field_names", 'l',
33 "write the field names for each event",
35 LTTV_OPT_NONE
, &a_field_names
, NULL
, NULL
);
38 lttv_option_add("process_state", 's',
39 "write the pid and state for each event",
41 LTTV_OPT_NONE
, &a_state
, NULL
, NULL
);
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
);
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
);
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
);
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
);
67 lttv_option_remove("output");
69 lttv_option_remove("field_names");
71 lttv_option_remove("process_state");
73 lttv_hooks_remove(before_event
, write_event
, NULL
);
75 lttv_hooks_remove(before_trace
, write_trace_header
, NULL
);
77 lttv_hooks_remove(before_trace
, write_traceset_header
, NULL
);
79 lttv_hooks_remove(before_trace
, write_traceset_footer
, NULL
);
83 /* Insert the hooks before and after each trace and tracefile, and for each
84 event. Print a global header. */
88 static GString
*a_string
;
90 static static gboolean
write_traceset_header(void *hook_data
, void *call_data
)
92 LttvTracesetContext
*tc
= (LttvTracesetContext
*)call_data
;
94 if(a_file_name
== NULL
) a_file
= stdout
;
95 else a_file
= fopen(a_file_name
, "w");
97 if(a_file
== NULL
) g_error("cannot open file %s", a_file_name
);
99 /* Print the trace set header */
100 fprintf(a_file
,"Trace set contains %d traces\n\n",
101 lttv_traceset_number(tc
->ta
);
107 static static gboolean
write_traceset_footer(void *hook_data
, void *call_data
)
109 LttvTracesetContext
*tc
= (LttvTracesetContext
*)call_data
;
111 if(a_file_name
!= NULL
) a_file
= fclose(a_file
);
113 fprintf(a_file
,"End trace set\n\n");
119 static gboolean
write_trace_header(void *hook_data
, void *call_data
)
121 LttvTraceContext
*tc
= (LttvTraceContext
*)call_data
;
123 LttSystemDescription
*system
= ltt_trace_system_description(tc
->t
);
125 fprintf(a_file
," Trace from %s in %s\n%s\n\n", system
->node_name
,
126 system
->domain_name
, system
->description
);
131 static int write_event_content(void *hook_data
, void *call_data
)
133 LttvTracefileContext
*tfc
= (LttvTracefileContext
*)call_data
;
135 LttvTracefileState
*tfs
= (LttvTracefileState
*)call_data
;
141 lttv_event_to_string(e
, tfc
->tf
, a_string
, TRUE
, a_field_names
);
144 g_string_append_printf(a_string
, " %s",
145 g_quark_to_string(tfs
->process
->state
->s
);
153 void lttv_event_to_string(LttEvent
*e
, LttTracefile
*tf
, g_string
*s
,
154 gboolean mandatory_fields
, gboolean field_names
)
156 LttFacility
*facility
;
158 LttEventType
*event_type
;
166 g_string_set_size(s
,0);
168 facility
= lttv_event_facility(e
);
169 eventtype
= ltt_event_eventtype(e
);
170 field
= ltt_event_field(e
);
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
));
179 print_field(e
,f
,s
, field_names
);
183 void print_field(LttEvent
*e
, LttField
*f
, g_string
*s
, gboolean field_names
) {
193 type
= ltt_field_type(f
);
194 switch(ltt_type_class(type
)) {
196 g_string_append_printf(s
, " %ld", ltt_event_get_long_int(e
,f
));
200 g_string_append_printf(s
, " %lu", ltt_event_get_long_unsigned(e
,f
));
204 g_string_append_printf(s
, " %g", ltt_event_get_double(e
,f
));
208 g_string_append_printf(s
, " \"%s\"", ltt_event_get_string(e
,f
));
212 g_string_append_printf(s
, " %s", ltt_enum_string_get(type
,
213 event_get_unsigned(e
,f
));
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
);
225 g_string_append_printf(s
, " }");
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
);
234 ltt_type_member_type(type
, &name
);
235 g_string_append_printf(s
, " %s = ", field_names
);
237 print_field(e
,element
,s
);
239 g_string_append_printf(s
, " }");