google-perftools を使うのがおすすめ.
sudo aptitude install libgoogle-perftools-dev
$ LD_PRELOAD=/usr/lib/libprofiler.so > profile.out ruby examples/hoge.rb
^CBye.
PROFILE: interrupts/evictions/bytes = 12/0/164
$ google-pprof --dot `which ruby` ./profile.out > prof.dot
Using local file /usr/local/bin/ruby.
Using local file ./profile.out.
$ dot -T png prof.dot > prof.png
$ eog prof.png
部分的に取得したいとき
#include "google/profiler.h"
//とりたいとこでかく
ProfilerStart("profile.out");
...
ProfilerStop();
callgrind でみたいとき
$ sudo aptitude install kcachegrind
$ google-pprof --callgrind `which ruby` ./profile.out > prof.callgrind