]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
patch for logging malloc/calloc/free traces to file
authorkostas <>
Fri, 27 Feb 1998 12:51:13 +0000 (12:51 +0000)
committerkostas <>
Fri, 27 Feb 1998 12:51:13 +0000 (12:51 +0000)
configure
configure.in
include/autoconf.h.in
lib/util.c
src/main.cc

index ba5c802fdb9ce32dc7aabe90b3248b61b1ca7ab3..95d0246853befe7e4ba5e913f2c136109bdce742 100755 (executable)
--- 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
index f8dc2356f856ef4795ab4d5974ebc28e11156522..eab456279f949290e7250d515cb53e48c3218d61 100644 (file)
@@ -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
index a31c2fe47b7e47917f0b7b78fa253afbc92ee20f..4192d69784e794e1d550126384bf8f6450343987 100644 (file)
@@ -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
 
index 36350d17a6598e2b4368cfbe3d738b61452bb873..c8bf6f796fa072ae45eb9d794933975ba297060f 100644 (file)
@@ -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);
 }
index 2a835a10e3faba1d882314bbef5d42f7d97feaae..169d69ed6ef02c6fddde789971f5a175c92264ad 100644 (file)
@@ -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);