Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit af35fe5

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 09d09d4 commit af35fe5

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/bin/pgbench/pgbench.c

+16-5
Original file line numberDiff line numberDiff line change
@@ -4944,6 +4944,7 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
49444944
int n;
49454945
int64 k;
49464946
int chars = 0;
4947+
int prev_chars = 0;
49474948
PGresult *res;
49484949
PQExpBufferData sql;
49494950
char copy_statement[256];
@@ -5004,10 +5005,10 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
50045005
double elapsed_sec = PG_TIME_GET_DOUBLE(pg_time_now() - start);
50055006
double remaining_sec = ((double) total - j) * elapsed_sec / j;
50065007

5007-
chars = fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) of %s done (elapsed %.2f s, remaining %.2f s)%c",
5008+
chars = fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) of %s done (elapsed %.2f s, remaining %.2f s)",
50085009
j, total,
50095010
(int) ((j * 100) / total),
5010-
table, elapsed_sec, remaining_sec, eol);
5011+
table, elapsed_sec, remaining_sec);
50115012
}
50125013
/* let's not call the timing for each row, but only each 100 rows */
50135014
else if (use_quiet && (j % 100 == 0))
@@ -5018,19 +5019,29 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
50185019
/* have we reached the next interval (or end)? */
50195020
if ((j == total) || (elapsed_sec >= log_interval * LOG_STEP_SECONDS))
50205021
{
5021-
chars = fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) of %s done (elapsed %.2f s, remaining %.2f s)%c",
5022+
chars = fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) of %s done (elapsed %.2f s, remaining %.2f s)",
50225023
j, total,
50235024
(int) ((j * 100) / total),
5024-
table, elapsed_sec, remaining_sec, eol);
5025+
table, elapsed_sec, remaining_sec);
50255026

50265027
/* skip to the next interval */
50275028
log_interval = (int) ceil(elapsed_sec / LOG_STEP_SECONDS);
50285029
}
50295030
}
5031+
5032+
/*
5033+
* If the previous progress message is longer than the current one,
5034+
* add spaces to the current line to fully overwrite any remaining
5035+
* characters from the previous message.
5036+
*/
5037+
if (prev_chars > chars)
5038+
fprintf(stderr, "%*c", prev_chars - chars, ' ');
5039+
fputc(eol, stderr);
5040+
prev_chars = chars;
50305041
}
50315042

50325043
if (chars != 0 && eol != '\n')
5033-
fprintf(stderr, "%*c\r", chars - 1, ' '); /* Clear the current line */
5044+
fprintf(stderr, "%*c\r", chars, ' '); /* Clear the current line */
50345045

50355046
if (PQputline(con, "\\.\n"))
50365047
pg_fatal("very last PQputline failed");

0 commit comments

Comments
 (0)