Changeset: e5eff3a1c024 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e5eff3a1c024 Modified Files: configure.ag gdk/gdk_posix.c Branch: Apr2012 Log Message:
Use getrusage() to get RSS (if it works). Also, on both Solaris and Linux, /proc/self is identical to /proc/<pid> for <pid>==getpid(). diffs (69 lines): diff --git a/configure.ag b/configure.ag --- a/configure.ag +++ b/configure.ag @@ -2608,6 +2608,12 @@ AC_CHECK_FUNCS([\ trunc \ uname \ ]) +AC_RUN_IFELSE([AC_LANG_PROGRAM( +[[#include <sys/time.h> +#include <sys/resource.h>]], +[[struct rusage u; exit(getrusage(RUSAGE_SELF, &u) != 0 || u.ru_maxrss <= 0);]])], +AC_DEFINE(HAVE_GETRUSAGE, 1, [Define if you have the getrusage function with working ru_maxrss.])) + LIBS="$save_LIBS" save_LIBS="$LIBS" LIBS= diff --git a/gdk/gdk_posix.c b/gdk/gdk_posix.c --- a/gdk/gdk_posix.c +++ b/gdk/gdk_posix.c @@ -53,6 +53,9 @@ extern char *sbrk(int); #ifdef HAVE_MACH_MACH_INIT_H # include <mach/mach_init.h> #endif +#ifdef HAVE_SYS_RESOURCE_H +#include <sys/resource.h> +#endif #if defined(DEBUG_ALLOC) && SIZEOF_VOID_P > 4 #undef DEBUG_ALLOC @@ -755,15 +758,10 @@ MT_getrss(void) { #if defined(HAVE_PROCFS_H) && defined(__sun__) /* retrieve RSS the Solaris way (2.6+) */ - static char MT_mmap_procfile[128] = { 0 }; int fd; psinfo_t psbuff; - if (MT_mmap_procfile[0] == 0) { - /* getpid returns pid_t, cast to long to be sure */ - sprintf(MT_mmap_procfile, "/proc/%ld/psinfo", (long) getpid()); - } - fd = open(MT_mmap_procfile, O_RDONLY); + fd = open("/proc/self/psinfo", O_RDONLY); if (fd >= 0) { if (read(fd, &psbuff, sizeof(psbuff)) == sizeof(psbuff)) { close(fd); @@ -779,16 +777,16 @@ MT_getrss(void) if (task_info(task, TASK_BASIC_INFO_64, (task_info_t)&t_info, &t_info_count) != KERN_INVALID_POLICY) return t_info.resident_size; /* bytes */ +#elif defined(HAVE_GETRUSAGE) + struct rusage usage; + + if (getrusage(RUSAGE_SELF, &usage) == 0) + return (size_t) usage.ru_maxrss * 1024; #else /* get RSS on Linux */ - static char MT_mmap_procfile[128] = { 0 }; int fd; - if (MT_mmap_procfile[0] == 0) { - /* getpid returns pid_t, cast to long to be sure */ - sprintf(MT_mmap_procfile, "/proc/%ld/stat", (long) getpid()); - } - fd = open(MT_mmap_procfile, O_RDONLY); + fd = open("/proc/self/stat", O_RDONLY); if (fd >= 0) { char buf[1024], *r = buf; size_t i, sz = read(fd, buf, 1024); _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list