[4.1] 17690d4 refresh period: missing option, sub-second, allow inc/dec

PÃ¥l Hermunn Johansen hermunn at varnish-software.com
Fri Sep 9 13:01:03 CEST 2016


commit 17690d40453dfeac2dae7fbffe0c15e5ee07c92b
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Sat Jul 23 18:04:17 2016 +0200

    refresh period: missing option, sub-second, allow inc/dec
    
    Actually implement the documented -p option
    
    Make the update delay a double to allow update frequencies of less
    than a second.
    
    Add + and - keys to the curses interface to update the refresh
    frequency while running.
    
    Show update frequency in the top line.

diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index 56dd246..bd17652 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -68,7 +68,7 @@ static int hist_buckets;
 static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
 
 static int end_of_file = 0;
-static int delay = 1;
+static double delay = 1;
 static unsigned rr_hist[HIST_N];
 static unsigned nhist;
 static unsigned next_hist;
@@ -218,7 +218,7 @@ update(void)
 		/* nothing */ ;
 	scale = scales[i];
 
-	mvprintw(0, 0, "1:%d, n = %d", scale, nhist);
+	mvprintw(0, 0, "1:%d, n = %d, d = %g", scale, nhist, delay);
 
 	for (j = 2; j < LINES - 3; j+=5)
 		mvprintw(j, 0, "%d_", (LINES - 3 - j) * scale);
@@ -395,6 +395,14 @@ do_curses(void *arg)
 		case '9':
 			delay = 1 << (ch - '0');
 			break;
+		case '+':
+			delay /= 2;
+			if (delay < 1e-3)
+				delay = 1e-3;
+			break;
+		case '-':
+			delay *= 2;
+			break;
 		default:
 			beep();
 			break;
@@ -445,6 +453,13 @@ main(int argc, char **argv)
 		case 'h':
 			/* Usage help */
 			usage(0);
+		case 'p':
+			delay = strtod(optarg, NULL);
+			if (delay <= 0) {
+				fprintf(stderr, "-p: invalid '%s'\n", optarg);
+				exit(1);
+			}
+			break;
 		case 'P':
 			colon = strchr(optarg, ':');
 			/* no colon, take the profile as a name*/
diff --git a/bin/varnishhist/varnishhist_options.h b/bin/varnishhist/varnishhist_options.h
index 16150a8..3846df3 100644
--- a/bin/varnishhist/varnishhist_options.h
+++ b/bin/varnishhist/varnishhist_options.h
@@ -41,7 +41,8 @@
 	VOPT("p:", "[-p period]", "Refresh period",			\
 	    "Specified the number of seconds between screen refreshes."	\
 	    " Default is 1 second, and can be changed at runtime by"	\
-	    " pressing the [1-9] keys."					\
+	    " pressing the [0-9] keys (powers of 2 in seconds"		\
+	    " or + and - (double/halve the speed)"			\
 	)
 
 #define HIS_OPT_P							\



More information about the varnish-commit mailing list