openssh7.4-peaktput.patch 1.69 KB
Newer Older
1 2
--- a/progressmeter.c
+++ b/progressmeter.c
3
@@ -69,6 +69,8 @@
Natanael Copa's avatar
Natanael Copa committed
4
 static off_t start_pos;		/* initial position of transfer */
5 6 7 8 9 10 11
 static off_t end_pos;		/* ending position of transfer */
 static off_t cur_pos;		/* transfer position as of last refresh */
+static off_t last_pos;
+static off_t max_delta_pos = 0;
 static volatile off_t *counter;	/* progress counter */
 static long stalled;		/* how long we have been stalled */
 static int bytes_per_second;	/* current speed in bytes per second */
12 13
@@ -132,6 +132,7 @@ refresh_progress_meter(void)
 	int cur_speed;
14 15 16 17
 	int hours, minutes, seconds;
 	int file_len;
+	off_t delta_pos;
 
18 19 20
 	if ((!alarm_fired && !win_resized) || !can_output())
 		return;
@@ -147,6 +148,10 @@ refresh_progress_meter(void)
21
 	now = monotime_double();
22 23 24
 	bytes_left = end_pos - cur_pos;
 
+	delta_pos = cur_pos - last_pos;
25
+	if (delta_pos > max_delta_pos)
26 27 28 29 30
+		max_delta_pos = delta_pos;
+
 	if (bytes_left > 0)
 		elapsed = now - last_update;
 	else {
31
@@ -171,7 +176,7 @@ refresh_progress_meter(void)
32 33 34
 
 	/* filename */
 	buf[0] = '\0';
35 36
-	file_len = win_size - 36;
+	file_len = win_size - 46;
37
 	if (file_len > 0) {
38 39
 		buf[0] = '\r';
 		snmprintf(buf+1, sizeof(buf)-1 , &file_len, "%*s",
40
@@ -188,6 +195,15 @@
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
 	    (off_t)bytes_per_second);
 	strlcat(buf, "/s ", win_size);
 
+	/* instantaneous rate */
+	if (bytes_left > 0)
+		format_rate(buf + strlen(buf), win_size - strlen(buf),
+			    delta_pos);
+	else
+		format_rate(buf + strlen(buf), win_size - strlen(buf),
+			    max_delta_pos);
+	strlcat(buf, "/s ", win_size);
+
 	/* ETA */
 	if (!transferred)
 		stalled += elapsed;
56
@@ -224,6 +240,7 @@
57 58 59 60 61 62 63
 
 	atomicio(vwrite, STDOUT_FILENO, buf, win_size - 1);
 	last_update = now;
+	last_pos = cur_pos;
 }
 
 /*ARGSUSED*/