From e5298fbcd9a48840e10d054addfdae38e879f04e Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 12 Apr 2016 17:02:19 -0400 Subject: [PATCH] barectf-tracepoint ex: put platform-specific stuff in separate files Signed-off-by: Philippe Proulx --- .../barectf-tracepoint/Makefile.barectf | 2 +- .../barectf-tracepoint/Makefile.lttng-ust | 2 +- .../barectf-tracepoint-linux-fs.h | 47 +++++++++++++++ .../barectf-tracepoint-lttng-ust.h | 11 ++++ .../barectf-tracepoint/barectf-tracepoint.c | 58 +++---------------- 5 files changed, 67 insertions(+), 53 deletions(-) create mode 100644 doc/examples/barectf-tracepoint/barectf-tracepoint-linux-fs.h create mode 100644 doc/examples/barectf-tracepoint/barectf-tracepoint-lttng-ust.h diff --git a/doc/examples/barectf-tracepoint/Makefile.barectf b/doc/examples/barectf-tracepoint/Makefile.barectf index 74fb5b3..af1f972 100644 --- a/doc/examples/barectf-tracepoint/Makefile.barectf +++ b/doc/examples/barectf-tracepoint/Makefile.barectf @@ -28,7 +28,7 @@ barectf.o: barectf.c barectf-platform-linux-fs.o: $(PLATFORM_DIR)/barectf-platform-linux-fs.c $(CC) $(CFLAGS) -c $< -$(TARGET).o: barectf-tracepoint.c barectf.h barectf-bitfield.h +$(TARGET).o: barectf-tracepoint.c barectf-tracepoint-linux-fs.h barectf.h barectf-bitfield.h $(CC) -o $@ $(CFLAGS) -c $< clean: diff --git a/doc/examples/barectf-tracepoint/Makefile.lttng-ust b/doc/examples/barectf-tracepoint/Makefile.lttng-ust index 84ec055..9763fcd 100644 --- a/doc/examples/barectf-tracepoint/Makefile.lttng-ust +++ b/doc/examples/barectf-tracepoint/Makefile.lttng-ust @@ -16,7 +16,7 @@ $(TARGET): $(OBJS) tp.o: tp.c $(CC) -c $(CFLAGS) -I. $< -$(TARGET).o: barectf-tracepoint.c tp.h +$(TARGET).o: barectf-tracepoint.c barectf-tracepoint-lttng-ust.h tp.h $(CC) -c -o $@ $(CFLAGS) -DWITH_LTTNG_UST=1 $< clean: diff --git a/doc/examples/barectf-tracepoint/barectf-tracepoint-linux-fs.h b/doc/examples/barectf-tracepoint/barectf-tracepoint-linux-fs.h new file mode 100644 index 0000000..0053b6d --- /dev/null +++ b/doc/examples/barectf-tracepoint/barectf-tracepoint-linux-fs.h @@ -0,0 +1,47 @@ +#ifndef _BARECTF_TRACEPOINT_LINUX_FS +#define _BARECTF_TRACEPOINT_LINUX_FS + +#include + +/* + * Include generated barectf header file: this contains the prefix and + * default stream name to be used by the tracepoint() macro. + */ +#include "barectf.h" + +/* define how the context is to be found by tracepoint() calls */ +#define BARECTF_TRACEPOINT_CTX (global_barectf_ctx) + +/* then include this: */ +#include + +/* global barectf context (default stream) */ +static struct barectf_default_ctx *global_barectf_ctx; + +/* global barectf platform context */ +static struct barectf_platform_linux_fs_ctx *global_barectf_platform_ctx; + +/* init function for this version */ +static void init_tracing(void) +{ + /* initialize platform */ + global_barectf_platform_ctx = + barectf_platform_linux_fs_init(512, "ctf", 1, 2, 7); + + if (!global_barectf_platform_ctx) { + fprintf(stderr, "Error: could not initialize platform\n"); + exit(1); + } + + global_barectf_ctx = barectf_platform_linux_fs_get_barectf_ctx( + global_barectf_platform_ctx); +} + +/* finalization function for this version */ +static void fini_tracing(void) +{ + /* finalize platform */ + barectf_platform_linux_fs_fini(global_barectf_platform_ctx); +} + +#endif /* _BARECTF_TRACEPOINT_LINUX_FS */ diff --git a/doc/examples/barectf-tracepoint/barectf-tracepoint-lttng-ust.h b/doc/examples/barectf-tracepoint/barectf-tracepoint-lttng-ust.h new file mode 100644 index 0000000..6a7377f --- /dev/null +++ b/doc/examples/barectf-tracepoint/barectf-tracepoint-lttng-ust.h @@ -0,0 +1,11 @@ +#ifndef _BARECTF_TRACEPOINT_LTTNG_UST +#define _BARECTF_TRACEPOINT_LTTNG_UST + +/* tracepoint provider header */ +#include "tp.h" + +/* empty init() and fini() function for this version */ +#define init_tracing() +#define fini_tracing() + +#endif /* _BARECTF_TRACEPOINT_LTTNG_UST */ diff --git a/doc/examples/barectf-tracepoint/barectf-tracepoint.c b/doc/examples/barectf-tracepoint/barectf-tracepoint.c index 6b94670..41708d2 100644 --- a/doc/examples/barectf-tracepoint/barectf-tracepoint.c +++ b/doc/examples/barectf-tracepoint/barectf-tracepoint.c @@ -3,29 +3,11 @@ #include #include -#ifdef WITH_LTTNG_UST -#include "tp.h" -#else /* #ifdef WITH_LTTNG_UST */ -#include - -/* - * Include generated barectf header file: this contains the prefix and - * default stream name to be used by the tracepoint() macro. - */ -#include "barectf.h" - -/* define how the context is to be found by tracepoint() calls */ -#define BARECTF_TRACEPOINT_CTX (global_barectf_ctx) - -/* then include this: */ -#include - -/* global barectf context (default stream) */ -static struct barectf_default_ctx *global_barectf_ctx; - -/* global barectf platform context */ -struct barectf_platform_linux_fs_ctx *global_barectf_platform_ctx; -#endif /* #ifdef WITH_LTTNG_UST */ +#if defined(WITH_LTTNG_UST) +#include "barectf-tracepoint-lttng-ust.h" +#else +#include "barectf-tracepoint-linux-fs.h" +#endif enum state_t { NEW, @@ -62,37 +44,11 @@ static void trace_stuff(int argc, char *argv[]) } } -#ifdef WITH_LTTNG_UST -#define init_barectf() -#define fini_barectf() -#else /* #ifdef WITH_LTTNG_UST */ -static void init_barectf(void) -{ - /* initialize platform */ - global_barectf_platform_ctx = - barectf_platform_linux_fs_init(512, "ctf", 1, 2, 7); - - if (!global_barectf_platform_ctx) { - fprintf(stderr, "Error: could not initialize platform\n"); - exit(1); - } - - global_barectf_ctx = barectf_platform_linux_fs_get_barectf_ctx( - global_barectf_platform_ctx); -} - -static void fini_barectf(void) -{ - /* finalize platform */ - barectf_platform_linux_fs_fini(global_barectf_platform_ctx); -} -#endif /* #ifdef WITH_LTTNG_UST */ - int main(int argc, char *argv[]) { - init_barectf(); + init_tracing(); trace_stuff(argc, argv); - fini_barectf(); + fini_tracing(); return 0; } -- 2.34.1