[master] 3399615ad Start interactive varnishstat with relevant verbosity

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Apr 1 07:49:08 UTC 2020


commit 3399615ad49617e427ab461555c0665888520953
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Fri Mar 6 11:42:45 2020 +0100

    Start interactive varnishstat with relevant verbosity
    
    Where relevant means the highest verbosity when fields are filtered with
    -f on the command line. There is still a caveat that this only applies
    for the first iteration, and some parameters may conditionally appear
    and not be visible when that event occurs (for example, when the child
    process starts).
    
    The rebuild variable was used as a bitmap but did not make use of
    individual bits. This is now the case, but only for the two actionable
    rebuild conditions.
    
    Closes #2990

diff --git a/bin/varnishstat/varnishstat.c b/bin/varnishstat/varnishstat.c
index 6247f5035..f9e6b89c1 100644
--- a/bin/varnishstat/varnishstat.c
+++ b/bin/varnishstat/varnishstat.c
@@ -54,6 +54,7 @@
 #include "varnishstat.h"
 
 static struct VUT *vut;
+int has_f = 0;
 
 /*--------------------------------------------------------------------*/
 
@@ -278,7 +279,6 @@ main(int argc, char * const *argv)
 	int once = 0, xml = 0, json = 0, f_list = 0, curses = 0;
 	signed char opt;
 	int i;
-	int has_f = 0;
 	struct vsc *vsc;
 
 	if (argc == 2 && !strcmp(argv[1], "--bindings"))
diff --git a/bin/varnishstat/varnishstat.h b/bin/varnishstat/varnishstat.h
index 2785407d6..dbdadaf7c 100644
--- a/bin/varnishstat/varnishstat.h
+++ b/bin/varnishstat/varnishstat.h
@@ -37,7 +37,12 @@
 #include "vas.h"
 #include "vcs.h"
 
+/* varnishstat.c */
+extern int has_f;
+
+/* varnishstat_curses.c */
 void do_curses(struct vsm *,  struct vsc *);
 
+/* varnishstat_curses_help.c */
 extern const char *const bindings_help[];
 extern const int bindings_help_len;
diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c
index 6a829a838..b8d5c7cf4 100644
--- a/bin/varnishstat/varnishstat_curses.c
+++ b/bin/varnishstat/varnishstat_curses.c
@@ -64,6 +64,9 @@
 
 #define VALUE_MAX		999999999999
 
+#define REBUILD_NEXT		(1u << 0)
+#define REBUILD_FIRST		(1u << 1)
+
 enum kb_e {
 #define BINDING(name, desc) KB_ ## name,
 #define BINDING_SIG
@@ -220,10 +223,15 @@ build_pt_array(void)
 
 	VTAILQ_FOREACH(pt, &ptlist, list) {
 		CHECK_OBJ_NOTNULL(pt, PT_MAGIC);
+		if (pt->vpt->level > verbosity) {
+			if (has_f && (rebuild & REBUILD_FIRST))
+				verbosity = VSC_ChangeLevel(verbosity,
+				    pt->vpt->level - verbosity);
+			else
+				continue;
+		}
 		if (!pt->seen && hide_unseen)
 			continue;
-		if (pt->vpt->level > verbosity)
-			continue;
 		assert(n_ptarray < n_ptlist);
 		ptarray[n_ptarray++] = pt;
 	}
@@ -254,7 +262,7 @@ sample_points(void)
 			continue;
 		if (!pt->seen) {
 			pt->seen = 1;
-			rebuild = 1;
+			rebuild = REBUILD_NEXT;
 		}
 		pt->last = pt->cur;
 		pt->cur = v;
@@ -964,11 +972,11 @@ handle_points_keypress(enum kb_e kb)
 		break;
 	case KB_UNSEEN:
 		hide_unseen = 1 - hide_unseen;
-		rebuild = 1;
+		rebuild = REBUILD_NEXT;
 		break;
 	case KB_SCALE:
 		scale = 1 - scale;
-		rebuild = 1;
+		rebuild = REBUILD_NEXT;
 		break;
 	case KB_ACCEL:
 		interval += 0.1;
@@ -988,11 +996,11 @@ handle_points_keypress(enum kb_e kb)
 		break;
 	case KB_VERBOSE:
 		verbosity = VSC_ChangeLevel(verbosity, 1);
-		rebuild = 1;
+		rebuild = REBUILD_NEXT;
 		break;
 	case KB_QUIET:
 		verbosity = VSC_ChangeLevel(verbosity, -1);
-		rebuild = 1;
+		rebuild = REBUILD_NEXT;
 		break;
 	case KB_SAMPLE:
 		sample = 1;
@@ -1094,7 +1102,7 @@ newpt(void *priv, const struct VSC_point *const vpt)
 
 	AZ(priv);
 	ALLOC_OBJ(pt, PT_MAGIC);
-	rebuild |= 1;
+	rebuild |= REBUILD_NEXT;
 	AN(pt);
 	pt->vpt = vpt;
 	pt->last = *pt->vpt->ptr;
@@ -1125,7 +1133,7 @@ delpt(void *priv, const struct VSC_point *const vpt)
 
 	AZ(priv);
 	CAST_OBJ_NOTNULL(pt, vpt->priv, PT_MAGIC);
-	rebuild |= 2;
+	rebuild |= REBUILD_NEXT;
 	VTAILQ_REMOVE(&ptlist, pt, list);
 	n_ptlist--;
 	FREE_OBJ(pt);
@@ -1159,6 +1167,7 @@ do_curses(struct vsm *vsm, struct vsc *vsc)
 
 	VSC_State(vsc, newpt, delpt, NULL);
 
+	rebuild |= REBUILD_FIRST;
 	(void)VSC_Iter(vsc, vsm, NULL, NULL);
 	build_pt_array();
 	init_hitrate();
diff --git a/bin/varnishtest/tests/r02990.vtc b/bin/varnishtest/tests/r02990.vtc
new file mode 100644
index 000000000..6d38efa2a
--- /dev/null
+++ b/bin/varnishtest/tests/r02990.vtc
@@ -0,0 +1,13 @@
+varnishtest "Initial varnishstat verbosity"
+
+varnish v1 -vcl {backend be none;} -start
+
+process p1 -dump {varnishstat -n ${v1_name}} -start
+process p2 -dump {varnishstat -n ${v1_name} -f MGT.child_start} -start
+
+process p1 -expect-text 0 0 INFO
+process p1 -screen_dump
+
+process p2 -expect-text 0 0 MGT.child_start
+process p2 -expect-text 0 0 DIAG
+process p2 -screen_dump


More information about the varnish-commit mailing list