Commit 6f7d02aa authored by Alvaro Herrera's avatar Alvaro Herrera

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
parent 7306d5e9
...@@ -62,13 +62,9 @@ InstrInit(Instrumentation *instr, int instrument_options) ...@@ -62,13 +62,9 @@ InstrInit(Instrumentation *instr, int instrument_options)
void void
InstrStartNode(Instrumentation *instr) InstrStartNode(Instrumentation *instr)
{ {
if (instr->need_timer) if (instr->need_timer &&
{ INSTR_TIME_SET_CURRENT_LAZY(instr->starttime))
if (INSTR_TIME_IS_ZERO(instr->starttime))
INSTR_TIME_SET_CURRENT(instr->starttime);
else
elog(ERROR, "InstrStartNode called twice in a row"); elog(ERROR, "InstrStartNode called twice in a row");
}
/* save buffer usage totals at node entry, if needed */ /* save buffer usage totals at node entry, if needed */
if (instr->need_bufusage) if (instr->need_bufusage)
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
* *
* INSTR_TIME_SET_CURRENT(t) set t to current time * INSTR_TIME_SET_CURRENT(t) set t to current time
* *
* INSTR_TIME_SET_CURRENT_LAZY(t) set t to current time if t is zero,
* evaluates to whether t changed
*
* INSTR_TIME_ADD(x, y) x += y * INSTR_TIME_ADD(x, y) x += y
* *
* INSTR_TIME_SUBTRACT(x, y) x -= y * INSTR_TIME_SUBTRACT(x, y) x -= y
...@@ -245,4 +248,9 @@ GetTimerFrequency(void) ...@@ -245,4 +248,9 @@ GetTimerFrequency(void)
#endif /* WIN32 */ #endif /* WIN32 */
/* same macro on all platforms */
#define INSTR_TIME_SET_CURRENT_LAZY(t) \
(INSTR_TIME_IS_ZERO(t) ? INSTR_TIME_SET_CURRENT(t), true : false)
#endif /* INSTR_TIME_H */ #endif /* INSTR_TIME_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment