How to use the Ruby stdlib profiler with Jruby?
I am trying to use Ruby's standard lib profiler, and I am not using ruby-prof because this is a jruby project.
Though, I am allways getting something like:
% cumulative self self total
time seconds seconds calls ms/call ms/call name
0.00 0.93 开发者_如何学C 0.00 1 0.00 930.00 #toplevel
The code that generates this is:
require 'profiler'
Profiler__.start_profile
# profiling_result = RubyProf.profile do
result= handle_request
# end
#Profiler__.stop_profile
# printer = RubyProf::FlatPrinter.new(result)
File.open("#{File.dirname(__FILE__)}/profiler/#{Time.now.to_i}.flat","w") do |f|
Profiler__.print_profile f
end
Profiler__.stop_profile
I would strongly recommend using the JRuby built-in profiler, detailed here: http://danlucraft.com/blog/2011/03/built-in-profiler-in-jruby-1.6/
The stdlib profiler uses feature of Ruby that incur a tremendous perf hit (set_trace_func, among others). You'll get better results using the built-in profiler, which avoids such overhead.
精彩评论