Module: Puppet::Rails::Benchmark
Instance Method Summary collapse
-
#accumulate_benchmark(message, label) ⇒ Object
Collect partial benchmarks to be logged when they’re all done.
- #debug_benchmark(message) ⇒ Object
-
#log_accumulated_marks(message) ⇒ Object
Log the accumulated marks.
- #railsmark(message) ⇒ Object
- #time_debug? ⇒ Boolean
- #write_benchmarks ⇒ Object
Instance Method Details
#accumulate_benchmark(message, label) ⇒ Object
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.
30 31 32 33 34 35 |
# File 'lib/vendor/puppet/rails/benchmark.rb', line 30 def accumulate_benchmark(, label) return yield unless time_debug? $benchmarks[:accumulated][] ||= Hash.new(0) $benchmarks[:accumulated][][label] += Benchmark.realtime { yield } end |
#debug_benchmark(message) ⇒ Object
20 21 22 23 24 |
# File 'lib/vendor/puppet/rails/benchmark.rb', line 20 def debug_benchmark() return yield unless Puppet::Rails::TIME_DEBUG railsmark() { yield } end |
#log_accumulated_marks(message) ⇒ Object
Log the accumulated marks.
38 39 40 41 42 43 44 45 46 |
# File 'lib/vendor/puppet/rails/benchmark.rb', line 38 def log_accumulated_marks() return unless time_debug? return if $benchmarks[:accumulated].empty? or $benchmarks[:accumulated][].nil? or $benchmarks[:accumulated][].empty? $benchmarks[:accumulated][].each do |label, value| Puppet.debug( + ("(#{label})") + (" in %0.2f seconds" % value)) end end |
#railsmark(message) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/vendor/puppet/rails/benchmark.rb', line 11 def railsmark() result = nil seconds = Benchmark.realtime { result = yield } Puppet.debug( + " in %0.2f seconds" % seconds) $benchmarks[] = seconds if time_debug? result end |
#time_debug? ⇒ Boolean
7 8 9 |
# File 'lib/vendor/puppet/rails/benchmark.rb', line 7 def time_debug? Puppet::Rails::TIME_DEBUG end |
#write_benchmarks ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vendor/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 |