Skip to content

Instantly share code, notes, and snippets.

@brixen
Created February 18, 2011 21:56
Show Gist options
  • Save brixen/834491 to your computer and use it in GitHub Desktop.
Save brixen/834491 to your computer and use it in GitHub Desktop.
Easy tool for checking how much memory Rubinius uses
$ rbx memory.rb
memory used: 19.4M
$ bin/mspec ci -T -rmemory core/array
rubinius 1.2.1 (1.8.7 cdbdd275 2011-02-15 JI) [i686-apple-darwin9.8.0]
................................................................................................................
Finished in 3.992361 seconds
112 files, 2166 examples, 4420 expectations, 0 failures, 0 errors
memory used: 22.7M
require 'rubinius/agent'
class MemoryCheck
include Rubinius::Stats::Units
def initialize
@agent = Rubinius::Agent.loopback
end
def check
total = [:young, :mature, :large, :code, :symbols].inject(0) do |s, m|
s + @agent.get("system.memory.#{m}.bytes").last
end
auto_bytes total
end
end
at_exit do
puts "memory used: #{MemoryCheck.new.check}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment