From: Linus Torvalds <torvalds@osdl.org>
To: Junio C Hamano <junkio@cox.net>, Git Mailing List <git@vger.kernel.org>
Subject: Make "git clone" pack-fetching download statistics better
Date: Sat, 11 Feb 2006 10:43:56 -0800 (PST) [thread overview]
Message-ID: <Pine.LNX.4.64.0602111041430.3691@g5.osdl.org> (raw)
Make "git clone" pack-fetching download statistics better
Average it out over a few events to make the numbers stable, and fix the
silly usec->binary-ms conversion.
Yeah, yeah, it's arguably eye-candy to keep the user calm, but let's do
that right.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
This is obviously against my previous diff to do the verbose output in the
first place. If you want a combined diff, just holler.
This makes the download speed be totally stable for me on an otherwise
idle DSL connection (146 kB/s, which sounds right, in case anybody cares).
diff --git a/fetch-clone.c b/fetch-clone.c
index d8216cb..da1b3ff 100644
--- a/fetch-clone.c
+++ b/fetch-clone.c
@@ -130,12 +130,35 @@ int receive_unpack_pack(int fd[2], const
die("git-unpack-objects died of unnatural causes %d", status);
}
+/*
+ * We average out the download speed over this many "events", where
+ * an event is a minimum of about half a second. That way, we get
+ * a reasonably stable number.
+ */
+#define NR_AVERAGE (4)
+
+/*
+ * A "binary msec" is a power-of-two-msec, aka 1/1024th of a second.
+ * Keeing the time in that format means that "bytes / msecs" means
+ * is the same as kB/s (modulo rounding).
+ *
+ * 1000512 is a magic number (usecs in a second, rounded up by half
+ * of 1024, to make "rounding" come out right ;)
+ */
+#define usec_to_binarymsec(x) ((int)(x) / (1000512 >> 10))
+
int receive_keep_pack(int fd[2], const char *me, int quiet)
{
char tmpfile[PATH_MAX];
int ofd, ifd;
unsigned long total;
static struct timeval prev_tv;
+ struct average {
+ unsigned long bytes;
+ unsigned long time;
+ } download[NR_AVERAGE] = { {0, 0}, };
+ unsigned long avg_bytes, avg_time;
+ int idx = 0;
ifd = fd[0];
snprintf(tmpfile, sizeof(tmpfile),
@@ -146,6 +169,8 @@ int receive_keep_pack(int fd[2], const c
gettimeofday(&prev_tv, NULL);
total = 0;
+ avg_bytes = 0;
+ avg_time = 0;
while (1) {
char buf[8192];
ssize_t sz, wsz, pos;
@@ -184,14 +209,27 @@ int receive_keep_pack(int fd[2], const c
gettimeofday(&tv, NULL);
msecs = tv.tv_sec - prev_tv.tv_sec;
msecs <<= 10;
- msecs += (int)(tv.tv_usec - prev_tv.tv_usec) >> 10;
+ msecs += usec_to_binarymsec(tv.tv_usec - prev_tv.tv_usec);
+
if (msecs > 500) {
prev_tv = tv;
last = total;
- fprintf(stderr, "%4lu.%03luMB (%lu kB/s) \r",
+
+ /* Update averages ..*/
+ avg_bytes += diff;
+ avg_time += msecs;
+ avg_bytes -= download[idx].bytes;
+ avg_time -= download[idx].time;
+ download[idx].bytes = diff;
+ download[idx].time = msecs;
+ idx++;
+ if (idx >= NR_AVERAGE)
+ idx = 0;
+
+ fprintf(stderr, "%4lu.%03luMB (%lu kB/s) \r",
total >> 20,
1000*((total >> 10) & 1023)>>10,
- diff / msecs );
+ avg_bytes / avg_time );
}
}
}
next reply other threads:[~2006-02-11 18:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-11 18:43 Linus Torvalds [this message]
2006-02-12 1:58 ` [PATCH] fetch-clone progress: finishing touches Junio C Hamano
2006-02-12 3:01 ` Linus Torvalds
2006-02-12 20:37 ` Linus Torvalds
2006-02-12 21:50 ` Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0602111041430.3691@g5.osdl.org \
--to=torvalds@osdl.org \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/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.
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 NNTP newsgroup(s).