From: kostas <> Date: Fri, 27 Feb 1998 12:51:13 +0000 (+0000) Subject: patch for logging malloc/calloc/free traces to file X-Git-Tag: SQUID_3_0_PRE1~3961 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36a97e19531e381006a0b7201d79c65572cce2c3;p=thirdparty%2Fsquid.git patch for logging malloc/calloc/free traces to file --- diff --git a/configure b/configure index ba5c802fdb..95d0246853 100755 --- a/configure +++ b/configure @@ -27,6 +27,9 @@ ac_help="$ac_help ac_help="$ac_help --enable-xmalloc-statistics Show malloc statistics in status page" +ac_help="$ac_help + --enable-mem-gen-trace + Trace memory alloc/free to /tmp/squid.alloc" ac_help="$ac_help --enable-async-io Do ASYNC disk I/O using threads" ac_help="$ac_help @@ -988,6 +991,18 @@ EOF fi +# Check whether --enable-mem-gen-trace or --disable-mem-gen-trace was given. +if test "${enable_mem_gen_trace+set}" = set; then + enableval="$enable_mem_gen_trace" + if test "$enableval" = "yes" ; then + echo "Alloc trace to file enabled" + cat >> confdefs.h <<\EOF +#define MEM_GEN_TRACE 1 +EOF + + fi + +fi # Check whether --enable-async_io or --disable-async_io was given. if test "${enable_async_io+set}" = set; then diff --git a/configure.in b/configure.in index f8dc2356f8..eab456279f 100644 --- a/configure.in +++ b/configure.in @@ -3,13 +3,13 @@ dnl Configuration input file for Squid dnl dnl Duane Wessels, wessels@nlanr.net, February 1996 (autoconf v2.9) dnl -dnl $Id: configure.in,v 1.101 1998/02/21 18:46:31 rousskov Exp $ +dnl $Id: configure.in,v 1.102 1998/02/27 05:51:14 kostas Exp $ dnl dnl dnl AC_INIT(src/main.c) AC_CONFIG_HEADER(include/autoconf.h) -AC_REVISION($Revision: 1.101 $)dnl +AC_REVISION($Revision: 1.102 $)dnl AC_PREFIX_DEFAULT(/usr/local/squid) AC_CONFIG_AUX_DIR(aux) @@ -186,6 +186,7 @@ AC_ARG_ENABLE(acltree, esac ]) + AC_ARG_ENABLE(xmalloc_debug, [ --enable-xmalloc-debug Do some simple malloc debugging], [ if test "$enableval" = "yes" ; then @@ -242,6 +243,14 @@ AC_ARG_ENABLE(delay_hack, fi ]) +AC_ARG_ENABLE(mem-gen-trace, +[ --enable-mem-gen-trace Do trace of memory stuff], +[ if test "$enableval" = "yes" ; then + echo "Memory trace (to file) enabled" + AC_DEFINE(MEM_GEN_TRACE) + fi +]) + AC_ARG_ENABLE(useragent_log, [ --enable-useragent-log Enable logging of User-Agent header], [ if test "$enableval" = "yes" ; then diff --git a/include/autoconf.h.in b/include/autoconf.h.in index a31c2fe47b..4192d69784 100644 --- a/include/autoconf.h.in +++ b/include/autoconf.h.in @@ -83,6 +83,9 @@ /* Define to have a detailed trace of memory allocations */ #undef XMALLOC_TRACE +/* Define to have mem trace to file */ +#undef MEM_GEN_TRACE + /* Define to use async disk I/O operations */ #undef USE_ASYNC_IO diff --git a/lib/util.c b/lib/util.c index 36350d17a6..c8bf6f796f 100644 --- a/lib/util.c +++ b/lib/util.c @@ -1,6 +1,6 @@ /* - * $Id: util.c,v 1.46 1998/02/26 22:16:26 kostas Exp $ + * $Id: util.c,v 1.47 1998/02/27 05:51:15 kostas Exp $ * * DEBUG: * AUTHOR: Harvest Derived @@ -139,6 +139,28 @@ static char msg[128]; extern int sys_nerr; +#if MEM_GEN_TRACE + +static FILE *tracefp; + +void +log_trace_init(char *fn) +{ + tracefp=fopen(fn,"w+"); + if (!tracefp) { + perror("log_trace_init"); + exit(1); + } +} + +void +log_trace_done() +{ + fclose(tracefp); +} + +#endif + #if XMALLOC_STATISTICS #define DBG_MAXSIZE (1024*1024) #define DBG_GRAIN (16) @@ -147,6 +169,7 @@ extern int sys_nerr; static int malloc_sizes[DBG_MAXINDEX + 1]; static int dbg_stat_init = 0; + static void stat_init(void) { @@ -448,6 +471,7 @@ xmalloc(size_t sz) if (sz < 1) sz = 1; + if ((p = malloc(sz)) == NULL) { if (failure_notify) { snprintf(msg, 128, "xmalloc: Unable to allocate %d bytes!\n", @@ -466,6 +490,9 @@ xmalloc(size_t sz) #endif #if XMALLOC_TRACE xmalloc_show_trace(p, 1); +#endif +#if MEM_GEN_TRACE + fprintf(tracefp, "m:%d:%x\n",sz,p); #endif return (p); } @@ -479,11 +506,15 @@ xfree(void *s) #if XMALLOC_TRACE xmalloc_show_trace(s, -1); #endif + #if XMALLOC_DEBUG check_free(s); #endif if (s != NULL) free(s); +#if MEM_GEN_TRACE + fprintf(tracefp,"f:%x\n",s); +#endif } /* xxfree() - like xfree(), but we already know s != NULL */ @@ -497,6 +528,9 @@ xxfree(void *s) check_free(s); #endif free(s); +#if MEM_GEN_TRACE + fprintf(tracefp,"f:%x\n",s); +#endif } /* @@ -567,6 +601,9 @@ xcalloc(int n, size_t sz) #endif #if XMALLOC_TRACE xmalloc_show_trace(p, 1); +#endif +#if MEM_GEN_TRACE + fprintf(tracefp,"c:%d:%d:%x\n", n, sz,p); #endif return (p); } diff --git a/src/main.cc b/src/main.cc index 2a835a10e3..169d69ed6e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.227 1998/02/26 18:00:45 wessels Exp $ + * $Id: main.cc,v 1.228 1998/02/27 05:51:15 kostas Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -132,6 +132,10 @@ static void serverConnectionsOpen(void); static void watch_child(char **); static void setEffectiveUser(void); static void normal_shutdown(void); +#if MEM_GEN_TRACE +extern void log_trace_done(); +extern void log_trace_init(char *); +#endif static void usage(void) @@ -509,11 +513,14 @@ main(int argc, char **argv) int errcount = 0; int n; /* # of GC'd objects */ time_t loop_delay; +#if MEM_GEN_TRACE + log_trace_init("/tmp/squid.alloc"); +#endif debug_log = stderr; if (FD_SETSIZE < Squid_MaxFD) Squid_MaxFD = FD_SETSIZE; - + /* call mallopt() before anything else */ #if HAVE_MALLOPT #ifdef M_GRAIN @@ -755,6 +762,10 @@ normal_shutdown(void) debug(1, 0) ("Memory used after shutdown: %d\n", xmalloc_total); } #endif +#if MEM_GEN_TRACE + log_trace_done(); +#endif + debug(1, 0) ("Squid Cache (Version %s): Exiting normally.\n", version_string); fclose(debug_log);