]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add support for User Statically Defined Tracing (USDT) probes
authorOndřej Surý <ondrej@isc.org>
Mon, 30 Jan 2023 14:36:49 +0000 (15:36 +0100)
committerOndřej Surý <ondrej@isc.org>
Mon, 21 Aug 2023 16:39:53 +0000 (18:39 +0200)
This adds support for User Statically Defined Tracing (USDT).  On
Linux, this uses the header from SystemTap and dtrace utility, but the
support is universal as long as dtrace is available.

Also add the required infrastructure to add probes to libisc, libdns and
libns libraries, where most of the probes will be.

18 files changed:
Makefile.am
Makefile.dtrace [new file with mode: 0644]
Makefile.top
bin/named/Makefile.am
configure.ac
doc/man/Makefile.am
doc/misc/Makefile.am
lib/dns/.gitignore
lib/dns/Makefile.am
lib/dns/probes.d [new file with mode: 0644]
lib/isc/.gitignore
lib/isc/Makefile.am
lib/isc/probes.d [new file with mode: 0644]
lib/ns/.gitignore [new file with mode: 0644]
lib/ns/Makefile.am
lib/ns/probes.d [new file with mode: 0644]
tests/dns/Makefile.am
util/dtrace.sh [new file with mode: 0755]

index 63bb88fd7b2707d7fd337b4ad0858fe158c530a5..df91934e037b10e75cd781d747283365b425abe9 100644 (file)
@@ -8,8 +8,8 @@ SUBDIRS += tests
 # run fuzz tests before system tests
 SUBDIRS += fuzz bin
 
-BUILT_SOURCES = bind.keys.h
-CLEANFILES = bind.keys.h
+BUILT_SOURCES += bind.keys.h
+CLEANFILES += bind.keys.h
 
 bind.keys.h: bind.keys Makefile
        ${PERL} ${top_srcdir}/util/bindkeys.pl ${top_srcdir}/bind.keys > $@
@@ -19,6 +19,7 @@ bind.keys.h: bind.keys Makefile
 EXTRA_DIST =                   \
        bind.keys               \
        util/bindkeys.pl        \
+       util/dtrace.sh          \
        contrib                 \
        CHANGES                 \
        COPYRIGHT               \
diff --git a/Makefile.dtrace b/Makefile.dtrace
new file mode 100644 (file)
index 0000000..ea15124
--- /dev/null
@@ -0,0 +1,18 @@
+# Hey Emacs, this is -*- makefile-automake -*- file!
+# vim: filetype=automake
+
+AM_V_DTRACE = $(AM_V_DTRACE_@AM_V@)
+AM_V_DTRACE_ = $(AM_V_DTRACE_@AM_DEFAULT_V@)
+AM_V_DTRACE_0 = @echo "  DTRACE   $@";
+
+BUILT_SOURCES += probes.h
+CLEANFILES += probes.h probes.o
+
+probes.h: probes.d
+       $(AM_V_DTRACE)$(DTRACE) -s $(srcdir)/probes.d -h -o $@
+probes.lo: probes.d $(DTRACE_DEPS)
+       $(AM_V_DTRACE)$(LIBTOOL) --mode=compile --tag=CC $(DTRACE) -s $(srcdir)/probes.d -G -o $@ $(DTRACE_OBJS)
+
+if HAVE_DTRACE
+DTRACE_LIBADD = probes.lo
+endif
index ffb63289a76fae7a8ce76ffbda502b3976868636..d01317dadb69f17922ffda8b7df15ab649c26af1 100644 (file)
@@ -15,6 +15,9 @@ AM_LDFLAGS =                                  \
        $(STD_LDFLAGS)
 LDADD =
 
+BUILT_SOURCES =
+CLEANFILES =
+
 if HOST_MACOS
 AM_LDFLAGS +=                                  \
        -Wl,-flat_namespace
@@ -26,6 +29,9 @@ LIBISC_CFLAGS =                                               \
        -I$(top_builddir)/lib/isc/include
 
 LIBISC_LIBS = $(top_builddir)/lib/isc/libisc.la
+if HAVE_DTRACE
+LIBISC_DTRACE = $(top_builddir)/lib/isc/probes.lo
+endif
 
 LIBDNS_CFLAGS = \
        -I$(top_srcdir)/lib/dns/include                 \
@@ -33,12 +39,18 @@ LIBDNS_CFLAGS = \
 
 LIBDNS_LIBS = \
        $(top_builddir)/lib/dns/libdns.la
+if HAVE_DTRACE
+LIBDNS_DTRACE = $(top_builddir)/lib/dns/probes.lo
+endif
 
 LIBNS_CFLAGS = \
        -I$(top_srcdir)/lib/ns/include
 
 LIBNS_LIBS = \
        $(top_builddir)/lib/ns/libns.la
+if HAVE_DTRACE
+LIBNS_DTRACE = $(top_builddir)/lib/ns/probes.lo
+endif
 
 LIBISCCFG_CFLAGS = \
        -I$(top_srcdir)/lib/isccfg/include
index 5c861b3ca6603086dd24f2bd91672f543134437d..291bab5e2a58f5a5841295f9542bb1d3b9c61af8 100644 (file)
@@ -38,8 +38,8 @@ AM_CPPFLAGS +=                                                \
 sbin_PROGRAMS = named
 
 nodist_named_SOURCES = xsl.c
-BUILT_SOURCES = xsl.c
-CLEANFILES = xsl.c
+BUILT_SOURCES += xsl.c
+CLEANFILES += xsl.c
 
 EXTRA_DIST = bind9.xsl
 
index 9455cf359ed7f8eb06086972f2ff278a4a4f2d9b..d14b2b3cbfeaebf39931f539decbaab1c13ee484 100644 (file)
@@ -1568,6 +1568,64 @@ AC_CHECK_HEADERS([glob.h])
 AX_GCC_FUNC_ATTRIBUTE([constructor])
 AX_GCC_FUNC_ATTRIBUTE([destructor])
 
+#
+# Check whether to enable User Statically Defined Tracing.
+#
+# This is supported only on Linux now and requires SystemTap libraries.
+#
+# [pairwise: --enable-tracing=auto, --enable-tracing=yes, --disable-tracing]
+AC_ARG_ENABLE([tracing],
+             [AS_HELP_STRING([--enable-tracing],
+                             [enable User Statically Defined Tracing])],
+             [],
+             [enable_tracing=auto])
+
+AC_ARG_VAR([DTRACE], [path to dtrace binary used to build User Statically Defined Tracing probes])
+AC_PATH_PROGS([DTRACE], [dtrace])
+AC_CHECK_HEADERS([sys/sdt.h])
+
+AC_MSG_CHECKING([whether to enable User Statically Defined Tracing support (default is auto)])
+AS_CASE([$enable_tracing],
+       [auto], [enable_tracing=yes
+                AS_IF([test "$ac_cv_header_sys_sdt_h" != "yes"], [enable_tracing=no])
+                AS_IF([test -z "$DTRACE"],[enable_tracing=no])
+                AC_COMPILE_IFELSE(
+                  [AC_LANG_PROGRAM([[]],
+                                   [[#if !defined(__has_feature)
+                                     #define __has_feature(x) 0
+                                     #endif /* if !defined(__has_feature) */
+                                     #if __has_feature(address_sanitizer)
+                                     #define __SANITIZE_ADDRESS__ 1
+                                     #endif /* if __has_feature(address_sanitizer) */
+                                     #if defined(__SANITIZE_ADDRESS__)
+                                     #error Address Sanitizer enabled
+                                     #endif
+                                    ]])],
+                  [],
+                  [enable_tracing=no]
+                )])
+AS_CASE([$enable_tracing],
+       [yes], [AS_IF([test "$ac_cv_header_sys_sdt_h" != "yes"],
+                     [AC_MSG_ERROR([sys/sdt.h header not found])])
+               AS_IF([test -z "$DTRACE"],
+                     [AC_MSG_ERROR([The dtrace command not found])])
+               AC_MSG_RESULT([yes])],
+       [DTRACE=""
+        AC_MSG_RESULT([no])])
+
+AS_CASE([$host],
+       [*-linux*],[have_systemtap=true])
+
+AM_CONDITIONAL([HAVE_SYSTEMTAP], [test -n "$have_systemtap"])
+AM_CONDITIONAL([HAVE_DTRACE], [test -n "$DTRACE"])
+
+# Use shim script if dtrace is not available
+AS_IF([test -z "$DTRACE"],
+      [DTRACE='$(top_srcdir)/util/dtrace.sh'])
+
+AC_SUBST([DTRACE])
+
+
 #
 # Files to configure.  These are listed here because we used to
 # specify them as arguments to AC_OUTPUT.
index d814b028d8992ce689960823f8980eb2d52868d0..2590e20da6d5d8196ee5c245c01a679e83e6d5a2 100644 (file)
@@ -123,7 +123,7 @@ EXTRA_DIST =                                \
        $(MANPAGES_RST)                 \
        $(MANPAGES_IN)
 
-CLEANFILES                           \
+CLEANFILES +=                          \
        $(man_MANS)
 
 #
index d613981855ff6b4ea42dd730c8bfbe4edc1b4282..898aa8f08b7c490c4cc2ac0992247a25e10b0bce 100644 (file)
@@ -37,7 +37,7 @@ cfg_test_LDADD =                      \
        $(LIBDNS_LIBS)                  \
        $(LIBISCCFG_LIBS)
 
-BUILT_SOURCES                                \
+BUILT_SOURCES +=                               \
        $(OPTIONS_FILES)
 
 rndc.grammar: cfg_test
index 66c95ddd79a93a87983c62c2d1fe02c270d0a812..b41f1dc49198b8325fd9285f41fb7490c39c0302 100644 (file)
@@ -6,4 +6,5 @@ enumtype.h
 rdatastruct.h
 gen.dSYM
 dnstap.pb-c.c
-dnstap.pb-c.h
\ No newline at end of file
+dnstap.pb-c.h
+/probes.h
index 9e0eeeb9e1d6a033832b78bb5f17a921390649e2..865a29f06a64f094b6babe6bf13a3dededd8a90d 100644 (file)
@@ -12,10 +12,10 @@ nodist_libdns_la_SOURCES =          \
        $(nodist_libdns_la_HEADERS)     \
        code.h
 
-BUILT_SOURCES =                                \
+BUILT_SOURCES +=                       \
        $(nodist_libdns_la_SOURCES)
 
-CLEANFILES                           \
+CLEANFILES +=                          \
        $(nodist_libdns_la_SOURCES)     \
        gen$(BUILD_EXEEXT)
 
@@ -124,6 +124,7 @@ libdns_la_HEADERS =                 \
        include/dns/ssu.h               \
        include/dns/stats.h             \
        include/dns/time.h              \
+       include/dns/trace.h             \
        include/dns/transport.h         \
        include/dns/tkey.h              \
        include/dns/trace.h             \
@@ -208,6 +209,7 @@ libdns_la_SOURCES =                 \
        order.c                         \
        peer.c                          \
        private.c                       \
+       probes.d                        \
        qp.c                            \
        qp_p.h                          \
        rbt.c                           \
@@ -330,3 +332,12 @@ if HAVE_LMDB
 libdns_la_CPPFLAGS += $(LMDB_CFLAGS)
 libdns_la_LIBADD += $(LMDB_LIBS)
 endif
+
+if !HAVE_SYSTEMTAP
+DTRACE_DEPS = libdns_la-xfrin.lo
+DTRACE_OBJS = .libs/libdns_la-xfrin.$(OBJEXT)
+endif
+
+include $(top_srcdir)/Makefile.dtrace
+
+libdns_la_LIBADD += $(DTRACE_LIBADD)
diff --git a/lib/dns/probes.d b/lib/dns/probes.d
new file mode 100644 (file)
index 0000000..056d9e6
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * SPDX-License-Identifier: MPL-2.0
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+provider libdns {
+};
index 734ffcd9b4ef62d4bb58f625d078a8b315cb9fe5..d71e8426645a7959b0d52823e3ade5b930f6abf7 100644 (file)
@@ -1 +1,2 @@
 !netdb.h
+/probes.h
index df2d327213ea6cf308e34d3a6c6b88d667da593b..0f692d32c6c497e6276254bbfbe9921499b293a0 100644 (file)
@@ -171,6 +171,7 @@ libisc_la_SOURCES =         \
        picohttpparser.c        \
        picohttpparser.h        \
        portset.c               \
