barectf-tracepoint ex: put platform-specific stuff in separate files
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 12 Apr 2016 21:02:19 +0000 (17:02 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 12 Apr 2016 21:23:00 +0000 (17:23 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
doc/examples/barectf-tracepoint/Makefile.barectf
doc/examples/barectf-tracepoint/Makefile.lttng-ust
doc/examples/barectf-tracepoint/barectf-tracepoint-linux-fs.h [new file with mode: 0644]
doc/examples/barectf-tracepoint/barectf-tracepoint-lttng-ust.h [new file with mode: 0644]
doc/examples/barectf-tracepoint/barectf-tracepoint.c

index 74fb5b38130d684454c076d5df6f7c42a7c55aa1..af1f9726b4deb18927f741d38f705aee816be45e 100644 (file)
@@ -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:
index 84ec05529653107c5c965c4a6cf6d25073aa9381..9763fcd34913ee7a598e575089f157d7a648efe1 100644 (file)
@@ -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 (file)
index 0000000..0053b6d
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef _BARECTF_TRACEPOINT_LINUX_FS
+#define _BARECTF_TRACEPOINT_LINUX_FS
+
+#include <barectf-platform-linux-fs.h>
+
+/*
+ * 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 <barectf-tracepoint.h>
+
+/* 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 (file)
index 0000000..6a7377f
--- /dev/null
@@ -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 */
index 6b9467031ec593e2e8728903074759c1cdc9d9d0..41708d2aaf1bd6325a1a7fa9849ae9e5503361c1 100644 (file)
@@ -3,29 +3,11 @@
 #include <stdlib.h>
 #include <time.h>
 
-#ifdef WITH_LTTNG_UST
-#include "tp.h"
-#else /* #ifdef WITH_LTTNG_UST */
-#include <barectf-platform-linux-fs.h>
-
-/*
- * 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 <barectf-tracepoint.h>
-
-/* 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;
 }
This page took 0.026142 seconds and 4 git commands to generate.