before each trace, to print each event, and to print statistics
after each trace. */
-void init(int argc, char **argv)
-{
- lttv_attributes *a;
- lttv_hooks *before, *after;
-
- a = lttv_global_attributes();
- before = (lttv_hooks *)lttv_attributes_get_pointer_pathname(a,
- "hooks/trace_set/before");
- after = (lttv_hooks *)lttv_attributes_get_pointer_pathname(a,
- "hooks/trace_set/after");
- lttv_hooks_add(before, textDump_trace_set_before, NULL);
- lttv_hooks_add(after, textDump_trace_set_after, NULL);
-}
+#include <lttv/lttv.h>
+#include <lttv/option.h>
+#include <lttv/module.h>
+#include <lttv/hook.h>
+#include <lttv/attribute.h>
+#include <lttv/iattribute.h>
+#include <lttv/state.h>
+#include <ltt/ltt.h>
+#include <ltt/event.h>
+#include <ltt/type.h>
+#include <ltt/trace.h>
+#include <stdio.h>
+static gboolean
+ a_field_names,
+ a_state;
-void destroy()
-{
- lttv_attributes *a;
- lttv_hooks *before, *after;
-
- a = lttv_global_attributes();
- before = (lttv_hooks *)lttv_attributes_get_pointer_pathname(a,
- "hooks/trace_set/before");
- after = (lttv_hooks *)lttv_attributes_get_pointer_pathname(a,
- "hooks/trace_set/after");
- lttv_hooks_remove(before, textDump_trace_set_before, NULL);
- lttv_hooks_remove(after, textDump_trace_set_after, NULL);
-}
+static char
+ *a_file_name;
-/* Insert the hooks before and after each trace and tracefile, and for each
- event. Print a global header. */
+static LttvHooks
+ *before_traceset,
+ *after_traceset,
+ *before_trace,
+ *before_event;
-typedef struct _trace_context {
- g_string s;
- FILE *fp;
- bool mandatory_fields;
- lttv_attributes *a;
-} trace_context;
-static bool textDump_trace_set_before(void *hook_data, void *call_data)
-{
- FILE *fp;
- int i, j, nb, nbtf;
- lttv_trace_set *s;
- lttv_attributes *a;
- trace_context *c;
-
- a = lttv_global_attributes();
- s = (lttv_trace_set *)call_data
-
- /* Get the file pointer */
-
- fp = (FILE *)lttv_attributes_get_pointer_pathname(a, "textDump/file");
-
- /* For each trace prepare the contexts and insert the hooks */
-
- nb = lttv_trace_set_number(s);
- for(i = 0 ; i < nb ; i++) {
- c = g_new(trace_context);
- a = lttv_trace_set_trace_attributes(s, i);
-
- if(lttv_attributes_get_pointer_pathname(a, "textDump/context") != NULL) {
- g_error("Recursive call to TextDump");
- }
-
- c->fp = fp;
- c->mandatory_fields = TRUE;
- c->s = g_string_new();
- c->a = a;
-
- lttv_attributes_set_pointer_pathname(a, "textDump/context", c);
-
- h = lttv_attributes_get_hooks(a, "hooks/before");
- lttv_hooks_add(h, textDump_trace_before, c);
- h = lttv_attributes_get_hooks(a, "hooks/after");
- lttv_hooks_add(h, textDump_trace_after, c);
- h = lttv_attributes_get_hooks(a, "hooks/tacefile/before");
- lttv_hooks_add(h, textDump_tracefile_before, c);
- h = lttv_attributes_get_hooks(a, "hooks/tracefile/after");
- lttv_hooks_add(h, textDump_tracefile_after, c);
- h = lttv_attributes_get_hooks(a, "hooks/event/selected");
- lttv_hooks_add(h, textDump_event, c);
- }
+void print_field(LttEvent *e, LttField *f, GString *s, gboolean field_names) {
- /* Print the trace set header */
- fprintf(fp,"Trace set contains %d traces\n\n", nb);
+ LttType *type;
- return TRUE;
-}
+ LttField *element;
+ char *name;
-/* Remove the hooks before and after each trace and tracefile, and for each
- event. Print trace set level statistics. */
+ int nb, i;
-static bool textDump_trace_set_after(void *hook_data, void *call_data)
-{
- FILE *fp;
- int i, j, nb, nbtf;
- lttv_trace_set *s;
- lttv_attributes *ga, *a;
- trace_context *c;
-
- ga = lttv_global_attributes();
- s = (lttv_trace_set *)lttv_attributes_get_pointer_pathname(ga,
- "trace_set/main");
-
- /* Get the file pointer */
-
- fp = (FILE *)lttv_attributes_get_pointer_pathname(ga, "textDump/file");
-
- /* For each trace remove the hooks */
-
- nb = lttv_trace_set_number(s);
- for(i = 0 ; i < nb ; i++) {
- a = lttv_trace_set_trace_attributes(s, i);
- c = (trace_context *)lttv_attributes_get_pointer_pathname(a,
- "textDump/context");
- lttv_attributes_set_pointer_pathname(a, "textDump/context", NULL);
- g_string_free(c->s);
-
- h = lttv_attributes_get_hooks(a, "hooks/before");
- lttv_hooks_remove(h, textDump_trace_before, c);
- h = lttv_attributes_get_hooks(a, "hooks/after");
- lttv_hooks_remove(h, textDump_trace_after, c);
- h = lttv_attributes_get_hooks(a, "hooks/tacefile/before");
- lttv_hooks_remove(h, textDump_tracefile_before, c);
- h = lttv_attributes_get_hooks(a, "hooks/tracefile/after");
- lttv_hooks_remove(h, textDump_tracefile_after, c);
- h = lttv_attributes_get_hooks(a, "hooks/event/selected");
- lttv_hooks_remove(h, textDump_event, c);
- g_free(c);
- }
+ type = ltt_field_type(f);
+ switch(ltt_type_class(type)) {
+ case LTT_INT:
+ g_string_append_printf(s, " %ld", ltt_event_get_long_int(e,f));
+ break;
+
+ case LTT_UINT:
+ g_string_append_printf(s, " %lu", ltt_event_get_long_unsigned(e,f));
+ break;
+
+ case LTT_FLOAT:
+ g_string_append_printf(s, " %g", ltt_event_get_double(e,f));
+ break;
- /* Print the trace set statistics */
+ case LTT_STRING:
+ g_string_append_printf(s, " \"%s\"", ltt_event_get_string(e,f));
+ break;
- fprintf(fp,"Trace set contains %d traces\n\n", nb);
+ case LTT_ENUM:
+ g_string_append_printf(s, " %s", ltt_enum_string_get(type,
+ ltt_event_get_unsigned(e,f)-1));
+ break;
- print_stats(fp, ga);
+ case LTT_ARRAY:
+ case LTT_SEQUENCE:
+ g_string_append_printf(s, " {");
+ nb = ltt_event_field_element_number(e,f);
+ element = ltt_field_element(f);
+ for(i = 0 ; i < nb ; i++) {
+ ltt_event_field_element_select(e,f,i);
+ print_field(e, element, s, field_names);
+ }
+ g_string_append_printf(s, " }");
+ break;
- return TRUE;
+ case LTT_STRUCT:
+ g_string_append_printf(s, " {");
+ nb = ltt_type_member_number(type);
+ for(i = 0 ; i < nb ; i++) {
+ element = ltt_field_member(f,i);
+ if(field_names) {
+ ltt_type_member_type(type, i, &name);
+ g_string_append_printf(s, " %s = ", name);
+ }
+ print_field(e, element, s, field_names);
+ }
+ g_string_append_printf(s, " }");
+ break;
+ }
}
-/* Print a trace level header */
+void lttv_event_to_string(LttEvent *e, LttTracefile *tf, GString *s,
+ gboolean mandatory_fields, gboolean field_names, LttvTracefileState *tfs)
+{
+ LttFacility *facility;
-static bool textDump_trace_before(void *hook_data, void *call_data)
-{
- ltt_trace *t;
- trace_context *c;
+ LttEventType *event_type;
- c = (trace_context *)hook_data;
- t = (ltt_trace *)call_data;
- fprintf(c->fp,"Start trace\n");
- return TRUE;
-}
+ LttType *type;
+ LttField *field;
-/* Print trace level statistics */
+ LttTime time;
-static bool textDump_trace_after(void *hook_data, void *call_data)
-{
- ltt_trace *t;
- trace_context *c;
-
- c = (trace_context *)hook_data;
- t = (ltt_trace *)call_data;
- fprintf(c->fp,"End trace\n");
- print_stats(c->fp,c->a);
- return TRUE;
-}
+ g_string_set_size(s,0);
+
+ facility = ltt_event_facility(e);
+ event_type = ltt_event_eventtype(e);
+ field = ltt_event_field(e);
+
+ if(mandatory_fields) {
+ time = ltt_event_time(e);
+ g_string_append_printf(s,"%s.%s: %ld.%ld (%s)",ltt_facility_name(facility),
+ ltt_eventtype_name(event_type), (long)time.tv_sec, time.tv_nsec,
+ ltt_tracefile_name(tf));
+ /* Print the process id and the state/interrupt type of the process */
+ g_string_append_printf(s,", %d, %s", tfs->process->pid,
+ g_quark_to_string(tfs->process->state->t));
+ }
+ if(field)
+ print_field(e, field, s, field_names);
+}
-static bool textDump_tracefile_before(void *hook_data, void *call_data)
-{
- ltt_tracefile *tf;
- trace_context *c;
- c = (trace_context *)hook_data;
- tf = (ltt_tracefile *)call_data;
- fprintf(c->fp,"Start tracefile\n");
- return TRUE;
-}
+/* Insert the hooks before and after each trace and tracefile, and for each
+ event. Print a global header. */
+
+static FILE *a_file;
+static GString *a_string;
-static bool textDump_tracefile_after(void *hook_data, void *call_data)
+static gboolean write_traceset_header(void *hook_data, void *call_data)
{
- ltt_tracefile *tf;
- trace_context *c;
+ LttvTracesetContext *tc = (LttvTracesetContext *)call_data;
- c = (trace_context *)hook_data;
- tf = (ltt_tracefile *)call_data;
- fprintf(c->fp,"End tracefile\n");
- return TRUE;
-}
+ if(a_file_name == NULL) a_file = stdout;
+ else a_file = fopen(a_file_name, "w");
+ if(a_file == NULL) g_error("cannot open file %s", a_file_name);
-/* Print the event content */
+ /* Print the trace set header */
+ fprintf(a_file,"Trace set contains %d traces\n\n",
+ lttv_traceset_number(tc->ts));
-static bool textDump_event(void *hook_data, void *call_data)
+ return FALSE;
+}
+
+
+static gboolean write_traceset_footer(void *hook_data, void *call_data)
{
- ltt_event *e;
- trace_context *c;
-
- e = (ltt_event *)call_data;
- c = (event_context *)hook_data;
- lttv_event_to_string(e,c->s,c->mandatory_fields);
- fputs(s, c->fd);
- return TRUE;
+ LttvTracesetContext *tc = (LttvTracesetContext *)call_data;
+
+ fprintf(a_file,"End trace set\n\n");
+
+ if(a_file_name != NULL) fclose(a_file);
+
+ return FALSE;
}
-static void print_stats(FILE *fp, lttv_attributes *a)
+static gboolean write_trace_header(void *hook_data, void *call_data)
{
- int i, j, k, nb, nbc;
-
- lttv_attributes *sa, *ra;
- lttv_attribute *reports, *content;
- lttv_key *key, *previous_key, null_key;
-
- null_key = lttv_key_new_pathname("");
- sa = (lttv_attributes *)lttv_attributes_get_pointer_pathname(a,"stats");
- reports = lttv_attributes_array_get(sa);
- nb= lttv_attributes_number(sa);
-
- for(i = 0 ; i < nb ; i++) {
- ra = (lttv_attributes *)reports[i].v.p;
- key = reports[i].key;
- g_assert(reports[i].t == LTTV_POINTER);
-
- /* CHECK maybe have custom handlers registered for some specific reports */
-
- print_key(fp,key);
-
- content = lttv_attributes_array_get(ra);
- nbc = lttv_attributes_number(ra);
- lttv_attribute_array_sort_lexicographic(content, nbc, NULL, 0);
- previous_key = nullKey;
- for(j = 0 ; j < nbc ; j++) {
- key = content[j].key;
- for(k = 0 ; lttv_key_index(previous_key,k) == lttv_index(key,k) ; k++)
- for(; k < lttv_key_number(key) ; k++) {
- for(l = 0 ; l < k ; l++) fprintf(fp," ");
- fprintf(fp, "%s", lttv_string_id_to_string(lttv_index(key,k)));
- if(k == lttv_key_number(key)) {
- switch(content[j].t) {
- case LTTV_INTEGER:
- fprintf(fp," %d\n", content[j].v.i);
- break;
- case LTTV_TIME:
- fprintf(fp," %d.%09d\n", content[j].v.t.tv_sec,
- content[j].v.t.tv_nsec);
- break;
- case LTTV_DOUBLE:
- fprintf(fp," %g\n", content[j].v.d);
- break;
- case LTTV_POINTER:
- fprintf(fp," pointer\n");
- break;
- }
- }
- else fprintf(fp,"\n");
- }
- }
- lttv_attribute_array_destroy(content);
- }
- lttv_attribute_array_destroy(reports);
- lttv_key_destroy(null_key);
+ LttvTraceContext *tc = (LttvTraceContext *)call_data;
+
+ LttSystemDescription *system = ltt_trace_system_description(tc->t);
+
+ fprintf(a_file," Trace from %s in %s\n%s\n\n", system->node_name,
+ system->domain_name, system->description);
+ return FALSE;
}
-void lttv_event_to_string(ltt_event *e, lttv_string *s, bool mandatory_fields)
+static int write_event_content(void *hook_data, void *call_data)
{
- ltt_facility *facility;
- ltt_eventtype *eventtype;
- ltt_type *type;
- ltt_field *field;
- ltt_time time;
+ LttvTracefileContext *tfc = (LttvTracefileContext *)call_data;
- g_string_set_size(s,0);
+ LttvTracefileState *tfs = (LttvTracefileState *)call_data;
- facility = lttv_event_facility(e);
- eventtype = ltt_event_eventtype(e);
- field = ltt_event_field(e);
+ LttEvent *e;
- if(mandatory_fields) {
- time = ltt_event_time(e);
- g_string_append_printf(s,"%s.%s: %ld.%ld",ltt_facility_name(facility),
- ltt_eventtype_name(eventtype), (long)time.tv_sec, time.tv_nsec);
+ e = tfc->e;
+
+ lttv_event_to_string(e, tfc->tf, a_string, TRUE, a_field_names, tfs);
+ g_string_append_printf(a_string,"\n");
+
+ if(a_state) {
+ g_string_append_printf(a_string, " %s",
+ g_quark_to_string(tfs->process->state->s));
}
- print_field(e,f,s);
-}
+ fputs(a_string->str, a_file);
+ return FALSE;
+}
-void print_field(ltt_event *e, ltt_field *f, lttv_string *s) {
- ltt_type *type;
- ltt_field *element;
- int nb, i;
+//void init(int argc, char **argv)
+G_MODULE_EXPORT void init(LttvModule *self, int argc, char **argv)
+{
+ LttvAttributeValue value;
+
+ LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
+
+ a_string = g_string_new("");
+
+ a_file_name = NULL;
+ lttv_option_add("output", 'o',
+ "output file where the text is written",
+ "file name",
+ LTTV_OPT_STRING, &a_file_name, NULL, NULL);
+
+ a_field_names = FALSE;
+ lttv_option_add("field_names", 'l',
+ "write the field names for each event",
+ "",
+ LTTV_OPT_NONE, &a_field_names, NULL, NULL);
+
+ a_state = FALSE;
+ lttv_option_add("process_state", 's',
+ "write the pid and state for each event",
+ "",
+ LTTV_OPT_NONE, &a_state, NULL, NULL);
+
+ g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
+ LTTV_POINTER, &value));
+ g_assert((before_event = *(value.v_pointer)) != NULL);
+ lttv_hooks_add(before_event, write_event_content, NULL);
+
+ g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
+ LTTV_POINTER, &value));
+ g_assert((before_trace = *(value.v_pointer)) != NULL);
+ lttv_hooks_add(before_trace, write_trace_header, NULL);
+
+ g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
+ LTTV_POINTER, &value));
+ g_assert((before_traceset = *(value.v_pointer)) != NULL);
+ lttv_hooks_add(before_traceset, write_traceset_header, NULL);
+
+ g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
+ LTTV_POINTER, &value));
+ g_assert((after_traceset = *(value.v_pointer)) != NULL);
+ lttv_hooks_add(after_traceset, write_traceset_footer, NULL);
+}
- type = ltt_field_type(f);
- switch(ltt_type_class(type)) {
- case LTT_INT:
- g_string_append_printf(s, " %ld", ltt_event_get_long_int(e,f));
- break;
- case LTT_UINT:
- g_string_append_printf(s, " %lu", ltt_event_get_long_unsigned(e,f));
- break;
+G_MODULE_EXPORT void destroy()
+{
+ lttv_option_remove("output");
- case LTT_FLOAT:
- g_string_append_printf(s, " %g", ltt_event_get_double(e,f));
- break;
+ lttv_option_remove("field_names");
- case LTT_STRING:
- g_string_append_printf(s, " \"%s\"", ltt_event_get_string(e,f));
- break;
+ lttv_option_remove("process_state");
- case LTT_ENUM:
- g_string_append_printf(s, " %s", ltt_enum_string_get(type,
- event_get_unsigned(e,f));
- break;
+ g_string_free(a_string, TRUE);
- case LTT_ARRAY:
- case LTT_SEQUENCE:
- g_string_append_printf(s, " {");
- nb = ltt_event_field_element_number(e,f);
- element = ltt_field_element(f);
- for(i = 0 ; i < nb ; i++) {
- ltt_event_field_element_select(e,f,i);
- print_field(e,element,s);
- }
- g_string_append_printf(s, " }");
- break;
+ lttv_hooks_remove_data(before_event, write_event_content, NULL);
- case LTT_STRUCT:
- g_string_append_printf(s, " {");
- nb = ltt_type_member_number(type);
- for(i = 0 ; i < nb ; i++) {
- element = ltt_field_member(f,i);
- print_field(e,element,s);
- }
- g_string_append_printf(s, " }");
- break;
- }
+ lttv_hooks_remove_data(before_trace, write_trace_header, NULL);
+
+ lttv_hooks_remove_data(before_trace, write_traceset_header, NULL);
+
+ lttv_hooks_remove_data(before_trace, write_traceset_footer, NULL);
}