src/common/sessiond-comm/Makefile
src/common/compat/Makefile
src/common/relayd/Makefile
+ src/common/testpoint/Makefile
src/lib/Makefile
src/lib/lttng-ctl/Makefile
src/lib/lttng-ctl/filter/Makefile
AM_CPPFLAGS =
-SUBDIRS = compat hashtable kernel-ctl sessiond-comm relayd kernel-consumer ust-consumer
+SUBDIRS = compat hashtable kernel-ctl sessiond-comm relayd \
+ kernel-consumer ust-consumer testpoint
AM_CFLAGS = -fno-strict-aliasing
# Common library
noinst_LTLIBRARIES = libcommon.la
-libcommon_la_SOURCES = error.h error.c utils.c utils.h runas.c runas.h common.h futex.c futex.h uri.c uri.h
+libcommon_la_SOURCES = error.h error.c utils.c utils.h runas.c runas.h \
+ common.h futex.c futex.h uri.c uri.h
# Consumer library
noinst_LTLIBRARIES += libconsumer.la
--- /dev/null
+AM_CPPFLAGS =
+
+noinst_LTLIBRARIES = libtestpoint.la
+
+libtestpoint_la_SOURCES = testpoint.h testpoint.c
+libtestpoint_la_LIBADD = -ldl
--- /dev/null
+/*
+ * Copyright (C) 2012 - Christian Babeux <christian.babeux@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef NTESTPOINT
+
+#define _GNU_SOURCE /* for RTLD_DEFAULT GNU extension */
+#include <dlfcn.h> /* for dlsym */
+#include <stdlib.h> /* for getenv */
+#include <string.h> /* for strncmp */
+
+#include "testpoint.h"
+
+/* Environment variable used to enable the testpoints facilities. */
+static const char *lttng_testpoint_env_var = "LTTNG_TESTPOINT_ENABLE";
+
+/* Testpoint toggle flag */
+int lttng_testpoint_activated;
+
+/*
+ * Toggle the support for testpoints on the application startup.
+ */
+static void __attribute__((constructor)) lttng_testpoint_check(void)
+{
+ char *testpoint_env_val = NULL;
+
+ testpoint_env_val = getenv(lttng_testpoint_env_var);
+ if (testpoint_env_val != NULL
+ && (strncmp(testpoint_env_val, "1", 1) == 0)) {
+ lttng_testpoint_activated = 1;
+ }
+}
+
+/*
+ * Lookup a symbol by name.
+ *
+ * Return the address where the symbol is loaded or NULL if the symbol was not
+ * found.
+ */
+void *lttng_testpoint_lookup(const char *name)
+{
+ if (!name) {
+ return NULL;
+ }
+
+ return dlsym(RTLD_DEFAULT, name);
+}
+
+#endif /* NTESTPOINT */
--- /dev/null
+/*
+ * Copyright (C) 2012 - Christian Babeux <christian.babeux@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License, version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef NTESTPOINT
+
+#define testpoint(name)
+#define TESTPOINT_DECL(name)
+
+#else /* NTESTPOINT */
+
+#include <urcu.h> /* for caa_likely/unlikely */
+
+extern int lttng_testpoint_activated;
+
+void *lttng_testpoint_lookup(const char *name);
+
+/*
+ * Testpoint is only active if the global lttng_testpoint_activated flag is
+ * set.
+ */
+#define testpoint(name) \
+ do { \
+ if (caa_unlikely(lttng_testpoint_activated)) { \
+ __testpoint_##name##_wrapper(); \
+ } \
+ } while (0)
+
+/*
+ * One wrapper per testpoint is generated. This is to keep track of the symbol
+ * lookup status and the corresponding function pointer, if any.
+ */
+#define _TESTPOINT_DECL(_name) \
+ static inline void __testpoint_##_name##_wrapper(void) \
+ { \
+ static void (*tp)(void); \
+ static int found; \
+ const char *tp_name = "__testpoint_" #_name; \
+ \
+ if (tp) { \
+ tp(); \
+ } else { \
+ if (!found) { \
+ tp = lttng_testpoint_lookup(tp_name); \
+ if (tp) { \
+ found = 1; \
+ tp(); \
+ } else { \
+ found = -1; \
+ } \
+ } \
+ } \
+ }
+
+/* Testpoint declaration */
+#define TESTPOINT_DECL(name) \
+ _TESTPOINT_DECL(name)
+
+#endif /* NTESTPOINT */