[master] 96f5919 Add the presentation field to the structures in libvarnishapi. *This breaks the API*

Martin Blix Grydeland martin at varnish-software.com
Tue Jan 27 17:17:56 CET 2015


commit 96f5919e56f4a5895c53e9bfc98cf643c4ea0ca6
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Tue Jan 27 16:50:58 2015 +0100

    Add the presentation field to the structures in libvarnishapi. *This breaks the API*
    
    As the API breaks because of this commit, also fix up some structure
    member name inconsistencies to match the table definition.
    
    Add the display format to the json/XML varnishstat output, but do not
    change the output field names to stay script compatible.

diff --git a/bin/varnishstat/varnishstat.c b/bin/varnishstat/varnishstat.c
index 27ef250..a65597e 100644
--- a/bin/varnishstat/varnishstat.c
+++ b/bin/varnishstat/varnishstat.c
@@ -55,7 +55,7 @@ do_xml_cb(void *priv, const struct VSC_point * const pt)
 	(void)priv;
 	if (pt == NULL)
 		return (0);
-	AZ(strcmp(pt->desc->fmt, "uint64_t"));
+	AZ(strcmp(pt->desc->ctype, "uint64_t"));
 	val = *(const volatile uint64_t*)pt->ptr;
 	sec = pt->section;
 
@@ -66,7 +66,8 @@ do_xml_cb(void *priv, const struct VSC_point * const pt)
 		printf("\t\t<ident>%s</ident>\n", sec->fantom->ident);
 	printf("\t\t<name>%s</name>\n", pt->desc->name);
 	printf("\t\t<value>%ju</value>\n", (uintmax_t)val);
-	printf("\t\t<flag>%c</flag>\n", pt->desc->flag);
+	printf("\t\t<flag>%c</flag>\n", pt->desc->semantics);
+	printf("\t\t<format>%c</format>\n", pt->desc->format);
 	printf("\t\t<description>%s</description>\n", pt->desc->sdesc);
 	printf("\t</stat>\n");
 	return (0);
@@ -100,7 +101,7 @@ do_json_cb(void *priv, const struct VSC_point * const pt)
 		return (0);
 
 	jp = priv;
-	AZ(strcmp(pt->desc->fmt, "uint64_t"));
+	AZ(strcmp(pt->desc->ctype, "uint64_t"));
 	val = *(const volatile uint64_t*)pt->ptr;
 	sec = pt->section;
 
@@ -121,7 +122,8 @@ do_json_cb(void *priv, const struct VSC_point * const pt)
 	if (strcmp(sec->fantom->ident, ""))
 		printf("\"ident\": \"%s\", ", sec->fantom->ident);
 	printf("\"value\": %ju, ", (uintmax_t)val);
-	printf("\"flag\": \"%c\", ", pt->desc->flag);
+	printf("\"flag\": \"%c\", ", pt->desc->semantics);
+	printf("\"format\": \"%c\", ", pt->desc->format);
 	printf("\"description\": \"%s\"", pt->desc->sdesc);
 	printf("}");
 
@@ -168,7 +170,7 @@ do_once_cb(void *priv, const struct VSC_point * const pt)
 	if (pt == NULL)
 		return (0);
 	op = priv;
-	AZ(strcmp(pt->desc->fmt, "uint64_t"));
+	AZ(strcmp(pt->desc->ctype, "uint64_t"));
 	val = *(const volatile uint64_t*)pt->ptr;
 	sec = pt->section;
 	i = 0;
