summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@nvidia.com>2020-09-28 17:22:53 -0400
committerQuentin Young <qlyoung@nvidia.com>2020-10-23 15:13:51 -0400
commit552e2a306a3b3335ee60965bbcd61c27eecc576d (patch)
tree7bc84d1121c84f56b02027cbdedde6ce09ce3c6e
parent912d45a1610dc7ec14017a2d8618ad357e89370e (diff)
lib: add trace.h, frrtrace(), support for USDT
Previous commits added LTTng tracepoints. This was primarily for testing / trial purposes; in practice we'd like to support arbitrary tracing methods, and especially USDT probes, which SystemTap and dtrace expect, and which are supported on at least one flavor of BSD (FreeBSD). To that end this patch adds an frr-specific tracing macro, frrtrace(), which proxies into either DTRACE_PROBEn() or tracepoint() macros depending on whether --enable-usdt or --enable-lttng is passed at compile time. At some point this could be tweaked to allow compiling in both types of probes. Ideally there should be some logic there to use LTTng's optional support for generating USDT probes when both are requested. No additional libraries are required to use USDT, since these probes are a kernel feature and only need the <sys/sdt.h> header. - add --enable-usdt to toggle use of LTTng tracepoints or USDT probes - add new trace.h library header for use with tracepoint definition headers - add frrtrace() wrapper macro; this should be used to define tracepoints instead of using tracepoint() or DTRACE_PROBEn() Compilation with USDT does nothing as of this commit; the existing LTTng tracepoints need to be converted to use the frrtrace*() macros in a subsequent commit. Signed-off-by: Quentin Young <qlyoung@nvidia.com>
-rwxr-xr-xconfigure.ac14
-rw-r--r--lib/subdir.am1
-rw-r--r--lib/trace.h80
3 files changed, 95 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 3ed7eabc72..bda9a34504 100755
--- a/configure.ac
+++ b/configure.ac
@@ -568,6 +568,8 @@ AC_ARG_ENABLE([zeromq],
AS_HELP_STRING([--enable-zeromq], [enable ZeroMQ handler (libfrrzmq)]))
AC_ARG_ENABLE([lttng],
AS_HELP_STRING([--enable-lttng], [enable LTTng tracing]))
+AC_ARG_ENABLE([usdt],
+ AS_HELP_STRING([--enable-usdt], [enable USDT probes]))
AC_ARG_WITH([libpam],
AS_HELP_STRING([--with-libpam], [use libpam for PAM support in vtysh]))
AC_ARG_ENABLE([ospfapi],
@@ -1865,6 +1867,18 @@ if test "$enable_lttng" = "yes"; then
])
fi
+dnl ----
+dnl USDT
+dnl ----
+if test "$enable_usdt" = "yes"; then
+ AC_CHECK_HEADERS([sys/sdt.h], [
+ AC_DEFINE([HAVE_USDT], [1], [Enable USDT probes])
+ USDT=true
+ ], [
+ AC_MSG_ERROR([configuration specifies --enable-usdt but no USDT kernel headers (sys/sdt.h) found])
+ ])
+fi
+
dnl ------
dnl ZeroMQ
dnl ------
diff --git a/lib/subdir.am b/lib/subdir.am
index 5c371f2cc9..ed3c30799d 100644
--- a/lib/subdir.am
+++ b/lib/subdir.am
@@ -253,6 +253,7 @@ pkginclude_HEADERS += \
lib/table.h \
lib/termtable.h \
lib/thread.h \
+ lib/trace.h \
lib/typerb.h \
lib/typesafe.h \
lib/vector.h \
diff --git a/lib/trace.h b/lib/trace.h
new file mode 100644
index 0000000000..73fc10a556
--- /dev/null
+++ b/lib/trace.h
@@ -0,0 +1,80 @@
+/* Tracing macros
+ *
+ * Wraps tracepoint macros for different tracing systems to allow switching
+ * between them at compile time.
+ *
+ * This should not be included directly by source files wishing to provide
+ * tracepoints. Instead, write a header that defines LTTng tracepoints and
+ * which includes this header, and include your new header in your source. USDT
+ * probes do not need tracepoint definitions, but are less capable than LTTng
+ * tracepoints.
+ *
+ * Copyright (C) 2020 NVIDIA Corporation
+ * Quentin Young
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * 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; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _TRACE_H_
+#define _TRACE_H_
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+/*
+ * Provided here:
+ * - frrtrace(n, provider, name, ...args...)
+ * - frrtrace_enabled(provider, name)
+ * - frrtracelog(level, msg, ...)
+ *
+ * Use frrtrace() to define tracepoints. n is the number of arguments; this is
+ * needed because USDT probe definitions use DTRACE_PROBEn macros, so the
+ * number of args must be passed in order to expand the correct macro.
+ *
+ * frrtrace_enabled() maps to tracepoint_enabled() under LTTng and is always
+ * true when using USDT. In the future it could be mapped to USDT semaphores
+ * but this is not implemented at present.
+ *
+ * frrtracelog() maps to tracelog() under LTTng and should only be used in zlog
+ * core code, to propagate zlog messages to LTTng. It expands to nothing
+ * otherwise.
+ */
+
+#if defined(HAVE_LTTNG)
+
+#define frrtrace(nargs, provider, name, ...) \
+ tracepoint(provider, name, ## __VA_ARGS__)
+#define frrtrace_enabled(...) tracepoint_enabled(__VA_ARGS__)
+#define frrtracelog(...) tracelog(__VA_ARGS__)
+
+#elif defined(HAVE_USDT)
+
+#include "sys/sdt.h"
+
+#define frrtrace(nargs, provider, name, ...) \
+ DTRACE_PROBE##nargs(provider, name, ## __VA_ARGS__)
+#define frrtrace_enabled(...) true
+#define frrtracelog(...)
+
+#else
+
+#define frrtrace(nargs, provider, name, ...) (void)0
+#define frrtrace_enabled(...) false
+#define frrtracelog(...) (void)0
+
+#endif
+
+#endif /* _TRACE_H_ */