[master] c6f20e4 Varnishstat hitrate implementation

arianna arianna.aondio at varnish-software.com
Mon Aug 11 14:24:09 CEST 2014


commit c6f20e4701cfc7484a8bc064e7c6f41de243865d
Author: arianna <arianna.aondio at varnish-software.com>
Date:   Fri Aug 8 12:56:55 2014 +0200

    Varnishstat hitrate implementation

diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c
index fd80580..8ce35f1 100644
--- a/bin/varnishstat/varnishstat_curses.c
+++ b/bin/varnishstat/varnishstat_curses.c
@@ -91,6 +91,15 @@ struct pt {
 	struct ma		ma_10, ma_100, ma_1000;
 };
 
+struct hitrate {
+	double lt;
+	uint64_t lhit, lmiss;
+	struct ma hr_10;
+	struct ma hr_100;
+	struct ma hr_1000;
+};
+static struct hitrate hitrate;
+
 static VTAILQ_HEAD(, pt) ptlist = VTAILQ_HEAD_INITIALIZER(ptlist);
 static int n_ptlist = 0;
 static int n_ptarray = 0;
@@ -119,6 +128,19 @@ static double t_sample = 0.;
 static double interval = 1.;
 
 static void
+init_hitrate(void)
+{
+	memset(&hitrate, 0, sizeof (struct hitrate));
+	if (VSC_C_main != NULL) {
+		hitrate.lhit = VSC_C_main->cache_hit;
+		hitrate.lmiss = VSC_C_main->cache_miss;
+	}
+	hitrate.hr_10.nmax = 10;
+	hitrate.hr_100.nmax = 100;
+	hitrate.hr_1000.nmax = 1000;
+}
+
+static void
 update_ma(struct ma *ma, double val)
 {
 	AN(ma);
@@ -348,10 +370,6 @@ sample_points(void)
 {
 	struct pt *pt;
 
-	t_sample = VTIM_mono();
-	sample = 0;
-	redraw = 1;
-
 	VTAILQ_FOREACH(pt, &ptlist, list) {
 		AN(pt->vpt);
 		AN(pt->ptr);
@@ -390,6 +408,46 @@ sample_points(void)
 }
 
 static void
+sample_hitrate(void)
+{
+	double tv,dt;
+	double hr, mr, ratio;
+	uint64_t hit, miss;
+
+	if (VSC_C_mgt == NULL)
+		return;
+
+	tv = VTIM_mono();
+	dt = tv - hitrate.lt;
+	hitrate.lt= tv;
+
+	hit = VSC_C_main->cache_hit;
+	miss = VSC_C_main->cache_miss;
+	hr = (hit - hitrate.lhit) / dt;
+	mr = (miss - hitrate.lmiss) / dt;
+	hitrate.lhit = hit;
+	hitrate.lmiss = miss;
+
+	if (hr + mr != 0)
+		ratio = hr / (hr + mr);
+	else
+		ratio = 0;
+	update_ma(&hitrate.hr_10, ratio);
+	update_ma(&hitrate.hr_100, ratio);
+	update_ma(&hitrate.hr_1000, ratio);
+}
+
+static void
+sample_data(void)
+{
+	t_sample = VTIM_mono();
+	sample = 0;
+	redraw = 1;
+	sample_points();
+	sample_hitrate();
+}
+
+static void
 make_windows(void)
 {
 	int Y, X;
@@ -489,8 +547,18 @@ draw_status(void)
 	AN(w_status);
 
 	werase(w_status);
-	if (VSC_C_mgt != NULL)
+
+	if (VSC_C_mgt != NULL) {
 		up_mgt = VSC_C_mgt->uptime;
+		if( COLS  > 70) {
+			mvwprintw(w_status, 0, (getmaxx (w_status) - 37),
+				"Hitrate n: %8u %8u %8u", hitrate.hr_10.n, hitrate.hr_100.n,
+				hitrate.hr_1000.n);
+			mvwprintw(w_status, 1, (getmaxx (w_status) - 37),
+				"   avg(n): %8.4f %8.4f %8.4f", hitrate.hr_10.acc,
+				hitrate.hr_100.acc, hitrate.hr_1000.acc);
+		}
+	}
 	if (VSC_C_main != NULL)
 		up_chld = VSC_C_main->uptime;
 
@@ -866,8 +934,10 @@ do_curses(struct VSM_data *vd, int delay)
 
 	VSC_C_mgt = VSC_Mgt(vd, &f_mgt);
 	VSC_C_main = VSC_Main(vd, &f_main);
+	init_hitrate();
 	while (keep_running) {
 		if (VSM_Abandoned(vd)) {
+			init_hitrate();
 			delete_pt_list();
 			VSM_Close(vd);
 			VSM_Open(vd);
@@ -881,7 +951,7 @@ do_curses(struct VSM_data *vd, int delay)
 		if (now - t_sample > interval)
 			sample = 1;
 		if (sample)
-			sample_points();
+			sample_data();
 		if (rebuild)
 			build_pt_array();
 		if (redraw)



More information about the varnish-commit mailing list