Skip to content

Commit 841a654

Browse files
committed
Fix progress logging when scale factor is large.
Integer overflow showed minus percent and minus remaining time something like this. 239300000 of 3800000000 tuples (-48%) done (elapsed 226.86 s, remaining -696.10 s).
1 parent 108e399 commit 841a654

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

contrib/pgbench/pgbench.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,11 +1720,11 @@ init(bool is_no_vacuum)
17201720
INSTR_TIME_SUBTRACT(diff, start);
17211721

17221722
elapsed_sec = INSTR_TIME_GET_DOUBLE(diff);
1723-
remaining_sec = (scale * naccounts - j) * elapsed_sec / j;
1723+
remaining_sec = ((double) scale * naccounts - j) * elapsed_sec / j;
17241724

17251725
fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s).\n",
17261726
j, (int64) naccounts * scale,
1727-
(int) (((int64) j * 100) / (naccounts * scale)),
1727+
(int) (((int64) j * 100) / (naccounts * (int64) scale)),
17281728
elapsed_sec, remaining_sec);
17291729
}
17301730
/* let's not call the timing for each row, but only each 100 rows */
@@ -1734,14 +1734,14 @@ init(bool is_no_vacuum)
17341734
INSTR_TIME_SUBTRACT(diff, start);
17351735

17361736
elapsed_sec = INSTR_TIME_GET_DOUBLE(diff);
1737-
remaining_sec = (scale * naccounts - j) * elapsed_sec / j;
1737+
remaining_sec = ((double) scale * naccounts - j) * elapsed_sec / j;
17381738

17391739
/* have we reached the next interval (or end)? */
17401740
if ((j == scale * naccounts) || (elapsed_sec >= log_interval * LOG_STEP_SECONDS))
17411741
{
17421742
fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s).\n",
17431743
j, (int64) naccounts * scale,
1744-
(int) (((int64) j * 100) / (naccounts * scale)), elapsed_sec, remaining_sec);
1744+
(int) (((int64) j * 100) / (naccounts * (int64) scale)), elapsed_sec, remaining_sec);
17451745

17461746
/* skip to the next interval */
17471747
log_interval = (int) ceil(elapsed_sec / LOG_STEP_SECONDS);

0 commit comments

Comments
 (0)