r889 - trunk/varnish-cache/bin/varnishhist

phk at projects.linpro.no phk at projects.linpro.no
Tue Aug 22 11:16:33 CEST 2006


Author: phk
Date: 2006-08-22 11:16:33 +0200 (Tue, 22 Aug 2006)
New Revision: 889

Modified:
   trunk/varnish-cache/bin/varnishhist/varnishhist.c
Log:
Use different marks for hit & miss

Autoscale vertical axis.


Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c
===================================================================
--- trunk/varnish-cache/bin/varnishhist/varnishhist.c	2006-08-22 08:55:15 UTC (rev 888)
+++ trunk/varnish-cache/bin/varnishhist/varnishhist.c	2006-08-22 09:16:33 UTC (rev 889)
@@ -22,11 +22,14 @@
 #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 @@
 	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 @@
 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 @@
 	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 @@
 	initscr();
 	erase();
 
-	bucket_hist[0] = HIST_N;
+	bucket_hit[0] = HIST_N;
 	move(LINES - 2, 0);
 	for (x = 0; x < HIST_W; x++)
 		addch('-');




More information about the varnish-commit mailing list