This is a multi-part message in MIME format.
--------------327EE5C51299041E64A2DEAB
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
------------------------------------------------------------------
Squid-1.2.beta13: Detailed tracing of memory allocations
Extend the memory counting to full a full trace, and change
some malloc/calloc/free to x-variants.
------------------------------------------------------------------
This patch extends the xmalloc counting show a full trace of memory
allocations. Enabled by configure --enable-xmalloc-debug-trace (replaces
xmalloc-debug-count)
Example:
+0x8685a00 size= 12/212639 acc= 0/178176 mallinfo= 16/229228
disk.c:143 xmalloc 196
-0x8685a00 size= -12/212627 acc= 0/178176 mallinfo= -56/229228
disk.c:195 xfree (195 disk.c:143)
+/- == allocatin/free
size = size/total of allocated memory
acc = delta/totat of accounted memory
mallinfo = delta/total as reported by mallinfo
sourcefile:line function
Allocations are followed by their number. Each allocation gets a unique
increasing number.
Free operations are followed by the allocation number and source
location.
My tuned-down 1.2b13 installation does 10100 memory allocations at
startup from a empty cache. 8000 of them is for calling storeCleanup.
/Henrik
--------------327EE5C51299041E64A2DEAB
Content-Type: text/plain; charset=us-ascii; name="squid-1.2.beta13.memory_tracing.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="squid-1.2.beta13.memory_tracing.patch"
Index: squid/acconfig.h
diff -u squid/acconfig.h:1.1.1.5 squid/acconfig.h:1.1.1.5.8.1
--- squid/acconfig.h:1.1.1.5 Wed Jan 7 03:51:13 1998
+++ squid/acconfig.h Fri Feb 6 00:57:46 1998
@@ -50,7 +50,7 @@
#undef XMALLOC_STATISTICS
/* Define to have a detailed trace of memory allocations */
-#undef XMALLOC_COUNT
+#undef XMALLOC_TRACE
/* Define to use async disk I/O operations */
#undef USE_ASYNC_IO
Index: squid/configure.in
diff -u squid/configure.in:1.1.1.8 squid/configure.in:1.1.1.8.4.1
--- squid/configure.in:1.1.1.8 Thu Feb 5 22:44:45 1998
+++ squid/configure.in Fri Feb 6 00:57:49 1998
@@ -194,12 +194,13 @@
fi
])
-AC_ARG_ENABLE(xmalloc_debug_count,
-[ --enable-xmalloc-debug-count
+AC_ARG_ENABLE(xmalloc_debug_trace,
+[ --enable-xmalloc-debug-trace
Detailed trace of memory allocations],
[ if test "$enableval" = "yes" ; then
- echo "Malloc tracing enabled"
- AC_DEFINE(XMALLOC_COUNT)
+ echo "Malloc debug trace enabled"
+ AC_DEFINE(XMALLOC_TRACE)
+ AC_DEFINE(XMALLOC_DEBUG)
fi
])
Index: squid/include/autoconf.h.in
diff -u squid/include/autoconf.h.in:1.1.1.4 squid/include/autoconf.h.in:1.1.1.4.4.1
--- squid/include/autoconf.h.in:1.1.1.4 Thu Feb 5 22:44:50 1998
+++ squid/include/autoconf.h.in Fri Feb 6 00:58:30 1998
@@ -81,7 +81,7 @@
#undef XMALLOC_STATISTICS
/* Define to have a detailed trace of memory allocations */
-#undef XMALLOC_COUNT
+#undef XMALLOC_TRACE
/* Define to use async disk I/O operations */
#undef USE_ASYNC_IO
Index: squid/include/util.h
diff -u squid/include/util.h:1.1.1.5 squid/include/util.h:1.1.1.5.10.1
--- squid/include/util.h:1.1.1.5 Fri Jan 2 11:57:57 1998
+++ squid/include/util.h Fri Feb 6 00:58:32 1998
@@ -154,6 +154,18 @@
void malloc_statistics(void (*)(int, int, void *), void *);
#endif
+#if XMALLOC_TRACE
+#define xmalloc(size) (xmalloc_func="xmalloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xmalloc(size))
+#define xfree(ptr) (xmalloc_func="xfree",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xfree(ptr))
+#define xxfree(ptr) (xmalloc_func="xxfree",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xxfree(ptr))
+#define xrealloc(ptr,size) (xmalloc_func="xrealloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xrealloc(ptr,size))
+#define xcalloc(n,size) (xmalloc_func="xcalloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xcalloc(n,size))
+#define xstrdup(ptr) (xmalloc_func="xstrdup",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xstrdup(ptr))
+extern int xmalloc_line;
+extern char *xmalloc_file;
+extern char *xmalloc_func;
+#endif
+
typedef struct in_addr SIA;
extern int safe_inet_addr(const char *, SIA *);
extern time_t parse_iso3307_time(const char *buf);
Index: squid/lib/util.c
diff -u squid/lib/util.c:1.1.1.6 squid/lib/util.c:1.1.1.6.4.1
--- squid/lib/util.c:1.1.1.6 Thu Feb 5 22:44:55 1998
+++ squid/lib/util.c Fri Feb 6 00:58:47 1998
@@ -174,11 +174,29 @@
+#if XMALLOC_TRACE
+char *xmalloc_file="";
+int xmalloc_line=0;
+char *xmalloc_func="";
+static int xmalloc_count=0;
+#undef xmalloc
+#undef xfree
+#undef xxfree
+#undef xrealloc
+#undef xcalloc
+#undef xstrdup
+#endif
+
#if XMALLOC_DEBUG
#define DBG_ARRY_SZ (1<<10)
#define DBG_ARRY_BKTS (1<<8)
static void *malloc_ptrs[DBG_ARRY_BKTS][DBG_ARRY_SZ];
static int malloc_size[DBG_ARRY_BKTS][DBG_ARRY_SZ];
+#if XMALLOC_TRACE
+static void *malloc_file[DBG_ARRY_BKTS][DBG_ARRY_SZ];
+static int malloc_line[DBG_ARRY_BKTS][DBG_ARRY_SZ];
+static int malloc_count[DBG_ARRY_BKTS][DBG_ARRY_SZ];
+#endif
static int dbg_initd = 0;
static int B = 0;
static int I = 0;
@@ -192,6 +210,11 @@
for (I = 0; I < DBG_ARRY_SZ; I++) {
malloc_ptrs[B][I] = NULL;
malloc_size[B][I] = 0;
+#if XMALLOC_TRACE
+ malloc_file[B][I] = NULL;
+ malloc_line[B][I] = 0;
+ malloc_count[B][I] = 0;
+#endif
}
}
dbg_initd = 1;
@@ -206,6 +229,11 @@
continue;
malloc_ptrs[B][I] = NULL;
malloc_size[B][I] = 0;
+#if XMALLOC_TRACE
+ malloc_file[B][I] = NULL;
+ malloc_line[B][I] = 0;
+ malloc_count[B][I] = 0;
+#endif
break;
}
if (I == DBG_ARRY_SZ) {
@@ -235,6 +263,11 @@
continue;
malloc_ptrs[B][I] = p;
malloc_size[B][I] = (int) sz;
+#if XMALLOC_TRACE
+ malloc_file[B][I] = xmalloc_file;
+ malloc_line[B][I] = xmalloc_line;
+ malloc_count[B][I] = xmalloc_count;
+#endif
break;
}
if (I == DBG_ARRY_SZ)
@@ -242,7 +275,7 @@
}
#endif
-#if XMALLOC_COUNT && !HAVE_MALLOCBLKSIZE
+#if XMALLOC_TRACE && !HAVE_MALLOCBLKSIZE
int
mallocblksize(void *p)
{
@@ -255,9 +288,39 @@
}
#endif
-#ifdef XMALLOC_COUNT
+#ifdef XMALLOC_TRACE
+static char *
+malloc_file_name(void *p)
+{
+ B = (((int) p) >> 4) & 0xFF;
+ for (I = 0; I < DBG_ARRY_SZ; I++) {
+ if (malloc_ptrs[B][I] == p)
+ return malloc_file[B][I];
+ }
+ return 0;
+}
+int
+malloc_line_number(void *p)
+{
+ B = (((int) p) >> 4) & 0xFF;
+ for (I = 0; I < DBG_ARRY_SZ; I++) {
+ if (malloc_ptrs[B][I] == p)
+ return malloc_line[B][I];
+ }
+ return 0;
+}
+int
+malloc_number(void *p)
+{
+ B = (((int) p) >> 4) & 0xFF;
+ for (I = 0; I < DBG_ARRY_SZ; I++) {
+ if (malloc_ptrs[B][I] == p)
+ return malloc_count[B][I];
+ }
+ return 0;
+}
static void
-xmalloc_count(void *p, int sign)
+xmalloc_trace(void *p, int sign)
{
int statMemoryAccounted();
static size_t last_total = 0, last_accounted = 0, last_mallinfo = 0;
@@ -268,16 +331,23 @@
static size_t total = 0;
sz = mallocblksize(p) * sign;
total += sz;
- fprintf(stderr, "xmalloc_count=%7d/%9d accounted=%7d/%9d mallinfo=%7d%9d\n",
+ xmalloc_count += sign>0;
+ fprintf(stderr, "%c%8p size=%5d/%d acc=%5d/%d mallinfo=%5d/%d %s:%d %s",
+ sign>0 ? '+':'-',p,
(int) total - last_total, (int) total,
(int) accounted - last_accounted, (int) accounted,
- (int) mi - last_mallinfo, (int) mi);
+ (int) mi - last_mallinfo, (int) mi,
+ xmalloc_file, xmalloc_line, xmalloc_func);
+ if (sign<0)
+ fprintf(stderr," (%d %s:%d)\n",malloc_number(p),malloc_file_name(p),malloc_line_number(p));
+ else
+ fprintf(stderr," %d\n",xmalloc_count);
last_total = total;
last_accounted = accounted;
last_mallinfo = mi;
}
-#endif /* XMALLOC_COUNT */
+#endif /* XMALLOC_TRACE */
/*
* xmalloc() - same as malloc(3). Used for portability.
@@ -306,8 +376,8 @@
#if XMALLOC_STATISTICS
malloc_stat(sz);
#endif
-#if XMALLOC_COUNT
- xmalloc_count(p, 1);
+#if XMALLOC_TRACE
+ xmalloc_trace(p, 1);
#endif
return (p);
}
@@ -318,8 +388,8 @@
void
xfree(void *s)
{
-#if XMALLOC_COUNT
- xmalloc_count(s, -1);
+#if XMALLOC_TRACE
+ xmalloc_trace(s, -1);
#endif
#if XMALLOC_DEBUG
check_free(s);
@@ -332,8 +402,8 @@
void
xxfree(void *s)
{
-#if XMALLOC_COUNT
- xmalloc_count(s, -1);
+#if XMALLOC_TRACE
+ xmalloc_trace(s, -1);
#endif
#if XMALLOC_DEBUG
check_free(s);
@@ -350,8 +420,8 @@
{
static void *p;
-#if XMALLOC_COUNT
- xmalloc_count(s, -1);
+#if XMALLOC_TRACE
+ xmalloc_trace(s, -1);
#endif
if (sz < 1)
@@ -372,8 +442,8 @@
#if XMALLOC_STATISTICS
malloc_stat(sz);
#endif
-#if XMALLOC_COUNT
- xmalloc_count(p, 1);
+#if XMALLOC_TRACE
+ xmalloc_trace(p, 1);
#endif
return (p);
}
@@ -407,8 +477,8 @@
#if XMALLOC_STATISTICS
malloc_stat(sz);
#endif
-#if XMALLOC_COUNT
- xmalloc_count(p, 1);
+#if XMALLOC_TRACE
+ xmalloc_trace(p, 1);
#endif
return (p);
}
Index: squid/snmplib/parse.c
diff -u squid/snmplib/parse.c:1.1.1.4 squid/snmplib/parse.c:1.1.1.4.8.1
--- squid/snmplib/parse.c:1.1.1.4 Wed Jan 7 03:51:26 1998
+++ squid/snmplib/parse.c Fri Feb 6 00:59:13 1998
@@ -524,11 +524,11 @@
oldnp = NULL;
for (np = child_list; np; np = np->next) {
if (oldnp)
- free(oldnp);
+ xfree(oldnp);
oldnp = np;
}
if (oldnp)
- free(oldnp);
+ xfree(oldnp);
}
@@ -601,9 +601,9 @@
while (ep) {
tep = ep;
ep = ep->next;
- free((char *) tep);
+ xfree((char *) tep);
}
- free((char *) np);
+ xfree((char *) np);
}
/*
@@ -686,7 +686,7 @@
/* free the oid array */
for (count = 0, op = oid; count < length; count++, op++) {
if (op->label)
- free(op->label);
+ xfree(op->label);
op->label = 0;
}
return root;
@@ -1130,7 +1130,7 @@
/* free oid array */
for (count = 0; count < length; count++) {
if (oid[count].label)
- free(oid[count].label);
+ xfree(oid[count].label);
oid[count].label = 0;
}
return np;
@@ -1196,7 +1196,7 @@
/* free oid array */
for (count = 0; count < length; count++) {
if (oid[count].label)
- free(oid[count].label);
+ xfree(oid[count].label);
oid[count].label = 0;
}
return np;
@@ -1261,7 +1261,7 @@
/* free oid array */
for (count = 0; count < length; count++) {
if (oid[count].label)
- free(oid[count].label);
+ xfree(oid[count].label);
oid[count].label = 0;
}
return np;
@@ -1307,7 +1307,7 @@
/* free oid array */
for (count = 0; count < length; count++) {
if (oid[count].label)
- free(oid[count].label);
+ xfree(oid[count].label);
oid[count].label = 0;
}
return np;
@@ -1355,7 +1355,7 @@
/* free oid array */
for (count = 0; count < length; count++) {
if (oid[count].label)
- free(oid[count].label);
+ xfree(oid[count].label);
oid[count].label = 0;
}
return np;
Index: squid/snmplib/snmp_api.c
diff -u squid/snmplib/snmp_api.c:1.1.1.5 squid/snmplib/snmp_api.c:1.1.1.5.8.1
--- squid/snmplib/snmp_api.c:1.1.1.5 Wed Jan 7 03:51:27 1998
+++ squid/snmplib/snmp_api.c Fri Feb 6 00:59:14 1998
@@ -440,7 +440,7 @@
if (orp->pdu != NULL) {
snmp_free_pdu(orp->pdu);
}
- free((char *) orp);
+ xfree((char *) orp);
}
/*
@@ -456,7 +456,7 @@
rp = rp->next_request;
if (orp->pdu != NULL)
snmp_free_pdu(orp->pdu);
- free((char *) orp);
+ xfree((char *) orp);
}
}
@@ -486,15 +486,15 @@
/* If we found the session, free all data associated with it */
if (slp) {
if (slp->session->community != NULL)
- free((char *) slp->session->community);
+ xfree((char *) slp->session->community);
if (slp->session->peername != NULL)
- free((char *) slp->session->peername);
- free((char *) slp->session);
+ xfree((char *) slp->session->peername);
+ xfree((char *) slp->session);
if (slp->internal->sd != -1)
close(slp->internal->sd);
free_request_list(slp->internal->requests);
- free((char *) slp->internal);
- free((char *) slp);
+ xfree((char *) slp->internal);
+ xfree((char *) slp);
} else {
snmp_errno = SNMPERR_BAD_SESSION;
return 0;
@@ -902,19 +902,19 @@
vp = pdu->variables;
while (vp) {
if (vp->name) {
- free((char *) vp->name);
+ xfree((char *) vp->name);
}
if (vp->val.string) {
- free((char *) vp->val.string);
+ xfree((char *) vp->val.string);
}
ovp = vp;
vp = vp->next_variable;
- free((char *) ovp);
+ xfree((char *) ovp);
}
if (pdu->enterprise) {
- free((char *) pdu->enterprise);
+ xfree((char *) pdu->enterprise);
}
- free((char *) pdu);
+ xfree((char *) pdu);
}
Index: squid/snmplib/snmp_client.c
diff -u squid/snmplib/snmp_client.c:1.1.1.3 squid/snmplib/snmp_client.c:1.1.1.3.8.1
--- squid/snmplib/snmp_client.c:1.1.1.3 Wed Jan 7 03:51:27 1998
+++ squid/snmplib/snmp_client.c Fri Feb 6 00:59:15 1998
@@ -129,7 +129,7 @@
if (var->name != NULL) {
newvar->name = xcalloc(1, var->name_length * sizeof(oid));
if (newvar->name == NULL) { /* paranoia */
- free(newvar);
+ xfree(newvar);
return NULL;
}
xmemcpy(newvar->name, var->name, var->name_length * sizeof(oid));
@@ -138,8 +138,8 @@
newvar->val.string = xcalloc(1, var->val_len);
if (newvar->val.string == NULL) { /* paranoia */
if (newvar->name != NULL)
- free(newvar->name);
- free(newvar);
+ xfree(newvar->name);
+ xfree(newvar);
return NULL;
}
xmemcpy(newvar->val.string, var->val.string, var->val_len);
Index: squid/src/cache_cf.c
diff -u squid/src/cache_cf.c:1.1.1.9 squid/src/cache_cf.c:1.1.1.9.4.1
--- squid/src/cache_cf.c:1.1.1.9 Thu Feb 5 22:44:58 1998
+++ squid/src/cache_cf.c Fri Feb 6 00:59:20 1998
@@ -1055,8 +1055,7 @@
static void
free_string(char **var)
{
- xfree(*var);
- *var = NULL;
+ safe_free(*var);
}
static void
Index: squid/src/snmp_config.c
diff -u squid/src/snmp_config.c:1.1.1.6 squid/src/snmp_config.c:1.1.1.6.4.1
--- squid/src/snmp_config.c:1.1.1.6 Thu Feb 5 22:45:08 1998
+++ squid/src/snmp_config.c Fri Feb 6 00:59:22 1998
@@ -81,7 +81,7 @@
break;
}
- new = (viewEntry *) calloc(1, sizeof(viewEntry));
+ new = (viewEntry *) xcalloc(1, sizeof(viewEntry));
memset(new, 0, sizeof(viewEntry));
strcpy(new->viewName, tokens[1]);
@@ -144,7 +144,7 @@
debug(49, 0) ("create_user: user '%s' already defined\n", tokens[1]);
return -1;
}
- new = (usecEntry *) calloc(1, sizeof(usecEntry));
+ new = (usecEntry *) xcalloc(1, sizeof(usecEntry));
if (Config.Snmp.users) {
prev->next = new;
} else {
@@ -254,7 +254,7 @@
return -1;
}
debug(49, 5) ("Adding %s\n", tokens[1]);
- new = (communityEntry *) calloc(1, sizeof(communityEntry));
+ new = (communityEntry *) xcalloc(1, sizeof(communityEntry));
memset(new, 0, sizeof(communityEntry));
strcpy(new->name, tokens[1]);
new->readView = find_view(tokens[2]);
--------------327EE5C51299041E64A2DEAB--
Received on Tue Jul 29 2003 - 13:15:46 MDT
This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:11:42 MST