@@ -180,7 +182,7 @@ 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 == 'c')
+	if (pt->desc->semantics == '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 b99ff53..4294999 100644
--- a/bin/varnishstat/varnishstat_curses.c
+++ b/bin/varnishstat/varnishstat_curses.c
@@ -79,7 +79,7 @@ struct pt {
 
 	char			*key;
 	char			*name;
-	int			flag;
+	int			semantics;
 	const volatile uint64_t	*ptr;
 
 	char			seen;
@@ -273,7 +273,7 @@ build_pt_list_cb(void *priv, const struct VSC_point *vpt)
 
 	CAST_OBJ_NOTNULL(pt_priv, priv, PT_PRIV_MAGIC);
 
-	AZ(strcmp(vpt->desc->fmt, "uint64_t"));
+	AZ(strcmp(vpt->desc->ctype, "uint64_t"));
 	snprintf(buf, sizeof buf, "%s.%s.%s", vpt->section->type,
 	    vpt->section->ident, vpt->desc->name);
 	buf[sizeof buf - 1] = '\0';
@@ -316,7 +316,7 @@ build_pt_list_cb(void *priv, const struct VSC_point *vpt)
 
 	pt->ptr = vpt->ptr;
 	pt->last = *pt->ptr;
-	pt->flag = vpt->desc->flag;
+	pt->semantics = vpt->desc->semantics;
 
 	pt->ma_10.nmax = 10;
 	pt->ma_100.nmax = 100;
@@ -384,12 +384,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->semantics == '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->semantics == 'c') {
 			if (VSC_C_main != NULL && VSC_C_main->uptime)
 				pt->avg = pt->cur / VSC_C_main->uptime;
 			else
@@ -692,7 +692,7 @@ draw_line_bitmap(WINDOW *w, int y, int x, int X, struct pt *pt)
 
 	AN(w);
 	AN(pt);
-	assert(pt->flag == 'b');
+	assert(pt->semantics == 'b');
 
 	col = 0;
 	while (col < COL_LAST) {
@@ -737,7 +737,7 @@ draw_line(WINDOW *w, int y, struct pt *pt)
 		mvwprintw(w, y, x, "%.*s", colw_name, pt->name);
 	x += colw_name;
 
-	if (pt->flag == 'b')
+	if (pt->semantics == 'b')
 		draw_line_bitmap(w, y, x, X, pt);
 	else
 		draw_line_default(w, y, x, X, pt);
diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c
index 2506093..fbe59f8 100644
--- a/bin/varnishtest/vtc_varnish.c
+++ b/bin/varnishtest/vtc_varnish.c
@@ -761,7 +761,7 @@ do_stat_cb(void *priv, const struct VSC_point * const pt)
 	if (strcmp(pt->desc->name, p))
 		return (0);
 
-	AZ(strcmp(pt->desc->fmt, "uint64_t"));
+	AZ(strcmp(pt->desc->ctype, "uint64_t"));
 	sp->val = *(const volatile uint64_t*)pt->ptr;
 	return (1);
 }
diff --git a/doc/sphinx/reference/varnishstat.rst b/doc/sphinx/reference/varnishstat.rst
index 8dd00eb..ea62918 100644
--- a/doc/sphinx/reference/varnishstat.rst
+++ b/doc/sphinx/reference/varnishstat.rst
@@ -151,7 +151,8 @@ When using the -x option, the output is::
       <ident>FIELD IDENT</ident>
       <name>FIELD NAME</name>
       <value>FIELD VALUE</value>
-      <flag>FIELD FORMAT</flag>
+      <flag>FIELD SEMANTICS</flag>
+      <format>FIELD DISPLAY FORMAT</format>
       <description>FIELD DESCRIPTION</description>
     </stat>
     [..]
@@ -164,7 +165,7 @@ With -j the output format is::
 
   {
     "timestamp": "YYYY-MM-DDTHH:mm:SS",
-    "FIELD NAME": {"type": "FIELD TYPE", "ident": "FIELD IDENT", "value": FIELD VALUE, "flag": "FIELD FORMAT", "description": "FIELD DESCRIPTION"},
+    "FIELD NAME": {"type": "FIELD TYPE", "ident": "FIELD IDENT", "value": FIELD VALUE, "flag": "FIELD SEMANTICS", "format": "FIELD DISPLAY FORMAT", "description": "FIELD DESCRIPTION"},
     [..]
   }
 
diff --git a/include/vapi/vsc.h b/include/vapi/vsc.h
index e653579..1247deb 100644
--- a/include/vapi/vsc.h
+++ b/include/vapi/vsc.h
@@ -126,13 +126,15 @@ struct VSC_section {
 	struct VSM_fantom *fantom;
 };
 
+/* See include/tbl/vsc_fields.h for descriptions */
 struct VSC_desc {
 	const char *name;		/* field name			*/
-	const char *fmt;		/* field format ("uint64_t")	*/
-	int flag;			/* 'c' = counter, 'g' = gauge	*/
+	const char *ctype;		/* C-type			*/
+	int semantics;			/* semantics			*/
+	int format;			/* display format		*/
+	const struct VSC_level_desc *level; /* verbosity level		*/
 	const char *sdesc;		/* short description		*/
 	const char *ldesc;		/* long description		*/
-	const struct VSC_level_desc *level;
 };
 
 struct VSC_point {
diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c
index 69c39e6..38dd5fb 100644
--- a/lib/libvarnishapi/vsc.c
+++ b/lib/libvarnishapi/vsc.c
@@ -565,7 +565,7 @@ VSC_LevelDesc(unsigned level)
 #undef VSC_TYPE_F
 
 #define VSC_DO(U,l,t)		const struct VSC_desc VSC_desc_##l[] = {
-#define VSC_F(n,t,l,s,f,v,d,e)		{#n,#t,s,d,e,&VSC_level_desc_##v},
+#define VSC_F(n,t,l,s,f,v,d,e)		{#n,#t,s,f,&VSC_level_desc_##v,d,e},
 #define VSC_DONE(U,l,t)		};
 #include "tbl/vsc_all.h"
 #undef VSC_DO



More information about the varnish-commit mailing list