pg_checksums_progress_eta_V0.patch
text/x-patch
Filename: pg_checksums_progress_eta_V0.patch
Type: text/x-patch
Part: 1
Patch
Format: unified
| File | + | − |
|---|---|---|
| src/bin/pg_checksums/pg_checksums.c | 11 | 2 |
diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c
index a439da231f..1d82b92bf0 100644
--- a/src/bin/pg_checksums/pg_checksums.c
+++ b/src/bin/pg_checksums/pg_checksums.c
@@ -136,6 +136,7 @@ report_progress(bool force)
{
instr_time now;
double elapsed;
+ double remaining;
double total_percent;
double current_speed;
@@ -163,6 +164,9 @@ report_progress(bool force)
/* Calculate current percent done */
total_percent = total_size ? 100.0 * current_size / total_size : 0.0;
+ /* Calculate remaining time in milliseconds */
+ remaining = elapsed * (100 / total_percent) - elapsed;
+
#define MEGABYTES (1024 * 1024)
/* Calculate current speed */
@@ -173,8 +177,13 @@ report_progress(bool force)
snprintf(currentstr, sizeof(currentstr), INT64_FORMAT,
current_size / MEGABYTES);
- fprintf(stderr, "%s/%s MB (%d%%, %.0f MB/s)",
- currentstr, totalstr, (int)total_percent, current_speed);
+ /* Only print remainging time after five seconds */
+ if (elapsed / 1000 < 5)
+ fprintf(stderr, "%s/%s MB (%d%%, %.0f MB/s)%20s",
+ currentstr, totalstr, (int)total_percent, current_speed, "");
+ else
+ fprintf(stderr, "%s/%s MB (%d%%, %.0f MB/s, %.0f s remaining)%20s",
+ currentstr, totalstr, (int)total_percent, current_speed, remaining / 1000, "");
/* Stay on the same line if reporting to a terminal */
fprintf(stderr, isatty(fileno(stderr)) ? "\r" : "\n");