]> err.no Git - varnish/commitdiff
Use different marks for hit & miss
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 22 Aug 2006 09:16:33 +0000 (09:16 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 22 Aug 2006 09:16:33 +0000 (09:16 +0000)
Autoscale vertical axis.

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

varnish-cache/bin/varnishhist/varnishhist.c

index b4b89e48d10fa8e9a6679a296aacf1b0142170d6..785a4fab9717e354d49227c0d54b7e63fce88d9b 100644 (file)
 #define HIST_LOW -50
 #define HIST_HIGH 25
 #define HIST_W (1 + (HIST_HIGH - HIST_LOW))
-#define HIST_N 10000
+#define HIST_N 2000
 
-static unsigned char rr_hist[HIST_N];
+static char rr_hist[HIST_N];
 static unsigned next_hist;
-static unsigned bucket_hist[HIST_W];
+static unsigned bucket_miss[HIST_W];
+static unsigned bucket_hit[HIST_W];
+static unsigned char hh[65536];
+static double scale = 10;
 static double c_hist;
 
 static void
@@ -43,22 +46,32 @@ r_hist(void)
        tl = t;
        m = 0;
        r = 0;
-       for (x = 0; x < HIST_W; x++) {
-               if (bucket_hist[x] > m)
-                       m = bucket_hist[x];
-               r += bucket_hist[x];
+       for (x = 1; x < HIST_W; x++) {
+               if (bucket_hit[x] + bucket_miss[x] > m)
+                       m = bucket_hit[x] + bucket_miss[x];
+               r += bucket_hit[x];
+               r += bucket_miss[x];
        }
 
-       mvprintw(0, 0, "Max %.0f Scale %u Tot: %.0f", m, HIST_N, r);
-       m = HIST_N / (LINES - 3);
+       while (m > HIST_N / scale)
+               scale--;
+
+       mvprintw(0, 0, "Max %.0f Scale %.0f Tot: %.0f", m, HIST_N / scale, r);
+       m = (HIST_N / scale) / (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 ? '#' : ' ');
+               for (x = 0; x < HIST_W; x++) {
+                       if (bucket_miss[x] > r)
+                               addch('|');
+                       else if (bucket_hit[x] + bucket_miss[x] > r)
+                               addch('#');
+                       else
+                               addch(' ');
+               }
                addch('\n');
        }
        refresh();
@@ -68,15 +81,19 @@ static int
 h_hist(void *priv, unsigned tag, unsigned fd, unsigned len, unsigned spec, const char *ptr)
 {
        double b;
-       int i;
+       int i, j;
        
        (void)priv;
        (void)fd;
        (void)len;
        (void)spec;
+       if (tag == SLT_Hit) {
+               hh[fd] = 1;
+               return (0);
+       }
        if (tag != SLT_ReqEnd)
                return (0);
-#if 0
+#if 1
        i = sscanf(ptr, "%*d %*f %*f %*f %lf", &b);
 #else
        i = sscanf(ptr, "%*d %*f %*f %lf", &b);
@@ -88,14 +105,30 @@ h_hist(void *priv, unsigned tag, unsigned fd, unsigned len, unsigned spec, const
        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]]++;
+       assert(i < HIST_W);
+
+       j = rr_hist[next_hist];
+       if (j < 0)  {
+               assert(bucket_miss[-j] > 0);
+               bucket_miss[-j]--;
+       } else {
+               assert(bucket_hit[j] > 0);
+               bucket_hit[j]--;
+       }
+
+       if (hh[fd] || i == 0) {
+               bucket_hit[i]++;
+               rr_hist[next_hist] = i;
+       } else {
+               bucket_miss[i]++;
+               rr_hist[next_hist] = -i;
+       }
        if (++next_hist == HIST_N) {
                next_hist = 0;
        }
        if (!(next_hist % 100))
                r_hist();
+       hh[fd] = 0;
        return (0);
 }
 
@@ -133,7 +166,7 @@ main(int argc, char **argv)
        initscr();
        erase();
 
-       bucket_hist[0] = HIST_N;
+       bucket_hit[0] = HIST_N;
        move(LINES - 2, 0);
        for (x = 0; x < HIST_W; x++)
                addch('-');