poise-profiler 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +60 -16
  3. data/CHANGELOG.md +6 -0
  4. data/Gemfile +1 -1
  5. data/README.md +1 -1
  6. data/lib/poise_profiler.rb +2 -1
  7. data/lib/poise_profiler/base.rb +121 -0
  8. data/lib/poise_profiler/cheftie.rb +4 -20
  9. data/lib/poise_profiler/config.rb +68 -0
  10. data/lib/poise_profiler/core_ext.rb +19 -0
  11. data/lib/poise_profiler/core_ext/cookbook_version.rb +42 -0
  12. data/lib/poise_profiler/core_ext/dispatcher.rb +45 -0
  13. data/lib/poise_profiler/core_ext/event_base.rb +41 -0
  14. data/lib/poise_profiler/core_ext/run_context.rb +53 -0
  15. data/lib/poise_profiler/{handler.rb → timing.rb} +7 -41
  16. data/lib/poise_profiler/version.rb +1 -1
  17. data/test/gemfiles/chef-12.0.gemfile +4 -0
  18. data/test/gemfiles/chef-12.1.gemfile +4 -0
  19. data/test/gemfiles/chef-12.10.gemfile +23 -0
  20. data/test/gemfiles/chef-12.11.gemfile +23 -0
  21. data/test/gemfiles/chef-12.12.gemfile +22 -0
  22. data/test/gemfiles/chef-12.13.gemfile +22 -0
  23. data/test/gemfiles/chef-12.14.gemfile +19 -0
  24. data/test/gemfiles/chef-12.15.gemfile +19 -0
  25. data/test/gemfiles/chef-12.16.gemfile +19 -0
  26. data/test/gemfiles/chef-12.17.gemfile +19 -0
  27. data/test/gemfiles/chef-12.18.gemfile +19 -0
  28. data/test/gemfiles/chef-12.19.gemfile +19 -0
  29. data/test/gemfiles/chef-12.2.gemfile +4 -0
  30. data/test/gemfiles/chef-12.3.gemfile +4 -0
  31. data/test/gemfiles/chef-12.4.gemfile +5 -2
  32. data/test/gemfiles/chef-12.5.gemfile +4 -0
  33. data/test/gemfiles/chef-12.6.gemfile +4 -0
  34. data/test/gemfiles/chef-12.7.gemfile +23 -0
  35. data/test/gemfiles/chef-12.8.gemfile +23 -0
  36. data/test/gemfiles/chef-12.9.gemfile +23 -0
  37. data/test/gemfiles/chef-12.gemfile +1 -1
  38. data/test/gemfiles/chef-13.0.gemfile +19 -0
  39. data/test/gemfiles/chef-13.gemfile +19 -0
  40. data/test/gemfiles/master.gemfile +1 -0
  41. data/test/spec/config_spec.rb +61 -0
  42. data/test/spec/integration_spec.rb +1 -1
  43. data/test/spec/{default_spec.rb → timing_spec.rb} +44 -10
  44. metadata +45 -7
@@ -0,0 +1,41 @@
1
+ #
2
+ # Copyright 2016, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/event_dispatch/base'
18
+ require 'chef/version'
19
+
20
+
21
+ module PoiseProfiler
22
+ module CoreExt
23
+ # Monkeypatch extensions for Chef::EventDispatch::Base to support the
24
+ # new recipe_loaded event.
25
+ #
26
+ # @since 1.1.0
27
+ # @api private
28
+ module EventBase
29
+ def recipe_loaded(recipe_name)
30
+ # This space left intentionally blank.
31
+ end
32
+
33
+ # Monkeypatch us in for ?. TODO THIS
34
+ if Gem::Version.create(Chef::VERSION) < Gem::Version.create('14')
35
+ Chef::EventDispatch::Base.include(self)
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+
@@ -0,0 +1,53 @@
1
+ #
2
+ # Copyright 2016, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/run_context'
18
+ require 'chef/version'
19
+
20
+
21
+ module PoiseProfiler
22
+ module CoreExt
23
+ # Monkeypatch extensions for Chef::RunContext to add support for the
24
+ # recipe_file_loaded event on older Chef.
25
+ #
26
+ # @since 1.1.0
27
+ # @api private
28
+ module RunContext
29
+ PRE_MAGIC_EVENTS = Gem::Version.create(Chef::VERSION) < Gem::Version.create('12.5.1')
30
+
31
+ def load_recipe(recipe_name, current_cookbook: nil)
32
+ super.tap do |ret|
33
+ cookbook_name, recipe_short_name = Chef::Recipe.parse_recipe_name(recipe_name, current_cookbook: current_cookbook)
34
+ cookbook = cookbook_collection[cookbook_name]
35
+ recipe_path = cookbook.recipe_filenames_by_name[recipe_short_name]
36
+ if PRE_MAGIC_EVENTS
37
+ events.recipe_file_loaded(recipe_path)
38
+ else
39
+ events.recipe_file_loaded(recipe_path, recipe_name)
40
+ end
41
+ end
42
+ end
43
+
44
+ # Monkeypatch us in for <12.14.53, which was the first build after
45
+ # https://github.com/chef/chef/commit/1c990a11ebe360f5e85ac13626ce1e09e295f919.
46
+ if Gem::Version.create(Chef::VERSION) < Gem::Version.create('12.14.53')
47
+ Chef::RunContext.prepend(self)
48
+ end
49
+
50
+ end
51
+ end
52
+ end
53
+
@@ -14,23 +14,13 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
- begin
18
- require 'chef/chef_class'
19
- rescue LoadError
20
- # ¯\_(ツ)_/¯ Chef < 12.3.
21
- end
22
- require 'chef/event_dispatch/base'
23
17
  require 'chef/json_compat'
