剖析黄瓜测试(红宝石/铁轨)

时间:2009-08-12 11:45:26

标签: ruby-on-rails testing profiling cucumber profiler

Profiler / profiling与黄瓜测试相关的问题。

我们的黄瓜测试之一运行得相当慢。我不想猜测我们的应用程序花费时间在哪里,我想以编程方式知道。

如何使用分析器触发黄瓜测试???

什么行不通:

  $ URL=/projects/by/114951412 #URL to slow rails page
  $ script/performance/profiler 'app.get "$URL"' 50

这不起作用,因为'app.get'仅适用于控制台,不适用于探查器脚本

  $ EXPENSIVE_METHOD="Project.find('6300003243').aggregated_total_amount"
  $ script/performance/profiler "$EXPENSIVE_METHOD" 50

这给出了结果,但我不得不猜测这种方法是瓶颈

(我使用黄瓜0.3.94,导轨2.3.2,红宝石1.8.7(2008-08-11补丁级别72)[i686-darwin9.6.0])

3 个答案:

答案 0 :(得分:8)

还可以尝试使用cucumber --format用法来获取有关最慢步骤的统计信息。

答案 1 :(得分:3)

另外一个实验实际上是我的问题的答案,但没有给我但是并没有真正给我一个特别有用的结果

$ PROJECT_DIR=`pwd`
$ which cucumber
/usr/local/bin/cucumber
$ ln -s `which cucumber` cukes #required for profiler to have local file in next step
$ ruby-prof cukes -- features/manager_overview.feature:36

这实际上在第36行运行单一黄瓜情景,但结果并不是特别有用

答案 2 :(得分:2)

使用ruby-prof,您可以在主题代码之前启动探查器并在之后再次停止。例如:

require 'ruby-prof'
RubyProf.start
# code here
result = RubyProf.stop

# You can then output the trace in different ways.
# Simply print a overview to stdout
printer = RubyProf::FlatPrinter.new(result)
printer.print($stdout, :min_percent => 0.1)

# Save a callgrind trace
# You can load this up in kcachegrind or a compatible tool.
printer = RubyProf::CallTreePrinter.new(result)
File.open "callgrind.out.42", 'w' do |file|
  RubyProf::CallTreePrinter.new(result).print(file)
end