mirror of
https://github.com/postgres/postgres.git
synced 2025-08-27 07:42:10 +03:00
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
This commit is contained in:
@@ -5344,7 +5344,7 @@ static void
|
||||
ShowTransactionState(const char *str)
|
||||
{
|
||||
/* skip work if message will definitely not be printed */
|
||||
if (log_min_messages <= DEBUG5 || client_min_messages <= DEBUG5)
|
||||
if (message_level_is_interesting(DEBUG5))
|
||||
ShowTransactionStateRec(str, CurrentTransactionState);
|
||||
}
|
||||
|
||||
@@ -5371,7 +5371,6 @@ ShowTransactionStateRec(const char *str, TransactionState s)
|
||||
if (s->parent)
|
||||
ShowTransactionStateRec(str, s->parent);
|
||||
|
||||
/* use ereport to suppress computation if msg will not be printed */
|
||||
ereport(DEBUG5,
|
||||
(errmsg_internal("%s(%d) name: %s; blockState: %s; state: %s, xid/subid/cid: %u/%u/%u%s%s",
|
||||
str, s->nestingLevel,
|
||||
|
@@ -105,7 +105,7 @@ log_invalid_page(RelFileNode node, ForkNumber forkno, BlockNumber blkno,
|
||||
* tracing of the cause (note the elog context mechanism will tell us
|
||||
* something about the XLOG record that generated the reference).
|
||||
*/
|
||||
if (log_min_messages <= DEBUG1 || client_min_messages <= DEBUG1)
|
||||
if (message_level_is_interesting(DEBUG1))
|
||||
report_invalid_page(DEBUG1, node, forkno, blkno, present);
|
||||
|
||||
if (invalid_page_tab == NULL)
|
||||
@@ -159,7 +159,7 @@ forget_invalid_pages(RelFileNode node, ForkNumber forkno, BlockNumber minblkno)
|
||||
hentry->key.forkno == forkno &&
|
||||
hentry->key.blkno >= minblkno)
|
||||
{
|
||||
if (log_min_messages <= DEBUG2 || client_min_messages <= DEBUG2)
|
||||
if (message_level_is_interesting(DEBUG2))
|
||||
{
|
||||
char *path = relpathperm(hentry->key.node, forkno);
|
||||
|
||||
@@ -192,7 +192,7 @@ forget_invalid_pages_db(Oid dbid)
|
||||
{
|
||||
if (hentry->key.node.dbNode == dbid)
|
||||
{
|
||||
if (log_min_messages <= DEBUG2 || client_min_messages <= DEBUG2)
|
||||
if (message_level_is_interesting(DEBUG2))
|
||||
{
|
||||
char *path = relpathperm(hentry->key.node, hentry->key.forkno);
|
||||
|
||||
|
Reference in New Issue
Block a user