分析Cucumber测试(ruby/rails)

4

与Cucumber测试相关的Profiler/分析问题。

我们的其中一个Cucumber测试运行速度相当缓慢。我不想猜测应用程序花费时间的位置,而是想以编程方式知道。

我如何使用分析器触发Cucumber测试???

未成功的尝试:

  $ 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

这会给出一个结果,但我必须猜测这个方法是瓶颈。(我正在使用cucumber 0.3.94、rails 2.3.2、ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9.6.0])
3个回答

8

还可以尝试使用cucumber --format usage命令获取一些关于最慢步骤的统计信息。


使用cucumber --format profile命令可以告诉我哪些场景(和步骤)运行缓慢。由于有许多费用报告,我已经知道这一步是问题的根本原因:1.8471970 Given I manage 45 projects with 1 expense reports of 100 DKK # features/manager_overview.feature:37现在,最有趣的部分是我的应用程序在哪里使用了时间! - Jesper Rønn-Jensen
8
FYI,看起来 --format profile 现在已更名为 --format usage - John

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行的单个cucumber场景,但结果并不特别有用。


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

我喜欢你的方法,但不幸的是它只让我集中在我认为问题可能出现的地方。我希望有一种更通用的方法,可以像Hudson这样的CI工具一样运行。 - Jesper Rønn-Jensen
1
我不确定在CI服务器上进行分析的价值。无论如何,您需要一个人来阅读分析数据才能从中获得任何有用的信息。 - troelskn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接