简体   繁体   中英

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      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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM