# In your ./Gemfile:
gem 'stackprof', group: :test

# At top of ./spec/rails_helper.rb
if ENV['STACKPROF']
  require 'stackprof'
  StackProf.start(mode: :wall, raw: true, interval: 1000, out: 'tmp/stackprof-wall-test.dump')
  at_exit do
    StackProf.stop
    StackProf.results
  end
end

# Depending on size of test suite, the above may produce too much output, consider
# running it only on selected specs by passing the spec paths to `rspec`:

# Profile checkout feature specs only:
# STACKPROF=1 bin/rspec spec/features/checkout

# To view results table:
# bundle exec stackprof tmp/stackprof-wall-test.dump
#
# To view flamegraph:
# 1) Generate data
# bundle exec stackprof --flamegraph tmp/stackprof-wall-test.dump > tmp/flamegraph
# 2) Open flamegraph in browser
#    - NOTE: when Safari is used this may not copy over the querystring correctly
#            so check the URL generated by the below command and copy it manually
#            to your browser.
#    - May be slow to generate graph
# bundle exec stackprof --flamegraph-viewer=tmp/flamegraph
