|
@ -67,3 +67,64 @@ exports.exec = function (command) { |
|
|
|
|
|
|
|
|
return promise; |
|
|
return promise; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
exports.memoryUsage = function () { |
|
|
|
|
|
if (process.platform == "linux2") { |
|
|
|
|
|
var data = require("file").read("/proc/self/stat").wait(); |
|
|
|
|
|
// from linux-2.6.29/Documentation/filesystems/proc.tx
|
|
|
|
|
|
// 0 pid process id
|
|
|
|
|
|
// 1 tcomm filename of the executable
|
|
|
|
|
|
// 2 state state (R is running, S is sleeping, D is sleeping in an
|
|
|
|
|
|
// uninterruptible wait, Z is zombie, T is traced or stopped)
|
|
|
|
|
|
// 3 ppid process id of the parent process
|
|
|
|
|
|
// 4 pgrp pgrp of the process
|
|
|
|
|
|
// 5 sid session id
|
|
|
|
|
|
// 6 tty_nr tty the process uses
|
|
|
|
|
|
// 7 tty_pgrp pgrp of the tty
|
|
|
|
|
|
// 8 flags task flags
|
|
|
|
|
|
// 9 min_flt number of minor faults
|
|
|
|
|
|
// 10 cmin_flt number of minor faults with child's
|
|
|
|
|
|
// 11 maj_flt number of major faults
|
|
|
|
|
|
// 12 cmaj_flt number of major faults with child's
|
|
|
|
|
|
// 13 utime user mode jiffies
|
|
|
|
|
|
// 14 stime kernel mode jiffies
|
|
|
|
|
|
// 15 cutime user mode jiffies with child's
|
|
|
|
|
|
// 16 cstime kernel mode jiffies with child's
|
|
|
|
|
|
// 17 priority priority level
|
|
|
|
|
|
// 18 nice nice level
|
|
|
|
|
|
// 19 num_threads number of threads
|
|
|
|
|
|
// 20 it_real_value (obsolete, always 0)
|
|
|
|
|
|
// 21 start_time time the process started after system boot
|
|
|
|
|
|
// 22 vsize virtual memory size
|
|
|
|
|
|
// 23 rss resident set memory size
|
|
|
|
|
|
// 24 rsslim current limit in bytes on the rss
|
|
|
|
|
|
// 25 start_code address above which program text can run
|
|
|
|
|
|
// 26 end_code address below which program text can run
|
|
|
|
|
|
// 27 start_stack address of the start of the stack
|
|
|
|
|
|
// 28 esp current value of ESP
|
|
|
|
|
|
// 29 eip current value of EIP
|
|
|
|
|
|
// 30 pending bitmap of pending signals (obsolete)
|
|
|
|
|
|
// 31 blocked bitmap of blocked signals (obsolete)
|
|
|
|
|
|
// 32 sigign bitmap of ignored signals (obsolete)
|
|
|
|
|
|
// 33 sigcatch bitmap of catched signals (obsolete)
|
|
|
|
|
|
// 34 wchan address where process went to sleep
|
|
|
|
|
|
// 35 0 (place holder)
|
|
|
|
|
|
// 36 0 (place holder)
|
|
|
|
|
|
// 37 exit_signal signal to send to parent thread on exit
|
|
|
|
|
|
// 38 task_cpu which CPU the task is scheduled on
|
|
|
|
|
|
// 39 rt_priority realtime priority
|
|
|
|
|
|
// 40 policy scheduling policy (man sched_setscheduler)
|
|
|
|
|
|
// 41 blkio_ticks time spent waiting for block IO
|
|
|
|
|
|
var fields = data.split(" "); |
|
|
|
|
|
|
|
|
|
|
|
// 22 vsize virtual memory size
|
|
|
|
|
|
// 23 rss resident set memory size
|
|
|
|
|
|
|
|
|
|
|
|
return { vsize: parseInt(fields[22]), rss: 4096*parseInt(fields[23]) }; |
|
|
|
|
|
|
|
|
|
|
|
} else if (process.platform == "darwin") { |
|
|
|
|
|
return process.macGetMemory(); |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new Error("Unsupported on your platform! Complain to Ryan!"); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|