Last active
August 29, 2015 14:20
-
-
Save nertzy/914d7009509a6c1054bc to your computer and use it in GitHub Desktop.
CallgrindProfiler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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