From edccc982e515e63a080a75fb49fd08b946f62cc6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 13 Feb 2018 16:48:52 +0100 Subject: [PATCH] progress meter: add disabled code for a more stable ETA Compiles to ~25 bytes if enabled. Signed-off-by: Denys Vlasenko --- include/libbb.h | 1 + libbb/progress.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/libbb.h b/include/libbb.h index 2c34859a2..c02621d94 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1949,6 +1949,7 @@ typedef struct bb_progress_t { unsigned last_update_sec; unsigned last_change_sec; unsigned start_sec; + /*unsigned last_eta;*/ const char *curfile; } bb_progress_t; diff --git a/libbb/progress.c b/libbb/progress.c index f1d980d68..23e974ce7 100644 --- a/libbb/progress.c +++ b/libbb/progress.c @@ -57,6 +57,9 @@ void FAST_FUNC bb_progress_init(bb_progress_t *p, const char *curfile) p->last_update_sec = p->start_sec; p->last_change_sec = p->start_sec; p->last_size = 0; +#if 0 + p->last_eta = INT_MAX; +#endif } /* File already had beg_size bytes. @@ -192,6 +195,16 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p, /* if 32bit, can overflow ^^^^^^^^^^, but this would only show bad ETA */ if (eta >= 1000*60*60) eta = 1000*60*60 - 1; +#if 0 + /* To prevent annoying "back-and-forth" estimation jitter, + * if new ETA is larger than the last just by a few seconds, + * disregard it, and show last one. The end result is that + * ETA usually only decreases, unless download slows down a lot. + */ + if ((unsigned)(eta - p->last_eta) < 10) + eta = p->last_eta; + p->last_eta = eta; +#endif secs = eta % 3600; hours = eta / 3600; fprintf(stderr, "%3u:%02u:%02u ETA", hours, secs / 60, secs % 60); -- 2.25.1