mirror of
https://github.com/postgres/postgres.git
synced 2025-04-29 13:56:47 +03:00
Fix pgbench's --progress-timestamp option to print Unix-epoch timestamps.
As a consequence of commit 1d63f7d2d, 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 74baa1e3b and 67a875355, 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
This commit is contained in:
parent
a6940bdcb9
commit
feffa0e079
@ -4652,10 +4652,21 @@ threadRun(void *arg)
|
|||||||
(cur.cnt - last.cnt);
|
(cur.cnt - last.cnt);
|
||||||
|
|
||||||
if (progress_timestamp)
|
if (progress_timestamp)
|
||||||
sprintf(tbuf, "%.03f s",
|
{
|
||||||
INSTR_TIME_GET_MILLISEC(now_time) / 1000.0);
|
/*
|
||||||
|
* On some platforms the current system timestamp is
|
||||||
|
* available in now_time, but rather than get entangled
|
||||||
|
* with that, we just eat the cost of an extra syscall in
|
||||||
|
* all cases.
|
||||||
|
*/
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
snprintf(tbuf, sizeof(tbuf), "%ld.%03ld s",
|
||||||
|
(long) tv.tv_sec, (long) (tv.tv_usec / 1000));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
sprintf(tbuf, "%.1f s", total_run);
|
snprintf(tbuf, sizeof(tbuf), "%.1f s", total_run);
|
||||||
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"progress: %s, %.1f tps, lat %.3f ms stddev %.3f",
|
"progress: %s, %.1f tps, lat %.3f ms stddev %.3f",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user