r2182 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Mon Oct 29 10:24:16 CET 2007


Author: phk
Date: 2007-10-29 10:24:16 +0100 (Mon, 29 Oct 2007)
New Revision: 2182

Modified:
   trunk/varnish-cache/bin/varnishd/cache_ws.c
Log:
Add compile-time selectable SHMlogging of WS-activity


Modified: trunk/varnish-cache/bin/varnishd/cache_ws.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_ws.c	2007-10-29 09:16:13 UTC (rev 2181)
+++ trunk/varnish-cache/bin/varnishd/cache_ws.c	2007-10-29 09:24:16 UTC (rev 2182)
@@ -45,11 +45,22 @@
 #include "cli_priv.h"
 #include "cache.h"
 
+/* Enable this to get detailed logging of WS usage */
+#if 0
+#  define WS_DEBUG(foo)	VSL foo
+#else
+#  define WS_DEBUG(foo)	/* nothing */
+#endif
+
 void
 WS_Assert(const struct ws *ws)
 {
 
 	assert(ws != NULL);
+	WS_DEBUG((SLT_Debug, 0, "WS(%p = (%p %u %u %u)",
+	    ws, ws->s, pdiff(ws->s, ws->f),
+	    ws->r == NULL ? 0 : pdiff(ws->f, ws->r),
+	    pdiff(ws->s, ws->e)));
 	assert(ws->s != NULL);
 	assert(ws->e != NULL);
 	assert(ws->s < ws->e);
@@ -65,6 +76,7 @@
 WS_Init(struct ws *ws, void *space, unsigned len)
 {
 
+	WS_DEBUG((SLT_Debug, 0, "WS_Init(%p, %p, %u)", ws, space, len));
 	assert(space != NULL);
 	memset(ws, 0, sizeof *ws);
 	ws->s = space;
@@ -78,6 +90,7 @@
 {
 
 	WS_Assert(ws);
+	WS_DEBUG((SLT_Debug, 0, "WS_Reset(%p, %p)", ws, p));
 	assert(ws->r == NULL);
 	if (p == NULL)
 		ws->f = ws->s;
@@ -99,6 +112,7 @@
 		return(NULL);
 	r = ws->f;
 	ws->f += bytes;
+	WS_DEBUG((SLT_Debug, 0, "WS_Alloc(%p, %u) = %p", ws, bytes, r));
 	return (r);
 }
 
@@ -112,6 +126,7 @@
 	p = WS_Alloc(ws, l);
 	if (p != NULL)
 		memcpy(p, s, l);
+	WS_DEBUG((SLT_Debug, 0, "WS_Dup(%p, \"%s\") = %p", ws, s, p));
 	return (p);
 }
 
@@ -119,26 +134,33 @@
 WS_Snapshot(struct ws *ws)
 {
 
+	WS_Assert(ws);
 	assert(ws->r == NULL);
+	WS_DEBUG((SLT_Debug, 0, "WS_Snapshot(%p) = %p", ws, ws->f));
 	return (ws->f);
 }
 
 unsigned
 WS_Reserve(struct ws *ws, unsigned bytes)
 {
+	unsigned b2 = bytes;
+
 	WS_Assert(ws);
 	assert(ws->r == NULL);
 	if (bytes == 0)
-		bytes = ws->e - ws->f;
-	xxxassert(ws->f + bytes <= ws->e);
-	ws->r = ws->f + bytes;
-	return (ws->r - ws->f);
+		b2 = ws->e - ws->f;
+	xxxassert(ws->f + b2 <= ws->e);
+	ws->r = ws->f + b2;
+	WS_DEBUG((SLT_Debug, 0, "WS_Reserve(%p, %u/%u) = %u",
+	    ws, b2, bytes, pdiff(ws->f, ws->r)));
+	return (pdiff(ws->f, ws->r));
 }
 
 void
 WS_Release(struct ws *ws, unsigned bytes)
 {
 	WS_Assert(ws);
+	WS_DEBUG((SLT_Debug, 0, "WS_Release(%p, %u)", ws, bytes));
 	assert(ws->r != NULL);
 	assert(ws->f + bytes <= ws->r);
 	ws->f += bytes;
@@ -149,6 +171,7 @@
 WS_ReleaseP(struct ws *ws, char *ptr)
 {
 	WS_Assert(ws);
+	WS_DEBUG((SLT_Debug, 0, "WS_ReleaseP(%p, %p)", ws, ptr));
 	assert(ws->r != NULL);
 	assert(ptr >= ws->f);
 	assert(ptr <= ws->r);




More information about the varnish-commit mailing list