Skip to content

Instantly share code, notes, and snippets.

@leonelgalan
Created November 17, 2014 21:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonelgalan/a613c1d8e293f3219327 to your computer and use it in GitHub Desktop.
Save leonelgalan/a613c1d8e293f3219327 to your computer and use it in GitHub Desktop.
Using stackprof and rspec (Rails)
  1. Existing rspec-stackprof is "empty"
  2. stackprof is written as a replacement for perftools.rb
  3. Added an environment variable to conditionally run the profiler, it slows down test runtime by a couple of seconds for me.
  4. Just add stackprof.rb to your spec/support folder, which is loaded on rails_helper.rb
if ENV['STACKPROF']
require 'stackprof'
RSpec.configure do |config|
config.before :suite do
StackProf.start(mode: :cpu, interval: 1000, out: 'tmp/stackprof-cpu-myapp.dump')
end
config.after :suite do
StackProf.stop
StackProf.results
end
end
end
# STACKPROF=TRUE rspec
# stackprof tmp/stackprof-cpu-*.dump --text
@mjc
Copy link

mjc commented Oct 29, 2015

StackProf.start(mode: ENV['STACKPROF'].to_sym, interval: 1000, out: "tmp/stackprof-#{ENV['STACKPROF']}-myapp.dump") is way more useful, this way you can do STACKPROF=cpu or any other mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment