--------------------- PatchSet 10201 Date: 2007/12/09 04:55:21 Author: adri Branch: s27_adri Tag: (none) Log: add in some basic statistics so I can gauge how effective this refcounted string thing is being. Members: libbuf/String.c:1.1.2.4->1.1.2.5 libbuf/String.h:1.1.2.4->1.1.2.5 src/String.c:1.7.44.1->1.7.44.2 src/main.c:1.80.2.1.4.3->1.80.2.1.4.4 src/protos.h:1.146.2.4.4.5->1.146.2.4.4.6 Index: squid/libbuf/String.c =================================================================== RCS file: /cvsroot/squid-sf//squid/libbuf/Attic/String.c,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- squid/libbuf/String.c 6 Dec 2007 06:34:38 -0000 1.1.2.4 +++ squid/libbuf/String.c 9 Dec 2007 04:55:21 -0000 1.1.2.5 @@ -1,6 +1,6 @@ /* - * $Id: String.c,v 1.1.2.4 2007/12/06 06:34:38 adri Exp $ + * $Id: String.c,v 1.1.2.5 2007/12/09 04:55:21 adri Exp $ * * DEBUG: section 67 String * AUTHOR: Duane Wessels @@ -47,6 +47,8 @@ const String StringNull = { 0, NULL }; +stringStatsStruct stringStats = { 0, 0, 0, 0, 0 }; + static void stringInitBuf(String * s, size_t sz) { @@ -71,7 +73,7 @@ if (src == NULL) *s = StringNull; else - stringLimitInit(s, strBuf(*src), strLen(*src)); + *s = stringDup(src); } void @@ -84,6 +86,7 @@ //printf("len: %d, buflen: %d, size %d\n", len, buf_len(s->nb), s->nb->size); a = buf_put_chr(s->nb, len, '\0'); assert(a); + stringStats.create++; s->len = len; } @@ -92,6 +95,7 @@ { String dup = StringNull; assert(s); + stringStats.dup++; dup.len = s->len; dup.nb = buf_ref(s->nb); return dup; @@ -104,6 +108,7 @@ if (s->nb) s->nb = buf_deref(s->nb); *s = StringNull; + stringStats.clean++; } void @@ -111,6 +116,7 @@ { stringClean(s); stringInit(s, str); + stringStats.reset++; } void @@ -144,6 +150,7 @@ return; debug(1, 1) ("stringMakePrivate: making %p private (%s)\n", s, strBuf(*s)); + stringStats.make_private++; /* If the reference count is >1 then we create a duplicate and deref the old one */ assert(buf_refcnt(s->nb) > 1); Index: squid/libbuf/String.h =================================================================== RCS file: /cvsroot/squid-sf//squid/libbuf/Attic/String.h,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- squid/libbuf/String.h 6 Dec 2007 06:25:37 -0000 1.1.2.4 +++ squid/libbuf/String.h 9 Dec 2007 04:55:21 -0000 1.1.2.5 @@ -89,6 +89,14 @@ extern void stringAppend(String * s, const char *buf, int len); /* extern void stringAppendf(String *s, const char *fmt, ...) PRINTF_FORMAT_ARG2; */ +typedef struct { + int create, reset, clean, dup, make_private; +} stringStatsStruct; + +extern stringStatsStruct stringStats; + + + extern const String StringNull; /* { 0, 0, NULL } */ #endif /* __LIBBUF_STRING__H_ */ Index: squid/src/String.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/String.c,v retrieving revision 1.7.44.1 retrieving revision 1.7.44.2 diff -u -r1.7.44.1 -r1.7.44.2 --- squid/src/String.c 3 Dec 2007 07:59:25 -0000 1.7.44.1 +++ squid/src/String.c 9 Dec 2007 04:55:21 -0000 1.7.44.2 @@ -1,6 +1,6 @@ /* - * $Id: String.c,v 1.7.44.1 2007/12/03 07:59:25 adri Exp $ + * $Id: String.c,v 1.7.44.2 2007/12/09 04:55:21 adri Exp $ * * DEBUG: section 67 String * AUTHOR: Duane Wessels @@ -32,3 +32,29 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. * */ + +/* Squid-specific string statistics */ + +#include "squid.h" + +static void +stringStatsOutput(StoreEntry *e) +{ + storeBuffer(e); + + storeAppendPrintf(e, "Create: %d\n", stringStats.create); + storeAppendPrintf(e, "Reset: %d\n", stringStats.reset); + storeAppendPrintf(e, "Clean: %d\n", stringStats.clean); + storeAppendPrintf(e, "Dup: %d\n", stringStats.dup); + storeAppendPrintf(e, "Copy-On-Modify: %d\n", stringStats.make_private); + + storeBufferFlush(e); +} + +void +stringStatsInit(void) +{ + cachemgrRegister("strings", "String Statistics", stringStatsOutput, 0, 1); +} + + Index: squid/src/main.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/main.c,v retrieving revision 1.80.2.1.4.3 retrieving revision 1.80.2.1.4.4 diff -u -r1.80.2.1.4.3 -r1.80.2.1.4.4 --- squid/src/main.c 6 Dec 2007 08:10:26 -0000 1.80.2.1.4.3 +++ squid/src/main.c 9 Dec 2007 04:55:21 -0000 1.80.2.1.4.4 @@ -1,6 +1,6 @@ /* - * $Id: main.c,v 1.80.2.1.4.3 2007/12/06 08:10:26 adri Exp $ + * $Id: main.c,v 1.80.2.1.4.4 2007/12/09 04:55:21 adri Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -828,6 +828,7 @@ WIN32_svcstatusupdate(SERVICE_START_PENDING, 10000); #endif mainInitialize(); + stringStatsInit(); #if defined(USE_WIN32_SERVICE) && defined(_SQUID_WIN32_) WIN32_svcstatusupdate(SERVICE_RUNNING, 0); Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.146.2.4.4.5 retrieving revision 1.146.2.4.4.6 diff -u -r1.146.2.4.4.5 -r1.146.2.4.4.6 --- squid/src/protos.h 6 Dec 2007 08:10:26 -0000 1.146.2.4.4.5 +++ squid/src/protos.h 9 Dec 2007 04:55:21 -0000 1.146.2.4.4.6 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.146.2.4.4.5 2007/12/06 08:10:26 adri Exp $ + * $Id: protos.h,v 1.146.2.4.4.6 2007/12/09 04:55:21 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1421,5 +1421,8 @@ extern void clientStoreURLRewriteStart(clientHttpRequest * http); extern void clientStoreURLRewriteDone(void *data, char *result); +/* String.c */ +extern void StringStatsInit(void); + #endif /* SQUID_PROTOS_H */