diff options
author | Fujii Masao <fujii@postgresql.org> | 2024-11-27 23:01:53 +0900 |
---|---|---|
committer | Fujii Masao <fujii@postgresql.org> | 2024-11-27 23:01:53 +0900 |
commit | af35fe501af52f90355ac184a17643932a26464f (patch) | |
tree | 0218f3c9fba9fab560177b24e30af50f60c36d1c /src | |
parent | 09d09d4297b9acbc2848ec35e8bf030d6c1fae18 (diff) | |
download | postgresql-af35fe501af52f90355ac184a17643932a26464f.tar.gz postgresql-af35fe501af52f90355ac184a17643932a26464f.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/pgbench/pgbench.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index ba247f3f85c..85e7b68baa3 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -4944,6 +4944,7 @@ initPopulateTable(PGconn *con, const char *table, int64 base, int n; int64 k; int chars = 0; + int prev_chars = 0; PGresult *res; PQExpBufferData sql; char copy_statement[256]; @@ -5004,10 +5005,10 @@ initPopulateTable(PGconn *con, const char *table, int64 base, double elapsed_sec = PG_TIME_GET_DOUBLE(pg_time_now() - start); double remaining_sec = ((double) total - j) * elapsed_sec / j; - chars = fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) of %s done (elapsed %.2f s, remaining %.2f s)%c", + chars = fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) of %s done (elapsed %.2f s, remaining %.2f s)", j, total, (int) ((j * 100) / total), - table, elapsed_sec, remaining_sec, eol); + table, elapsed_sec, remaining_sec); } /* let's not call the timing for each row, but only each 100 rows */ else if (use_quiet && (j % 100 == 0)) @@ -5018,19 +5019,29 @@ initPopulateTable(PGconn *con, const char *table, int64 base, /* have we reached the next interval (or end)? */ if ((j == total) || (elapsed_sec >= log_interval * LOG_STEP_SECONDS)) { - chars = fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) of %s done (elapsed %.2f s, remaining %.2f s)%c", + chars = fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) of %s done (elapsed %.2f s, remaining %.2f s)", j, total, (int) ((j * 100) / total), - table, elapsed_sec, remaining_sec, eol); + table, elapsed_sec, remaining_sec); /* skip to the next interval */ log_interval = (int) ceil(elapsed_sec / LOG_STEP_SECONDS); } } + + /* + * If the previous progress message is longer than the current one, + * add spaces to the current line to fully overwrite any remaining + * characters from the previous message. + */ + if (prev_chars > chars) + fprintf(stderr, "%*c", prev_chars - chars, ' '); + fputc(eol, stderr); + prev_chars = chars; } if (chars != 0 && eol != '\n') - fprintf(stderr, "%*c\r", chars - 1, ' '); /* Clear the current line */ + fprintf(stderr, "%*c\r", chars, ' '); /* Clear the current line */ if (PQputline(con, "\\.\n")) pg_fatal("very last PQputline failed"); |