lib/nanoc/cli/commands/compile.rb in nanoc-3.4.0 vs lib/nanoc/cli/commands/compile.rb in nanoc-3.4.1
- old
+ new
@@ -48,13 +48,21 @@
time_before = Time.now
@rep_times = {}
@filter_times = {}
setup_notifications
+ # Set up progress indicator threads
+ @progress_locks = {}
+ @progress_threads = {}
+
# Prepare for generating diffs
setup_diffs
+ # Set up GC control
+ @gc_lock = Mutex.new
+ @gc_count = 0
+
# Compile
self.site.compile
# Find reps
reps = self.site.items.map { |i| i.reps }.flatten
@@ -70,11 +78,11 @@
# Stop diffing
teardown_diffs
# Prune
- if self.site.config[:auto_prune]
+ if self.site.config[:prune][:auto_prune]
Nanoc::Extra::Pruner.new(self.site).run
end
# Give general feedback
puts
@@ -104,12 +112,13 @@
end
# File notifications
Nanoc::NotificationCenter.on(:rep_written) do |rep, path, is_created, is_modified|
action = (is_created ? :create : (is_modified ? :update : :identical))
+ level = (is_created ? :high : (is_modified ? :high : :low))
duration = Time.now - @rep_times[rep.raw_path] if @rep_times[rep.raw_path]
- Nanoc::CLI::Logger.instance.file(:high, action, path, duration)
+ Nanoc::CLI::Logger.instance.file(level, action, path, duration)
end
# Debug notifications
if self.debug?
Nanoc::NotificationCenter.on(:compilation_started) do |rep|
@@ -142,10 +151,16 @@
end
end
# Timing notifications
Nanoc::NotificationCenter.on(:compilation_started) do |rep|
+ if @gc_count % 20 == 0 && !ENV.has_key?('TRAVIS')
+ GC.enable
+ GC.start
+ GC.disable
+ end
+ @gc_count += 1
@rep_times[rep.raw_path] = Time.now
end
Nanoc::NotificationCenter.on(:compilation_ended) do |rep|
@rep_times[rep.raw_path] = Time.now - @rep_times[rep.raw_path]
end
@@ -215,39 +230,45 @@
def start_filter_progress(rep, filter_name)
# Only show progress on terminals
return if !$stdout.tty?
- @progress_thread = Thread.new do
- delay = 1.0
- step = 0
+ @progress_locks[rep.inspect + filter_name.inspect] = lock = Mutex.new
+ lock.synchronize do
+ @progress_threads[rep.inspect + filter_name.inspect] = Thread.new do
+ delay = 1.0
+ step = 0
- text = "Running #{filter_name} filter… "
+ text = "Running #{filter_name} filter… "
- while !Thread.current[:stopped]
- sleep 0.1
+ while !Thread.current[:stopped]
+ sleep 0.1
- # Wait for a while before showing text
- delay -= 0.1
- next if delay > 0.05
+ # Wait for a while before showing text
+ delay -= 0.1
+ next if delay > 0.05
- # Print progress
- $stdout.print text + %w( | / - \\ )[step] + "\r"
- step = (step + 1) % 4
- end
+ # Print progress
+ $stdout.print text + %w( | / - \\ )[step] + "\r"
+ step = (step + 1) % 4
+ end
- # Clear text
- if delay < 0.05
- $stdout.print ' ' * (text.length + 1 + 1) + "\r"
+ # Clear text
+ if delay < 0.05
+ $stdout.print ' ' * (text.length + 1 + 1) + "\r"
+ end
end
end
end
def stop_filter_progress(rep, filter_name)
# Only show progress on terminals
return if !$stdout.tty?
- @progress_thread[:stopped] = true
+ lock = @progress_locks[rep.inspect + filter_name.inspect]
+ lock.synchronize do
+ @progress_threads[rep.inspect + filter_name.inspect][:stopped] = true
+ end
end
def print_profiling_feedback(reps)
# Get max filter length
max_filter_name_length = @filter_times.keys.map { |k| k.to_s.size }.max