1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

From: Massimo Dal Zotto <dz@cs.unitn.it>

> tprintf.patch
>
>       tprintf.patch
>
>       adds functions and macros which implement a conditional trace package
>       with the ability to change flags and numeric options of running
>       backends at runtime.
>       Options/flags can be specified in the command line and/or read from
>       the file pg_options in the data directory.
This commit is contained in:
Marc G. Fournier
1998-08-25 21:34:10 +00:00
parent 51e8e187d1
commit 7414d61950
9 changed files with 430 additions and 188 deletions

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.30 1998/07/12 04:43:28 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.31 1998/08/25 21:34:01 scrappy Exp $
*
* NOTES
*
@@ -39,6 +39,7 @@
#include <sys/shm.h>
#include "utils/memutils.h"
#include "libpq/libpq.h"
#include "utils/trace.h"
#if defined(solaris_sparc)
#include <string.h>
@@ -113,17 +114,26 @@ proc_exit(int code)
{
int i;
TPRINTF(TRACE_VERBOSE, "proc_exit(%d) [#%d]", code, proc_exit_inprogress);
/*
* If proc_exit is called too many times something bad is
* happenig, so exit immediately.
*/
if (proc_exit_inprogress > 9) {
elog(ERROR, "infinite recursion in proc_exit");
goto exit;
}
/* ----------------
* if proc_exit_inprocess is true, then it means that we
* are being invoked from within an on_exit() handler
* and so we return immediately to avoid recursion.
* ----------------
*/
if (proc_exit_inprogress)
if (proc_exit_inprogress++)
return;
proc_exit_inprogress = 1;
/* do our shared memory exits first */
shmem_exit(code);
@@ -134,6 +144,8 @@ proc_exit(int code)
for (i = on_proc_exit_index - 1; i >= 0; --i)
(*on_proc_exit_list[i].function) (code, on_proc_exit_list[i].arg);
exit:
TPRINTF(TRACE_VERBOSE, "exit(%d)", code);
exit(code);
}
@@ -150,17 +162,27 @@ shmem_exit(int code)
{
int i;
TPRINTF(TRACE_VERBOSE, "shmem_exit(%d) [#%d]",
code, shmem_exit_inprogress);
/*
* If shmem_exit is called too many times something bad is
* happenig, so exit immediately.
*/
if (shmem_exit_inprogress > 9) {
elog(ERROR, "infinite recursion in shmem_exit");
exit(-1);
}
/* ----------------
* if shmem_exit_inprocess is true, then it means that we
* are being invoked from within an on_exit() handler
* and so we return immediately to avoid recursion.
* ----------------
*/
if (shmem_exit_inprogress)
if (shmem_exit_inprogress++)
return;
shmem_exit_inprogress = 1;
/* ----------------
* call all the callbacks registered before calling exit().
* ----------------
@@ -315,7 +337,7 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
{
*status = IpcSemIdNotExist; /* there doesn't exist a semaphore */
#ifdef DEBUG_IPC
fprintf(stderr, "calling semget with %d, %d , %d\n",
EPRINTF("calling semget with %d, %d , %d\n",
semKey,
semNum,
IPC_CREAT | permission);
@@ -324,8 +346,9 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
if (semId < 0)
{
perror("semget");
IpcConfigTip();
EPRINTF("IpcSemaphoreCreate: semget failed (%s) "
"key=%d, num=%d, permission=%o",
strerror(errno), semKey, semNum, permission);
proc_exit(3);
}
for (i = 0; i < semNum; i++)
@@ -334,8 +357,8 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
errStatus = semctl(semId, 0, SETALL, semun);
if (errStatus == -1)
{
perror("semctl");
IpcConfigTip();
EPRINTF("IpcSemaphoreCreate: semctl failed (%s) id=%d",
strerror(errno), semId);
}
if (removeOnExit)
@@ -349,7 +372,7 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
}
#ifdef DEBUG_IPC
fprintf(stderr, "\nIpcSemaphoreCreate, status %d, returns %d\n",
EPRINTF("\nIpcSemaphoreCreate, status %d, returns %d\n",
*status,
semId);
fflush(stdout);
@@ -379,8 +402,8 @@ IpcSemaphoreSet(int semId, int semno, int value)
if (errStatus == -1)
{
perror("semctl");
IpcConfigTip();
EPRINTF("IpcSemaphoreSet: semctl failed (%s) id=%d",
strerror(errno), semId);
}
}
@@ -441,8 +464,8 @@ IpcSemaphoreLock(IpcSemaphoreId semId, int sem, int lock)
if (errStatus == -1)
{
perror("semop");
IpcConfigTip();
EPRINTF("IpcSemaphoreLock: semop failed (%s) id=%d",
strerror(errno), semId);
proc_exit(255);
}
}
@@ -486,8 +509,8 @@ IpcSemaphoreUnlock(IpcSemaphoreId semId, int sem, int lock)
if (errStatus == -1)
{
perror("semop");
IpcConfigTip();
EPRINTF("IpcSemaphoreUnlock: semop failed (%s) id=%d",
strerror(errno), semId);
proc_exit(255);
}
}
@@ -534,10 +557,9 @@ IpcMemoryCreate(IpcMemoryKey memKey, uint32 size, int permission)
if (shmid < 0)
{
fprintf(stderr, "IpcMemoryCreate: memKey=%d , size=%d , permission=%d",
memKey, size, permission);
perror("IpcMemoryCreate: shmget(..., create, ...) failed");
IpcConfigTip();
EPRINTF("IpcMemoryCreate: shmget failed (%s) "
"key=%d, size=%d, permission=%o",
strerror(errno), memKey, size, permission);
return (IpcMemCreationFailed);
}
@@ -560,10 +582,9 @@ IpcMemoryIdGet(IpcMemoryKey memKey, uint32 size)
if (shmid < 0)
{
fprintf(stderr, "IpcMemoryIdGet: memKey=%d , size=%d , permission=%d",
memKey, size, 0);
perror("IpcMemoryIdGet: shmget() failed");
IpcConfigTip();
EPRINTF("IpcMemoryIdGet: shmget failed (%s) "
"key=%d, size=%d, permission=%o",
strerror(errno), memKey, size, 0);
return (IpcMemIdGetFailed);
}
@@ -602,8 +623,8 @@ IpcMemoryAttach(IpcMemoryId memId)
/* if ( *memAddress == -1) { XXX ??? */
if (memAddress == (char *) -1)
{
perror("IpcMemoryAttach: shmat() failed");
IpcConfigTip();
EPRINTF("IpcMemoryAttach: shmat failed (%s) id=%d",
strerror(errno), memId);
return (IpcMemAttachFailed);
}

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.14 1998/06/27 15:47:45 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.15 1998/08/25 21:34:03 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -31,6 +31,7 @@
#include "storage/shmem.h"
#include "storage/spin.h"
#include "storage/proc.h"
#include "utils/trace.h"
#ifndef HAS_TEST_AND_SET
#include <sys/sem.h>
@@ -81,10 +82,12 @@ InitSpinLocks(int init, IPCKey key)
}
#ifdef LOCKDEBUG
#define PRINT_LOCK(LOCK) printf("(locklock = %d, flag = %d, nshlocks = %d, \
shlock = %d, exlock =%d)\n", LOCK->locklock, \
LOCK->flag, LOCK->nshlocks, LOCK->shlock, \
LOCK->exlock)
#define PRINT_LOCK(LOCK) \
TPRINTF(TRACE_SPINLOCKS, \
"(locklock = %d, flag = %d, nshlocks = %d, shlock = %d, " \
"exlock =%d)\n", LOCK->locklock, \
LOCK->flag, LOCK->nshlocks, LOCK->shlock, \
LOCK->exlock)
#endif
/* from ipc.c */
@@ -98,8 +101,7 @@ SpinAcquire(SPINLOCK lockid)
/* This used to be in ipc.c, but move here to reduce function calls */
slckP = &(SLockArray[lockid]);
#ifdef LOCKDEBUG
printf("SpinAcquire(%d)\n", lockid);
printf("IN: ");
TPRINTF(TRACE_SPINLOCKS, "SpinAcquire: %d", lockid);
PRINT_LOCK(slckP);
#endif
ex_try_again:
@@ -112,7 +114,7 @@ ex_try_again:
S_LOCK(&(slckP->shlock));
S_UNLOCK(&(slckP->locklock));
#ifdef LOCKDEBUG
printf("OUT: ");
TPRINTF(TRACE_SPINLOCKS, "OUT: ");
PRINT_LOCK(slckP);
#endif
break;
@@ -124,6 +126,9 @@ ex_try_again:
goto ex_try_again;
}
PROC_INCR_SLOCK(lockid);
#ifdef LOCKDEBUG
TPRINTF(TRACE_SPINLOCKS, "SpinAcquire: got %d", lockid);
#endif
}
void
@@ -131,13 +136,23 @@ SpinRelease(SPINLOCK lockid)
{
SLock *slckP;
PROC_DECR_SLOCK(lockid);
/* This used to be in ipc.c, but move here to reduce function calls */
slckP = &(SLockArray[lockid]);
#ifdef USE_ASSERT_CHECKING
/*
* Check that we are actually holding the lock we are releasing.
* This can be done only after MyProc has been initialized.
*/
if (MyProc)
Assert(MyProc->sLocks[lockid] > 0);
Assert(slckP->flag != NOLOCK);
#endif
PROC_DECR_SLOCK(lockid);
#ifdef LOCKDEBUG
printf("SpinRelease(%d)\n", lockid);
printf("IN: ");
TPRINTF("SpinRelease: %d\n", lockid);
PRINT_LOCK(slckP);
#endif
S_LOCK(&(slckP->locklock));
@@ -160,7 +175,7 @@ SpinRelease(SPINLOCK lockid)
S_UNLOCK(&(slckP->exlock));
S_UNLOCK(&(slckP->locklock));
#ifdef LOCKDEBUG
printf("OUT: ");
TPRINTF(TRACE_SPINLOCKS, "SpinRelease: released %d", lockid);
PRINT_LOCK(slckP);
#endif
}