r348 - trunk/varnish-cache/bin/varnishstat

phk at projects.linpro.no phk at projects.linpro.no
Thu Jul 6 12:18:33 CEST 2006


Author: phk
Date: 2006-07-06 12:18:33 +0200 (Thu, 06 Jul 2006)
New Revision: 348

Modified:
   trunk/varnish-cache/bin/varnishstat/varnishstat.c
Log:
Add exponential hitrate displays (with -c)


Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat.c	2006-07-06 09:31:45 UTC (rev 347)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat.c	2006-07-06 10:18:33 UTC (rev 348)
@@ -15,6 +15,15 @@
 #include "shmlog.h"
 #include "varnishapi.h"
 
+static void
+myexp(double *acc, double val, unsigned *n, unsigned nmax)
+{
+
+	if (*n < nmax)
+		(*n)++;
+	(*acc) += (val - *acc) / (double)*n;
+}
+
 int
 main(int argc, char **argv)
 {
@@ -24,8 +33,13 @@
 	int c_flag = 0;
 	intmax_t ju;
 	struct timespec ts;
-	double tt, lt;
+	double tt, lt, hit, miss, ratio;
+	double a1, a2, a3;
+	unsigned n1, n2, n3;
 
+	a1 = a2 = a3 = 0;
+	n1 = n2 = n3 = 0;
+
 	lh = VSL_OpenLog();
 
 	VSL_stats = &lh->stats;
@@ -47,10 +61,26 @@
 		erase();
 
 		while (1) {
-			move(0,0);
 			clock_gettime(CLOCK_MONOTONIC, &ts);
 			tt = ts.tv_nsec * 1e-9 + ts.tv_sec;
 			lt = tt - lt;
+			move(0,0);
+			hit = (intmax_t)VSL_stats->cache_hit -
+			    (intmax_t)copy.cache_hit;
+			miss = (intmax_t)VSL_stats->cache_miss -
+			    (intmax_t)copy.cache_miss;
+			hit /= lt;
+			miss /= lt;
+			if (hit + miss != 0) {
+				ratio = hit / (hit + miss);
+				myexp(&a1, ratio, &n1, 10);
+				myexp(&a2, ratio, &n2, 100);
+				myexp(&a3, ratio, &n3, 1000);
+			}
+			printw("Hitrate ratio: %8u %8u %8u\n", n1, n2, n3);
+			printw("Hitrate avg:   %8.4f %8.4f %8.4f\n", a1, a2, a3);
+			printw("\n");
+
 #define MAC_STAT(n,t,f,d) \
 			ju = VSL_stats->n; \
 			printw("%12ju  %10.2f " d "\n", ju, (ju - (intmax_t)copy.n)/lt); \




More information about the varnish-commit mailing list