JRuby::Profiler::CallgrindPrinter

Summary

This gem provides the similar functionality to that of ruby-prof's RubyProf::CallTreePrinter, but for the JRuby's Profiler. Specifically, JRuby::Profiler::CallgrindPrinter will produce 'callgrind' formatted output for analysis in any tool that understands Valgrind's 'callgrind' file format, such as KCacheGrind and QCacheGrind.

CallgrindPrinter has been written in pure-ruby, as opposed to Java, simply to see if it was possible (and it was).

Usage

For a runnable example, see examples/example1.rb.

Generally, you would do something like the following:

require 'jruby/profiler'
require 'jruby/profiler/callgrind_printer'

result = JRuby::Profiler.profile do 
  # Do some expensive stuff.
end

printer = JRuby::Profiler::CallgrindPrinter.new(result)
File.open("callgrind.out", "w") do |fio|
  printer.printHeader(fio)
  printer.printProfile(fio)
  printer.printFooter(fio)
end

and then run the above with 'jruby --profile.api your_code.rb'. You can then open up 'callgrind.out' with Kcachegrind or Qcachegrind.

Important!

The jruby profiler is disabled by default. You must run jruby with the '--profile.api' switch in order for any data to be gathered. Something along the lines of 'jruby --profile.api some_script.rb'

If you don't enable the profiler, everything will run fine, but it will seem as though no data is being gathered, and somewhat empty outputs will be produced.