summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut2008-03-17 19:44:41 +0000
committerPeter Eisentraut2008-03-17 19:44:41 +0000
commit2ae621ca2c1e2b2b27eb7f92f9bc5e27a268c456 (patch)
tree2a8ea6a8bdb45886b6ef61576d1059863ec049b9
parent9d19aeac71b9cffd65f80835a418c8ba3c63ce49 (diff)
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 <[email protected]>
-rw-r--r--src/backend/Makefile13
-rw-r--r--src/backend/access/transam/xact.c7
-rw-r--r--src/backend/storage/lmgr/lock.c5
-rw-r--r--src/backend/storage/lmgr/lwlock.c13
-rw-r--r--src/backend/utils/Gen_dummy_probes.sed16
-rw-r--r--src/backend/utils/Makefile14
-rw-r--r--src/include/Makefile2
-rw-r--r--src/include/c.h1
-rw-r--r--src/include/pg_trace.h39
9 files changed, 56 insertions, 54 deletions
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 78511b83b3..0f175ca288 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -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 14f3d56ff9..16f51799a2 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -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 2f821d0b12..c07bb5c848 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -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 d5f61e55ea..9aea776c26 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -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..5a5a9dbe55
--- /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$
+#-------------------------------------------------------------------------
+
+/^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 c6efd1d0a8..f98aa81721 100644
--- a/src/backend/utils/Makefile
+++ b/src/backend/utils/Makefile
@@ -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 [email protected]
+ sed -e 's/POSTGRESQL_/TRACE_POSTGRESQL_/g' [email protected] >$@
+else
+ sed -f $(srcdir)/Gen_dummy_probes.sed $< >$@
+endif
+
+
clean:
- rm -f fmgroids.h fmgrtab.c
+ rm -f fmgroids.h fmgrtab.c probes.h
diff --git a/src/include/Makefile b/src/include/Makefile
index 4b80820028..3ddd357457 100644
--- a/src/include/Makefile
+++ b/src/include/Makefile
@@ -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
diff --git a/src/include/c.h b/src/include/c.h
index f9537cefff..3752827fc0 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -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
diff --git a/src/include/pg_trace.h b/src/include/pg_trace.h
index 3903fb1bde..5cd572f6ea 100644
--- a/src/include/pg_trace.h
+++ b/src/include/pg_trace.h
@@ -12,43 +12,6 @@
#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 */