From a7b7b07af340c73adee9959edf260695591a9496 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 17 Mar 2008 19:44:41 +0000 Subject: Enable probes to work with Mac OS X Leopard and other OSes that will 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 --- src/backend/Makefile | 15 +++++++++++++-- src/backend/access/transam/xact.c | 9 +++++---- src/backend/storage/lmgr/lock.c | 7 ++++--- src/backend/storage/lmgr/lwlock.c | 15 ++++++++------- src/backend/utils/Gen_dummy_probes.sed | 16 ++++++++++++++++ src/backend/utils/Makefile | 16 +++++++++++++--- 6 files changed, 59 insertions(+), 19 deletions(-) create mode 100644 src/backend/utils/Gen_dummy_probes.sed (limited to 'src/backend') diff --git a/src/backend/Makefile b/src/backend/Makefile index bb4064238b..597ec8d8eb 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -5,7 +5,7 @@ # Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group # Portions Copyright (c) 1994, Regents of the University of California # -# $PostgreSQL: pgsql/src/backend/Makefile,v 1.127 2008/02/26 14:42:27 petere Exp $ +# $PostgreSQL: pgsql/src/backend/Makefile,v 1.128 2008/03/17 19:44:40 petere Exp $ # #------------------------------------------------------------------------- @@ -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 ########################################################################## diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 79158d8d71..9af53a5953 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.259 2008/03/17 02:18:55 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.260 2008/03/17 19:44:41 petere Exp $ * *------------------------------------------------------------------------- */ @@ -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 diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index c8ba3538cf..fbd1be586b 100644 --- a/src/backend/storage/lmgr/lock.c +++ b/src/backend/storage/lmgr/lock.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.182 2008/03/04 19:54:06 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.183 2008/03/17 19:44:41 petere Exp $ * * NOTES * A lock table is a shared memory hash table. When @@ -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 diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 036c32fad0..5fcad46f2f 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -15,7 +15,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.50 2008/01/01 19:45:52 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.51 2008/03/17 19:44:41 petere Exp $ * *------------------------------------------------------------------------- */ @@ -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 index 0000000000..db29e4188f --- /dev/null +++ b/src/backend/utils/Gen_dummy_probes.sed @@ -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: pgsql/src/backend/utils/Gen_dummy_probes.sed,v 1.1 2008/03/17 19:44:41 petere Exp $ +#------------------------------------------------------------------------- + +/^probe /!d +s/^probe \([^(]*\)\(.*\);/\1\2/ +s/__/_/g +y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/ +s/^/#define TRACE_POSTGRESQL_/ +s/(INT, INT)/(INT1, INT2)/ +P +s/(.*$/_ENABLED() (0)/ diff --git a/src/backend/utils/Makefile b/src/backend/utils/Makefile index 0e3b9500f5..f753016173 100644 --- a/src/backend/utils/Makefile +++ b/src/backend/utils/Makefile @@ -1,7 +1,7 @@ # # Makefile for utils # -# $PostgreSQL: pgsql/src/backend/utils/Makefile,v 1.26 2008/02/19 10:30:08 petere Exp $ +# $PostgreSQL: pgsql/src/backend/utils/Makefile,v 1.27 2008/03/17 19:44:41 petere Exp $ # subdir = src/backend/utils @@ -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 -- cgit v1.2.1