call_graph 1.4.3 → 2.0.0.pre
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/README.md +3 -6
- data/examples/foobar.rb +3 -3
- data/lib/call_graph/instrument.rb +26 -60
- data/lib/call_graph/version.rb +1 -1
- data/lib/call_graph.rb +2 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cd7595348f729124dcfb2f6539fa64a07cf9252a95f064db16f213a2d4eb5d9
|
4
|
+
data.tar.gz: 0363b8ea3eac72bddf9333e2b13b4719a877d0a81356df724413f8db616f40b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65e02be5c6814108da3345da3f004c17b53a4fb3d8266f060db92be498fad222f7c558633119adfcfeb433af3b68ea823e61a047b6c71f193fb68d3160b1ad2f
|
7
|
+
data.tar.gz: 5e4fbc1daa3ca4dc6d2e03bd8f9bc2e09d976efc589e7e1e945ff94b7b5e90b63c3b80ad491573e0e41c8b0d60cf232047d698b871ad3e86c3c2a6d44faafb3d
|
data/README.md
CHANGED
@@ -41,9 +41,9 @@ CallGraph.config do |config|
|
|
41
41
|
config.file_path = "examples/call-graph"
|
42
42
|
end
|
43
43
|
|
44
|
-
CallGraph.
|
45
|
-
A.x
|
46
|
-
|
44
|
+
CallGraph.trace do
|
45
|
+
A.x
|
46
|
+
end
|
47
47
|
```
|
48
48
|
|
49
49
|
Print the captured execution with the provided rake tasks.
|
@@ -68,9 +68,6 @@ rake call_graph:printer:png # write png file from dot file
|
|
68
68
|
```ruby
|
69
69
|
CallGraph.config do |config|
|
70
70
|
config.file_path = "examples/call-graph"
|
71
|
-
config.ignore_paths.clear
|
72
|
-
config.ignore_methods << "stop"
|
73
|
-
config.path(:png)
|
74
71
|
end
|
75
72
|
```
|
76
73
|
|
data/examples/foobar.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'set'
|
2
2
|
require 'binding_of_caller'
|
3
3
|
|
4
|
+
INTROSPECT = "(self.class == Class ? self.name : self.class.name) + ' ' + (self.class == Class ? '(Class)' : '(Instance)')"
|
5
|
+
|
4
6
|
module CallGraph
|
5
7
|
class Instrument
|
6
|
-
attr_accessor :file_path, :
|
8
|
+
attr_accessor :file_path, :set
|
7
9
|
|
8
|
-
def initialize(file_path: default_file_path
|
10
|
+
def initialize(file_path: default_file_path)
|
9
11
|
@file_path = file_path
|
10
|
-
@ignore_paths = ignore_paths
|
11
|
-
@ignore_methods = ignore_methods
|
12
12
|
@set = Set.new
|
13
13
|
end
|
14
14
|
|
@@ -17,72 +17,38 @@ module CallGraph
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def default_file_path
|
20
|
-
'
|
21
|
-
end
|
22
|
-
|
23
|
-
def default_ignore_paths
|
24
|
-
[
|
25
|
-
/#{RUBY_VERSION}/,
|
26
|
-
/\(eval\)/,
|
27
|
-
/bundle\/gems/,
|
28
|
-
/spec/,
|
29
|
-
/test/
|
30
|
-
]
|
20
|
+
'call-graph'
|
31
21
|
end
|
32
22
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
:initialize,
|
38
|
-
:new,
|
39
|
-
:attr_reader,
|
40
|
-
:method_added,
|
41
|
-
:private,
|
42
|
-
:inherited,
|
43
|
-
:singleton_method_added,
|
44
|
-
:set_trace_func,
|
45
|
-
:call
|
46
|
-
]
|
47
|
-
end
|
23
|
+
def trace(&block)
|
24
|
+
trace_point.enable
|
25
|
+
yield
|
26
|
+
trace_point.disable
|
48
27
|
|
49
|
-
|
50
|
-
# :nocov:
|
51
|
-
set_trace_func ->(event, file, _line, id, receiver_binding, classname) do
|
52
|
-
return if ignore_paths.any? { |path| file && file[path] }
|
53
|
-
|
54
|
-
case event
|
55
|
-
when 'call', 'c-call'
|
56
|
-
caller_binding = receiver_binding.of_caller(2)
|
28
|
+
File.open(path(:tmp), 'w') { |fd| fd.write set.to_a.compact.join("\n") }
|
57
29
|
|
58
|
-
|
59
|
-
|
60
|
-
caller_class = caller_class + ' ' + caller_binding.eval("self.class == Class ? '(Class)' : '(Instance)'")
|
30
|
+
set.clear
|
31
|
+
end
|
61
32
|
|
33
|
+
private
|
62
34
|
|
63
|
-
|
64
|
-
|
65
|
-
|
35
|
+
def trace_point
|
36
|
+
@trace_point ||= begin
|
37
|
+
TracePoint.new(:call) do |trace|
|
38
|
+
next if trace.defined_class == self.class
|
66
39
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
40
|
+
case trace.event
|
41
|
+
when :call
|
42
|
+
id = trace.method_id
|
43
|
+
caller = trace.binding.of_caller(2).eval(INTROSPECT)
|
44
|
+
receiver = trace.binding.eval(INTROSPECT)
|
71
45
|
|
72
|
-
|
46
|
+
next if caller == receiver
|
47
|
+
|
48
|
+
set.add("#{caller},#{receiver},#{id}")
|
49
|
+
end
|
73
50
|
end
|
74
|
-
rescue Exception => e
|
75
|
-
puts e.message
|
76
51
|
end
|
77
|
-
#:nocov:
|
78
|
-
end
|
79
|
-
|
80
|
-
def stop
|
81
|
-
set_trace_func nil
|
82
|
-
|
83
|
-
File.open(path(:tmp), 'w') { |fd| fd.write set.to_a.compact.join("\n") }
|
84
|
-
|
85
|
-
set.clear
|
86
52
|
end
|
87
53
|
end
|
88
54
|
end
|
data/lib/call_graph/version.rb
CHANGED
data/lib/call_graph.rb
CHANGED
@@ -4,8 +4,8 @@ require 'call_graph/printers/dot'
|
|
4
4
|
require 'call_graph/printers/png'
|
5
5
|
|
6
6
|
module CallGraph
|
7
|
-
def self.
|
8
|
-
instrument.
|
7
|
+
def self.trace(&block)
|
8
|
+
instrument.trace(&block)
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.config
|
@@ -16,10 +16,6 @@ module CallGraph
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.stop
|
20
|
-
instrument.stop
|
21
|
-
end
|
22
|
-
|
23
19
|
private
|
24
20
|
|
25
21
|
def self.instrument
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: call_graph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Moriarty
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: binding_of_caller
|
@@ -109,9 +109,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
111
|
requirements:
|
112
|
-
- - "
|
112
|
+
- - ">"
|
113
113
|
- !ruby/object:Gem::Version
|
114
|
-
version:
|
114
|
+
version: 1.3.1
|
115
115
|
requirements: []
|
116
116
|
rubygems_version: 3.0.1
|
117
117
|
signing_key:
|