Hello,
i am often sitting behind a very slow internet link and thought, it might be useful to show the current bandwidth while downloading something with ftp(1). This looks like: $ ftp http://url 60% |************* | 105 MB 0116 KB/s 11:22 ETA Is this of interest for others? Any comments on that? Christian diff --git util.c util.c index 1c82f3fb478..a260db74375 100644 --- util.c +++ util.c @@ -748,6 +748,17 @@ static struct timespec start; char *action; +static int +find_prefix_index(off_t* sz, off_t maxidx) { + int j = 0; + + while (*sz >= 100000 && j < maxidx - 1) { + j++; + *sz >>= 10; + } + return j; +} + void progressmeter(int flag, const char *filename) { @@ -761,9 +772,9 @@ progressmeter(int flag, const char *filename) static off_t lastsize; static char *title = NULL; struct timespec now, td, wait; - off_t cursize, abbrevsize; + off_t cursize, abbrevsize, abbrevsize_bw = 0; double elapsed; - int ratio, barlength, i, remaining, overhead = 30; + int ratio, barlength, i, j, remaining, overhead = 40; char buf[512]; if (flag == -1) { @@ -841,12 +852,9 @@ progressmeter(int flag, const char *filename) barlength - i, ""); } - i = 0; abbrevsize = cursize; - while (abbrevsize >= 100000 && i < sizeof(prefixes)-1) { - i++; - abbrevsize >>= 10; - } + i = find_prefix_index(&abbrevsize, sizeof(prefixes)); + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %5lld %c%c ", (long long)abbrevsize, prefixes[i], prefixes[i] == ' ' ? ' ' : 'B'); @@ -878,7 +886,7 @@ progressmeter(int flag, const char *filename) "%02d:%02d ", i / 60, i % 60); } else if (bytes <= 0 || elapsed <= 0.0 || cursize > filesize) { snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), - " --:-- ETA"); + " 0000 B/s --:-- ETA"); } else if (wait.tv_sec >= STALLTIME) { snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " - stalled -"); @@ -886,6 +894,13 @@ progressmeter(int flag, const char *filename) remaining = (int)((filesize - restart_point) / (bytes / elapsed) - elapsed); i = remaining / 3600; + + if (elapsed) + abbrevsize_bw = cursize / elapsed; + j = find_prefix_index(&abbrevsize_bw, sizeof(prefixes)); + + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), + " %04lld %cB/s", abbrevsize_bw, prefixes[j]); if (i) snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%2d:", i); |
Hi Christian,
On 08.04.2018 22:42, Christian Barthel wrote: > Hello, > > i am often sitting behind a very slow internet link and thought, it > might be useful to show the current bandwidth while downloading > something with ftp(1). Since I sometimes work with crappy WLANs/connections I very much appreciate your patch! Have you tried your patch in bsd.rd or in a classic 80x25 screen where screen space is limited? Cheers Matthias |
On 2018/04/09 09:27, Matthias Schmidt wrote:
> Hi Christian, > > On 08.04.2018 22:42, Christian Barthel wrote: > > Hello, > > > > i am often sitting behind a very slow internet link and thought, it > > might be useful to show the current bandwidth while downloading > > something with ftp(1). > > Since I sometimes work with crappy WLANs/connections I very much appreciate > your patch! Do you know you can just send SIGINFO (often bound to ^T) to get the same information? |
Stuart Henderson <[hidden email]> writes:
> On 2018/04/09 09:27, Matthias Schmidt wrote: >> Hi Christian, >> >> On 08.04.2018 22:42, Christian Barthel wrote: >> > Hello, >> > >> > i am often sitting behind a very slow internet link and thought, it >> > might be useful to show the current bandwidth while downloading >> > something with ftp(1). >> >> Since I sometimes work with crappy WLANs/connections I very much appreciate >> your patch! > > Do you know you can just send SIGINFO (often bound to ^T) to get the same > information? Hi Stuart, Hi Matthias, thanks for your replies. I've tested it with 80x25 terminals and also checked the bsd.rd installer image. To me, it looks ok. I also know about SIGINFO but in my particular case, it was useful to print the bandwidth all the time. But I guess that most users don't need that information and having SIGINFO/^T is sufficient. Thanks for your comments, Christian |
Free forum by Nabble | Edit this page |