[experimental-ims] 4f610d3 I've spent some time trying to think more clearly about stats counters and it's all a mess.

Geoff Simmons geoff at varnish-cache.org
Mon Jan 9 21:51:56 CET 2012


commit 4f610d3a28939cc2bbc74d4c7100a6613a3d9555
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sun Sep 18 07:58:27 2011 +0000

    I've spent some time trying to think more clearly about stats counters
    and it's all a mess.
    
    Try to get it right, and document in the head-comment what I mean with
    "right".
    
    Goal:  Cleaned up for 3.1

diff --git a/bin/varnishd/cache_session.c b/bin/varnishd/cache_session.c
index 4c01f34..80e8da5 100644
--- a/bin/varnishd/cache_session.c
+++ b/bin/varnishd/cache_session.c
@@ -110,7 +110,7 @@ ses_sm_alloc(void)
 
 	hl = HTTP_estimate(nhttp);
 	l = sizeof *sm + nws + 2 * hl;
-	VSC_C_main->g_sessmem_size = l;
+	VSC_C_main->sessmem_size = l;
 	p = malloc(l);
 	if (p == NULL)
 		return (NULL);
@@ -190,20 +190,20 @@ SES_New(struct worker *wrk, struct sesspool *pp)
 		pp->nsess++;
 		do_alloc = 1;
 	}
-	wrk->stats.c_sessmem_free += pp->dly_free_cnt;
+	wrk->stats.sessmem_free += pp->dly_free_cnt;
 	pp->dly_free_cnt = 0;
 	Lck_Unlock(&pp->mtx);
 	if (do_alloc) {
 		sm = ses_sm_alloc();
 		if (sm != NULL) {
-			wrk->stats.c_sessmem_alloc++;
+			wrk->stats.sessmem_alloc++;
 			sm->pool = pp;
 			ses_setup(sm);
 		} else {
-			wrk->stats.c_sessmem_fail++;
+			wrk->stats.sessmem_fail++;
 		}
 	} else if (sm == NULL) {
-		wrk->stats.c_sessmem_limit++;
+		wrk->stats.sessmem_limit++;
 	}
 	if (sm == NULL)
 		return (NULL);
@@ -325,7 +325,7 @@ SES_Delete(struct sess *sp, const char *reason)
 		free(sm);
 		Lck_Lock(&pp->mtx);
 		if (wrk != NULL)
-			wrk->stats.c_sessmem_free++;
+			wrk->stats.sessmem_free++;
 		else
 			pp->dly_free_cnt++;
 		pp->nsess--;
@@ -335,7 +335,7 @@ SES_Delete(struct sess *sp, const char *reason)
 		ses_setup(sm);
 		Lck_Lock(&pp->mtx);
 		if (wrk != NULL) {
-			wrk->stats.c_sessmem_free += pp->dly_free_cnt;
+			wrk->stats.sessmem_free += pp->dly_free_cnt;
 			pp->dly_free_cnt = 0;
 		}
 		VTAILQ_INSERT_HEAD(&pp->freelist, sm, list);
diff --git a/bin/varnishstat/varnishstat.c b/bin/varnishstat/varnishstat.c
index b5b1e6f..a8b1d5f 100644
--- a/bin/varnishstat/varnishstat.c
+++ b/bin/varnishstat/varnishstat.c
@@ -110,7 +110,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->flag == 'a')
+	if (pt->flag == 'a' || pt->flag == 'c')
 		printf("%12ju %12.2f %s\n", val, val / op->up, pt->desc);
 	else
 		printf("%12ju %12s %s\n", val, ".  ", pt->desc);
diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c
index d0eb001..d0db9f0 100644
--- a/bin/varnishstat/varnishstat_curses.c
+++ b/bin/varnishstat/varnishstat_curses.c
@@ -59,7 +59,7 @@ struct pt {
 	VTAILQ_ENTRY(pt)	next;
 	const volatile uint64_t	*ptr;
 	uint64_t		ref;
-	int			type;
+	int			flag;
 	char			seen;
 	char			*name;
 };
@@ -81,7 +81,7 @@ do_curses_cb(void *priv, const struct VSC_point * const sp)
 
 	pt->ptr = sp->ptr;
 	pt->ref = *pt->ptr;
-	pt->type = sp->flag;
+	pt->flag = sp->flag;
 
 	*buf = '\0';
 	if (strcmp(sp->class, "")) {
@@ -210,13 +210,13 @@ do_curses(struct VSM_data *vd, const struct VSC_C_main *VSC_C_main,
 				line++;
 				if (line >= LINES)
 					break;
-				if (pt->type == 'a') {
+				if (pt->flag == 'a' || pt->flag == 'c') {
 					AC(mvprintw(line, 0,
 					    "%12ju %12.2f %12.2f %s\n",
 					    ju, (ju - (intmax_t)pt->ref)/lt,
 					    ju / up, pt->name));
 					pt->ref = ju;
-				} else if (pt->type == 'b') {
+				} else if (pt->flag == 'b') {
 					AC(mvprintw(line, 0, "  %010.10jx <",
 					    (ju >> 24) & 0xffffffffffLL));
 					for (ch = 0x800000; ch; ch >>= 1)
diff --git a/include/vsc_fields.h b/include/vsc_fields.h
index 79ad315..6f910de 100644
--- a/include/vsc_fields.h
+++ b/include/vsc_fields.h
@@ -26,15 +26,31 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * 3rd argument marks fields for inclusion in the per worker-thread
- * stats structure.
+ * Definition of all shared memory statistics below.
+ *
+ * Fields (n, t, l, f, e, d):
+ *    n - Name:		Field name, in C-source and stats programs
+ *    t - Type:		C-type, uint64_t, unless marked in 'f'
+ *    l - Local:	Local counter in worker thread.
+ *    f - Format: 	Semantics of the value in this field
+ *				'a' - Accumulator (deprecated, use 'c')
+ *				'b' - Bitmap
+ *				'c' - Counter, never decreases.
+ *				'g' - Gauge, goes up and down
+ *				'i' - Integer (deprecated, use 'g')
+ *    e - Explantion:	Short explanation of field (for screen use)
+ *    d - Description:	Long explanation of field (for doc use)
+ *	
+ * -----------------------
+ * NB: Cleanup in progress
+ * -----------------------
+ *
+ * Insufficient attention has caused this to become a swamp of conflicting
+ * conventions, shorthands and general mumbo-jumbo.  I'm trying to clean
+ * it up as I go over the code in other business.
+ *
+ * Please see the sessmem section for how it should look.
  *
- * XXX: We need a much more consistent naming of these fields, this has
- * XXX: turned into a major mess, causing trouble already for backends.
- * XXX:
- * XXX: Please converge on:
- * XXX:		c_* counter	(total bytes ever allocated from sma, "")
- * XXX:		g_* gauge	(presently allocated bytes from sma, "")
  */
 
 /**********************************************************************/
@@ -77,27 +93,27 @@ VSC_F(fetch_304,		uint64_t, 1, 'a', "Fetch no body (304)", "")
  *    see: cache_session.c
  */
 
-VSC_F(g_sessmem_size,		uint64_t, 1, 'i',
+VSC_F(sessmem_size,		uint64_t, 1, 'g',
     "Session mem size",
 	"Bytes of memory allocated for last allocated session."
 )
 
-VSC_F(c_sessmem_alloc,		uint64_t, 1, 'a',
+VSC_F(sessmem_alloc,		uint64_t, 1, 'c',
     "Session mem allocated",
 	"Count of all allocations of session memory."
 )
 
-VSC_F(c_sessmem_free,		uint64_t, 1, 'a',
+VSC_F(sessmem_free,		uint64_t, 1, 'c',
     "Session mem freed",
 	"Count of all frees of session memory."
 )
 
-VSC_F(c_sessmem_fail,		uint64_t, 1, 'a',
+VSC_F(sessmem_fail,		uint64_t, 1, 'c',
     "Session mem alloc failed",
 	"Count of session memory allocation failures."
 )
 
-VSC_F(c_sessmem_limit,		uint64_t, 1, 'a',
+VSC_F(sessmem_limit,		uint64_t, 1, 'c',
     "Session mem alloc limited",
 	"Count of session memory allocations blocked by limit (max_sess)."
 )



More information about the varnish-commit mailing list