Class: Chef::Handler::SlowReport
Instance Attribute Summary collapse
#run_status
Instance Method Summary
collapse
#action_collection, #all_resources, #data, exception_handlers, #failed_resources, handler_for, report_handlers, resolve_handler_instance, run_exception_handlers, run_report_handlers, #run_report_safely, #run_report_unsafe, run_start_handlers, #skipped_resources, start_handlers, #unprocessed_resources, #up_to_date_resources, #updated_resources
Constructor Details
#initialize(amount) ⇒ SlowReport
Returns a new instance of SlowReport.
26
27
28
29
|
# File 'lib/chef/handler/slow_report.rb', line 26
def initialize(amount)
@amount = Integer(amount) rescue nil
@amount ||= 10
end
|
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
24
25
26
|
# File 'lib/chef/handler/slow_report.rb', line 24
def amount
@amount
end
|
Instance Method Details
#all_records ⇒ Object
51
52
53
|
# File 'lib/chef/handler/slow_report.rb', line 51
def all_records
@all_records ||= action_collection&.filtered_collection(unprocessed: false) || []
end
|
#count ⇒ Object
55
56
57
58
|
# File 'lib/chef/handler/slow_report.rb', line 55
def count
num = all_resources.count
num > amount ? amount : num
end
|
#report ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/chef/handler/slow_report.rb', line 31
def report
if count == 0
puts "\nNo resources to profile\n\n"
return
end
top = all_records.sort_by(&:elapsed_time).last(amount).reverse
data = top.map { |r| [ r.new_resource.to_s, r.elapsed_time, r.action, r.new_resource.cookbook_name, r.new_resource.recipe_name, stripped_source_line(r.new_resource) ] }
puts "\nTop #{count} slowest #{count == 1 ? "resource" : "resources"}:\n\n"
table = TTY::Table.new(%w{resource elapsed_time action cookbook recipe source}, data)
rendered = table.render do |renderer|
renderer.border do
mid "-"
mid_mid " "
end
end
puts rendered
puts "\n"
end
|
#stripped_source_line(resource) ⇒ Object
60
61
62
63
|
# File 'lib/chef/handler/slow_report.rb', line 60
def stripped_source_line(resource)
resource.source_line&.gsub(%r{.*/cookbooks/}, "")&.gsub(%r{.*/chef-[0-9\.]+/}, "")
end
|