Skip to content

Commit 7847a15

Browse files
committed
Add optional support for CLOCK_MONOTONIC_COARSE when explain analyze.
Resolution of CLOCK_MONOTONIC_COARSE: 0.004000000 seconds, this change improve explain analyze performance.
1 parent 8c28729 commit 7847a15

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/backend/executor/instrument.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ InstrStopNodeSync(Instrumentation *instr, uint64 nTuples)
123123
if (INSTR_TIME_IS_ZERO(instr->starttime))
124124
elog(ERROR, "InstrStopNode called without start");
125125

126-
INSTR_TIME_SET_CURRENT(endtime);
126+
INSTR_TIME_SET_CURRENT_COARSE(endtime);
127127
INSTR_TIME_ACCUM_DIFF(instr->counter, endtime, instr->starttime);
128128

129129
INSTR_TIME_SET_ZERO(instr->starttime);

src/include/portability/instr_time.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ typedef struct timespec instr_time;
9191

9292
#define INSTR_TIME_SET_CURRENT(t) ((void) clock_gettime(PG_INSTR_CLOCK, &(t)))
9393

94+
#ifdef CLOCK_MONOTONIC_COARSE
95+
#define INSTR_TIME_SET_CURRENT_COARSE(t) ((void) clock_gettime(CLOCK_MONOTONIC_COARSE, &(t)))
96+
#else
97+
#define INSTR_TIME_SET_CURRENT_COARSE(t) INSTR_TIME_SET_CURRENT(t)
98+
#endif
99+
94100
#define INSTR_TIME_ASSIGN(x,y) ((x).tv_sec = (y).tv_sec, (x).tv_nsec = (y).tv_nsec)
95101

96102
#define INSTR_TIME_ADD(x,y) \
@@ -157,6 +163,8 @@ typedef struct timeval instr_time;
157163

158164
#define INSTR_TIME_SET_CURRENT(t) gettimeofday(&(t), NULL)
159165

166+
#define INSTR_TIME_SET_CURRENT_COARSE(t) INSTR_TIME_SET_CURRENT(t)
167+
160168
#define INSTR_TIME_ASSIGN(x,y) ((x).tv_sec = (y).tv_sec, (x).tv_usec = (y).tv_usec)
161169

162170
#define INSTR_TIME_ADD(x,y) \
@@ -223,6 +231,8 @@ typedef LARGE_INTEGER instr_time;
223231

224232
#define INSTR_TIME_SET_CURRENT(t) QueryPerformanceCounter(&(t))
225233

234+
#define INSTR_TIME_SET_CURRENT_COARSE(t) INSTR_TIME_SET_CURRENT(t)
235+
226236
#define INSTR_TIME_ASSIGN(x,y) ((x).QuadPart = (y).QuadPart)
227237

228238
#define INSTR_TIME_ADD(x,y) \
@@ -257,6 +267,6 @@ GetTimerFrequency(void)
257267
/* same macro on all platforms */
258268

259269
#define INSTR_TIME_SET_CURRENT_LAZY(t) \
260-
(INSTR_TIME_IS_ZERO(t) ? INSTR_TIME_SET_CURRENT(t), true : false)
270+
(INSTR_TIME_IS_ZERO(t) ? INSTR_TIME_SET_CURRENT_COARSE(t), true : false)
261271

262272
#endif /* INSTR_TIME_H */

0 commit comments

Comments
 (0)