Records the time spent per filter and per item representation
@see Listener#enable_for?
# File lib/nanoc/cli/commands/compile.rb, line 158 def self.enable_for?(command_runner) command_runner.options.fetch(:verbose, false) end
@option params [Array<Nanoc::ItemRep>] :reps The list of item representations in the site
# File lib/nanoc/cli/commands/compile.rb, line 163 def initialize(params={}) @filter_times = {} @reps = params.fetch(:reps) end
@see Listener#start
# File lib/nanoc/cli/commands/compile.rb, line 170 def start Nanoc::NotificationCenter.on(:filtering_started) do |rep, filter_name| @filter_times[filter_name] ||= [] @filter_times[filter_name] << Time.now end Nanoc::NotificationCenter.on(:filtering_ended) do |rep, filter_name| @filter_times[filter_name] << Time.now - @filter_times[filter_name].pop end end
@see Listener#stop
# File lib/nanoc/cli/commands/compile.rb, line 181 def stop super self.print_profiling_feedback end
# File lib/nanoc/cli/commands/compile.rb, line 188 def print_profiling_feedback # Get max filter length max_filter_name_length = @filter_times.keys.map { |k| k.to_s.size }.max return if max_filter_name_length.nil? # Print warning if necessary if @reps.any? { |r| !r.compiled? } $stderr.puts $stderr.puts "Warning: profiling information may not be accurate because " + "some items were not compiled." end # Print header puts puts ' ' * max_filter_name_length + ' | count min avg max tot' puts '-' * max_filter_name_length + '-+-----------------------------------' @filter_times.to_a.sort_by { |r| r[1] }.each do |row| self.print_row(row) end end
# File lib/nanoc/cli/commands/compile.rb, line 210 def print_row(row) # Extract data filter_name, samples = *row # Calculate stats count = samples.size min = samples.min tot = samples.inject { |memo, i| memo + i} avg = tot/count max = samples.max # Format stats count = format('%4d', count) min = format('%4.2f', min) avg = format('%4.2f', avg) max = format('%4.2f', max) tot = format('%5.2f', tot) # Output stats filter_name = format("%#{max}s", filter_name) puts "#{filter_name} | #{count} #{min}s #{avg}s #{max}s #{tot}s" end
Generated with the Darkfish Rdoc Generator 2.