memprof © Joe Damato @joedamato timetobleed.com¶ ↑
Memprof is a Ruby level memory profiler that can help you find reference leaks in your application. Memprof can also do very lightweight function call tracing to help you figure out which system calls, and library calls your code causes.
gem install memprof
Memprof.track { 100.times{ "abc" } 100.times{ 1.23 + 1 } 100.times{ Module.new } }
Outputs:
100 file.rb:2:String 100 file.rb:3:Float 100 file.rb:4:Module
Use the Memprof::Middleware
Memprof.dump { "hello" + "world" }
Outputs:
{ "_id": "0x19c610", "file": "file.rb", "line": 2, "type": "string", "class": "0x1ba7f0", "class_name": "String", "length": 10, "data": "helloworld" }
You can dump any Ruby object you want.
Memprof.dump_all("file.json")
This will dump out every single live object as json to /tmp/file.json
require 'memprof' Memprof.start # ruby code Memprof.stats # more ruby code Memprof.stats Memprof.stop
The above code will output 2 summaries, allowing you to compare which objects were destroyed and which are still around.
Memprof.stats also takes an (optional) file name to write the output to a file.
This system is under development and the API may change without warning.
You can use the middleware Memprof::Tracer to output function tracing and request information for each request that comes in to your app.
You must have debug symbols installed or a an unstripped version of Ruby.
To install debug symbols on Debian-like systems:
apt-get install libruby1.8-dbg
Not supporting:
* OSX default Ruby * Stripped Ruby binaries without debug symbols * Any and all Windows Ruby builds * Ruby 1.9+ on all systems * 32bit systems
Supporting:
* Linux (enable-shared AND disable-shared): * x86_64 builds of Ruby Enterprise Edition 1.8.6/1.8.7 * x86_64 builds of MRI Ruby * Snow Leopard (enable-shared AND disable-shared): * x86_64 builds of Ruby Enterprise Edition 1.8.6/1.8.7 * x86_64 builds of MRI Ruby
Coming soon:
Official support for Ruby 1.9 Official support for i386/i686
* Jake Douglas for the Mach O/snow leopard support. * Aman Gupta for various bug fixes and other cleanup. * Rob Benson for 1.9 support and cleanup. * Paul Barry for force_gc support in Memprof::Middleware