Look for mallinfo() and use it to display
authorMartin Pool <mbp@samba.org>
Fri, 11 Jan 2002 07:16:11 +0000 (07:16 +0000)
committerMartin Pool <mbp@samba.org>
Fri, 11 Jan 2002 07:16:11 +0000 (07:16 +0000)
heap usage information in --stats

configure.in
main.c
rsync.h

index f6cd900..c274d89 100644 (file)
@@ -204,6 +204,7 @@ AC_CHECK_HEADERS(compat.h sys/param.h ctype.h sys/wait.h sys/ioctl.h)
 AC_CHECK_HEADERS(sys/filio.h string.h stdlib.h sys/socket.h sys/mode.h)
 AC_CHECK_HEADERS(glob.h alloca.h mcheck.h sys/sysctl.h arpa/inet.h arpa/nameser.h)
 AC_CHECK_HEADERS(netdb.h)
+AC_CHECK_HEADERS(malloc.h)
 
 AC_CHECK_SIZEOF(int)
 AC_CHECK_SIZEOF(long)
@@ -309,7 +310,7 @@ AC_FUNC_UTIME_NULL
 AC_CHECK_FUNCS(waitpid wait4 getcwd strdup strerror chown chmod mknod)
 AC_CHECK_FUNCS(fchmod fstat strchr readlink link utime utimes strftime)
 AC_CHECK_FUNCS(memmove lchown vsnprintf snprintf asprintf setsid glob strpbrk)
-AC_CHECK_FUNCS(strlcat strlcpy mtrace)
+AC_CHECK_FUNCS(strlcat strlcpy mtrace mallinfo)
 
 AC_CACHE_CHECK([for working socketpair],rsync_cv_HAVE_SOCKETPAIR,[
 AC_TRY_RUN([
diff --git a/main.c b/main.c
index c092bd2..8938837 100644 (file)
--- a/main.c
+++ b/main.c
@@ -2,7 +2,7 @@
    
    Copyright (C) 1996-2001 by Andrew Tridgell <tridge@samba.org>
    Copyright (C) Paul Mackerras 1996
-   Copyright (C) 2001 by Martin Pool <mbp@samba.org>
+   Copyright (C) 2001, 2002 by Martin Pool <mbp@samba.org>
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -27,6 +27,7 @@ struct stats stats;
 
 extern int verbose;
 
+static void show_malloc_stats(void);
 
 /****************************************************************************
 wait for a process to exit, calling io_flush while waiting
@@ -119,6 +120,7 @@ static void report(int f)
                rprintf(FINFO,"total size is %.0f  speedup is %.2f\n",
                       (double)stats.total_size,
                       (1.0*stats.total_size)/(stats.total_written+stats.total_read));
+               show_malloc_stats();
        }
 
        fflush(stdout);
@@ -126,6 +128,31 @@ static void report(int f)
 }
 
 
+/**
+ * If our C library can get malloc statistics, then show them to FINFO
+ **/
+static void show_malloc_stats(void)
+{
+#ifdef HAVE_MALLINFO
+       struct mallinfo mi;
+
+       mi = mallinfo();
+
+       rprintf(FINFO, RSYNC_NAME " heap statistics:\n");
+       rprintf(FINFO, "  arena:     %10d   (bytes from sbrk)\n", mi.arena);
+       rprintf(FINFO, "  ordblks:   %10d   (chunks not in use)\n", mi.ordblks);
+       rprintf(FINFO, "  smblks:    %10d\n", mi.smblks);
+       rprintf(FINFO, "  hblks:     %10d   (chunks from mmap)\n", mi.hblks);
+       rprintf(FINFO, "  hblkhd:    %10d   (bytes from mmap)\n", mi.hblkhd);
+       rprintf(FINFO, "  usmblks:   %10d\n", mi.usmblks);
+       rprintf(FINFO, "  fsmblks:   %10d\n", mi.fsmblks);
+       rprintf(FINFO, "  uordblks:  %10d   (bytes used)\n", mi.uordblks);
+       rprintf(FINFO, "  fordblks:  %10d   (bytes free)\n", mi.fordblks);
+       rprintf(FINFO, "  keepcost:  %10d   (bytes in releasable chunk)\n", mi.keepcost);
+#endif /* HAVE_MALLINFO */
+}
+
+
 /* Start the remote shell.   cmd may be NULL to use the default. */
 static pid_t do_cmd(char *cmd,char *machine,char *user,char *path,int *f_in,int *f_out)
 {
diff --git a/rsync.h b/rsync.h
index 7217644..7d1ab38 100644 (file)
--- a/rsync.h
+++ b/rsync.h
@@ -185,6 +185,10 @@ enum logcode {FNONE=0, FERROR=1, FINFO=2, FLOG=3 };
 #include <glob.h>
 #endif
 
+#ifdef HAVE_MALLOC_H
+#  include <malloc.h>
+#endif
+
 /* these are needed for the uid/gid mapping code */
 #include <pwd.h>
 #include <grp.h>