Skip to content

Instantly share code, notes, and snippets.

@mfrister
Last active August 31, 2015 06:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfrister/c0a834853c1c5b05a7af to your computer and use it in GitHub Desktop.
Save mfrister/c0a834853c1c5b05a7af to your computer and use it in GitHub Desktop.
Ruby Flamegraphs

ruby-prof Flamegraphs

ruby-prof

require 'ruby-prof'
require 'ruby-prof-flamegraph'
result = RubyProf.profile do

  # code to profile

end
printer = printer = RubyProf::FlameGraphPrinter.new(result)
File.open("tmp/flamegraph-data-#{DateTime.now.iso8601}", 'w') do |f|
  printer.print(f, {})
end

Gemfile

gem 'ruby-prof'
gem 'ruby-prof-flamegraph'

Analyze

cat $(ls -1tr tmp/flamegraph-* | tail -n1) | ~/src/FlameGraph/flamegraph.pl --countname=ms --width=728 | bcat

miniprof Flamegraphs

For use in Rack apps.

config.ru

require 'rack-mini-profiler'
require 'flamegraph'
use Rack::MiniProfiler

Gemfile

gem 'rack-mini-profiler'
gem 'flamegraph'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment