为什么 ruby-prof 将 "Kernel#`" 列为资源占用者?
Why does ruby-prof list "Kernel#`" as a resource hog?
我正在使用 ruby-prof
找出我在 Ruby 中构建的小型 2D 游戏引擎的 CPU 时间。除了主要的 Kernel#`
条目外,这里的一切看起来都很正常。 Ruby 文档 here 表明这是一个用于在子 shell 中获取命令 运行 的 STDOUT 的函数:
Measure Mode: wall_time
Thread ID: 7966920
Fiber ID: 16567620
Total: 7.415271
Sort by: self_time
%self total self wait child calls name
28.88 2.141 2.141 0.000 0.000 476 Kernel#`
10.72 1.488 0.795 0.000 0.693 1963500 Tile#draw
9.35 0.693 0.693 0.000 0.000 1963976 Gosu::Image#draw
6.67 7.323 0.495 0.000 6.828 476 Gosu::Window#_tick
1.38 0.102 0.102 0.000 0.000 2380 Gosu::Font#draw
0.26 4.579 0.019 0.000 4.560 62832 *Array#each
0.15 0.011 0.011 0.000 0.000 476 Gosu::Window#caption=
0.09 6.873 0.007 0.000 6.867 476 PlayState#draw
0.07 0.005 0.005 0.000 0.000 476 String#gsub
0.06 2.155 0.004 0.000 2.151 476 GameWindow#memory_usage
0.06 4.580 0.004 0.000 4.576 1904 Hash#each
0.04 0.003 0.003 0.000 0.000 476 String#chomp
0.04 0.038 0.003 0.000 0.035 476 Gosu::Window#protected_update
0.04 0.004 0.003 0.000 0.001 3167 Gosu::Window#button_down?
0.04 0.005 0.003 0.000 0.002 952 Enumerable#map
0.03 0.015 0.003 0.000 0.012 476 Player#update
0.03 4.596 0.002 0.000 4.593 476 <Module::Gosu>#scale
0.03 0.002 0.002 0.000 0.000 5236 Fixnum#to_s
0.03 7.326 0.002 0.000 7.324 476 Gosu::Window#tick
0.03 0.003 0.002 0.000 0.001 952 Player#coord_facing
0.03 4.598 0.002 0.000 4.597 476 <Module::Gosu>#translate
0.02 0.002 0.002 0.000 0.000 952 Array#reject
关于为什么会发生这种情况有什么建议吗?我相当有信心我没有在我的代码中使用它——除非它以某种方式被间接调用。不知道从哪里开始寻找这类东西。
我的问题已经解决了。考虑到我在问题中链接的 ruby 文档,虽然我不是很清楚,但问题的根源是 ruby-prof
如何对 #{}
快捷方式的用法进行分类,也称为'string interpolation'。我在这些快捷方式中执行了半密集调试逻辑。
关闭我的调试文本解决了我的问题。
我正在使用 ruby-prof
找出我在 Ruby 中构建的小型 2D 游戏引擎的 CPU 时间。除了主要的 Kernel#`
条目外,这里的一切看起来都很正常。 Ruby 文档 here 表明这是一个用于在子 shell 中获取命令 运行 的 STDOUT 的函数:
Measure Mode: wall_time
Thread ID: 7966920
Fiber ID: 16567620
Total: 7.415271
Sort by: self_time
%self total self wait child calls name
28.88 2.141 2.141 0.000 0.000 476 Kernel#`
10.72 1.488 0.795 0.000 0.693 1963500 Tile#draw
9.35 0.693 0.693 0.000 0.000 1963976 Gosu::Image#draw
6.67 7.323 0.495 0.000 6.828 476 Gosu::Window#_tick
1.38 0.102 0.102 0.000 0.000 2380 Gosu::Font#draw
0.26 4.579 0.019 0.000 4.560 62832 *Array#each
0.15 0.011 0.011 0.000 0.000 476 Gosu::Window#caption=
0.09 6.873 0.007 0.000 6.867 476 PlayState#draw
0.07 0.005 0.005 0.000 0.000 476 String#gsub
0.06 2.155 0.004 0.000 2.151 476 GameWindow#memory_usage
0.06 4.580 0.004 0.000 4.576 1904 Hash#each
0.04 0.003 0.003 0.000 0.000 476 String#chomp
0.04 0.038 0.003 0.000 0.035 476 Gosu::Window#protected_update
0.04 0.004 0.003 0.000 0.001 3167 Gosu::Window#button_down?
0.04 0.005 0.003 0.000 0.002 952 Enumerable#map
0.03 0.015 0.003 0.000 0.012 476 Player#update
0.03 4.596 0.002 0.000 4.593 476 <Module::Gosu>#scale
0.03 0.002 0.002 0.000 0.000 5236 Fixnum#to_s
0.03 7.326 0.002 0.000 7.324 476 Gosu::Window#tick
0.03 0.003 0.002 0.000 0.001 952 Player#coord_facing
0.03 4.598 0.002 0.000 4.597 476 <Module::Gosu>#translate
0.02 0.002 0.002 0.000 0.000 952 Array#reject
关于为什么会发生这种情况有什么建议吗?我相当有信心我没有在我的代码中使用它——除非它以某种方式被间接调用。不知道从哪里开始寻找这类东西。
我的问题已经解决了。考虑到我在问题中链接的 ruby 文档,虽然我不是很清楚,但问题的根源是 ruby-prof
如何对 #{}
快捷方式的用法进行分类,也称为'string interpolation'。我在这些快捷方式中执行了半密集调试逻辑。
关闭我的调试文本解决了我的问题。