visual_call_html 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/call.rb +30 -0
- data/lib/html.rb +1 -1
- data/lib/tracer.rb +35 -15
- data/lib/visual_call_html.rb +31 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b3bc8a9e40282d73db18c4fc8c5fe335f67b56215cae90e16798677586c8bf3
|
4
|
+
data.tar.gz: 53ce8bf54cc935ec9e38be6de0c803c99cc6845dc556c28058b35d70666e014d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18039c0ce4a18ef08e3a3d22e2ed04162f087f244b65eb64dfa062f165c2991adf9b400a4e647ace2e67a81bc4ef252deb338b0837cd61acdc11b2139568f7b1
|
7
|
+
data.tar.gz: 30b9cd2347484b739fc46d03d2016e054eb2dc3da6b906c19ead252e58df32403a10cd97aab549deb791e294f2764fddd3b92da4ec7acfa2899731a9aa161853
|
data/lib/call.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
class Call
|
2
|
+
attr_reader :key, :class_id, :method_id
|
3
|
+
attr_accessor :start_time, :finish_time
|
4
|
+
|
5
|
+
def initialize(event)
|
6
|
+
@start_time = Time.now.to_f
|
7
|
+
@class_id = event.defined_class
|
8
|
+
@method_id = event.method_id
|
9
|
+
@key = generate_key
|
10
|
+
end
|
11
|
+
|
12
|
+
def finish
|
13
|
+
@finish_time ||= Time.now.to_f
|
14
|
+
execute_time
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute_time
|
18
|
+
@finish_time.to_f - @start_time
|
19
|
+
end
|
20
|
+
|
21
|
+
def key?(key)
|
22
|
+
@key == key
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def generate_key
|
28
|
+
[('a'..'z'), (0..9)].map(&:to_a).flatten.shuffle.join
|
29
|
+
end
|
30
|
+
end
|
data/lib/html.rb
CHANGED
@@ -47,7 +47,7 @@ class Html
|
|
47
47
|
// the template we defined earlier
|
48
48
|
myDiagram.nodeTemplate =
|
49
49
|
$(go.Node, "Horizontal",
|
50
|
-
|
50
|
+
new go.Binding("background", "color"),
|
51
51
|
$(go.TextBlock, "Default Text",
|
52
52
|
{ margin: 12, stroke: "white", font: "bold 16px sans-serif" },
|
53
53
|
new go.Binding("text", "text"))
|
data/lib/tracer.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative 'call'
|
2
|
+
|
1
3
|
class Tracer
|
2
4
|
attr_reader :path, :data
|
3
5
|
|
@@ -18,28 +20,46 @@ class Tracer
|
|
18
20
|
|
19
21
|
private
|
20
22
|
|
21
|
-
def uniq_key
|
22
|
-
rand(1..1_000).to_s + Time.now.to_f.to_s
|
23
|
-
end
|
24
|
-
|
25
23
|
def build_tracer
|
26
24
|
TracePoint.new(:call, :return) do |event|
|
27
|
-
next if event
|
25
|
+
next if not_able_to_add?(event)
|
28
26
|
|
29
27
|
case event.event
|
30
28
|
when :return
|
31
|
-
|
32
|
-
key: uniq_key,
|
33
|
-
parent: @path.last,
|
34
|
-
text: "Return: #{event.return_value}"
|
35
|
-
)
|
36
|
-
@path.pop
|
29
|
+
run_when_return(event)
|
37
30
|
when :call
|
38
|
-
|
39
|
-
data = { key: key, parent: @path.last, text: event.method_id }.compact
|
40
|
-
@data.push(data)
|
41
|
-
@path.push(key)
|
31
|
+
run_when_call(event)
|
42
32
|
end
|
43
33
|
end
|
44
34
|
end
|
35
|
+
|
36
|
+
def not_able_to_add?(event)
|
37
|
+
event.defined_class == self.class || event.defined_class == TracePoint
|
38
|
+
end
|
39
|
+
|
40
|
+
def run_when_call(event)
|
41
|
+
call = Call.new(event)
|
42
|
+
|
43
|
+
data = {
|
44
|
+
key: call.key,
|
45
|
+
parent: @path.last&.key,
|
46
|
+
call: call,
|
47
|
+
level: @path.size
|
48
|
+
}.compact
|
49
|
+
|
50
|
+
@data.push(data)
|
51
|
+
@path.push(call)
|
52
|
+
end
|
53
|
+
|
54
|
+
def run_when_return(event)
|
55
|
+
call = @path.pop
|
56
|
+
call&.finish
|
57
|
+
if @options[:display_return_value] && event.return_value && call
|
58
|
+
@data.push(
|
59
|
+
key: "#{call.key}_return",
|
60
|
+
parent: call.key,
|
61
|
+
return: event.return_value
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
45
65
|
end
|
data/lib/visual_call_html.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'tracer'
|
2
2
|
require_relative 'html'
|
3
|
+
require_relative 'call'
|
3
4
|
|
4
5
|
module VisualCallHtml
|
5
6
|
class << self
|
@@ -11,7 +12,36 @@ module VisualCallHtml
|
|
11
12
|
yield
|
12
13
|
tracer.disable
|
13
14
|
|
14
|
-
|
15
|
+
data = tracer.data.map do |o|
|
16
|
+
next if o[:call].nil? && o[:return].nil?
|
17
|
+
|
18
|
+
text = if !o[:return].nil?
|
19
|
+
o[:return]
|
20
|
+
else
|
21
|
+
r = o[:call]&.class_id.to_s + "#" + o[:call]&.method_id.to_s
|
22
|
+
r += " (#{(o[:call].execute_time * 1000).round}ms)" if options[:display_time]
|
23
|
+
end
|
24
|
+
|
25
|
+
color = if o[:return]
|
26
|
+
"red"
|
27
|
+
else
|
28
|
+
"#44CCFF"
|
29
|
+
end
|
30
|
+
|
31
|
+
{
|
32
|
+
key: o[:key],
|
33
|
+
parent: o[:parent],
|
34
|
+
text: text,
|
35
|
+
color: color,
|
36
|
+
level: o[:level]
|
37
|
+
}.compact
|
38
|
+
end
|
39
|
+
|
40
|
+
if options[:level]
|
41
|
+
data = data.select{|o| o[:level].to_i <= options[:level]}
|
42
|
+
end
|
43
|
+
|
44
|
+
Html.new(data.compact).print
|
15
45
|
end
|
16
46
|
end
|
17
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: visual_call_html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hungkieu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Uses the TracePoint class & GoJS to generate a visual representation
|
14
14
|
of all the methods called by another method.
|
@@ -17,6 +17,7 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- lib/call.rb
|
20
21
|
- lib/html.rb
|
21
22
|
- lib/tracer.rb
|
22
23
|
- lib/visual_call_html.rb
|
@@ -39,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '0'
|
41
42
|
requirements: []
|
42
|
-
rubygems_version: 3.
|
43
|
+
rubygems_version: 3.3.3
|
43
44
|
signing_key:
|
44
45
|
specification_version: 4
|
45
46
|
summary: This gem helps you see all the other methods called by another method.
|