git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: "積丹尼 Dan Jacobson" <jidanni@jidanni.org>, git@vger.kernel.org
Subject: Re: 0 bytes/s vs. ∞ bytes/s
Date: Sat, 8 Jul 2017 18:43:42 +0200	[thread overview]
Message-ID: <2ac080ed-57aa-5492-8887-4421c50cf3cd@web.de> (raw)
In-Reply-To: <87lgo02qat.fsf@jidanni.org>

Am 07.07.2017 um 17:57 schrieb 積丹尼 Dan Jacobson:
> Receiving objects: 100% (1003/1003), 1.15 MiB | 0 bytes/s, done.
> Receiving objects: 100% (1861/1861), 11.74 MiB | 4.58 MiB/s, done.
> Receiving objects: 100% (474/474), 160.72 KiB | 0 bytes/s, done.
> Receiving objects: 100% (7190/7190), 26.02 MiB | 6.53 MiB/s, done.
> 
> If the connection is too fast to calculate, please report
> ∞ bytes/s or
> inf bytes/s or
> ? bytes/s or
> anything but 0 bytes/s, which means nothing (transmitted.)

I don't know your actual transfer rate, but I would guess it's closer to
zero than to infinity. :)

How about this, though:

-- >8 --
Subject: [PATCH] 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>
---
 progress.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/progress.c b/progress.c
index 29378caa05..73e36d4a42 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;
-- 
2.13.2

  reply	other threads:[~2017-07-08 16:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-07 15:57 0 bytes/s vs. ∞ bytes/s 積丹尼 Dan Jacobson
2017-07-08 16:43 ` René Scharfe [this message]
2017-07-08 19:30 ` 積丹尼 Dan Jacobson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2ac080ed-57aa-5492-8887-4421c50cf3cd@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=jidanni@jidanni.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).