+       probes.d                \
        quota.c                 \
        radix.c                 \
        random.c                \
@@ -256,3 +257,12 @@ libisc_la_CPPFLAGS +=              \
 libisc_la_LIBADD +=            \
        $(LIBXML2_LIBS)
 endif HAVE_LIBXML2
+
+if !HAVE_SYSTEMTAP
+DTRACE_DEPS = libisc_la-rwlock.lo libisc_la-job.lo
+DTRACE_OBJS = .libs/libisc_la-rwlock.$(OBJEXT) .libs/libisc_la-job.$(OBJEXT)
+endif
+
+include $(top_srcdir)/Makefile.dtrace
+
+libisc_la_LIBADD += $(DTRACE_LIBADD)
diff --git a/lib/isc/probes.d b/lib/isc/probes.d
new file mode 100644 (file)
index 0000000..bc587ed
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * SPDX-License-Identifier: MPL-2.0
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+provider libisc {
+};
diff --git a/lib/ns/.gitignore b/lib/ns/.gitignore
new file mode 100644 (file)
index 0000000..1d0e72d
--- /dev/null
@@ -0,0 +1 @@
+/probes.h
index 37274babe55bf03c6f5688b18e76476688c6b6eb..39b64a76b3728eb4f52b5c737076875486738fe5 100644 (file)
@@ -30,6 +30,7 @@ libns_la_SOURCES =            \
        listenlist.c            \
        log.c                   \
        notify.c                \
+       probes.d                \
        query.c                 \
        server.c                \
        sortlist.c              \
@@ -54,3 +55,12 @@ libns_la_LIBADD =    \
 libns_la_LDFLAGS =             \
        $(AM_LDFLAGS)           \
        -release "$(PACKAGE_VERSION)"
+
+if !HAVE_SYSTEMTAP
+DTRACE_DEPS = libns_la-query.lo
+DTRACE_OBJS = .libs/libns_la-query.$(OBJEXT)
+endif
+
+include $(top_srcdir)/Makefile.dtrace
+
+libns_la_LIBADD += $(DTRACE_LIBADD)
diff --git a/lib/ns/probes.d b/lib/ns/probes.d
new file mode 100644 (file)
index 0000000..316ca37
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * SPDX-License-Identifier: MPL-2.0
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+provider libns {
+};
index da775f4995f869b70c1e47f7eaceed1cafb29889..aa9f1ea74462b8dd12f193b8e97eb79bc11359f3 100644 (file)
@@ -48,8 +48,6 @@ check_PROGRAMS =              \
        zonemgr_test            \
        zt_test
 
-CLEANFILES =
-
 if HAVE_PERL
 
 check_PROGRAMS +=              \
diff --git a/util/dtrace.sh b/util/dtrace.sh
new file mode 100755 (executable)
index 0000000..a9da900
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0.  If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+USAGE="# Usage: ${0} [-h | -G] -s File.d [-o <File>]"
+
+mode=
+while getopts hGs:o: opt; do
+       case "${opt}" in
+               h) mode=header ;;
+               s) input=$OPTARG ;;
+               o) output=$OPTARG ;;
+               G) mode=object ;;
+               \?) echo $USAGE; exit 1;;
+       esac
+done
+shift $((OPTIND - 1))
+
+if test -z "${mode}" || test -z "${input}"; then
+       echo $USAGE; exit 1;
+fi
+
+case "${mode}" in
+       header)
+               if test -z "${output}"; then
+                       output="$(basename "${input}" .d).h"
+               fi
+               PROVIDER=$(cat "${input}" | sed -ne 's/^provider \(.*\) {/\1/p' | tr "a-z" "A-Z")
+               sed -ne 's/.*probe \(.*\)(.*);/\1/p' "${input}" | tr "a-z" "A-Z" | while read PROBE; do
+                       echo "#define ${PROVIDER}_${PROBE}_ENABLED() 0";
+                       echo "#define ${PROVIDER}_${PROBE}(...)";
+               done > "${output}"
+               ;;
+       object)
+               if test -z "${output}"; then
+                       output="$(basename "${input}" .d).o"
+               fi
+               echo "extern int empty;" | gcc -xc -c - -fPIC -DPIC  -o "${output}"
+               ;;
+esac