Created
January 1, 2010 06:54
-
-
Save simoncpu/267065 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From a3d0d8e89dd0c091414df9aaa3ef03f64911e587 Mon Sep 17 00:00:00 2001 | |
From: Simon Cornelius P. Umacob <[email protected]> | |
Date: Thu, 10 Dec 2009 20:18:29 +0800 | |
Subject: [PATCH] Implement getmem() for FreeBSD platform. | |
--- | |
src/node.cc | 32 ++++++++++++++++++++++++++++++++ | |
wscript | 8 +++++--- | |
2 files changed, 37 insertions(+), 3 deletions(-) | |
diff --git a/src/node.cc b/src/node.cc | |
index b830c4c..33674a1 100644 | |
--- a/src/node.cc | |
+++ b/src/node.cc | |
@@ -434,6 +434,38 @@ int getmem(size_t *rss, size_t *vsize) { | |
} | |
#endif // __APPLE__ | |
+#ifdef __FreeBSD__ | |
+# define HAVE_GETMEM 1 | |
+/* | |
+ * Simon Cornelius P. Umacob <[email protected]> | |
+ */ | |
+#include <sys/param.h> | |
+#include <sys/sysctl.h> | |
+#include <sys/user.h> | |
+#include <sys/types.h> | |
+ | |
+#include <fcntl.h> | |
+#include <kvm.h> | |
+#include <limits.h> | |
+#include <unistd.h> | |
+ | |
+int getmem(size_t *rss, size_t *vsize) { | |
+ struct kinfo_proc *kp; | |
+ char errbuf[_POSIX2_LINE_MAX]; | |
+ int count = 0; | |
+ kvm_t* kvm = kvm_open(NULL, NULL, NULL, O_RDONLY, errbuf); | |
+ | |
+ if (kvm == NULL) return -1; | |
+ | |
+ kp = kvm_getprocs(kvm, KERN_PROC_PID, (int)getpid(), &count); | |
+ | |
+ *rss = (size_t)((kp->ki_rssize * PAGE_SIZE) / 1024); | |
+ *vsize = (size_t)(kp->ki_size / 1024); | |
+ | |
+ return kvm_close(kvm); | |
+} | |
+#endif // __FreeBSD__ | |
+ | |
#ifdef __linux__ | |
# define HAVE_GETMEM 1 | |
# include <sys/param.h> /* for MAXPATHLEN */ | |
diff --git a/wscript b/wscript | |
index 7e2bd0a..8e1ea22 100644 | |
--- a/wscript | |
+++ b/wscript | |
@@ -115,9 +115,11 @@ def configure(conf): | |
#if Options.options.efence: | |
# conf.check(lib='efence', libpath=['/usr/lib', '/usr/local/lib'], uselib_store='EFENCE') | |
- if not conf.check(lib="execinfo", libpath=['/usr/lib', '/usr/local/lib'], uselib_store="EXECINFO"): | |
- if sys.platform.startswith("freebsd"): | |
+ if sys.platform.startswith("freebsd"): | |
+ if not conf.check(lib="execinfo", libpath=['/usr/lib', '/usr/local/lib'], uselib_store="EXECINFO"): | |
conf.fatal("Install the libexecinfo port from /usr/ports/devel/libexecinfo.") | |
+ if not conf.check(lib="kvm", libpath=['/usr/lib', '/usr/local/lib'], uselib_store="KVM"): | |
+ conf.fatal("KVM not found.") | |
if conf.check_cfg(package='gnutls', | |
args='--cflags --libs', | |
@@ -344,7 +346,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 GPGERROR GNUTLS KVM' | |
node.install_path = '${PREFIX}/lib' | |
node.install_path = '${PREFIX}/bin' | |
-- | |
1.6.5.3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[email protected]