Skip to content
This repository

A Ruby gem for memory profiling

tree: 35535c2eb9

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 bin memprof --info to show info about ruby binary April 22, 2010
Octocat-spinner-32 ext
Octocat-spinner-32 lib fix middleware June 14, 2010
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore update .gitignore March 23, 2010
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile Refactor CI task March 26, 2010
Octocat-spinner-32 memprof.gemspec
README.rdoc

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.

Installing

gem install memprof

Usage

Memory Tracking

Blocks (memory tracking)

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

Rails requests (memory tracking)

Use the Memprof::Middleware

Dump objects

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.

Dumping the entire heap

Memprof.dump_all("file.json")

This will dump out every single live object as json to /tmp/file.json

Less elegant tracking usage:

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.

Function call tracing

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.

Compatibility

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

Special Thanks

* 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
Something went wrong with that request. Please try again.