Skip to content

Commit

Permalink
progress: show overall rate in last update
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Rene Scharfe <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
rscharfe authored and gitster committed Jul 9, 2017
1 parent 8c8e978 commit 0fae1e0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions progress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit 0fae1e0

Please sign in to comment.