Install test-prof
and stackprof
gems.
group :test do
gem "test-prof", "~> 1.0"
gem "stackprof", '>= 0.2.9', require: false
end
Run test with flag TEST_STACK_PROF=1
. Better to run only part of tests or use SAMPLE=10
flag, otherwise you could get too big of a stack dump.
TEST_STACK_PROF=1 bundle exec rspec spec/my_test.rb
Then you could visualize it.
Visualize with speedscope
Another way is to use speedscope, as it provides better interface. For this, generate json
output
stackprof --flamegraph tmp/test_prof/stack-prof-report-wall-raw-total.dump > tmp/test_prof/stack-prof-report-wall-raw-total.json
And upload the file to speedscope, e.g. at https://www.speedscope.app/
Visualize with stackprof's viewer
Then convert flamegraph dump to html
stackprof --flamegraph tmp/test_prof/stack-prof-report-wall-raw-total.dump > tmp/test_prof/stack-prof-report-wall-raw-total.html
Then you could see the flamegraph with gem's viewer. From inside docker you could copy flamegraph.js and viewer.html to same shared folder, e.g. tmp folder in project.
cp /usr/local/bundle/gems/stackprof-0.2.26/lib/stackprof/flamegraph/viewer.html ./tmp/test_prof/
cp /usr/local/bundle/gems/stackprof-0.2.26/lib/stackprof/flamegraph/flamegraph.js ./tmp/test_prof/
And then open in the browser url like
file:///home/my/path_to_project_folder/tmp/test_prof/viewer.html?data=/home/my/path_to_project_folder/tmp/test_prof/stack-prof-report-wall-raw-total.html
Links
- https://github.com/test-prof/test-prof Test-prof gem
- https://evilmartians.com/chronicles/testprof-a-good-doctor-for-slow-ruby-tests article about usage
Top comments (0)