Skip to content

Commit 0fae1e0

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8c8e978 commit 0fae1e0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

progress.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct progress {
3636
unsigned delay;
3737
unsigned delayed_percent_treshold;
3838
struct throughput *throughput;
39+
uint64_t start_ns;
3940
};
4041

4142
static volatile sig_atomic_t progress_update;
@@ -221,6 +222,7 @@ struct progress *start_progress_delay(const char *title, unsigned total,
221222
progress->delayed_percent_treshold = percent_treshold;
222223
progress->delay = delay;
223224
progress->throughput = NULL;
225+
progress->start_ns = getnanotime();
224226
set_progress_signal();
225227
return progress;
226228
}
@@ -247,8 +249,10 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
247249
struct throughput *tp = progress->throughput;
248250

249251
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);
252256
throughput_string(&tp->display, tp->curr_total, rate);
253257
}
254258
progress_update = 1;

0 commit comments

Comments
 (0)