Enable probes to work with Mac OS X Leopard and other OSes that will
authorPeter Eisentraut <peter_e@gmx.net>
Mon, 17 Mar 2008 19:44:41 +0000 (19:44 +0000)
committerPeter Eisentraut <peter_e@gmx.net>
Mon, 17 Mar 2008 19:44:41 +0000 (19:44 +0000)
support DTrace in the future.

Switch from using DTRACE_PROBEn macros to the dynamically generated macros.
Use "dtrace -h" to create a header file that contains the dynamically
generated macros to be used in the source code instead of the DTRACE_PROBEn
macros.  A dummy header file is generated for builds without DTrace support.

Author: Robert Lor <Robert.Lor@sun.com>

src/backend/Makefile
src/backend/access/transam/xact.c
src/backend/storage/lmgr/lock.c
src/backend/storage/lmgr/lwlock.c
src/backend/utils/Gen_dummy_probes.sed [new file with mode: 0644]
src/backend/utils/Makefile
src/include/Makefile
src/include/c.h
src/include/pg_trace.h

index 78511b83b39e2e3716ad6f0ac2990e2f8ccb4224..0f175ca288a6a05d95f0b7372cfe7cd12b538243 100644 (file)
@@ -20,9 +20,11 @@ SUBDIRS = access bootstrap catalog parser commands executor lib libpq \
 
 include $(srcdir)/common.mk
 
+ifeq ($(PORTNAME), solaris)
 ifeq ($(enable_dtrace), yes)
 LOCALOBJS += utils/probes.o
 endif
+endif
 
 OBJS = $(SUBDIROBJS) $(LOCALOBJS) $(top_builddir)/src/port/libpgport_srv.a
 
@@ -103,7 +105,7 @@ endif
 endif # aix
 
 # Update the commonly used headers before building the subdirectories
-$(SUBDIRS:%=%-recursive): $(top_builddir)/src/include/parser/parse.h $(top_builddir)/src/include/utils/fmgroids.h
+$(SUBDIRS:%=%-recursive): $(top_builddir)/src/include/parser/parse.h $(top_builddir)/src/include/utils/fmgroids.h $(top_builddir)/src/include/utils/probes.h
 
 
 # The postgres.o target is needed by the rule in Makefile.global that
@@ -122,6 +124,9 @@ $(srcdir)/parser/parse.h: parser/gram.y
 utils/fmgroids.h: utils/Gen_fmgrtab.sh $(top_srcdir)/src/include/catalog/pg_proc.h
        $(MAKE) -C utils fmgroids.h
 
+utils/probes.h: utils/probes.d
+       $(MAKE) -C utils probes.h
+
 # Make symlinks for these headers in the include directory. That way
 # we can cut down on the -I options. Also, a symlink is automatically
 # up to date when we update the base file.
@@ -135,9 +140,15 @@ $(top_builddir)/src/include/utils/fmgroids.h: utils/fmgroids.h
        cd $(dir $@) && rm -f $(notdir $@) && \
            $(LN_S) ../../../$(subdir)/utils/fmgroids.h .
 
+$(top_builddir)/src/include/utils/probes.h: utils/probes.h
+       cd $(dir $@) && rm -f $(notdir $@) && \
+           $(LN_S) ../../../$(subdir)/utils/probes.h .
 
+
+ifeq ($(PORTNAME), solaris)
 utils/probes.o: utils/probes.d $(SUBDIROBJS)
        $(DTRACE) $(DTRACEFLAGS) -G -s $(call expand_subsys,$^) -o $@
+endif
 
 
 ##########################################################################
index 14f3d56ff97fbfea74e5e67c86cee44facc38146..16f51799a2e9f42c08d61e272a94bd7ff0304cd0 100644 (file)
@@ -46,6 +46,7 @@
 #include "utils/memutils.h"
 #include "utils/relcache.h"
 #include "utils/xml.h"
+#include "pg_trace.h"
 
 
 /*
@@ -1547,7 +1548,7 @@ StartTransaction(void)
        Assert(MyProc->backendId == vxid.backendId);
        MyProc->lxid = vxid.localTransactionId;
 
-       PG_TRACE1(transaction__start, vxid.localTransactionId);
+       TRACE_POSTGRESQL_TRANSACTION_START(vxid.localTransactionId);
 
        /*
         * set transaction_timestamp() (a/k/a now()).  We want this to be the same
@@ -1674,7 +1675,7 @@ CommitTransaction(void)
         */
        latestXid = RecordTransactionCommit();
 
-       PG_TRACE1(transaction__commit, MyProc->lxid);
+       TRACE_POSTGRESQL_TRANSACTION_COMMIT(MyProc->lxid);
 
        /*
         * Let others know about no transaction in progress by me. Note that this
@@ -2084,7 +2085,7 @@ AbortTransaction(void)
         */
        latestXid = RecordTransactionAbort(false);
 
-       PG_TRACE1(transaction__abort, MyProc->lxid);
+       TRACE_POSTGRESQL_TRANSACTION_ABORT(MyProc->lxid);
 
        /*
         * Let others know about no transaction in progress by me. Note that this
index 2f821d0b1220e658f5edd42dbc47525ecdbe94e3..c07bb5c848cb3e8dac8006d7343485a9484957ec 100644 (file)
@@ -40,6 +40,7 @@
 #include "utils/memutils.h"
 #include "utils/ps_status.h"
 #include "utils/resowner.h"
+#include "pg_trace.h"
 
 
 /* This configuration variable is used to set the lock table size */
@@ -786,11 +787,11 @@ LockAcquire(const LOCKTAG *locktag,
                 * Sleep till someone wakes me up.
                 */
 
-               PG_TRACE2(lock__startwait, locktag->locktag_field2, lockmode);
+               TRACE_POSTGRESQL_LOCK_STARTWAIT(locktag->locktag_field2, lockmode);
 
                WaitOnLock(locallock, owner);
 
-               PG_TRACE2(lock__endwait, locktag->locktag_field2, lockmode);
+               TRACE_POSTGRESQL_LOCK_ENDWAIT(locktag->locktag_field2, lockmode);
 
                /*
                 * NOTE: do not do any material change of state between here and
index d5f61e55ea39a6baad458956a8797247bd1b837e..9aea776c26900f7e36fbfde6a57a46631eb51782 100644 (file)
@@ -28,6 +28,7 @@
 #include "storage/ipc.h"
 #include "storage/proc.h"
 #include "storage/spin.h"
+#include "pg_trace.h"
 
 
 /* We use the ShmemLock spinlock to protect LWLockAssign */
@@ -447,7 +448,7 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
                block_counts[lockid]++;
 #endif
 
-               PG_TRACE2(lwlock__startwait, lockid, mode);
+               TRACE_POSTGRESQL_LWLOCK_STARTWAIT(lockid, mode);
 
                for (;;)
                {
@@ -458,7 +459,7 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
                        extraWaits++;
                }
 
-               PG_TRACE2(lwlock__endwait, lockid, mode);
+               TRACE_POSTGRESQL_LWLOCK_ENDWAIT(lockid, mode);
 
                LOG_LWDEBUG("LWLockAcquire", lockid, "awakened");
 
@@ -469,7 +470,7 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
        /* We are done updating shared state of the lock itself. */
        SpinLockRelease(&lock->mutex);
 
-       PG_TRACE2(lwlock__acquire, lockid, mode);
+       TRACE_POSTGRESQL_LWLOCK_ACQUIRE(lockid, mode);
 
        /* Add lock to list of locks held by this backend */
        held_lwlocks[num_held_lwlocks++] = lockid;
@@ -540,13 +541,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);
+               TRACE_POSTGRESQL_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);
+               TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE(lockid, mode);
        }
 
        return !mustwait;
@@ -631,7 +632,7 @@ LWLockRelease(LWLockId lockid)
        /* We are done updating shared state of the lock itself. */
        SpinLockRelease(&lock->mutex);
 
-       PG_TRACE1(lwlock__release, lockid);
+       TRACE_POSTGRESQL_LWLOCK_RELEASE(lockid);
 
        /*
         * Awaken any waiters I removed from the queue.
diff --git a/src/backend/utils/Gen_dummy_probes.sed b/src/backend/utils/Gen_dummy_probes.sed
new file mode 100644 (file)
index 0000000..5a5a9db
--- /dev/null
@@ -0,0 +1,16 @@
+#-------------------------------------------------------------------------
+# sed script to create dummy probes.h file when dtrace is not available
+#
+# Copyright (c) 2008, PostgreSQL Global Development Group
+#
+# $PostgreSQL$
+#-------------------------------------------------------------------------
+
+/^probe /!d
+s/^probe \([^(]*\)\(.*\);/\1\2/
+s/__/_/g
+y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
+s/^/#define TRACE_POSTGRESQL_/
+s/(INT, INT)/(INT1, INT2)/
+P
+s/(.*$/_ENABLED() (0)/
index c6efd1d0a88a0c891a37343258a78ea2c1163052..f98aa817217478f092f6895f8a73469e19e64b3e 100644 (file)
@@ -13,12 +13,22 @@ SUBDIRS     = adt cache error fmgr hash init mb misc mmgr resowner sort time
 
 include $(top_srcdir)/src/backend/common.mk
 
-all: fmgroids.h
+all: fmgroids.h probes.h
 
 $(SUBDIRS:%=%-recursive): fmgroids.h
 
 fmgroids.h fmgrtab.c: Gen_fmgrtab.sh $(top_srcdir)/src/include/catalog/pg_proc.h
        AWK='$(AWK)' $(SHELL) $< $(top_srcdir)/src/include/catalog/pg_proc.h
 
+probes.h: probes.d
+ifeq ($(enable_dtrace), yes)
+       $(DTRACE) -h -s $< -o $@.tmp
+       sed -e 's/POSTGRESQL_/TRACE_POSTGRESQL_/g' $@.tmp >$@
+       rm $@.tmp
+else
+       sed -f $(srcdir)/Gen_dummy_probes.sed $< >$@
+endif
+
+
 clean:
-       rm -f fmgroids.h fmgrtab.c
+       rm -f fmgroids.h fmgrtab.c probes.h
index 4b808200282848300dac446e56518ebf6bd12f2a..3ddd357457a010a902e5b56581de732140e13ebc 100644 (file)
@@ -60,7 +60,7 @@ uninstall:
 
 
 clean:
-       rm -f utils/fmgroids.h parser/parse.h
+       rm -f utils/fmgroids.h parser/parse.h utils/probes.h
 
 distclean maintainer-clean: clean
        rm -f pg_config.h dynloader.h pg_config_os.h stamp-h
index f9537cefffd359e5aa38cdcedd5d3ff81d2419b9..3752827fc0d78ac7fd2bcf1abfe7e5c4487a8907 100644 (file)
@@ -57,7 +57,6 @@
 #include "pg_config_os.h"              /* must be before any system header files */
 #endif
 #include "postgres_ext.h"
-#include "pg_trace.h"
 
 #if _MSC_VER >= 1400
 #define errcode __msvc_errcode
index 3903fb1bde2cb64c3d486b8097d7a7bdeb37def2..5cd572f6ea9437422faa43139e8584e806668f2b 100644 (file)
 #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 */
+#include "utils/probes.h"
 
 #endif   /* PG_TRACE_H */