File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff 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 );
Original file line number Diff line number Diff 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 ) \
You can’t perform that action at this time.
0 commit comments