# Jruby\_gc\_stats 0.1: a set of GC monitoring methods similar to REE

**URL:** <https://www.ruby-forum.com/t/jruby-gc-stats-0-1-a-set-of-gc-monitoring-methods-similar-to-ree/187572>\
**Category:** Ruby\
**Created:** [April 26, 2010, 4:22am UTC](https://www.ruby-forum.com/t/jruby-gc-stats-0-1-a-set-of-gc-monitoring-methods-similar-to-ree/187572 "2010-04-26T04:22:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![headius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7c8e57/32.png) [@headius](https://www.ruby-forum.com/u/headius)\
**Post date:** [April 26, 2010, 4:22am UTC](https://www.ruby-forum.com/t/jruby-gc-stats-0-1-a-set-of-gc-monitoring-methods-similar-to-ree/187572/1 "2010-04-26T04:22:17Z")

</div>

Hiya! I just released a gem called jruby\_gc\_stats, which provides for  
JRuby most of the GC-monitoring methods users of Ruby Enterprise  
Edition might be using. These methods are provided without any  
performance impact using standard JVM monitoring capabilities, and  
should work on any mainstream JVM.

Repo:

> **[GitHub - headius/jruby\_gc\_stats: GC stat-monitoring methods similar to Ruby...](https://github.com/headius/jruby_gc_stats)**
>
> GC stat-monitoring methods similar to Ruby Enterprise Edition - GitHub - headius/jruby\_gc\_stats: GC stat-monitoring methods similar to Ruby Enterprise Edition

Supported methods:

GC.enable\_status/disable\_stats  
(stats do not incur any perf penalty on JRuby, so these methods just  
reset counters)

GC.collections: number of garbage collections since “enable\_stats”  
GC.time: amount of time in GC since “enable\_stats”  
GC.growth: uncollected memory increase since last GC run  
GC.dump: dump information about all memory pools  
GC.allocation\_size: increase in total heap size since “enable\_stats”  
caller\_for\_all\_threads: dump the caller stack for all active threads

Unsupported:

GC.num\_allocations: no equivalent on JVM  
ObjectSpace.live\_objects: requires doing a very costly heap dump  
ObjectSpace.allocated\_objects: requires starting JVM in debug mode

Install:

gem install jruby\_gc\_stats

Example:

require ‘rubygems’  
require ‘jruby/gc\_stats’

require ‘pp’  
puts “Enabling stats…”  
GC.enable\_stats  
puts “allocation size: #{GC.allocation\_size}”  
puts “Running loop…”  
1\_000.times {  
ary = []  
1\_000.times {ary \<\< ‘foo’ + ‘bar’}  
}  
puts “collections: #{GC.collections}”  
puts “time: #{GC.time}ms”  
puts “bytes since last GC: #{GC.growth}”  
puts “size change: #{GC.allocation\_size}”  
puts “Dumping…”  
GC.dump

puts “Dumping caller for all threads…”  
2.times {Thread.new {sleep}}  
pp caller\_for\_all\_threads
