From: wessels <> Date: Tue, 22 Nov 2005 05:41:45 +0000 (+0000) Subject: Turned "leakfinder" into something more like C++. X-Git-Tag: SQUID_3_0_PRE4~523 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ba126beee15969a7464e0b59db0ff7a73c1196da;p=thirdparty%2Fsquid.git Turned "leakfinder" into something more like C++. --- diff --git a/src/leakfinder.cc b/src/LeakFinder.cc similarity index 55% rename from src/leakfinder.cc rename to src/LeakFinder.cc index 0afc3c6998..e865640d79 100644 --- a/src/leakfinder.cc +++ b/src/LeakFinder.cc @@ -1,6 +1,6 @@ /* - * $Id: leakfinder.cc,v 1.9 2003/02/21 22:50:09 robertc Exp $ + * $Id: LeakFinder.cc,v 1.1 2005/11/21 22:41:45 wessels Exp $ * * DEBUG: section 45 Callback Data Registry * AUTHOR: Duane Wessels @@ -38,64 +38,49 @@ */ #include "squid.h" +#include "LeakFinder.h" #include "Store.h" -static hash_table *htable = NULL; - -static int leakCount = 0; +/* ========================================================================= */ -typedef struct _ptr +LeakFinderPtr::LeakFinderPtr(void *p , const char *f, const int l) : + file(f), line(l), when(squid_curtime) { - hash_link hash; /* must be first */ - void *key; - - struct _ptr *next; - const char *file; - int line; - time_t when; + key = p; + next = NULL; } -ptr; - -static HASHCMP ptr_cmp; -static HASHHASH ptr_hash; -static OBJH ptrDump; - /* ========================================================================= */ -void -leakInit(void) +LeakFinder::LeakFinder() { - debug(45, 3) ("ptrInit\n"); - htable = hash_create(ptr_cmp, 1 << 8, ptr_hash); + debug(45, 3) ("LeakFinder constructed\n"); + table = hash_create(cmp, 1 << 8, hash); +#if 0 + cachemgrRegister("leaks", "Memory Leak Tracking", - ptrDump, 0, 1); + cachemgr_dump, 0, 1); +#endif } void * -leakAddFL(void *p, const char *file, int line) + +LeakFinder::add + (void *p, const char *file, int line) { - ptr *c; - assert(p); - assert(htable != NULL); - assert(hash_lookup(htable, p) == NULL); - c = (ptr *)xcalloc(1, sizeof(*c)); - c->key = p; - c->file = file; - c->line = line; - c->when = squid_curtime; - hash_join(htable, &c->hash); - leakCount++; + assert(hash_lookup(table, p) == NULL); + LeakFinderPtr *c = new LeakFinderPtr(p, file, line); + hash_join(table, c); + count++; return p; } void * -leakTouchFL(void *p, const char *file, int line) +LeakFinder::touch(void *p, const char *file, int line) { - ptr *c = (ptr *) hash_lookup(htable, p); assert(p); - assert(htable != NULL); + LeakFinderPtr *c = (LeakFinderPtr *) hash_lookup(table, p); assert(c); c->file = file; c->line = line; @@ -104,43 +89,52 @@ leakTouchFL(void *p, const char *file, int line) } void * -leakFreeFL(void *p, const char *file, int line) +LeakFinder::free(void *p, const char *file, int line) { - ptr *c = (ptr *) hash_lookup(htable, p); assert(p); - assert(c != NULL); - hash_remove_link(htable, (hash_link *) c); - leakCount--; - xfree(c); + LeakFinderPtr *c = (LeakFinderPtr *) hash_lookup(table, p); + assert(c); + hash_remove_link(table, c); + count--; + delete c; + dump(); return p; } /* ========================================================================= */ -static int -ptr_cmp(const void *p1, const void *p2) +int +LeakFinder::cmp(const void *p1, const void *p2) { return (char *) p1 - (char *) p2; } -static unsigned int -ptr_hash(const void *p, unsigned int mod) +unsigned int +LeakFinder::hash(const void *p, unsigned int mod) { return ((unsigned long) p >> 8) % mod; } -static void -ptrDump(StoreEntry * sentry) +void +LeakFinder::dump() { - hash_link *hptr; - ptr *c; - storeAppendPrintf(sentry, "Tracking %d pointers\n", leakCount); - hash_first(htable); - - while ((hptr = (hash_link *)hash_next(htable))) { - c = (ptr *) hptr; - storeAppendPrintf(sentry, "%20p last used %9d seconds ago by %s:%d\n", - c->key, (int)(squid_curtime - c->when), c->file, c->line); + if (0 == count) + return; + + if (squid_curtime == last_dump) + return; + + last_dump = squid_curtime; + + debug(45,1)("Tracking %d pointers\n", count); + + hash_first(table); + + LeakFinderPtr *c; + + while ((c = (LeakFinderPtr *)hash_next(table))) { + debug(45,1)("%20p last used %9d seconds ago by %s:%d\n", + c->key, (int)(squid_curtime - c->when), c->file, c->line); } } diff --git a/src/Makefile.am b/src/Makefile.am index f25c921ec7..4c142d4785 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.am,v 1.116 2005/11/05 21:56:27 serassio Exp $ +# $Id: Makefile.am,v 1.117 2005/11/21 22:41:45 wessels Exp $ # # Uncomment and customize the following to suit your needs: # @@ -103,7 +103,7 @@ HTCPSOURCE = htcp.cc htcp.h endif if MAKE_LEAKFINDER -LEAKFINDERSOURCE = leakfinder.cc +LEAKFINDERSOURCE = LeakFinder.cc else LEAKFINDERSOURCE = endif @@ -249,7 +249,7 @@ EXTRA_squid_SOURCES = \ $(IDENT_ALL_SOURCE) \ $(ESI_ALL_SOURCE) \ ProfStats.cc \ - leakfinder.cc \ + LeakFinder.cc \ snmp_core.cc \ snmp_agent.cc \ unlinkd.cc \ diff --git a/src/Makefile.in b/src/Makefile.in index 6d70e6556a..d164e417fb 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -17,7 +17,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.in,v 1.353 2005/11/06 01:11:39 hno Exp $ +# $Id: Makefile.in,v 1.354 2005/11/21 22:41:45 wessels Exp $ # # Uncomment and customize the following to suit your needs: # @@ -194,7 +194,7 @@ am__squid_SOURCES_DIST = access_log.cc AccessLogEntry.h acl.cc ACL.h \ HttpMsg.cc HttpMsg.h HttpReply.cc HttpReply.h HttpRequest.cc \ HttpRequest.h HttpVersion.h icmp.cc ICP.h icp_v2.cc icp_v3.cc \ ACLIdent.cc ACLIdent.h ident.cc int.cc internal.cc ipc.cc \ - ipcache.cc IPInterception.cc IPInterception.h leakfinder.cc \ + ipcache.cc IPInterception.cc IPInterception.h LeakFinder.cc \ list.cc logfile.cc main.cc mem.cc mem_node.cc mem_node.h Mem.h \ MemBuf.cc MemObject.cc MemObject.h mime.cc multicast.cc \ neighbors.cc net_db.cc Packer.cc Parsing.cc Parsing.h \ @@ -253,7 +253,7 @@ am__objects_8 = ESI.$(OBJEXT) ESIAssign.$(OBJEXT) ESIContext.$(OBJEXT) \ @ENABLE_HTCP_TRUE@am__objects_10 = htcp.$(OBJEXT) am__objects_11 = ACLIdent.$(OBJEXT) ident.$(OBJEXT) @ENABLE_IDENT_TRUE@am__objects_12 = $(am__objects_11) -@MAKE_LEAKFINDER_TRUE@am__objects_13 = leakfinder.$(OBJEXT) +@MAKE_LEAKFINDER_TRUE@am__objects_13 = LeakFinder.$(OBJEXT) @ENABLE_XPROF_STATS_TRUE@am__objects_14 = ProfStats.$(OBJEXT) @USE_SNMP_TRUE@am__objects_15 = snmp_core.$(OBJEXT) \ @USE_SNMP_TRUE@ snmp_agent.$(OBJEXT) @@ -422,7 +422,7 @@ am__ufsdump_SOURCES_DIST = debug.cc int.cc ufsdump.cc store.cc \ HttpBody.cc HttpMsg.cc HttpReply.cc HttpRequest.cc \ HttpRequest.h icmp.cc icp_v2.cc icp_v3.cc ACLIdent.cc \ ACLIdent.h ident.cc internal.cc ipc.cc ipcache.cc \ - IPInterception.cc IPInterception.h leakfinder.cc list.cc \ + IPInterception.cc IPInterception.h LeakFinder.cc list.cc \ logfile.cc mem.cc mem_node.cc mem_node.h Mem.h MemBuf.cc \ MemObject.cc MemObject.h mime.cc multicast.cc neighbors.cc \ net_db.cc Packer.cc Parsing.cc ProfStats.cc pconn.cc \ @@ -815,7 +815,7 @@ ESI_ALL_SOURCE = \ @ENABLE_XPROF_STATS_TRUE@XPROF_STATS_SOURCE = ProfStats.cc @ENABLE_HTCP_TRUE@HTCPSOURCE = htcp.cc htcp.h @MAKE_LEAKFINDER_FALSE@LEAKFINDERSOURCE = -@MAKE_LEAKFINDER_TRUE@LEAKFINDERSOURCE = leakfinder.cc +@MAKE_LEAKFINDER_TRUE@LEAKFINDERSOURCE = LeakFinder.cc @ENABLE_UNLINKD_FALSE@UNLINKDSOURCE = @ENABLE_UNLINKD_TRUE@UNLINKDSOURCE = unlinkd.cc @ENABLE_UNLINKD_FALSE@UNLINKD = @@ -904,7 +904,7 @@ EXTRA_squid_SOURCES = \ $(IDENT_ALL_SOURCE) \ $(ESI_ALL_SOURCE) \ ProfStats.cc \ - leakfinder.cc \ + LeakFinder.cc \ snmp_core.cc \ snmp_agent.cc \ unlinkd.cc \ @@ -2210,6 +2210,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HttpRequest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HttpStatusLine.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/IPInterception.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LeakFinder.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MemBuf.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MemObject.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NullDelayId.Po@am__quote@ @@ -2278,7 +2279,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/internal.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipc.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipcache.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/leakfinder.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/logfile.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ diff --git a/src/main.cc b/src/main.cc index f16f7b5959..31c6dcd017 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.413 2005/08/25 19:31:22 wessels Exp $ + * $Id: main.cc,v 1.414 2005/11/21 22:41:45 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -989,12 +989,6 @@ main(int argc, char **argv) assert(!configured_once); -#if USE_LEAKFINDER - - leakInit(); - -#endif - Mem::Init(); cbdataInit(); diff --git a/src/squid.h b/src/squid.h index 0e922721ee..074a3908ad 100644 --- a/src/squid.h +++ b/src/squid.h @@ -1,6 +1,6 @@ /* - * $Id: squid.h,v 1.247 2005/07/03 15:25:08 serassio Exp $ + * $Id: squid.h,v 1.248 2005/11/21 22:41:45 wessels Exp $ * * AUTHOR: Duane Wessels * @@ -302,16 +302,6 @@ SQUIDCEXTERN size_t getpagesize(void); #define LOCAL_ARRAY(type,name,size) static type name[size] #endif -#if USE_LEAKFINDER -#define leakAdd(p) leakAddFL(p,__FILE__,__LINE__) -#define leakTouch(p) leakTouchFL(p,__FILE__,__LINE__) -#define leakFree(p) leakFreeFL(p,__FILE__,__LINE__) -#else -#define leakAdd(p) p -#define leakTouch(p) p -#define leakFree(p) p -#endif - #if defined(_SQUID_NEXT_) && !defined(S_ISDIR) #define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR)) #endif