47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/lingo/debug.rb', line 47
def profile(base)
return yield unless base
require 'ruby-prof'
result = RubyProf.profile { yield }
result.eliminate_methods! [/\b(?:Gem|HighLine)\b/,
/\A(?:Benchmark|FileUtils|Pathname|Util)\b/]
if base.is_a?(IO)
RubyProf::FlatPrinter.new(result).print(base)
else
FileUtils.mkdir_p(File.dirname(base))
mode = ENV['RUBY_PROF_MEASURE_MODE']
base += "-#{mode}" if mode && !mode.empty?
{
txt: :FlatPrinter,
lines: :FlatPrinterWithLineNumbers,
html: :GraphHtmlPrinter,
stack: :CallStackPrinter
}.each { |ext, name|
File.open("#{base}.#{ext}", 'a+', encoding: ENCODING) { |f|
RubyProf.const_get(name).new(result).print(f)
}
}
end
end
|