r1589 - trunk/varnish-cache/bin/varnishstat

des at projects.linpro.no des at projects.linpro.no
Thu Jun 28 12:29:27 CEST 2007


Author: des
Date: 2007-06-28 12:29:27 +0200 (Thu, 28 Jun 2007)
New Revision: 1589

Modified:
   trunk/varnish-cache/bin/varnishstat/varnishstat.c
Log:
Numerous improvements: display the instance name in the upper right corner;
don't show more lines than the terminal can fit; correctly react to terminal
size changes; react to Ctrl-L (redraw) and Ctrl-C / Ctrl-Q (quit).

The layout code could use a cleanup, and we still fail to DTRT if the width
of the terminal is less than that of our data, but this should not be a
problem in daily use.


Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat.c	2007-06-28 10:25:47 UTC (rev 1588)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat.c	2007-06-28 10:29:27 UTC (rev 1589)
@@ -31,14 +31,14 @@
  * Log tailer for Varnish
  */
 
+#include <curses.h>
+#include <errno.h>
+#include <limits.h>
 #include <stdio.h>
-#include <errno.h>
+#include <stdlib.h>
 #include <string.h>
-#include <stdlib.h>
+#include <time.h>
 #include <unistd.h>
-#include <curses.h>
-#include <time.h>
-#include <limits.h>
 
 #ifndef HAVE_CLOCK_GETTIME
 #include "compat/clock_gettime.h"
@@ -67,15 +67,18 @@
 	double a1, a2, a3;
 	unsigned n1, n2, n3;
 	time_t rt;
-	int i;
+	int ch, line;
 
-
 	memset(&copy, 0, sizeof copy);
 
 	a1 = a2 = a3 = 0.0;
 	n1 = n2 = n3 = 0;
 
 	initscr();
+	raw();
+	noecho();
+	nonl();
+	intrflush(stdscr, false);
 	erase();
 
 	lt = 0;
@@ -87,18 +90,19 @@
 		rt = ts.tv_sec - VSL_stats->start_time;
 		up = rt;
 
-		move(0,0);
-		i = 0;
+		move(0, 0);
+		printw("%*s\n", COLS - 1, VSL_Name());
+		move(0, 0);
 		if (rt > 86400) {
 			printw("%dd+", rt / 86400);
 			rt %= 86400;
-			i++;
 		}
 		printw("%02d:", rt / 3600);
 		rt %= 3600;
 		printw("%02d:", rt / 60);
 		rt %= 60;
-		printw("%02d\n", rt);
+		printw("%02d", rt);
+		move(1, 0);
 		hit = (intmax_t)VSL_stats->cache_hit -
 		    (intmax_t)copy.cache_hit;
 		miss = (intmax_t)VSL_stats->cache_miss -
@@ -115,8 +119,9 @@
 		printw("Hitrate avg:   %8.4f %8.4f %8.4f\n", a1, a2, a3);
 		printw("\n");
 
+		line = 0;
 #define MAC_STAT(n, t, f, d) \
-	do { \
+	if (++line < LINES - 4) { \
 		ju = VSL_stats->n; \
 		if (f == 'a') { \
 			printw("%12ju %12.2f %12.2f %s\n", \
@@ -125,12 +130,31 @@
 		} else { \
 			printw("%12ju %12s %12s %s\n", ju, ".  ", ".  ", d); \
 		} \
-	} while (0);
+	}
 #include "stat_field.h"
 #undef MAC_STAT
 		lt = tt;
 		refresh();
-		sleep(delay);
+		timeout(delay * 1000);
+		switch ((ch = getch())) {
+		case ERR:
+			break;
+		case KEY_RESIZE:
+			erase();
+			break;
+		case '\014':
+			redrawwin(stdscr);
+			refresh();
+			break;
+		case '\003': /* Ctrl-C */
+		case '\021': /* Ctrl-Q */
+		case 'Q':
+		case 'q':
+			endwin();
+			return;
+		default:
+			break;
+		}
 	}
 }
 




More information about the varnish-commit mailing list