Ruby ruby-prof

From wikinotes
Revision as of 15:47, 25 January 2023 by Will (talk | contribs)

A cross platform profiler for ruby.
dump to a file, then obtain reports like flamegraphs, call-trees, etc.

Documentation

official docs https://ruby-prof.github.io/

Example

1: Add 'ruby-prof' to Gemfile
2: bundle install
3: write file: |
  # foo.rb
  result = RubyProf.profile do
    # ... your code ...
  end

  printer = RubyProf::CallStackPrinter.new(result)
  Tempfile.create(["foo", ".html"]) do |fo|
    printer.print(fo)
    %x{open -a "Google Chrome.app" -W "#{fo.path}"}
  end

4: cat foo.rb | rails c
5: a colour-coded flamegraph!