]> err.no Git - varnish/commitdiff
Add varnishhist(1) a program that shows the responsetime as a curses
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 20 Aug 2006 07:27:52 +0000 (07:27 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 20 Aug 2006 07:27:52 +0000 (07:27 +0000)
histogram.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@842 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/Makefile.am
varnish-cache/bin/varnishhist/Makefile.am [new file with mode: 0644]
varnish-cache/bin/varnishhist/varnishhist.c [new file with mode: 0644]
varnish-cache/configure.ac

index 8dc68b0a271c467327d599f4c9f2a5c32b54af8c..d31c6076a155cd70c70cabfbbd93e8a02208b83b 100644 (file)
@@ -1,3 +1,3 @@
 # $Id$
 
-SUBDIRS = varnishd varnishlog varnishncsa varnishstat varnishtop
+SUBDIRS = varnishd varnishhist varnishlog varnishncsa varnishstat varnishtop
diff --git a/varnish-cache/bin/varnishhist/Makefile.am b/varnish-cache/bin/varnishhist/Makefile.am
new file mode 100644 (file)
index 0000000..c624d5a
--- /dev/null
@@ -0,0 +1,17 @@
+# $Id: Makefile.am 767 2006-08-08 12:31:19Z des $
+
+INCLUDES = -I$(top_srcdir)/include
+
+bin_PROGRAMS = varnishhist
+
+# dist_man_MANS = varnishlog.1
+
+varnishhist_SOURCES = varnishhist.c
+
+varnishhist_CFLAGS = -include config.h
+
+varnishhist_LDADD = \
+       $(top_builddir)/lib/libcompat/libcompat.a \
+       $(top_builddir)/lib/libvarnish/libvarnish.la \
+       $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
+       -lm -lcurses
diff --git a/varnish-cache/bin/varnishhist/varnishhist.c b/varnish-cache/bin/varnishhist/varnishhist.c
new file mode 100644 (file)
index 0000000..f0860ce
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * $Id: varnishlog.c 833 2006-08-18 20:07:37Z phk $
+ *
+ * Log tailer for Varnish
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <regex.h>
+#include <math.h>
+#include <curses.h>
+
+#include "compat/vis.h"
+
+#include "libvarnish.h"
+#include "shmlog.h"
+#include "varnishapi.h"
+
+#define HIST_LOW -55
+#define HIST_HIGH 20
+#define HIST_W (1 + (HIST_HIGH - HIST_LOW))
+#define HIST_N 1000
+
+static unsigned char rr_hist[HIST_N];
+static unsigned next_hist;
+static unsigned bucket_hist[HIST_W];
+static double c_hist;
+
+static void
+r_hist(void)
+{
+       int x, y;
+       double m, r;
+
+       m = 0;
+       r = 0;
+       for (x = 0; x < HIST_W; x++) {
+               if (bucket_hist[x] > m)
+                       m = bucket_hist[x];
+               r += bucket_hist[x];
+       }
+
+       mvprintw(0, 0, "Max %.0f Scale %u Tot: %.0f", m, HIST_N, r);
+       m = HIST_N / (LINES - 3);
+       move(1,0);
+       for (y = LINES - 3; y > 0; y--) {
+               if (y == 1)
+                       r = 0;
+               else
+                       r = y * m;
+               for (x = 0; x < HIST_W; x++)
+                       addch(bucket_hist[x] > r ? '#' : ' ');
+               addch('\n');
+       }
+       refresh();
+}
+
+static int 
+h_hist(void *priv, unsigned tag, unsigned fd, unsigned len, unsigned spec, const char *ptr)
+{
+       double b;
+       int i;
+       
+       (void)priv;
+       (void)fd;
+       (void)len;
+       (void)spec;
+       if (tag != SLT_ReqEnd)
+               return (0);
+       i = sscanf(ptr, "%*d %*f %*f %lf", &b);
+       assert(i == 1);
+       i = log(b) * c_hist;
+       if (i < HIST_LOW)
+               i = HIST_LOW;
+       if (i > HIST_HIGH)
+               i = HIST_HIGH;
+       i -= HIST_LOW;
+       bucket_hist[rr_hist[next_hist]]--;
+       rr_hist[next_hist] = i;
+       bucket_hist[rr_hist[next_hist]]++;
+       if (++next_hist == HIST_N) {
+               next_hist = 0;
+       }
+       if (!(next_hist % 100))
+               r_hist();
+       return (0);
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
+usage(void)
+{
+       fprintf(stderr,
+           "usage: varnishhist");
+       exit(1);
+}
+
+int
+main(int argc, char **argv)
+{
+       int i, c, x;
+       struct VSL_data *vd;
+
+       vd = VSL_New();
+       
+       while ((c = getopt(argc, argv, VSL_ARGS)) != -1) {
+               switch (c) {
+               default:
+                       if (VSL_Arg(vd, c, optarg) > 0)
+                               break;
+                       usage();
+               }
+       }
+
+       c_hist = 10.0 / log(10.0);
+       initscr();
+       erase();
+
+       bucket_hist[0] = HIST_N;
+       move(LINES - 2, 0);
+       for (x = 0; x < HIST_W; x++)
+               addch('-');
+
+       for (x = 0; x < HIST_W; x++) {
+               if ((x + HIST_LOW) % 10 != 0)
+                       continue;
+               mvprintw(LINES - 2, x, "+");
+               mvprintw(LINES - 1, x, "|1e%d", (x + HIST_LOW) / 10);
+       }
+
+       while (1) {
+               i = VSL_Dispatch(vd, h_hist, NULL);
+               if (i < 0)
+                       break;
+               if (i == 0)
+                       r_hist();
+       } 
+
+       return (0);
+}
index 925eb4c7d5cd9488c02cca3c0978096e61011942..c3faca72e4a6b47ffe189db1c8d255ad850d39a7 100644 (file)
@@ -98,6 +98,7 @@ AC_CONFIG_FILES([
     bin/Makefile
     bin/varnishd/Makefile
     bin/varnishlog/Makefile
+    bin/varnishhist/Makefile
     bin/varnishncsa/Makefile
     bin/varnishstat/Makefile
     bin/varnishtop/Makefile