tools lib traceevent: Introduce trace_seq_do_fprintf function
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 3 Feb 2015 15:44:09 +0000 (12:44 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 6 Feb 2015 10:46:37 +0000 (11:46 +0100)
So that we can specify a FILE object where to direct the formatted
output.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/n/tip-a49bhdrx8851f04hppn8bqxq@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/traceevent/event-parse.h
tools/lib/traceevent/trace-seq.c

index 7a3873ff9a4fb0ebad9018c04b795e061626e1a7..5b4efc06232054bb7b12316dbe9c5fa612b32024 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <stdbool.h>
 #include <stdarg.h>
+#include <stdio.h>
 #include <regex.h>
 #include <string.h>
 
@@ -91,6 +92,7 @@ extern int trace_seq_putc(struct trace_seq *s, unsigned char c);
 
 extern void trace_seq_terminate(struct trace_seq *s);
 
+extern int trace_seq_do_fprintf(struct trace_seq *s, FILE *fp);
 extern int trace_seq_do_printf(struct trace_seq *s);
 
 
index ec3bd16a548881252d482e3f09e499a9bd12898d..292dc9f1d2334f2a9cab35d70b1531d74f68fca4 100644 (file)
@@ -231,19 +231,24 @@ void trace_seq_terminate(struct trace_seq *s)
        s->buffer[s->len] = 0;
 }
 
-int trace_seq_do_printf(struct trace_seq *s)
+int trace_seq_do_fprintf(struct trace_seq *s, FILE *fp)
 {
        TRACE_SEQ_CHECK(s);
 
        switch (s->state) {
        case TRACE_SEQ__GOOD:
-               return printf("%.*s", s->len, s->buffer);
+               return fprintf(fp, "%.*s", s->len, s->buffer);
        case TRACE_SEQ__BUFFER_POISONED:
-               puts("Usage of trace_seq after it was destroyed");
+               fprintf(fp, "%s\n", "Usage of trace_seq after it was destroyed");
                break;
        case TRACE_SEQ__MEM_ALLOC_FAILED:
-               puts("Can't allocate trace_seq buffer memory");
+               fprintf(fp, "%s\n", "Can't allocate trace_seq buffer memory");
                break;
        }
        return -1;
 }
+
+int trace_seq_do_printf(struct trace_seq *s)
+{
+       return trace_seq_do_fprintf(s, stdout);
+}