Skip to content

texel/memprof

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A Ruby gem for memory profiling

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 90.1%
  • Ruby 9.9%