Skip to content

Instantly share code, notes, and snippets.

@nertzy
Last active August 29, 2015 14:20
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 nertzy/914d7009509a6c1054bc to your computer and use it in GitHub Desktop.
Save nertzy/914d7009509a6c1054bc to your computer and use it in GitHub Desktop.
CallgrindProfiler
require 'jruby/profiler'
require 'jruby/profiler/callgrind_printer'
module CallgrindProfiler
def callgrind
unless JRuby.runtime.instance_config.is_profiling?
STDERR.puts 'Profiling not enabled, re-run with `ruby --profile.api`'
return
end
return_value = nil
profile = JRuby::Profiler.profile do
return_value = yield
end
File.open("callgrind.out-#{Time.now.to_i}", 'w') do |file|
printer = JRuby::Profiler::CallgrindPrinter.new(profile)
printer.printHeader(file)
printer.printProfile(file)
printer.printFooter(file)
end
return_value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment