[master] 0d58783 Add a vsc to vmod_debug for testing / troubleshooting

Nils Goroll nils.goroll at uplex.de
Mon Nov 6 19:24:08 UTC 2017


commit 0d587836fa415409c561b8737fb1aada6aa276c4
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Nov 6 20:02:14 2017 +0100

    Add a vsc to vmod_debug for testing / troubleshooting
    
    vmod_vtc might be a better place for it, but we should probably get $VSC
    support in vmodtool first and generate the am_boilerplate for it.
    
    Ref #2470

diff --git a/lib/libvmod_debug/Makefile.am b/lib/libvmod_debug/Makefile.am
index 0bc92d3..edb074c 100644
--- a/lib/libvmod_debug/Makefile.am
+++ b/lib/libvmod_debug/Makefile.am
@@ -42,8 +42,21 @@ vcc_if.h vmod_debug.rst vmod_debug.man.rst: vcc_if.c
 vcc_if.c: $(vmodtool) $(vmod_srcdir)/vmod.vcc
 	@PYTHON@ $(vmodtool) $(vmodtoolargs) $(vmod_srcdir)/vmod.vcc
 
+.vsc.c:
+	$(PYTHON) $(top_srcdir)/lib/libvcc/vsctool.py -ch $<
+
+VSC_SRC		= VSC_debug.vsc
+VSC_GEN_C	= VSC_debug.c
+VSC_GEN_H	= VSC_debug.h
+
+BUILT_SOURCES			 = $(VSC_GEN_C)
+libvmod_debug_la_SOURCES	+= $(VSC_SRC)
+
+$(VSC_GEN_C): $(top_srcdir)/lib/libvcc/vsctool.py
+
 EXTRA_DIST = vmod.vcc
 
 CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h \
 	$(builddir)/vmod_debug.rst \
-	$(builddir)/vmod_debug.man.rst
+	$(builddir)/vmod_debug.man.rst \
+	$(VSC_GEN_C) $(VSC_GEN_H)
diff --git a/lib/libvmod_debug/VSC_debug.vsc b/lib/libvmod_debug/VSC_debug.vsc
new file mode 100644
index 0000000..aac6410
--- /dev/null
+++ b/lib/libvmod_debug/VSC_debug.vsc
@@ -0,0 +1,15 @@
+#
+.. varnish_vsc_begin::	debug
+	:oneliner:	Example Counters
+	:order:		70
+
+	Test counters from vmod_debug
+
+.. varnish_vsc:: foo
+	:type:		counter
+	:level:		debug
+	:oneliner:	arbitrary counter
+
+	Just counting something
+
+.. varnish_vsc_end::	debug
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index b33e0d9..bb12df3 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -213,3 +213,11 @@ Returns the size in bytes of a collection of C-datatypes.
 * 'z' = size_t
 * 'o' = off_t
 * 'j' = intmax_t
+
+$Function VOID vsc_new()
+
+Add a vsc
+
+$Function VOID vsc_destroy()
+
+Remove a vsc
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index 74718e7..ad6b6a5 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -42,6 +42,7 @@
 #include "vtcp.h"
 #include "vtim.h"
 #include "vcc_if.h"
+#include "VSC_debug.h"
 
 #include "common/common_param.h"
 
@@ -64,6 +65,9 @@ struct priv_vcl {
 
 static VCL_DURATION vcl_release_delay = 0.0;
 
+pthread_mutex_t vsc_mtx = PTHREAD_MUTEX_INITIALIZER;
+static struct VSC_debug *vsc;
+
 VCL_VOID __match_proto__(td_debug_panic)
 xyzzy_panic(VRT_CTX, const char *str, ...)
 {
@@ -351,6 +355,10 @@ event_function(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
 	case VCL_EVENT_LOAD: return (event_load(ctx, priv));
 	case VCL_EVENT_WARM: return (event_warm(ctx, priv));
 	case VCL_EVENT_COLD: return (event_cold(ctx, priv));
+	case VCL_EVENT_DISCARD:
+		if (vsc)
+			VSC_debug_Destroy(&vsc);
+		return (0);
 	default: return (0);
 	}
 }
@@ -565,3 +573,25 @@ xyzzy_typesize(VRT_CTX, VCL_STRING s)
 	}
 	return ((VCL_INT)i);
 }
+
+VCL_VOID
+xyzzy_vsc_new(VRT_CTX)
+{
+	(void)ctx;
+	AZ(pthread_mutex_lock(&vsc_mtx));
+	if (vsc == NULL)
+		vsc = VSC_debug_New("");
+	AN(vsc);
+	AZ(pthread_mutex_unlock(&vsc_mtx));
+}
+
+VCL_VOID
+xyzzy_vsc_destroy(VRT_CTX)
+{
+	(void)ctx;
+	AZ(pthread_mutex_lock(&vsc_mtx));
+	if (vsc)
+		VSC_debug_Destroy(&vsc);
+	AZ(vsc);
+	AZ(pthread_mutex_unlock(&vsc_mtx));
+}


More information about the varnish-commit mailing list