[master] 87c20ed Make the VSC types a tbl defined list, with descriptions.

Martin Blix Grydeland martin at varnish-cache.org
Wed May 15 14:46:13 CEST 2013


commit 87c20ed8a665a2eaaf2fcfca9249df61f4478a9e
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Thu Jan 24 13:23:33 2013 +0100

    Make the VSC types a tbl defined list, with descriptions.
    
    Add global variables for the type name strings.
    
    Compile in static VSC type descriptions in libvarnishapi

diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 18699e5..de6b28a 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -50,6 +50,7 @@ varnishd_SOURCES = \
 	cache/cache_wrw.c \
 	cache/cache_ws.c \
 	common/common_vsm.c \
+	common/common_vsc.c \
 	hash/hash_classic.c \
 	hash/hash_critbit.c \
 	hash/hash_mgt.c \
diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c
index 15e1104..5b68bfb 100644
--- a/bin/varnishd/cache/cache_backend_cfg.c
+++ b/bin/varnishd/cache/cache_backend_cfg.c
@@ -206,7 +206,7 @@ VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb)
 	    vb->ipv4_addr == NULL ? "" : vb->ipv4_addr,
 	    vb->ipv6_addr == NULL ? "" : vb->ipv6_addr, vb->port);
 
-	b->vsc = VSM_Alloc(sizeof *b->vsc, VSC_CLASS, VSC_TYPE_VBE, buf);
+	b->vsc = VSM_Alloc(sizeof *b->vsc, VSC_CLASS, VSC_type_vbe, buf);
 	b->vsc->vcls++;
 
 	VTAILQ_INIT(&b->connlist);
diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c
index bd34046..37fa115 100644
--- a/bin/varnishd/cache/cache_lck.c
+++ b/bin/varnishd/cache/cache_lck.c
@@ -204,7 +204,7 @@ LCK_Init(void)
 	AZ(pthread_mutex_init(&lck_mtx, NULL));
 #define LOCK(nam)						\
 	lck_##nam = VSM_Alloc(sizeof(struct VSC_C_lck),		\
-	   VSC_CLASS, VSC_TYPE_LCK, #nam);
+	   VSC_CLASS, VSC_type_lck, #nam);
 #include "tbl/locks.h"
 #undef LOCK
 }
diff --git a/bin/varnishd/cache/cache_mempool.c b/bin/varnishd/cache/cache_mempool.c
index 5f06750..fded87b 100644
--- a/bin/varnishd/cache/cache_mempool.c
+++ b/bin/varnishd/cache/cache_mempool.c
@@ -237,7 +237,7 @@ MPL_New(const char *name,
 	Lck_New(&mpl->mtx, lck_mempool);
 	/* XXX: prealloc min_pool */
 	mpl->vsc = VSM_Alloc(sizeof *mpl->vsc,
-	    VSC_CLASS, VSC_TYPE_MEMPOOL, mpl->name);
+	    VSC_CLASS, VSC_type_mempool, mpl->name);
 	AN(mpl->vsc);
 	AZ(pthread_create(&mpl->thread, NULL, mpl_guard, mpl));
 	AZ(pthread_detach(mpl->thread));
diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c
index 198e225..5dbd44f 100644
--- a/bin/varnishd/cache/cache_shmlog.c
+++ b/bin/varnishd/cache/cache_shmlog.c
@@ -378,7 +378,7 @@ VSM_Init(void)
 	vsl_ptr = vsl_start + 1;
 
 	VSC_C_main = VSM_Alloc(sizeof *VSC_C_main,
-	    VSC_CLASS, VSC_TYPE_MAIN, "");
+	    VSC_CLASS, VSC_type_main, "");
 	AN(VSC_C_main);
 
 	vsl_wrap();
diff --git a/bin/varnishd/common/common_vsc.c b/bin/varnishd/common/common_vsc.c
new file mode 100644
index 0000000..7078595
--- /dev/null
+++ b/bin/varnishd/common/common_vsc.c
@@ -0,0 +1,34 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2013 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Martin Blix Grydeland <martin at varnish-software.com>
+ *
+ * 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.
+ *
+ */
+
+/* Build the static vsc type names */
+#define VSC_TYPE_F(n,t,l,e,d)		const char *VSC_type_##n = t;
+#include "tbl/vsc_types.h"
+#undef VSC_TYPE_F
diff --git a/bin/varnishd/mgt/mgt_shmem.c b/bin/varnishd/mgt/mgt_shmem.c
index a0aaa9d..507eb84 100644
--- a/bin/varnishd/mgt/mgt_shmem.c
+++ b/bin/varnishd/mgt/mgt_shmem.c
@@ -241,7 +241,7 @@ mgt_SHM_Create(void)
 
 	/* Copy management counters to shm and update pointer */
 	VSC_C_mgt = VSM_common_alloc(heritage.vsm,
-	    sizeof *VSC_C_mgt, VSC_CLASS, VSC_TYPE_MGT, "");
+	    sizeof *VSC_C_mgt, VSC_CLASS, VSC_type_mgt, "");
 	AN(VSC_C_mgt);
 	*VSC_C_mgt = static_VSC_C_mgt;
 
diff --git a/bin/varnishd/storage/storage_file.c b/bin/varnishd/storage/storage_file.c
index 3d422fe..ac0b6c4 100644
--- a/bin/varnishd/storage/storage_file.c
+++ b/bin/varnishd/storage/storage_file.c
@@ -433,7 +433,7 @@ smf_open(const struct stevedore *st)
 
 	CAST_OBJ_NOTNULL(sc, st->priv, SMF_SC_MAGIC);
 	sc->stats = VSM_Alloc(sizeof *sc->stats,
-	    VSC_CLASS, VSC_TYPE_SMF, st->ident);
+	    VSC_CLASS, VSC_type_smf, st->ident);
 	Lck_New(&sc->mtx, lck_smf);
 	Lck_Lock(&sc->mtx);
 	smf_open_chunk(sc, sc->filesize, 0, &fail, &sum);
diff --git a/bin/varnishd/storage/storage_malloc.c b/bin/varnishd/storage/storage_malloc.c
index 88cb948..adb6cd2 100644
--- a/bin/varnishd/storage/storage_malloc.c
+++ b/bin/varnishd/storage/storage_malloc.c
@@ -238,7 +238,7 @@ sma_open(const struct stevedore *st)
 	CAST_OBJ_NOTNULL(sma_sc, st->priv, SMA_SC_MAGIC);
 	Lck_New(&sma_sc->sma_mtx, lck_sma);
 	sma_sc->stats = VSM_Alloc(sizeof *sma_sc->stats,
-	    VSC_CLASS, VSC_TYPE_SMA, st->ident);
+	    VSC_CLASS, VSC_type_sma, st->ident);
 	memset(sma_sc->stats, 0, sizeof *sma_sc->stats);
 	if (sma_sc->sma_max != SIZE_MAX)
 		sma_sc->stats->g_space = sma_sc->sma_max;
diff --git a/include/Makefile.am b/include/Makefile.am
index cb10bc4..6c3f687 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -18,6 +18,7 @@ nobase_pkginclude_HEADERS = \
 	tbl/vcc_types.h \
 	tbl/vcl_returns.h \
 	tbl/vrt_stv_var.h \
+	tbl/vsc_types.h \
 	tbl/vsc_all.h \
 	tbl/vsc_fields.h \
 	tbl/vsc_f_main.h \
diff --git a/include/tbl/vsc_all.h b/include/tbl/vsc_all.h
index e1ccb52..deb5eaf 100644
--- a/include/tbl/vsc_all.h
+++ b/include/tbl/vsc_all.h
@@ -28,42 +28,42 @@
  */
 
 
-VSC_DO(MGT, mgt, VSC_TYPE_MGT)
+VSC_DO(MGT, mgt, VSC_type_mgt)
 #define VSC_DO_MGT
 #include "tbl/vsc_fields.h"
 #undef VSC_DO_MGT
-VSC_DONE(MGT, mgt, VSC_TYPE_MGT)
+VSC_DONE(MGT, mgt, VSC_type_mgt)
 
-VSC_DO(LCK, lck, VSC_TYPE_LCK)
+VSC_DO(LCK, lck, VSC_type_lck)
 #define VSC_DO_LCK
 #include "tbl/vsc_fields.h"
 #undef VSC_DO_LCK
-VSC_DONE(LCK, lck, VSC_TYPE_LCK)
+VSC_DONE(LCK, lck, VSC_type_lck)
 
-VSC_DO(MAIN, main, VSC_TYPE_MAIN)
+VSC_DO(MAIN, main, VSC_type_main)
 #include "tbl/vsc_f_main.h"
-VSC_DONE(MAIN, main, VSC_TYPE_MAIN)
+VSC_DONE(MAIN, main, VSC_type_main)
 
-VSC_DO(SMA, sma, VSC_TYPE_SMA)
+VSC_DO(SMA, sma, VSC_type_sma)
 #define VSC_DO_SMA
 #include "tbl/vsc_fields.h"
 #undef VSC_DO_SMA
-VSC_DONE(SMA, sma, VSC_TYPE_SMA)
+VSC_DONE(SMA, sma, VSC_type_sma)
 
-VSC_DO(SMF, smf, VSC_TYPE_SMF)
+VSC_DO(SMF, smf, VSC_type_smf)
 #define VSC_DO_SMF
 #include "tbl/vsc_fields.h"
 #undef VSC_DO_SMF
-VSC_DONE(SMF, smf, VSC_TYPE_SMF)
+VSC_DONE(SMF, smf, VSC_type_smf)
 
-VSC_DO(VBE, vbe, VSC_TYPE_VBE)
+VSC_DO(VBE, vbe, VSC_type_vbe)
 #define VSC_DO_VBE
 #include "tbl/vsc_fields.h"
 #undef VSC_DO_VBE
-VSC_DONE(VBE, vbe, VSC_TYPE_VBE)
+VSC_DONE(VBE, vbe, VSC_type_vbe)
 
-VSC_DO(MEMPOOL, mempool, VSC_TYPE_MEMPOOL)
+VSC_DO(MEMPOOL, mempool, VSC_type_mempool)
 #define VSC_DO_MEMPOOL
 #include "tbl/vsc_fields.h"
 #undef VSC_DO_MEMPOOL
-VSC_DONE(MEMPOOL, mempool, VSC_TYPE_MEMPOOL)
+VSC_DONE(MEMPOOL, mempool, VSC_type_mempool)
diff --git a/include/tbl/vsc_types.h b/include/tbl/vsc_types.h
new file mode 100644
index 0000000..0fcb0dc
--- /dev/null
+++ b/include/tbl/vsc_types.h
@@ -0,0 +1,61 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2013 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Martin Blix Grydeland <martin at varnish-software.com>
+ *
+ * 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 (n, l, e, d):
+ *    n - Name:		Field name, in C-source
+ *    t - Type:		Type name, in shm chunk
+ *    l - Label:	Display name, in stats programs
+ *    e - Explanation:	Short description of this counter type
+ *    d - Description:	Long description of this counter type
+ *
+ */
+
+
+VSC_TYPE_F(main,	"MAIN",		"",		"Child",
+    "Child process main counters"
+)
+VSC_TYPE_F(mgt,		"MGT",		"MGT",		"Master",
+    "Management process counters"
+)
+VSC_TYPE_F(sma,		"SMA",		"SMA",		"Storage malloc",
+    "Malloc storage counters"
+)
+VSC_TYPE_F(smf,		"SMF",		"SMF",		"Storage file",
+    "File storage counters"
+)
+VSC_TYPE_F(lck,		"LCK",		"LCK",		"Lock",
+    "Mutex lock counters"
+)
+VSC_TYPE_F(mempool,	"MEMPOOL",	"MEMPOOL",	"Memory pool",
+    "Memory pool counters"
+)
+VSC_TYPE_F(vbe,		"VBE",		"VBE",		"Backend",
+    "Backend counters"
+)
diff --git a/include/vapi/vsc.h b/include/vapi/vsc.h
index d21cb43..6c56626 100644
--- a/include/vapi/vsc.h
+++ b/include/vapi/vsc.h
@@ -65,6 +65,12 @@ struct VSC_C_main *VSC_Main(struct VSM_data *vd);
 	 * returns NULL until child has been started.
 	 */
 
