[master] 73632b2 Add a debug parameter and start moving diag_bitmap stuff into it.

Poul-Henning Kamp phk at varnish-cache.org
Mon Aug 27 20:10:21 CEST 2012


commit 73632b2c74bfc12f15ec06d9e0ad0cea1acd0fe6
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Aug 27 18:09:17 2012 +0000

    Add a debug parameter and start moving diag_bitmap stuff into it.
    
    XXX: doc-update needed

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 43c104e..f3e32c3 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -976,12 +976,6 @@ void VSLbt(struct vsl_log *, enum VSL_tag_e tag, txt t);
 
 void VSL_Flush(struct vsl_log *, int overflow);
 
-#define DSL(flag, tag, id, ...)					\
-	do {							\
-		if (cache_param->diag_bitmap & (flag))		\
-			VSL((tag), (id), __VA_ARGS__);		\
-	} while (0)
-
 #endif
 
 /* cache_response.c */
@@ -1122,3 +1116,16 @@ Tadd(txt *t, const char *p, int l)
  * extra timestamps in cache_pool.c.  Hide this detail with a macro
  */
 #define W_TIM_real(w) ((w)->lastused = VTIM_real())
+
+static inline int
+DO_DEBUG(enum debug_bits x)
+{
+	return (cache_param->debug_bits[(unsigned)x>>3] &
+	    (0x80U >> ((unsigned)x & 7)));
+}
+
+#define DSL(flag, tag, id, ...)					\
+	do {							\
+		if (cache_param->diag_bitmap & (flag))		\
+			VSL((tag), (id), __VA_ARGS__);		\
+	} while (0)
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index e99ed6c..e12da55 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -1220,7 +1220,7 @@ CNT_Request(struct worker *wrk, struct req *req)
 		switch (req->req_step) {
 #define REQ_STEP(l,u,arg) \
 		    case R_STP_##u: \
-			if (cache_param->diag_bitmap & 0x01) \
+			if (DO_DEBUG(DBG_REQ_STATE)) \
 				cnt_diag(req, #u); \
 			done = cnt_##l arg; \
 		        break;
diff --git a/bin/varnishd/common/params.h b/bin/varnishd/common/params.h
index e2c9ec1..6c3abb4 100644
--- a/bin/varnishd/common/params.h
+++ b/bin/varnishd/common/params.h
@@ -33,6 +33,13 @@
 
 #define VSM_CLASS_PARAM		"Params"
 
+enum debug_bits {
+#define DEBUG_BIT(U, l, p, d) DBG_##U,
+#include "tbl/debug_bits.h"
+#undef DEBUG_BIT
+       DBG_Reserved
+};
+
 struct poolparam {
 	unsigned		min_pool;
 	unsigned		max_pool;
@@ -198,5 +205,6 @@ struct params {
 	struct poolparam	sess_pool;
 	struct poolparam	vbo_pool;
 
-	uint8_t			vsl_mask[256/8];
+	uint8_t			vsl_mask[256>>3];
+	uint8_t			debug_bits[(DBG_Reserved+7)>>3];
 };
diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c
index 9ce9470..7696292 100644
--- a/bin/varnishd/mgt/mgt_param.c
+++ b/bin/varnishd/mgt/mgt_param.c
@@ -1046,7 +1046,6 @@ static const struct parspec input_parspec[] = {
 		WAITER_DEFAULT, NULL },
 	{ "diag_bitmap", tweak_diag_bitmap, 0, 0, 0,
 		"Bitmap controlling diagnostics code:\n"
-		"  0x00000001 - CNT_Session states.\n"
 		"  0x00000002 - workspace debugging.\n"
 		"  0x00000004 - kqueue debugging.\n"
 		"  0x00000008 - mutex logging.\n"
diff --git a/bin/varnishd/mgt/mgt_param_bits.c b/bin/varnishd/mgt/mgt_param_bits.c
index 1910f2b..b238823 100644
--- a/bin/varnishd/mgt/mgt_param_bits.c
+++ b/bin/varnishd/mgt/mgt_param_bits.c
@@ -154,6 +154,45 @@ tweak_vsl_mask(struct cli *cli, const struct parspec *par, const char *arg)
 }
 
 /*--------------------------------------------------------------------
+ * The debug parameter
+ */
+
+static const char * const debug_tags[] = {
+#  define DEBUG_BIT(U,l,p,d)       [DBG_##U] = #l,
+#  include "tbl/debug_bits.h"
+#  undef DEBUG_BIT
+       NULL
+};
+
+static void
+tweak_debug(struct cli *cli, const struct parspec *par, const char *arg)
+{
+	const char *s;
+	unsigned j;
+	(void)par;
+
+	if (arg != NULL) {
+		if (!strcmp(arg, "none")) {
+			memset(mgt_param.debug_bits,
+			    0, sizeof mgt_param.debug_bits);
+		} else {
+			bit_tweak(cli, mgt_param.debug_bits,
+			    DBG_Reserved, arg, debug_tags, "debug bit", "+");
+		}
+	} else {
+		s = "";
+		for (j = 0; j < (unsigned)DBG_Reserved; j++) {
+			if (bit(mgt_param.debug_bits, j, BTST)) {
+				VCLI_Out(cli, "%s+%s", s, debug_tags[j]);
+				s = ",";
+			}
+		}
+		if (*s == '\0')
+			VCLI_Out(cli, "none");
+	}
+}
+
+/*--------------------------------------------------------------------
  * The parameter table itself
  */
 
@@ -164,5 +203,13 @@ const struct parspec VSL_parspec[] = {
 		"Use +/- prefixe in front of VSL tag name, to mask/unmask "
 		"individual VSL messages.",
 		0, "default", "" },
+	{ "debug", tweak_debug, NULL, 0, 0,
+		"Enable/Disable various kinds of debugging.\n"
+		"\tnone\t\tDisable all debugging\n"
+		"Use +/- prefix to set/reset individual bits:\n"
+#define DEBUG_BIT(U, l, p, d) "\t" #l "\t" p d "\n"
+#include "tbl/debug_bits.h"
+#undef DEBUG_BIT
+		, 0, "none", "" },
 	{ NULL, NULL, NULL }
 };
diff --git a/bin/varnishtest/tests.disabled/t00000.vtc b/bin/varnishtest/tests.disabled/t00000.vtc
index 57ab7c7..8265195 100644
--- a/bin/varnishtest/tests.disabled/t00000.vtc
+++ b/bin/varnishtest/tests.disabled/t00000.vtc
@@ -20,7 +20,7 @@ varnish v1 -vcl+backend {
 	}
 } -start 
 
-varnish v1 -cliok "param.set diag_bitmap 1"
+varnish v1 -cliok "param.set debug +req_state"
 
 client c1 {
 	txreq  -hdr "foo: /foo"
diff --git a/bin/varnishtest/tests/r00902.vtc b/bin/varnishtest/tests/r00902.vtc
index 67e4c96..8caf652 100644
--- a/bin/varnishtest/tests/r00902.vtc
+++ b/bin/varnishtest/tests/r00902.vtc
@@ -15,7 +15,7 @@ server s1 {
 varnish v1 -vcl+backend {
 } -start 
 
-varnish v1 -cliok "param.set diag_bitmap 1"
+varnish v1 -cliok "param.set debug +req_state"
 
 client c1 {
 	txreq  -hdr "foo: /foo"
diff --git a/include/Makefile.am b/include/Makefile.am
index b70a825..7562f6c 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -6,6 +6,7 @@ nobase_pkginclude_HEADERS = \
 	tbl/backend_poll.h \
 	tbl/ban_vars.h \
 	tbl/body_status.h \
+	tbl/debug_bits.h \
 	tbl/http_headers.h \
 	tbl/http_response.h \
 	tbl/locks.h \
diff --git a/include/tbl/debug_bits.h b/include/tbl/debug_bits.h
new file mode 100644
index 0000000..7acf6d8
--- /dev/null
+++ b/include/tbl/debug_bits.h
@@ -0,0 +1,32 @@
+/*-
+ * Copyright (c) 2012 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Fields in the debug parameter
+ *
+ */
+
+DEBUG_BIT(REQ_STATE,		req_state,	"",  "Request state engine")



More information about the varnish-commit mailing list