Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First passes at exposing prusage.

  • Loading branch information...
commit 1a2311d6311b263b6fd489fcd82c630ba4535547 0 parents
@dshaw authored
8 .gitignore
@@ -0,0 +1,8 @@
+*.swp
+.DS_Store
+.idea
+nohup.out
+npm-debug.log
+node_modules
+*.pem
+*.srl
10 package.json
@@ -0,0 +1,10 @@
+{
+ "name": "proc",
+ "version": "0.0.1",
+ "description": "Solaris process info",
+ "author": "Daniel D. Shaw <dshaw@dshaw.com> (http://dshaw.com)",
+ "main": "./build/Release/prusage",
+ "scripts": {
+ "install": "node-waf configure clean build"
+ }
+}
86 prusage.cc
@@ -0,0 +1,86 @@
+#include "node.h"
+
+#include <unistd.h> /* getpagesize() */
+#include <stdlib.h> /* getexecname() */
+#include <strings.h> /* strncpy() */
+
+#include <kstat.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <sys/loadavg.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <fcntl.h>
+
+#if (!defined(_LP64)) && (_FILE_OFFSET_BITS - 0 == 64)
+#define PROCFS_FILE_OFFSET_BITS_HACK 1
+#undef _FILE_OFFSET_BITS
+#else
+#define PROCFS_FILE_OFFSET_BITS_HACK 0
+#endif
+
+#include <sys/procfs.h>
+
+#if (PROCFS_FILE_OFFSET_BITS_HACK - 0 == 1)
+#define _FILE_OFFSET_BITS 64
+#endif
+
+
+using namespace std;
+using namespace node;
+using namespace v8;
+
+
+static Handle<Value> GetMsnd(const Arguments &args);
+static Handle<Value> GetIoch(const Arguments &args);
+extern "C" void init (Handle<Object>);
+
+
+static Handle<Value> GetMsnd(const Arguments &args) {
+ HandleScope scope;
+ prusage_t prusage;
+ ulong_t msnd;
+ int fd;
+
+ if ((fd = open("/proc/self/usage", O_RDONLY)) < 0)
+ return scope.Close(Integer::New(-1));
+
+ if (read(fd, &prusage, sizeof (prusage_t)) != sizeof (prusage_t)) {
+ (void) close(fd);
+ return scope.Close(Integer::New(-1));
+ }
+
+ msnd = (ulong_t) prusage.pr_msnd;
+ (void) close(fd);
+
+ return scope.Close(Integer::New(msnd));
+}
+
+static Handle<Value> GetIoch(const Arguments &args) {
+ HandleScope scope;
+ prusage_t prusage;
+ ulong_t ioch;
+ int fd;
+
+ if ((fd = open("/proc/self/usage", O_RDONLY)) < 0)
+ return scope.Close(Integer::New(-1));
+
+ if (read(fd, &prusage, sizeof (prusage_t)) != sizeof (prusage_t)) {
+ (void) close(fd);
+ return scope.Close(Integer::New(-1));
+ }
+
+ ioch = (ulong_t) prusage.pr_ioch;
+ (void) close(fd);
+
+ return scope.Close(Integer::New(ioch));
+}
+
+extern "C" void init (Handle<Object> target) {
+ HandleScope scope;
+ NODE_SET_METHOD(target, "msnd", GetMsnd);
+ NODE_SET_METHOD(target, "ioch", GetIoch);
+}
25 test/usage.test.js
@@ -0,0 +1,25 @@
+var net = require('net')
+ , usage = require('..');
+
+var msnd = usage.msnd()
+ , ioch = usage.ioch();
+
+console.dir(usage);
+
+var client;
+
+for (var i=0; i < 3; i++) {
+ client = net.connect(80, 'google.com', function() { //'connect' listener
+ console.log('client connected');
+ client.write('world!\r\n');
+ });
+ client.on('data', function(data) {
+ //console.log(data.toString(), 'msnd', msnd, 'ioch', ioch);
+ console.log('msnd', msnd, 'ioch', ioch);
+ client.end();
+ });
+ client.on('end', function() {
+ console.log('client disconnected');
+ console.log('msnd', msnd, 'ioch', ioch);
+ });
+}
17 wscript
@@ -0,0 +1,17 @@
+srcdir = "."
+blddir = "build"
+VERSION = "0.0.1"
+
+def set_options(opt):
+ opt.tool_options("compiler_cxx")
+
+def configure(conf):
+ conf.check_tool("compiler_cxx")
+ conf.check_tool("node_addon")
+
+def build(bld):
+ obj = bld.new_task_gen("cxx", "shlib", "node_addon")
+ # without this, eio_custom doesn't keep a ref to the req->data
+ obj.cxxflags = ["-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE"]
+ obj.target = "prusage"
+ obj.source = "prusage.cc"
Please sign in to comment.
Something went wrong with that request. Please try again.