From: des Date: Tue, 22 Aug 2006 10:14:39 +0000 (+0000) Subject: Allow the delay between screen updates to be specified with -w. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7a78b81258a04a56cf4d00f6f2b0b80f0caaf16;p=varnish Allow the delay between screen updates to be specified with -w. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@893 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishhist/varnishhist.c b/varnish-cache/bin/varnishhist/varnishhist.c index b2a32809..547baa70 100644 --- a/varnish-cache/bin/varnishhist/varnishhist.c +++ b/varnish-cache/bin/varnishhist/varnishhist.c @@ -4,14 +4,15 @@ * Log tailer for Varnish */ -#include +#include #include -#include +#include +#include +#include +#include #include +#include #include -#include -#include -#include #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(); }