class Nanoc::CLI::Commands::Compile::TimingRecorder

Records the time spent per filter and per item representation

Public Class Methods

enable_for?(command_runner) click to toggle source

@see Listener#enable_for?

# File lib/nanoc/cli/commands/compile.rb, line 144
def self.enable_for?(command_runner)
  command_runner.options.fetch(:verbose, false)
end
new(reps:) click to toggle source

@param [Enumerable<Nanoc::Int::ItemRep>] reps

# File lib/nanoc/cli/commands/compile.rb, line 149
def initialize(reps))
  @times = {}

  @reps = reps
end

Public Instance Methods

start() click to toggle source

@see Nanoc::CLI::Commands::Compile::Listener#start

# File lib/nanoc/cli/commands/compile.rb, line 156
def start
  Nanoc::Int::NotificationCenter.on(:filtering_started) do |_rep, filter_name|
    @times[filter_name] ||= []
    @times[filter_name] << { start: Time.now }
  end
  Nanoc::Int::NotificationCenter.on(:filtering_ended) do |_rep, filter_name|
    @times[filter_name].last[:stop] = Time.now
  end
end
stop() click to toggle source

@see Nanoc::CLI::Commands::Compile::Listener#stop

# File lib/nanoc/cli/commands/compile.rb, line 167
def stop
  print_profiling_feedback
  super
end

Protected Instance Methods

durations_for_filter(filter_name) click to toggle source
# File lib/nanoc/cli/commands/compile.rb, line 232
def durations_for_filter(filter_name)
  result = []
  @times[filter_name].each do |sample|
    if sample[:start] && sample[:stop]
      result << sample[:stop] - sample[:start]
    end
  end
  result
end
durations_per_filter() click to toggle source
# File lib/nanoc/cli/commands/compile.rb, line 219
def durations_per_filter
  @_durations_per_filter ||= begin
    result = {}
    @times.keys.each do |filter_name|
      durations = durations_for_filter(filter_name)
      if durations
        result[filter_name] = durations
      end
    end
    result
  end
end
print_profiling_feedback() click to toggle source
print_row(row, length) click to toggle source