使用ruby-prof的未定义方法'threads'

时间:2011-05-19 15:14:12

标签: ruby rubygems profiling benchmarking ruby-prof

我正在尝试使用ruby-prof来分析一些代码。它似乎一直工作到下面的行:

require 'rubygems'
require 'ruby-prof'
result = RubyProf.start do
  puts "do stuff..."
end

printer = RubyProf::FlatPrinter.new(result)
printer.print(STDOUT, {})  #fails here

错误:

hulkster@ubuntu:~/code/clancms$ ruby ./memtest.rb
/home/hulkster/.rvm/gems/ruby-1.9.2-p180/gems/ruby-prof-0.10.7/lib/ruby-prof/flat_printer.rb:31:in `print_threads': undefined method `threads' for RubyProf:Module (NoMethodError)
    from /home/hulkster/.rvm/gems/ruby-1.9.2-p180/gems/ruby-prof-0.10.7/lib/ruby-prof/flat_printer.rb:25:in `print'
    from ./memtest.rb:8:in `<main>'

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

您确定它应该是printer.print(STDOUT, {})而不是printer.print(STDOUT, 0)吗?

查看关闭垃圾收集是否有帮助。请参阅以下错误报告:https://github.com/rdp/ruby-prof/issues/80

另外,看看在Ruby 1.8(MRI)下运行它是否有帮助。

如果您可以生成更具体的错误报告,那也很有用。 :(

答案 1 :(得分:0)

我遇到了这个错误。您是否有可能在结果变量中隐藏/在代码中稍后将其分配给其他内容?确保&#34;结果&#34;您传入的实际上是RubyProf结果对象。