Skip to content

Commit 0f13e1a

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 4c0e70f commit 0f13e1a

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
@@ -4222,6 +4222,8 @@ initGenerateDataClientSide(PGconn *con)
42224222
PGresult *res;
42234223
int i;
42244224
int64 k;
4225+
int chars = 0;
4226+
int prev_chars = 0;
42254227

42264228
/* used to track elapsed time and estimate of the remaining time */
42274229
pg_time_usec_t start;
@@ -4304,10 +4306,10 @@ initGenerateDataClientSide(PGconn *con)
43044306
double elapsed_sec = PG_TIME_GET_DOUBLE(pg_time_now() - start);
43054307
double remaining_sec = ((double) scale * naccounts - j) * elapsed_sec / j;
43064308

4307-
fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)%c",
4308-
j, (int64) naccounts * scale,
4309-
(int) (((int64) j * 100) / (naccounts * (int64) scale)),
4310-
elapsed_sec, remaining_sec, eol);
4309+
chars = fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)",
4310+
j, (int64) naccounts * scale,
4311+
(int) (((int64) j * 100) / (naccounts * (int64) scale)),
4312+
elapsed_sec, remaining_sec);
43114313
}
43124314
/* let's not call the timing for each row, but only each 100 rows */
43134315
else if (use_quiet && (j % 100 == 0))
@@ -4318,14 +4320,24 @@ initGenerateDataClientSide(PGconn *con)
43184320
/* have we reached the next interval (or end)? */
43194321
if ((j == scale * naccounts) || (elapsed_sec >= log_interval * LOG_STEP_SECONDS))
43204322
{
4321-
fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)%c",
4322-
j, (int64) naccounts * scale,
4323-
(int) (((int64) j * 100) / (naccounts * (int64) scale)), elapsed_sec, remaining_sec, eol);
4323+
chars = fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)",
4324+
j, (int64) naccounts * scale,
4325+
(int) (((int64) j * 100) / (naccounts * (int64) scale)), elapsed_sec, remaining_sec);
43244326

43254327
/* skip to the next interval */
43264328
log_interval = (int) ceil(elapsed_sec / LOG_STEP_SECONDS);
43274329
}
43284330
}
4331+
4332+
/*
4333+
* If the previous progress message is longer than the current one,
4334+
* add spaces to the current line to fully overwrite any remaining
4335+
* characters from the previous message.
4336+
*/
4337+
if (prev_chars > chars)
4338+
fprintf(stderr, "%*c", prev_chars - chars, ' ');
4339+
fputc(eol, stderr);
4340+
prev_chars = chars;
43294341
}
43304342

43314343
if (eol != '\n')

0 commit comments

Comments
 (0)