+struct VSC_type_desc {
+	const char *label;		/* label */
+	const char *sdesc;		/* short description */
+	const char *ldesc;		/* long description */
+};
+
 struct VSC_desc {
 	const char *name;		/* field name			*/
 	const char *fmt;		/* field format ("uint64_t")	*/
@@ -96,14 +102,20 @@ int VSC_Iter(struct VSM_data *vd, VSC_iter_f *func, void *priv);
 	 */
 
 /**********************************************************************
- * Precompiled VSC_desc's for all know VSCs.
+ * Precompiled VSC_type_desc's and VSC_desc's for all know VSCs.
  */
-#define VSC_F(n,t,l,f,d,e)
+
+#define VSC_TYPE_F(n,t,l,e,d) \
+	extern const struct VSC_type_desc VSC_type_desc_##n;
+#include "tbl/vsc_types.h"
+#undef VSC_TYPE_F
+
 #define VSC_DO(U,l,t) extern const struct VSC_desc VSC_desc_##l[];
+#define VSC_F(n,t,l,f,d,e)
 #define VSC_DONE(U,l,t)
 #include "tbl/vsc_all.h"
-#undef VSC_F
 #undef VSC_DO
+#undef VSC_F
 #undef VSC_DONE
 
 #endif /* VAPI_VSC_H_INCLUDED */
diff --git a/include/vapi/vsc_int.h b/include/vapi/vsc_int.h
index b98df57..2109379 100644
--- a/include/vapi/vsc_int.h
+++ b/include/vapi/vsc_int.h
@@ -30,21 +30,16 @@
 
 #define VSC_CLASS		"Stat"
 
-#define VSC_TYPE_MGT		"MGT"
-#define VSC_TYPE_MAIN		""
-#define VSC_TYPE_SMA		"SMA"
-#define VSC_TYPE_SMF		"SMF"
-#define VSC_TYPE_VBE		"VBE"
-#define VSC_TYPE_LCK		"LCK"
-#define VSC_TYPE_MEMPOOL	"MEMPOOL"
-
-#define VSC_F(n, t, l, f, e, d)	t n;
-
-#define VSC_DO(u,l,t) struct VSC_C_##l {
-#define VSC_DONE(u,l,t) };
+/* Forward declare the static vsc type names */
+#define VSC_TYPE_F(n,t,l,e,d)		extern const char *VSC_type_##n;
+#include "tbl/vsc_types.h"
+#undef VSC_TYPE_F
 
+/* Define the vsc type structs */
+#define VSC_DO(u,l,t)			struct VSC_C_##l {
+#define VSC_F(n,t,l,f,e,d)			t n;
+#define VSC_DONE(u,l,t)			};
 #include "tbl/vsc_all.h"
-
 #undef VSC_DO
 #undef VSC_F
 #undef VSC_DONE
diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c
index 31b297f..b40e35e 100644
--- a/lib/libvarnishapi/vsc.c
+++ b/lib/libvarnishapi/vsc.c
@@ -248,7 +248,7 @@ VSC_Main(struct VSM_data *vd)
 	struct vsc *vsc = vsc_setup(vd);
 
 	if (!VSM_StillValid(vd, &vsc->main_fantom) &&
-	    !VSM_Get(vd, &vsc->main_fantom, VSC_CLASS, "", ""))
+	    !VSM_Get(vd, &vsc->main_fantom, VSC_CLASS, VSC_type_main, ""))
 		return (NULL);
 	return ((void*)vsc->main_fantom.b);
 }
@@ -416,10 +416,19 @@ VSC_Iter(struct VSM_data *vd, VSC_iter_f *func, void *priv)
  * Build the static point descriptions
  */
 
-#define VSC_F(n,t,l,f,d,e)	{#n,#t,f,d,e},
-#define VSC_DO(U,l,t) const struct VSC_desc VSC_desc_##l[] = {
-#define VSC_DONE(U,l,t) };
+#define VSC_TYPE_F(n,t,l,e,d)	const char *VSC_type_##n = t;
+#include "tbl/vsc_types.h"
+#undef VSC_TYPE_F
+
+#define VSC_TYPE_F(n,t,l,e,d)			\
+	const struct VSC_type_desc VSC_type_desc_##n = {l,e,d};
+#include "tbl/vsc_types.h"
+#undef VSC_TYPE_F
+
+#define VSC_DO(U,l,t)		const struct VSC_desc VSC_desc_##l[] = {
+#define VSC_F(n,t,l,f,d,e)		{#n,#t,f,d,e},
+#define VSC_DONE(U,l,t)		};
 #include "tbl/vsc_all.h"
-#undef VSC_F
 #undef VSC_DO
+#undef VSC_F
 #undef VSC_DONE



More information about the varnish-commit mailing list