Browse files

Return usage object.

  • Loading branch information...
1 parent 1a2311d commit 4f42ab2e44685b8104b84cbd2b90c80201e58099 @dshaw committed Mar 28, 2012
Showing with 82 additions and 3 deletions.
  1. +41 −0 Readme.md
  2. +2 −2 package.json
  3. +38 −0 prusage.cc
  4. +1 −1 wscript
View
41 Readme.md
@@ -0,0 +1,41 @@
+# Proc
+
+Expose low level system proc data.
+
+## usage
+
+/*
+ * Resource usage. /proc/<pid>/usage /proc/<pid>/lwp/<lwpid>/lwpusage
+ */
+typedef struct prusage {
+ id_t pr_lwpid; /* lwp id. 0: process or defunct */
+ int pr_count; /* number of contributing lwps */
+ timestruc_t pr_tstamp; /* current time stamp */
+ timestruc_t pr_create; /* process/lwp creation time stamp */
+ timestruc_t pr_term; /* process/lwp termination time stamp */
+ timestruc_t pr_rtime; /* total lwp real (elapsed) time */
+ timestruc_t pr_utime; /* user level cpu time */
+ timestruc_t pr_stime; /* system call cpu time */
+ timestruc_t pr_ttime; /* other system trap cpu time */
+ timestruc_t pr_tftime; /* text page fault sleep time */
+ timestruc_t pr_dftime; /* data page fault sleep time */
+ timestruc_t pr_kftime; /* kernel page fault sleep time */
+ timestruc_t pr_ltime; /* user lock wait sleep time */
+ timestruc_t pr_slptime; /* all other sleep time */
+ timestruc_t pr_wtime; /* wait-cpu (latency) time */
+ timestruc_t pr_stoptime; /* stopped time */
+ timestruc_t filltime[6]; /* filler for future expansion */
+ ulong_t pr_minf; /* minor page faults */
+ ulong_t pr_majf; /* major page faults */
+ ulong_t pr_nswap; /* swaps */
+ ulong_t pr_inblk; /* input blocks */
+ ulong_t pr_oublk; /* output blocks */
+ ulong_t pr_msnd; /* messages sent */
+ ulong_t pr_mrcv; /* messages received */
+ ulong_t pr_sigs; /* signals received */
+ ulong_t pr_vctx; /* voluntary context switches */
+ ulong_t pr_ictx; /* involuntary context switches */
+ ulong_t pr_sysc; /* system calls */
+ ulong_t pr_ioch; /* chars read and written */
+ ulong_t filler[10]; /* filler for future expansion */
+} prusage_t;
View
4 package.json
@@ -1,9 +1,9 @@
{
"name": "proc",
- "version": "0.0.1",
+ "version": "0.0.2",
"description": "Solaris process info",
"author": "Daniel D. Shaw <dshaw@dshaw.com> (http://dshaw.com)",
- "main": "./build/Release/prusage",
+ "main": "./build/Release/usage",
"scripts": {
"install": "node-waf configure clean build"
}
View
38 prusage.cc
@@ -34,10 +34,47 @@ using namespace node;
using namespace v8;
+static Handle<Value> GetUsage(const Arguments &args);
static Handle<Value> GetMsnd(const Arguments &args);
static Handle<Value> GetIoch(const Arguments &args);
extern "C" void init (Handle<Object>);
+/*
+ * Get usage.
+ */
+static Handle<Value> GetUsage(const Arguments &args) {
+ HandleScope scope;
+ prusage_t prusage;
+ int fd;
+ Local<Object> usage = Object::New();
+
+ if ((fd = open("/proc/self/usage", O_RDONLY)) < 0)
+ return scope.Close(usage);
+
+ if (read(fd, &prusage, sizeof (prusage_t)) != sizeof (prusage_t)) {
+ (void) close(fd);
+ return scope.Close(usage);
+ }
+
+ usage->Set(String::New("lwpid"), Integer::New((id_t) prusage.pr_lwpid));
+ usage->Set(String::New("count"), Integer::New((int) prusage.pr_count));
+ usage->Set(String::New("minf"), Integer::New((ulong_t) prusage.pr_minf));
+ usage->Set(String::New("majf"), Integer::New((ulong_t) prusage.pr_majf));
+ usage->Set(String::New("nswap"), Integer::New((ulong_t) prusage.pr_nswap));
+ usage->Set(String::New("inblk"), Integer::New((ulong_t) prusage.pr_inblk));
+ usage->Set(String::New("oublk"), Integer::New((ulong_t) prusage.pr_oublk));
+ usage->Set(String::New("msnd"), Integer::New((ulong_t) prusage.pr_msnd));
+ usage->Set(String::New("mrcv"), Integer::New((ulong_t) prusage.pr_mrcv));
+ usage->Set(String::New("sigs"), Integer::New((ulong_t) prusage.pr_sigs));
+ usage->Set(String::New("vctx"), Integer::New((ulong_t) prusage.pr_vctx));
+ usage->Set(String::New("ictx"), Integer::New((ulong_t) prusage.pr_ictx));
+ usage->Set(String::New("sysc"), Integer::New((ulong_t) prusage.pr_sysc));
+ usage->Set(String::New("ioch"), Integer::New((ulong_t) prusage.pr_ioch));
+
+ (void) close(fd);
+
+ return scope.Close(usage);
+}
static Handle<Value> GetMsnd(const Arguments &args) {
HandleScope scope;
@@ -81,6 +118,7 @@ static Handle<Value> GetIoch(const Arguments &args) {
extern "C" void init (Handle<Object> target) {
HandleScope scope;
+ NODE_SET_METHOD(target, "usage", GetUsage);
NODE_SET_METHOD(target, "msnd", GetMsnd);
NODE_SET_METHOD(target, "ioch", GetIoch);
}
View
2 wscript
@@ -13,5 +13,5 @@ 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.target = "usage"
obj.source = "prusage.cc"

0 comments on commit 4f42ab2

Please sign in to comment.