The following two patches add support for scaling byte fields in
varnishstat(1).
Fixes #1653.

The first one marks byte fields as such using the uppercase variant; bytes
counter becomes 'C' and bytes gauge 'G'.

The second adds support to scale these byte fields using "e" in the ncurses
interface.

Comments? OKs?
From 0d1cb4f5ba525c0caafb3209c99a69ae1000388c Mon Sep 17 00:00:00 2001
From: "Federico G. Schwindt" <[email protected]>
Date: Tue, 6 Jan 2015 14:52:00 +0000
Subject: [PATCH 1/2] Add specific counters for byte fields

This will allow to treat them specially in varnishstat(1) and other
tools.
---
 bin/varnishstat/varnishstat.c        |  3 ++-
 bin/varnishstat/varnishstat_curses.c |  4 ++--
 include/tbl/vsc_f_main.h             | 30 ++++++++++++++++--------------
 include/tbl/vsc_fields.h             | 24 +++++++++++++-----------
 4 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/bin/varnishstat/varnishstat.c b/bin/varnishstat/varnishstat.c
index f5153b4..0e91457 100644
--- a/bin/varnishstat/varnishstat.c
+++ b/bin/varnishstat/varnishstat.c
@@ -179,7 +179,8 @@ do_once_cb(void *priv, const struct VSC_point * const pt)
 	if (i >= op->pad)
 		op->pad = i + 1;
 	printf("%*.*s", op->pad - i, op->pad - i, "");
-	if (pt->desc->flag == 'a' || pt->desc->flag == 'c')
+	if (pt->desc->flag == 'a' || pt->desc->flag == 'c' ||
+	    pt->desc->flag == 'C')
 		printf("%12ju %12.2f %s\n",
 		    (uintmax_t)val, val / op->up, pt->desc->sdesc);
 	else
diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c
index 00c4dac..9a399c7 100644
--- a/bin/varnishstat/varnishstat_curses.c
+++ b/bin/varnishstat/varnishstat_curses.c
@@ -388,12 +388,12 @@ sample_points(void)
 			pt->chg = ((intmax_t)pt->cur - (intmax_t)pt->last) /
 			    (pt->t_cur - pt->t_last);
 
-		if (pt->flag == 'g') {
+		if (pt->flag == 'g' || pt->flag == 'G') {
 			pt->avg = 0.;
 			update_ma(&pt->ma_10, pt->cur);
 			update_ma(&pt->ma_100, pt->cur);
 			update_ma(&pt->ma_1000, pt->cur);
-		} else if (pt->flag == 'c') {
+		} else if (pt->flag == 'c' || pt->flag == 'C') {
 			if (VSC_C_main != NULL && VSC_C_main->uptime)
 				pt->avg = pt->cur / VSC_C_main->uptime;
 			else
diff --git a/include/tbl/vsc_f_main.h b/include/tbl/vsc_f_main.h
index 42c57e2..ab555a2 100644
--- a/include/tbl/vsc_f_main.h
+++ b/include/tbl/vsc_f_main.h
@@ -36,7 +36,9 @@
  *				'a' - Accumulator (deprecated, use 'c')
  *				'b' - Bitmap
  *				'c' - Counter, never decreases.
+ *				'C' - Counter in bytes, never decreases.
  *				'g' - Gauge, goes up and down
+ *				'G' - Gauge in bytes, goes up and down
  *				'i' - Integer (deprecated, use 'g')
  *    e - Explanation:	Short explanation of field (for screen use)
  *    d - Description:	Long explanation of field (for doc use)
@@ -379,32 +381,32 @@ VSC_F(s_synth,			uint64_t, 1, 'c', info,
     "Total synthethic responses made",
 	""
 )
-VSC_F(s_req_hdrbytes,		uint64_t, 1, 'c', info,
+VSC_F(s_req_hdrbytes,		uint64_t, 1, 'C', info,
     "Request header bytes",
 	"Total request header bytes received"
 )
-VSC_F(s_req_bodybytes,		uint64_t, 1, 'c', info,
+VSC_F(s_req_bodybytes,		uint64_t, 1, 'C', info,
     "Request body bytes",
 	"Total request body bytes received"
 )
-VSC_F(s_resp_hdrbytes,		uint64_t, 1, 'c', info,
+VSC_F(s_resp_hdrbytes,		uint64_t, 1, 'C', info,
     "Response header bytes",
 	"Total response header bytes transmitted"
 )
-VSC_F(s_resp_bodybytes,		uint64_t, 1, 'c', info,
+VSC_F(s_resp_bodybytes,		uint64_t, 1, 'C', info,
     "Response body bytes",
 	"Total response body bytes transmitted"
 )
-VSC_F(s_pipe_hdrbytes,		uint64_t, 0, 'c', info,
+VSC_F(s_pipe_hdrbytes,		uint64_t, 0, 'C', info,
     "Pipe request header bytes",
 	"Total request bytes received for piped sessions"
 )
-VSC_F(s_pipe_in,		uint64_t, 0, 'c', info,
+VSC_F(s_pipe_in,		uint64_t, 0, 'C', info,
     "Piped bytes from client",
 	"Total number of bytes forwarded from clients in"
 	" pipe sessions"
 )
-VSC_F(s_pipe_out,		uint64_t, 0, 'c', info,
+VSC_F(s_pipe_out,		uint64_t, 0, 'C', info,
     "Piped bytes to client",
 	"Total number of bytes forwarded to clients in"
 	" pipe sessions"
@@ -543,11 +545,11 @@ VSC_F(bans_lurker_contention,	uint64_t, 0, 'c', diag,
     "Lurker gave way for lookup",
 	"Number of times the ban-lurker had to wait for lookups."
 )
-VSC_F(bans_persisted_bytes,	uint64_t, 0, 'g', diag,
+VSC_F(bans_persisted_bytes,	uint64_t, 0, 'G', diag,
     "Bytes used by the persisted ban lists",
 	"Number of bytes used by the persisted ban lists."
 )
-VSC_F(bans_persisted_fragmentation,	uint64_t, 0, 'g', diag,
+VSC_F(bans_persisted_fragmentation,	uint64_t, 0, 'G', diag,
     "Extra bytes in persisted ban lists due to fragmentation",
 	"Number of extra bytes accumulated through dropped and"
 	" completed bans in the persistent ban lists."
@@ -622,33 +624,33 @@ VSC_F(n_gunzip,			uint64_t, 0, 'c', info,
 
 /*--------------------------------------------------------------------*/
 
-VSC_F(vsm_free,			uint64_t, 0, 'g', diag,
+VSC_F(vsm_free,			uint64_t, 0, 'G', diag,
     "Free VSM space",
 	"Number of bytes free in the shared memory used to communicate"
 	" with tools like varnishstat, varnishlog etc."
 )
 
-VSC_F(vsm_used,			uint64_t, 0, 'g', diag,
+VSC_F(vsm_used,			uint64_t, 0, 'G', diag,
     "Used VSM space",
 	"Number of bytes used in the shared memory used to communicate"
 	" with tools like varnishstat, varnishlog etc."
 )
 
-VSC_F(vsm_cooling,		uint64_t, 0, 'g', debug,
+VSC_F(vsm_cooling,		uint64_t, 0, 'G', debug,
     "Cooling VSM space",
 	"Number of bytes which will soon (max 1 minute) be freed"
 	" in the shared memory used to communicate"
 	" with tools like varnishstat, varnishlog etc."
 )
 
-VSC_F(vsm_overflow,		uint64_t, 0, 'g', diag,
+VSC_F(vsm_overflow,		uint64_t, 0, 'G', diag,
     "Overflow VSM space",
 	"Number of bytes which does not fit"
 	" in the shared memory used to communicate"
 	" with tools like varnishstat, varnishlog etc."
 )
 
-VSC_F(vsm_overflowed,		uint64_t, 0, 'c', diag,
+VSC_F(vsm_overflowed,		uint64_t, 0, 'C', diag,
     "Overflowed VSM space",
 	"Total number of bytes which did not fit"
 	" in the shared memory used to communicate"
diff --git a/include/tbl/vsc_fields.h b/include/tbl/vsc_fields.h
index 3f20184..ff4e058 100644
--- a/include/tbl/vsc_fields.h
+++ b/include/tbl/vsc_fields.h
@@ -36,7 +36,9 @@
  *				'a' - Accumulator (deprecated, use 'c')
  *				'b' - Bitmap
  *				'c' - Counter, never decreases.
+ *				'C' - Counter in bytes, never decreases.
  *				'g' - Gauge, goes up and down
+ *				'G' - Gauge in bytes, goes up and down
  *				'i' - Integer (deprecated, use 'g')
  *    v - Verbosity:	Counter verbosity level (see vsc_levels.h)
  *    e - Explanation:	Short explanation of field (for screen use)
@@ -126,11 +128,11 @@ VSC_F(c_fail,			uint64_t, 0, 'c', info,
     "Allocator failures",
 	""
 )
-VSC_F(c_bytes,			uint64_t, 0, 'c', info,
+VSC_F(c_bytes,			uint64_t, 0, 'C', info,
     "Bytes allocated",
 	""
 )
-VSC_F(c_freed,			uint64_t, 0, 'c', info,
+VSC_F(c_freed,			uint64_t, 0, 'C', info,
     "Bytes freed",
 	""
 )
@@ -138,11 +140,11 @@ VSC_F(g_alloc,			uint64_t, 0, 'g', info,
     "Allocations outstanding",
 	""
 )
-VSC_F(g_bytes,			uint64_t, 0, 'g', info,
+VSC_F(g_bytes,			uint64_t, 0, 'G', info,
     "Bytes outstanding",
 	""
 )
-VSC_F(g_space,			uint64_t, 0, 'g', info,
+VSC_F(g_space,			uint64_t, 0, 'G', info,
     "Bytes available",
 	""
 )
@@ -184,32 +186,32 @@ VSC_F(happy,			uint64_t, 0, 'b', info,
     "Happy health probes",
 	""
 )
-VSC_F(bereq_hdrbytes,		uint64_t, 0, 'c', info,
+VSC_F(bereq_hdrbytes,		uint64_t, 0, 'C', info,
     "Request header bytes",
 	"Total backend request header bytes sent"
 )
-VSC_F(bereq_bodybytes,		uint64_t, 0, 'c', info,
+VSC_F(bereq_bodybytes,		uint64_t, 0, 'C', info,
     "Request body bytes",
 	"Total backend request body bytes sent"
 )
-VSC_F(beresp_hdrbytes,		uint64_t, 0, 'c', info,
+VSC_F(beresp_hdrbytes,		uint64_t, 0, 'C', info,
     "Response header bytes",
 	"Total backend response header bytes received"
 )
-VSC_F(beresp_bodybytes,		uint64_t, 0, 'c', info,
+VSC_F(beresp_bodybytes,		uint64_t, 0, 'C', info,
     "Response body bytes",
 	"Total backend response body bytes received"
 )
-VSC_F(pipe_hdrbytes,		uint64_t, 0, 'c', info,
+VSC_F(pipe_hdrbytes,		uint64_t, 0, 'C', info,
     "Pipe request header bytes",
 	"Total request bytes sent for piped sessions"
 )
-VSC_F(pipe_out,			uint64_t, 0, 'c', info,
+VSC_F(pipe_out,			uint64_t, 0, 'C', info,
     "Piped bytes to backend",
 	"Total number of bytes forwarded to backend in"
 	" pipe sessions"
 )
-VSC_F(pipe_in,			uint64_t, 0, 'c', info,
+VSC_F(pipe_in,			uint64_t, 0, 'C', info,
     "Piped bytes from backend",
 	"Total number of bytes forwarded from backend in"
 	" pipe sessions"
-- 
2.1.4

From d54b6a3f307dd939bddabd6b053cc672321cd891 Mon Sep 17 00:00:00 2001
From: "Federico G. Schwindt" <[email protected]>
Date: Wed, 7 Jan 2015 02:48:12 +0000
Subject: [PATCH 2/2] Add support to scale byte fields in varnishstat(1)

This is available in the ncurses interface using 'e'.

Fixes #1653
---
 bin/varnishstat/varnishstat_curses.c | 47 ++++++++++++++++++++++++++++++------
 doc/sphinx/reference/varnishstat.rst |  3 +++
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c
index 9a399c7..7143b11 100644
--- a/bin/varnishstat/varnishstat_curses.c
+++ b/bin/varnishstat/varnishstat_curses.c
@@ -62,7 +62,7 @@
 #define LINES_POINTS_MIN	3
 
 #define N_COL			6
-#define COLW			13
+#define COLW			14
 #define COLW_NAME_MIN		24
 
 struct ma {
@@ -100,6 +100,18 @@ struct hitrate {
 };
 static struct hitrate hitrate;
 
+static struct {
+	float div;
+	const char *fmt;
+} scaletab[] = {
+	{ 1, " %12.0f" },
+	{ 1024., " %12.2fk" },
+	{ 1024.*1024, " %12.2fm" },
+	{ 1024.*1024*1024,  " %12.2fg" },
+	{ 1024.*1024*1024*1024,  " %12.2ft" },
+	{ 1024.*1024*1024*1024*1024, " %12.2fp" }
+};
+
 static VTAILQ_HEAD(, pt) ptlist = VTAILQ_HEAD_INITIALIZER(ptlist);
 static int n_ptlist = 0;
 static int n_ptarray = 0;
@@ -124,6 +136,7 @@ static int current = 0;
 static int rebuild = 0;
 static int redraw = 0;
 static int sample = 0;
+static int scale = 0;
 static double t_sample = 0.;
 static double interval = 1.;
 
@@ -647,34 +660,46 @@ draw_line_default(WINDOW *w, int y, int x, int X, struct pt *pt)
 	AN(w);
 	AN(pt);
 
+#define isB(f)	(f == 'C' || f == 'G')
+#define scT(e)	scaletab[scale]. e
+#define prS(num)	do { 						\
+	if (isB(pt->flag))						\
+		mvwprintw(w, y, x, scT(fmt), (float)num / scT(div));	\
+	else								\
+		mvwprintw(w, y, x, " %12.2f", num);			\
+} while(0)
 	col = 0;
 	while (col < COL_LAST) {
 		if (X - x < COLW)
 			break;
 		switch (col) {
 		case COL_CUR:
-			mvwprintw(w, y, x, " %12ju", (uintmax_t)pt->cur);
+			if (isB(pt->flag))
+				prS(pt->cur);
+			else
+				mvwprintw(w, y, x, " %12ju",
+				    (uintmax_t)pt->cur);
 			break;
 		case COL_CHG:
 			if (pt->t_last)
-				mvwprintw(w, y, x, " %12.2f", pt->chg);
+				prS(pt->chg);
 			else
 				mvwprintw(w, y, x, " %12s", ".  ");
 			break;
 		case COL_AVG:
 			if (pt->avg)
-				mvwprintw(w, y, x, " %12.2f", pt->avg);
+				prS(pt->avg);
 			else
 				mvwprintw(w, y, x, " %12s", ".  ");
 			break;
 		case COL_MA10:
-			mvwprintw(w, y, x, " %12.2f", pt->ma_10.acc);
+			prS(pt->ma_10.acc);
 			break;
 		case COL_MA100:
-			mvwprintw(w, y, x, " %12.2f", pt->ma_100.acc);
+			prS(pt->ma_100.acc);
 			break;
 		case COL_MA1000:
-			mvwprintw(w, y, x, " %12.2f", pt->ma_1000.acc);
+			prS(pt->ma_1000.acc);
 			break;
 		default:
 			break;
@@ -682,6 +707,9 @@ draw_line_default(WINDOW *w, int y, int x, int X, struct pt *pt)
 		x += COLW;
 		col++;
 	}
+#undef isB
+#undef scT
+#undef prS
 }
 
 static void
@@ -861,6 +889,11 @@ handle_keypress(int ch)
 		current -= l_points;
 		page_start -= l_points;
 		break;
+	case 'e':
+		if (++scale >= sizeof(scaletab)/sizeof(scaletab[0]))
+			scale = 0;
+		rebuild = 1;
+		break;
 	case KEY_NPAGE:
 	case ' ':
 		current += l_points;
diff --git a/doc/sphinx/reference/varnishstat.rst b/doc/sphinx/reference/varnishstat.rst
index 8940d80..24f2850 100644
--- a/doc/sphinx/reference/varnishstat.rst
+++ b/doc/sphinx/reference/varnishstat.rst
@@ -119,6 +119,9 @@ The following keys control the interactive display:
 <PAGEDOWN> or <SPACE>
 	Navigate the counter list one page down.
 
+<e>
+	Change scaling factor, cycling from bytes through pedibytes.
+
 <g>
 	Go to the top of the counter list.
 
-- 
2.1.4

_______________________________________________
varnish-dev mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Reply via email to