Ruby ruby-prof: Difference between revisions
From wikinotes
No edit summary |
No edit summary |
||
Line 9: | Line 9: | ||
|} | |} | ||
</blockquote><!-- Documentation --> | </blockquote><!-- Documentation --> | ||
= Example = | |||
<blockquote> | |||
<syntaxhighlight lang="yaml"> | |||
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! | |||
</syntaxhighlight> | |||
</blockquote><!-- Example --> |
Revision as of 15:47, 25 January 2023
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!