2011-03-08 92 views
8

我可以使用什麼來剖析1.9.2中的代碼?所有ruby-prof的版本我都發現了1.9.2的segfault。如何在1.9.2中剖析Ruby代碼?

舉例來說,當我添加

gem "ruby-prof" 

我Rails項目的Gemfile中,然後運行

bundle 
bundle exec ruby-prof config/environment.rb 

,我收到了段錯誤。

鎮上有新的造型寶石嗎?有沒有辦法讓紅寶石教練玩好?

+0

當你沒有'gem「ruby-prof」'但是運行包命令時它不會發生段錯誤? – 2011-03-08 22:10:14

+0

那麼,如果我在捆綁中沒有'ruby-prof',那麼我就不能'捆綁exec ruby​​-prof'。但是'bundle exec ruby​​ config/environment.rb'不會segfault。 – Peeja 2011-03-09 03:44:32

回答

2

不知道它有幫助,但我偶然發現這可能會增加更多的清晰度或帶領你走上不同的道路:http://www.devheads.net/development/ruby/core/segmentation-fault-when-using-ruby-prof-and-ruby-192.htm。你可能想檢查出基於該線程的wycats的叉子:https://github.com/wycats/ruby-prof

另外,我還沒有嘗試過自己,它可能不是你正在尋找,但阿曼Github的聲譽有一個谷歌端口, Ruby的perftools: https://github.com/tmm1/perftools.rb

2

作爲@ chris.baglieri建議,您可以使用perftools.rb gem來分析Ruby 1.9代碼。

gem install perftools.rb 

然後

require 'perftools' 
PerfTools::CpuProfiler.start('profile_data') do 
    # something cpu-intensive 
end 
`pprof.rb --text profile_data profile.txt` 
`pprof.rb --pdf profile_data profile.pdf` 
2

您可以使用另一種流行的Profiler工具 - MethodProfiler

這是非常方便的找到目標類中緩慢方法。