]> err.no Git - varnish/commitdiff
Allow the delay between screen updates to be specified with -w.
authordes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 22 Aug 2006 10:14:39 +0000 (10:14 +0000)
committerdes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 22 Aug 2006 10:14:39 +0000 (10:14 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@893 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishhist/varnishhist.c

index b2a32809b7c1bbfcba20cbf2ebe3a4f2cb7a57a9..547baa700593526eefb2217d7db7100bde21143a 100644 (file)
@@ -4,14 +4,15 @@
  * Log tailer for Varnish
  */
 
-#include <stdio.h>
+#include <curses.h>
 #include <errno.h>
-#include <string.h>
+#include <math.h>
+#include <regex.h>
+#include <signal.h>
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
-#include <regex.h>
-#include <math.h>
-#include <curses.h>
 
 #include "compat/vis.h"
 
@@ -24,6 +25,8 @@
 #define HIST_W (1 + (HIST_HIGH - HIST_LOW))
 #define HIST_N 2000
 
+static int delay = 1;
+static volatile sig_atomic_t redraw;
 static char rr_hist[HIST_N];
 static unsigned next_hist;
 static unsigned bucket_miss[HIST_W];
@@ -32,18 +35,20 @@ static unsigned char hh[65536];
 static double scale = 10;
 static double c_hist;
 
+static void
+sigalrm(int sig)
+{
+
+       (void)sig;
+       redraw = 1;
+}
+
 static void
 r_hist(void)
 {
        int x, y;
        double m, r;
-       time_t t;
-       static time_t tl;
 
-       t = time(NULL);
-       if (t == tl)
-               return;
-       tl = t;
        m = 0;
        r = 0;
        for (x = 1; x < HIST_W; x++) {
@@ -75,6 +80,8 @@ r_hist(void)
                addch('\n');
        }
        refresh();
+       redraw = 0;
+       alarm(delay);
 }
 
 static int 
@@ -126,8 +133,6 @@ h_hist(void *priv, unsigned tag, unsigned fd, unsigned len, unsigned spec, const
        if (++next_hist == HIST_N) {
                next_hist = 0;
        }
-       if (!(next_hist % 100))
-               r_hist();
        hh[fd] = 0;
        return (0);
 }
@@ -150,8 +155,11 @@ main(int argc, char **argv)
 
        vd = VSL_New();
        
-       while ((c = getopt(argc, argv, VSL_ARGS)) != -1) {
+       while ((c = getopt(argc, argv, VSL_ARGS "w:")) != -1) {
                switch (c) {
+               case 'w':
+                       delay = atoi(optarg);
+                       break;
                default:
                        if (VSL_Arg(vd, c, optarg) > 0)
                                break;
@@ -178,11 +186,13 @@ main(int argc, char **argv)
                mvprintw(LINES - 1, x, "|1e%d", (x + HIST_LOW) / 10);
        }
 
+       signal(SIGALRM, sigalrm);
+       redraw = 1;
        while (1) {
                i = VSL_Dispatch(vd, h_hist, NULL);
                if (i < 0)
                        break;
-               if (i == 0)
+               if (redraw)
                        r_hist();
        }