Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1a2311d
Showing
5 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.swp | ||
.DS_Store | ||
.idea | ||
nohup.out | ||
npm-debug.log | ||
node_modules | ||
*.pem | ||
*.srl |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |