Skip to content

快速开始

安装

test-prof gem 添加到你的应用:

ruby
group :test do
  gem "test-prof", "1.0.0.rc1"
end

完成!现在就可以使用 TestProf 的 profilers 了。

配置

大多数 profilers 使用的 TestProf 通用配置:

ruby
TestProf.configure do |config|
  # the directory to put artifacts (reports) in ('tmp/test_prof' by default)
  config.output_dir = "tmp/test_prof"

  # use unique filenames for reports (by simply appending current timestamp)
  config.timestamps = true

  # color output
  config.color = true
end

你也可以通过TEST_PROF_REPORT环境变量动态添加 artifacts/reports 后缀。

如果你没使用时间戳并想要用不同设置生成多个报告且比较它们时,就很有用。

例如,让我们使用stackprof来比较下测试用和不用bootsnap的加载时间:

sh
# Generate first report using `-with-bootsnap` suffix
$ TEST_STACK_PROF=boot TEST_PROF_REPORT=with-bootsnap bundle exec rake
$ #=> StackProf report generated: tmp/test_prof/stack-prof-report-wall-raw-boot-with-bootsnap.dump

# Assume that you disabled bootsnap and want to generate a new report
$ TEST_STACK_PROF=boot TEST_PROF_REPORT=no-bootsnap bundle exec rake
$ #=> StackProf report generated: tmp/test_prof/stack-prof-report-wall-raw-boot-no-bootsnap.dump

现在你就有了两个带清晰名称的 stackprof 报告!