Skip to content

Commit feffa0e

Browse files
committed
Fix pgbench's --progress-timestamp option to print Unix-epoch timestamps.
As a consequence of commit 1d63f7d, on platforms with CLOCK_MONOTONIC, you got some random timescale or other instead of standard Unix timestamps as expected. I'd attempted to fix pgbench for that change in commits 74baa1e and 67a8753, but missed this place. Fix in the same way as those previous commits, ie, just eat the cost of an extra gettimeofday(); one extra syscall per progress report isn't worth sweating over. Per report from Jeff Janes. In passing, use snprintf not sprintf for this purpose. I don't think there's any chance of actual buffer overrun, but it just looks safer. Discussion: https://postgr.es/m/CAMkU=1zrQaPwBN+NcBd3pWCb=vWaiL=mmWfJjDJjh-a7eVr-Og@mail.gmail.com
1 parent a6940bd commit feffa0e

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/bin/pgbench/pgbench.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -4652,10 +4652,21 @@ threadRun(void *arg)
46524652
(cur.cnt - last.cnt);
46534653

46544654
if (progress_timestamp)
4655-
sprintf(tbuf, "%.03f s",
4656-
INSTR_TIME_GET_MILLISEC(now_time) / 1000.0);
4655+
{
4656+
/*
4657+
* On some platforms the current system timestamp is
4658+
* available in now_time, but rather than get entangled
4659+
* with that, we just eat the cost of an extra syscall in
4660+
* all cases.
4661+
*/
4662+
struct timeval tv;
4663+
4664+
gettimeofday(&tv, NULL);
4665+
snprintf(tbuf, sizeof(tbuf), "%ld.%03ld s",
4666+
(long) tv.tv_sec, (long) (tv.tv_usec / 1000));
4667+
}
46574668
else
4658-
sprintf(tbuf, "%.1f s", total_run);
4669+
snprintf(tbuf, sizeof(tbuf), "%.1f s", total_run);
46594670

46604671
fprintf(stderr,
46614672
"progress: %s, %.1f tps, lat %.3f ms stddev %.3f",

0 commit comments

Comments
 (0)