2013-06-19 18:33:02 -04:00
|
|
|
require 'benchmark'
|
|
|
|
require 'pp'
|
2013-11-05 17:13:08 -05:00
|
|
|
require 'optparse'
|
|
|
|
|
|
|
|
$list = true
|
|
|
|
$gcprof = true
|
|
|
|
|
|
|
|
opt = OptionParser.new
|
|
|
|
opt.on('-q'){$list = false}
|
2013-11-05 17:27:27 -05:00
|
|
|
opt.on('-d'){$gcprof = false}
|
2013-11-05 17:13:08 -05:00
|
|
|
opt.parse!(ARGV)
|
2013-06-19 18:33:02 -04:00
|
|
|
|
2013-06-20 04:25:16 -04:00
|
|
|
script = File.join(File.dirname(__FILE__), ARGV.shift)
|
2013-06-20 02:18:09 -04:00
|
|
|
script += '.rb' unless FileTest.exist?(script)
|
|
|
|
raise "#{script} not found" unless FileTest.exist?(script)
|
|
|
|
|
|
|
|
puts "Script: #{script}"
|
2013-06-19 18:33:02 -04:00
|
|
|
|
2013-11-05 17:13:08 -05:00
|
|
|
if $gcprof
|
|
|
|
GC::Profiler.enable
|
|
|
|
end
|
|
|
|
|
2013-06-19 18:33:02 -04:00
|
|
|
tms = Benchmark.measure{|x|
|
|
|
|
load script
|
|
|
|
}
|
|
|
|
|
2013-11-05 17:13:08 -05:00
|
|
|
gc_time = 0
|
|
|
|
|
|
|
|
if $gcprof
|
|
|
|
gc_time = GC::Profiler.total_time
|
|
|
|
GC::Profiler.report if $list and RUBY_VERSION >= '2.0.0' # before 1.9.3, report() may run infinite loop
|
|
|
|
GC::Profiler.disable
|
|
|
|
end
|
|
|
|
|
|
|
|
pp GC.stat
|
2013-11-09 10:43:30 -05:00
|
|
|
|
2013-12-18 20:49:59 -05:00
|
|
|
puts "#{RUBY_DESCRIPTION} #{GC::OPTS.inspect}" if defined?(GC::OPTS)
|
2013-11-09 10:43:30 -05:00
|
|
|
|
2013-06-21 04:57:18 -04:00
|
|
|
desc = "#{RUBY_VERSION}#{RUBY_PATCHLEVEL >= 0 ? "p#{RUBY_PATCHLEVEL}" : "dev"}"
|
|
|
|
name = File.basename(script, '.rb')
|
|
|
|
|
2013-06-19 18:33:02 -04:00
|
|
|
puts
|
2013-06-20 02:18:09 -04:00
|
|
|
puts script
|
2013-06-19 18:33:02 -04:00
|
|
|
puts Benchmark::CAPTION
|
|
|
|
puts tms
|
|
|
|
puts "GC total time (sec): #{gc_time}"
|
2013-10-31 12:09:10 -04:00
|
|
|
|
|
|
|
# show High-Water Mark on Linux
|
|
|
|
if File.exist?('/proc/self/status') && /VmHWM:\s*(\d+.+)/ =~ File.read('/proc/self/status')
|
|
|
|
puts
|
|
|
|
puts "VmHWM: #{$1.chomp}"
|
|
|
|
end
|
|
|
|
|
2013-06-19 18:33:02 -04:00
|
|
|
puts
|
2013-06-21 04:57:18 -04:00
|
|
|
puts "Summary of #{name} on #{desc}\t#{tms.real}\t#{gc_time}\t#{GC.count}"
|
2013-06-19 19:15:56 -04:00
|
|
|
puts " (real time in sec, GC time in sec, GC count)"
|