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
45
|
# File 'lib/visual_call_html.rb', line 7
def trace(options = {})
return unless block_given?
tracer = Tracer.new(options)
tracer.enable
yield
tracer.disable
data = tracer.data.map do |o|
next if o[:call].nil? && o[:return].nil?
text = if !o[:return].nil?
o[:return]
else
r = o[:call]&.class_id.to_s + "#" + o[:call]&.method_id.to_s
r += " (#{(o[:call].execute_time * 1000).round}ms)" if options[:display_time]
end
color = if o[:return]
"red"
else
"#44CCFF"
end
{
key: o[:key],
parent: o[:parent],
text: text,
color: color,
level: o[:level]
}.compact
end
if options[:level]
data = data.select{|o| o[:level].to_i <= options[:level]}
end
Html.new(data.compact).print
end
|