From e5a2b8544dee410dcdeafbc2f1b82f9a8f4faf23 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 11 Jan 2002 07:16:11 +0000 Subject: [PATCH] Look for mallinfo() and use it to display heap usage information in --stats --- configure.in | 3 ++- main.c | 29 ++++++++++++++++++++++++++++- rsync.h | 4 ++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/configure.in b/configure.in index f6cd9004..c274d894 100644 --- a/configure.in +++ b/configure.in @@ -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 c092bd23..89388373 100644 --- a/main.c +++ b/main.c @@ -2,7 +2,7 @@ Copyright (C) 1996-2001 by Andrew Tridgell Copyright (C) Paul Mackerras 1996 - Copyright (C) 2001 by Martin Pool + Copyright (C) 2001, 2002 by Martin Pool 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 72176449..7d1ab383 100644 --- a/rsync.h +++ b/rsync.h @@ -185,6 +185,10 @@ enum logcode {FNONE=0, FERROR=1, FINFO=2, FLOG=3 }; #include #endif +#ifdef HAVE_MALLOC_H +# include +#endif + /* these are needed for the uid/gid mapping code */ #include #include -- 2.34.1