diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.global.in | 5 | ||||
-rw-r--r-- | src/backend/Makefile | 14 | ||||
-rw-r--r-- | src/backend/access/transam/xact.c | 8 | ||||
-rw-r--r-- | src/backend/storage/lmgr/lock.c | 7 | ||||
-rw-r--r-- | src/backend/storage/lmgr/lwlock.c | 12 | ||||
-rw-r--r-- | src/backend/utils/probes.d | 24 | ||||
-rw-r--r-- | src/include/c.h | 3 | ||||
-rw-r--r-- | src/include/pg_config.h.in | 3 | ||||
-rw-r--r-- | src/include/pg_trace.h | 56 |
9 files changed, 124 insertions, 8 deletions
diff --git a/src/Makefile.global.in b/src/Makefile.global.in index 70c82bd314a..c3066b2f111 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -1,5 +1,5 @@ # -*-makefile-*- -# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.224 2006/07/21 22:37:37 petere Exp $ +# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.225 2006/07/24 16:32:44 petere Exp $ #------------------------------------------------------------------------------ # All PostgreSQL makefiles include this file and use the variables it sets, @@ -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 8908a5a7dbb..12de33e4044 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -4,7 +4,7 @@ # # Copyright (c) 1994, Regents of the University of California # -# $PostgreSQL: pgsql/src/backend/Makefile,v 1.116 2006/06/22 23:50:35 tgl Exp $ +# $PostgreSQL: pgsql/src/backend/Makefile,v 1.117 2006/07/24 16:32:44 petere Exp $ # #------------------------------------------------------------------------- @@ -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 2694f24c37d..e9473acaa6b 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.223 2006/07/14 14:52:17 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.224 2006/07/24 16:32:44 petere Exp $ * *------------------------------------------------------------------------- */ @@ -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 2b3a4c63c4f..a0bc2869c00 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.168 2006/07/23 23:08:46 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.169 2006/07/24 16:32:45 petere Exp $ * * NOTES * A lock table is a shared memory hash table. When @@ -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 077bec4a60f..f10de0dca0e 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.41 2006/07/23 03:07:58 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.42 2006/07/24 16:32:45 petere Exp $ * *------------------------------------------------------------------------- */ @@ -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 00000000000..2720de8cd93 --- /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: pgsql/src/backend/utils/probes.d,v 1.1 2006/07/24 16:32:45 petere Exp $ + * ---------- + */ + +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 bd09a430edc..5195db2ac75 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -12,7 +12,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/c.h,v 1.206 2006/07/06 01:55:51 momjian Exp $ + * $PostgreSQL: pgsql/src/include/c.h,v 1.207 2006/07/24 16:32:45 petere Exp $ * *------------------------------------------------------------------------- */ @@ -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 82ccde63c1c..e84205c9ea0 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 00000000000..6c35cb2e8dd --- /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: pgsql/src/include/pg_trace.h,v 1.1 2006/07/24 16:32:45 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 */ + +#endif /* PG_TRACE_H */ |