Skip to content

Commit 6f7d02a

Browse files
committed
instr_time.h: add INSTR_TIME_SET_CURRENT_LAZY
Sets the timestamp to current if not already set. Will acquire more callers momentarily. Author: Fabien Coelho Discussion: https://postgr.es/m/alpine.DEB.2.21.1808111104320.1705@lancre
1 parent 7306d5e commit 6f7d02a

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/backend/executor/instrument.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,9 @@ InstrInit(Instrumentation *instr, int instrument_options)
6262
void
6363
InstrStartNode(Instrumentation *instr)
6464
{
65-
if (instr->need_timer)
66-
{
67-
if (INSTR_TIME_IS_ZERO(instr->starttime))
68-
INSTR_TIME_SET_CURRENT(instr->starttime);
69-
else
70-
elog(ERROR, "InstrStartNode called twice in a row");
71-
}
65+
if (instr->need_timer &&
66+
INSTR_TIME_SET_CURRENT_LAZY(instr->starttime))
67+
elog(ERROR, "InstrStartNode called twice in a row");
7268

7369
/* save buffer usage totals at node entry, if needed */
7470
if (instr->need_bufusage)

src/include/portability/instr_time.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
*
2121
* INSTR_TIME_SET_CURRENT(t) set t to current time
2222
*
23+
* INSTR_TIME_SET_CURRENT_LAZY(t) set t to current time if t is zero,
24+
* evaluates to whether t changed
25+
*
2326
* INSTR_TIME_ADD(x, y) x += y
2427
*
2528
* INSTR_TIME_SUBTRACT(x, y) x -= y
@@ -245,4 +248,9 @@ GetTimerFrequency(void)
245248

246249
#endif /* WIN32 */
247250

251+
/* same macro on all platforms */
252+
253+
#define INSTR_TIME_SET_CURRENT_LAZY(t) \
254+
(INSTR_TIME_IS_ZERO(t) ? INSTR_TIME_SET_CURRENT(t), true : false)
255+
248256
#endif /* INSTR_TIME_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy