getmem for freebsd
authorVanilla Hsu <v@fatpipi.com>
Thu, 7 Jan 2010 07:37:27 +0000 (23:37 -0800)
committerRyan Dahl <ry@tinyclouds.org>
Thu, 7 Jan 2010 07:37:27 +0000 (23:37 -0800)
src/node.cc
wscript

index 5841937..14144a5 100644 (file)
@@ -457,6 +457,44 @@ v8::Handle<v8::Value> Exit(const v8::Arguments& args) {
   return Undefined();
 }
 
+
+#ifdef __FreeBSD__
+#define HAVE_GETMEM 1
+#include <kvm.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/user.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+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 (file)
--- 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'