Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

+3-7
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

+8
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)