mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-30 13:37:18 +02:00
Prevent lwlock dtrace probes from unnecessary work
If dtrace is compiled in but disabled, the lwlock dtrace probes still evaluate their arguments. Since PostgreSQL 13, T_NAME(lock) does nontrivial work, so it should be avoided if not needed. To fix, make these calls conditional on the *_ENABLED() macro corresponding to each probe. Reviewed-by: Craig Ringer <craig.ringer@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/CAGRY4nwxKUS_RvXFW-ugrZBYxPFFM5kjwKT5O+0+Stuga5b4+Q@mail.gmail.com
This commit is contained in:
parent
3eeadc425c
commit
e48ce7ef0e
@ -1323,7 +1323,8 @@ LWLockAcquire(LWLock *lock, LWLockMode mode)
|
||||
#endif
|
||||
|
||||
LWLockReportWaitStart(lock);
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_START(T_NAME(lock), mode);
|
||||
if (TRACE_POSTGRESQL_LWLOCK_WAIT_START_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_START(T_NAME(lock), mode);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
@ -1345,7 +1346,8 @@ LWLockAcquire(LWLock *lock, LWLockMode mode)
|
||||
}
|
||||
#endif
|
||||
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_DONE(T_NAME(lock), mode);
|
||||
if (TRACE_POSTGRESQL_LWLOCK_WAIT_DONE_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_DONE(T_NAME(lock), mode);
|
||||
LWLockReportWaitEnd();
|
||||
|
||||
LOG_LWDEBUG("LWLockAcquire", lock, "awakened");
|
||||
@ -1354,7 +1356,8 @@ LWLockAcquire(LWLock *lock, LWLockMode mode)
|
||||
result = false;
|
||||
}
|
||||
|
||||
TRACE_POSTGRESQL_LWLOCK_ACQUIRE(T_NAME(lock), mode);
|
||||
if (TRACE_POSTGRESQL_LWLOCK_ACQUIRE_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_ACQUIRE(T_NAME(lock), mode);
|
||||
|
||||
/* Add lock to list of locks held by this backend */
|
||||
held_lwlocks[num_held_lwlocks].lock = lock;
|
||||
@ -1405,14 +1408,16 @@ LWLockConditionalAcquire(LWLock *lock, LWLockMode mode)
|
||||
RESUME_INTERRUPTS();
|
||||
|
||||
LOG_LWDEBUG("LWLockConditionalAcquire", lock, "failed");
|
||||
TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE_FAIL(T_NAME(lock), mode);
|
||||
if (TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE_FAIL_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE_FAIL(T_NAME(lock), mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Add lock to list of locks held by this backend */
|
||||
held_lwlocks[num_held_lwlocks].lock = lock;
|
||||
held_lwlocks[num_held_lwlocks++].mode = mode;
|
||||
TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE(T_NAME(lock), mode);
|
||||
if (TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE(T_NAME(lock), mode);
|
||||
}
|
||||
return !mustwait;
|
||||
}
|
||||
@ -1484,7 +1489,8 @@ LWLockAcquireOrWait(LWLock *lock, LWLockMode mode)
|
||||
#endif
|
||||
|
||||
LWLockReportWaitStart(lock);
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_START(T_NAME(lock), mode);
|
||||
if (TRACE_POSTGRESQL_LWLOCK_WAIT_START_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_START(T_NAME(lock), mode);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
@ -1502,7 +1508,8 @@ LWLockAcquireOrWait(LWLock *lock, LWLockMode mode)
|
||||
Assert(nwaiters < MAX_BACKENDS);
|
||||
}
|
||||
#endif
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_DONE(T_NAME(lock), mode);
|
||||
if (TRACE_POSTGRESQL_LWLOCK_WAIT_DONE_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_DONE(T_NAME(lock), mode);
|
||||
LWLockReportWaitEnd();
|
||||
|
||||
LOG_LWDEBUG("LWLockAcquireOrWait", lock, "awakened");
|
||||
@ -1532,7 +1539,8 @@ LWLockAcquireOrWait(LWLock *lock, LWLockMode mode)
|
||||
/* Failed to get lock, so release interrupt holdoff */
|
||||
RESUME_INTERRUPTS();
|
||||
LOG_LWDEBUG("LWLockAcquireOrWait", lock, "failed");
|
||||
TRACE_POSTGRESQL_LWLOCK_ACQUIRE_OR_WAIT_FAIL(T_NAME(lock), mode);
|
||||
if (TRACE_POSTGRESQL_LWLOCK_ACQUIRE_OR_WAIT_FAIL_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_ACQUIRE_OR_WAIT_FAIL(T_NAME(lock), mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1540,7 +1548,8 @@ LWLockAcquireOrWait(LWLock *lock, LWLockMode mode)
|
||||
/* Add lock to list of locks held by this backend */
|
||||
held_lwlocks[num_held_lwlocks].lock = lock;
|
||||
held_lwlocks[num_held_lwlocks++].mode = mode;
|
||||
TRACE_POSTGRESQL_LWLOCK_ACQUIRE_OR_WAIT(T_NAME(lock), mode);
|
||||
if (TRACE_POSTGRESQL_LWLOCK_ACQUIRE_OR_WAIT_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_ACQUIRE_OR_WAIT(T_NAME(lock), mode);
|
||||
}
|
||||
|
||||
return !mustwait;
|
||||
@ -1700,7 +1709,8 @@ LWLockWaitForVar(LWLock *lock, uint64 *valptr, uint64 oldval, uint64 *newval)
|
||||
#endif
|
||||
|
||||
LWLockReportWaitStart(lock);
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_START(T_NAME(lock), LW_EXCLUSIVE);
|
||||
if (TRACE_POSTGRESQL_LWLOCK_WAIT_START_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_START(T_NAME(lock), LW_EXCLUSIVE);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
@ -1719,7 +1729,8 @@ LWLockWaitForVar(LWLock *lock, uint64 *valptr, uint64 oldval, uint64 *newval)
|
||||
}
|
||||
#endif
|
||||
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_DONE(T_NAME(lock), LW_EXCLUSIVE);
|
||||
if (TRACE_POSTGRESQL_LWLOCK_WAIT_DONE_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_DONE(T_NAME(lock), LW_EXCLUSIVE);
|
||||
LWLockReportWaitEnd();
|
||||
|
||||
LOG_LWDEBUG("LWLockWaitForVar", lock, "awakened");
|
||||
@ -1727,7 +1738,8 @@ LWLockWaitForVar(LWLock *lock, uint64 *valptr, uint64 oldval, uint64 *newval)
|
||||
/* Now loop back and check the status of the lock again. */
|
||||
}
|
||||
|
||||
TRACE_POSTGRESQL_LWLOCK_ACQUIRE(T_NAME(lock), LW_EXCLUSIVE);
|
||||
if (TRACE_POSTGRESQL_LWLOCK_ACQUIRE_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_ACQUIRE(T_NAME(lock), LW_EXCLUSIVE);
|
||||
|
||||
/*
|
||||
* Fix the process wait semaphore's count for any absorbed wakeups.
|
||||
@ -1870,7 +1882,8 @@ LWLockRelease(LWLock *lock)
|
||||
LWLockWakeup(lock);
|
||||
}
|
||||
|
||||
TRACE_POSTGRESQL_LWLOCK_RELEASE(T_NAME(lock));
|
||||
if (TRACE_POSTGRESQL_LWLOCK_RELEASE_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_RELEASE(T_NAME(lock));
|
||||
|
||||
/*
|
||||
* Now okay to allow cancel/die interrupts.
|
||||
|
Loading…
Reference in New Issue
Block a user