Skip to content

Instantly share code, notes, and snippets.

Created December 29, 2011 12:42
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Monitoring per-thread allocation using JRuby and
require 'java'
require 'jruby'
thread_bean =
t1 = do
a = nil
loop do
a = 'foo'
t1_thread = JRuby.reference(t1).native_thread
main = Thread.current
main_thread = JRuby.reference(main).native_thread
loop do
sleep 1
t1_alloc = thread_bean.get_thread_allocated_bytes([].to_java(:long))[0]
main_alloc = thread_bean.get_thread_allocated_bytes([].to_java(:long))[0]
puts "main allocated: #{main_alloc}"
puts "t1 allocated: #{t1_alloc}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment