From d22952bfe0e6f7f6f0001cbfdc15433591d1f1cd Mon Sep 17 00:00:00 2001 From: Vanilla Hsu Date: Wed, 6 Jan 2010 23:37:27 -0800 Subject: [PATCH] getmem for freebsd --- src/node.cc | 38 ++++++++++++++++++++++++++++++++++++++ wscript | 7 +++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/node.cc b/src/node.cc index 5841937..14144a5 100644 --- a/src/node.cc +++ b/src/node.cc @@ -457,6 +457,44 @@ v8::Handle Exit(const v8::Arguments& args) { return Undefined(); } + +#ifdef __FreeBSD__ +#define HAVE_GETMEM 1 +#include +#include +#include +#include +#include +#include + +int getmem(size_t *rss, size_t *vsize) { + kvm_t *kd = NULL; + struct kinfo_proc *kinfo = NULL; + pid_t pid; + int nprocs; + + pid = getpid(); + + kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open"); + if (kd == NULL) goto error; + + kinfo = kvm_getprocs(kd, KERN_PROC_PID, pid, &nprocs); + if (kinfo == NULL) goto error; + + *rss = kinfo->ki_rssize * PAGE_SIZE; + *vsize = kinfo->ki_size; + + kvm_close(kd); + + return 0; + +error: + if (kd) kvm_close(kd); + return -1; +} +#endif // __FreeBSD__ + + #ifdef __APPLE__ #define HAVE_GETMEM 1 /* Researched by Tim Becker and Michael Knight diff --git a/wscript b/wscript index 594647d..08bd591 100644 --- a/wscript +++ b/wscript @@ -109,6 +109,9 @@ def configure(conf): conf.env.append_value("CCFLAGS", "-rdynamic") conf.env.append_value("LINKFLAGS_DL", "-rdynamic") + if sys.platform.startswith("freebsd"): + conf.check(lib='kvm', uselib_store='KVM') + #if Options.options.debug: # conf.check(lib='profiler', uselib_store='PROFILER') @@ -127,7 +130,7 @@ def configure(conf): #libpath=['/usr/lib', '/usr/local/lib'], uselib_store='GNUTLS'): if conf.check(lib='gpg-error', - #libpath=['/usr/lib', '/usr/local/lib'], + libpath=['/usr/lib', '/usr/local/lib'], uselib_store='GPGERROR'): conf.env.append_value("CCFLAGS", "-DEVCOM_HAVE_GNUTLS=1") conf.env.append_value("CXXFLAGS", "-DEVCOM_HAVE_GNUTLS=1") @@ -346,7 +349,7 @@ def build(bld): """ node.add_objects = 'ev eio evcom http_parser coupling' node.uselib_local = '' - node.uselib = 'UDNS V8 EXECINFO DL GPGERROR GNUTLS' + node.uselib = 'UDNS V8 EXECINFO DL KVM GPGERROR GNUTLS' node.install_path = '${PREFIX}/lib' node.install_path = '${PREFIX}/bin' -- 2.7.4