Skip to content

Commit 784d055

Browse files
committed
Add support for User Statically Defined Tracing (USDT) probes
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.
1 parent 1e16d41 commit 784d055

File tree

18 files changed

+226
-11
lines changed

18 files changed

+226
-11
lines changed

Makefile.am

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ SUBDIRS += tests
88
# run fuzz tests before system tests
99
SUBDIRS += fuzz bin
1010

11-
BUILT_SOURCES = bind.keys.h
12-
CLEANFILES = bind.keys.h
11+
BUILT_SOURCES += bind.keys.h
12+
CLEANFILES += bind.keys.h
1313

1414
bind.keys.h: bind.keys Makefile
1515
${PERL} ${top_srcdir}/util/bindkeys.pl ${top_srcdir}/bind.keys > $@
@@ -19,6 +19,7 @@ bind.keys.h: bind.keys Makefile
1919
EXTRA_DIST = \
2020
bind.keys \
2121
util/bindkeys.pl \
22+
util/dtrace.sh \
2223
contrib \
2324
CHANGES \
2425
COPYRIGHT \

Makefile.dtrace

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Hey Emacs, this is -*- makefile-automake -*- file!
2+
# vim: filetype=automake
3+
4+
AM_V_DTRACE = $(AM_V_DTRACE_@AM_V@)
5+
AM_V_DTRACE_ = $(AM_V_DTRACE_@AM_DEFAULT_V@)
6+
AM_V_DTRACE_0 = @echo " DTRACE $@";
7+
8+
BUILT_SOURCES += probes.h
9+
CLEANFILES += probes.h probes.o
10+
11+
probes.h: probes.d
12+
$(AM_V_DTRACE)$(DTRACE) -s $(srcdir)/probes.d -h -o $@
13+
probes.lo: probes.d $(DTRACE_DEPS)
14+
$(AM_V_DTRACE)$(LIBTOOL) --mode=compile --tag=CC $(DTRACE) -s $(srcdir)/probes.d -G -o $@ $(DTRACE_OBJS)
15+
16+
if HAVE_DTRACE
17+
DTRACE_LIBADD = probes.lo
18+
endif

Makefile.top

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ AM_LDFLAGS = \
1515
$(STD_LDFLAGS)
1616
LDADD =
1717

18+
BUILT_SOURCES =
19+
CLEANFILES =
20+
1821
if HOST_MACOS
1922
AM_LDFLAGS += \
2023
-Wl,-flat_namespace
@@ -26,19 +29,28 @@ LIBISC_CFLAGS = \
2629
-I$(top_builddir)/lib/isc/include
2730

2831
LIBISC_LIBS = $(top_builddir)/lib/isc/libisc.la
32+
if HAVE_DTRACE
33+
LIBISC_DTRACE = $(top_builddir)/lib/isc/probes.lo
34+
endif
2935

3036
LIBDNS_CFLAGS = \
3137
-I$(top_srcdir)/lib/dns/include \
3238
-I$(top_builddir)/lib/dns/include
3339

3440
LIBDNS_LIBS = \
3541
$(top_builddir)/lib/dns/libdns.la
42+
if HAVE_DTRACE
43+
LIBDNS_DTRACE = $(top_builddir)/lib/dns/probes.lo
44+
endif
3645

3746
LIBNS_CFLAGS = \
3847
-I$(top_srcdir)/lib/ns/include
3948

4049
LIBNS_LIBS = \
4150
$(top_builddir)/lib/ns/libns.la
51+
if HAVE_DTRACE
52+
LIBNS_DTRACE = $(top_builddir)/lib/ns/probes.lo
53+
endif
4254

4355
LIBISCCFG_CFLAGS = \
4456
-I$(top_srcdir)/lib/isccfg/include

bin/named/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ AM_CPPFLAGS += \
3838
sbin_PROGRAMS = named
3939

4040
nodist_named_SOURCES = xsl.c
41-
BUILT_SOURCES = xsl.c
42-
CLEANFILES = xsl.c
41+
BUILT_SOURCES += xsl.c
42+
CLEANFILES += xsl.c
4343

4444
EXTRA_DIST = bind9.xsl
4545

configure.ac

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,64 @@ AC_CHECK_HEADERS([glob.h])
15681568
AX_GCC_FUNC_ATTRIBUTE([constructor])
15691569
AX_GCC_FUNC_ATTRIBUTE([destructor])
15701570

1571+
#
1572+
# Check whether to enable User Statically Defined Tracing.
1573+
#
1574+
# This is supported only on Linux now and requires SystemTap libraries.
1575+
#
1576+
# [pairwise: --enable-tracing=auto, --enable-tracing=yes, --disable-tracing]
1577+
AC_ARG_ENABLE([tracing],
1578+
[AS_HELP_STRING([--enable-tracing],
1579+
[enable User Statically Defined Tracing])],
1580+
[],
1581+
[enable_tracing=auto])
1582+
1583+
AC_ARG_VAR([DTRACE], [path to dtrace binary used to build User Statically Defined Tracing probes])
1584+
AC_PATH_PROGS([DTRACE], [dtrace])
1585+
AC_CHECK_HEADERS([sys/sdt.h])
1586+
1587+
AC_MSG_CHECKING([whether to enable User Statically Defined Tracing support (default is auto)])
1588+
AS_CASE([$enable_tracing],
1589+
[auto], [enable_tracing=yes
1590+
AS_IF([test "$ac_cv_header_sys_sdt_h" != "yes"], [enable_tracing=no])
1591+
AS_IF([test -z "$DTRACE"],[enable_tracing=no])
1592+
AC_COMPILE_IFELSE(
1593+
[AC_LANG_PROGRAM([[]],
1594+
[[#if !defined(__has_feature)
1595+
#define __has_feature(x) 0
1596+
#endif /* if !defined(__has_feature) */
1597+
#if __has_feature(address_sanitizer)
1598+
#define __SANITIZE_ADDRESS__ 1
1599+
#endif /* if __has_feature(address_sanitizer) */
1600+
#if defined(__SANITIZE_ADDRESS__)
1601+
#error Address Sanitizer enabled
1602+
#endif
1603+
]])],
1604+
[],
1605+
[enable_tracing=no]
1606+
)])
1607+
AS_CASE([$enable_tracing],
1608+
[yes], [AS_IF([test "$ac_cv_header_sys_sdt_h" != "yes"],
1609+
[AC_MSG_ERROR([sys/sdt.h header not found])])
1610+
AS_IF([test -z "$DTRACE"],
1611+
[AC_MSG_ERROR([The dtrace command not found])])
1612+
AC_MSG_RESULT([yes])],
1613+
[DTRACE=""
1614+
AC_MSG_RESULT([no])])
1615+
1616+
AS_CASE([$host],
1617+
[*-linux*],[have_systemtap=true])
1618+
1619+
AM_CONDITIONAL([HAVE_SYSTEMTAP], [test -n "$have_systemtap"])
1620+
AM_CONDITIONAL([HAVE_DTRACE], [test -n "$DTRACE"])
1621+
1622+
# Use shim script if dtrace is not available
1623+
AS_IF([test -z "$DTRACE"],
1624+
[DTRACE='$(top_srcdir)/util/dtrace.sh'])
1625+
1626+
AC_SUBST([DTRACE])
1627+
1628+
15711629
#
15721630
# Files to configure. These are listed here because we used to
15731631
# specify them as arguments to AC_OUTPUT.

doc/man/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ EXTRA_DIST = \
123123
$(MANPAGES_RST) \
124124
$(MANPAGES_IN)
125125

126-
CLEANFILES = \
126+
CLEANFILES += \
127127
$(man_MANS)
128128

129129
#

doc/misc/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ cfg_test_LDADD = \
3737
$(LIBDNS_LIBS) \
3838
$(LIBISCCFG_LIBS)
3939

40-
BUILT_SOURCES = \
40+
BUILT_SOURCES += \
4141
$(OPTIONS_FILES)
4242

4343
rndc.grammar: cfg_test

lib/dns/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ enumtype.h
66
rdatastruct.h
77
gen.dSYM
88
dnstap.pb-c.c
9-
dnstap.pb-c.h
9+
dnstap.pb-c.h
10+
/probes.h

lib/dns/Makefile.am

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ nodist_libdns_la_SOURCES = \
1212
$(nodist_libdns_la_HEADERS) \
1313
code.h
1414

15-
BUILT_SOURCES = \
15+
BUILT_SOURCES += \
1616
$(nodist_libdns_la_SOURCES)
1717

18-
CLEANFILES = \
18+
CLEANFILES += \
1919
$(nodist_libdns_la_SOURCES) \
2020
gen$(BUILD_EXEEXT)
2121

@@ -124,6 +124,7 @@ libdns_la_HEADERS = \
124124
include/dns/ssu.h \
125125
include/dns/stats.h \
126126
include/dns/time.h \
127+
include/dns/trace.h \
127128
include/dns/transport.h \
128129
include/dns/tkey.h \
129130
include/dns/trace.h \
@@ -208,6 +209,7 @@ libdns_la_SOURCES = \
208209
order.c \
209210
peer.c \
210211
private.c \
212+
probes.d \
211213
qp.c \
212214
qp_p.h \
213215
rbt.c \
@@ -330,3 +332,12 @@ if HAVE_LMDB
330332
libdns_la_CPPFLAGS += $(LMDB_CFLAGS)
331333
libdns_la_LIBADD += $(LMDB_LIBS)
332334
endif
335+
336+
if !HAVE_SYSTEMTAP
337+
DTRACE_DEPS = libdns_la-xfrin.lo
338+
DTRACE_OBJS = .libs/libdns_la-xfrin.$(OBJEXT)
339+
endif
340+
341+
include $(top_srcdir)/Makefile.dtrace
342+
343+
libdns_la_LIBADD += $(DTRACE_LIBADD)

lib/dns/probes.d

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3+
*
4+
* SPDX-License-Identifier: MPL-2.0
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
9+
*
10+
* See the COPYRIGHT file distributed with this work for additional
11+
* information regarding copyright ownership.
12+
*/
13+
14+
provider libdns {
15+
};

0 commit comments

Comments
 (0)