One more wheel that doesn't need to be re-invented. This will probably
work on MacOS and Solaris, but I don't have them to test it. I don't
remember whether Cygwin has "getrusage" or not -- if it does, that means
it could be implemented on Windows Ruby somehow.
--
M. Edward (Ed) Borasky
http://ruby-perspectives.blogspot.com/
"A mathematician is a machine for turning coffee into theorems." --
Alfréd Rényi via Paul Erdős
Good news. :)
--
http://antoniocangiano.com - Zen and the Art of Programming
http://math-blog.com - Mathematics is wonderful!
http://stacktrace.it - Aperiodico di resistenza informatica
Currently writing "Ruby on Rails for Microsoft Developers" for Wrox.
Works for KRI:
$ which ruby
/home/znmeb/cougar/PTR2/install/bin/ruby
$ ruby --version
ruby 1.9.0 (2008-07-07 revision 17945) [x86_64-linux]
$ which gem
/home/znmeb/cougar/PTR2/install/bin/gem
$ gem install proc-wait3
Building native extensions. This could take a while...
Successfully installed proc-wait3-1.5.4
1 gem installed
Installing ri documentation for proc-wait3-1.5.4...
Installing RDoc documentation for proc-wait3-1.5.4...
$ which irb
/home/znmeb/cougar/PTR2/install/bin/irb
$ irb
irb(main):001:0> require 'proc/wait3'
=> true
irb(main):002:0> Process.getrusage
=> #<struct Struct::RUsage utime=0.068989, stime=0.024996, maxrss=0,
ixrss=0, idrss=0, isrss=0, minflt=2145, majflt=2, nswap=0, inblock=432,
oublock=0, msgsnd=0, msgrcv=0, nsignals=0, nvcsw=2548, nivcsw=13>
irb(main):003:0> Process.getrusage
=> #<struct Struct::RUsage utime=0.070989, stime=0.027995, maxrss=0,
ixrss=0, idrss=0, isrss=0, minflt=2152, majflt=2, nswap=0, inblock=432,
oublock=0, msgsnd=0, msgrcv=0, nsignals=0, nvcsw=3294, nivcsw=13>
irb(main):004:0>
Whether or not you get all of those numbers depends on which kernel you
have. I've forgotten the exact versions when some of these appeared, but
utime, stime, minflt and majflt have more or less "always" been there.
"inblock" and "oublock" are relatively new, as are "nvcsw" and "nivcsw".
But it looks like you're still going to need to go directly to
/proc/self/stat to pick up RSS and VSZ.
On JRuby and Rubinius, it would be nice to get an FFI-based version of
that. We also have a JRubyist that's looking at making an FFI lib for
MRI, so it would be a good long-term way to go.
- Charlie
Well, you're still probably going to be stuck on Windows, unless the
underlying C library has "getrusage". But everything "Unix-like" has
"getrusage" as far as I know, and pretty much the only one that doesn't
implement all of the fields is Linux. :) It took Linux till
2.6.20-something to get per-process I/O counters!