Skip to content
/ rbheap Public

A tool to help with tracking down memory leaks in Ruby.

License

Notifications You must be signed in to change notification settings

jimeh/rbheap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rbheap Build Status

A tool for working with and analyzing Ruby processes' heap dumps created via ObjectSpace.dump_all.

How to dump the heap

Dumping the heap from a running Ruby process is not very difficult as long as your app has required the rbtrace gem.

  1. Add the rbtrace gem to your application, and require it in your code when the application boots.
  2. Find the PID of your running Ruby process.
  3. Run the following to dump your process' heap to a file called heap.jsonl:
    rbtrace -p $PID -e 'Thread.new{GC.start;require "objspace";File.open("heap.jsonl","w"){|f|ObjectSpace.dump_all(output: f)}}'

Commands

leak

The leak command is intended to help track down memory leaks. By requiring three heap dumps as input, it attempts to find memory that showed up in dump #2, and is still there in #3.

The idea is to take a heap dump shortly after the application starts and before it's had much of a chance to leak memory. Then take another heap dump after it's been running for a while and leaked memory. And finally take a third heap dump after it's been running for a while longer and leaked even more.

But comparing these three dumps and extracting only the objects which are held in memory during heap dumps #2 and #3, we should mostly be left with objects which are leaked memory.

Usage:
  rbheap leak [flags] <dump-A> <dump-B> <dump-C>

Flags:
  -f, --format string   output format: "hex" / "json" (default "hex")
  -h, --help            help for leak
  -v, --verbose         print verbose information

Credits

This project is mostly based on the ideas and concepts from the following articles:

About

A tool to help with tracking down memory leaks in Ruby.

Resources

License

Stars

Watchers

Forks

Packages

No packages published