r580 - in trunk/varnish-cache: bin/varnishd bin/varnishlog include

phk at projects.linpro.no phk at projects.linpro.no
Mon Jul 31 23:49:29 CEST 2006


Author: phk
Date: 2006-07-31 23:49:29 +0200 (Mon, 31 Jul 2006)
New Revision: 580

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
   trunk/varnish-cache/bin/varnishd/cache_http.c
   trunk/varnish-cache/bin/varnishd/cache_response.c
   trunk/varnish-cache/bin/varnishlog/varnishlog.c
   trunk/varnish-cache/include/shmlog_tags.h
Log:
Create three groups of seven SHMlog tags:

	{Rx,Tx,Obj}{Request,Response,Status,URL,Protocol,Header,LostHeader}

And log http header munching accordingly.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-07-31 21:46:32 UTC (rev 579)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-07-31 21:49:29 UTC (rev 580)
@@ -67,7 +67,11 @@
 	char			*e;		/* (E)nd of buffer */
 
 	unsigned char		conds;		/* If-* headers present */
-	unsigned char		objlog;
+	enum httpwhence {
+		HTTP_Rx,
+		HTTP_Tx,
+		HTTP_Obj
+	}			logtag;
 
 	struct http_hdr		hd[MAX_HTTP_HDRS];
 	unsigned		nhd;

Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2006-07-31 21:46:32 UTC (rev 579)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2006-07-31 21:49:29 UTC (rev 580)
@@ -229,7 +229,7 @@
 	 * cache_response.c
 	 */
 	http_ClrHeader(sp->http);
-	sp->http->objlog = 1;	/* log as SLT_ObjHeader */
+	sp->http->logtag = HTTP_Obj;
 	http_CopyResp(sp->fd, sp->http, vc->http);
 	http_FilterHeader(sp->fd, sp->http, vc->http, HTTPH_A_INS);
 	
@@ -244,7 +244,6 @@
 		    "Content-Length: %u", sp->obj->len);
 	} else
 		cls = 0;
-	sp->http->objlog = 0;
 	http_CopyHttp(&sp->obj->http, sp->http);
 
 	if (http_GetHdr(vc->http, H_Connection, &b) && !strcasecmp(b, "close"))
@@ -282,6 +281,8 @@
 	assert(vc != NULL);	/* XXX: handle this */
 	VSL(SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name);
 
+	http_ClrHeader(vc->http);
+	vc->http->logtag = HTTP_Tx;
 	http_GetReq(vc->fd, vc->http, sp->http);
 	http_FilterHeader(vc->fd, vc->http, sp->http, HTTPH_R_FETCH);
 	http_PrintfHeader(vc->fd, vc->http, "X-Varnish: %u", sp->xid);

Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-31 21:46:32 UTC (rev 579)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-31 21:49:29 UTC (rev 580)
@@ -19,12 +19,48 @@
 #include "http_headers.h"
 #undef HTTPH
 
+enum httptag {
+	HTTP_T_Request,
+	HTTP_T_Response,
+	HTTP_T_Status,
+	HTTP_T_URL,
+	HTTP_T_Protocol,
+	HTTP_T_Header,
+	HTTP_T_LostHeader,
+};
+
+#define LOGMTX2(ax, bx) 	\
+	[HTTP_T_##bx] = SLT_##ax##bx
+
+#define LOGMTX1(ax) { 		\
+	LOGMTX2(ax, Request),	\
+	LOGMTX2(ax, Response),	\
+	LOGMTX2(ax, Status),	\
+	LOGMTX2(ax, URL),	\
+	LOGMTX2(ax, Protocol),	\
+	LOGMTX2(ax, Header),	\
+	LOGMTX2(ax, LostHeader)	\
+	}
+
+static enum shmlogtag logmtx[3][7] = {
+	[HTTP_Rx] = LOGMTX1(Rx),
+	[HTTP_Tx] = LOGMTX1(Tx),
+	[HTTP_Obj] = LOGMTX1(Obj)
+};
+
+static enum shmlogtag
+T(struct http *hp, enum httptag t)
+{
+
+	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
+	assert(hp->logtag >= HTTP_Rx && hp->logtag <= HTTP_Obj);
+	assert(t >= HTTP_T_Request && t <= HTTP_T_LostHeader);
+	return (logmtx[hp->logtag][t]);
+}
+
 #define VSLH(ax, bx, cx, dx) \
