【问题标题】:How can I profile Ruby code in 1.9.2?如何在 1.9.2 中分析 Ruby 代码?
【发布时间】:2011-03-08 21:50:37
【问题描述】:

在 1.9.2 中我可以使用什么来分析代码?我发现 ruby​​-prof 的所有版本都针对 1.9.2 存在段错误。

例如,当我添加时

gem "ruby-prof"

到我的 Rails 项目的 Gemfile 并运行

bundle
bundle exec ruby-prof config/environment.rb

我遇到了段错误。

镇上有没有新的分析宝石?有没有办法让 ruby​​-prof 玩得更好?

【问题讨论】:

  • 当你没有gem "ruby-prof"但运行捆绑命令时它不会出现段错误?
  • 好吧,如果捆绑包中没有ruby-prof,那么我不能bundle exec ruby-prof。但是bundle exec ruby config/environment.rb 没有段错误。

标签: ruby profiling ruby-prof


【解决方案1】:

不确定它是否有帮助,但我偶然发现了这一点,这可能会增加一点清晰度或引导您走不同的道路: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 的 Aman 有一个用于 Ruby 的 google-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`
    

    【讨论】:

      【解决方案3】:

      您可以使用另一个流行的分析工具 - MethodProfiler

      在目标类中查找慢方法非常方便。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-05-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-16
        • 1970-01-01
        相关资源
        最近更新 更多