/*
- * $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
*/
#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;
}
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);
}
}
#
# 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:
#
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 \
@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)
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 \
@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 =
$(IDENT_ALL_SOURCE) \
$(ESI_ALL_SOURCE) \
ProfStats.cc \
- leakfinder.cc \
+ LeakFinder.cc \
snmp_core.cc \
snmp_agent.cc \
unlinkd.cc \
@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@
@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@