There is a gem that supports getrusage!

45 views
Skip to first unread message

M. Edward (Ed) Borasky

unread,
Jul 7, 2008, 11:50:57 AM7/7/08
to ruby-bench...@googlegroups.com
At least for MRI -- I'm just about to test it with KRI. It's part of the
"proc-wait3" gem, which in turn is part of Daniel Berger's "shards"
project on RubyForge. https://rubyforge.org/projects/shards/

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

znmeb.vcf

Antonio Cangiano

unread,
Jul 7, 2008, 12:29:42 PM7/7/08
to ruby-bench...@googlegroups.com
M. Edward (Ed) Borasky wrote:
> At least for MRI -- I'm just about to test it with KRI. It's part of the
> "proc-wait3" gem, which in turn is part of Daniel Berger's "shards"
> project on RubyForge. https://rubyforge.org/projects/shards/
>
> 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.

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.

M. Edward (Ed) Borasky

unread,
Jul 7, 2008, 12:38:59 PM7/7/08
to ruby-bench...@googlegroups.com
M. Edward (Ed) Borasky wrote:
> At least for MRI -- I'm just about to test it with KRI. It's part of the
> "proc-wait3" gem, which in turn is part of Daniel Berger's "shards"
> project on RubyForge. https://rubyforge.org/projects/shards/
>
> 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.

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.

znmeb.vcf

Charles Oliver Nutter

unread,
Jul 7, 2008, 1:21:45 PM7/7/08
to ruby-bench...@googlegroups.com
M. Edward (Ed) Borasky wrote:
> At least for MRI -- I'm just about to test it with KRI. It's part of the
> "proc-wait3" gem, which in turn is part of Daniel Berger's "shards"
> project on RubyForge. https://rubyforge.org/projects/shards/
>
> 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.

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

M. Edward (Ed) Borasky

unread,
Jul 7, 2008, 1:31:18 PM7/7/08
to ruby-bench...@googlegroups.com

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!

znmeb.vcf

Jim Deville

unread,
Jul 7, 2008, 1:53:41 PM7/7/08
to ruby-bench...@googlegroups.com
Does anyone know if it could be built for Windows if the POSIX subsystem was enabled?

JD
Reply all
Reply to author
Forward
0 new messages