Code Profiling

Snippet to make a useful encapsulation in Rails apps.

config/initializers/rubyprof.rb:

1
2
3
4
5
6
7
8
9
10
11
12
13
class Prof
  def self.callstack(filename='callstack.html')
    result = nil
    profile = RubyProf.profile do
      result = yield
    end
    report = RubyProf::CallStackPrinter.new(profile)
    File.open(filename, 'w') do |file|
      report.print(file)
    end
    result
  end
end

About

Avatar of Author

Jamie Macey is a senior software engineer with over 15 years experience in the Ruby and Rails ecosystems, largely on the back-end.

Husband, father, gamer, and all-around geek. Ask about my latest 3d print, or toy software project.