mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-30 14:17: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,6 +1323,7 @@ LWLockAcquire(LWLock *lock, LWLockMode mode)
|
||||
#endif
|
||||
|
||||
LWLockReportWaitStart(lock);
|
||||
if (TRACE_POSTGRESQL_LWLOCK_WAIT_START_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_START(T_NAME(lock), mode);
|
||||
|
||||
for (;;)
|
||||
@ -1345,6 +1346,7 @@ LWLockAcquire(LWLock *lock, LWLockMode mode)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (TRACE_POSTGRESQL_LWLOCK_WAIT_DONE_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_DONE(T_NAME(lock), mode);
|
||||
LWLockReportWaitEnd();
|
||||
|
||||
@ -1354,6 +1356,7 @@ LWLockAcquire(LWLock *lock, LWLockMode mode)
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (TRACE_POSTGRESQL_LWLOCK_ACQUIRE_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_ACQUIRE(T_NAME(lock), mode);
|
||||
|
||||
/* Add lock to list of locks held by this backend */
|
||||
@ -1405,6 +1408,7 @@ LWLockConditionalAcquire(LWLock *lock, LWLockMode mode)
|
||||
RESUME_INTERRUPTS();
|
||||
|
||||
LOG_LWDEBUG("LWLockConditionalAcquire", lock, "failed");
|
||||
if (TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE_FAIL_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE_FAIL(T_NAME(lock), mode);
|
||||
}
|
||||
else
|
||||
@ -1412,6 +1416,7 @@ LWLockConditionalAcquire(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;
|
||||
if (TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE(T_NAME(lock), mode);
|
||||
}
|
||||
return !mustwait;
|
||||
@ -1484,6 +1489,7 @@ LWLockAcquireOrWait(LWLock *lock, LWLockMode mode)
|
||||
#endif
|
||||
|
||||
LWLockReportWaitStart(lock);
|
||||
if (TRACE_POSTGRESQL_LWLOCK_WAIT_START_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_START(T_NAME(lock), mode);
|
||||
|
||||
for (;;)
|
||||
@ -1502,6 +1508,7 @@ LWLockAcquireOrWait(LWLock *lock, LWLockMode mode)
|
||||
Assert(nwaiters < MAX_BACKENDS);
|
||||
}
|
||||
#endif
|
||||
if (TRACE_POSTGRESQL_LWLOCK_WAIT_DONE_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_DONE(T_NAME(lock), mode);
|
||||
LWLockReportWaitEnd();
|
||||
|
||||
@ -1532,6 +1539,7 @@ LWLockAcquireOrWait(LWLock *lock, LWLockMode mode)
|
||||
/* Failed to get lock, so release interrupt holdoff */
|
||||
RESUME_INTERRUPTS();
|
||||
LOG_LWDEBUG("LWLockAcquireOrWait", lock, "failed");
|
||||
if (TRACE_POSTGRESQL_LWLOCK_ACQUIRE_OR_WAIT_FAIL_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_ACQUIRE_OR_WAIT_FAIL(T_NAME(lock), mode);
|
||||
}
|
||||
else
|
||||
@ -1540,6 +1548,7 @@ 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;
|
||||
if (TRACE_POSTGRESQL_LWLOCK_ACQUIRE_OR_WAIT_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_ACQUIRE_OR_WAIT(T_NAME(lock), mode);
|
||||
}
|
||||
|
||||
@ -1700,6 +1709,7 @@ LWLockWaitForVar(LWLock *lock, uint64 *valptr, uint64 oldval, uint64 *newval)
|
||||
#endif
|
||||
|
||||
LWLockReportWaitStart(lock);
|
||||
if (TRACE_POSTGRESQL_LWLOCK_WAIT_START_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_START(T_NAME(lock), LW_EXCLUSIVE);
|
||||
|
||||
for (;;)
|
||||
@ -1719,6 +1729,7 @@ LWLockWaitForVar(LWLock *lock, uint64 *valptr, uint64 oldval, uint64 *newval)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (TRACE_POSTGRESQL_LWLOCK_WAIT_DONE_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_WAIT_DONE(T_NAME(lock), LW_EXCLUSIVE);
|
||||
LWLockReportWaitEnd();
|
||||
|
||||
@ -1727,6 +1738,7 @@ LWLockWaitForVar(LWLock *lock, uint64 *valptr, uint64 oldval, uint64 *newval)
|
||||
/* Now loop back and check the status of the lock again. */
|
||||
}
|
||||
|
||||
if (TRACE_POSTGRESQL_LWLOCK_ACQUIRE_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_ACQUIRE(T_NAME(lock), LW_EXCLUSIVE);
|
||||
|
||||
/*
|
||||
@ -1870,6 +1882,7 @@ LWLockRelease(LWLock *lock)
|
||||
LWLockWakeup(lock);
|
||||
}
|
||||
|
||||
if (TRACE_POSTGRESQL_LWLOCK_RELEASE_ENABLED())
|
||||
TRACE_POSTGRESQL_LWLOCK_RELEASE(T_NAME(lock));
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user