Skip to content

Instantly share code, notes, and snippets.

@cball
Created January 10, 2012 18:13
Show Gist options
  • Save cball/1590325 to your computer and use it in GitHub Desktop.
Save cball/1590325 to your computer and use it in GitHub Desktop.
How to use perftools.rb
# generate profile around a script/test
$ CPUPROFILE=/tmp/my_app_profile RUBYOPT="-r`gem which perftools | tail -1`" ruby -I spec spec/models/user_role_spec.rb
# generate profile using a block
# (this is in ruby obviously)
require 'perftools'
PerfTools::CpuProfiler.start("/tmp/add_numbers_profile") do
5_000_000.times{ 1+2+3+4+5 }
end
# show as text
$ pprof.rb --text /tmp/my_app_profile
# show as gif
$ pprof.rb --gif /tmp/my_app_profile > /tmp/my_app_profile.gif
# if that fails,
$ brew install graphviz ghostscript
# generate profile around a script/test
$ CPUPROFILE=/tmp/my_app_profile RUBYOPT="-r`gem which perftools | tail -1`" ruby -I spec spec/models/user_role_spec.rb
# generate profile using a block
# (this is in ruby obviously)
require 'perftools'
PerfTools::CpuProfiler.start("/tmp/add_numbers_profile") do
5_000_000.times{ 1+2+3+4+5 }
end
# show as text
$ pprof.rb --text /tmp/my_app_profile
# show as gif
$ pprof.rb --gif /tmp/my_app_profile > /tmp/my_app_profile.gif
# if that fails,
$ brew install graphviz ghostscript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment