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 <Robert.Lor@sun.com>
This commit is contained in:
Peter Eisentraut 2008-03-17 19:44:41 +00:00
parent e7115a224a
commit a7b7b07af3
9 changed files with 64 additions and 62 deletions

View File

@ -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
##########################################################################

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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)/

View File

@ -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

View File

@ -4,7 +4,7 @@
#
# 'make install' installs whole contents of src/include.
#
# $PostgreSQL: pgsql/src/include/Makefile,v 1.23 2007/10/14 17:07:51 tgl Exp $
# $PostgreSQL: pgsql/src/include/Makefile,v 1.24 2008/03/17 19:44:41 petere Exp $
#
#-------------------------------------------------------------------------
@ -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

View File

@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/c.h,v 1.223 2008/02/23 19:11:45 tgl Exp $
* $PostgreSQL: pgsql/src/include/c.h,v 1.224 2008/03/17 19:44:41 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -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

View File

@ -5,50 +5,13 @@
*
* Copyright (c) 2006-2008, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/include/pg_trace.h,v 1.3 2008/01/02 02:42:06 momjian Exp $
* $PostgreSQL: pgsql/src/include/pg_trace.h,v 1.4 2008/03/17 19:44:41 petere Exp $
* ----------
*/
#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 */