-	VSLR((ax), (bx), (cx)->hd[(dx)].b, (cx)->hd[(dx)].e);
+	VSLR(T((cx), (ax)), (bx), (cx)->hd[(dx)].b, (cx)->hd[(dx)].e);
 
-#define VSLHT(bx, cx, dx) \
-	VSLH((cx)->objlog ? SLT_ObjHeader : SLT_TxHeader, bx, cx, dx)
-
 /*--------------------------------------------------------------------*/
 
 void
@@ -241,11 +277,11 @@
 		if (hp->nhd < MAX_HTTP_HDRS) {
 			hp->hd[hp->nhd].b = p;
 			hp->hd[hp->nhd].e = q;
-			VSLH(SLT_RxHeader, fd, hp, hp->nhd);
+			VSLH(HTTP_T_Header, fd, hp, hp->nhd);
 			hp->nhd++;
 		} else {
 			VSL_stats->losthdr++;
-			VSLR(SLT_LostHeader, fd, p, q);
+			VSLR(T(hp, HTTP_T_LostHeader), fd, p, q);
 		}
 	}
 	assert(hp->t <= hp->v);
@@ -263,6 +299,8 @@
 	assert(hp->t != NULL);
 	assert(hp->s < hp->t);
 	assert(hp->t <= hp->v);
+	hp->logtag = HTTP_Rx;
+
 	for (p = hp->s ; isspace(*p); p++)
 		continue;
 
@@ -271,7 +309,7 @@
 	for (; isalpha(*p); p++)
 		;
 	hp->hd[HTTP_HDR_REQ].e = p;
-	VSLH(SLT_Request, fd, hp, HTTP_HDR_REQ);
+	VSLH(HTTP_T_Request, fd, hp, HTTP_HDR_REQ);
 	*p++ = '\0';
 
 	/* Next find the URI */
@@ -285,7 +323,7 @@
 	while (!isspace(*p))
 		p++;
 	hp->hd[HTTP_HDR_URL].e = p;
-	VSLH(SLT_URL, fd, hp, HTTP_HDR_URL);
+	VSLH(HTTP_T_URL, fd, hp, HTTP_HDR_URL);
 	if (*p == '\n') {
 		VSLR(SLT_HttpGarbage, fd, hp->s, hp->v);
 		return (400);
@@ -303,7 +341,7 @@
 	while (!isspace(*p))
 		p++;
 	hp->hd[HTTP_HDR_PROTO].e = p;
-	VSLH(SLT_Protocol, fd, hp, HTTP_HDR_PROTO);
+	VSLH(HTTP_T_Protocol, fd, hp, HTTP_HDR_PROTO);
 	if (*p != '\n')
 		*p++ = '\0';
 	while (isspace(*p) && *p != '\n')
@@ -327,6 +365,8 @@
 	assert(hp->t != NULL);
 	assert(hp->s < hp->t);
 	assert(hp->t <= hp->v);
+	hp->logtag = HTTP_Rx;
+
 	for (p = hp->s ; isspace(*p); p++)
 		continue;
 
@@ -335,7 +375,7 @@
 	while (!isspace(*p))
 		p++;
 	hp->hd[HTTP_HDR_PROTO].e = p;
-	VSLH(SLT_Protocol, fd, hp, HTTP_HDR_PROTO);
+	VSLH(HTTP_T_Protocol, fd, hp, HTTP_HDR_PROTO);
 	*p++ = '\0';
 
 	/* Next find the status */
@@ -345,7 +385,7 @@
 	while (!isspace(*p))
 		p++;
 	hp->hd[HTTP_HDR_STATUS].e = p;
-	VSLH(SLT_Status, fd, hp, HTTP_HDR_STATUS);
+	VSLH(HTTP_T_Status, fd, hp, HTTP_HDR_STATUS);
 	*p++ = '\0';
 
 	/* Next find the response */
@@ -359,7 +399,7 @@
 		continue;
 	*q = '\0';
 	hp->hd[HTTP_HDR_RESPONSE].e = q;
-	VSLH(SLT_Response, fd, hp, HTTP_HDR_RESPONSE);
+	VSLH(HTTP_T_Response, fd, hp, HTTP_HDR_RESPONSE);
 	p++;
 
 	return (http_dissect_hdrs(hp, fd, p));
@@ -526,17 +566,17 @@
 /*--------------------------------------------------------------------*/
 
 static void
-http_seth(int fd, struct http *to, unsigned n, enum shmlogtag tag, const char *fm)
+http_seth(int fd, struct http *to, unsigned n, enum httptag tag, const char *fm)
 {
 	assert(n < MAX_HTTP_HDRS);
 	assert(fm != NULL);
 	to->hd[n].b = (void*)(uintptr_t)fm;
-	to->hd[n].e = strchr(fm, '\0');
+	to->hd[n].e = (void*)(uintptr_t)strchr(fm, '\0');
 	VSLH(tag, fd, to, n);
 }
 
 static void
-http_copyh(int fd, struct http *to, struct http *fm, unsigned n, enum shmlogtag tag)
+http_copyh(int fd, struct http *to, struct http *fm, unsigned n, enum httptag tag)
 {
 
 	assert(n < MAX_HTTP_HDRS);
@@ -552,9 +592,9 @@
 
 	CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC);
 	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
-	http_seth(fd, to, HTTP_HDR_REQ, SLT_Request, "GET");
-	http_copyh(fd, to, fm, HTTP_HDR_URL, SLT_URL);
-	http_seth(fd, to, HTTP_HDR_PROTO, SLT_Protocol, "HTTP/1.1");
+	http_seth(fd, to, HTTP_HDR_REQ, HTTP_T_Request, "GET");
+	http_copyh(fd, to, fm, HTTP_HDR_URL, HTTP_T_URL);
+	http_seth(fd, to, HTTP_HDR_PROTO, HTTP_T_Protocol, "HTTP/1.1");
 }
 
 void
@@ -563,9 +603,9 @@
 
 	CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC);
 	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
-	http_copyh(fd, to, fm, HTTP_HDR_REQ, SLT_Request);
-	http_copyh(fd, to, fm, HTTP_HDR_URL, SLT_URL);
-	http_copyh(fd, to, fm, HTTP_HDR_PROTO, SLT_Protocol);
+	http_copyh(fd, to, fm, HTTP_HDR_REQ, HTTP_T_Request);
+	http_copyh(fd, to, fm, HTTP_HDR_URL, HTTP_T_URL);
+	http_copyh(fd, to, fm, HTTP_HDR_PROTO, HTTP_T_Protocol);
 }
 
 
@@ -575,18 +615,18 @@
 
 	CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC);
 	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
-	http_copyh(fd, to, fm, HTTP_HDR_PROTO, SLT_Protocol);
-	http_copyh(fd, to, fm, HTTP_HDR_STATUS, SLT_Status);
-	http_copyh(fd, to, fm, HTTP_HDR_RESPONSE, SLT_Response);
+	http_copyh(fd, to, fm, HTTP_HDR_PROTO, HTTP_T_Protocol);
+	http_copyh(fd, to, fm, HTTP_HDR_STATUS, HTTP_T_Status);
+	http_copyh(fd, to, fm, HTTP_HDR_RESPONSE, HTTP_T_Response);
 }
 
 void
 http_SetResp(int fd, struct http *to, const char *proto, const char *status, const char *response)
 {
 	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
-	http_seth(fd, to, HTTP_HDR_PROTO, SLT_Protocol, proto);
-	http_seth(fd, to, HTTP_HDR_STATUS, SLT_Status, status);
-	http_seth(fd, to, HTTP_HDR_RESPONSE, SLT_Response, response);
+	http_seth(fd, to, HTTP_HDR_PROTO, HTTP_T_Protocol, proto);
+	http_seth(fd, to, HTTP_HDR_STATUS, HTTP_T_Status, status);
+	http_seth(fd, to, HTTP_HDR_RESPONSE, HTTP_T_Response, response);
 }
 
 static void
@@ -600,11 +640,11 @@
 	if (to->nhd < MAX_HTTP_HDRS) {
 		to->hd[to->nhd].b = fm->hd[n].b;
 		to->hd[to->nhd].e = fm->hd[n].e;
-		VSLHT(fd, to, to->nhd);
+		VSLH(HTTP_T_Header, fd, to, to->nhd);
 		to->nhd++;
 	} else  {
 		VSL_stats->losthdr++;
-		VSLH(SLT_LostHeader, fd, fm, n);
+		VSLH(HTTP_T_LostHeader, fd, fm, n);
 	}
 }
 
@@ -645,11 +685,12 @@
 {
 
 	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
-	to->hd[to->nhd].b = (void*)(uintptr_t)hdr;
-	to->hd[to->nhd].e = strchr(hdr, '\0');
-	assert(to->hd[to->nhd].e != NULL);
-	VSLHT(fd, to, to->nhd);
-	to->nhd++;
+	if (to->nhd >= MAX_HTTP_HDRS) {
+		VSL_stats->losthdr++;
+		VSL(T(to, HTTP_T_LostHeader), fd, "%s", hdr);
+		return;
+	}
+	http_seth(fd, to, to->nhd++, HTTP_T_Header, hdr);
 }
 
 /*--------------------------------------------------------------------*/
@@ -666,13 +707,13 @@
 	n = vsnprintf(to->f, l, fmt, ap);
 	if (n + 1 > l || to->nhd >= MAX_HTTP_HDRS) {
 		VSL_stats->losthdr++;
-		VSL(SLT_LostHeader, fd, "%s", to->f);
+		VSL(T(to, HTTP_T_LostHeader), fd, "%s", to->f);
 	} else {
 		assert(to->f < to->e);
 		to->hd[to->nhd].b = to->f;
 		to->hd[to->nhd].e = to->f + n;
 		to->f += n + 1;
-		VSLHT(fd, to, to->nhd);
+		VSLH(HTTP_T_Header, fd, to, to->nhd);
 		to->nhd++;
 	}
 	va_end(ap);

Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c	2006-07-31 21:46:32 UTC (rev 579)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c	2006-07-31 21:49:29 UTC (rev 580)
@@ -82,6 +82,7 @@
 	VSL(SLT_Length, sp->fd, "%u", 0);
 
 	http_ClrHeader(sp->http);
+	sp->http->logtag = HTTP_Tx;
 	http_SetResp(sp->fd, sp->http, "HTTP/1.1", "304", "Not Modified");
 	http_SetHeader(sp->fd, sp->http, "Via: 1.1 varnish");
 	http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u", sp->xid);
@@ -134,6 +135,7 @@
 	VSL(SLT_Length, sp->fd, "%u", sp->obj->len);
 
 	http_ClrHeader(sp->http);
+	sp->http->logtag = HTTP_Tx;
 	http_CopyResp(sp->fd, sp->http, &sp->obj->http);
 	http_FilterHeader(sp->fd, sp->http, &sp->obj->http, HTTPH_A_DELIVER);
 	if (sp->xid != sp->obj->xid)

Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishlog/varnishlog.c	2006-07-31 21:46:32 UTC (rev 579)
+++ trunk/varnish-cache/bin/varnishlog/varnishlog.c	2006-07-31 21:49:29 UTC (rev 580)
@@ -126,7 +126,7 @@
 		else
 			v = 1;
 		break;
-	case SLT_Request:
+	case SLT_RxRequest:
 		if (h_opt && p[1] == 3 && !memcmp(p + 4, "GET", 3))
 			hc[u]++;
 		if (h_opt && p[1] == 4 && !memcmp(p + 4, "HEAD", 4))
@@ -137,7 +137,7 @@
 		xrf[u] = atoi(p + 4);
 		v = 1;
 		break;
-	case SLT_Status:
+	case SLT_RxStatus:
 		if (h_opt && p[1] == 3 && !memcmp(p + 4, "200", 3))
 			hc[u]++;
 		v = 1;

Modified: trunk/varnish-cache/include/shmlog_tags.h
===================================================================
--- trunk/varnish-cache/include/shmlog_tags.h	2006-07-31 21:46:32 UTC (rev 579)
+++ trunk/varnish-cache/include/shmlog_tags.h	2006-07-31 21:49:29 UTC (rev 580)
@@ -24,16 +24,32 @@
 SLTM(HttpGarbage)
 SLTM(ClientAddr)
 SLTM(Backend)
-SLTM(Request)
-SLTM(Response)
 SLTM(Length)
-SLTM(Status)
-SLTM(URL)
-SLTM(Protocol)
+
+SLTM(RxRequest)
+SLTM(RxResponse)
+SLTM(RxStatus)
+SLTM(RxURL)
+SLTM(RxProtocol)
 SLTM(RxHeader)
+SLTM(RxLostHeader)
+
+SLTM(TxRequest)
+SLTM(TxResponse)
+SLTM(TxStatus)
+SLTM(TxURL)
+SLTM(TxProtocol)
 SLTM(TxHeader)
+SLTM(TxLostHeader)
+
+SLTM(ObjRequest)
+SLTM(ObjResponse)
+SLTM(ObjStatus)
+SLTM(ObjURL)
+SLTM(ObjProtocol)
 SLTM(ObjHeader)
-SLTM(LostHeader)
+SLTM(ObjLostHeader)
+
 SLTM(TTL)
 SLTM(VCL_acl)
 SLTM(VCL_call)




More information about the varnish-commit mailing list