Class: Nanoc::CLI::Commands::Compile::TimingRecorder

Inherits:
Listener
  • Object
show all
Defined in:
lib/nanoc/cli/commands/compile.rb

Overview

Records the time spent per filter and per item representation

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (TimingRecorder) initialize(params = {})

Returns a new instance of TimingRecorder

Parameters:

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):



157
158
159
160
161
# File 'lib/nanoc/cli/commands/compile.rb', line 157

def initialize(params = {})
  @times = {}

  @reps = params.fetch(:reps)
end

Class Method Details

+ (Boolean) enable_for?(command_runner)

Returns:

  • (Boolean)

See Also:

  • Listener#enable_for?


152
153
154
# File 'lib/nanoc/cli/commands/compile.rb', line 152

def self.enable_for?(command_runner)
  command_runner.options.fetch(:verbose, false)
end

Instance Method Details

- (Object) start

See Also:



164
165
166
167
168
169
170
171
172
# File 'lib/nanoc/cli/commands/compile.rb', line 164

def start
  Nanoc::NotificationCenter.on(:filtering_started) do |_rep, filter_name|
    @times[filter_name] ||= []
    @times[filter_name] << { start: Time.now }
  end
  Nanoc::NotificationCenter.on(:filtering_ended) do |_rep, filter_name|
    @times[filter_name].last[:stop] = Time.now
  end
end

- (Object) stop

See Also:



175
176
177
178
# File 'lib/nanoc/cli/commands/compile.rb', line 175

def stop
  print_profiling_feedback
  super
end