pg_time_now(). This uses INSTR_TIME_SET_CURRENT in it, but this macro can call clock_gettime(CLOCK_MONOTONIC[_RAW], ) instead of gettimeofday or clock_gettime(CLOCK_REALTIME, ). When CLOCK_MONOTONIC[_RAW] is used, clock_gettime doesn't return epoch time. Therefore, we can use INSTR_TIME_SET_CURRENT aiming to calculate a duration, but we should not have used this to get the current timestamp.I think we can fix this issue by using gettimeofday for logging as before this was changed. I attached the patch.
I cannot say that I'm thrilled by having multiple tv stuff back in several place. I can be okay with one, though. What about the attached? Does it make sense?
-- Fabien.
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index d7479925cb..5fe2a9286f 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -672,11 +672,11 @@ static const PsqlScanCallbacks pgbench_callbacks = { static inline pg_time_usec_t pg_time_now(void) { - instr_time now; + struct timeval tv; - INSTR_TIME_SET_CURRENT(now); + gettimeofday(&tv, NULL); - return (pg_time_usec_t) INSTR_TIME_GET_MICROSEC(now); + return tv.tv_sec * 1000000 + tv.tv_usec; } static inline void