summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut2006-07-24 16:32:45 +0000
committerPeter Eisentraut2006-07-24 16:32:45 +0000
commitb281dd1a1df459833f95b8da65c1975b914fe256 (patch)
tree5930263365dc84199cc20521d7768cd0d8dd79c3
parentaab521b2d09a6976219812169235e964489bd6f6 (diff)
DTrace support, with a small initial set of probes
by Robert Lor
-rwxr-xr-xconfigure83
-rw-r--r--configure.in11
-rw-r--r--doc/src/sgml/installation.sgml11
-rw-r--r--src/Makefile.global.in3
-rw-r--r--src/backend/Makefile12
-rw-r--r--src/backend/access/transam/xact.c6
-rw-r--r--src/backend/storage/lmgr/lock.c5
-rw-r--r--src/backend/storage/lmgr/lwlock.c10
-rw-r--r--src/backend/utils/probes.d24
-rw-r--r--src/include/c.h1
-rw-r--r--src/include/pg_config.h.in3
-rw-r--r--src/include/pg_trace.h56
12 files changed, 222 insertions, 3 deletions
diff --git a/configure b/configure
index af2bbe6a49..20084080c5 100755
--- a/configure
+++ b/configure
@@ -314,7 +314,7 @@ ac_includes_default="\
# include <unistd.h>
#endif"
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS configure_args build build_cpu build_vendor build_os host host_cpu host_vendor host_os PORTNAME docdir enable_nls WANTED_LANGUAGES default_port enable_shared enable_rpath enable_debug CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP GCC TAS autodepend INCLUDES enable_thread_safety with_tcl with_perl with_python with_krb5 krb_srvtab with_pam with_ldap with_bonjour with_openssl with_zlib EGREP ELF_SYS LDFLAGS_SL AWK FLEX FLEXFLAGS LN_S LD with_gnu_ld ld_R_works RANLIB ac_ct_RANLIB TAR STRIP ac_ct_STRIP STRIP_STATIC_LIB STRIP_SHARED_LIB YACC YFLAGS PERL perl_archlibexp perl_privlibexp perl_useshrplib perl_embed_ldflags PYTHON python_version python_configdir python_includespec python_libdir python_libspec python_additional_libs HAVE_IPV6 LIBOBJS acx_pthread_config PTHREAD_CC PTHREAD_LIBS PTHREAD_CFLAGS HAVE_POSIX_SIGNALS MSGFMT MSGMERGE XGETTEXT localedir TCLSH TCL_CONFIG_SH TCL_INCLUDE_SPEC TCL_LIB_FILE TCL_LIBS TCL_LIB_SPEC TCL_SHARED_BUILD TCL_SHLIB_LD_LIBS NSGMLS JADE have_docbook DOCBOOKSTYLE COLLATEINDEX SGMLSPL vpath_build LTLIBOBJS'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS configure_args build build_cpu build_vendor build_os host host_cpu host_vendor host_os PORTNAME docdir enable_nls WANTED_LANGUAGES default_port enable_shared enable_rpath enable_debug DTRACE DTRACEFLAGS enable_dtrace CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP GCC TAS autodepend INCLUDES enable_thread_safety with_tcl with_perl with_python with_krb5 krb_srvtab with_pam with_ldap with_bonjour with_openssl with_zlib EGREP ELF_SYS LDFLAGS_SL AWK FLEX FLEXFLAGS LN_S LD with_gnu_ld ld_R_works RANLIB ac_ct_RANLIB TAR STRIP ac_ct_STRIP STRIP_STATIC_LIB STRIP_SHARED_LIB YACC YFLAGS PERL perl_archlibexp perl_privlibexp perl_useshrplib perl_embed_ldflags PYTHON python_version python_configdir python_includespec python_libdir python_libspec python_additional_libs HAVE_IPV6 LIBOBJS acx_pthread_config PTHREAD_CC PTHREAD_LIBS PTHREAD_CFLAGS HAVE_POSIX_SIGNALS MSGFMT MSGMERGE XGETTEXT localedir TCLSH TCL_CONFIG_SH TCL_INCLUDE_SPEC TCL_LIB_FILE TCL_LIBS TCL_LIB_SPEC TCL_SHARED_BUILD TCL_SHLIB_LD_LIBS NSGMLS JADE have_docbook DOCBOOKSTYLE COLLATEINDEX SGMLSPL vpath_build LTLIBOBJS'
ac_subst_files=''
# Initialize some variables set by options.
@@ -865,6 +865,7 @@ Optional Features:
--disable-rpath do not embed shared library search path in executables
--disable-spinlocks do not use spinlocks
--enable-debug build with debugging symbols (-g)
+ --enable-dtrace build with DTrace support
--enable-depend turn on automatic dependency tracking
--enable-cassert enable assertion checks (for debugging)
--enable-thread-safety make client libraries thread-safe
@@ -1947,6 +1948,82 @@ fi;
#
+# DTrace
+#
+
+
+
+# Check whether --enable-dtrace or --disable-dtrace was given.
+if test "${enable_dtrace+set}" = set; then
+ enableval="$enable_dtrace"
+
+ case $enableval in
+ yes)
+
+cat >>confdefs.h <<\_ACEOF
+#define ENABLE_DTRACE 1
+_ACEOF
+
+for ac_prog in dtrace
+do
+ # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_DTRACE+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ if test -n "$DTRACE"; then
+ ac_cv_prog_DTRACE="$DTRACE" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_prog_DTRACE="$ac_prog"
+ echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+done
+
+fi
+fi
+DTRACE=$ac_cv_prog_DTRACE
+if test -n "$DTRACE"; then
+ echo "$as_me:$LINENO: result: $DTRACE" >&5
+echo "${ECHO_T}$DTRACE" >&6
+else
+ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+ test -n "$DTRACE" && break
+done
+
+
+ ;;
+ no)
+ :
+ ;;
+ *)
+ { { echo "$as_me:$LINENO: error: no argument expected for --enable-dtrace option" >&5
+echo "$as_me: error: no argument expected for --enable-dtrace option" >&2;}
+ { (exit 1); exit 1; }; }
+ ;;
+ esac
+
+else
+ enable_dtrace=no
+
+fi;
+
+
+
+#
# C compiler
#
@@ -22759,6 +22836,7 @@ enable_shared) ;;
enable_rpath) ;;
enable_spinlocks) ;;
enable_debug) ;;
+enable_dtrace) ;;
with_CC) ;;
enable_depend) ;;
enable_cassert) ;;
@@ -23431,6 +23509,9 @@ s,@default_port@,$default_port,;t t
s,@enable_shared@,$enable_shared,;t t
s,@enable_rpath@,$enable_rpath,;t t
s,@enable_debug@,$enable_debug,;t t
+s,@DTRACE@,$DTRACE,;t t
+s,@DTRACEFLAGS@,$DTRACEFLAGS,;t t
+s,@enable_dtrace@,$enable_dtrace,;t t
s,@CC@,$CC,;t t
s,@CFLAGS@,$CFLAGS,;t t
s,@LDFLAGS@,$LDFLAGS,;t t
diff --git a/configure.in b/configure.in
index 269dde7980..54bd0ae859 100644
--- a/configure.in
+++ b/configure.in
@@ -206,6 +206,17 @@ PGAC_ARG_BOOL(enable, debug, no,
AC_SUBST(enable_debug)
#
+# DTrace
+#
+PGAC_ARG_BOOL(enable, dtrace, no,
+ [ --enable-dtrace build with DTrace support],
+[AC_DEFINE([ENABLE_DTRACE], 1,
+ [Define to 1 to enable DTrace support. (--enable-dtrace)])
+AC_CHECK_PROGS(DTRACE, dtrace)
+AC_SUBST(DTRACEFLAGS)])
+AC_SUBST(enable_dtrace)
+
+#
# C compiler
#
diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index 5399f7af20..57a2796330 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -1007,6 +1007,17 @@ su - postgres
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--enable-dtrace</option></term>
+ <listitem>
+ <para>
+ Compiles with support for the dynamic tracing tool DTrace.
+ Operating system support for DTrace is currently only
+ available in Solaris.
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</para>
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index c3e3c4ab25..299bd4d531 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -157,6 +157,7 @@ enable_shared = @enable_shared@
enable_rpath = @enable_rpath@
enable_nls = @enable_nls@
enable_debug = @enable_debug@
+enable_dtrace = @enable_dtrace@
enable_thread_safety = @enable_thread_safety@
python_includespec = @python_includespec@
@@ -212,6 +213,8 @@ YACC = @YACC@
YFLAGS = @YFLAGS@
FLEX = @FLEX@
FLEXFLAGS = @FLEXFLAGS@ $(LFLAGS)
+DTRACE = @DTRACE@
+DTRACEFLAGS = @DTRACEFLAGS@
# Linking
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 433e34e3d0..2438ff69ca 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -19,7 +19,11 @@ DIRS := access bootstrap catalog parser commands executor lib libpq \
SUBSYSOBJS := $(DIRS:%=%/SUBSYS.o)
-OBJS := $(SUBSYSOBJS) $(top_builddir)/src/port/libpgport_srv.a
+ifeq ($(enable_dtrace), yes)
+LOCALOBJS += utils/probes.o
+endif
+
+OBJS = $(SUBSYSOBJS) $(LOCALOBJS) $(top_builddir)/src/port/libpgport_srv.a
# We put libpgport into OBJS, so remove it from LIBS
LIBS := $(filter-out -lpgport, $(LIBS))
@@ -135,6 +139,10 @@ $(top_builddir)/src/include/utils/fmgroids.h: utils/fmgroids.h
$(LN_S) ../../../$(subdir)/utils/fmgroids.h .
+utils/probes.o: utils/probes.d $(SUBSYSOBJS)
+ $(DTRACE) $(DTRACEFLAGS) -G -s $^
+
+
##########################################################################
distprep:
@@ -220,7 +228,7 @@ endif
##########################################################################
clean:
- rm -f postgres$(X) $(POSTGRES_IMP) \
+ rm -f $(LOCALOBJS) postgres$(X) $(POSTGRES_IMP) \
$(top_srcdir)/src/include/parser/parse.h \
$(top_builddir)/src/include/utils/fmgroids.h
ifeq ($(PORTNAME), cygwin)
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 3782f53d6c..246f76cf08 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -1384,6 +1384,8 @@ StartTransaction(void)
XactLockTableInsert(s->transactionId);
+ PG_TRACE1 (transaction__start, s->transactionId);
+
/*
* set transaction_timestamp() (a/k/a now()). We want this to be the
* same as the first command's statement_timestamp(), so don't do a
@@ -1535,6 +1537,8 @@ CommitTransaction(void)
LWLockRelease(ProcArrayLock);
}
+ PG_TRACE1 (transaction__commit, s->transactionId);
+
/*
* This is all post-commit cleanup. Note that if an error is raised here,
* it's too late to abort the transaction. This should be just
@@ -1931,6 +1935,8 @@ AbortTransaction(void)
LWLockRelease(ProcArrayLock);
}
+ PG_TRACE1 (transaction__abort, s->transactionId);
+
/*
* Post-abort cleanup. See notes in CommitTransaction() concerning
* ordering.
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index 0674f61f5b..18aeeec562 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -796,8 +796,13 @@ LockAcquire(const LOCKTAG *locktag,
/*
* Sleep till someone wakes me up.
*/
+
+ PG_TRACE2(lock__startwait, locktag->locktag_field2, lockmode);
+
WaitOnLock(locallock, owner);
+ PG_TRACE2(lock__endwait, locktag->locktag_field2, lockmode);
+
/*
* NOTE: do not do any material change of state between here and
* return. All required changes in locktable state must have been
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index d64b2551dd..f8b5392947 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -420,6 +420,8 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
block_counts[lockid]++;
#endif
+ PG_TRACE2(lwlock__startwait, lockid, mode);
+
for (;;)
{
/* "false" means cannot accept cancel/die interrupt here. */
@@ -429,6 +431,8 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
extraWaits++;
}
+ PG_TRACE2(lwlock__endwait, lockid, mode);
+
LOG_LWDEBUG("LWLockAcquire", lockid, "awakened");
/* Now loop back and try to acquire lock again. */
@@ -438,6 +442,8 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
/* We are done updating shared state of the lock itself. */
SpinLockRelease(&lock->mutex);
+ PG_TRACE2(lwlock__acquire, lockid, mode);
+
/* Add lock to list of locks held by this backend */
held_lwlocks[num_held_lwlocks++] = lockid;
@@ -507,11 +513,13 @@ LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode)
/* Failed to get lock, so release interrupt holdoff */
RESUME_INTERRUPTS();
LOG_LWDEBUG("LWLockConditionalAcquire", lockid, "failed");
+ PG_TRACE2(lwlock__condacquire__fail, lockid, mode);
}
else
{
/* Add lock to list of locks held by this backend */
held_lwlocks[num_held_lwlocks++] = lockid;
+ PG_TRACE2(lwlock__condacquire, lockid, mode);
}
return !mustwait;
@@ -596,6 +604,8 @@ LWLockRelease(LWLockId lockid)
/* We are done updating shared state of the lock itself. */
SpinLockRelease(&lock->mutex);
+ PG_TRACE1(lwlock__release, lockid);
+
/*
* Awaken any waiters I removed from the queue.
*/
diff --git a/src/backend/utils/probes.d b/src/backend/utils/probes.d
new file mode 100644
index 0000000000..ca39c2feef
--- /dev/null
+++ b/src/backend/utils/probes.d
@@ -0,0 +1,24 @@
+/* ----------
+ * DTrace probes for PostgreSQL backend
+ *
+ * Copyright (c) 2006, PostgreSQL Global Development Group
+ *
+ * $PostgreSQL$
+ * ----------
+ */
+
+provider postgresql {
+
+probe transaction__start(int);
+probe transaction__commit(int);
+probe transaction__abort(int);
+probe lwlock__acquire(int, int);
+probe lwlock__release(int);
+probe lwlock__startwait(int, int);
+probe lwlock__endwait(int, int);
+probe lwlock__condacquire(int, int);
+probe lwlock__condacquire__fail(int, int);
+probe lock__startwait(int, int);
+probe lock__endwait(int, int);
+
+};
diff --git a/src/include/c.h b/src/include/c.h
index 18311a0a4d..dca8a61198 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -56,6 +56,7 @@
#include "pg_config_os.h" /* must be before any system header files */
#endif
#include "postgres_ext.h"
+#include "pg_trace.h"
#if defined(_MSC_VER) || defined(__BORLANDC__)
#define WIN32_ONLY_COMPILER
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 82ccde63c1..e84205c9ea 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -36,6 +36,9 @@
/* Define to the default TCP port number as a string constant. */
#undef DEF_PGPORT_STR
+/* Define to 1 to enable DTrace support. (--enable-dtrace) */
+#undef ENABLE_DTRACE
+
/* Define to 1 if you want National Language Support. (--enable-nls) */
#undef ENABLE_NLS
diff --git a/src/include/pg_trace.h b/src/include/pg_trace.h
new file mode 100644
index 0000000000..f7677cfbc0
--- /dev/null
+++ b/src/include/pg_trace.h
@@ -0,0 +1,56 @@
+/* ----------
+ * pg_trace.h
+ *
+ * Definitions for the PostgreSQL tracing framework
+ *
+ * Copyright (c) 2006, PostgreSQL Global Development Group
+ *
+ * $PostgreSQL$
+ * ----------
+ */
+
+#ifndef PG_TRACE_H
+#define PG_TRACE_H
+
+#ifdef ENABLE_DTRACE
+
+#include <sys/sdt.h>
+
+/*
+ * The PG_TRACE macros are mapped to the appropriate macros used by DTrace.
+ *
+ * Only one DTrace provider called "postgresql" will be used for PostgreSQL,
+ * so the name is hard-coded here to avoid having to specify it in the
+ * source code.
+ */
+
+#define PG_TRACE(name) \
+ DTRACE_PROBE(postgresql, name)
+#define PG_TRACE1(name, arg1) \
+ DTRACE_PROBE1(postgresql, name, arg1)
+#define PG_TRACE2(name, arg1, arg2) \
+ DTRACE_PROBE2(postgresql, name, arg1, arg2)
+#define PG_TRACE3(name, arg1, arg2, arg3) \
+ DTRACE_PROBE3(postgresql, name, arg1, arg2, arg3)
+#define PG_TRACE4(name, arg1, arg2, arg3, arg4) \
+ DTRACE_PROBE4(postgresql, name, arg1, arg2, arg3, arg4)
+#define PG_TRACE5(name, arg1, arg2, arg3, arg4, arg5) \
+ DTRACE_PROBE5(postgresql, name, arg1, arg2, arg3, arg4, arg5)
+
+#else /* not ENABLE_DTRACE */
+
+/*
+ * Unless DTrace is explicitly enabled with --enable-dtrace, the PG_TRACE
+ * macros will expand to no-ops.
+ */
+
+#define PG_TRACE(name)
+#define PG_TRACE1(name, arg1)
+#define PG_TRACE2(name, arg1, arg2)
+#define PG_TRACE3(name, arg1, arg2, arg3)
+#define PG_TRACE4(name, arg1, arg2, arg3, arg4)
+#define PG_TRACE5(name, arg1, arg2, arg3, arg4, arg5)
+
+#endif /* not ENABLE_DTRACE */
+
+#endif /* PG_TRACE_H */