summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-06-06 11:21:51 -0700
committerJohn Keiser <john@johnkeiser.com>2015-06-06 11:21:51 -0700
commit3d2b4e6751e3eaa05a0e10ffab881bb03e75244c (patch)
treee2ed0d8e24c5b2681a4387363c6c76e865455b8a
parent20f7e1c78c55d2a16d5033bc2bbe5904d225adb0 (diff)
downloadchef-jk/profile.tar.gz
Add profiling support to Chefjk/profile
-rw-r--r--Gemfile1
-rw-r--r--spec/spec_helper.rb21
-rw-r--r--spec/unit/recipe_spec.rb2
3 files changed, 23 insertions, 1 deletions
diff --git a/Gemfile b/Gemfile
index d3da2919da..373ce59848 100644
--- a/Gemfile
+++ b/Gemfile
@@ -13,6 +13,7 @@ group(:development, :test) do
gem "simplecov"
gem 'rack', "~> 1.5.1"
gem 'cheffish', "~> 1.2"
+ gem 'rspec-prof'
gem 'ruby-shadow', :platforms => :ruby unless RUBY_PLATFORM.downcase.match(/(aix|cygwin)/)
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index dcf244c3cc..ffef54fe70 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -190,6 +190,27 @@ RSpec.configure do |config|
end
end
+require 'ruby-prof'
+
+RSpec.configure do |c|
+ def profile(example)
+ result = RubyProf.profile { yield }
+ name = example.metadata[:full_description].downcase.gsub(/[^a-z0-9_-]/, "-").gsub(/-+/, "-")
+ printer = RubyProf::CallTreePrinter.new(result)
+ open("/Users/jkeiser/src/chef/profiles/callgrind.#{name}.#{Time.now.to_i}.trace", "w") do |f|
+ printer.print(f)
+ end
+ end
+
+ c.around(:each) do |example|
+ if ENV['PROFILE'] == 'all' or (example.metadata[:profile] and ENV['PROFILE'])
+ profile(example) { example.run }
+ else
+ example.run
+ end
+ end
+end
+
require 'webrick/utils'
# Webrick uses a centralized/synchronized timeout manager. It works by
diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb
index 72d5cc6f63..a811d9d002 100644
--- a/spec/unit/recipe_spec.rb
+++ b/spec/unit/recipe_spec.rb
@@ -22,7 +22,7 @@
require 'spec_helper'
require 'chef/platform/resource_priority_map'
-describe Chef::Recipe do
+describe Chef::Recipe, :profile do
let(:cookbook_repo) { File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks")) }