Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.