Skip to content

Commit d37ddb7

Browse files
committed
Use carriage returns for data insertion logs in pgbench on terminal
This is similar to what pg_basebackup and pg_rewind do when reporting cumulative data, and that's more user-friendly. Carriage returns are now used when stderr points to a terminal, and newlines are used in other cases, like a redirection to a log file. Author: Amit Langote Reviewed-by: Fabien Coelho Discussion: https://postgr.es/m/CA+HiwqFNwEjPeVaQsp2L7DyCPv1Eg1guwhrVhzMYqUJUk8ULKg@mail.gmail.com
1 parent 85b9ef5 commit d37ddb7

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/bin/pgbench/pgbench.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3835,6 +3835,9 @@ initGenerateDataClientSide(PGconn *con)
38353835
remaining_sec;
38363836
int log_interval = 1;
38373837

3838+
/* Stay on the same line if reporting to a terminal */
3839+
char eol = isatty(fileno(stderr)) ? '\r' : '\n';
3840+
38383841
fprintf(stderr, "generating data (client-side)...\n");
38393842

38403843
/*
@@ -3910,10 +3913,10 @@ initGenerateDataClientSide(PGconn *con)
39103913
elapsed_sec = INSTR_TIME_GET_DOUBLE(diff);
39113914
remaining_sec = ((double) scale * naccounts - j) * elapsed_sec / j;
39123915

3913-
fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)\n",
3916+
fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)%c",
39143917
j, (int64) naccounts * scale,
39153918
(int) (((int64) j * 100) / (naccounts * (int64) scale)),
3916-
elapsed_sec, remaining_sec);
3919+
elapsed_sec, remaining_sec, eol);
39173920
}
39183921
/* let's not call the timing for each row, but only each 100 rows */
39193922
else if (use_quiet && (j % 100 == 0))
@@ -3927,16 +3930,19 @@ initGenerateDataClientSide(PGconn *con)
39273930
/* have we reached the next interval (or end)? */
39283931
if ((j == scale * naccounts) || (elapsed_sec >= log_interval * LOG_STEP_SECONDS))
39293932
{
3930-
fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)\n",
3933+
fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) done (elapsed %.2f s, remaining %.2f s)%c",
39313934
j, (int64) naccounts * scale,
3932-
(int) (((int64) j * 100) / (naccounts * (int64) scale)), elapsed_sec, remaining_sec);
3935+
(int) (((int64) j * 100) / (naccounts * (int64) scale)), elapsed_sec, remaining_sec, eol);
39333936

39343937
/* skip to the next interval */
39353938
log_interval = (int) ceil(elapsed_sec / LOG_STEP_SECONDS);
39363939
}
39373940
}
3938-
39393941
}
3942+
3943+
if (eol != '\n')
3944+
fputc('\n', stderr); /* Need to move to next line */
3945+
39403946
if (PQputline(con, "\\.\n"))
39413947
{
39423948
fprintf(stderr, "very last PQputline failed\n");

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy