]> granicus.if.org Git - postgresql/commitdiff
instr_time.h: add INSTR_TIME_SET_CURRENT_LAZY
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 21 Nov 2018 18:02:37 +0000 (15:02 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 21 Nov 2018 18:04:25 +0000 (15:04 -0300)
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

src/backend/executor/instrument.c
src/include/portability/instr_time.h

index fe5d55904d27f2f2bc5f77b013d5c52a32d5b5d2..0f2da2214831eb5f6feef06fd1524717181f3fb9 100644 (file)
@@ -62,13 +62,9 @@ InstrInit(Instrumentation *instr, int instrument_options)
 void
 InstrStartNode(Instrumentation *instr)
 {
-       if (instr->need_timer)
-       {
-               if (INSTR_TIME_IS_ZERO(instr->starttime))
-                       INSTR_TIME_SET_CURRENT(instr->starttime);
-               else
-                       elog(ERROR, "InstrStartNode called twice in a row");
-       }
+       if (instr->need_timer &&
+               INSTR_TIME_SET_CURRENT_LAZY(instr->starttime))
+               elog(ERROR, "InstrStartNode called twice in a row");
 
        /* save buffer usage totals at node entry, if needed */
        if (instr->need_bufusage)
index f968444671cb97fab95b20cbcebbe308e3507470..60984905b25af38ff15fc42723c97334dabc827c 100644 (file)
@@ -20,6 +20,9 @@
  *
  * 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_SUBTRACT(x, y)           x -= y
@@ -245,4 +248,9 @@ GetTimerFrequency(void)
 
 #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 */