summaryrefslogtreecommitdiff
path: root/src/backend/storage/lmgr/proc.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-11-23 19:04:07 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2020-11-23 19:10:46 -0500
commit789b938bf2b8e38d0894261eae6bc84bbbb4714e (patch)
tree91b3949ee6d16e3afcccfc8ae720cc2b6439adaa /src/backend/storage/lmgr/proc.c
parent1fa22a43a56e1fe44c7bb3a3d5ef31be5bcac41d (diff)
Centralize logic for skipping useless ereport/elog calls.
While ereport() and elog() themselves are quite cheap when the error message level is too low to be printed, some places need to do substantial work before they can call those macros at all. To allow optimizing away such setup work when nothing is to be printed, make elog.c export a new function message_level_is_interesting(elevel) that reports whether ereport/elog will do anything. Make use of that in various places that had ad-hoc direct tests of log_min_messages etc. Also teach ProcSleep to use it to avoid some work. (There may well be other places that could usefully use this; I didn't search hard.) Within elog.c, refactor a little bit to avoid having duplicate copies of the policy-setting logic. When that code was written, we weren't relying on the availability of inline functions; so it had some duplications in the name of efficiency, which I got rid of. Alvaro Herrera and Tom Lane Discussion: https://postgr.es/m/129515.1606166429@sss.pgh.pa.us
Diffstat (limited to 'src/backend/storage/lmgr/proc.c')
-rw-r--r--src/backend/storage/lmgr/proc.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c
index 40eac704dc0..7dc3911590e 100644
--- a/src/backend/storage/lmgr/proc.c
+++ b/src/backend/storage/lmgr/proc.c
@@ -1337,26 +1337,30 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable)
!(statusFlags & PROC_VACUUM_FOR_WRAPAROUND))
{
int pid = autovac->pid;
- StringInfoData locktagbuf;
- StringInfoData logbuf; /* errdetail for server log */
/* report the case, if configured to do so */
- initStringInfo(&locktagbuf);
- initStringInfo(&logbuf);
- DescribeLockTag(&locktagbuf, &locktag_copy);
- appendStringInfo(&logbuf,
- _("Process %d waits for %s on %s."),
- MyProcPid,
- GetLockmodeName(lockmethod_copy, lockmode),
- locktagbuf.data);
-
- ereport(DEBUG1,
- (errmsg("sending cancel to blocking autovacuum PID %d",
- pid),
- errdetail_log("%s", logbuf.data)));
-
- pfree(logbuf.data);
- pfree(locktagbuf.data);
+ if (message_level_is_interesting(DEBUG1))
+ {
+ StringInfoData locktagbuf;
+ StringInfoData logbuf; /* errdetail for server log */
+
+ initStringInfo(&locktagbuf);
+ initStringInfo(&logbuf);
+ DescribeLockTag(&locktagbuf, &locktag_copy);
+ appendStringInfo(&logbuf,
+ _("Process %d waits for %s on %s."),
+ MyProcPid,
+ GetLockmodeName(lockmethod_copy, lockmode),
+ locktagbuf.data);
+
+ ereport(DEBUG1,
+ (errmsg("sending cancel to blocking autovacuum PID %d",
+ pid),
+ errdetail_log("%s", logbuf.data)));
+
+ pfree(locktagbuf.data);
+ pfree(logbuf.data);
+ }
/* send the autovacuum worker Back to Old Kent Road */
if (kill(pid, SIGINT) < 0)