Collect partial benchmarks to be logged when they’re all done.
These are always low-level debugging so we only
print them if time_debug is enabled.
# File lib/puppet/rails/benchmark.rb, line 30 def accumulate_benchmark(message, label) return yield unless time_debug? $benchmarks[:accumulated][message] ||= Hash.new(0) $benchmarks[:accumulated][message][label] += Benchmark.realtime { yield } end
# File lib/puppet/rails/benchmark.rb, line 20 def debug_benchmark(message) return yield unless Puppet::Rails::TIME_DEBUG railsmark(message) { yield } end
Log the accumulated marks.
# File lib/puppet/rails/benchmark.rb, line 38 def log_accumulated_marks(message) return unless time_debug? return if $benchmarks[:accumulated].empty? or $benchmarks[:accumulated][message].nil? or $benchmarks[:accumulated][message].empty? $benchmarks[:accumulated][message].each do |label, value| Puppet.debug(message + ("(#{label})") + (" in %0.2f seconds" % value)) end end
# File lib/puppet/rails/benchmark.rb, line 11 def railsmark(message) result = nil seconds = Benchmark.realtime { result = yield } Puppet.debug(message + " in %0.2f seconds" % seconds) $benchmarks[message] = seconds if time_debug? result end
# File lib/puppet/rails/benchmark.rb, line 7 def time_debug? Puppet::Rails::TIME_DEBUG end
# File lib/puppet/rails/benchmark.rb, line 48 def write_benchmarks return unless time_debug? branch = %x{git branch}.split("\n").find { |l| l =~ /^\*/ }.sub("* ", '') file = "/tmp/time_debugging.yaml" if FileTest.exist?(file) data = YAML.load_file(file) else data = {} end data[branch] = $benchmarks Puppet::Util.replace_file(file, 0644) { |f| f.print YAML.dump(data) } end