4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/profiling/engine.rb', line 4
def run(label=nil, options={})
enabled = options[:if].nil? ? true : !!options[:if]
return yield unless enabled
@dir = File.join(config[:dir], label.to_s)
FileUtils.mkdir_p(@dir) unless File.exist?(@dir)
require 'ruby-prof'
profile = RubyProf::Profile.new
profile.exclude_methods!(::Profiler::Engine, :run)
profile.exclude_common_methods! if config[:exclude_standard_lib]
profile.start
begin
yield
rescue => e
profile.stop
raise e
end
@results = profile.stop
if !@results.threads.empty? && config[:exclude_gems]
@results.threads.each do |thread|
thread.methods.each do |method|
if method.source_file.match(/\/gems\//)
method.eliminate!
end
end
end
end
out()
end
|