24
18
 
19
+ require 'poise_profiler/base'
25
20
 
26
- module PoiseProfiler
27
- class Handler < Chef::EventDispatch::Base
28
- include Singleton
29
-
30
- # Used in {#monkey_patch_old_chef}
31
- # @api private
32
- attr_writer :events, :monkey_patched
33
21
 
22
+ module PoiseProfiler
23
+ class Timing < PoiseProfiler::Base
34
24
  def resource_completed(resource)
35
25
  key = resource.resource_name.to_s.end_with?('_test') ? :test_resources : :resources
36
26
  timers[key]["#{resource.resource_name}[#{resource.name}]"] += resource.elapsed_time
@@ -38,12 +28,12 @@ module PoiseProfiler
38
28
  end
39
29
 
40
30
  def run_completed(node)
41
- Chef::Log.debug('Processing poise-profiler data')
42
- puts('Poise Profiler:')
31
+ Chef::Log.debug('Processing poise-profiler timing data')
32
+ puts('Poise Profiler Timing:')
43
33
  puts_timer(:resources, 'Resource')
44
34
  puts_timer(:test_resources, 'Test Resource') unless timers[:test_resources].empty?
45
35
  puts_timer(:classes, 'Class')
46
- puts("Profiler JSON: #{Chef::JSONCompat.to_json(timers)}") if ENV['CI'] || node['CI']
36
+ puts("Profiler JSON: #{Chef::JSONCompat.to_json(timers)}") if config.fetch('timing_json', ENV['CI'] || node['CI'])
47
37
  puts('')
48
38
  end
49
39
 
@@ -53,23 +43,7 @@ module PoiseProfiler
53
43
 
54
44
  def reset!
55
45
  timers.clear
56
- @events = nil
57
- end
58
-
59
- # Inject this instance for Chef < 12.3. Don't call this on newer Chef.
60
- def monkey_patch_old_chef!
61
- return if @monkey_patched
62
- require 'chef/event_dispatch/dispatcher'
63
- instance = self
64
- orig_method = Chef::EventDispatch::Dispatcher.instance_method(:library_file_loaded)
65
- Chef::EventDispatch::Dispatcher.send(:define_method, :library_file_loaded) do |filename|
66
- instance.events = self
67
- instance.monkey_patched = false
68
- @subscribers << instance
69
- Chef::EventDispatch::Dispatcher.send(:define_method, :library_file_loaded, orig_method)
70
- orig_method.bind(self).call(filename)
71
- end
72
- @monkey_patched = true
46
+ super
73
47
  end
74
48
 
75
49
  private
@@ -87,13 +61,5 @@ module PoiseProfiler
87
61
  puts ""
88
62
  end
89
63
 
90
- def puts(line)
91
- events.stream_output(:profiler, line+"\n")
92
- end
93
-
94
- def events
95
- @events ||= Chef.run_context.events
96
- end
97
-
98
64
  end
99
65
  end
@@ -16,5 +16,5 @@
16
16
 
17
17
 
18
18
  module PoiseProfiler
19
- VERSION = '1.0.1'
19
+ VERSION = '1.1.0'
20
20
  end
@@ -17,3 +17,7 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.0.3'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
22
+ gem 'fauxhai', '<= 3.9.0'
23
+ gem 'chefspec', '< 6'
@@ -17,3 +17,7 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.1.2'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
22
+ gem 'fauxhai', '<= 3.9.0'
23
+ gem 'chefspec', '< 6'
@@ -0,0 +1,23 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.10.24'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
22
+ gem 'fauxhai', '<= 3.9.0'
23
+ gem 'chefspec', '< 6'
@@ -0,0 +1,23 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.11.18'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
22
+ gem 'fauxhai', '<= 3.9.0'
23
+ gem 'chefspec', '< 6'
@@ -0,0 +1,22 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.12.15'
20
+ gem 'foodcritic', '< 8'
21
+ gem 'fauxhai', '<= 3.9.0'
22
+ gem 'chefspec', '< 6'
@@ -0,0 +1,22 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.13.37'
20
+ gem 'foodcritic', '< 8'
21
+ gem 'fauxhai', '<= 3.9.0'
22
+ gem 'chefspec', '< 6'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.14.89'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.15.19'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.16.42'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.17.44'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.18.31'
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.19.36'
@@ -17,3 +17,7 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.2.1'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
22
+ gem 'fauxhai', '<= 3.9.0'
23
+ gem 'chefspec', '< 6'
@@ -17,3 +17,7 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.3.0'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
22
+ gem 'fauxhai', '<= 3.9.0'
23
+ gem 'chefspec', '< 6'
@@ -17,5 +17,8 @@
17
17
  eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
18
 
19
19
  gem 'chef', '~> 12.4.3'
20
- # Pending https://github.com/berkshelf/ridley/pull/335
21
- gem 'ridley', '4.4.1'
20
+ gem 'rack', '< 2'
21
+ gem 'foodcritic', '< 8'
22
+ gem 'fauxhai', '<= 3.9.0'
23
+ gem 'chefspec', '< 6'
24
+ gem 'gh', '0.14.0'