Download speed feature

Jerry Quinn (jquinn@nortel.ca)
12 Mar 1998 10:02 EST


Hi.  Not a bug report, but a possible feature.  I've always liked the report
of download speed from Fetch on the Mac and have added a simple d/l speed
report to efs.  It is just the number of bytes over the time for the last N
samples with a length of 20 samples, so we get a sliding window of rate
measurement.  This helps keep the rate from bouncing around too much.

This patch is applied to efs 1.15.

-- 
Jerry Quinn				Tel: (514) 761-8737
jquinn@nortel.ca			Fax: (514) 761-8505
Speech Recognition Research


--- efs.el.orig	Tue Feb 18 12:00:57 1997
+++ efs.el	Fri Mar  6 01:41:42 1998
@@ -1863,6 +1863,10 @@
 (defvar efs-process-hash-mark-unit nil)
 (make-variable-buffer-local 'efs-process-hash-mark-unit)
 
+;; JQ - history of hash-mark counts and times to compute transfer rate
+(defvar efs-process-hash-mark-history (list (list 0 (current-time))))
+(make-variable-buffer-local 'efs-process-hash-mark-history)
+
 (defvar efs-process-last-percent -1)
 (make-variable-buffer-local 'efs-process-last-percent)
 
@@ -3188,10 +3192,48 @@
 			       (ash efs-process-hash-mark-count -6))
 			  (ash (* efs-process-hash-mark-unit
 				  efs-process-hash-mark-count)
-			       -6))))
+			       -6)))
+		;; JQ For figuring out K/s rate
+		;; dkbytes is the number of kbytes since previous call
+		(oldhashcnt (car (car efs-process-hash-mark-history)))
+		(oldtime (nth 1 (car efs-process-hash-mark-history)))
+		(diffcount (- efs-process-hash-mark-count oldhashcnt))
+		(dkbytes (if big
+			     (* efs-process-hash-mark-unit
+				(ash diffcount -6))
+			   (ash (* efs-process-hash-mark-unit
+				   diffcount)
+				-6)))
+		(curtime (current-time))
+		dtime rate)
+
+	   ;; JQ - For K/s rate
+	
+	   ;; Update hashmark history - add current info, remove old stuff
+;	   (nconc efs-process-hash-mark-history (list (list efs-process-hash-mark-count curtime)))
+	   (setq efs-process-hash-mark-history
+		 (append efs-process-hash-mark-history (list (list efs-process-hash-mark-count curtime))))
+	   (if (> (length efs-process-hash-mark-history) 20)
+	       (setq efs-process-hash-mark-history (cdr efs-process-hash-mark-history)))
+
+	   ;; JQ k/s calc
+	   ;; We'll assume there aren't 18 hours between hash updates
+	   (setq dtime (nth 1 (efs-time-minus curtime oldtime)))
+	   (setq dtime (- (+ dtime (/ (nth 2 curtime) 1000000.0))
+			  (/ (nth 2 oldtime) 1000000.0)))
+	   (setq rate (round (* 1000.0 (/ (float dkbytes) dtime))))
+	   (if (< rate 1000)
+	       (setq rate (format "(%d B/s)" rate))
+	     (setq rate (number-to-string (round (/ rate 100.0))))
+	     (setq rate (format "(%s.%s KB/s)"
+				(substring rate 0 -1)
+				(substring rate -1 nil))))
+;	   (setq rate (concat (substring rate 0 -4) "." (substring rate -4 -2)))
+
+	   ;; End k/s calc
 	   (if (zerop efs-process-xfer-size)
 	       (or (zerop kbytes)
-		   (efs-message "%s...%dk" efs-process-msg kbytes))
+		   (efs-message "%s...%dk %s" efs-process-msg kbytes rate))
 	     (let ((percent (if big
 				(/ (* 100 (ash kbytes -7))
 				   (ash efs-process-xfer-size -7))
@@ -3202,7 +3244,7 @@
 	       (or (eq percent efs-process-last-percent)
 		   (progn
 		     (setq efs-process-last-percent percent)
-		     (efs-message "%s...%d%%" efs-process-msg percent)))))))
+		     (efs-message "%s...%d%% %s" efs-process-msg percent rate)))))))
 	(concat (substring str 0 (match-beginning 0))
 		(and (/= (length str) (match-end 0))
 		     (substring str (1+ (match-end 0))))))
@@ -3772,6 +3814,7 @@
 	      efs-process-server-confused nil
 	      efs-process-nowait nowait
 	      efs-process-hash-mark-count 0
+	      efs-process-hash-mark-history (list (list 0 (current-time)))
 	      efs-process-last-percent -1
 	      efs-process-xfer-size 0
 	      efs-process-cmd-counter (% (1+ efs-process-cmd-counter) 16))