From f96708d14ab0073abd95c463eaf8d60db42f411d Mon Sep 17 00:00:00 2001 From: Yuto Hayamizu Date: Tue, 20 May 2014 16:19:56 +0900 Subject: [PATCH] pre-populating lwlock_stats entries --- src/backend/storage/lmgr/lwlock.c | 21 +++++++++++++++++++++ src/backend/storage/lmgr/proc.c | 8 ++++++++ src/include/storage/lwlock.h | 4 ++++ 3 files changed, 33 insertions(+) diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index d23ac62..fc97ae0 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -359,8 +359,29 @@ CreateLWLocks(void) MainLWLockTranche.array_base = MainLWLockArray; MainLWLockTranche.array_stride = sizeof(LWLockPadded); LWLockRegisterTranche(0, &MainLWLockTranche); + +#ifdef LWLOCK_STATS + InitializeLWLockStats(); +#endif } +#ifdef LWLOCK_STATS +void +InitializeLWLockStats(void) +{ + int numLocks = NumLWLocks(); + int id; + LWLockPadded *lock; + + if (MyProc == NULL) return; + + /* Initialize all lwlock_stats entries of MainLWLockArray */ + for (id = 0, lock = MainLWLockArray; id < numLocks; id++, lock++) + { + get_lwlock_stats_entry(&lock->lock); + } +} +#endif /* * LWLockAssign - assign a dynamically-allocated LWLock number diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 266b0da..e09cbf8 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -415,6 +415,10 @@ InitProcess(void) * the deadlock checker. */ InitDeadLockChecking(); + +#ifdef LWLOCK_STATS + InitializeLWLockStats(); +#endif } /* @@ -566,6 +570,10 @@ InitAuxiliaryProcess(void) * Arrange to clean up at process exit. */ on_shmem_exit(AuxiliaryProcKill, Int32GetDatum(proctype)); + +#ifdef LWLOCK_STATS + InitializeLWLockStats(); +#endif } /* diff --git a/src/include/storage/lwlock.h b/src/include/storage/lwlock.h index 175fae3..f0f1c21 100644 --- a/src/include/storage/lwlock.h +++ b/src/include/storage/lwlock.h @@ -209,6 +209,10 @@ extern int LWLockNewTrancheId(void); extern void LWLockRegisterTranche(int, LWLockTranche *); extern void LWLockInitialize(LWLock *, int tranche_id); +#ifdef LWLOCK_STATS +extern void InitializeLWLockStats(void); +#endif + /* * Prior to PostgreSQL 9.4, we used an enum type called LWLockId to refer * to LWLocks. New code should instead use LWLock *. However, for the -- 1.7.10.4