Ruby profiler堆栈级别太深错误

wro*_*ame 4 ruby profiler ruby-prof

好像我总是在我的一个脚本上出现这个错误:

/Users/amosng/.rvm/gems/ruby-1.9.3-p194/gems/ruby-prof-0.11.2/lib/ruby-prof/profile.rb:25: stack level too deep (SystemStackError)
Run Code Online (Sandbox Code Playgroud)

有没有人遇到此错误?可能导致它的原因,以及我可以采取哪些措施来防止它发生?

我使用命令运行我的ruby-prof脚本

ruby-prof --printer=graph --file=profile.txt scraper.rb -- "fall 2012"
Run Code Online (Sandbox Code Playgroud)

编辑我在Mac OS X上,如果这很重要.ulimit -s 64000不幸的是,做起来似乎没什么帮助.这是ulimit -a给出的:

$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 256
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 64000
cpu time               (seconds, -t) unlimited
max user processes              (-u) 709
virtual memory          (kbytes, -v) unlimited
Run Code Online (Sandbox Code Playgroud)

编辑2

Andrew Grimm的解决方案可以很好地防止ruby-prof崩溃,但是分析器似乎有自己的问题,因为我看到百分比占流程总时间的679.50%......

And*_*imm 6

一种解决方法是打开尾部调用优化.

以下是与TCO配合使用的示例,但在TCO关闭时不起作用.

RubyVM::InstructionSequence.compile_option = {
  :tailcall_optimization => true,
  :trace_instruction => false
}

def countUpTo(current, final)
  puts current
  return nil if current == final
  countUpTo(current+1, final)
end

countUpTo(1, 10_000)
Run Code Online (Sandbox Code Playgroud)

  • 链接死了:"海报空间不再可用" (2认同)