Rss?

Is there an easy jruby way to get the rss of the current process?
Just wondering.
Thanks.
-r

I don’t know about ‘easy’, but you can use JMX to inspect the
java.lang.Memory MBean and get information about it that way. Would that
meet your needs? I think there is a JMX gem which might help with that.

Cheers,

James

2010/1/19 Roger P. [email protected]

On Tue, Jan 19, 2010 at 6:11 AM, James A. [email protected]
wrote:

I don’t know about ‘easy’, but you can use JMX to inspect the
java.lang.Memory MBean and get information about it that way. Would that
meet your needs? I think there is a JMX gem which might help with that.

Here’s an example…no JMX needed to access the beans from within the
same process:

~/projects/jruby âž” jirb --simple-prompt

require ‘java’
=> true
mem_bean = java.lang.management.ManagementFactory.memory_mxbean
=> sun.management.MemoryImpl@b0de2e
mem_bean.gc
=> nil
heap_usage = mem_bean.heap_memory_usage
=> init = 0(0K) used = 3033160(2962K) committed = 5459968(5332K) max =
520290304(508096K)
nonheap_usage = mem_bean.non_heap_memory_usage
=> init = 29523968(28832K) used = 21956272(21441K) committed =
32210944(31456K) max = 121634816(118784K)
mem_bean.verbose = true
=> true
ary = []; 1000.times { ary << “hello” }; ary = nil; mem_bean.gc
[GC 3463K->2959K(5332K), 0.0017047 secs]
[GC 3471K->2942K(5332K), 0.0011893 secs]
[GC 3452K->2988K(5332K), 0.0011530 secs]
[Full GC 3163K->2746K(5332K), 0.0669727 secs]
=> nil

What you’re interested in here is the committed sizes; heap plus
nonheap should be pretty close to RSS. For more than that you could
call out to C via FFI. I also show turning on verbose GC logging here.

There’s more fun if you want to dig deeper:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/package-summary.html

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

nonheap_usage = mem_bean.non_heap_memory_usage

Cool.
I added its RSS as

mem_bean.heap_memory_usage.used + mem_bean.non_heap_memory_usage.used

and now I can get the rss for a jruby process on doze, without win32ole
:slight_smile:

-r