Class: Chef::Handler::Profiler

Inherits:
Chef::Handler show all
Defined in:
lib/chef/handler/chef_profiler.rb

Constant Summary collapse

VERSION =
'0.0.2'

Instance Method Summary collapse

Instance Method Details

#reportObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/chef/handler/chef_profiler.rb', line 14

def report
  cookbooks = Hash.new(0)
  recipes = Hash.new(0)
  resources = Hash.new(0)

  # collect all profiled timings and group by type
  all_resources.each do |r|
    cookbooks[r.cookbook_name] += r.elapsed_time
    recipes["#{r.cookbook_name}::#{r.recipe_name}"] += r.elapsed_time
    resources["#{r.resource_name}[#{r.name}]"] = r.elapsed_time
  end

  # print each timing by group, sorting with highest elapsed time first
  Chef::Log.debug "Elapsed_time  Cookbook"
  Chef::Log.debug "------------  -------------"
  cookbooks.sort_by{ |k,v| -v }.each do |cookbook, run_time|
    Chef::Log.debug "%12f  %s" % [run_time, cookbook]
  end
  Chef::Log.debug ""

  Chef::Log.debug "Elapsed_time  Recipe"
  Chef::Log.debug "------------  -------------"
  recipes.sort_by{ |k,v| -v }.each do |recipe, run_time|
    Chef::Log.debug "%12f  %s" % [run_time, recipe]
  end
  Chef::Log.debug ""

  Chef::Log.debug "Elapsed_time  Resource"
  Chef::Log.debug "------------  -------------"
  resources.sort_by{ |k,v| -v }.each do |resource, run_time|
    Chef::Log.debug "%12f  %s" % [run_time, resource]
  end
  Chef::Log.debug ""
end