less than 1 minute read

Some time ago I spoke about Flamegraph, but only recently found that there’s better way to generate it for ruby:

USAGE:

1. add gem 'stackprof' to your Gemfile

2.

# HINT: play with `ignore_gc` and `aggregate` options (both boolean)
StackProf.run(mode: :wall, raw: true, ignore_gc: true, out: 'tmp/stackprof-cpu-myapp.dump') do 
  # do some heavy work
end

3. EITHER

use stackcollapse option + flamegraph.pl

stackprof --stackcollapse tmp/stackprof-cpu-myapp.dump > tmp/stackcollapse
stackprof-flamegraph.pl tmp/stackcollapse > tmp/real-flamegraph.html # (this will produce an HTML file, ready to be open)

OR

use stackcollapse option + speedscope service

  • stackprof --stackcollapse tmp/stackprof-cpu-myapp.dump > tmp/stackcollapse
  • open speedscope.app , drag&drop tmp/stackcollapse, switch to Left Heavy tab at the top left corner

OR

use d3-flamegraph

# (this will produce an HTML file, ready to be open)
stackprof --d3-flamegraph tmp/stackprof-cpu-myapp.dump > tmp/d3-flamegraph.html

OR

use alphabetical flamegraph

stackprof --alphabetical-flamegraph tmp/stackprof-cpu-myapp.dump > tmp/alpha-flamegraph
stackprof --flamegraph-viewer=tmp/alpha-flamegraph # then open the URL Stackprof gives you and enjoy!

TIP: other possible options