lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

lynx-dev [PATCH 2.8.3.dev4] More verbose transfer stats


From: Ilya Zakharevich
Subject: lynx-dev [PATCH 2.8.3.dev4] More verbose transfer stats
Date: Fri, 23 Jul 1999 08:20:39 -0400 (EDT)

This patch 
  a) makes size/transfer rate reports use format "8.3 KB" (instead
        of "8 KB") if numbers are below 10 KB and reports are in KB;
  b) makes transferred/expected/transfer-rate use bytes/KB independently
     so "236 bytes of 56 KB" is possible, as is
        "8.3 of 56 KB, 456 bytes/sec";
  c) adds "ETA 23 sec" info if available;
  d) adds " (stalled for 75 sec)" info if available (updated each 5
     sec or so);
  e) uses gettimeofday() if present (instead of current hacks) to get more
     frequent updates.

The longest message I have seen is

Read 12 of 19 KB of data, 116 bytes/sec (stalled for 77 sec), ETA 57 sec.

Note that to implement "d" a change to ./WWW/* is required.  Do not know
what is a proper way to do this, I just include the patch in this
message...

Note that due to "e" I see no reason to have a separate logic for Win*
version (maybe a small define to get correct times).

Enjoy,
Ilya

--- ./src/HTAlert.c~    Wed Jul 14 09:25:26 1999
+++ ./src/HTAlert.c     Fri Jul 23 05:07:52 1999
@@ -174,6 +174,33 @@ PUBLIC void HTProgress ARGS1(
 #endif
 }
 
+PRIVATE char *sprint_bytes ARGS3(char *, s, long, n, char *, was_units)
+{
+    static long kb_units = 1024;
+    static char *bunits;
+    static char *kbunits;
+    char *u;
+
+    if (!bunits) {
+       bunits = gettext("bytes");
+       kbunits = gettext("KB");
+    }
+
+    u = kbunits;
+    if (LYshow_kb_rate && (n >= 10 * kb_units))
+       sprintf(s, "%ld", n/kb_units);
+    else if (LYshow_kb_rate && (n >= kb_units))
+       sprintf(s, "%.2g", ((double)n)/kb_units);
+    else {
+       sprintf(s, "%ld", n);
+       u = bunits;
+    }
+
+    if (!was_units || was_units != u)
+       sprintf(s + strlen(s), " %s", u);
+    return u;
+}
+
 /*     Issue a read-progress message.                  HTReadProgress()
 **     ------------------------------
 */
@@ -242,62 +269,79 @@ PUBLIC void HTReadProgress ARGS2(
        _HTProgress(line);
     }
 #else
-    static long kb_units = 1024;
-    static time_t first, last;
-    static long bytes_last;
+    static long bytes_last, total_last;
     static long transfer_rate = 0;
-    long divisor;
-    char line[80];
+    char line[300], bytesp[80], totalp[80], transferp[80];
+    int renew = 0;
+    char *was_units;
+#if HAVE_GETTIMEOFDAY
+    struct timeval tv;
+    int dummy = gettimeofday(&tv, (struct timezone *)0);
+    double now = tv.tv_sec + tv.tv_usec/1000000. ;
+    static double first, last, last_active;
+#else
     time_t now = time((time_t *)0);  /* once per second */
-    static char *units = "bytes";
+    static time_t first, last, last_active;
+#endif
 
     if (bytes == 0) {
-       first = last = now;
+       first = last = last_active = now;
        bytes_last = bytes;
-    } else if ((bytes > 0) &&
+       line[0] = 0;
+    } else if (bytes < 0) {    /* stalled */
+       bytes = bytes_last;
+       total = total_last;
+    }
+    if ((bytes > 0) &&
               (now != first))
-               /* 1 sec delay for transfer_rate calculation :-( */ {
+               /* 1 sec delay for transfer_rate calculation without g-t-o-d */ 
{
        if (transfer_rate <= 0)    /* the very first time */
            transfer_rate = (bytes) / (now - first);   /* bytes/sec */
+       total_last = total;
 
        /*
         * Optimal refresh time:  every 0.2 sec, use interpolation.  Transfer
         * rate is not constant when we have partial content in a proxy, so
         * interpolation lies - will check every second at least for sure.
         */
+#if HAVE_GETTIMEOFDAY
+       if (now >= last + 0.2)
+           renew = 1;
+#else
        if (((bytes - bytes_last) > (transfer_rate / 5)) || (now != last)) {
-
+           renew = 1;
            bytes_last += (transfer_rate / 5);  /* until we got next second */
-
+       }
+#endif
+       if (renew) {
            if (now != last) {
                last = now;
+               if (bytes_last != bytes)
+                   last_active = now;
                bytes_last = bytes;
-               transfer_rate = (bytes_last) / (last - first); /* more accurate 
here */
-           }
-
-           units = gettext("bytes");
-           divisor = 1;
-           if (LYshow_kb_rate
-             && (total >= kb_units || bytes >= kb_units)) {
-               units = gettext("KB");
-               divisor = kb_units;
-               bytes /= divisor;
-               if (total > 0) total /= divisor;
+               transfer_rate = bytes / (now - first); /* more accurate here */
            }
 
-           if (total >  0)
-               sprintf (line, gettext("Read %ld of %ld %s of data"), bytes, 
total, units);
+           if (total > 0)
+               was_units = sprint_bytes(totalp, total, 0);
            else
-               sprintf (line, gettext("Read %ld %s of data"), bytes, units);
-           if ((transfer_rate > 0)
-                 && (!LYshow_kb_rate || (bytes * divisor >= kb_units)))
-               sprintf (line + strlen(line), gettext(", %ld %s/sec."), 
transfer_rate / divisor, units);
+               was_units = 0;
+           sprint_bytes(bytesp, bytes, was_units);
+           sprint_bytes(transferp, transfer_rate, 0);
+
+           if (total > 0)
+               sprintf (line, gettext("Read %s of %s of data"), bytesp, 
totalp);
            else
-               sprintf (line + strlen(line), ".");
-           if (total <  0) {
-               if (total < -1)
-                   strcat(line, gettext(" (Press 'z' to abort)"));
-           }
+               sprintf (line, gettext("Read %s of data"), bytesp);
+           if (transfer_rate > 0)
+               sprintf (line + strlen(line), gettext(", %s/sec"), transferp);
+           if (now - last_active >= 5)
+               sprintf (line + strlen(line), gettext(" (stalled for %ld 
sec)"), (long)(now - last_active));
+           if (total > 0 && transfer_rate)
+               sprintf (line + strlen(line), gettext(", ETA %ld sec"), 
(long)((total - bytes)/transfer_rate));
+           sprintf (line + strlen(line), ".");
+           if (total < -1)
+               strcat(line, gettext(" (Press 'z' to abort)"));
 
            /* do not store the message for history page. */
            statusline(line);
--- ./WWW/Library/Implementation/HTTCP.c~       Wed Jul 14 09:25:26 1999
+++ ./WWW/Library/Implementation/HTTCP.c        Fri Jul 23 04:41:16 1999
@@ -1775,7 +1775,8 @@ PUBLIC int HTDoRead ARGS3(
     int ready, ret;
     fd_set readfds;
     struct timeval timeout;
-    int tries=0;
+    int tries=0, otries = 0;
+    time_t otime = time((time_t *)0);
 #if defined(UNIX) || defined(UCX)
     int nb;
 #endif /* UCX, BSN */
@@ -1821,6 +1822,16 @@ PUBLIC int HTDoRead ARGS3(
            SOCKET_ERRNO = EINTR;
 #endif
            return HT_INTERRUPTED;
+       }
+
+       if (tries - otries > 10) {
+           time_t t = time((time_t *)0);
+
+           otries = tries;
+           if (t - otime >= 5) {
+               otime = t;
+               HTReadProgress(-1, 0);  /* Put "stalled" message */
+           }
        }
 
        /*

reply via email to

[Prev in Thread] Current Thread [Next in Thread]