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
|
# File 'lib/profiling/engine.rb', line 5
def run(*args)
label = args.find { |a| a.is_a?(String) }
opts = args.find { |a| a.is_a?(Hash) }
enabled = opts.nil? ? true : opts[: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 StandardError => e
profile.stop
raise e
end
@results = profile.stop
if !@results.threads.empty? && exclusion_regex
@results.threads.each do |thread|
thread.methods.each { |m| m.eliminate! if m.source_file.match(exclusion_regex) }
end
end
out
end
|