progress: show overall rate in last update
The values in struct throughput are only updated every 0.5 seconds. If we're all done before that time span then the final update will show a rate of 0 bytes/s, which is misleading if some bytes had been handled. Remember the start time and show the total throughput instead. And avoid division by zero by enforcing a minimum time span value of 1 (unit: 1/1024th of a second). That makes the resulting rate an underestimation, but it's closer to the actual value than the currently shown 0 bytes/s. Reported-by: 積丹尼 Dan Jacobson <jidanni@jidanni.org> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jul 8, 2017 at 18:43 UTC
0fae1e072a925b76f35666c9bcd965ea5e3e5574
1 file changed
+6
-2
progress.c
+6
-2
@@ -36,6 +36,7 @@ struct progress {
36
unsigned delay;
37
unsigned delayed_percent_treshold;
38
struct throughput *throughput;
39
+ uint64_t start_ns;
40
};
41
42
static volatile sig_atomic_t progress_update;
@@ -221,6 +222,7 @@ struct progress *start_progress_delay(const char *title, unsigned total,
222
progress->delayed_percent_treshold = percent_treshold;
223
progress->delay = delay;
224
progress->throughput = NULL;
225
+ progress->start_ns = getnanotime();
226
set_progress_signal();
227
return progress;
228
}
@@ -247,8 +249,10 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
249
struct throughput *tp = progress->throughput;
250
251
if (tp) {
250
- unsigned int rate = !tp->avg_misecs ? 0 :
251
- tp->avg_bytes / tp->avg_misecs;
252
+ uint64_t now_ns = getnanotime();
253
+ unsigned int misecs, rate;
254
+ misecs = ((now_ns - progress->start_ns) * 4398) >> 32;
255
+ rate = tp->curr_total / (misecs ? misecs : 1);
256
throughput_string(&tp->display, tp->curr_total, rate);
257
}
258
progress_update = 1;