From: wessels <> Date: Wed, 18 Feb 1998 08:00:43 +0000 (+0000) Subject: From: Henrik Nordstrom X-Git-Tag: SQUID_3_0_PRE1~4073 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ce875eb60c3989a40a4aa5b9ba0da6a815e16dc;p=thirdparty%2Fsquid.git From: Henrik Nordstrom Squid-1.2.beta15: Show memory map as a tree Part of my beta14 memory map patch did not make it into beta15. Here are the missing pieces. --- diff --git a/lib/util.c b/lib/util.c index 6e037ea976..c9a4e26df1 100644 --- a/lib/util.c +++ b/lib/util.c @@ -1,6 +1,6 @@ /* - * $Id: util.c,v 1.42 1998/02/13 18:26:57 wessels Exp $ + * $Id: util.c,v 1.43 1998/02/18 01:00:48 wessels Exp $ * * DEBUG: * AUTHOR: Harvest Derived @@ -355,55 +355,61 @@ xmalloc_show_trace(void *p, int sign) last_accounted = accounted; last_mallinfo = mi; } -short (*malloc_refs)[DBG_ARRY_SZ]; -char **xmalloc_leak_test; -#define XMALLOC_LEAK_CHECKED (1<<15) + +short malloc_refs[DBG_ARRY_BKTS][DBG_ARRY_SZ]; #define XMALLOC_LEAK_ALIGN (4) -static int -xmalloc_scan_region(void *start, int size) +static void +xmalloc_scan_region(void *start, int size, int depth) { int B, I; char *ptr = start; char *end = ptr + size - XMALLOC_LEAK_ALIGN; - int found = 0; + static int sum = 0; while (ptr <= end) { void *p = *(void **) ptr; if (p && p != start) { B = (((int) p) >> 4) & 0xFF; for (I = 0; I < DBG_ARRY_SZ; I++) { if (malloc_ptrs[B][I] == p) { - if (!malloc_refs[B][I]) - found++; - malloc_refs[B][I]++; + if (!malloc_refs[B][I]++) { + /* A new reference */ + fprintf(stderr, "%*s%p %s:%d size %d allocation %d\n", + depth, "", + malloc_ptrs[B][I], malloc_file[B][I], + malloc_line[B][I], malloc_size[B][I], + malloc_count[B][I]); + sum += malloc_size[B][I]; + xmalloc_scan_region(malloc_ptrs[B][I], malloc_size[B][I], depth + 1); + if (depth == 0) { + if (sum != malloc_size[B][I]) + fprintf(stderr, "=== %d bytes\n", sum); + sum = 0; + } +#if XMALLOC_SHOW_ALL_REFERENCES + } else { + /* We have already scanned this pointer... */ + fprintf(stderr, "%*s%p %s:%d size %d allocation %d ... (%d)\n", + depth * 2, "", + malloc_ptrs[B][I], malloc_file[B][I], + malloc_line[B][I], malloc_size[B][I], + malloc_count[B][I], malloc_refs[B][I]); +#endif + } } } } ptr += XMALLOC_LEAK_ALIGN; } - return found; } -extern void _etext; + void xmalloc_find_leaks(void) { int B, I; - int found; int leak_sum = 0; - fprintf(stderr, "Searching for memory references...\n"); - malloc_refs = xcalloc(DBG_ARRY_BKTS, sizeof(*malloc_refs)); - found = xmalloc_scan_region(&_etext, (void *) sbrk(0) - (void *) &_etext); - while (found) { - found = 0; - for (I = 0; I < DBG_ARRY_SZ && !found; I++) { - for (B = 0; B < DBG_ARRY_BKTS; B++) { - if (malloc_refs[B][I] > 0) { - malloc_refs[B][I] |= XMALLOC_LEAK_CHECKED; - found += xmalloc_scan_region(malloc_ptrs[B][I], - malloc_size[B][I]); - } - } - } - } + extern void _etext; + fprintf(stderr, "----- Memory map ----\n"); + xmalloc_scan_region(&_etext, (void *) sbrk(0) - (void *) &_etext, 0); for (B = 0; B < DBG_ARRY_BKTS; B++) { for (I = 0; I < DBG_ARRY_SZ; I++) { if (malloc_ptrs[B][I] && malloc_refs[B][I] == 0) { @@ -411,8 +417,8 @@ xmalloc_find_leaks(void) fprintf(stderr, "Leak found: %p", malloc_ptrs[B][I]); fprintf(stderr, " %s", malloc_file[B][I]); fprintf(stderr, ":%d", malloc_line[B][I]); - fprintf(stderr, " size %d\n", malloc_size[B][I]); - fprintf(stderr, " allocation %d", malloc_count[B][I]); + fprintf(stderr, " size %d", malloc_size[B][I]); + fprintf(stderr, " allocation %d\n", malloc_count[B][I]); leak_sum += malloc_size[B][I]; } } @@ -422,22 +428,6 @@ xmalloc_find_leaks(void) } else { fprintf(stderr, "No memory leaks detected\n"); } -} -void -xmalloc_dump_map(void) -{ - int B, I; - fprintf(stderr, "----- Memory map ----\n"); - for (B = 0; B < DBG_ARRY_BKTS; B++) { - for (I = 0; I < DBG_ARRY_SZ; I++) { - if (malloc_ptrs[B][I]) { - printf("%p %s:%d size %d allocation %d references %d\n", - malloc_ptrs[B][I], malloc_file[B][I], malloc_line[B][I], - malloc_size[B][I], malloc_count[B][I], - malloc_refs[B][I] & (XMALLOC_LEAK_CHECKED - 1)); - } - } - } fprintf(stderr, "----------------------\n"); } #endif /* XMALLOC_TRACE */ diff --git a/src/main.cc b/src/main.cc index 62f108b230..0060381825 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.221 1998/02/17 23:04:04 wessels Exp $ + * $Id: main.cc,v 1.222 1998/02/18 01:00:43 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -749,9 +749,7 @@ normal_shutdown(void) { extern int xmalloc_total; extern void xmalloc_find_leaks(void); - extern void xmalloc_dump_map(void); xmalloc_find_leaks(); - xmalloc_dump_map(); debug(1, 0) ("Memory used after shutdown: %d\n", xmalloc_total); } #endif