Skip to content
This repository
tree: 54ae824332

Fetching latest commit…

Cannot retrieve the latest commit at this time

README
google-perftools for ruby code
  (c) 2009 Aman Gupta (tmm1)

=== Usage

  Run the profiler with a block:

    require 'perftools'
    PerfTools::CpuProfiler.start("/tmp/add_numbers_profile") do
      5_000_000.times{ 1+2+3+4+5 }
    end

  Start and stop the profiler manually:

    require 'perftools'
    PerfTools::CpuProfiler.start("/tmp/add_numbers_profile")
    5_000_000.times{ 1+2+3+4+5 }
    PerfTools::CpuProfiler.stop

  Profile an existing ruby application without modifying it:

    $ CPUPROFILE=/tmp/my_app_profile RUBYOPT="-r`gem which perftools | tail -1`" ruby my_app.rb


=== Reporting

  pprof.rb --text /tmp/add_numbers_profile

  pprof.rb --pdf /tmp/add_numbers_profile > /tmp/add_numbers_profile.pdf

  pprof.rb --gif /tmp/add_numbers_profile > /tmp/add_numbers_profile.gif

  pprof.rb --callgrind /tmp/add_numbers_profile > /tmp/add_numbers_profile.grind
  kcachegrind /tmp/add_numbers_profile.grind

  pprof.rb --gif --focus=Integer /tmp/add_numbers_profile > /tmp/add_numbers_custom.gif

  pprof.rb --text --ignore=require /tmp/add_numbers_profile


=== Sample profiles

  http://tmm1.net/redis-rb.gif vs http://tmm1.net/redis-rb-notimeout.gif
  http://tmm1.net/rails.gif    vs http://tmm1.net/merb.gif


=== Installation

  You'll need a patched version of Ruby 1.8:

    wget http://.../ruby-1.8.XpYYY.tar.gz
    tar zxvf ruby-1.8....
    cd ruby-1.8....

    wget http://github.com/tmm1/perftools.rb/raw/master/patches/ruby.patch
    patch -p1 ruby.patch

    ./configure --prefix=/opt/ruby-profiling
    make
    sudo make install

  Install rubygems:

    wget http://rubyforge.org/frs/download.php/57643/rubygems-1.3.4.tgz
    tar zxvf rubygems-1.3.4.tgz
    cd rubygems-1.3.4
    /opt/ruby-profiling/bin/ruby setup.rb

  Install the perftools.rb gem, which will download and compile google-perftools for you:

    git clone git://github.com/tmm1/perftools.rb
    cd perftools.rb
    gem build perftools.rb.gemspec
    /opt/ruby-profiling/bin/gem install perftools.rb


=== TODO

  * Add support for heap profiling to find memory leaks


=== Resources

  Google Perftools
    http://code.google.com/p/google-perftools/

  Analyzing profiles and interpreting different output formats
    http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html#pprof
Something went wrong with that request. Please try again.