Skip to content

Instantly share code, notes, and snippets.

@kares
Forked from danlucraft/jruby-profile-to-string.rb
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kares/9948938 to your computer and use it in GitHub Desktop.
Save kares/9948938 to your computer and use it in GitHub Desktop.
printing JRuby profiler data output (examples)
require 'jruby/profiler'
profile_data = JRuby::Profiler.profile do
# code to be profiled....
end
# print data in flat format to STDOUT :
profile_printer = JRuby::Profiler::FlatProfilePrinter.new(profile_data)
profile_printer.printProfile(STDOUT)
# print the data to a string in graph format :
my_output_stream = java.io.ByteArrayOutputStream.new
print_stream = java.io.PrintStream.new(my_output_stream)
profile_printer = JRuby::Profiler::GraphProfilePrinter.new(profile_data)
profile_printer.printProfile(print_stream)
result = my_output_stream.toString # Ruby String might puts to File etc.
# print the data directly to an output File in html format :
append = false
my_output_stream = java.io.FileOutputStream('/home/kares/profile.out', append)
print_stream = java.io.PrintStream.new(my_output_stream)
profile_printer = JRuby::Profiler::HtmlProfilePrinter.new(profile_data)
profile_printer.printProfile(print_stream)
my_output_stream.flush # to make sure it gets written down
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment