Methods
public instance
Constants
| PROFILE_OPTIONS | = | { :measure_modes => [RubyProf::PROCESS_TIME], :count => 10, :printers => [RubyProf::FlatPrinter, RubyProf::GraphHtmlPrinter], :min_percent => 0.05, :output_dir => Dir.pwd } |
Public instance methods
format_profile_total
(total, measure_mode)
[show source]
# File lib/ruby-prof/test.rb, line 95 95: def format_profile_total(total, measure_mode) 96: case measure_mode 97: when RubyProf::PROCESS_TIME, RubyProf::WALL_TIME 98: "%.2f seconds" % total 99: when RubyProf::MEMORY 100: "%.2f kilobytes" % total 101: when RubyProf::ALLOCATIONS 102: "%d allocations" % total 103: else 104: "%.2f #{measure_mode}" 105: end 106: end
measure_mode_name
(measure_mode)
[show source]
# File lib/ruby-prof/test.rb, line 138 138: def measure_mode_name(measure_mode) 139: case measure_mode 140: when RubyProf::PROCESS_TIME; 'process_time' 141: when RubyProf::WALL_TIME; 'wall_time' 142: when RubyProf::MEMORY; 'memory' 143: when RubyProf::ALLOCATIONS; 'allocations' 144: else "measure#{measure_mode}" 145: end 146: end
output_dir
()
[show source]
# File lib/ruby-prof/test.rb, line 15 15: def output_dir 16: PROFILE_OPTIONS[:output_dir] 17: end
report_filename
(printer, measure_mode)
The report filename is test_name + measure_mode + report_type
[show source]
# File lib/ruby-prof/test.rb, line 125 125: def report_filename(printer, measure_mode) 126: suffix = 127: case printer 128: when RubyProf::FlatPrinter; 'flat.txt' 129: when RubyProf::GraphPrinter; 'graph.txt' 130: when RubyProf::GraphHtmlPrinter; 'graph.html' 131: when RubyProf::CallTreePrinter; 'tree.txt' 132: else printer.to_s.downcase 133: end 134: 135: "#{output_dir}/#{method_name}_#{measure_mode_name(measure_mode)}_#{suffix}" 136: end
report_profile
(data, measure_mode)
[show source]
# File lib/ruby-prof/test.rb, line 108 108: def report_profile(data, measure_mode) 109: PROFILE_OPTIONS[:printers].each do |printer_klass| 110: printer = printer_klass.new(data) 111: 112: # Makes sure the output directory exits 113: FileUtils.mkdir_p(output_dir) 114: 115: # Open the file 116: file_name = report_filename(printer, measure_mode) 117: 118: File.open(file_name, 'wb') do |file| 119: printer.print(file, PROFILE_OPTIONS) 120: end 121: end 122: end
run
(result) {|self.class::STARTED, name| ...}
[show source]
# File lib/ruby-prof/test.rb, line 19 19: def run(result) 20: return if @method_name.to_s == "default_test" 21: 22: yield(self.class::STARTED, name) 23: @_result = result 24: run_warmup 25: PROFILE_OPTIONS[:measure_modes].each do |measure_mode| 26: data = run_profile(measure_mode) 27: report_profile(data, measure_mode) 28: result.add_run 29: end 30: yield(self.class::FINISHED, name) 31: end
run_profile
(measure_mode)
[show source]
# File lib/ruby-prof/test.rb, line 63 63: def run_profile(measure_mode) 64: RubyProf.measure_mode = measure_mode 65: 66: print ' ' 67: PROFILE_OPTIONS[:count].times do |i| 68: run_test do 69: begin 70: print '.' 71: $stdout.flush 72: GC.disable 73: 74: RubyProf.resume do 75: __send__(@method_name) 76: end 77: ensure 78: GC.enable 79: end 80: end 81: end 82: 83: data = RubyProf.stop 84: bench = data.threads.values.inject(0) do |total, method_infos| 85: top = method_infos.sort.last 86: total += top.total_time 87: total 88: end 89: 90: puts "\n #{measure_mode_name(measure_mode)}: #{format_profile_total(bench, measure_mode)}\n" 91: 92: data 93: end
run_test
() {|| ...}
[show source]
# File lib/ruby-prof/test.rb, line 33 33: def run_test 34: begin 35: setup 36: yield 37: rescue ::Test::Unit::AssertionFailedError => e 38: add_failure(e.message, e.backtrace) 39: rescue StandardError, ScriptError 40: add_error($!) 41: ensure 42: begin 43: teardown 44: rescue ::Test::Unit::AssertionFailedError => e 45: add_failure(e.message, e.backtrace) 46: rescue StandardError, ScriptError 47: add_error($!) 48: end 49: end 50: end
run_warmup
()
[show source]
# File lib/ruby-prof/test.rb, line 52 52: def run_warmup 53: print "\n#{self.class.name}##{method_name}" 54: 55: run_test do 56: bench = Benchmark.realtime do 57: __send__(@method_name) 58: end 59: puts " (%.2fs warmup)" % bench 60: end 61: end