Skip to content

Commit f1cb5e5

Browse files
committed
pgbench: Ensure previous progress message is fully cleared when updating.
During pgbench's table initialization, progress updates could display leftover characters from the previous message if the new message was shorter. This commit resolves the issue by appending spaces to the current message to fully overwrite any remaining characters from the previous line. Back-patch to all the supported versions. Author: Yushi Ogiwara, Tatsuo Ishii, Fujii Masao Reviewed-by: Tatsuo Ishii, Fujii Masao Discussion: https://postgr.es/m/9a9b8b95b6a709877ae48ad5b0c59bb9@oss.nttdata.com
1 parent de01960 commit f1cb5e5

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/bin/pgbench/pgbench.c

+19-7
Original file line numberDiff line numberDiff line change
@@ -3840,6 +3840,8 @@ initGenerateDataClientSide(PGconn *con)
38403840
PGresult *res;
38413841
int i;
38423842
int64 k;
3843+
int chars = 0;
3844+
int prev_chars = 0;
38433845

38443846
/* used to track elapsed time and estimate of the remaining time */
38453847
instr_time start,
@@ -3926,10 +3928,10 @@ initGenerateDataClientSide(PGconn *con)
39263928
elapsed_sec = INSTR_TIME_GET_DOUBLE(diff);
39273929
remaining_sec = ((double) scale * naccounts - j) * elapsed_sec / j;
39283930

3929-
fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)%c",
3930-
j, (int64) naccounts * scale,
3931-
(int) (((int64) j * 100) / (naccounts * (int64) scale)),
3932-
elapsed_sec, remaining_sec, eol);
3931+
chars = fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)",
3932+
j, (int64) naccounts * scale,
3933+
(int) (((int64) j * 100) / (naccounts * (int64) scale)),
3934+
elapsed_sec, remaining_sec);
39333935
}
39343936
/* let's not call the timing for each row, but only each 100 rows */
39353937
else if (use_quiet && (j % 100 == 0))
@@ -3943,14 +3945,24 @@ initGenerateDataClientSide(PGconn *con)
39433945
/* have we reached the next interval (or end)? */
39443946
if ((j == scale * naccounts) || (elapsed_sec >= log_interval * LOG_STEP_SECONDS))
39453947
{
3946-
fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)%c",
3947-
j, (int64) naccounts * scale,
3948-
(int) (((int64) j * 100) / (naccounts * (int64) scale)), elapsed_sec, remaining_sec, eol);
3948+
chars = fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)",
3949+
j, (int64) naccounts * scale,
3950+
(int) (((int64) j * 100) / (naccounts * (int64) scale)), elapsed_sec, remaining_sec);
39493951

39503952
/* skip to the next interval */
39513953
log_interval = (int) ceil(elapsed_sec / LOG_STEP_SECONDS);
39523954
}
39533955
}
3956+
3957+
/*
3958+
* If the previous progress message is longer than the current one,
3959+
* add spaces to the current line to fully overwrite any remaining
3960+
* characters from the previous message.
3961+
*/
3962+
if (prev_chars > chars)
3963+
fprintf(stderr, "%*c", prev_chars - chars, ' ');
3964+
fputc(eol, stderr);
3965+
prev_chars = chars;
39543966
}
39553967

39563968
if (eol != '\n')

0 commit comments

Comments
 (0)