Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 08f95de

Browse files
author
Commitfest Bot
committed
[CF 5669] Use CLOCK_MONOTONIC_COARSE for instr_time for explain analyze
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5669 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CAAZLFmRHBahQxwnEz_W1uo0EUxv95yeus_kckAyR_kHzXU3gGQ@mail.gmail.com Author(s): Jianghua yang
2 parents dbf42b8 + 76f66be commit 08f95de

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/backend/executor/instrument.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ InstrStopNode(Instrumentation *instr, double nTuples)
9595
if (INSTR_TIME_IS_ZERO(instr->starttime))
9696
elog(ERROR, "InstrStopNode called without start");
9797

98-
INSTR_TIME_SET_CURRENT(endtime);
98+
INSTR_TIME_SET_CURRENT_COARSE(endtime);
9999
INSTR_TIME_ACCUM_DIFF(instr->counter, endtime, instr->starttime);
100100

101101
INSTR_TIME_SET_ZERO(instr->starttime);

src/include/portability/instr_time.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,25 @@ pg_clock_gettime_ns(void)
125125
#define INSTR_TIME_GET_NANOSEC(t) \
126126
((int64) (t).ticks)
127127

128+
#ifdef CLOCK_MONOTONIC_COARSE
129+
/* helper for INSTR_TIME_SET_CURRENT_COARSE */
130+
static inline instr_time
131+
pg_clock_gettime_ns_coarse(void)
132+
{
133+
instr_time now;
134+
struct timespec tmp;
135+
136+
clock_gettime(CLOCK_MONOTONIC_COARSE, &tmp);
137+
now.ticks = tmp.tv_sec * NS_PER_S + tmp.tv_nsec;
138+
139+
return now;
140+
}
141+
142+
#define INSTR_TIME_SET_CURRENT_COARSE(t) ((t) = pg_clock_gettime_ns_coarse())
143+
#else
144+
#define INSTR_TIME_SET_CURRENT_COARSE(t) INSTR_TIME_SET_CURRENT(t)
145+
#endif
146+
128147

129148
#else /* WIN32 */
130149

@@ -159,6 +178,8 @@ GetTimerFrequency(void)
159178
#define INSTR_TIME_GET_NANOSEC(t) \
160179
((int64) ((t).ticks * ((double) NS_PER_S / GetTimerFrequency())))
161180

181+
#define INSTR_TIME_SET_CURRENT_COARSE(t) INSTR_TIME_SET_CURRENT(t)
182+
162183
#endif /* WIN32 */
163184

164185

@@ -172,7 +193,7 @@ GetTimerFrequency(void)
172193
#define INSTR_TIME_SET_ZERO(t) ((t).ticks = 0)
173194

174195
#define INSTR_TIME_SET_CURRENT_LAZY(t) \
175-
(INSTR_TIME_IS_ZERO(t) ? INSTR_TIME_SET_CURRENT(t), true : false)
196+
(INSTR_TIME_IS_ZERO(t) ? INSTR_TIME_SET_CURRENT_COARSE(t), true : false)
176197

177198

178199
#define INSTR_TIME_ADD(x,y) \

0 commit comments

Comments
 (0)