summaryrefslogtreecommitdiff
path: root/progress.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-07-08 16:43:42 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-07-09 16:54:20 (GMT)
commit0fae1e072a925b76f35666c9bcd965ea5e3e5574 (patch)
tree16d03a933c8e27a9c41a5d9269056735d15555f5 /progress.c
parent8c8e978f5719c6a58fb998742207bf907f963143 (diff)
downloadgit-0fae1e072a925b76f35666c9bcd965ea5e3e5574.zip
git-0fae1e072a925b76f35666c9bcd965ea5e3e5574.tar.gz
git-0fae1e072a925b76f35666c9bcd965ea5e3e5574.tar.bz2
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>
Diffstat (limited to 'progress.c')
-rw-r--r--progress.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/progress.c b/progress.c
index 29378ca..73e36d4 100644
--- a/progress.c
+++ b/progress.c
@@ -36,6 +36,7 @@ struct progress {
unsigned delay;
unsigned delayed_percent_treshold;
struct throughput *throughput;
+ uint64_t start_ns;
};
static volatile sig_atomic_t progress_update;
@@ -221,6 +222,7 @@ struct progress *start_progress_delay(const char *title, unsigned total,
progress->delayed_percent_treshold = percent_treshold;
progress->delay = delay;
progress->throughput = NULL;
+ progress->start_ns = getnanotime();
set_progress_signal();
return progress;
}
@@ -247,8 +249,10 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
struct throughput *tp = progress->throughput;
if (tp) {
- unsigned int rate = !tp->avg_misecs ? 0 :
- tp->avg_bytes / tp->avg_misecs;
+ uint64_t now_ns = getnanotime();
+ unsigned int misecs, rate;
+ misecs = ((now_ns - progress->start_ns) * 4398) >> 32;
+ rate = tp->curr_total / (misecs ? misecs : 1);
throughput_string(&tp->display, tp->curr_total, rate);
}
progress_update = 1;